CostProjectDocumentManagerImpl.java 31 KB

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