hyingbo
6 天以前 418d29b85d943f57b5600d84acf9cf6ca0ce9173
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DocInfoServiceImpl.java
@@ -1,5 +1,6 @@
package org.jeecg.modules.dnc.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -11,9 +12,12 @@
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.FileUploadResult;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.ext.NcTxtFilePathInfo;
import org.jeecg.modules.dnc.listener.FileMonitorConfig;
import org.jeecg.modules.dnc.mapper.DocInfoMapper;
import org.jeecg.modules.dnc.request.DocInfoQueryRequest;
import org.jeecg.modules.dnc.request.DocInfoUploadRequest;
@@ -24,7 +28,14 @@
import org.jeecg.modules.dnc.utils.file.FileUtilS;
import org.jeecg.modules.dncFlow.entity.DispatchFile;
import org.jeecg.modules.dncFlow.service.IDispatchFileService;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.system.entity.SysParams;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysParamsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@@ -35,13 +46,22 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
@Service
public class DocInfoServiceImpl extends ServiceImpl<DocInfoMapper, DocInfo> implements IDocInfoService {
    @Autowired
    private FileMonitorConfig config;
    @Autowired
    private IMdcEquipmentService iMdcEquipmentService;
    @Autowired
    private IMdcProductionService iMdcProductionService;
    @Autowired
    private IDocClassificationService docClassificationService;
    @Autowired
@@ -52,12 +72,19 @@
    @Lazy
    private IDocRelativeService docRelativeService;
    @Autowired
    @Lazy
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDeviceGroupService deviceGroupService;
    @Autowired
    private IDispatchFileService dispatchFileService;
    @Autowired
    private ISysParamsService sysParamsService;
    @Autowired
    @Lazy
    private IComponentInfoService componentInfoService;
    @Autowired
    @Lazy
    private IGuideCardBatchService guideCardBatchService;
    @Autowired
    private IFlowMyBusinessService flowMyBusinessService;
    @Autowired
    private IFlowTaskService flowTaskService;
    /*备份处理*/
    @Override
@@ -94,6 +121,19 @@
        docRelative.setAttributionType(uploadRequest.getAttributionType());
        docRelative.setClassificationId(docClass.getClassificationId());
        boolean b = docRelativeService.save(docRelative);
        if (uploadRequest.getAttributionType()==2){
            //查询借用的部件
            List<ComponentInfo> borrowComponentInfoList=componentInfoService.list(new QueryWrapper<ComponentInfo>().eq("borrow_id", uploadRequest.getAttributionId()));
            if (!borrowComponentInfoList.isEmpty()) {
                borrowComponentInfoList.forEach(item->{
                    DocRelative borrowDocRelative = new DocRelative();
                    BeanUtil.copyProperties(docRelative,borrowDocRelative);
                    borrowDocRelative.setAttributionId(item.getComponentId());
                    borrowDocRelative.setId(null);
                    docRelativeService.save(borrowDocRelative);
                });
            }
        }
        if(!b)
            ExceptionCast.cast(DocumentCode.DOC_UPLOAD_ERROR);
        DocFile docFile = new DocFile();
@@ -109,43 +149,56 @@
        docInfo.setPublishVersion(docFile.getDocVersion());
        docInfo.setPublishFileId(docFile.getFileId());
        //COPY
        DeviceInfo deviceInfo= deviceInfoService.getById(uploadRequest.getAttributionId());
        if (deviceInfo != null) {
            List<String> strings =  deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId());
        MdcEquipment mdcEquipment= iMdcEquipmentService.getById(uploadRequest.getAttributionId());
        if (mdcEquipment != null) {
            List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
            boolean copyFileNc = false;
            if (strings != null && !strings.isEmpty()) {
                String path = org.apache.commons.lang3.StringUtils.join(strings.toArray(), "/");
                copyFileNc = FileUtilS.copyFile(fileUploadResult.getFilePath()+"/" + fileUploadResult.getFileEncodeName(),
                        path+ "/" + deviceInfo.getDeviceNo() ,fileNameAll);
                        path+ "/" + mdcEquipment.getEquipmentId() ,fileNameAll);
                if (!copyFileNc) {
                    ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                } else {
                    FileUtilS.deleteZipFromToSend(path + "/"+ deviceInfo.getDeviceNo(),
                    FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(),
                            docFile.getFileName(),docFile.getFileSuffix());
                }
            } else {
                copyFileNc =FileUtilS.copyFile(fileUploadResult.getFilePath()+"/" + fileUploadResult.getFileEncodeName(),
                        deviceInfo.getDeviceNo() ,fileNameAll);
                        mdcEquipment.getEquipmentId() ,fileNameAll);
                if (!copyFileNc) {
                    ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                } else {
                    FileUtilS.deleteZipFromToSend(fileUploadResult.getFilePath()+"/" + fileUploadResult.getFileEncodeName() + "/"+ deviceInfo.getDeviceNo(),
                    FileUtilS.deleteZipFromToSend(fileUploadResult.getFilePath()+"/" + fileUploadResult.getFileEncodeName() + "/"+ mdcEquipment.getEquipmentId(),
                            docFile.getFileName(),docFile.getFileSuffix());
                }
            }
        }
        boolean saveBool = super.save(docInfo);
        if (uploadRequest.getIsApprove()&&saveBool){
            //触发审签
            DispatchFile dispatchFile = new DispatchFile();
            dispatchFile.setDocId(docInfo.getDocId());
            dispatchFile.setFileId(docFile.getFileId());
            dispatchFile.setAttributionId(uploadRequest.getAttributionId());
            dispatchFile.setAttributionType(String.valueOf(uploadRequest.getAttributionType()));
            dispatchFile.setDocClassCode(uploadRequest.getDocClassCode());
            dispatchFileService.saveDispatchFile(dispatchFile);
        if (uploadRequest.getDocClassCode().equals("NC")||uploadRequest.getDocClassCode().equals("other")){
            SysParams sysParams=sysParamsService.getSysPramBySettingKey("nc_dispatch_file");
            if (sysParams ==null){
                throw new JeecgBootException("未配置导入NC与电子图版是否触发审签流程,请联系管理员");
            }else {
                if (saveBool&&sysParams.getSettingValue().equals("1")){
                    //触发审签
                    DispatchFile dispatchFile = new DispatchFile();
                    dispatchFile.setDocId(docInfo.getDocId());
                    dispatchFile.setFileId(docFile.getFileId());
                    dispatchFile.setAttributionId(uploadRequest.getAttributionId());
                    dispatchFile.setAttributionType(String.valueOf(uploadRequest.getAttributionType()));
                    dispatchFile.setDocClassCode(uploadRequest.getDocClassCode());
                    dispatchFileService.saveDispatchFile(dispatchFile);
                }
            }
        }
        if (uploadRequest.getDocClassCode().equals("NC")){
            boolean savaGuideCardBatch=guideCardBatchService.importGuideCardBatch(docInfo.getDocId(),uploadRequest.getAttributionId(),uploadRequest.getAttributionType());
            if (!savaGuideCardBatch) {
                ExceptionCast.cast(DocumentCode.DOC_BATCH_ERROR);
            }
        }
        return saveBool;
    }
@@ -174,8 +227,8 @@
        if (StringUtils.isEmpty(deviceNo)) {
            return false;
        }
        DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);
        if (deviceInfo == null) {
        MdcEquipment mdcEquipment = iMdcEquipmentService.findEquipmentNameByEquipmentId(deviceNo);
        if (mdcEquipment == null) {
            return false;
        }
        String fileName = FileUtilS.getFilenameNonSuffix(file.getOriginalFilename());
@@ -184,7 +237,7 @@
        if(fileUploadResult == null) {
            return false;
        }
        DocInfo en = findByAttrAndDocName(fileName, 4, deviceInfo.getDeviceId());
        DocInfo en = findByAttrAndDocName(fileName, 7, mdcEquipment.getId());
        if(en != null) {
            return false;
        }
@@ -197,9 +250,9 @@
        docInfo.setDocStatus(1);
        docInfo.setSyncStatus(2);
        DocRelative docRelative = new DocRelative();
        docRelative.setAttributionId(deviceInfo.getDeviceId());
        docRelative.setAttributionId(mdcEquipment.getId());
        docRelative.setDocId(docInfo.getDocId());
        docRelative.setAttributionType(4);
        docRelative.setAttributionType(7);
        docRelative.setClassificationId(docClass.getClassificationId());
        boolean b = docRelativeService.save(docRelative);
        if(!b) {
@@ -222,6 +275,94 @@
        return saveBool;
    }
    /**
     * 解析NC文档通用方法
     * @param pathFile,fileRec
     * @return
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addDocInfoAnalysisGwNcService(String pathFile,File file) throws FileNotFoundException {
        String line;
        int count = 0;
        String loFilePath = config.getPaths().get(0)+"/" + file.getName();
        FileInputStream fis = new FileInputStream(loFilePath);
        NcTxtFilePathInfo result = new NcTxtFilePathInfo();
        Scanner sc = new Scanner(fis, "UTF-8");
        while (count < 8 &&  sc.hasNext()) {
            line = sc.nextLine();
            if (count ==0) {
                result.setFileTxtName(line.trim());
            } else  if (count ==1) {
                result.setFileNcName(line.trim());
            }else  if (count ==2) {
                result.setOrigFileName(line.trim());
            }else  if (count ==3) {
                result.setOrigFileSuffix(line.trim());
            }else  if (count ==4) {
                result.setFilePath(line.trim());
            }else  if (count ==5) {
                result.setEquipmentId(line.trim());
            }else  if (count ==6) {
                result.setFileAddOrDelete(Integer.valueOf(line.trim()));
            }else  if (count == 7) {
                result.setFileSize(line.trim());
            }
            count++;
        }
        sc.close();
        if (result.getFileAddOrDelete() != null ) {
            if ( result.getFileAddOrDelete()==1) {
                String path = config.getPaths().get(0) +"/" + result.getFileNcName()+ ".NC";
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(result.getFileNcName()) &&
                            result.getFileNcName().equals("null")) {
                        //文件待处理
                        //备份数据
                        FileUtilS.deleteFileNewRec(loFilePath);
                    }
                File ncFile = new File(path);
                //已经存在文件需要备份
                String size = String.valueOf(ncFile.length());
                if (!size.equals(result.getFileSize())) {
                    return false;
                }
                boolean bool = this.addDocInfoRecService(result.getEquipmentId(),
                        ncFile,result.getOrigFileSuffix(),
                        FileUtilS.getFilenameNonSuffix(result.getOrigFileName())
                        ,result.getFilePath());
                if (bool) {
                    FileUtilS.deleteFileNewRec(path);
                    FileUtilS.deleteFileNewRec(loFilePath);
                }else {
                    return false;
                }
            }
        }
        return true;
    }
    /**
     * 程序回传(涉密解析工控)
     * @param pathFile
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addDocInfoAnalysisSmwNcService(String pathFile,File fileRec){
        //确认解析目录
        return true;
    }
    /**
     * 文档解析
     * todo 修改创建文件关联关系,改成固定docId,去除创建DocInfo
     * @param equipmentId
     * @param fileRec
     * @param fileNameSuffix
     * @param fileNameNew
     * @param filePath
     * @return
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addDocInfoRecService(String equipmentId,File fileRec,String fileNameSuffix,String fileNameNew,String filePath ) {
@@ -234,12 +375,11 @@
            ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
        }
        //根据设备编号查询数据
        String deviceNo = equipmentId;
        if (StringUtils.isEmpty(deviceNo)) {
        if (StringUtils.isEmpty(equipmentId)) {
            return false;
        }
        DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);
        if (deviceInfo == null) {
        MdcEquipment mdcEquipment = iMdcEquipmentService.findEquipmentNameByEquipmentId(equipmentId);
        if (mdcEquipment == null) {
            return false;
        }
        String fileName = FileUtilS.getFilenameNonSuffix(file.getOriginalFilename());
@@ -248,7 +388,7 @@
        if(fileUploadResult == null) {
            return false;
        }
        DocInfo en = findByAttrAndDocName(fileName, 4, deviceInfo.getDeviceId());
        DocInfo en = findByAttrAndDocName(fileName, 7, mdcEquipment.getId());
        if(en != null) {
            return false;
        }
@@ -261,9 +401,9 @@
        docInfo.setDocStatus(1);
        docInfo.setSyncStatus(2);
        DocRelative docRelative = new DocRelative();
        docRelative.setAttributionId(deviceInfo.getDeviceId());
        docRelative.setAttributionId(mdcEquipment.getId());
        docRelative.setDocId(docInfo.getDocId());
        docRelative.setAttributionType(4);
        docRelative.setAttributionType(7);
        docRelative.setClassificationId(docClass.getClassificationId());
        boolean b = docRelativeService.save(docRelative);
        if(!b) {
@@ -308,7 +448,7 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteDocInfo(String id) {
    public boolean deleteDocInfo(String id,String attrType,String attrId) {
        if(!ValidateUtil.validateString(id))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        DocInfo en = super.getById(id);
@@ -316,6 +456,20 @@
            ExceptionCast.cast(DocumentCode.DOC_NOT_EXIST);
        if(en.getDocStatus() != 1)
            ExceptionCast.cast(DocumentCode.DOC_DEL_ERROR);
        //查询对应的关系
        if ("2".equals(attrType)) {
            //判断部件引用
            ComponentInfo componentInfo=componentInfoService.getById(attrId);
            if(componentInfo!=null&&componentInfo.getBorrowId()!=null){
                //借用的部件,只删除自己的关系
                DocRelative docRelative=docRelativeService.getOne(new QueryWrapper<DocRelative>()
                        .eq("attribution_id", attrId).eq("attribution_type", 2).eq("doc_id",id));
                if(docRelative!=null){
                    docRelativeService.removeById(docRelative.getId());
                    return true;
                }
            }
        }
        FileOperate operate = fileOperateService.getByDocId(id);
        if(operate != null)
            ExceptionCast.cast(DocumentCode.DOC_IS_OPERATING);
@@ -325,6 +479,14 @@
        b = docRelativeService.deleteByDocId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //强制结束流程 删除用户的此待办任务
        List<DispatchFile> dispatchFiles=dispatchFileService.list(new QueryWrapper<DispatchFile>().eq("doc_id",id));
        if (dispatchFiles != null && !dispatchFiles.isEmpty()) {
            FlowMyBusiness flowMyBusiness = flowMyBusinessService.selectByDataId(dispatchFiles.get(0).getId());
            if (flowMyBusiness != null) {
                flowTaskService.end(flowMyBusiness.getProcessInstanceId(), "删除文档");
            }
        }
        return super.removeById(id);
    }
@@ -626,7 +788,7 @@
    public boolean deleteByDeviceId(String deviceId) {
        if(!ValidateUtil.validateString(deviceId))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        Integer attrType = 4;
        Integer attrType = 7;
        /*boolean b = docFileService.deleteByDocAttr(attrType, deviceId);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
@@ -828,6 +990,45 @@
        return super.getBaseMapper().findDocExtList(queryWrapper);
    }
    /**
     * 通过一组attributionId,docClassCode,attributionType查询可指派的文档信息列表
     * @param docQuery
     * @return
     */
    @Override
    public List<DocInfo> findListByDocQuery(DocInfoQueryRequest docQuery){
        if(docQuery == null || !ValidateUtil.validateString(docQuery.getAttributionIds())
                || !ValidateUtil.validateInteger(docQuery.getAttributionType()) ||
                !ValidateUtil.validateString(docQuery.getDocClassCode())) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
        DocClassification docClassification = docClassificationService.getByCode(docQuery.getDocClassCode());
        if(docClassification == null) {
            ExceptionCast.cast(CommonCode.INVALID_PAGE);
        }
        List<String> attributionIds = Arrays.asList(docQuery.getAttributionIds().split(","));
        QueryWrapper<DocInfo> queryWrapper = Wrappers.query();
        queryWrapper.eq(StrUtil.isNotEmpty(docQuery.getDocId()),"u.doc_id",docQuery.getDocId());
        queryWrapper.eq("r.attribution_type", docQuery.getAttributionType())
                .in("r.attribution_id", attributionIds)
                .eq("r.classification_id", docClassification.getClassificationId());
        if (StringUtils.isNotEmpty(docQuery.getDocName())) {
            int dotIndex = docQuery.getDocName().lastIndexOf(".");
            if (dotIndex == -1) {
                queryWrapper.like("u.doc_name", docQuery.getDocName());
            } else {
                String[] docNameArr = docQuery.getDocName().split("\\.");
                queryWrapper.like(StrUtil.isNotEmpty(docNameArr[0]), "u.doc_name", docNameArr[0]);
                queryWrapper.eq(StrUtil.isNotEmpty(docNameArr[1]), "u.doc_suffix", docNameArr[1]);
            }
        }
        getDocQuery(docQuery, queryWrapper);
        return super.getBaseMapper().findDocExtList(queryWrapper);
    }
    @Override
    public List<DocInfo> getByProcessIds(List<ProcessStream> streams) {
        List<String> ids = new ArrayList<>();
@@ -847,11 +1048,11 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean batchRemoveDocInfo(String[] docIds) {
    public boolean batchRemoveDocInfo(String[] docIds,String attrType,String attrId) {
        if(docIds == null || docIds.length < 1)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        for(String docId : docIds) {
            this.deleteDocInfo(docId);
            this.deleteDocInfo(docId,attrType,attrId);
        }
        return true;
    }