CostProjectTaskMaterialManagerImpl.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package com.hotent.project.manager.impl;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import com.hotent.project.manager.CostProjectTaskManager;
  5. import com.hotent.project.model.CostProjectTask;
  6. import com.hotent.surveyinfo.manager.CostSurveyFdTemplateManager;
  7. import com.hotent.surveyinfo.manager.CostSurveyTemplateManager;
  8. import com.hotent.surveyinfo.model.CostSurveyFdTemplate;
  9. import com.hotent.sys.persistence.manager.DataDictManager;
  10. import com.hotent.sys.persistence.model.DataDict;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  15. import com.baomidou.mybatisplus.core.metadata.IPage;
  16. import com.hotent.base.manager.impl.BaseManagerImpl;
  17. import com.hotent.base.query.QueryFilter;
  18. import com.hotent.base.util.BeanUtils;
  19. import com.hotent.project.dao.CostProjectTaskMaterialDao;
  20. import com.hotent.project.manager.CostProjectTaskMaterialManager;
  21. import com.hotent.project.model.CostProjectTaskMaterial;
  22. import javax.annotation.Resource;
  23. /**
  24. * 任务定制-报送资料要求 服务实现类
  25. *
  26. * @company 山西清众科技股份有限公司
  27. * @author 超级管理员
  28. * @since 2025-10-09
  29. */
  30. @Service
  31. public class CostProjectTaskMaterialManagerImpl extends BaseManagerImpl<CostProjectTaskMaterialDao, CostProjectTaskMaterial> implements CostProjectTaskMaterialManager {
  32. @Resource
  33. DataDictManager dataDictManager;
  34. @Autowired
  35. private CostSurveyFdTemplateManager costSurveyFdTemplateManager;
  36. @Autowired
  37. private CostProjectTaskManager costProjectTaskManager;
  38. @Override
  39. public CostProjectTaskMaterial getDetail(String id) {
  40. CostProjectTaskMaterial costProjectTaskMaterial = this.get(id);
  41. if (BeanUtils.isEmpty(costProjectTaskMaterial)) {
  42. throw new RuntimeException("任务定制-报送资料要求不存在");
  43. }
  44. return costProjectTaskMaterial;
  45. }
  46. @Override
  47. @Transactional
  48. public void createOrUpdate(CostProjectTaskMaterial costProjectTaskMaterial) {
  49. // 根据taskId获取任务节点
  50. if (costProjectTaskMaterial.getTaskId() != null) {
  51. CostProjectTask task = costProjectTaskManager.getById(costProjectTaskMaterial.getTaskId());
  52. if (task != null) {
  53. String currentNode = task.getCurrentNode();
  54. costProjectTaskMaterial.setTaskNode(currentNode);
  55. // 如果不是clcs节点,且有文件上传,需要根据文件类型设置informationType
  56. if (!"clcs".equals(currentNode) && costProjectTaskMaterial.getFileUrl() != null) {
  57. String fileUrl = costProjectTaskMaterial.getFileUrl();
  58. String fileExtension = getFileExtension(fileUrl);
  59. if (isWordFile(fileExtension)) {
  60. // Word文件设置为3
  61. costProjectTaskMaterial.setInformationType("1");
  62. } else if (isExcelFile(fileExtension)) {
  63. // Excel文件设置为2
  64. costProjectTaskMaterial.setInformationType("2");
  65. }
  66. }
  67. }
  68. }
  69. //新建或更新
  70. this.saveOrUpdate(costProjectTaskMaterial);
  71. }
  72. /**
  73. * 获取文件扩展名
  74. */
  75. private String getFileExtension(String fileUrl) {
  76. if (fileUrl == null || fileUrl.isEmpty()) {
  77. return "";
  78. }
  79. int lastDotIndex = fileUrl.lastIndexOf(".");
  80. if (lastDotIndex > 0 && lastDotIndex < fileUrl.length() - 1) {
  81. return fileUrl.substring(lastDotIndex + 1).toLowerCase();
  82. }
  83. return "";
  84. }
  85. /**
  86. * 判断是否为Word文件
  87. */
  88. private boolean isWordFile(String extension) {
  89. return "doc".equals(extension) || "docx".equals(extension);
  90. }
  91. /**
  92. * 判断是否为Excel文件
  93. */
  94. private boolean isExcelFile(String extension) {
  95. return "xls".equals(extension) || "xlsx".equals(extension);
  96. }
  97. @Override
  98. @Transactional
  99. public void deleteById(String id) {
  100. this.removeById(id);
  101. }
  102. @Override
  103. @Transactional
  104. public void batchDelete(String[] ids) {
  105. this.removeByIds(Arrays.asList(ids));
  106. }
  107. @Override
  108. public List<CostProjectTaskMaterial> listByTaskId(String taskId) {
  109. QueryWrapper<CostProjectTaskMaterial> queryWrapper = new QueryWrapper<>();
  110. queryWrapper.eq("task_id", taskId);
  111. queryWrapper.orderByAsc("order_num");
  112. List<CostProjectTaskMaterial> list = this.list(queryWrapper);
  113. for (CostProjectTaskMaterial costProjectTaskMaterial : list) {
  114. DataDict byDictKey = dataDictManager.getByDictKey("1976557733440159744", costProjectTaskMaterial.getInformationType());
  115. if (!BeanUtils.isEmpty(byDictKey)){
  116. costProjectTaskMaterial.setInformationTypeName(byDictKey.getName());
  117. }
  118. if(costProjectTaskMaterial.getTemplateId() != null){
  119. CostSurveyFdTemplate manager = costSurveyFdTemplateManager.getById(costProjectTaskMaterial.getTemplateId());
  120. if (manager != null){
  121. costProjectTaskMaterial.setTemplateType(manager.getTemplateType());
  122. }
  123. }
  124. CostProjectTask task = costProjectTaskManager.getById(taskId);
  125. costProjectTaskMaterial.setAuditedUnitId(task.getAuditedUnitId()); ;
  126. }
  127. return list;
  128. }
  129. }