CostProjectDocumentManagerImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. package com.hotent.project.manager.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.hotent.baseInfo.manager.AuditedUnitManager;
  8. import com.hotent.baseInfo.manager.CostDocumentTemplateManager;
  9. import com.hotent.baseInfo.manager.CostDocumentWhManager;
  10. import com.hotent.baseInfo.model.AuditedUnit;
  11. import com.hotent.baseInfo.model.CostDocumentTemplate;
  12. import com.hotent.baseInfo.model.CostDocumentWh;
  13. import com.hotent.config.EipConfig;
  14. import com.hotent.constant.BaseConstant;
  15. import com.hotent.project.manager.CostProjectDocumentFileManager;
  16. import com.hotent.project.model.CostProjectDocument;
  17. import com.hotent.project.dao.CostProjectDocumentDao;
  18. import com.hotent.project.manager.CostProjectDocumentManager;
  19. import com.hotent.base.manager.impl.BaseManagerImpl;
  20. import com.hotent.project.model.CostProjectDocumentFile;
  21. import com.hotent.project.req.CostProjectDocumentPageReq;
  22. import com.hotent.project.req.CostProjectDocumentReq;
  23. import com.hotent.project.resp.CostProjectDocumentResp;
  24. import com.hotent.uc.exception.BaseException;
  25. import com.hotent.util.wordexcelutils.DocumentProcessor;
  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.tools.ant.util.DateUtils;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import java.time.LocalDateTime;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. import com.hotent.util.FileUploadUtil;
  35. /**
  36. * 监审项目文书表 服务实现类
  37. *
  38. * @author 超级管理员
  39. * @company 山西清众科技股份有限公司
  40. * @since 2025-09-26
  41. */
  42. @Service
  43. public class CostProjectDocumentManagerImpl extends BaseManagerImpl<CostProjectDocumentDao, CostProjectDocument> implements CostProjectDocumentManager {
  44. @Autowired
  45. private CostProjectDocumentFileManager costProjectDocumentFileManager;
  46. @Autowired
  47. private CostDocumentTemplateManager costDocumentTemplateManager;
  48. @Autowired
  49. private AuditedUnitManager auditedUnitManager;
  50. @Autowired
  51. private CostDocumentWhManager costDocumentWhManager;
  52. @Override
  53. public CostProjectDocument getDetail(String id) {
  54. CostProjectDocument costProjectDocument = this.get(id);
  55. return costProjectDocument;
  56. }
  57. @Override
  58. public void deleteByIds(List<String> ids) {
  59. List<CostProjectDocument> costProjectDocuments = this.listByIds(ids);
  60. if (costProjectDocuments!=null){
  61. costProjectDocuments.forEach(item -> {
  62. //逻辑删除
  63. item.setIsDeleted( BaseConstant.DELETE_FLAG);
  64. });
  65. this.updateBatchById(costProjectDocuments);
  66. }
  67. }
  68. @Override
  69. @Transactional
  70. public void createOrUpdate(CostProjectDocument costProjectDocument) {
  71. //新建或更新
  72. this.saveOrUpdate(costProjectDocument);
  73. }
  74. @Override
  75. public IPage<CostProjectDocument> pageList(CostProjectDocumentPageReq req) {
  76. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  77. if (req.getDocumentType() != null) {
  78. // LambdaQueryWrapper<CostDocumentTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  79. // lambdaQueryWrapper.eq(CostDocumentTemplate::getId, req.getDocumentType());
  80. // lambdaQueryWrapper.eq(CostDocumentTemplate::getIsWh, "0");
  81. qw.eq(CostProjectDocument::getDocumentType, req.getDocumentType());
  82. }
  83. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  84. IPage<CostProjectDocument> page = new Page<>(req.getPageNum(), req.getPageSize());
  85. return this.page(page, qw);
  86. }
  87. // @Override
  88. // public void create(CostProjectDocument costProjectDocument) {
  89. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentId())) {
  90. // throw new BaseException("请选择文书模板");
  91. // }
  92. // if (ObjectUtil.isEmpty(costProjectDocument.getProjectId())) {
  93. // throw new BaseException("请选择项目");
  94. // }
  95. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentNumber())) {
  96. // throw new BaseException("请填写通知文号");
  97. // }
  98. // if (ObjectUtil.isEmpty(costProjectDocument.getEnterpriseId())) {
  99. // throw new BaseException("请选择监审单位");
  100. // }
  101. // costProjectDocument.setGenerateTime(LocalDateTime.now());
  102. // costProjectDocument.setIsPushed("1");
  103. //
  104. // CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  105. // if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  106. // throw new BaseException("文书模板不存在");
  107. // }
  108. // costProjectDocument.setDocumentAlias(costDocumentTemplate.getAlias());
  109. // AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
  110. // if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  111. // throw new BaseException("被监审单位不存在");
  112. // }
  113. // CostDocumentWh costDocumentWh = costDocumentWhManager.get(costProjectDocument.getDocumentWhId());
  114. // if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  115. // throw new BaseException("文书文号不存在");
  116. // }
  117. //
  118. // LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  119. // qw.eq(CostProjectDocument::getProjectId, costProjectDocument.getProjectId());
  120. // qw.eq(CostProjectDocument::getDocumentId, costProjectDocument.getDocumentId());
  121. // qw.eq(CostProjectDocument::getEnterpriseId, costProjectDocument.getEnterpriseId());
  122. // if (this.count(qw) > 0) {
  123. // throw new BaseException("该项目监审单位已存在此文书");
  124. // }
  125. // super.create(costProjectDocument);
  126. //
  127. //
  128. // }
  129. @Override
  130. public void create(CostProjectDocumentReq req) {
  131. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  132. throw new BaseException("请选择文书模板");
  133. }
  134. if (ObjectUtil.isEmpty(req.getProjectId())) {
  135. throw new BaseException("请选择项目");
  136. }
  137. if (ObjectUtil.isEmpty(req.getDocumentNumber())) {
  138. throw new BaseException("请填写通知文号");
  139. }
  140. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  141. throw new BaseException("请选择监审单位");
  142. }
  143. req.setGenerateTime(LocalDateTime.now());
  144. req.setIsPushed("1");
  145. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  146. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  147. throw new BaseException("文书模板不存在");
  148. }
  149. req.setDocumentAlias(costDocumentTemplate.getAlias());
  150. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  151. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  152. throw new BaseException("被监审单位不存在");
  153. }
  154. CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
  155. if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  156. throw new BaseException("文书文号不存在");
  157. }
  158. //返回文号
  159. String whNo = costDocumentWh.getRulePattern().replace("{prefixText}", costDocumentWh.getPrefixText())
  160. .replace("{year}", costDocumentWh.getYear()).replace("{currentValue}", costDocumentWh.getCurrentValue().toString());
  161. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  162. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  163. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  164. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  165. if (this.count(qw) > 0) {
  166. throw new BaseException("该项目监审单位已存在此文书");
  167. }
  168. //类型转换
  169. CostProjectDocument costProjectDocument = new CostProjectDocument();
  170. BeanUtil.copyProperties(req, costProjectDocument);
  171. costProjectDocument.setDocumentNumber(whNo);
  172. costProjectDocument.setDocumentName(costDocumentTemplate.getDocumentName());
  173. costProjectDocument.setDocumentType(costDocumentTemplate.getType());
  174. super.create(costProjectDocument);
  175. //文件关联信息赋值
  176. req.getCostProjectDocumentFiles().forEach(costProjectDocumentFile -> {
  177. costProjectDocumentFile.setDocumentId(costProjectDocument.getDocumentId());
  178. costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
  179. //送达回证特殊处理字段 后期在说
  180. if ("送达回证".equals(costProjectDocument.getDocumentName())) {
  181. if (costProjectDocumentFile.getPinyin().equals("SongDaWenShuMingCheng")){
  182. costProjectDocumentFile.setDataValue(costDocumentTemplate.getDocumentName());
  183. }
  184. if (costProjectDocumentFile.getPinyin().equals("SongDaWenShuWenHao")){
  185. costProjectDocumentFile.setDataValue(whNo);
  186. }
  187. if (costProjectDocumentFile.getPinyin().equals("SongDaWenShuMingCheng")){
  188. costProjectDocumentFile.setDataValue(costDocumentTemplate.getDocumentName());
  189. }
  190. if (costProjectDocumentFile.getPinyin().equals("TongZhiSongDaShiJian")){
  191. costProjectDocumentFile.setDataValue(DateUtils.format(new Date(),"yyyy-MM-dd"));
  192. }
  193. if (costProjectDocumentFile.getPinyin().equals("BeiJianShenDanWeiBanGongDiDian")){
  194. costProjectDocumentFile.setDataValue(auditedUnit.getAddress());
  195. }
  196. if (costProjectDocumentFile.getPinyin().equals("ShouSongDaRen")){
  197. costProjectDocumentFile.setDataValue(auditedUnit.getContactName());
  198. }
  199. }
  200. });
  201. //保存解析出的文件内容
  202. costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
  203. //更新文号值
  204. costDocumentWhManager.updateCurrentValue(costDocumentWh.getId());
  205. }
  206. @Override
  207. public List<CostProjectDocumentFile> getDocumentFileList(String id) {
  208. CostProjectDocument costProjectDocument = this.get(id);
  209. if(costProjectDocument == null){
  210. throw new BaseException("文书模板不存在");
  211. }
  212. return null;
  213. }
  214. @Override
  215. public void updateProjectDocument(CostProjectDocumentReq req) {
  216. if (ObjectUtil.isEmpty(req.getId())) {
  217. throw new BaseException("请选择要修改的文书");
  218. }
  219. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  220. throw new BaseException("请选择文书模板");
  221. }
  222. if (ObjectUtil.isEmpty(req.getProjectId())) {
  223. throw new BaseException("请选择项目");
  224. }
  225. if (ObjectUtil.isEmpty(req.getDocumentNumber())) {
  226. throw new BaseException("请填写通知文号");
  227. }
  228. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  229. throw new BaseException("请选择监审单位");
  230. }
  231. CostProjectDocument selectCostProjectDocument = this.get(req.getId());
  232. if (selectCostProjectDocument == null) {
  233. throw new BaseException("请选择要修改的文书");
  234. }
  235. req.setIsPushed("1");
  236. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  237. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  238. throw new BaseException("文书模板不存在");
  239. }
  240. req.setDocumentAlias(costDocumentTemplate.getAlias());
  241. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  242. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  243. throw new BaseException("被监审单位不存在");
  244. }
  245. CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
  246. if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  247. throw new BaseException("文书文号不存在");
  248. }
  249. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  250. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  251. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  252. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  253. if (this.count(qw) > 0) {
  254. throw new BaseException("该项目监审单位已存在此文书");
  255. }
  256. selectCostProjectDocument.setDocumentWhId(req.getDocumentWhId());
  257. selectCostProjectDocument.setDocumentId(req.getDocumentId());
  258. selectCostProjectDocument.setEnterpriseId(req.getEnterpriseId());
  259. selectCostProjectDocument.setElectronicDocumentUrl("");
  260. // 类型转换
  261. BeanUtil.copyProperties(req,selectCostProjectDocument);
  262. super.update(selectCostProjectDocument);
  263. costProjectDocumentFileManager.remove(new LambdaQueryWrapper<CostProjectDocumentFile>().eq(CostProjectDocumentFile::getProjectId,selectCostProjectDocument.getProjectId()));
  264. List<CostProjectDocumentFile> costProjectDocumentFiles = req.getCostProjectDocumentFiles();
  265. if (costProjectDocumentFiles != null){
  266. for (CostProjectDocumentFile costProjectDocumentFile : costProjectDocumentFiles) {
  267. costProjectDocumentFile.setDocumentId(selectCostProjectDocument.getDocumentId());
  268. costProjectDocumentFile.setProjectId(selectCostProjectDocument.getProjectId());
  269. }
  270. }
  271. costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
  272. }
  273. @Override
  274. public List<CostProjectDocument> getListByProjectId(String projectId) {
  275. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  276. qw.eq(CostProjectDocument::getProjectId, projectId);
  277. qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
  278. List<CostProjectDocument> list = this.list(qw);
  279. if (ObjectUtil.isEmpty(list)) {
  280. return new ArrayList<>();
  281. }
  282. return list;
  283. }
  284. @Override
  285. public CostProjectDocumentResp getByProjectId(String projectId){
  286. //查询监审文书
  287. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  288. qw.eq(CostProjectDocument::getProjectId, projectId);
  289. qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
  290. CostProjectDocument costProjectDocument = this.getOne(qw);
  291. //转换为返回类型
  292. CostProjectDocumentResp costProjectDocumentResp = BeanUtil.copyProperties(costProjectDocument, CostProjectDocumentResp.class);
  293. //查询文书下的文书内容
  294. LambdaQueryWrapper<CostProjectDocumentFile> wrapper = new LambdaQueryWrapper<>();
  295. wrapper.eq(CostProjectDocumentFile::getProjectId, costProjectDocument.getProjectId());
  296. //获取文件内容返回
  297. costProjectDocumentResp.setCostProjectDocumentFiles(costProjectDocumentFileManager.list(wrapper));
  298. CostDocumentTemplate costDocumentTemplate = costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  299. costProjectDocumentResp.setFullPath(EipConfig.getImgUrl()+costDocumentTemplate.getFileUrl());
  300. return costProjectDocumentResp;
  301. }
  302. @Override
  303. public String createDocument(String id) {
  304. CostProjectDocument costProjectDocument = this.getDetail(id);
  305. List<CostProjectDocumentFile> list = costProjectDocumentFileManager.getCostProjectDocumentFiles(costProjectDocument.getProjectId(),costProjectDocument.getDocumentId());
  306. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  307. //生成文书
  308. Map<String,String> map = new HashMap<>();
  309. list.stream().forEach(p->{
  310. map.put("{"+p.getOriginalText()+"}",p.getDataValue());
  311. });
  312. //先处理一种文件
  313. String templatePath = costDocumentTemplate.getFileUrl().replace(BaseConstant.RESOURCE_PREFIX,"");
  314. templatePath = EipConfig.getProfile()+templatePath;
  315. String fileExtension = FileUploadUtil.getFileExtension(costDocumentTemplate.getFileUrl());
  316. String fileName = FileUploadUtil.generateFileName(costDocumentTemplate.getDocumentName()+"."+fileExtension);
  317. String outputPath = FileUploadUtil.generateSavePath(EipConfig.getUploadPath(), fileName, fileExtension);
  318. DocumentProcessor.processWordDocument(templatePath,outputPath,map,new LinkedHashMap<>());
  319. return EipConfig.getImgUrl()+FileUploadUtil.getPathFileName(outputPath,fileName);
  320. }
  321. }