CostProjectDocumentManagerImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package com.hotent.project.manager.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.hotent.base.util.StringUtil;
  10. import com.hotent.base.util.UniqueIdUtil;
  11. import com.hotent.baseInfo.manager.AuditedUnitManager;
  12. import com.hotent.baseInfo.manager.CostDocumentTemplateFileManager;
  13. import com.hotent.baseInfo.manager.CostDocumentTemplateManager;
  14. import com.hotent.baseInfo.manager.CostDocumentWhManager;
  15. import com.hotent.baseInfo.model.AuditedUnit;
  16. import com.hotent.baseInfo.model.CostDocumentTemplate;
  17. import com.hotent.baseInfo.model.CostDocumentTemplateFile;
  18. import com.hotent.baseInfo.model.CostDocumentWh;
  19. import com.hotent.config.EipConfig;
  20. import com.hotent.constant.BaseConstant;
  21. import com.hotent.project.manager.*;
  22. import com.hotent.project.model.*;
  23. import com.hotent.project.dao.CostProjectDocumentDao;
  24. import com.hotent.base.manager.impl.BaseManagerImpl;
  25. import com.hotent.project.req.CostProjectDocumentPageReq;
  26. import com.hotent.project.req.CostProjectDocumentReq;
  27. import com.hotent.project.resp.CostProjectDocumentResp;
  28. import com.hotent.uc.api.model.IUser;
  29. import com.hotent.uc.exception.BaseException;
  30. import com.hotent.uc.manager.OrgManager;
  31. import com.hotent.uc.manager.UserManager;
  32. import com.hotent.uc.model.Org;
  33. import com.hotent.uc.model.User;
  34. import com.hotent.uc.util.ContextUtil;
  35. import com.hotent.util.CostDataUtil;
  36. import com.hotent.util.FileUtils;
  37. import com.hotent.util.HtmlUtils;
  38. import com.hotent.util.wordexcelutils.*;
  39. import org.apache.commons.lang.StringUtils;
  40. import org.apache.poi.xwpf.usermodel.XWPFDocument;
  41. import org.apache.tools.ant.util.DateUtils;
  42. import org.springframework.beans.BeanUtils;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.stereotype.Service;
  45. import org.springframework.transaction.annotation.Transactional;
  46. import java.io.FileInputStream;
  47. import java.io.FileOutputStream;
  48. import java.io.IOException;
  49. import java.time.LocalDate;
  50. import java.time.LocalDateTime;
  51. import java.time.YearMonth;
  52. import java.util.*;
  53. import java.util.regex.Matcher;
  54. import java.util.regex.Pattern;
  55. import java.util.stream.Collectors;
  56. import com.hotent.util.FileUploadUtil;
  57. import springfox.documentation.spring.web.json.Json;
  58. import static org.apache.tools.ant.util.DateUtils.ISO8601_DATE_PATTERN;
  59. /**
  60. * 监审项目文书表 服务实现类
  61. *
  62. * @author 超级管理员
  63. * @company 山西清众科技股份有限公司
  64. * @since 2025-09-26
  65. */
  66. @Service
  67. public class CostProjectDocumentManagerImpl extends BaseManagerImpl<CostProjectDocumentDao, CostProjectDocument> implements CostProjectDocumentManager {
  68. @Autowired
  69. private CostProjectDocumentFileManager costProjectDocumentFileManager;
  70. @Autowired
  71. private CostDocumentTemplateManager costDocumentTemplateManager;
  72. @Autowired
  73. private AuditedUnitManager auditedUnitManager;
  74. @Autowired
  75. private CostDocumentTemplateFileManager costDocumentTemplateFileManager;
  76. @Autowired
  77. private CostProjectTaskEvidenceManager costProjectTaskEvidenceManager;
  78. @Autowired
  79. private CostProjectTaskManager costProjectTaskManager;
  80. @Autowired
  81. private CostDocumentWhManager costDocumentWhManager;
  82. @Autowired
  83. private CostProjectApprovalManager costProjectApprovalManager;
  84. @Autowired
  85. private UserManager userService;
  86. @Autowired
  87. private CostDocumentTemplateFileManager costTemplateFileManager;
  88. @Autowired
  89. private OrgManager orgManager;
  90. @Override
  91. public CostProjectDocument getDetail(String id) {
  92. CostProjectDocument costProjectDocument = this.get(id);
  93. return costProjectDocument;
  94. }
  95. @Override
  96. public void deleteByIds(List<String> ids) {
  97. List<CostProjectDocument> costProjectDocuments = this.listByIds(ids);
  98. if (costProjectDocuments!=null){
  99. costProjectDocuments.forEach(item -> {
  100. //逻辑删除
  101. item.setIsDeleted( BaseConstant.DELETE_FLAG);
  102. });
  103. this.updateBatchById(costProjectDocuments);
  104. }
  105. }
  106. @Override
  107. @Transactional
  108. public void createOrUpdate(CostProjectDocument costProjectDocument) {
  109. //新建或更新
  110. this.saveOrUpdate(costProjectDocument);
  111. }
  112. @Override
  113. public IPage<CostProjectDocument> pageList(CostProjectDocumentPageReq req) throws Exception {
  114. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  115. if (StringUtil.isNotEmpty(req.getDocumentType())) {
  116. // LambdaQueryWrapper<CostDocumentTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  117. // lambdaQueryWrapper.eq(CostDocumentTemplate::getId, req.getDocumentType());
  118. // lambdaQueryWrapper.eq(CostDocumentTemplate::getIsWh, "0");
  119. qw.eq(CostProjectDocument::getDocumentType, req.getDocumentType());
  120. }
  121. if (StringUtil.isNotEmpty(req.getProjectId())) {
  122. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  123. }
  124. if(req.getPermissionType().equals(1)){
  125. IUser iUser = ContextUtil.getCurrentUser();
  126. User user = userService.getByAccount(iUser.getAccount());
  127. List<AuditedUnit> auditedUnit=auditedUnitManager.getByUserAccount(user.getId());
  128. List<String> collected = auditedUnit.stream().map(AuditedUnit::getUnitId).distinct().collect(Collectors.toList());
  129. if(!collected.isEmpty()){
  130. qw.in(CostProjectDocument::getEnterpriseId, collected);
  131. }
  132. } else if (req.getPermissionType().equals(2)) {
  133. IUser iUser = ContextUtil.getCurrentUser();
  134. User user = userService.getByAccount(iUser.getAccount());
  135. qw.eq(CostProjectDocument::getCreateBy, user.getAccount());
  136. }
  137. IPage<CostProjectDocument> page = new Page<>(req.getPageNum(), req.getPageSize());
  138. return this.page(page, qw);
  139. }
  140. // @Override
  141. // public void create(CostProjectDocument costProjectDocument) {
  142. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentId())) {
  143. // throw new BaseException("请选择文书模板");
  144. // }
  145. // if (ObjectUtil.isEmpty(costProjectDocument.getProjectId())) {
  146. // throw new BaseException("请选择项目");
  147. // }
  148. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentNumber())) {
  149. // throw new BaseException("请填写通知文号");
  150. // }
  151. // if (ObjectUtil.isEmpty(costProjectDocument.getEnterpriseId())) {
  152. // throw new BaseException("请选择监审单位");
  153. // }
  154. // costProjectDocument.setGenerateTime(LocalDateTime.now());
  155. // costProjectDocument.setIsPushed("1");
  156. //
  157. // CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  158. // if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  159. // throw new BaseException("文书模板不存在");
  160. // }
  161. // costProjectDocument.setDocumentAlias(costDocumentTemplate.getAlias());
  162. // AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
  163. // if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  164. // throw new BaseException("被监审单位不存在");
  165. // }
  166. // CostDocumentWh costDocumentWh = costDocumentWhManager.get(costProjectDocument.getDocumentWhId());
  167. // if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  168. // throw new BaseException("文书文号不存在");
  169. // }
  170. //
  171. // LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  172. // qw.eq(CostProjectDocument::getProjectId, costProjectDocument.getProjectId());
  173. // qw.eq(CostProjectDocument::getDocumentId, costProjectDocument.getDocumentId());
  174. // qw.eq(CostProjectDocument::getEnterpriseId, costProjectDocument.getEnterpriseId());
  175. // if (this.count(qw) > 0) {
  176. // throw new BaseException("该项目监审单位已存在此文书");
  177. // }
  178. // super.create(costProjectDocument);
  179. //
  180. //
  181. // }
  182. @Override
  183. @Transactional
  184. public String create(CostProjectDocumentReq req) throws Exception {
  185. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  186. throw new BaseException("请选择文书模板");
  187. }
  188. if (ObjectUtil.isEmpty(req.getProjectId())) {
  189. throw new BaseException("请选择项目");
  190. }
  191. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  192. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  193. throw new BaseException("文书模板不存在");
  194. }
  195. if (costDocumentTemplate.getIsWh().equals("0") && StringUtil.isEmpty(req.getDocumentNumber())) {
  196. throw new BaseException("请填写通知文号");
  197. }
  198. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  199. throw new BaseException("请选择监审单位");
  200. }
  201. req.setGenerateTime(LocalDateTime.now());
  202. req.setIsPushed("1");
  203. req.setDocumentAlias(costDocumentTemplate.getAlias());
  204. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  205. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  206. throw new BaseException("被监审单位不存在");
  207. }
  208. CostDocumentWh costDocumentWh;
  209. //返回文号
  210. String whNo;
  211. if (costDocumentTemplate.getIsWh().equals("0")) {
  212. costDocumentWh= costDocumentWhManager.get(req.getDocumentWhId());
  213. if (costDocumentWh == null) {
  214. throw new BaseException("文书文号不存在");
  215. }
  216. //返回文号
  217. whNo = this.getWH(costDocumentWh);
  218. } else {
  219. costDocumentWh = null;
  220. whNo = "";
  221. }
  222. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  223. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  224. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  225. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  226. if (this.count(qw) > 0) {
  227. throw new BaseException("该项目监审单位已存在此文书");
  228. }
  229. IUser iUser = ContextUtil.getCurrentUser();
  230. User user = userService.getByAccount(iUser.getAccount());
  231. CostProjectApproval costProjectApproval = costProjectApprovalManager.get(req.getProjectId());
  232. Org org = orgManager.getById(costProjectApproval.getOrgId());
  233. //类型转换
  234. CostProjectDocument costProjectDocument = new CostProjectDocument();
  235. BeanUtil.copyProperties(req, costProjectDocument);
  236. costProjectDocument.setDocumentNumber(whNo);
  237. costProjectDocument.setDocumentName(costDocumentTemplate.getDocumentName());
  238. costProjectDocument.setCreateBy(user.getCreateBy());
  239. costProjectDocument.setDocumentType(costDocumentTemplate.getType());
  240. costProjectDocument.setProjectId(costProjectApproval.getProjectId());
  241. super.create(costProjectDocument);
  242. //文件关联信息赋值
  243. req.getCostProjectDocumentFiles().forEach(costProjectDocumentFile -> {
  244. costProjectDocumentFile.setDocumentId(costProjectDocument.getDocumentId());
  245. costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
  246. costProjectDocumentFile.setProjectDocumentId(costProjectDocument.getId());
  247. switch (costProjectDocumentFile.getPinyin()) {
  248. case "SongDaWenShuWenHao":
  249. costProjectDocumentFile.setDataValue(whNo);
  250. break;
  251. }
  252. if (StringUtils.isNotBlank(costProjectDocumentFile.getTableName()) && StringUtil.isEmpty(costProjectDocumentFile.getDataValue())){
  253. if(StringUtil.isEmpty(costProjectDocumentFile.getWhereValue()) && StringUtil.isNotEmpty(costProjectDocumentFile.getWhereName())){
  254. costProjectDocumentFile.setWhereValue(costProjectApproval.getProjectId());
  255. } else if (costProjectDocument.getDocumentAlias().equals("cbjsgzdg")
  256. &&!costProjectDocument.getDocumentAlias().equals("cbjsjtsyjl")
  257. &&!costProjectDocument.getDocumentAlias().equals("cbshcbyjb1")
  258. &&!costProjectDocument.getDocumentAlias().equals("cbjstqzldjb")) {
  259. String whereValue1 = costProjectDocumentFile.getWhereValue();
  260. String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
  261. String replaced = replace.replace("&", auditedUnit.getUnitId());
  262. costProjectDocumentFile.setWhereValue(replaced);
  263. String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
  264. //获取whereValue字段值
  265. costProjectDocumentFile.setDataValue(colValue);
  266. } else if (StringUtil.isEmpty(costProjectDocumentFile.getWhereName()) && StringUtil.isEmpty(costProjectDocumentFile.getWhereValue())) {
  267. String tableName = costProjectDocumentFile.getTableName();
  268. List<CostProjectTask> taskByProjectId = costProjectTaskManager.findTaskByProjectId(costProjectApproval.getProjectId(), auditedUnit.getUnitId());
  269. if (taskByProjectId!=null && !taskByProjectId.isEmpty()) {
  270. String replace = tableName.replace("?", "'" + taskByProjectId.get(0).getId() + "'");
  271. String colValue = costTemplateFileManager.getColValue2(replace);
  272. costProjectDocumentFile.setDataValue(colValue);
  273. }
  274. } else {
  275. String whereValue1 = costProjectDocumentFile.getWhereValue();
  276. String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
  277. costProjectDocumentFile.setWhereValue(replace);
  278. String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
  279. //获取whereValue字段值
  280. costProjectDocumentFile.setDataValue(colValue);
  281. }
  282. }
  283. });
  284. if (costDocumentTemplate.getIsWh().equals("0")) {
  285. CostDocumentTemplate templateManagerById = costDocumentTemplateManager.getByAlias("sdhz");
  286. if (templateManagerById==null) {
  287. throw new BaseException("未查询到送达回证文书模板信息,请先添加");
  288. }
  289. ArrayList<CostProjectDocumentFile> arrayList = new ArrayList<>();
  290. CostProjectDocument projectDocument = new CostProjectDocument();
  291. BeanUtil.copyProperties(costProjectDocument, projectDocument);
  292. projectDocument.setId(UniqueIdUtil.getSuid());
  293. projectDocument.setCreateBy(user.getAccount());
  294. projectDocument.setCreateTime(LocalDateTime.now());
  295. projectDocument.setDocumentNumber(costProjectDocument.getDocumentNumber());
  296. projectDocument.setElectronicDocumentUrl(templateManagerById.getFileUrl());
  297. if(costDocumentWh!=null){
  298. projectDocument.setDocumentWhId(costDocumentWh.getId());
  299. }
  300. projectDocument.setDocumentId(String.valueOf(templateManagerById.getId()));
  301. projectDocument.setDocumentName(costProjectDocument.getDocumentName()+"-"+templateManagerById.getDocumentName());
  302. projectDocument.setDocumentType(templateManagerById.getType());
  303. projectDocument.setDocumentAlias(templateManagerById.getAlias());
  304. //super.create(projectDocument);
  305. this.save(projectDocument);
  306. List<CostDocumentTemplateFile> documentFileList = costDocumentTemplateFileManager.getDocumentFileList(String.valueOf(templateManagerById.getId()));
  307. documentFileList.forEach(f->{
  308. CostProjectDocumentFile costProjectDocumentFile = new CostProjectDocumentFile();
  309. BeanUtils.copyProperties(f,costProjectDocumentFile);
  310. costProjectDocumentFile.setId(UniqueIdUtil.getUId());
  311. costProjectDocumentFile.setCreateBy(user.getAccount());
  312. costProjectDocumentFile.setCreateTime(LocalDateTime.now());
  313. costProjectDocumentFile.setProjectId(costProjectApproval.getProjectId());
  314. costProjectDocumentFile.setProjectDocumentId(projectDocument.getId());
  315. //costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
  316. switch (f.getPinyin()) {
  317. case "JiaGeZhuGuanBuMenHuoChengBenDiaoChaJiGou":
  318. case "JiaGeZhuGuanBuMenHuoChengBenJianShenJiGou":
  319. costProjectDocumentFile.setDataValue(org.getName());
  320. break;
  321. case "SongDaWenShuMingCheng":
  322. if (costDocumentWh!=null) {
  323. costProjectDocumentFile.setDataValue(costDocumentWh.getWhName());
  324. }
  325. break;
  326. case "SongDaWenShuWenHao":
  327. costProjectDocumentFile.setDataValue(costProjectDocument.getDocumentNumber());
  328. break;
  329. case "ShouSongDaRen":
  330. costProjectDocumentFile.setDataValue(auditedUnit.getContactName());
  331. break;
  332. case "BeiJianShenDanWeiBanGongDiDian":
  333. costProjectDocumentFile.setDataValue(auditedUnit.getAddress());
  334. break;
  335. case "TongZhiSongDaShiJian":
  336. costProjectDocumentFile.setDataValue(DateUtils.format(new Date(),"yyyy-MM-dd"));
  337. break;
  338. case "BeiJianShenDanWeiLianXiRenDianHua":
  339. costProjectDocumentFile.setDataValue(auditedUnit.getContactMobile());
  340. break;
  341. default:
  342. costProjectDocumentFile.setDataValue("");
  343. break;
  344. }
  345. arrayList.add(costProjectDocumentFile);
  346. });
  347. costProjectDocumentFileManager.saveBatch(arrayList);
  348. }
  349. //保存解析出的文件内容
  350. costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
  351. return costProjectDocument.getId();
  352. }
  353. public synchronized String getWH(CostDocumentWh costDocumentWh){
  354. if("incremental".equals(costDocumentWh.getGenerateType())){
  355. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  356. costDocumentWh.setLastGenerateDate(LocalDate.now());
  357. } else if ("daily".equals(costDocumentWh.getGenerateType())) {
  358. boolean b = LocalDate.now().isEqual(costDocumentWh.getLastGenerateDate());
  359. if (!b) {
  360. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  361. costDocumentWh.setLastGenerateDate(LocalDate.now());
  362. }
  363. }else if ("monthly".equals(costDocumentWh.getGenerateType())) {
  364. LocalDate date = LocalDate.now(); // 获取当前日期
  365. YearMonth currentYearMonth = YearMonth.from(date);
  366. if (currentYearMonth.equals(YearMonth.from(costDocumentWh.getLastGenerateDate()))) {
  367. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  368. costDocumentWh.setLastGenerateDate(LocalDate.now());
  369. }
  370. }else if ("yearly".equals(costDocumentWh.getGenerateType())) {
  371. LocalDate date = LocalDate.now(); // 获取当前日期
  372. // 获取当前年份
  373. int currentYear = date.getYear();
  374. if (costDocumentWh.getLastGenerateDate().getYear() == currentYear) {
  375. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  376. costDocumentWh.setLastGenerateDate(LocalDate.now());
  377. }
  378. }
  379. costDocumentWhManager.update(costDocumentWh);
  380. return costDocumentWh.getRulePattern().replace("{prefixText}", costDocumentWh.getPrefixText())
  381. .replace("{year}","【" +costDocumentWh.getYear()+"】").replace("{currentValue}", costDocumentWh.getCurrentValue().toString());
  382. }
  383. @Override
  384. public List<CostProjectDocumentFile> getDocumentFileList(String id) {
  385. CostProjectDocument costProjectDocument = this.get(id);
  386. if(costProjectDocument == null){
  387. throw new BaseException("文书模板不存在");
  388. }
  389. return null;
  390. }
  391. @Override
  392. public void updateProjectDocument(CostProjectDocumentReq req) {
  393. if (ObjectUtil.isEmpty(req.getId())) {
  394. throw new BaseException("请选择要修改的文书");
  395. }
  396. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  397. throw new BaseException("请选择文书模板");
  398. }
  399. if (ObjectUtil.isEmpty(req.getProjectId())) {
  400. throw new BaseException("请选择项目");
  401. }
  402. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  403. throw new BaseException("请选择监审单位");
  404. }
  405. CostProjectDocument selectCostProjectDocument = this.get(req.getId());
  406. if (selectCostProjectDocument == null) {
  407. throw new BaseException("请选择要修改的文书");
  408. }
  409. req.setIsPushed("1");
  410. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  411. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  412. throw new BaseException("文书模板不存在");
  413. }
  414. /*if (costDocumentTemplate.getIsWh().equals("1")) {
  415. throw new BaseException("请填写通知文号");
  416. }*/
  417. req.setDocumentAlias(costDocumentTemplate.getAlias());
  418. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  419. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  420. throw new BaseException("被监审单位不存在");
  421. }
  422. /*CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
  423. if(costDocumentTemplate.getIsWh().equals("0")){
  424. if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  425. throw new BaseException("文书文号不存在");
  426. }
  427. }*/
  428. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  429. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  430. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  431. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  432. /*if (this.count(qw) > 0) {
  433. throw new BaseException("该项目监审单位已存在此文书");
  434. }*/
  435. CostDocumentWh costDocumentWh;
  436. //返回文号
  437. String whNo=selectCostProjectDocument.getDocumentNumber();
  438. /*if (costDocumentTemplate.getIsWh().equals("0")) {
  439. costDocumentWh= costDocumentWhManager.get(req.getDocumentWhId());
  440. if (costDocumentWh == null) {
  441. throw new BaseException("文书文号不存在");
  442. }
  443. //返回文号
  444. whNo = this.getWH(costDocumentWh);
  445. } else {
  446. costDocumentWh = null;
  447. whNo = "";
  448. }*/
  449. selectCostProjectDocument.setDocumentWhId(req.getDocumentWhId());
  450. selectCostProjectDocument.setDocumentId(req.getDocumentId());
  451. selectCostProjectDocument.setEnterpriseId(req.getEnterpriseId());
  452. selectCostProjectDocument.setElectronicDocumentUrl("");
  453. // 类型转换
  454. BeanUtil.copyProperties(req,selectCostProjectDocument);
  455. selectCostProjectDocument.setDocumentNumber(whNo);
  456. super.update(selectCostProjectDocument);
  457. req.getCostProjectDocumentFiles().forEach(f->{
  458. f.setProjectDocumentId(selectCostProjectDocument.getId());
  459. });
  460. costProjectDocumentFileManager.updateBatchById(req.getCostProjectDocumentFiles());
  461. }
  462. @Override
  463. public List<CostProjectDocument> getListByProjectId(String projectId) {
  464. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  465. qw.eq(CostProjectDocument::getProjectId, projectId);
  466. List<CostProjectDocument> list = this.list(qw);
  467. if (ObjectUtil.isEmpty(list)) {
  468. return new ArrayList<>();
  469. }
  470. return list;
  471. }
  472. @Override
  473. public CostProjectDocumentResp getByProjectId(String projectId){
  474. //查询监审文书
  475. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  476. qw.eq(CostProjectDocument::getProjectId, projectId);
  477. qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
  478. CostProjectDocument costProjectDocument = this.getOne(qw);
  479. //转换为返回类型
  480. CostProjectDocumentResp costProjectDocumentResp = BeanUtil.copyProperties(costProjectDocument, CostProjectDocumentResp.class);
  481. //查询文书下的文书内容
  482. LambdaQueryWrapper<CostProjectDocumentFile> wrapper = new LambdaQueryWrapper<>();
  483. wrapper.eq(CostProjectDocumentFile::getProjectId, costProjectDocument.getProjectId());
  484. //获取文件内容返回
  485. costProjectDocumentResp.setCostProjectDocumentFiles(costProjectDocumentFileManager.list(wrapper));
  486. CostDocumentTemplate costDocumentTemplate = costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  487. costProjectDocumentResp.setFullPath(EipConfig.getImgUrl()+costDocumentTemplate.getFileUrl());
  488. return costProjectDocumentResp;
  489. }
  490. @Override
  491. public String createDocument(String id) {
  492. CostProjectDocument costProjectDocument = this.getDetail(id);
  493. if (StringUtil.isEmpty(costProjectDocument.getActUrl())) {
  494. List<CostProjectDocumentFile> list = costProjectDocumentFileManager.getCostProjectDocumentFiles(costProjectDocument.getProjectId(),costProjectDocument.getDocumentId());
  495. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  496. //生成文书
  497. Map<String,String> map = new HashMap<>();
  498. list.stream().forEach(p->{
  499. map.put("{"+p.getOriginalText()+"}", HtmlUtils.stripHtmlFast(p.getDataValue()) );
  500. });
  501. //先处理一种文件
  502. String templatePath = costDocumentTemplate.getFileUrl().replace(BaseConstant.RESOURCE_PREFIX,"");
  503. templatePath = EipConfig.getProfile()+templatePath;
  504. String fileExtension = FileUploadUtil.getFileExtension(costDocumentTemplate.getFileUrl());
  505. String fileName = FileUploadUtil.generateFileName(costDocumentTemplate.getDocumentName()+"."+fileExtension);
  506. String outputPath = FileUploadUtil.generateSavePath(EipConfig.getUploadPath(), fileName, fileExtension);
  507. try (FileInputStream fis = new FileInputStream(templatePath);
  508. XWPFDocument document = new XWPFDocument(fis);
  509. FileOutputStream fos = FileUtils.createFileOutputStream(outputPath);) {
  510. if (costProjectDocument.getDocumentAlias().equals("cbjstqzldjb")) {
  511. List<CostProjectTaskEvidence> costProjectTaskEvidences= costProjectTaskEvidenceManager.findEvidenceListByTaskIds(costProjectDocument.getProjectId(),costProjectDocument.getEnterpriseId());
  512. if (!costProjectTaskEvidences.isEmpty()) {
  513. List<CompleteTemplateProcessor.TableRowData> mapList = costProjectTaskEvidences.stream().map(c -> {
  514. CompleteTemplateProcessor.TableRowData tableRowData = new CompleteTemplateProcessor.TableRowData();
  515. tableRowData.setDocumentName(c.getMaterialName());
  516. tableRowData.setRemark(c.getRemark());
  517. tableRowData.setPageCount(c.getPageCount());
  518. return tableRowData;
  519. }).collect(Collectors.toList());
  520. AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
  521. CompleteTemplateProcessor.processTemplateComplete(document,auditedUnit.getUnitName(),mapList,DateUtils.format(new Date(),ISO8601_DATE_PATTERN));
  522. }
  523. } else if (costProjectDocument.getDocumentAlias().equals("zfdjcbjsjlbg")) {
  524. CostProjectApproval costProjectApproval = costProjectApprovalManager.get(costProjectDocument.getProjectId());
  525. List<CostProjectTask> taskByProjectId = costProjectTaskManager.findTaskByProjectId(costProjectApproval.getProjectId(), costProjectDocument.getEnterpriseId());
  526. List<Map<String,Object>> maps= costTemplateFileManager.getSurveyTemplate(taskByProjectId.get(0).getId());
  527. CostDataUtil costDataUtil = new CostDataUtil();
  528. Map<String, Object> map1 = costDataUtil.convertToCostFormat(maps);
  529. @SuppressWarnings("unchecked")
  530. List<String> years = (List<String>)map1.get("years");
  531. @SuppressWarnings("unchecked")
  532. List<Map<String, Object>> costItems = (List<Map<String, Object>>) map1.get("costItems");
  533. // 处理文档
  534. RobustComplexDocumentProcessor.processDocumentWithMaps(
  535. document,
  536. map,
  537. years,
  538. costItems
  539. );
  540. } else {
  541. SmartTemplateWriter.writeToTemplate(document,map);
  542. }
  543. document.write(fos);
  544. } catch (IOException e) {
  545. throw new RuntimeException("处理Word文档时出错", e);
  546. }
  547. costProjectDocument.setActUrl(EipConfig.getImgUrl() + FileUploadUtil.getPathFileName(outputPath, fileName));
  548. }
  549. return costProjectDocument.getActUrl() ;
  550. }
  551. @Override
  552. public void feedbackDocumentUrl(CostProjectDocumentReq req) {
  553. if (ObjectUtil.isEmpty(req.getId())) {
  554. throw new BaseException("请选择要修改的文书");
  555. }
  556. if (ObjectUtil.isEmpty(req.getFeedbackDocumentUrl())) {
  557. throw new BaseException("被监审单位反馈资料附件ID集合不能为空");
  558. }
  559. CostProjectDocument projectDocument = this.get(req.getId());
  560. if(projectDocument==null){
  561. throw new BaseException("根据id未查询到实体信息");
  562. }
  563. projectDocument.setFeedbackDocumentUrl(req.getFeedbackDocumentUrl());
  564. projectDocument.setFeedbackTime(LocalDateTime.now());
  565. this.update(projectDocument);
  566. }
  567. }