yangys
2025-08-12 8a93ac3f06f3a61af3186a333fcba2628dd15f11
插入注释调整
已删除2个文件
已添加2个文件
已修改2个文件
502 ■■■■■ 文件已修改
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java 209 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MachineAnnotationService.java 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/ProgramAnnotationService.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/test/java/org/springblade/mdm/program/service/MachineAnnotationServiceTest.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/test/java/org/springblade/mdm/program/service/ProgramAnnotationServiceTest.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java
@@ -14,7 +14,6 @@
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.springblade.core.launch.constant.FlowConstant;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
@@ -46,9 +45,6 @@
    private final TaskService taskService;
    private final HistoryService historyService;
    private final IUserClient userClient;
    private final ProcessProgRefService processProgRefService;
    private final ApproveRecordService approveRecordService;
    private final NcProgramService ncProgramService;
    private final FlowProgramFileService flowProgramFileService;
    /**
     * æŸ¥è¯¢æˆ‘的流程(个人待办列表)
@@ -108,146 +104,6 @@
            todoQuery.endOr();
        }
    }
    /*
    @Override
    public IPage<BladeFlow> selectSendPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
        String taskUser = TaskUtil.getTaskUser();
        List<BladeFlow> flowList = new LinkedList<>();
        HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc();
        if (bladeFlow.getCategory() != null) {
            historyQuery.processDefinitionCategory(bladeFlow.getCategory());
        }
        if (bladeFlow.getProcessDefinitionName() != null) {
            historyQuery.processDefinitionName(bladeFlow.getProcessDefinitionName());
        }
        if (bladeFlow.getBeginDate() != null) {
            historyQuery.startedAfter(bladeFlow.getBeginDate());
        }
        if (bladeFlow.getEndDate() != null) {
            historyQuery.startedBefore(bladeFlow.getEndDate());
        }
        // æŸ¥è¯¢åˆ—表
        List<HistoricProcessInstance> historyList = historyQuery.listPage(Func.toInt((page.getCurrent() - 1) * page.getSize()), Func.toInt(page.getSize()));
        historyList.forEach(historicProcessInstance -> {
            BladeFlow flow = new BladeFlow();
            // historicProcessInstance
            flow.setCreateTime(historicProcessInstance.getStartTime());
            flow.setEndTime(historicProcessInstance.getEndTime());
            flow.setVariables(historicProcessInstance.getProcessVariables());
            String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
            if (businessKey.length > 1) {
                flow.setBusinessTable(businessKey[0]);
                flow.setBusinessId(businessKey[1]);
            }
            flow.setHistoryActivityName(historicProcessInstance.getName());
            flow.setProcessInstanceId(historicProcessInstance.getId());
            flow.setHistoryProcessInstanceId(historicProcessInstance.getId());
            // ProcessDefinition
            FlowProcess processDefinition = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
            flow.setProcessDefinitionId(processDefinition.getId());
            flow.setProcessDefinitionName(processDefinition.getName());
            flow.setProcessDefinitionVersion(processDefinition.getVersion());
            flow.setProcessDefinitionKey(processDefinition.getKey());
            flow.setCategory(processDefinition.getCategory());
            flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
            flow.setProcessInstanceId(historicProcessInstance.getId());
            // HistoricTaskInstance
            List<HistoricTaskInstance> historyTasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(historicProcessInstance.getId()).orderByHistoricTaskInstanceEndTime().desc().list();
            if (Func.isNotEmpty(historyTasks)) {
                HistoricTaskInstance historyTask = historyTasks.iterator().next();
                flow.setTaskId(historyTask.getId());
                flow.setTaskName(historyTask.getName());
                flow.setTaskDefinitionKey(historyTask.getTaskDefinitionKey());
            }
            // Status
            if (historicProcessInstance.getEndActivityId() != null) {
                flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED);
            } else {
                flow.setProcessIsFinished(FlowEngineConstant.STATUS_UNFINISHED);
            }
            flow.setStatus(FlowEngineConstant.STATUS_FINISH);
            flowList.add(flow);
        });
        // è®¡ç®—总数
        long count = historyQuery.count();
        // è®¾ç½®æ€»æ•°
        page.setTotal(count);
        page.setRecords(flowList);
        return page;
    }
    @Override
    public IPage<BladeFlow> selectDonePage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
        String taskUser = TaskUtil.getTaskUser();
        List<BladeFlow> flowList = new LinkedList<>();
        HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished()
            .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();
        if (bladeFlow.getCategory() != null) {
            doneQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
        }
        if (bladeFlow.getProcessDefinitionName() != null) {
            doneQuery.processDefinitionName(bladeFlow.getProcessDefinitionName());
        }
        if (bladeFlow.getBeginDate() != null) {
            doneQuery.taskCompletedAfter(bladeFlow.getBeginDate());
        }
        if (bladeFlow.getEndDate() != null) {
            doneQuery.taskCompletedBefore(bladeFlow.getEndDate());
        }
        // æŸ¥è¯¢åˆ—表
        List<HistoricTaskInstance> doneList = doneQuery.listPage(Func.toInt((page.getCurrent() - 1) * page.getSize()), Func.toInt(page.getSize()));
        doneList.forEach(historicTaskInstance -> {
            BladeFlow flow = new BladeFlow();
            flow.setTaskId(historicTaskInstance.getId());
            flow.setTaskDefinitionKey(historicTaskInstance.getTaskDefinitionKey());
            flow.setTaskName(historicTaskInstance.getName());
            flow.setAssignee(historicTaskInstance.getAssignee());
            flow.setCreateTime(historicTaskInstance.getCreateTime());
            flow.setExecutionId(historicTaskInstance.getExecutionId());
            flow.setHistoryTaskEndTime(historicTaskInstance.getEndTime());
            flow.setVariables(historicTaskInstance.getProcessVariables());
            FlowProcess processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
            flow.setProcessDefinitionId(processDefinition.getId());
            flow.setProcessDefinitionName(processDefinition.getName());
            flow.setProcessDefinitionKey(processDefinition.getKey());
            flow.setProcessDefinitionVersion(processDefinition.getVersion());
            flow.setCategory(processDefinition.getCategory());
            flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
            flow.setProcessInstanceId(historicTaskInstance.getProcessInstanceId());
            flow.setHistoryProcessInstanceId(historicTaskInstance.getProcessInstanceId());
            HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance((historicTaskInstance.getProcessInstanceId()));
            if (Func.isNotEmpty(historicProcessInstance)) {
                String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
                flow.setBusinessTable(businessKey[0]);
                flow.setBusinessId(businessKey[1]);
                if (historicProcessInstance.getEndActivityId() != null) {
                    flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED);
                } else {
                    flow.setProcessIsFinished(FlowEngineConstant.STATUS_UNFINISHED);
                }
            }
            flow.setStatus(FlowEngineConstant.STATUS_FINISH);
            flowList.add(flow);
        });
        // è®¡ç®—总数
        long count = doneQuery.count();
        // è®¾ç½®æ€»æ•°
        page.setTotal(count);
        page.setRecords(flowList);
        return page;
    }
    */
    /**
     * æž„建流程
     *
@@ -288,8 +144,6 @@
            flow.setProcessDefinitionId(task.getProcessDefinitionId());
            flow.setFile(getFileString(task.getProcessInstanceId()));
            //flow.setProcessDefinitionKey(processDefinition.getKey());
            //flow.setProcessDefinitionVersion(processDefinition.getVersion());
            flow.setProcessInstanceId(task.getProcessInstanceId());
            // æŸ¥è¯¢æµç¨‹å®žä¾‹åˆ›å»ºæ—¶é—´
@@ -530,47 +384,15 @@
    }
    /**
     * æŸ¥è¯¢å·²åŠžä»»åŠ¡åˆ†é¡µæ•°æ®
     * ä¸ªäººå·²åŠž(已完成任务)
     * @param page
     * @param processDefinitionKey
     * @param createTimeBegin
     * @param createTimeEnd
     * @param keyword
     * @return
     */
    /*
    public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) {
        String userId = "" + AuthUtil.getUserId();
        List<FlowVO> flowList = new LinkedList<>();
        HistoricTaskInstanceQuery doneTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables();
        //TaskQuery todoQuery =  historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables()
        if (Func.isNotEmpty(createTimeBegin)) {
            doneTaskQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin));
        }
        if (Func.isNotEmpty(createTimeEnd)) {
            doneTaskQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd));
            //todoQuery.taskInProgressStartTimeBefore(DateUtil.toDate(createTimeEnd));
        }
        if (Func.isNotEmpty(keyword)) {
            addKeywordCondition(doneTaskQuery, keyword);
        }
        todoQuery.orderByTaskCreateTime().desc();
        // æž„建列表数据
        FlowVO bladeFlow = new FlowVO();
        buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());
        // è®¡ç®—总数
        long count = todoQuery.count();
        // è®¾ç½®æ€»æ•°
        page.setTotal(count);
        // è®¾ç½®æ•°æ®
        page.setRecords(flowList);
        return page;
    }*/
    public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime completeTimeBegin, LocalDateTime createTimeEnd, String keyword) {
    public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) {
        String userId = "" + AuthUtil.getUserId();
        HistoricTaskInstanceQuery doneTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables();
@@ -578,13 +400,26 @@
        if(Func.isNotEmpty(processDefinitionKey)) {
            doneTaskQuery.processDefinitionKey(processDefinitionKey);
        }
        if(completeTimeBegin!=null) {
            doneTaskQuery.taskCompletedAfter(DateUtil.toDate(completeTimeBegin));
        if(createTimeBegin!=null) {
            Date after = DateUtil.toDate(createTimeBegin);
            doneTaskQuery.taskCreatedAfter(after);
            //doneTaskQuery.taskCreatedOn(after);
            //doneTaskQuery.taskInProgressStartTimeAfter(after);
        }
        if(createTimeEnd!=null) {
            doneTaskQuery.taskCompletedBefore(DateUtil.toDate(createTimeEnd));
            Date before = DateUtil.toDate(createTimeEnd);
            doneTaskQuery.taskCreatedBefore(before);
            //doneTaskQuery.taskInProgressStartTimeBefore(before);
        }
        //QueryProperty
        if (Func.isNotEmpty(keyword)) {
            addKeywordCondition(doneTaskQuery, keyword);
        }
        doneTaskQuery.orderByTaskCreateTime().desc(); // æŒ‰ç»“束时间降序排列
        page.setTotal(doneTaskQuery.count());
@@ -594,12 +429,10 @@
            .listPage((int)firstResult, (int)page.getSize());
        List<FlowVO> records = new LinkedList<>();
        //Map<String,String> processDefKeyMap = new HashMap<>();//使用TaskDefinitionKey缓存ProcessDefinitionKey
        //Map<String,String> processDefNameMap = new HashMap<>();//使用TaskDefinitionKey缓存ProcessDefinitionName
        Map<String,String> startUserMap = new HashMap<>();//使用userId缓存其姓名
        for(HistoricTaskInstance hisTask : processes) {
            FlowVO vo = new FlowVO();
            HistoricProcessInstance processInstance = historyService
                .createHistoricProcessInstanceQuery()
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MachineAnnotationService.java
ÎļþÒÑɾ³ý
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java
@@ -58,6 +58,7 @@
    private final NcNodeService ncNodeService;
    private final OssTemplate ossTemplate;
    private final FlowProgramFileService flowProgramFileService;
    private final ProgramAnnotationService programAnnotationService;
    //public static final String PROGRAM_JSON_FILE = "exp_mdm_nc_program.json";
    //public static final String NODE_JSON_FILE = "exp_mdm_nc_node.json";
    //public static final String APPROVE_RECORD_JSON_FILE = "exp_mdm_approve_record.json";
@@ -121,7 +122,7 @@
        }else if(programPackageNode.hasCured()){
            status = "GH";
        }
        List<Dict> annotationList = getAnnotionList();
        List<Dict> annotationList = programAnnotationService.getAnnotionList();
        for (NcNode node : programNodes) {
            String filePathInZip = packageFolder + node.getName();
            programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId());
@@ -157,7 +158,7 @@
     */
    InputStream addSendDirAnnotation(InputStream inputStream,Machine machine,List<Dict> annotationList) throws IOException {
        //检测第二行是否是路径
        String annotationText = generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList);
        String annotationText = programAnnotationService.generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList);
        //TODO æ”¹åˆ¤æ–­è¡Œå†…容
        return FileContentUtil.insertLine(inputStream,1,annotationText);
@@ -173,7 +174,8 @@
     * @throws IOException
     */
    InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException {
        String annoText= generateAnnotation(status,machine.getMachineGroupCode(),annotationList);
        String annoText= programAnnotationService.generateAnnotation(status,machine.getMachineGroupCode(),annotationList);
        return FileContentUtil.insertLine(inputStream,2,annoText);
    }
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/ProgramAnnotationService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,96 @@
package org.springblade.mdm.program.service;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.tool.api.R;
import org.springblade.system.feign.IDictClient;
import org.springblade.system.pojo.entity.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
 * ä¸‹å‘/回传程序统计
 *
 * @author yangys
 */
@Slf4j
@Service
public class ProgramAnnotationService {
    @Autowired
    private IDictClient dictClient;
    private static final String DEFAULT_ANNOTATION_SETTING = "(,)";
    public static final String ANNOTATION_DICT = "machine_annotation";
    public List<Dict> getAnnotionList(){
        List<Dict> annotationList;
        R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT);
        if(dictsResult.isSuccess()) {
            annotationList = dictsResult.getData();
        }else{
            annotationList = Collections.emptyList();
        }
        return annotationList;
    }
    /**
     * åˆ¤æ–­ä¸€è¡Œæ–‡æœ¬æ˜¯å¦æ˜¯æ³¨é‡Š
     * @param line
     * @param annotationList æ³¨é‡Šæ³¨é‡Šå­—典项列表
     * @return
     */
    public boolean isAnnotation(String line,String machineGroupCode,List<Dict> annotationList){
        boolean isAnno = false;
        Optional<Dict> dictOpt = annotationList.stream().filter(dict -> {return dict.getDictKey().equals(machineGroupCode);}).findFirst();
        String annotationSetting = DEFAULT_ANNOTATION_SETTING;
        if(dictOpt.isPresent()) {
            annotationSetting = dictOpt.get().getRemark();
        }
        String begin = "";
        String end = "";
        String[] arr = annotationSetting.split(",");
        if(arr.length == 2){
            begin = arr[0];
            end = arr[1];
        }
        isAnno = StringUtils.startsWith(line,begin) && StringUtils.endsWith(line,end);
        return isAnno;
    }
    public String generateAnnotation(String oriTest,String machineGroupCode,List<Dict> annotationList) {
        String annotation = oriTest;
        String begin = "(";
        String end = ")";
        Optional<Dict> dictOpt = annotationList.stream().filter(dict -> {return dict.getDictKey().equals(machineGroupCode);}).findFirst();
        String annotationSetting = DEFAULT_ANNOTATION_SETTING;
        if(dictOpt.isPresent()) {
            annotationSetting = dictOpt.get().getRemark();
        }
        String[] arr = StringUtils.split(annotationSetting,",");
        if(arr.length == 2){
            begin = arr[0];
            end = arr[1];
        }else if(arr.length == 1){
            begin = begin = arr[0];
            end = "";
        }
        annotation = begin + oriTest + end;
        return annotation;
    }
}
blade-service/blade-mdm/src/test/java/org/springblade/mdm/program/service/MachineAnnotationServiceTest.java
ÎļþÒÑɾ³ý
blade-service/blade-mdm/src/test/java/org/springblade/mdm/program/service/ProgramAnnotationServiceTest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,52 @@
package org.springblade.mdm.program.service;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springblade.system.pojo.entity.Dict;
import java.util.Arrays;
import java.util.List;
public class ProgramAnnotationServiceTest {
    @Test
    public void testIsAnnotation(){
        ProgramAnnotationService s = new ProgramAnnotationService();
        Dict fanucDict = new Dict();
        fanucDict.setCode("machine_annotation");
        fanucDict.setDictKey("FANUC");
        fanucDict.setRemark("(,)");
        Dict xmz = new Dict();
        xmz.setCode("machine_annotation");
        xmz.setDictKey("XIMENZI");
        xmz.setRemark("*-,");
        List<Dict> dictList = Arrays.asList(fanucDict, xmz);
        Assertions.assertTrue(s.isAnnotation("(abc)","FANUC", dictList));
        Assertions.assertFalse(s.isAnnotation("*-","FANUC",dictList));
        Assertions.assertTrue(s.isAnnotation("*-","XIMENZI", dictList));
    }
    @Test
    public void testIsAnnotation2(){
        ProgramAnnotationService s = new ProgramAnnotationService();
        Dict fanucDict = new Dict();
        fanucDict.setCode("machine_annotation");
        fanucDict.setDictKey("FANUC");
        fanucDict.setRemark("(,)");
        Dict xmz = new Dict();
        xmz.setCode("machine_annotation");
        xmz.setDictKey("XIMENZI");
        xmz.setRemark("*-,");
        List<Dict> dictList = Arrays.asList(fanucDict, xmz);
        Assertions.assertEquals("(A)",s.generateAnnotation("A","FANUC",dictList));
        Assertions.assertEquals("*-A",s.generateAnnotation("A","XIMENZI",dictList));
    }
}