| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- package com.hotent.project.manager.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.ObjectUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.hotent.base.util.StringUtil;
- import com.hotent.base.util.UniqueIdUtil;
- import com.hotent.baseInfo.manager.AuditedUnitManager;
- import com.hotent.baseInfo.manager.CostDocumentTemplateFileManager;
- import com.hotent.baseInfo.manager.CostDocumentTemplateManager;
- import com.hotent.baseInfo.manager.CostDocumentWhManager;
- import com.hotent.baseInfo.model.AuditedUnit;
- import com.hotent.baseInfo.model.CostDocumentTemplate;
- import com.hotent.baseInfo.model.CostDocumentTemplateFile;
- import com.hotent.baseInfo.model.CostDocumentWh;
- import com.hotent.config.EipConfig;
- import com.hotent.constant.BaseConstant;
- import com.hotent.project.manager.CostProjectApprovalManager;
- import com.hotent.project.manager.CostProjectDocumentFileManager;
- import com.hotent.project.model.CostProjectApproval;
- import com.hotent.project.model.CostProjectDocument;
- import com.hotent.project.dao.CostProjectDocumentDao;
- import com.hotent.project.manager.CostProjectDocumentManager;
- import com.hotent.base.manager.impl.BaseManagerImpl;
- import com.hotent.project.model.CostProjectDocumentFile;
- import com.hotent.project.req.CostProjectDocumentPageReq;
- import com.hotent.project.req.CostProjectDocumentReq;
- import com.hotent.project.resp.CostProjectDocumentResp;
- import com.hotent.uc.api.model.IUser;
- import com.hotent.uc.exception.BaseException;
- import com.hotent.uc.manager.UserManager;
- import com.hotent.uc.model.User;
- import com.hotent.uc.util.ContextUtil;
- import com.hotent.util.wordexcelutils.DocumentProcessor;
- import org.apache.commons.lang.StringUtils;
- import org.apache.tools.ant.util.DateUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.time.LocalDateTime;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.hotent.util.FileUploadUtil;
- /**
- * 监审项目文书表 服务实现类
- *
- * @author 超级管理员
- * @company 山西清众科技股份有限公司
- * @since 2025-09-26
- */
- @Service
- public class CostProjectDocumentManagerImpl extends BaseManagerImpl<CostProjectDocumentDao, CostProjectDocument> implements CostProjectDocumentManager {
- @Autowired
- private CostProjectDocumentFileManager costProjectDocumentFileManager;
- @Autowired
- private CostDocumentTemplateManager costDocumentTemplateManager;
- @Autowired
- private AuditedUnitManager auditedUnitManager;
- @Autowired
- private CostDocumentTemplateFileManager costDocumentTemplateFileManager;
- @Autowired
- private CostDocumentWhManager costDocumentWhManager;
- @Autowired
- private CostProjectApprovalManager costProjectApprovalManager;
- @Autowired
- private UserManager userService;
- @Autowired
- private CostDocumentTemplateFileManager costTemplateFileManager;
-
- private static final HashMap<String, Boolean> whMap = new HashMap<>();
- @Override
- public CostProjectDocument getDetail(String id) {
- CostProjectDocument costProjectDocument = this.get(id);
- return costProjectDocument;
- }
- @Override
- public void deleteByIds(List<String> ids) {
- List<CostProjectDocument> costProjectDocuments = this.listByIds(ids);
- if (costProjectDocuments!=null){
- costProjectDocuments.forEach(item -> {
- //逻辑删除
- item.setIsDeleted( BaseConstant.DELETE_FLAG);
- });
- this.updateBatchById(costProjectDocuments);
- }
- }
- @Override
- @Transactional
- public void createOrUpdate(CostProjectDocument costProjectDocument) {
- //新建或更新
- this.saveOrUpdate(costProjectDocument);
- }
- @Override
- public IPage<CostProjectDocument> pageList(CostProjectDocumentPageReq req) {
- LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- if (req.getDocumentType() != null) {
- // LambdaQueryWrapper<CostDocumentTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- // lambdaQueryWrapper.eq(CostDocumentTemplate::getId, req.getDocumentType());
- // lambdaQueryWrapper.eq(CostDocumentTemplate::getIsWh, "0");
- qw.eq(CostProjectDocument::getDocumentType, req.getDocumentType());
- }
- qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
- IPage<CostProjectDocument> page = new Page<>(req.getPageNum(), req.getPageSize());
- return this.page(page, qw);
- }
- // @Override
- // public void create(CostProjectDocument costProjectDocument) {
- // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentId())) {
- // throw new BaseException("请选择文书模板");
- // }
- // if (ObjectUtil.isEmpty(costProjectDocument.getProjectId())) {
- // throw new BaseException("请选择项目");
- // }
- // if (ObjectUtil.isEmpty(costProjectDocument.getDocumentNumber())) {
- // throw new BaseException("请填写通知文号");
- // }
- // if (ObjectUtil.isEmpty(costProjectDocument.getEnterpriseId())) {
- // throw new BaseException("请选择监审单位");
- // }
- // costProjectDocument.setGenerateTime(LocalDateTime.now());
- // costProjectDocument.setIsPushed("1");
- //
- // CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
- // if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
- // throw new BaseException("文书模板不存在");
- // }
- // costProjectDocument.setDocumentAlias(costDocumentTemplate.getAlias());
- // AuditedUnit auditedUnit = auditedUnitManager.get(costProjectDocument.getEnterpriseId());
- // if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
- // throw new BaseException("被监审单位不存在");
- // }
- // CostDocumentWh costDocumentWh = costDocumentWhManager.get(costProjectDocument.getDocumentWhId());
- // if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
- // throw new BaseException("文书文号不存在");
- // }
- //
- // LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- // qw.eq(CostProjectDocument::getProjectId, costProjectDocument.getProjectId());
- // qw.eq(CostProjectDocument::getDocumentId, costProjectDocument.getDocumentId());
- // qw.eq(CostProjectDocument::getEnterpriseId, costProjectDocument.getEnterpriseId());
- // if (this.count(qw) > 0) {
- // throw new BaseException("该项目监审单位已存在此文书");
- // }
- // super.create(costProjectDocument);
- //
- //
- // }
- @Override
- @Transactional
- public void create(CostProjectDocumentReq req) throws Exception {
- if (ObjectUtil.isEmpty(req.getDocumentId())) {
- throw new BaseException("请选择文书模板");
- }
- if (ObjectUtil.isEmpty(req.getProjectId())) {
- throw new BaseException("请选择项目");
- }
- if (ObjectUtil.isEmpty(req.getDocumentNumber())) {
- throw new BaseException("请填写通知文号");
- }
- if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
- throw new BaseException("请选择监审单位");
- }
- req.setGenerateTime(LocalDateTime.now());
- req.setIsPushed("1");
- CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
- if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
- throw new BaseException("文书模板不存在");
- }
- req.setDocumentAlias(costDocumentTemplate.getAlias());
- AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
- if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
- throw new BaseException("被监审单位不存在");
- }
- CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
- if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
- throw new BaseException("文书文号不存在");
- }
- //返回文号
- String whNo = this.getWH(costDocumentWh);
- //校验文号唯一性
- Boolean b = whMap.get(whNo);
- if (b==null || !b) {
- whMap.put(whNo,true);
- }else {
- throw new BaseException("【"+whNo+"】文号已存在请重新添加");
- }
- LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
- qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
- qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
- if (this.count(qw) > 0) {
- throw new BaseException("该项目监审单位已存在此文书");
- }
- CostProjectApproval costProjectApproval = costProjectApprovalManager.get(req.getProjectId());
- //类型转换
- CostProjectDocument costProjectDocument = new CostProjectDocument();
- BeanUtil.copyProperties(req, costProjectDocument);
- costProjectDocument.setDocumentNumber(whNo);
- costProjectDocument.setDocumentName(costDocumentTemplate.getDocumentName());
- costProjectDocument.setDocumentType(costDocumentTemplate.getType());
- costProjectDocument.setProjectId(costProjectApproval.getProjectId());
- super.create(costProjectDocument);
- /*if (costProjectDocument.getDocumentAlias().equals("cbjstzs")) {
- CostDocumentTemplate templateManagerById = costDocumentTemplateManager.getByAlias("sdhz");
- if (templateManagerById==null) {
- throw new BaseException("未查询到送达回证文书模板信息,请先添加");
- }
- IUser iUser = ContextUtil.getCurrentUser();
- User user = userService.getByAccount(iUser.getAccount());
- ArrayList<CostProjectDocumentFile> arrayList = new ArrayList<>();
- CostProjectDocument projectDocument = new CostProjectDocument();
- BeanUtil.copyProperties(costProjectDocument, projectDocument);
- projectDocument.setId(UniqueIdUtil.getSuid());
- projectDocument.setCreateBy(user.getAccount());
- projectDocument.setCreateTime(LocalDateTime.now());
- QueryWrapper<CostDocumentWh> wrapper = new QueryWrapper<>();
- wrapper.eq("wh_type","187");
- List<CostDocumentWh> list = costDocumentWhManager.list(wrapper);
- if (list == null || list.isEmpty()) {
- throw new BaseException("文书文号不存在");
- }
- CostDocumentWh costDocument = list.get(0);
- projectDocument.setDocumentNumber(costDocument.getRulePattern().replace("{prefixText}", costDocument.getPrefixText())
- .replace("{year}", costDocument.getYear()).replace("{currentValue}", costDocument.getCurrentValue().toString()));
- projectDocument.setElectronicDocumentUrl(templateManagerById.getFileUrl());
- projectDocument.setDocumentWhId(costDocument.getId());
- projectDocument.setDocumentId(String.valueOf(templateManagerById.getId()));
- projectDocument.setDocumentName(templateManagerById.getDocumentName());
- projectDocument.setDocumentType(templateManagerById.getType());
- projectDocument.setDocumentAlias(templateManagerById.getAlias());
- //super.create(projectDocument);
- this.save(projectDocument);
- List<CostDocumentTemplateFile> documentFileList = costDocumentTemplateFileManager.getDocumentFileList(String.valueOf(templateManagerById.getId()));
- documentFileList.forEach(f->{
- CostProjectDocumentFile costProjectDocumentFile = new CostProjectDocumentFile();
- BeanUtils.copyProperties(f,costProjectDocumentFile);
- costProjectDocumentFile.setId(UniqueIdUtil.getUId());
- costProjectDocumentFile.setCreateBy(user.getAccount());
- costProjectDocumentFile.setCreateTime(LocalDateTime.now());
- costProjectDocumentFile.setProjectId(costProjectApproval.getProjectId());
- costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
- switch (f.getPinyin()) {
- case "SongDaWenShuWenHao":
- costProjectDocumentFile.setDataValue(projectDocument.getDocumentNumber());
- break;
- }
- if (StringUtils.isNotBlank(f.getTableName())){
- if(StringUtil.isEmpty(costProjectDocumentFile.getWhereValue())){
- costProjectDocumentFile.setWhereValue(costProjectApproval.getProjectId());
- }else {
- String whereValue1 = costProjectDocumentFile.getWhereValue();
- String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
- costProjectDocumentFile.setWhereValue(replace);
- }
- String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
- //获取whereValue字段值
- costProjectDocumentFile.setDataValue(colValue);
- }
- arrayList.add(costProjectDocumentFile);
- });
- costProjectDocumentFileManager.saveBatch(arrayList);
- }*/
- //文件关联信息赋值
- req.getCostProjectDocumentFiles().forEach(costProjectDocumentFile -> {
- costProjectDocumentFile.setDocumentId(costProjectDocument.getDocumentId());
- costProjectDocumentFile.setProjectId(costProjectDocument.getProjectId());
- switch (costProjectDocumentFile.getPinyin()) {
- case "SongDaWenShuWenHao":
- costProjectDocumentFile.setDataValue(whNo);
- break;
- }
- if (StringUtils.isNotBlank(costProjectDocumentFile.getTableName())){
- if(StringUtil.isEmpty(costProjectDocumentFile.getWhereValue())){
- costProjectDocumentFile.setWhereValue(costProjectApproval.getProjectId());
- }else {
- String whereValue1 = costProjectDocumentFile.getWhereValue();
- String replace = whereValue1.replace("?", "'" + costProjectApproval.getProjectId() + "'");
- costProjectDocumentFile.setWhereValue(replace);
- }
- String colValue = costTemplateFileManager.getColValue(costProjectDocumentFile.getTableName(), costProjectDocumentFile.getColName(), costProjectDocumentFile.getWhereName(), costProjectDocumentFile.getWhereValue());
- //获取whereValue字段值
- costProjectDocumentFile.setDataValue(colValue);
- }
- });
- //保存解析出的文件内容
- costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
- //更新文号值
- costDocumentWhManager.updateCurrentValue(costDocumentWh.getId());
- whMap.remove(whNo);
- }
- public synchronized String getWH(CostDocumentWh costDocumentWh){
- return costDocumentWh.getRulePattern().replace("{prefixText}", costDocumentWh.getPrefixText())
- .replace("{year}", costDocumentWh.getYear()).replace("{currentValue}", costDocumentWh.getCurrentValue().toString());
- }
- @Override
- public List<CostProjectDocumentFile> getDocumentFileList(String id) {
- CostProjectDocument costProjectDocument = this.get(id);
- if(costProjectDocument == null){
- throw new BaseException("文书模板不存在");
- }
- return null;
- }
- @Override
- public void updateProjectDocument(CostProjectDocumentReq req) {
- if (ObjectUtil.isEmpty(req.getId())) {
- throw new BaseException("请选择要修改的文书");
- }
- if (ObjectUtil.isEmpty(req.getDocumentId())) {
- throw new BaseException("请选择文书模板");
- }
- if (ObjectUtil.isEmpty(req.getProjectId())) {
- throw new BaseException("请选择项目");
- }
- if (ObjectUtil.isEmpty(req.getDocumentNumber())) {
- throw new BaseException("请填写通知文号");
- }
- if (ObjectUtil.isEmpty(req.getEnterpriseId())) {
- throw new BaseException("请选择监审单位");
- }
- CostProjectDocument selectCostProjectDocument = this.get(req.getId());
- if (selectCostProjectDocument == null) {
- throw new BaseException("请选择要修改的文书");
- }
- req.setIsPushed("1");
- CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(req.getDocumentId());
- if (costDocumentTemplate == null || BaseConstant.DELETE_FLAG.equals(costDocumentTemplate.getIsDeleted())) {
- throw new BaseException("文书模板不存在");
- }
- req.setDocumentAlias(costDocumentTemplate.getAlias());
- AuditedUnit auditedUnit = auditedUnitManager.get(req.getEnterpriseId());
- if (auditedUnit == null || BaseConstant.DELETE_FLAG.equals(auditedUnit.getIsDeleted())) {
- throw new BaseException("被监审单位不存在");
- }
- CostDocumentWh costDocumentWh = costDocumentWhManager.get(req.getDocumentWhId());
- if (costDocumentWh == null || BaseConstant.DELETE_FLAG.equals(costDocumentWh.getIsDeleted())) {
- throw new BaseException("文书文号不存在");
- }
- LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- qw.eq(CostProjectDocument::getProjectId, req.getProjectId());
- qw.eq(CostProjectDocument::getDocumentId, req.getDocumentId());
- qw.eq(CostProjectDocument::getEnterpriseId, req.getEnterpriseId());
- if (this.count(qw) > 0) {
- throw new BaseException("该项目监审单位已存在此文书");
- }
- selectCostProjectDocument.setDocumentWhId(req.getDocumentWhId());
- selectCostProjectDocument.setDocumentId(req.getDocumentId());
- selectCostProjectDocument.setEnterpriseId(req.getEnterpriseId());
- selectCostProjectDocument.setElectronicDocumentUrl("");
- // 类型转换
- BeanUtil.copyProperties(req,selectCostProjectDocument);
- super.update(selectCostProjectDocument);
- costProjectDocumentFileManager.remove(new LambdaQueryWrapper<CostProjectDocumentFile>().eq(CostProjectDocumentFile::getProjectId,selectCostProjectDocument.getProjectId()));
- List<CostProjectDocumentFile> costProjectDocumentFiles = req.getCostProjectDocumentFiles();
- if (costProjectDocumentFiles != null){
- for (CostProjectDocumentFile costProjectDocumentFile : costProjectDocumentFiles) {
- costProjectDocumentFile.setDocumentId(selectCostProjectDocument.getDocumentId());
- costProjectDocumentFile.setProjectId(selectCostProjectDocument.getProjectId());
- }
- }
- costProjectDocumentFileManager.saveBatch(req.getCostProjectDocumentFiles());
- }
- @Override
- public List<CostProjectDocument> getListByProjectId(String projectId) {
- LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- qw.eq(CostProjectDocument::getProjectId, projectId);
- qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
- List<CostProjectDocument> list = this.list(qw);
- if (ObjectUtil.isEmpty(list)) {
- return new ArrayList<>();
- }
- return list;
- }
- @Override
- public CostProjectDocumentResp getByProjectId(String projectId){
- //查询监审文书
- LambdaQueryWrapper<CostProjectDocument> qw = new LambdaQueryWrapper<>();
- qw.eq(CostProjectDocument::getProjectId, projectId);
- qw.eq(CostProjectDocument::getIsDeleted, BaseConstant.NORMAL_STATUS);
- CostProjectDocument costProjectDocument = this.getOne(qw);
- //转换为返回类型
- CostProjectDocumentResp costProjectDocumentResp = BeanUtil.copyProperties(costProjectDocument, CostProjectDocumentResp.class);
- //查询文书下的文书内容
- LambdaQueryWrapper<CostProjectDocumentFile> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CostProjectDocumentFile::getProjectId, costProjectDocument.getProjectId());
- //获取文件内容返回
- costProjectDocumentResp.setCostProjectDocumentFiles(costProjectDocumentFileManager.list(wrapper));
- CostDocumentTemplate costDocumentTemplate = costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
- costProjectDocumentResp.setFullPath(EipConfig.getImgUrl()+costDocumentTemplate.getFileUrl());
- return costProjectDocumentResp;
- }
- @Override
- public String createDocument(String id) {
- CostProjectDocument costProjectDocument = this.getDetail(id);
- List<CostProjectDocumentFile> list = costProjectDocumentFileManager.getCostProjectDocumentFiles(costProjectDocument.getProjectId(),costProjectDocument.getDocumentId());
- CostDocumentTemplate costDocumentTemplate = this.costDocumentTemplateManager.get(costProjectDocument.getDocumentId());
- //生成文书
- Map<String,String> map = new HashMap<>();
- list.stream().forEach(p->{
- map.put("{"+p.getOriginalText()+"}",p.getDataValue());
- });
- //先处理一种文件
- String templatePath = costDocumentTemplate.getFileUrl().replace(BaseConstant.RESOURCE_PREFIX,"");
- templatePath = EipConfig.getProfile()+templatePath;
- String fileExtension = FileUploadUtil.getFileExtension(costDocumentTemplate.getFileUrl());
- String fileName = FileUploadUtil.generateFileName(costDocumentTemplate.getDocumentName()+"."+fileExtension);
- String outputPath = FileUploadUtil.generateSavePath(EipConfig.getUploadPath(), fileName, fileExtension);
- DocumentProcessor.processWordDocument(templatePath,outputPath,map,new LinkedHashMap<>());
- return EipConfig.getImgUrl()+FileUploadUtil.getPathFileName(outputPath,fileName);
- }
- }
|