1.DNC模块,设备结构树权限分配优化与修改bug
2.MDC模块,设备编辑车间同步平移设备send目录
3.优化原有指派设备代码
已添加1个文件
已修改9个文件
714 ■■■■ 文件已修改
lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java 584 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IPermissionStreamService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceGroupPermissionServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PermissionStreamServiceImpl.java 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DncCopyEquipment.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcProductionService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcProductionServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcUserProductionServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java
@@ -194,150 +194,37 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean applyAssignFileActive(AssignFileStream stream) {
        //校验开始
        if(stream == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId())
                || !ValidateUtil.validateString(stream.getFileId())||!ValidateUtil.validateString(stream.getAttributionType()) )
            ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
        if(!ValidateUtil.validateString(stream.getDeviceId()))
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        //修改为前端传入
        DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId());
        if(docInfo == null || docInfo.getDocStatus() == 3)
            ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
        DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId());
        if(deviceInfo == null)
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        if(deviceInfo == null)
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        validateParams(stream);
        DocInfo docInfo = getDocInfo(stream);
        MdcEquipment mdcEquipment = getMdcEquipment(stream);
        DocFile docFile = docFileService.getById(stream.getFileId());
        DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId());
        if(deviceDoc != null) {
            /*// åˆ é™¤ å¤‡ä»½  è¦†ç›– åŽŸæœ‰çš„
            List<String> strings =  deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId());
            if (strings != null && !strings.isEmpty()) {
                String path = StringUtils.join(strings.toArray(), "/");
                boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ deviceInfo.getDeviceNo(),
                        docFile.getFileName(), docFile.getFileSuffix());
                if (!copyFileNc) {
                    ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                } else {
                    //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId());
                    boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(),4,stream.getDeviceId());
                    if (!doc) {
                        ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE);
                    }
                }
            }*/
            handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId());
        }
        deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId());
        if(deviceDoc != null) {
            // åˆ é™¤ å¤‡ä»½  è¦†ç›– åŽŸæœ‰çš„
           /* List<String> strings =  deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId());
            if (strings != null && !strings.isEmpty()) {
                String path = StringUtils.join(strings.toArray(), "/");
                boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ deviceInfo.getDeviceNo(),
                        docFile.getFileName(), docFile.getFileSuffix());
                if (!copyFileNc) {
                    ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
                } else {
                    //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId());
                    boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(),4,stream.getDeviceId());
                    if (!doc) {
                        ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE);
            handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId());
                    }
                }
            }*/
        }
        ProcessStream processStream = processStreamService.getById(stream.getProcessId());
        if(processStream == null)
            ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
        stream.setProductId(processStream.getProductId());
        stream.setComponentId(processStream.getComponentId());
        stream.setPartsId(processStream.getPartsId());
        List<PermissionStream> permissionStreams = null;
        if(ValidateUtil.validateString(processStream.getPartsId())) {
            //进入零件
            permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
        }else if(ValidateUtil.validateString(processStream.getComponentId())) {
            //进入部件的处理
            permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
        }
        if(permissionStreams == null || permissionStreams.isEmpty())
            ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
        List<String> departIds = new ArrayList<>();
        Map<String, Department> map = departmentService.getMapByUserId(userId);
        permissionStreams.forEach(item -> {
            if(map.containsKey(item.getDepartId())) {
                departIds.add(item.getDepartId());
            }
        });
        if(departIds.isEmpty())
            ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM);
        //获取部门审批人
        List<String> userIdList = definitionService.getByDepartIds(departIds);
        if(userIdList == null || userIdList.isEmpty())
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        //校验结束
        String streamId = IdWorker.getIdStr();
        stream.setStreamId(streamId);
        stream.setApplyUserId(userId);
        stream.setApplyTime(DateUtil.getNow());
        stream.setStatus(1);
        //保存流程业务对象
        boolean b = super.save(stream);
        if(!b)
            ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
        //保存流程任务
        String approveUsers = String.join(",", userIdList);
        Map<String, Object> avariableMap = new HashMap<>();
        avariableMap.put(APPLY_VARIABLE, userId);
        avariableMap.put(APPROVE_VARIABLE, approveUsers);
        //启动流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, streamId, avariableMap);
        if(processInstance == null)
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        //查询当前流程用户流程任务
        Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId)
                .processInstanceId(processInstance.getId()).singleResult();
        if(task == null)
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        //完成流程任务
        taskService.complete(task.getId());
        List<PermissionStream> permissionStreams = getPermissionStreams(stream);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        List<String> departIds = getDepartIds(permissionStreams, userId);
        List<String> userIdList = getUserIdList(departIds);
        saveBusinessObject(stream, userId);
        ProcessInstance processInstance = startProcessInstance(stream, userIdList);
        completeTask(processInstance, userId);
        return true;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public ResponseResult applyAssignFileNonActive(AssignFileStream stream) {
        if(stream == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId())
                || !ValidateUtil.validateString(stream.getFileId())||!ValidateUtil.validateString(stream.getAttributionType()))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(stream.getDeviceId()))
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId());
        if(docInfo == null || docInfo.getDocStatus() == 3)
            ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
        MdcEquipment mdcEquipment = iMdcEquipmentService.getById(stream.getDeviceId());
//        DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId());
        if(mdcEquipment == null)
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        DocFile docFile = docFileService.getById(stream.getFileId());
        if(docFile == null)
            ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
        //权限校验
        validateParams(stream);
        DocInfo docInfo = getDocInfo(stream);
        MdcEquipment mdcEquipment = getMdcEquipment(stream);
        DocFile docFile = getDocFile(stream);
        DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId());
        if(deviceDoc != null) {
            // åˆ é™¤ å¤‡ä»½  è¦†ç›– åŽŸæœ‰çš„
@@ -348,7 +235,6 @@
                        docFile.getFileName(), docFile.getFileSuffix());
            }
        }
        /*deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId());
        if(deviceDoc != null) {
            // åˆ é™¤ å¤‡ä»½  è¦†ç›– åŽŸæœ‰çš„
@@ -359,73 +245,12 @@
                        docFile.getFileName(), docFile.getFileSuffix());
            }
        }*/
        List<String> departIds = new ArrayList<>();
        if (stream.getAttributionType().equals("5")){
            //工序
            ProcessStream processStream = processStreamService.getById(stream.getAttributionId());
            if(processStream == null)
                ExceptionCast.cast(CommonCode.INVALID_PARAM);
            stream.setProductId(processStream.getProductId());
            stream.setComponentId(processStream.getComponentId());
            stream.setPartsId(processStream.getPartsId());
            stream.setProcessId(stream.getAttributionId());
            List<PermissionStream> permissionStreams = null;
            if(ValidateUtil.validateString(processStream.getPartsId())) {
                //进入零件
                permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
            }else if(ValidateUtil.validateString(processStream.getComponentId())) {
                //进入部件的处理
                permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
            }
            if(permissionStreams == null || permissionStreams.isEmpty())
                ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
            Map<String, Department> map = departmentService.getMapByUserId(userId);
            permissionStreams.forEach(item -> {
                if(map.containsKey(item.getDepartId())) {
                    departIds.add(item.getDepartId());
                }
            });
        }else{
            //工步
            WorkStep workStep=workStepService.getById(stream.getAttributionId());
            if(workStep == null)
                ExceptionCast.cast(CommonCode.INVALID_PARAM);
            stream.setProductId(workStep.getProductId());
            stream.setComponentId(workStep.getComponentId());
            stream.setPartsId(workStep.getPartsId());
            stream.setProcessId(workStep.getProcessId());
            stream.setProcessId(stream.getAttributionId());
            List<PermissionStream> permissionStreams = null;
            if(ValidateUtil.validateString(workStep.getProcessId())) {
                //进入工序
                permissionStreams=permissionStreamService.getByProcessId(stream.getProductId(), stream.getComponentId(), stream.getPartsId(),stream.getProcessId());
            }else if(ValidateUtil.validateString(workStep.getPartsId())) {
                //进入零件
                permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
            }else if(ValidateUtil.validateString(workStep.getComponentId())) {
                //进入部件的处理
                permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
            }
            if(permissionStreams == null || permissionStreams.isEmpty())
                ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
            Map<String, Department> map = departmentService.getMapByUserId(userId);
            permissionStreams.forEach(item -> {
                if(map.containsKey(item.getDepartId())) {
                    departIds.add(item.getDepartId());
                }
            });
        }
        if(departIds.isEmpty())
            ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM);
        //deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId());
        /*if(deviceDoc != null)
            ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);*/
        getPermissionStreams(stream);
        //插入文档到设备发送文档
        if(deviceDoc == null) {
            DocClassification classification = classificationService.getByCode(SEND_CODE);
            if(classification == null)
                ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
            DocRelative docRelative = new DocRelative();
            docRelative.setDocId(docInfo.getDocId());
            docRelative.setClassificationId(classification.getClassificationId());
@@ -437,121 +262,8 @@
            }
        }
        //TODO
        //插入文件传输任务表
        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());
            }
        } else {
            return new ResponseResult(CommonCode.FAIL);
        }
        String size = FileUtilS.fileSizeNC(docFile.getFilePath(),docFile.getFileEncodeName());
        if (whether.equals("true") && !docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar") ) {
            //处理文件 è®°å½•并上报
            //1、 åˆ¤æ–­ç«¯å£æ˜¯å¦èƒ½å¤Ÿè®¿é—® æ–‡ä»¶è·¯å¾„加
            /*boolean btelnetPort =  TelnetUtil.telnetPort(serverIp,serverPort,10);
            if (!btelnetPort) {
                ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
            }*/
            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));
            Integer fileTxt = 0, fileNc =0;
            if (dncPassLog !=null) {
                fileTxt = dncPassLog.getSequenceNumber() + 1;
                fileNc = fileTxt + 1;
            } else {
                fileTxt =  1;
                fileNc = fileTxt + 1;
            }
            //处理文件名称  æ–‡ä»¶è·¯å¾„
            String sequence = String.format("%06d",fileTxt);
            String sequenceNc = String.format("%06d",fileNc);
            passInfoTxt.setSequenceNumber(fileTxt);
            passInfoTxt.setSequenceOrder(sequence);
            passInfoTxt.setCreateTime(dateFirst);
            System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME));
            passInfoTxt.setPassType("02");
            dncPassLogService.save(passInfoTxt);
            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);
            NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
            ncTxt.setEquipmentId(mdcEquipment.getEquipmentId());
            ncTxt.setFileNcName("02A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc);
            ncTxt.setFileTxtName("02A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequence);
            ncTxt.setFilePath(path + "/"+ mdcEquipment.getEquipmentId() + "/" );
            ncTxt.setOrigFileName(docFile.getFileName());
            ncTxt.setOrigFileSuffix(docFile.getFileSuffix());
            ncTxt.setFileAddOrDelete(1);
            String loFilePath = localFilePath + ncTxt.getFileTxtName() + ".nc";
//            String loFilePath = localFilePath + "\\" + ncTxt.getFileTxtName() + ".nc";
            try {
                String allList = new String();
                allList=(ncTxt.getFileTxtName()+"\n");
                allList+=(ncTxt.getFileNcName()+"\n");
                allList+=(ncTxt.getOrigFileName()+"\n");
                allList+=(ncTxt.getOrigFileSuffix()+"\n");
                allList+=(ncTxt.getFilePath()+"\n");
                allList+=(ncTxt.getEquipmentId()+"\n");
                allList+=(ncTxt.getFileAddOrDelete().toString()+"\n");
                // æ–‡ä»¶å¤§å°å­—节  ç¬¬äºŒè¡Œ å·¥æŽ§ç½‘进行文件分析
                allList+= (size+"\n");
                FileUtilS.fileWriterSql(loFilePath,allList);
                //文件解析重新规划
                //添加文件名字,第一行,
/*
                boolean copyFileNc = FileUtilS.copyFileNcIntegration(path + "/"+ deviceInfo.getDeviceNo() +"/send/" +
                                docFile.getFileName(),
                        localFilePath + "\\" + ncTxt.getFileNcName(),
                        docFile.getFileSuffix());
*/
                boolean copyFileNc = FileUtilS.copyFileUpName(path + "/"+ mdcEquipment.getEquipmentId() +"/send/" +
                                docFile.getFileName(),
                        localFilePath  + ncTxt.getFileNcName(),
//                        localFilePath + "\\" + ncTxt.getFileNcName(),
                        docFile.getFileSuffix(),"NC");
                if (!copyFileNc) {
                    FileUtilS.deleteNcFile(loFilePath);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        handleFileTransfer(mdcEquipment, docFile);
        handleFileProcessing(docFile, mdcEquipment, whether, localFilePath);
        synchronizedFlagService.updateFlag(2);
        return new ResponseResult(CommonCode.SUCCESS);
    }
@@ -848,4 +560,258 @@
        }
        return synchronizedFlagService.updateFlag(1);
    }
    //传参验证
    private void validateParams(AssignFileStream stream) {
        if (stream == null) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
        if (!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId())
                || !ValidateUtil.validateString(stream.getFileId()) || !ValidateUtil.validateString(stream.getAttributionType())) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
        if (!ValidateUtil.validateString(stream.getDeviceId())) {
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        }
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if (!ValidateUtil.validateString(userId)) {
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        }
    }
    //获取文件信息
    private DocInfo getDocInfo(AssignFileStream stream) {
        DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId());
        if (docInfo == null || docInfo.getDocStatus() == 3) {
            ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
        }
        return docInfo;
    }
    //获取文件
    private void handleExistingDeviceDoc(DocFile docFile, MdcEquipment mdcEquipment, String deviceId) {
        List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getEquipmentId());
        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);
            } else {
                DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 4, deviceId);
                boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 4, deviceId);
                if (!doc) {
                    ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE);
                }
            }
        }
    }
    //权限校验
    private List<PermissionStream> getPermissionStreams(AssignFileStream stream) {
        List<PermissionStream> permissionStreams = new ArrayList<>();
        if (stream.getAttributionType().equals("5")) {
            // å·¥åº
            ProcessStream processStream = processStreamService.getById(stream.getAttributionId());
            if (processStream == null) {
                ExceptionCast.cast(CommonCode.INVALID_PARAM);
            }
            stream.setProductId(processStream.getProductId());
            stream.setComponentId(processStream.getComponentId());
            stream.setPartsId(processStream.getPartsId());
            stream.setProcessId(processStream.getProcessId());
            permissionStreams = permissionStreamService
                    .getByProcessId(processStream.getProductId(), processStream.getComponentId(), processStream.getPartsId(), processStream.getProcessId());
        } else {
            // å·¥æ­¥
            WorkStep workStep = workStepService.getById(stream.getAttributionId());
            if (workStep == null) {
                ExceptionCast.cast(CommonCode.INVALID_PARAM);
            }
            stream.setProductId(workStep.getProductId());
            stream.setComponentId(workStep.getComponentId());
            stream.setPartsId(workStep.getPartsId());
            stream.setProcessId(workStep.getProcessId());
            stream.setStepId(workStep.getId());
            permissionStreams = permissionStreamService
                    .getByStepId(workStep.getProductId(), workStep.getComponentId(), workStep.getPartsId(), workStep.getProcessId(), workStep.getId());
        }
        if (permissionStreams == null || permissionStreams.isEmpty()) {
            ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
        }
        return permissionStreams;
    }
    //获取部门信息
    //todo ä¿®æ”¹
    private List<String> getDepartIds(List<PermissionStream> permissionStreams, String userId) {
        Map<String, Department> map = departmentService.getMapByUserId(userId);
        List<String> departIds = permissionStreams.stream()
                .filter(item -> map.containsKey(item.getDepartId()))
                .map(PermissionStream::getDepartId)
                .collect(Collectors.toList());
        if (departIds.isEmpty()) {
            ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM);
        }
        return departIds;
    }
    //获取多个部门的审批人 åŽ»é‡
    private List<String> getUserIdList(List<String> departIds) {
        List<String> userIdList = definitionService.getByDepartIds(departIds);
        if (userIdList == null || userIdList.isEmpty()) {
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        }
        return userIdList;
    }
    //封装数据
    private void saveBusinessObject(AssignFileStream stream, String userId) {
        String streamId = IdWorker.getIdStr();
        stream.setStreamId(streamId);
        stream.setApplyUserId(userId);
        stream.setApplyTime(DateUtil.getNow());
        stream.setStatus(1);
        boolean b = super.save(stream);
        if (!b) {
            ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
        }
    }
    //开始工作流
    private ProcessInstance startProcessInstance(AssignFileStream stream, List<String> userIdList) {
        String approveUsers = String.join(",", userIdList);
        Map<String, Object> avariableMap = new HashMap<>();
        avariableMap.put(APPLY_VARIABLE, stream.getApplyUserId());
        avariableMap.put(APPROVE_VARIABLE, approveUsers);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, stream.getStreamId(), avariableMap);
        if (processInstance == null) {
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        }
        return processInstance;
    }
    //拾取任务
    private void completeTask(ProcessInstance processInstance, String userId) {
        Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId)
                .processInstanceId(processInstance.getId()).singleResult();
        if (task == null) {
            ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
        }
        taskService.complete(task.getId());
    }
    //获取设备
    private MdcEquipment getMdcEquipment(AssignFileStream stream) {
        MdcEquipment mdcEquipment = iMdcEquipmentService.getById(stream.getDeviceId());
        if (mdcEquipment == null) {
            ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
        }
        return mdcEquipment;
    }
    //获取文件
    private DocFile getDocFile(AssignFileStream stream) {
        DocFile docFile = docFileService.getById(stream.getFileId());
        if (docFile == null) {
            ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
        }
        return docFile;
    }
    //插入文件传输任务表
    private void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) {
        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());
            }
        } else {
            throw new RuntimeException("文件传输路径获取失败");
        }
    }
    //封装处理文件
    private void handleFileProcessing(DocFile docFile, MdcEquipment mdcEquipment, String whether, String localFilePath) {
        if (whether.equals("true") && !docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) {
            String size = FileUtilS.fileSizeNC(docFile.getFilePath(), docFile.getFileEncodeName());
            List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
            if (strings != null && !strings.isEmpty()) {
                String path = StringUtils.join(strings.toArray(), "/");
                Date dateFirst = DateUtil.getNow();
                DncPassLog passInfoTxt = new DncPassLog();
                passInfoTxt.setDayTime(DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY));
                DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY));
                Integer fileTxt = 0, fileNc = 0;
                if (dncPassLog != null) {
                    fileTxt = dncPassLog.getSequenceNumber() + 1;
                    fileNc = fileTxt + 1;
                } else {
                    fileTxt = 1;
                    fileNc = fileTxt + 1;
                }
                String sequence = String.format("%06d", fileTxt);
                String sequenceNc = String.format("%06d", fileNc);
                passInfoTxt.setSequenceNumber(fileTxt);
                passInfoTxt.setSequenceOrder(sequence);
                passInfoTxt.setCreateTime(dateFirst);
                passInfoTxt.setPassType("02");
                dncPassLogService.save(passInfoTxt);
                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);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
                dncPassLogService.save(passInfoNc);
                NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
                ncTxt.setEquipmentId(mdcEquipment.getEquipmentId());
                ncTxt.setFileNcName("02A" + DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY) + sequenceNc);
                ncTxt.setFileTxtName("02A" + DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY) + sequence);
                ncTxt.setFilePath(path + "/" + mdcEquipment.getEquipmentId() + "/");
                ncTxt.setOrigFileName(docFile.getFileName());
                ncTxt.setOrigFileSuffix(docFile.getFileSuffix());
                ncTxt.setFileAddOrDelete(1);
                String loFilePath = localFilePath + ncTxt.getFileTxtName() + ".nc";
                try {
                    String allList = ncTxt.getFileTxtName() + "\n"
                            + ncTxt.getFileNcName() + "\n"
                            + ncTxt.getOrigFileName() + "\n"
                            + ncTxt.getOrigFileSuffix() + "\n"
                            + ncTxt.getFilePath() + "\n"
                            + ncTxt.getEquipmentId() + "\n"
                            + ncTxt.getFileAddOrDelete().toString() + "\n"
                            + size + "\n";
                    FileUtilS.fileWriterSql(loFilePath, allList);
                    boolean copyFileNc = FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" +
                                    docFile.getFileName(),
                            localFilePath + ncTxt.getFileNcName(),
                            docFile.getFileSuffix(), "NC");
                    if (!copyFileNc) {
                        FileUtilS.deleteNcFile(loFilePath);
                    }
                } catch (IOException e) {
                    throw new RuntimeException("文件处理失败", e);
                }
            }
        }
    }
}
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IPermissionStreamService.java
@@ -86,6 +86,17 @@
    List<PermissionStream> getByProcessId(String productId, String componentId, String partsId, String processId);
    /**
     * æ ¹æ®å·¥æ­¥ç¼–号查找部门权限
     * @param productId
     * @param componentId
     * @param partsId
     * @param processId
     * @param stepId
     * @return
     */
    List<PermissionStream> getByStepId(String productId, String componentId, String partsId,String processId,String stepId);
    /**
     * åˆ é™¤ç”¨æˆ·æƒé™
     * @param productId
     * @return
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceGroupPermissionServiceImpl.java
@@ -144,10 +144,6 @@
                permissionStreamList.add(stream);
            }
        });
        //校验清空设备分组权限操作
        List<MdcUserProduction> existList = mdcUserProductionService.list(new QueryWrapper<MdcUserProduction>().eq("pro_id",mdcProduction.getId()));
        if(existList.size() <= mdcUserProductions.size())
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_USER_NONE);
        if(!mdcUserProductions.isEmpty()) {
            boolean b = mdcUserProductionService.removeByCollection(mdcUserProductions);
            if(!b) {
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
@@ -298,14 +298,14 @@
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
            //获取分组下所有的子分组
            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
            List<MdcProduction> childrenList = mdcProductionService.recursionChildrenByPid(mdcProduction.getId());
            List<String> childrenIds = new ArrayList<>();
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    childrenIds.add(item.getId());
                    boolean b = checkDevicePerm(1, item.getId());
                    if(b) {
                        b = deviceGroupPermissionService.assignAddUser(mdcProduction, userList);
                        b = deviceGroupPermissionService.assignAddUser(item, userList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }
@@ -488,14 +488,14 @@
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
            //获取分组下所有的子分组
            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
            List<MdcProduction> childrenList = mdcProductionService.recursionChildrenByPid(mdcProduction.getId());
            List<String> childrenIds = new ArrayList<>();
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    childrenIds.add(item.getId());
                    boolean b = checkDevicePerm(1, item.getId());
                    if(b) {
                        b = deviceGroupPermissionService.assignRemoveUser(mdcProduction, userList);
                        b = deviceGroupPermissionService.assignRemoveUser(item, userList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PermissionStreamServiceImpl.java
@@ -138,12 +138,24 @@
    @Override
    public List<PermissionStream> getByProcessId(String productId, String componentId, String partsId, String processId){
        if(!ValidateUtil.validateString(productId) || !ValidateUtil.validateString(componentId)
                || !ValidateUtil.validateString(partsId) || !ValidateUtil.validateString(processId))
        List<PermissionStream> list = super.lambdaQuery()
                .eq(StrUtil.isNotEmpty(productId),PermissionStream::getProductId, productId)
                .eq(StrUtil.isNotEmpty(componentId),PermissionStream::getComponentId, componentId)
                .eq(StrUtil.isNotEmpty(partsId),PermissionStream::getPartsId, partsId)
                .eq(StrUtil.isNotEmpty(processId),PermissionStream::getProcessId,processId).list();
        if(list == null || list.isEmpty())
            return null;
        List<PermissionStream> list = super.lambdaQuery().eq(PermissionStream::getProductId, productId).
                isNull(PermissionStream::getUserId).eq(PermissionStream::getComponentId, componentId)
                .eq(PermissionStream::getPartsId, partsId).eq(PermissionStream::getProcessId,processId).list();
        return list;
    }
    @Override
    public List<PermissionStream> getByStepId(String productId, String componentId, String partsId,String processId,String stepId){
        List<PermissionStream> list = super.lambdaQuery()
                .eq(StrUtil.isNotEmpty(productId),PermissionStream::getProductId, productId)
                .eq(StrUtil.isNotEmpty(componentId),PermissionStream::getComponentId, componentId)
                .eq(StrUtil.isNotEmpty(partsId),PermissionStream::getPartsId, partsId)
                .eq(StrUtil.isNotEmpty(processId),PermissionStream::getProcessId,processId)
                .eq(StrUtil.isNotEmpty(stepId),PermissionStream::getStepId,stepId).list();
        if(list == null || list.isEmpty())
            return null;
        return list;
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -25,6 +25,7 @@
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.DncCopyEquipment;
import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil;
import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
import org.jeecg.modules.mdc.vo.*;
@@ -34,14 +35,19 @@
import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper;
import org.jeecg.modules.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -99,6 +105,9 @@
    @Resource
    private DncDevicePermissionMapper dncDevicePermissionMapper;
    @Value("${fileNCPath}")
    private String fileNCPath;
    @Override
@@ -194,6 +203,14 @@
                    break;
            }
        }
        //平移设备目录下现有结构与文件
        //获取原有结构
        String OldPath="";
        String NewPath="";
        List<String> OldStrings=mdcProductionService.findListParentTreeAll(mdcEquipment.getId());
        if (OldStrings != null && !OldStrings.isEmpty()) {
            OldPath = fileNCPath+"/"+StringUtils.join(OldStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId();
        }
        //step.1 ä¿®æ”¹è®¾å¤‡åŸºç¡€ä¿¡æ¯
        this.updateById(mdcEquipment);
        //step.2 ä¿®æ”¹éƒ¨é—¨
@@ -226,6 +243,13 @@
                mdcProductionEquipmentMapper.insert(productionEquipment);
            }
        }
        List<String> NewStrings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId());
        if (NewStrings != null && !NewStrings.isEmpty()) {
            NewPath = fileNCPath+"/"+StringUtils.join(NewStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId();
        }
        // å¹³ç§»OldPath下的文件到NewPath下
        DncCopyEquipment.CopyEquipmentPath(OldPath,NewPath);
        //保存设备对应的产线权限
        addDevicePermission(mdcEquipment);
        //step.4 ä¿®æ”¹è®¾å¤‡æƒé™
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DncCopyEquipment.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,45 @@
package org.jeecg.modules.mdc.util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
/***
 * DNC平移设备车间工具类
 */
public class DncCopyEquipment {
    public static void CopyEquipmentPath(String OldPath,String NewPath){
        if (!OldPath.equals(NewPath)) {
            File oldDir = new File(OldPath);
            File newDir = new File(NewPath);
            // åˆ›å»ºæ–°ç›®å½•
            if (!newDir.exists()) {
                if (!newDir.mkdirs()) {
                    System.err.println("无法创建新目录: " + NewPath);
                    return;
                }
            }
            // éåŽ†æ—§ç›®å½•ä¸‹çš„æ‰€æœ‰æ–‡ä»¶å’Œå­ç›®å½•
            if (oldDir.exists() && oldDir.isDirectory()) {
                File[] files = oldDir.listFiles();
                if (files != null) {
                    for (File file : files) {
                        try {
                            File destFile = new File(newDir, file.getName());
                            // å¤åˆ¶æ–‡ä»¶
                            Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                        } catch (IOException e) {
                            System.err.println("文件平移过程中出现错误: " + e.getMessage());
                        }
                    }
                }
            }
            // åˆ é™¤æ—§ç›®å½•
            if (!oldDir.delete()) {
                System.err.println("删除原目录失败: " + oldDir);
            }
        }
    }
}
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcProductionService.java
@@ -61,6 +61,11 @@
    List<MdcProduction> queryProdByPid(String pid);
    /**
     * é€’归查询所有子节点
     */
    List<MdcProduction> recursionChildrenByPid(String pid);
    /**
     * æ ¹æ®ç”¨æˆ·id获取产线下拉树选项
     */
    List<ProductionIdModel> loadProductionTreeOptions(String userId);
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcProductionServiceImpl.java
@@ -196,6 +196,15 @@
    }
    /**
     * é€’归查询所有子节点
     */
    @Override
    public List<MdcProduction> recursionChildrenByPid(String pid){
        List<String> ids=this.recursionChildren(pid);
        return super.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).in(MdcProduction::getId, ids));
    }
    /**
     * æ ¹æ®ç”¨æˆ·id获取产线下拉树选项
     */
    @Override
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcUserProductionServiceImpl.java
@@ -131,7 +131,7 @@
    @Override
    public MdcUserProduction getByUserIdAndGroupId(String userId, String proId){
        if(StrUtil.isNotEmpty(userId) || !StrUtil.isNotEmpty(proId))
        if(StrUtil.isEmpty(userId) || StrUtil.isEmpty(proId))
            return null;
        List<MdcUserProduction> list = super.lambdaQuery().eq(MdcUserProduction::getUserId, userId).eq(MdcUserProduction::getProId, proId).list();
        if(list == null || list.isEmpty())