CostProjectDocumentManagerImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 (req.getDocumentType() != null) {
  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. qw.in(CostProjectDocument::getEnterpriseId, collected);
  130. } else if (req.getPermissionType().equals(2)) {
  131. IUser iUser = ContextUtil.getCurrentUser();
  132. User user = userService.getByAccount(iUser.getAccount());
  133. qw.eq(CostProjectDocument::getCreateBy, user.getAccount());
  134. }
  135. IPage<CostProjectDocument> page = new Page<>(req.getPageNum(), req.getPageSize());
  136. return this.page(page, qw);
  137. }
  138. // @Override
  139. // public void create(CostProjectDocument costProjectDocument) {
  140. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentId())) {
  141. // throw new BaseException("请选择文书模板");
  142. // }
  143. // if (ObjectUtil.isEmpty(costProjectDocument.getProjectId())) {
  144. // throw new BaseException("请选择项目");
  145. // }
  146. // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentNumber())) {
  147. // throw new BaseException("请填写通知文号");
  148. // }
  149. // if (ObjectUtil.isEmpty(costProjectDocument.getEnterpriseId())) {
  150. // throw new BaseException("请选择监审单位");
  151. // }
  152. // costProjectDocument.setGenerateTime(LocalDateTime.now());
  153. // costProjectDocument.setIsPushed("1");
  154. //
  155. // CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  156. // if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  157. // throw new BaseException("文书模板不存在");
  158. // }
  159. // costProjectDocument.setDocumentAlias(costDocumentTemplate.getAlias());
  160. // AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
  161. // if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  162. // throw new BaseException("被监审单位不存在");
  163. // }
  164. // CostDocumentWh costDocumentWh = costDocumentWhManager.get(costProjectDocument.getDocumentWhId());
  165. // if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  166. // throw new BaseException("文书文号不存在");
  167. // }
  168. //
  169. // LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  170. // qw.eq(CostProjectDocument::getProjectId, costProjectDocument.getProjectId());
  171. // qw.eq(CostProjectDocument::getDocumentId, costProjectDocument.getDocumentId());
  172. // qw.eq(CostProjectDocument::getEnterpriseId, costProjectDocument.getEnterpriseId());
  173. // if (this.count(qw) > 0) {
  174. // throw new BaseException("该项目监审单位已存在此文书");
  175. // }
  176. // super.create(costProjectDocument);
  177. //
  178. //
  179. // }
  180. @Override
  181. @Transactional
  182. public String create(CostProjectDocumentReq req) throws Exception {
  183. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  184. throw new BaseException("请选择文书模板");
  185. }
  186. if (ObjectUtil.isEmpty(req.getProjectId())) {
  187. throw new BaseException("请选择项目");
  188. }
  189. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  190. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  191. throw new BaseException("文书模板不存在");
  192. }
  193. if (costDocumentTemplate.getIsWh().equals("0")) {
  194. throw new BaseException("请填写通知文号");
  195. }
  196. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  197. throw new BaseException("请选择监审单位");
  198. }
  199. req.setGenerateTime(LocalDateTime.now());
  200. req.setIsPushed("1");
  201. req.setDocumentAlias(costDocumentTemplate.getAlias());
  202. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  203. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  204. throw new BaseException("被监审单位不存在");
  205. }
  206. CostDocumentWh costDocumentWh;
  207. //返回文号
  208. String whNo;
  209. if (costDocumentTemplate.getIsWh().equals("0")) {
  210. costDocumentWh= costDocumentWhManager.get(req.getDocumentWhId());
  211. if (costDocumentWh == null) {
  212. throw new BaseException("文书文号不存在");
  213. }
  214. //返回文号
  215. whNo = this.getWH(costDocumentWh);
  216. } else {
  217. costDocumentWh = null;
  218. whNo = "";
  219. }
  220. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  221. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  222. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  223. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  224. if (this.count(qw) > 0) {
  225. throw new BaseException("该项目监审单位已存在此文书");
  226. }
  227. IUser iUser = ContextUtil.getCurrentUser();
  228. User user = userService.getByAccount(iUser.getAccount());
  229. CostProjectApproval costProjectApproval = costProjectApprovalManager.get(req.getProjectId());
  230. Org org = orgManager.getById(costProjectApproval.getOrgId());
  231. //类型转换
  232. CostProjectDocument costProjectDocument = new CostProjectDocument();
  233. BeanUtil.copyProperties(req, costProjectDocument);
  234. costProjectDocument.setDocumentNumber(whNo);
  235. costProjectDocument.setDocumentName(costDocumentTemplate.getDocumentName());
  236. costProjectDocument.setCreateBy(user.getCreateBy());
  237. costProjectDocument.setDocumentType(costDocumentTemplate.getType());
  238. costProjectDocument.setProjectId(costProjectApproval.getProjectId());
  239. super.create(costProjectDocument);
  240. //文件关联信息赋值
  241. req.getCostProjectDocumentFiles().forEach(costProjectDocumentFile -> {
  242. costProjectDocumentFile.setDocumentId(costProjectDocument.getDocumentId());
  243. costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
  244. costProjectDocumentFile.setProjectDocumentId(costProjectDocument.getId());
  245. switch (costProjectDocumentFile.getPinyin()) {
  246. case "SongDaWenShuWenHao":
  247. costProjectDocumentFile.setDataValue(whNo);
  248. break;
  249. }
  250. if (StringUtils.isNotBlank(costProjectDocumentFile.getTableName())){
  251. if(StringUtil.isEmpty(costProjectDocumentFile.getWhereValue()) && StringUtil.isNotEmpty(costProjectDocumentFile.getWhereName())){
  252. costProjectDocumentFile.setWhereValue(costProjectApproval.getProjectId());
  253. } else if (costProjectDocument.getDocumentAlias().equals("cbjsgzdg")
  254. &&!costProjectDocument.getDocumentAlias().equals("cbjsjtsyjl")
  255. &&!costProjectDocument.getDocumentAlias().equals("cbshcbyjb1")
  256. &&!costProjectDocument.getDocumentAlias().equals("cbjstqzldjb")) {
  257. String whereValue1 = costProjectDocumentFile.getWhereValue();
  258. String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
  259. String replaced = replace.replace("&", auditedUnit.getUnitId());
  260. costProjectDocumentFile.setWhereValue(replaced);
  261. String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
  262. //获取whereValue字段值
  263. costProjectDocumentFile.setDataValue(colValue);
  264. } else if (StringUtil.isEmpty(costProjectDocumentFile.getWhereName()) && StringUtil.isEmpty(costProjectDocumentFile.getWhereValue())) {
  265. String tableName = costProjectDocumentFile.getTableName();
  266. List<CostProjectTask> taskByProjectId = costProjectTaskManager.findTaskByProjectId(costProjectApproval.getProjectId(), auditedUnit.getUnitId());
  267. if (taskByProjectId!=null && !taskByProjectId.isEmpty()) {
  268. String replace = tableName.replace("?", "'" + taskByProjectId.get(0).getId() + "'");
  269. String colValue = costTemplateFileManager.getColValue2(replace);
  270. costProjectDocumentFile.setDataValue(colValue);
  271. }
  272. } else {
  273. String whereValue1 = costProjectDocumentFile.getWhereValue();
  274. String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
  275. costProjectDocumentFile.setWhereValue(replace);
  276. String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
  277. //获取whereValue字段值
  278. costProjectDocumentFile.setDataValue(colValue);
  279. }
  280. }
  281. });
  282. if (costDocumentTemplate.getIsWh().equals("0")) {
  283. CostDocumentTemplate templateManagerById = costDocumentTemplateManager.getByAlias("sdhz");
  284. if (templateManagerById==null) {
  285. throw new BaseException("未查询到送达回证文书模板信息,请先添加");
  286. }
  287. ArrayList<CostProjectDocumentFile> arrayList = new ArrayList<>();
  288. CostProjectDocument projectDocument = new CostProjectDocument();
  289. BeanUtil.copyProperties(costProjectDocument, projectDocument);
  290. projectDocument.setId(UniqueIdUtil.getSuid());
  291. projectDocument.setCreateBy(user.getAccount());
  292. projectDocument.setCreateTime(LocalDateTime.now());
  293. projectDocument.setDocumentNumber(costProjectDocument.getDocumentNumber());
  294. projectDocument.setElectronicDocumentUrl(templateManagerById.getFileUrl());
  295. if(costDocumentWh!=null){
  296. projectDocument.setDocumentWhId(costDocumentWh.getId());
  297. }
  298. projectDocument.setDocumentId(String.valueOf(templateManagerById.getId()));
  299. projectDocument.setDocumentName(costProjectDocument.getDocumentName()+"-"+templateManagerById.getDocumentName());
  300. projectDocument.setDocumentType(templateManagerById.getType());
  301. projectDocument.setDocumentAlias(templateManagerById.getAlias());
  302. //super.create(projectDocument);
  303. this.save(projectDocument);
  304. List<CostDocumentTemplateFile> documentFileList = costDocumentTemplateFileManager.getDocumentFileList(String.valueOf(templateManagerById.getId()));
  305. documentFileList.forEach(f->{
  306. CostProjectDocumentFile costProjectDocumentFile = new CostProjectDocumentFile();
  307. BeanUtils.copyProperties(f,costProjectDocumentFile);
  308. costProjectDocumentFile.setId(UniqueIdUtil.getUId());
  309. costProjectDocumentFile.setCreateBy(user.getAccount());
  310. costProjectDocumentFile.setCreateTime(LocalDateTime.now());
  311. costProjectDocumentFile.setProjectId(costProjectApproval.getProjectId());
  312. costProjectDocumentFile.setProjectDocumentId(projectDocument.getId());
  313. //costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
  314. switch (f.getPinyin()) {
  315. case "JiaGeZhuGuanBuMenHuoChengBenJianShenJiGou":
  316. costProjectDocumentFile.setDataValue(org.getName());
  317. break;
  318. case "SongDaWenShuMingCheng":
  319. if (costDocumentWh!=null) {
  320. costProjectDocumentFile.setDataValue(costDocumentWh.getWhName());
  321. }
  322. break;
  323. case "SongDaWenShuWenHao":
  324. costProjectDocumentFile.setDataValue(costProjectDocument.getDocumentNumber());
  325. break;
  326. case "ShouSongDaRen":
  327. costProjectDocumentFile.setDataValue(auditedUnit.getContactName());
  328. break;
  329. case "BeiJianShenDanWeiBanGongDiDian":
  330. costProjectDocumentFile.setDataValue(auditedUnit.getAddress());
  331. break;
  332. case "TongZhiSongDaShiJian":
  333. costProjectDocumentFile.setDataValue(DateUtils.format(new Date(),"yyyy-MM-dd"));
  334. break;
  335. case "BeiJianShenDanWeiLianXiRenDianHua":
  336. costProjectDocumentFile.setDataValue(auditedUnit.getContactMobile());
  337. break;
  338. default:
  339. costProjectDocumentFile.setDataValue("");
  340. break;
  341. }
  342. arrayList.add(costProjectDocumentFile);
  343. });
  344. costProjectDocumentFileManager.saveBatch(arrayList);
  345. }
  346. //保存解析出的文件内容
  347. costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
  348. return costProjectDocument.getId();
  349. }
  350. public synchronized String getWH(CostDocumentWh costDocumentWh){
  351. if("incremental".equals(costDocumentWh.getGenerateType())){
  352. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  353. costDocumentWh.setLastGenerateDate(LocalDate.now());
  354. } else if ("daily".equals(costDocumentWh.getGenerateType())) {
  355. boolean b = LocalDate.now().isEqual(costDocumentWh.getLastGenerateDate());
  356. if (!b) {
  357. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  358. costDocumentWh.setLastGenerateDate(LocalDate.now());
  359. }
  360. }else if ("monthly".equals(costDocumentWh.getGenerateType())) {
  361. LocalDate date = LocalDate.now(); // 获取当前日期
  362. YearMonth currentYearMonth = YearMonth.from(date);
  363. if (currentYearMonth.equals(YearMonth.from(costDocumentWh.getLastGenerateDate()))) {
  364. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  365. costDocumentWh.setLastGenerateDate(LocalDate.now());
  366. }
  367. }else if ("yearly".equals(costDocumentWh.getGenerateType())) {
  368. LocalDate date = LocalDate.now(); // 获取当前日期
  369. // 获取当前年份
  370. int currentYear = date.getYear();
  371. if (costDocumentWh.getLastGenerateDate().getYear() == currentYear) {
  372. costDocumentWh.setCurrentValue(costDocumentWh.getCurrentValue()+1);
  373. costDocumentWh.setLastGenerateDate(LocalDate.now());
  374. }
  375. }
  376. costDocumentWhManager.update(costDocumentWh);
  377. return costDocumentWh.getRulePattern().replace("{prefixText}", costDocumentWh.getPrefixText())
  378. .replace("{year}","【" +costDocumentWh.getYear()+"】").replace("{currentValue}", costDocumentWh.getCurrentValue().toString());
  379. }
  380. @Override
  381. public List<CostProjectDocumentFile> getDocumentFileList(String id) {
  382. CostProjectDocument costProjectDocument = this.get(id);
  383. if(costProjectDocument == null){
  384. throw new BaseException("文书模板不存在");
  385. }
  386. return null;
  387. }
  388. @Override
  389. public void updateProjectDocument(CostProjectDocumentReq req) {
  390. if (ObjectUtil.isEmpty(req.getId())) {
  391. throw new BaseException("请选择要修改的文书");
  392. }
  393. if (ObjectUtil.isEmpty(req.getDocumentId())) {
  394. throw new BaseException("请选择文书模板");
  395. }
  396. if (ObjectUtil.isEmpty(req.getProjectId())) {
  397. throw new BaseException("请选择项目");
  398. }
  399. if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
  400. throw new BaseException("请选择监审单位");
  401. }
  402. CostProjectDocument selectCostProjectDocument = this.get(req.getId());
  403. if (selectCostProjectDocument == null) {
  404. throw new BaseException("请选择要修改的文书");
  405. }
  406. req.setIsPushed("1");
  407. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
  408. if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
  409. throw new BaseException("文书模板不存在");
  410. }
  411. if (costDocumentTemplate.getIsWh().equals("1")) {
  412. throw new BaseException("请填写通知文号");
  413. }
  414. req.setDocumentAlias(costDocumentTemplate.getAlias());
  415. AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
  416. if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
  417. throw new BaseException("被监审单位不存在");
  418. }
  419. CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
  420. if(costDocumentTemplate.getIsWh().equals("1")){
  421. if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
  422. throw new BaseException("文书文号不存在");
  423. }
  424. }
  425. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  426. qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
  427. qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
  428. qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
  429. /*if (this.count(qw) > 0) {
  430. throw new BaseException("该项目监审单位已存在此文书");
  431. }*/
  432. selectCostProjectDocument.setDocumentWhId(req.getDocumentWhId());
  433. selectCostProjectDocument.setDocumentId(req.getDocumentId());
  434. selectCostProjectDocument.setEnterpriseId(req.getEnterpriseId());
  435. selectCostProjectDocument.setElectronicDocumentUrl("");
  436. // 类型转换
  437. BeanUtil.copyProperties(req,selectCostProjectDocument);
  438. super.update(selectCostProjectDocument);
  439. req.getCostProjectDocumentFiles().forEach(f->{
  440. f.setProjectDocumentId(selectCostProjectDocument.getId());
  441. });
  442. costProjectDocumentFileManager.updateBatchById(req.getCostProjectDocumentFiles());
  443. }
  444. @Override
  445. public List<CostProjectDocument> getListByProjectId(String projectId) {
  446. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  447. qw.eq(CostProjectDocument::getProjectId, projectId);
  448. List<CostProjectDocument> list = this.list(qw);
  449. if (ObjectUtil.isEmpty(list)) {
  450. return new ArrayList<>();
  451. }
  452. return list;
  453. }
  454. @Override
  455. public CostProjectDocumentResp getByProjectId(String projectId){
  456. //查询监审文书
  457. LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
  458. qw.eq(CostProjectDocument::getProjectId, projectId);
  459. qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
  460. CostProjectDocument costProjectDocument = this.getOne(qw);
  461. //转换为返回类型
  462. CostProjectDocumentResp costProjectDocumentResp = BeanUtil.copyProperties(costProjectDocument, CostProjectDocumentResp.class);
  463. //查询文书下的文书内容
  464. LambdaQueryWrapper<CostProjectDocumentFile> wrapper = new LambdaQueryWrapper<>();
  465. wrapper.eq(CostProjectDocumentFile::getProjectId, costProjectDocument.getProjectId());
  466. //获取文件内容返回
  467. costProjectDocumentResp.setCostProjectDocumentFiles(costProjectDocumentFileManager.list(wrapper));
  468. CostDocumentTemplate costDocumentTemplate = costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  469. costProjectDocumentResp.setFullPath(EipConfig.getImgUrl()+costDocumentTemplate.getFileUrl());
  470. return costProjectDocumentResp;
  471. }
  472. @Override
  473. public String createDocument(String id) {
  474. CostProjectDocument costProjectDocument = this.getDetail(id);
  475. List<CostProjectDocumentFile> list = costProjectDocumentFileManager.getCostProjectDocumentFiles(costProjectDocument.getProjectId(),costProjectDocument.getDocumentId());
  476. CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
  477. //生成文书
  478. Map<String,String> map = new HashMap<>();
  479. list.stream().forEach(p->{
  480. map.put("{"+p.getOriginalText()+"}", HtmlUtils.stripHtmlFast(p.getDataValue()) );
  481. });
  482. //先处理一种文件
  483. String templatePath = costDocumentTemplate.getFileUrl().replace(BaseConstant.RESOURCE_PREFIX,"");
  484. templatePath = EipConfig.getProfile()+templatePath;
  485. String fileExtension = FileUploadUtil.getFileExtension(costDocumentTemplate.getFileUrl());
  486. String fileName = FileUploadUtil.generateFileName(costDocumentTemplate.getDocumentName()+"."+fileExtension);
  487. String outputPath = FileUploadUtil.generateSavePath(EipConfig.getUploadPath(), fileName, fileExtension);
  488. try (FileInputStream fis = new FileInputStream(templatePath);
  489. XWPFDocument document = new XWPFDocument(fis);
  490. FileOutputStream fos = FileUtils.createFileOutputStream(outputPath);) {
  491. if (costProjectDocument.getDocumentAlias().equals("cbjstqzldjb")) {
  492. List<CostProjectTaskEvidence> costProjectTaskEvidences= costProjectTaskEvidenceManager.findEvidenceListByTaskIds(costProjectDocument.getProjectId(),costProjectDocument.getEnterpriseId());
  493. if (!costProjectTaskEvidences.isEmpty()) {
  494. List<CompleteTemplateProcessor.TableRowData> mapList = costProjectTaskEvidences.stream().map(c -> {
  495. CompleteTemplateProcessor.TableRowData tableRowData = new CompleteTemplateProcessor.TableRowData();
  496. tableRowData.setDocumentName(c.getMaterialName());
  497. tableRowData.setRemark(c.getRemark());
  498. tableRowData.setPageCount(c.getPageCount());
  499. return tableRowData;
  500. }).collect(Collectors.toList());
  501. AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
  502. CompleteTemplateProcessor.processTemplateComplete(document,auditedUnit.getUnitName(),mapList,DateUtils.format(new Date(),ISO8601_DATE_PATTERN));
  503. }
  504. } else if (costProjectDocument.getDocumentAlias().equals("zfdjcbjsjlbg")) {
  505. CostProjectApproval costProjectApproval = costProjectApprovalManager.get(costProjectDocument.getProjectId());
  506. List<CostProjectTask> taskByProjectId = costProjectTaskManager.findTaskByProjectId(costProjectApproval.getProjectId(), costProjectDocument.getEnterpriseId());
  507. List<Map<String,Object>> maps= costTemplateFileManager.getSurveyTemplate(taskByProjectId.get(0).getId());
  508. CostDataUtil costDataUtil = new CostDataUtil();
  509. Map<String, Object> map1 = costDataUtil.convertToCostFormat(maps);
  510. @SuppressWarnings("unchecked")
  511. List<String> years = (List<String>)map1.get("years");
  512. @SuppressWarnings("unchecked")
  513. List<Map<String, Object>> costItems = (List<Map<String, Object>>) map1.get("costItems");
  514. // 处理文档
  515. RobustComplexDocumentProcessor.processDocumentWithMaps(
  516. document,
  517. map,
  518. years,
  519. costItems
  520. );
  521. } else {
  522. SmartTemplateWriter.writeToTemplate(document,map);
  523. }
  524. document.write(fos);
  525. } catch (IOException e) {
  526. throw new RuntimeException("处理Word文档时出错", e);
  527. }
  528. return EipConfig.getImgUrl()+FileUploadUtil.getPathFileName(outputPath,fileName);
  529. }
  530. @Override
  531. public void feedbackDocumentUrl(CostProjectDocumentReq req) {
  532. if (ObjectUtil.isEmpty(req.getId())) {
  533. throw new BaseException("请选择要修改的文书");
  534. }
  535. if (ObjectUtil.isEmpty(req.getFeedbackDocumentUrl())) {
  536. throw new BaseException("被监审单位反馈资料附件ID集合不能为空");
  537. }
  538. CostProjectDocument projectDocument = this.get(req.getId());
  539. if(projectDocument==null){
  540. throw new BaseException("根据id未查询到实体信息");
  541. }
  542. projectDocument.setFeedbackDocumentUrl(req.getFeedbackDocumentUrl());
  543. projectDocument.setFeedbackTime(LocalDateTime.now());
  544. this.update(projectDocument);
  545. }
  546. }