lyh
2 天以前 82c1b82a6d46620a5ae493353c37d40da691f716
lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java
@@ -98,15 +98,23 @@
    private String secretFolder;    //涉密网传输nc文件夹
    @Autowired
    private FileFerryService ferryService;
    @Autowired
    private IDocClassificationService iDocClassificationService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public Result applyAssignFile(AssignFileStream stream) {
    public Result<?> applyAssignFile(AssignFileStream stream) {
        synchronized (this){
            //判断设备特殊字符
            String specialChar = getDeviceSpecialChar(stream.getDeviceId(),stream.getFileId());
            if (StrUtil.isNotEmpty(specialChar)){
                //抛出特殊字符异常
                return Result.error("文件名称存在设备特殊字符");
            }
            //查询文档的状态,批准状态才可以指派
            DocInfo docInfo=getDocInfo(stream);
            DocClassification docClassification=iDocClassificationService.getById(docInfo.getClassificationId());
            if (docInfo.getDocDispatchStatus()!=null&&docInfo.getDocDispatchStatus()!=3&&docInfo.getDocDispatchStatus()!=5&&docClassification.getClassificationCode().equals("nc")){
                return Result.error("该文件状态不允许指派,请先完成审签流程");
            }
            if(flowableEnable) {
                return applyAssignFileActive(stream);
@@ -174,14 +182,13 @@
        validateParams(stream);
        DocInfo docInfo = getDocInfo(stream);
        MdcEquipment mdcEquipment = getMdcEquipment(stream);
        DocFile docFile = docFileService.getById(stream.getFileId());
        DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId());
        if (deviceDoc != null) {
            handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId());
            return Result.error("存在相同文档,不允许重复指派,请删除后指派");
        }
        deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 7, stream.getDeviceId());
        if (deviceDoc != null) {
            handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId());
            return Result.error("存在相同文档,不允许重复指派,请删除后指派");
        }
        PermissionStreamNew permissionStreams = getPermissionStreams(stream);
        if (permissionStreams==null){
@@ -191,7 +198,7 @@
        String userId = user.getId();
        saveBusinessObject(stream, userId);
        System.out.println("指派NC文档到设备流程:" + stream.getDocId());
        flowCommonService.initActBusiness("指派NC文档到设备流程:" +docInfo.getDocName()+"."+docInfo.getDocSuffix()+"到设备->"+mdcEquipment.getEquipmentName() ,
        flowCommonService.initActBusiness("指派NC文档到设备流程:" +docInfo.getDocName()+"."+docInfo.getDocSuffix()+"到设备->"+mdcEquipment.getEquipmentId() ,
                stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", stream.getStreamId());
@@ -258,9 +265,9 @@
        }
        handleFileTransfer(mdcEquipment, docFile);
        //NC文件的拷贝
        handleFileProcessing(docFile, mdcEquipment, secretFolder);
//        handleFileProcessing(docFile, mdcEquipment, secretFolder);
        //对应产品结构树拷贝
        handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
//        handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
        synchronizedFlagService.updateFlag(2);
        return Result.OK("操作成功");
    }
@@ -339,8 +346,11 @@
            DocFile docFile = docFileService.getById(en.getFileId());
            if(docFile == null)
                ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
            //修改原有状态
            docInfo.setDocDispatchStatus(4);
            //修改NC状态
            if (Objects.equals(en.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode().toString()) ||
                    Objects.equals(en.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode().toString())) {
                docInfo.setDocDispatchStatus(4);
            }
            docInfoService.updateById(docInfo);
            DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),7, en.getDeviceId());
            if(deviceDoc != null) {
@@ -371,19 +381,17 @@
            }
            if(!b)
                ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
            if (mdcEquipment != null) {
                List<String> strings =  iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
                if (strings != null && !strings.isEmpty()) {
                    String path = StringUtils.join(strings.toArray(), "/");
                    boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(),path + "/"+ mdcEquipment.getEquipmentId(),
                            docFile.getFileEncodeName(),
            List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
            if (strings != null && !strings.isEmpty()) {
                String path = StringUtils.join(strings.toArray(), "/");
                boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(),path + "/"+ mdcEquipment.getEquipmentId(),
                        docFile.getFileEncodeName(),
                        docFile.getFileName(),docFile.getFileSuffix());
                if (!copyFileNc) {
                    ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                } else {
                    FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(),
                            docFile.getFileName(),docFile.getFileSuffix());
                    if (!copyFileNc) {
                        ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                    } else {
                        FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(),
                                docFile.getFileName(),docFile.getFileSuffix());
                    }
                }
            }
            List<DocRelative> docRelativeList=docRelativeService.
@@ -394,13 +402,15 @@
            if (docRelativeList.isEmpty()){
                ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
            }
            //涉密网进行NC文件的拷贝
            handleFileTransfer(mdcEquipment, docFile);
            //NC文件的拷贝
            handleFileProcessing(docFile, mdcEquipment, secretFolder);
            //对应产品结构树拷贝
            handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
            return synchronizedFlagService.updateFlag(1);
            DocRelative docRelative=docRelativeList.get(0);
            if (!Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode()) ||
                    !Objects.equals(docRelative.getAttributionType(), DocAttributionTypeEnum.WORKSITE.getCode())) {
                //其他文件的拷贝
                handleFileOtherProcessing(docFile, mdcEquipment, secretFolder);
                //对应产品结构树拷贝
                handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId());
            }
            return true;
        }else if(up.getStatus() == 3) {
            //拒绝操作 什么也不做
            return true;
@@ -524,16 +534,16 @@
    }
    //获取文件
    private void handleExistingDeviceDoc(DocFile docFile, MdcEquipment mdcEquipment, String deviceId) {
    private void handleExistingDeviceDoc(DocInfo docInfo,DocFile docFile, MdcEquipment mdcEquipment, String deviceId) {
        List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
        if (strings != null && !strings.isEmpty()) {
            String path = StringUtils.join(strings.toArray(), "/");
            boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/" + mdcEquipment.getEquipmentId(),
                    docFile.getFileName(), docFile.getFileSuffix());
            if (!copyFileNc) {
                ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
            } else {
                DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 7, deviceId);
                DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(docInfo.getDocId(), 7, deviceId);
                boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 7, deviceId);
                if (!doc) {
                    ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE);
@@ -680,16 +690,86 @@
        passInfoTxt.setPassType(DncPassLogPassType.PRODUCTSTRUCTURE.getCode());
        dncPassLogService.save(passInfoTxt);
        String fileName="10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY);
        if (Objects.equals(docInfo.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode())){
            //工序对应设备类
            String filePath = ferryService.exportData(TransferPackage.DataType.PROCESS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
            System.out.println("工序数据已导出: " + filePath);
        }else {
            //工步对应设备类
            String filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
            System.out.println("工步数据已导出: " + filePath);
        String filePath="";
        switch (docInfo.getAttributionType()){
            case 1:
                //产品对应其他文档
                filePath = ferryService.exportData(TransferPackage.DataType.PRODUCT, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("产品数据已导出: " + filePath);
                break;
            case 2:
                //部件对应其他文档
                filePath = ferryService.exportData(TransferPackage.DataType.COMPONENT, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("部件数据已导出: " + filePath);
                break;
            case 3:
                //零件对应其他文档
                filePath = ferryService.exportData(TransferPackage.DataType.PARTS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("零件数据已导出: " + filePath);
                break;
            case 4:
                //工艺版本对应其他文档
                filePath = ferryService.exportData(TransferPackage.DataType.OPERATION, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("工艺版本数据已导出: " + filePath);
                break;
            case 5:
                //工序对应设备类
                filePath = ferryService.exportData(TransferPackage.DataType.PROCESS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("工序数据已导出: " + filePath);
                break;
            case 6:
                //工步对应设备类
                filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry");
                System.out.println("工步数据已导出: " + filePath);
                break;
            default:
                break;
        }
    }
    //封装处理其他文件
    private void handleFileOtherProcessing(DocFile docFile, MdcEquipment mdcEquipment, String secretFolder) {
        if (!docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) {
            List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
            if (strings != null && !strings.isEmpty()) {
                DncPassLog passInfoTxt = new DncPassLog();
                String path = StringUtils.join(strings.toArray(), "/");
                Date dateFirst = DateUtil.getNow();
                passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
                /*查询最后一条记录*/
                //休眠 500毫秒
                DncPassLog dncPassLog  = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
                int fileNc =0;
                if (dncPassLog !=null) {
                    fileNc = dncPassLog.getSequenceNumber() + 1;
                } else {
                    fileNc =  1;
                }
                //处理文件名称  文件路径
                String sequenceNc = String.format("%06d",fileNc);
                DncPassLog passInfoNc = new DncPassLog();
                passInfoNc.setSequenceNumber(fileNc);
                passInfoNc.setSequenceOrder(sequenceNc);
                passInfoNc.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY));
                passInfoNc.setPassType("02");
                passInfoNc.setPassName(docFile.getFileName());
                try {
                    Thread.sleep(1000);
                    Date date = new Date();
                    passInfoNc.setCreateTime(date);
                    System.out.println(DateUtil.format(date,DateUtil.STR_DATE_TIME));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                dncPassLogService.save(passInfoNc);
                FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" +
                                docFile.getFileName(),
                        secretFolder +"/"+"10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc+"_"+mdcEquipment.getEquipmentId(),
                        docFile.getFileSuffix(), docFile.getFileSuffix());
            }
        }
    }
    @Override
    public void afterFlowHandle(FlowMyBusiness business) {
        business.getTaskNameId();//接下来审批的节点