| | |
| | | .eq(ProduceDivision::getTeamLeaderId,division.getTeamLeaderId()).count()>0; |
| | | } |
| | | |
| | | public ProduceDivision getByDrawingNo(String drawingNo){ |
| | | List<ProduceDivision> divs = lambdaQuery().eq(ProduceDivision::getDrawingNo, drawingNo).list(); |
| | | if(divs.isEmpty()){ |
| | | return null; |
| | | }else{ |
| | | return divs.get(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å¤å²é¶ä»¶å·äºä¸»ç®¡ç¼å¶è·ååå·¥è¡¨æ°æ® å¾å·->å¤å²æ°æ®ï¼ç¼å¶ï¼ -> 主å¶åå·¥è¡¨æ°æ® |
| | |
| | | public ProduceDivision getByDrawingNoWithQinzhe(String drawingNo){ |
| | | QinzheFgb qinzheFgb = qinzheFgbService.getByLjh(drawingNo); |
| | | if(qinzheFgb == null){ |
| | | throw new ServiceException("æªæ¾å°é¶ç»ä»¶å·"); |
| | | throw new ServiceException("æªæ¾å°é¶ç»ä»¶å·:"+drawingNo); |
| | | } |
| | | |
| | | Long programmerId = tUserService.getUserIdByName(qinzheFgb.getZggy()); |
| | |
| | | if(division == null){ |
| | | throw new ServiceException("主å¶å工表æ å·¥èºå"+qinzheFgb.getZggy()+"对åºçæ°æ®"); |
| | | } |
| | | List<ProduceDivision> divs = lambdaQuery().eq(ProduceDivision::getDrawingNo, drawingNo).list(); |
| | | if(divs.isEmpty()){ |
| | | return null; |
| | | }else{ |
| | | return divs.get(0); |
| | | } |
| | | |
| | | return division; |
| | | } |
| | | } |
| | |
| | | /** |
| | | * ä»»å¡è½¦é´ |
| | | */ |
| | | public static final String WORK_SHOP = "workShop"; |
| | | public static final String WORKSHOP = "workshop"; |
| | | |
| | | /** |
| | | * å离åå· |
| | |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.excution.StartDispatcher; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | |
| | | import org.springblade.mdm.flow.vo.ReplaceUploadVO; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springblade.mdm.program.service.ProgramFlowStatusQueryService; |
| | | import org.springblade.mdm.program.vo.NcNodeVO; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | @RequestMapping("/flow/replace") |
| | | @Tag(name = "æ¿æ¢æµç¨", description = "æ¿æ¢æµç¨") |
| | | public class ReplaceFlowController { |
| | | |
| | | private final TaskService taskService; |
| | | private final RuntimeService runtimeService; |
| | | |
| | | private final ApproveRecordService approveRecordService; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final DefaultFlowCompleteService defaultFlowCompleteService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | private final ProduceDivisionService produceDivisionService; |
| | | private final ReplaceFlowService replaceFlowService; |
| | | |
| | | @PostMapping("/pre") |
| | |
| | | } |
| | | return R.success(); |
| | | } |
| | | |
| | | @GetMapping("/default-assignees") |
| | | @Operation(summary = "é»è®¤çå®¡æ ¸ç¨æ·", description = "åå¤ç¨åºæ¿æ¢æµç¨ï¼æå¼çé¢ä¹åè°ç¨ï¼è°ç¨ä¹åä¼åå§åæä»¶å表,") |
| | | public R<ProduceDivision> defaultAssignees(@Parameter(description = "é¶ç»ä»¶å·") String drawingNo) { |
| | | return R.data(produceDivisionService.getByDrawingNoWithQinzhe(drawingNo)); |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | //private final ProduceDivisionMapper divMapper; |
| | | private final ProduceDivisionService divService; |
| | | |
| | | /* |
| | | public Map<String,Object> autoAssignUsers(TaskAssignVO startVO){ |
| | | LambdaQueryWrapper<ProduceDivision> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(ProduceDivision::getDrawingNo,startVO.getDrawingNo()); |
| | |
| | | result.put(FlowContants.SENIOR,division.getSeniorId()); |
| | | |
| | | return result; |
| | | } |
| | | }*/ |
| | | } |
| | |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | //public static final String PROCESS_KEY = "dispatch"; |
| | | private final ProduceDivisionService produceDivisionService; |
| | | |
| | | |
| | | /** |
| | | * å¯å¨æ´¾å·¥æµç¨ |
| | |
| | | */ |
| | | @Transactional |
| | | public String start(TaskAssignVO startVO){ |
| | | |
| | | Map<String,Object> preAssignee = autoAssignUsersService.autoAssignUsers(startVO); |
| | | Map<String, Object> vars = new HashMap<>(preAssignee); |
| | | vars.put(FlowContants.ASSIGNEE,preAssignee.get(FlowContants.TEAM_LEADER));//第ä¸ä¸ªå®¡æ¹ç¨æ·ï¼ç»é¿ |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | //Map<String,Object> preAssignee = autoAssignUsersService.autoAssignUsers(startVO); |
| | | this.putDefaultAssignees(vars,startVO.getDrawingNo()); |
| | | |
| | | vars.put(FlowContants.TITLE,startVO.getTitle()); |
| | | //æºåºç¼å· |
| | | vars.put(FlowContants.MACHINE_CODE,startVO.getMachineCode()); |
| | | String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(startVO.getMachineCode()); |
| | | vars.put("workshop",workshop); |
| | | vars.put(FlowContants.WORKSHOP,workshop); |
| | | //æºåºåå· |
| | | vars.put(FlowContants.MACHINE_MODE,startVO.getMachineMode()); |
| | | |
| | | |
| | | vars.put(FlowContants.PROCESS_NO,startVO.getProcessNo()); |
| | | vars.put(FlowContants.PROCESS_NAME,startVO.getProcessName()); |
| | |
| | | if(vars.getOrDefault(FlowContants.HAS_CURED_PROGRAM,FlowContants.N).equals(FlowContants.Y)){ |
| | | myProcessName = "åºåä¸åæµç¨"; |
| | | } |
| | | if(StringUtils.isNotBlank(startVO.getDeviation()) ){ |
| | | myProcessName = "å离å"; |
| | | } |
| | | vars.put(FlowContants.MY_PROCESS_NAME, myProcessName); |
| | | |
| | | String businessKey = "0";//ä¸å¡è¡¨key |
| | |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åæåºåç¨åºå
åèç¹ï¼å¤å¶ä¸ä¸ªï¼èµäºæ°çæµç¨å®ä¾id |
| | | * @param programPkg åæåºåçç¨åºå
åèç¹ |
| | | * @param processInstanceId æµç¨å®ä¾id |
| | | * å°é»è®¤å®¡æ¹ç¨æ·æ¾å
¥mapä¸ |
| | | * @param vars å¯å¨æµç¨çåémap |
| | | * @param drawingNo é¶ç»ä»¶å· |
| | | */ |
| | | void putDefaultAssignees(Map<String, Object> vars,String drawingNo){ |
| | | ProduceDivision div = produceDivisionService.getByDrawingNoWithQinzhe(drawingNo); |
| | | vars.put(FlowContants.TEAM_LEADER,div.getTeamLeaderId()); |
| | | vars.put(FlowContants.PROGRAMMER,div.getProgrammerId()); |
| | | vars.put(FlowContants.CHECKER,div.getCheckerId()); |
| | | vars.put(FlowContants.SENIOR,div.getSeniorId()); |
| | | |
| | | void cloneNodes(NcNode programPkg,String processInstanceId){ |
| | | NcNode newProgramPkg = new NcNode(); |
| | | BeanUtils.copyProperties(programPkg,newProgramPkg); |
| | | EntityUtil.clearBaseProperties(newProgramPkg); |
| | | |
| | | newProgramPkg.setProcessInstanceId(processInstanceId); |
| | | this.ncNodeService.save(newProgramPkg); |
| | | vars.put(FlowContants.ASSIGNEE,div.getTeamLeaderId());//第ä¸ä¸ªå®¡æ¹ç¨æ·ï¼ç»é¿ |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * çæé¶ç»ä»¶ç¼å· |
| | | * å¾å·ãå¾å·ç次ãå·¥åºå·ãå·¥åºåç§°ãå·¥èºç次ãå·¥åºç次 ç»åèµ·æ¥è·å¾é¶ç»ä»¶å· |
| | | * @param startVO |
| | | * @return |
| | | */ |
| | | /* |
| | | String generatePartNo(TaskAssignVO startVO){ |
| | | //TODO è¿ä¸ªæ ¼å¼æªç¡®å®ï¼éè¦ç¡®è®¤ |
| | | return String.format("%s-%s-%s-%s-%s-%s", |
| | | startVO.getPartNo(), |
| | | startVO.getPartNoEdition(), |
| | | startVO.getProcessNo(), |
| | | startVO.getProcessName(), |
| | | startVO.getCraftEdition(), |
| | | startVO.getProcessEdition()); |
| | | }*/ |
| | | |
| | | } |
| | |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.excution.AutoAssignUsersService; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.entity.ProcessProgRef; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springblade.mdm.program.service.NodeDeptQueryService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final HistoryService historyService; |
| | | private final TaskService taskService; |
| | | private final IdentityService identityService; |
| | | |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | private final NcNodeService ncNodeService; |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | |
| | | vars.put(FlowContants.MACHINE_CODE,oldVars.get(FlowContants.MACHINE_CODE)); |
| | | //æºåºåå· |
| | | vars.put(FlowContants.MACHINE_MODE,oldVars.get(FlowContants.MACHINE_MODE)); |
| | | |
| | | String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(programPackage.getMachineCode()); |
| | | vars.put(FlowContants.WORKSHOP,workshop); |
| | | |
| | | vars.put(FlowContants.PROCESS_NO,oldVars.get(FlowContants.PROCESS_NO)); |
| | | vars.put(FlowContants.PROCESS_NAME,oldVars.get(FlowContants.PROCESS_NAME)); |
| | | vars.put(FlowContants.PROCESS_EDITION,oldVars.get(FlowContants.PROCESS_EDITION)); |
| | |
| | | |
| | | vars.put(FlowContants.PRODUCT_MODEL,programPackage.getProductModel()); |
| | | |
| | | vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPackage.getName()); |
| | | |
| | | ProduceDivision div = produceDivisionService.getByDrawingNo(programPackage.getDrawingNo()); |
| | | ProduceDivision div = produceDivisionService.getByDrawingNoWithQinzhe(programPackage.getDrawingNo()); |
| | | if(div != null) { |
| | | vars.put(FlowContants.PROGRAMMER,div.getProgrammerId()); |
| | | vars.put(FlowContants.CHECKER,div.getCheckerId()); |
| | |
| | | String fileName = programFile.getOssName(); |
| | | try (InputStream inputStream = ossTemplate.statFileStream(fileName)) { |
| | | ByteArrayInputStream bos = new ByteArrayInputStream(inputStream.readAllBytes()); |
| | | boolean isText= FileContentUtil.isTextFile(bos); |
| | | boolean isText = StringUtils.endsWithIgnoreCase(fileName,".txt") || StringUtils.endsWithIgnoreCase(fileName,".nc")|| StringUtils.endsWithIgnoreCase(fileName,".xml"); |
| | | if(!isText){ |
| | | isText= FileContentUtil.isTextFile(bos); |
| | | } |
| | | if(isText){ |
| | | bos.reset(); |
| | | bos.reset(); |
| | | result = FileContentUtil.getContentFromStream(bos); |
| | | }else{ |
| | | result = "<éææ¬æä»¶>"; |
| | |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.NodeDeptQueryService; |
| | | import org.springblade.mdm.program.service.ProgramFlowStatusQueryService; |
| | | import org.springblade.mdm.program.vo.NcNodeVO; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springblade.mdm.utils.ProgramFileNameCheckUtil; |
| | |
| | | private final IdentityService identityService; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ReplaceProgramFileService replaceProgramFileService; |
| | | private final ProgramFlowStatusQueryService flowStatusQueryService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | private OssTemplate ossTemplate; |
| | | public static final String NODE_ID = "nodeId"; |
| | |
| | | |
| | | */ |
| | | |
| | | /** |
| | | * å夿¿æ¢æµç¨éè¦çæ°æ® |
| | | * @param nodeId è¦æ¿æ¢çç¨åºå
åèç¹id |
| | | * @param tempInstanceId ä¸´æ¶æµç¨å®ä¾idï¼ç¨äºæ°çæä»¶ |
| | | * @return å¯å¨æ°æ® |
| | | */ |
| | | @Transactional |
| | | public NcNodeVO pre(long nodeId, String tempInstanceId) { |
| | | checkFlowStatus(nodeId); |
| | | |
| | | List<NcNode> fileNodes = nodeService.lambdaQuery() |
| | | .eq(NcNode::getParentId, nodeId) |
| | |
| | | return vo; |
| | | } |
| | | |
| | | void checkFlowStatus(long nodeId) { |
| | | NcNode packageNode = nodeService.getById(nodeId); |
| | | int status = flowStatusQueryService.queryFlowStatus(packageNode.getProcessInstanceId()); |
| | | if (status == 1) { |
| | | throw new ServiceException("ç¨åºçæµç¨æ£å¨è¿è¡ä¸ï¼ä¸è½è¿è¡æ¿æ¢"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¯å¨æ¿æ¢æµç¨ |
| | | */ |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.checkerframework.checker.units.qual.N; |
| | | import org.flowable.engine.delegate.DelegateExecution; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.contants.ParamConstants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.pojo.entity.Dict; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | |
| | | private final FlowCommonService flowCommonService; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ISysClient sysClient; |
| | | private final OssTemplate ossTemplate; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | private final MachineService machineService; |
| | | |
| | | public static final String GH = "GH"; |
| | | |
| | | |
| | | /** |
| | | * é»è®¤æææé´ï¼ææ°ï¼,2å¹´ |
| | | */ |
| | |
| | | * åºå审æ¹éè¿å¤çä»»å¡ï¼ |
| | | * @param execution æµç¨execution |
| | | */ |
| | | public void execute(DelegateExecution execution) { |
| | | @Transactional |
| | | public void execute(DelegateExecution execution) throws IOException { |
| | | log.info("æ§è¡åºåç¨åºä»»å¡æå¡,æµç¨å®ä¾id={}", execution.getProcessInstanceId()); |
| | | //åºåç¨åºæ£æ¥æææï¼ |
| | | //1.å°æµç¨è®¾ç½® |
| | | dealWithNode(execution.getProcessInstanceId()); |
| | | } |
| | | |
| | |
| | | * å¤çnodeç¶æã |
| | | * @param processInstanceId æµç¨å®ä¾id |
| | | */ |
| | | void dealWithNode(String processInstanceId) { |
| | | void dealWithNode(String processInstanceId) throws IOException { |
| | | //ç¨åºå
èç¹åä¸å±ç¨åºèç¹(å
æ¬åå²èç¹éææ°çæ¬ç)ä»è¯åæªå°åºåä¸é¢ |
| | | //ç¨åºå
èç¹ è®¾ç½®æªå·²åºå |
| | | NcNode pkgNode = nodeService.lambdaQuery().eq(NcNode::getProcessInstanceId, processInstanceId).one(); |
| | |
| | | * @param pkgNode è¦æªå¨çèç¹ |
| | | * @param historyProgramPackageNodes ç¨åºå
å åå²èç¹ |
| | | */ |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) { |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) throws IOException { |
| | | //å建èç¹å°æºåºçº§å«.(åºåæ ) |
| | | NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties); |
| | | |
| | |
| | | } |
| | | nodeService.updateBatchById(historyProgramPackageNodes); |
| | | |
| | | Machine machine = machineService.getByCode(pkgNode.getMachineCode()); |
| | | List<Dict> annoDicts = programAnnotationService.getAnnotionList(); |
| | | //æ°çæµç¨æä»¶ï¼éè¦å¨å
èç¹ä¸æ°å»ºï¼ä¸è½ç¨èç |
| | | List<FlowProgramFile> files = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId,pkgNode.getProcessInstanceId()).list(); |
| | | for(FlowProgramFile flowProgramFile : files){ |
| | |
| | | newProgNode.setFlowProgramFileId(flowProgramFile.getId()); |
| | | newProgNode.setIsCured(1); |
| | | ncNodeService.save(newProgNode); |
| | | |
| | | //ä¿®æ¹æä»¶å
å®¹æ´æ°æ³¨éï¼å¹¶æ´æ°æä»¶æ°æ®çå°å |
| | | ///æ¿æ¢æ³¨éåæ»æ¯ä¸è¡å |
| | | setGhAnnotation(flowProgramFile,machine.getMachineGroupCode(),annoDicts); |
| | | |
| | | flowProgramFileService.updateById(flowProgramFile); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置åºå注é,å®ç°æ¹å¼ï¼è·åæä»¶åèä¸ï¼ä¿®æ¹åæ¿æ¢æä»¶ |
| | | * @param flowProgramFile oss æä»¶ |
| | | * |
| | | */ |
| | | void setGhAnnotation(FlowProgramFile flowProgramFile,String machineGroup,List<Dict> annoDicts) throws IOException { |
| | | String ossName = flowProgramFile.getOssName(); |
| | | // |
| | | try(InputStream ins = ossTemplate.statFileStream(ossName);){ |
| | | String annoTxt = programAnnotationService.generateAnnotation("GH",machineGroup,annoDicts); |
| | | int statusLineIndex = 2; |
| | | String line2 = FileContentUtil.readLineAt(ins,statusLineIndex);//第ä¸è¡åºè¯¥æ¯ç¶ææ³¨é |
| | | InputStream finishedStream; |
| | | if(programAnnotationService.isAnnotation(line2,machineGroup,annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(ins,statusLineIndex,annoTxt); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(ins,statusLineIndex,annoTxt); |
| | | } |
| | | try(finishedStream) { |
| | | finishedStream.reset(); |
| | | BladeFile bfile = ossTemplate.putFile(flowProgramFile.getName(), finishedStream); |
| | | //æ¿æ¢åæçæä»¶å°å |
| | | flowProgramFile.setOssName(bfile.getName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | /* |
| | | @Operation(summary = "dncåä¼ æ°æ®å页", description = "dncåä¼ æ°æ®å页") |
| | | @GetMapping("/page") |
| | | public R<IPage<DncSendBackData>> page(Query query) { |
| | | IPage<DncSendBackData> pages = ncProgramExchangeService.dncSendBackPageQuery(query); |
| | | return R.data(pages); |
| | | @GetMapping("/back-file-content") |
| | | @Operation(summary = "è·ååä¼ æä»¶å
容", description = "æ¥çå·¥æ§ç½åä¼ æä»¶å
容") |
| | | public R<String> fileContent(@Parameter(description = "æä»¶çentryName") String entryName) { |
| | | try { |
| | | return R.data(dncSendBackService.getEntryFileContent(entryName)); |
| | | }catch(Exception e) { |
| | | log.error("å é¤æä»¶å¤±è´¥",e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | */ |
| | | @PostMapping("accept") |
| | | @ApiOperationSupport(order = 2) |
| | | @Operation(summary = "DNCåä¼ æ°æ®å
¥åº", description = "å
¥åºï¼åæ¶å¯å¨åºåæµç¨,å
¥å为ä¸ä¼ æ¯è§£æçæ°æ®å表") |
| | |
| | | List<NcNodeVO> list = ncNodeService.lazyList(parentId); |
| | | if(list != null && !list.isEmpty()) { |
| | | for(NcNodeVO ncNodeVO : list) { |
| | | if(!NcNode.TYPE_PROGRAM_PACKAGE.equals(ncNodeVO.getNodeType())){ |
| | | break; |
| | | if(NcNode.TYPE_PROGRAM_PACKAGE.equals(ncNodeVO.getNodeType())){ |
| | | ncNodeVO.setFlowStatus(programFlowStatusQueryService.queryFlowStatus(ncNodeVO.getProcessInstanceId())); |
| | | } |
| | | ncNodeVO.setFlowStatus(programFlowStatusQueryService.queryFlowStatus(ncNodeVO.getProcessInstanceId())); |
| | | } |
| | | |
| | | } |
| | | return R.data(list); |
| | | } |
| | |
| | | <result column="is_deleted" property="isDeleted"/> |
| | | </resultMap> |
| | | <select id="exportDncPageQuery" resultType="org.springblade.mdm.program.vo.NcProgramExportDncPageVO"> |
| | | select a.id,a.title,n.name,a.nc_node_id,n.drawing_no,n.drawing_no_edition,n.process_name,a.create_time from mdm_nc_program_approved a |
| | | select a.id,a.title,n.name,a.nc_node_id,n.drawing_no,n.drawing_no_edition,n.process_name,a.create_time,a.update_time from mdm_nc_program_approved a |
| | | inner join mdm_nc_node n on a.nc_node_id=n.id |
| | | <where> |
| | | a.is_deleted=0 and a.status=#{query.status} |
| | |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | private String getFileKey(){ |
| | | return "dncexpfile-"+ AuthUtil.getUserId(); |
| | | return "dncimpfile-"+ AuthUtil.getUserId(); |
| | | } |
| | | /** |
| | | * dncåä¼ æä»¶ä¸ä¼ |
| | |
| | | //设置ä¸ä¸ªç¼åï¼2å°æ¶è¿æ |
| | | bladeRedis.setEx(getFileKey(),bfile.getName(), Duration.ofHours(2)); |
| | | |
| | | InputStream zipFileInputStream = file.getInputStream();//test |
| | | |
| | | list = parseProgramListFromZip(zipFileInputStream); |
| | | |
| | | try(InputStream zipFileInputStream = ossTemplate.statFileStream(bfile.getName());) { |
| | | //InputStream zipFileInputStream = file.getInputStream();//test |
| | | list = parseProgramListFromZip(zipFileInputStream); |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("ä¸ä¼ dncåä¼ æä»¶å¤±è´¥",e); |
| | | throw new ServiceException("è§£æDNCåä¼ æ°æ®å¤±è´¥"); |
| | |
| | | if(programPackageNode != null) { |
| | | progData.setId(programPackageNode.getId()); |
| | | progData.setProgramNo(programPackageNode.getProgramNo()); |
| | | |
| | | List<String> fileEtriyNames = fileEntryNameList.stream().filter(n -> n.startsWith(packageName)).toList(); |
| | | List<DncSendBackFile> programFiles = new ArrayList<>(); |
| | | fileEtriyNames.forEach( filePath ->{ |
| | | DncSendBackFile backFile = new DncSendBackFile(); |
| | | backFile.setEntryName(filePath); |
| | | backFile.setName(StringUtils.removeStart(filePath,entryName)); |
| | | programFiles.add(backFile); |
| | | }); |
| | | |
| | | progData.setFiles(programFiles); |
| | | list.add(progData); |
| | | }else{ |
| | | throw new ServiceException("æ¾ä¸å°ç¨åºå
å:"+packageName+statusLine); |
| | |
| | | |
| | | this.save(exchange); |
| | | }*/ |
| | | bladeRedis.del(filekey); |
| | | this.ossTemplate.removeFile(zipFileName); |
| | | log.info("å é¤ossæä»¶:{}",zipFileName); |
| | | //bladeRedis.del(filekey); |
| | | //this.ossTemplate.removeFile(zipFileName); |
| | | //log.info("å é¤ossæä»¶:{}",zipFileName); |
| | | |
| | | //cureFlowService.startCure(newProgramPackageList,programPackageSubMap); |
| | | cureFlowService.startCureNew(pkgIdFileMap); |
| | |
| | | |
| | | return tempFile; |
| | | } |
| | | void setBaseProperties(BizEntity entity, JSONObject jsonObject){ |
| | | entity.setCreateTime(jsonObject.getDate("createTime")); |
| | | entity.setUpdateTime(jsonObject.getDate("updateTime")); |
| | | entity.setStatus(jsonObject.getInteger("status")); |
| | | entity.setCreateUser(jsonObject.getLong("createUser")); |
| | | entity.setUpdateUser(jsonObject.getLong("updateUser")); |
| | | |
| | | /** |
| | | * è·ååä¼ æä»¶çå
容 |
| | | * @param entryName æä»¶å¨å缩å
å
çè·¯å¾ |
| | | * @return æä»¶å
å®¹ææ¬ |
| | | */ |
| | | public String getEntryFileContent(String entryName) throws IOException { |
| | | String result = ""; |
| | | String zipFileName = bladeRedis.get(getFileKey()); |
| | | try(InputStream inputStream = this.ossTemplate.statFileStream(zipFileName);){ |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | | ZipEntry entry; |
| | | try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) { |
| | | Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
| | | while (entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | if (!entryName.equals(entry.getName())) { |
| | | continue; |
| | | } |
| | | try (InputStream fileIns = zipFile.getInputStream(zipFile.getEntry(entryName))) { |
| | | ByteArrayInputStream bos = new ByteArrayInputStream(fileIns.readAllBytes()); |
| | | boolean isText = FileContentUtil.isTextFile(bos); |
| | | if (isText) { |
| | | bos.reset(); |
| | | result = FileContentUtil.getContentFromStream(bos); |
| | | } else { |
| | | result = "<éææ¬æä»¶>"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | /* |
| | | void clearBaseProperties(BizEntity entity){ |
| | | entity.setId(null); |
| | | entity.setCreateTime(null); |
| | | entity.setUpdateTime(null); |
| | | entity.setStatus(null); |
| | | entity.setCreateUser(null); |
| | | entity.setUpdateUser(null); |
| | | }*/ |
| | | |
| | | } |
| | |
| | | for (Long approvedId : approvedIdArray) { |
| | | NcProgramApproved approved = approvedService.getById(approvedId); |
| | | addProgramPackageToZip(zipOut,approved); |
| | | |
| | | approved.setStatus(NcProgramApproved.STATUS_EXPORTED); |
| | | approvedService.updateById(approved); |
| | | } |
| | | |
| | | //ç¶æä¿®æ¹ä¸ºå·²å¯¼åº |
| | | /* |
| | | approvedService.lambdaUpdate().in(NcProgramApproved::getId, Arrays.asList(approvedIdArray)) |
| | | .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update(); |
| | | .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update();*/ |
| | | }catch(Exception e){ |
| | | Throwable [] err = e.getSuppressed(); |
| | | throw new ServiceException("导åºå·¥æ§ç½é误"+e.getMessage()); |
| | |
| | | private String md5; |
| | | |
| | | @Schema(description = "åæä»¶ï¼ç¨äºå¯è¯å«æä»¶å çæºå¨è¿åçç¨åºï¼") |
| | | private List<String> children; |
| | | private List<DncSendBackFile> files; |
| | | private boolean hasChildren; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | @Setter |
| | | @Getter |
| | | @Schema(description = "DNCåä¼ æ°æ®") |
| | | public class DncSendBackFile { |
| | | |
| | | @Schema(description = "æä»¶å") |
| | | private String name; |
| | | @Schema(description = "æä»¶è·¯å¾") |
| | | private String entryName; |
| | | |
| | | } |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | |
| | | System.out.println(entryNameList); |
| | | |
| | | /* |
| | | try (ZipFile zipFile = new ZipFile(tempFile.toFile())) { |
| | | ZipEntry entry = zipFile.getEntry(entryn); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | | |
| | | Path outputPath = Paths.get("d:/downtest.txt"); |
| | | Files.copy(ins, outputPath, StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | |
| | | List<String> entryNameList = new ArrayList<>(); |
| | | try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes); |
| | | ZipFile zipFile = new ZipFile(channel)) { |
| | | |
| | | ZipArchiveEntry entry; |
| | | Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); |
| | | String entryn = "CP1-13-1/CP1-13-1-1-1-1.txt"; |
| | | while (entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | entryNameList.add(entry.getName()); |
| | | } |
| | | }*/ |
| | | /* |
| | | try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes); |
| | | ZipFile zipFile = new ZipFile(channel)) { |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList) { |
| | | entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> { |
| | | ZipArchiveEntry fileEntry = zipFile.getEntry(entryName); |
| | | //ZipArchiveEntry fileEntry = entryMap.get(entryName); |
| | | String fileName = StringUtils.removeStart(entryName,dir);//å»é¤æä»¶åè·¯å¾é¨å |
| | | try { |
| | | InputStream ins = zipFile.getInputStream(fileEntry); |
| | | ByteArrayInputStream byteS = new ByteArrayInputStream(ins.readAllBytes()); |
| | | |
| | | Path outputPath = Paths.get("d:/downtest.txt"); |
| | | Files.copy(byteS, outputPath, StandardCopyOption.REPLACE_EXISTING); |
| | | byteS.reset(); |
| | | |
| | | BladeFile newOssFile = ossTemplate.putFile("mdm", fileName, byteS); |
| | | r.setData(newOssFile.getName()); |
| | | System.out.println(newOssFile.getName()); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | }); |
| | | } |
| | | }*/ |
| | | return r; |
| | | } |
| | | |
| | | @GetMapping("/replace") |
| | | @ApiOperationSupport(order = 2) |
| | | @Operation(summary = "æ¿æ¢å
容") |
| | | public R<String> replace(String filepath) throws IOException { |
| | | File file = new File(filepath); |
| | | FileInputStream fis = new FileInputStream(file); |
| | | InputStream newins = FileContentUtil.replaceAtLine(fis,2,"GHTEST"); |
| | | |
| | | BladeFile bfile = ossTemplate.putFile("replaceok.txt",newins); |
| | | return R.data(bfile.getLink()+","+bfile.getName()); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.utils; |
| | | import org.apache.tika.detect.Detector; |
| | | import org.apache.tika.io.TikaInputStream; |
| | | import org.apache.tika.metadata.Metadata; |
| | | import org.apache.tika.mime.MediaType; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | public class AnsiTextDetector implements Detector { |
| | | // 坿å°å符èå´ï¼ASCII + æ©å±ANSIåç¬¦ï¼ |
| | | private static final int PRINTABLE_START = 32; |
| | | private static final int PRINTABLE_END = 126; |
| | | private static final int EXTENDED_ANSI_START = 128; |
| | | private static final int EXTENDED_ANSI_END = 255; |
| | | |
| | | // ææ¬å¤å®éå¼ï¼å¯æå°åç¬¦å æ¯ >= 80% |
| | | private static final double TEXT_THRESHOLD = 0.8; |
| | | |
| | | @Override |
| | | public MediaType detect(InputStream input, Metadata metadata) throws IOException { |
| | | TikaInputStream tis = TikaInputStream.get(input); |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead = tis.read(buffer); |
| | | if (bytesRead <= 0) { |
| | | return MediaType.OCTET_STREAM; |
| | | } |
| | | |
| | | int total = 0; |
| | | int printable = 0; |
| | | for (int i = 0; i < bytesRead; i++) { |
| | | byte b = buffer[i]; |
| | | int unsigned = b & 0xFF; // 转为æ 符å·åè |
| | | total++; |
| | | // 夿æ¯å¦ä¸ºå¯æå°å符ï¼å«æ©å±ANSIï¼ |
| | | if ((unsigned >= PRINTABLE_START && unsigned <= PRINTABLE_END) || |
| | | (unsigned >= EXTENDED_ANSI_START && unsigned <= EXTENDED_ANSI_END)) { |
| | | printable++; |
| | | } |
| | | } |
| | | |
| | | // è¥å¯æå°åç¬¦å æ¯è¾¾æ ï¼å¤å®ä¸ºææ¬ |
| | | if ((double) printable / total >= TEXT_THRESHOLD) { |
| | | return MediaType.TEXT_PLAIN; |
| | | } |
| | | return MediaType.OCTET_STREAM; |
| | | } |
| | | } |
| | |
| | | package org.springblade.mdm.utils; |
| | | |
| | | import org.apache.tika.Tika; |
| | | import org.apache.tika.config.TikaConfig; |
| | | import org.apache.tika.detect.CompositeDetector; |
| | | import org.apache.tika.detect.DefaultDetector; |
| | | import org.apache.tika.detect.Detector; |
| | | import org.apache.tika.detect.TextDetector; |
| | | import org.apache.tika.mime.MimeType; |
| | | import org.apache.tika.mime.MimeTypeException; |
| | | import org.apache.tika.mime.MimeTypes; |
| | | import org.mozilla.universalchardet.UniversalDetector; |
| | | import org.springblade.core.tool.utils.Charsets; |
| | | |
| | | import java.io.*; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static boolean isTextFile(InputStream inputStream) { |
| | | Tika tika = new Tika(); |
| | | MimeTypes mimeTypes = MimeTypes.getDefaultMimeTypes(); |
| | | Tika tika = new Tika(mimeTypes); |
| | | |
| | | try { |
| | | String mimeType = tika.detect(inputStream); |
| | | //String mimeType = tika.detect(file); |
| | |
| | | |
| | | return new String(bytes, charset); |
| | | } |
| | | |
| | | /** |
| | | * æ¿æ¢æä»¶ä¸çæä¸è¡ |
| | | * @param ins è¾å
¥æµ |
| | | * @param repalceWith æ¿æ¢åçææ¬ |
| | | * @param lineIndex è¡ç´¢å¼ 0 based |
| | | */ |
| | | public static InputStream replaceAtLine(InputStream ins, int lineIndex,String repalceWith) throws IOException { |
| | | byte[] bytes = ins.readAllBytes(); |
| | | ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); |
| | | Charset charset = Charsets.charset(detectFromInputStream(byteStream)); |
| | | byteStream.reset(); |
| | | |
| | | Path tempFile = Files.createTempFile("temppro"+System.currentTimeMillis(), ".tmp"); |
| | | |
| | | try (InputStreamReader isr = new InputStreamReader(byteStream, charset); |
| | | BufferedReader reader = new BufferedReader(isr); |
| | | BufferedWriter writer = Files.newBufferedWriter(tempFile,charset)) {// |
| | | |
| | | int currentLine = 0; |
| | | String line; |
| | | |
| | | while ((line = reader.readLine()) != null) { |
| | | // 妿æ¯ç®æ è¡ï¼åå
¥æ°å
容 |
| | | if (currentLine == lineIndex) { |
| | | writer.write(repalceWith); |
| | | } else { |
| | | writer.write(line); |
| | | } |
| | | writer.newLine(); |
| | | currentLine++; |
| | | } |
| | | |
| | | } |
| | | return new ByteArrayInputStream(Files.newInputStream(tempFile).readAllBytes()); |
| | | } |
| | | } |
| | |
| | | package org.springblade.mdm.utils; |
| | | |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.junit.jupiter.api.Assertions; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.jupiter.api.io.TempDir; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Charsets; |
| | | |
| | |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.List; |
| | | |
| | | public class FileContentUtilTest { |
| | | |
| | |
| | | //System.out.println(charset); |
| | | } |
| | | |
| | | //@Test |
| | | @Test |
| | | public void testReadLineAt() throws IOException { |
| | | String file = "D:/a.txt"; |
| | | |
| | | Path source = Paths.get("src/test/resources/filecontenttest.txt"); |
| | | int lineIndex = 1; |
| | | FileInputStream fis = new FileInputStream(file); |
| | | FileInputStream fis = new FileInputStream(source.toFile()); |
| | | |
| | | String expected = "第äºè¡"; |
| | | String read = FileContentUtil.readLineAt(fis,lineIndex); |
| | | Assertions.assertEquals(expected,read); |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void testReplaceReadLineAt(@TempDir Path tempDir) throws IOException { |
| | | // å è½½èµæºæä»¶ |
| | | Path source = Paths.get("src/test/resources/filecontenttest.txt"); |
| | | //File file = new File(classLoader.getResource("filecontenttest.txt").getFile()); |
| | | File testFile = source.toFile(); |
| | | try(FileInputStream fis = new FileInputStream(testFile);) { |
| | | |
| | | String expected = "newline2"; |
| | | int lineIndex = 1; |
| | | InputStream ins = FileContentUtil.replaceAtLine(fis, lineIndex, expected); |
| | | List<String> list = IOUtils.readLines(ins, Charsets.UTF_8); |
| | | System.out.println(list); |
| | | Assertions.assertEquals(expected, list.get(lineIndex)); |
| | | } |
| | | |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | çä¸ä¼ |
| | | 第äºè¡ |
| | | 第äº3 |
| | | 第4è¡x |