blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/controller/MachineFileController.java
@@ -11,16 +11,13 @@ import org.springblade.core.tool.api.R; import org.springblade.mdm.gkw.programnode.entity.MachineFile; import org.springblade.mdm.gkw.programnode.service.MachineFileService; import org.springblade.mdm.gkw.programnode.service.ProgramNodeService; import org.springblade.mdm.gkw.programnode.vo.MachineFileQueryVO; import org.springblade.mdm.gkw.programnode.vo.ProgramNodeVO; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.util.List; /** * å ¬å¼ç½ç¨åºèç¹ @@ -42,7 +39,7 @@ IPage<MachineFile> pageData = machineFileService.lambdaQuery() .eq(MachineFile::getMachineCode,query.getMachineCode()) .eq(MachineFile::getDirType,query.getDirType()).page(Condition.getPage(query)); .eq(MachineFile::getDirType,query.getDirType()).ne(MachineFile::getStatus,MachineFile.STATUS_REMOVED).page(Condition.getPage(query)); return R.data(pageData); } @@ -58,7 +55,7 @@ @Operation(summary = "ä¿åæºåºæä»¶", description = "ä¿åæºåºæä»¶å°ç£ç") public R<Void> machineFileSave(Long id,String content) { try { machineFileService.saveFileConent(id,content); machineFileService.saveFileContent(id,content); } catch (IOException e) { log.error(e.getMessage()); return R.fail(e.getMessage()); blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/entity/MachineFile.java
@@ -19,19 +19,19 @@ /** * æ£å¸¸ç¶æï¼åæ¥æ¶ */ public static final int STATUS_NORMAL = 0; public static final int STATUS_NORMAL = 1; /** * ç¨æ·æ¥æ¶äº */ public static final int STATUS_ACCEPTED = 1; public static final int STATUS_ACCEPTED = 2; /** * ç¨æ·æç»æ¥æ¶ */ public static final int STATUS_REJECTED = 2; public static final int STATUS_REJECTED = 3; /** * æä»¶è¢«æ¸ é¤(è¢«å®æ¶ä»»å¡æ è®°) */ public static final int STATUS_REMOVED = 3; public static final int STATUS_REMOVED = 4; /** * èç¹ç±»åï¼ RECç®å½ */ @@ -71,7 +71,7 @@ */ private Date fileCreateTime; private Date fileModifyDate; private Date fileModifyTime; /** * æä»¶md5 @@ -82,6 +82,10 @@ */ private Long fileSize; /** * 确认æ¶é´ï¼æ¥åæè æç»çæ¶é´ */ private Date determineTime; /** * çææä»¶å¤§å°çæ¾ç¤ºææ¬ * @return æ¾ç¤ºææ¬ @@ -98,4 +102,17 @@ public void markFileDeleted() { this.setStatus(STATUS_REMOVED); } /** * æ¥æ¶æä»¶ */ public void accept() { setStatus(STATUS_ACCEPTED); this.determineTime = new Date(); } public void reject() { setStatus(STATUS_REJECTED); this.determineTime = new Date(); } } blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/mapper/MachineFileMapper.java
@@ -6,6 +6,7 @@ import org.springblade.mdm.gkw.programnode.entity.MachineFile; import org.springblade.mdm.gkw.programnode.entity.ProgramNode; import org.springblade.mdm.gkw.programnode.vo.ProgramNodeVO; import org.springblade.mdm.machineback.vo.MachineBackFileHandleQueryVO; import org.springblade.mdm.machineback.vo.MachineBackFileQueryVO; import org.springblade.mdm.machineback.vo.MachineBackFileVO; @@ -19,4 +20,6 @@ * @return */ IPage<MachineBackFileVO> machineBackFilePageQuery(IPage<MachineBackFileVO> page, @Param("query")MachineBackFileQueryVO queryVO); IPage<MachineBackFileVO> handlePageQuery(@Param("page")IPage<MachineBackFileVO> page,@Param("query") MachineBackFileHandleQueryVO query); } blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/mapper/MachineFileMapper.xml
@@ -14,7 +14,7 @@ select f.id,f.name,f.machine_code,f.file_create_time arrived_time,f.md5,f.file_size from mdm_machine_file f join mdm_machine m on f.machine_code=m.code and m.is_deleted=0 <where> f.dir_type='REC' and f.is_deleted=0 f.dir_type='REC' and f.status=1 and f.is_deleted=0 <if test="query.machineSpec!=null and query.machineSpec!=''"> and m.machine_spec=#{query.machineSpec,jdbcType=VARCHAR} @@ -27,6 +27,20 @@ </if> </where> </select> <select id="handlePageQuery" resultType="org.springblade.mdm.machineback.vo.MachineBackFileVO"> select f.id,f.name,f.machine_code,f.file_create_time arrived_time,f.md5,f.file_size,f.determine_time from mdm_machine_file f join mdm_machine m on f.machine_code=m.code and m.is_deleted=0 <where> f.dir_type='REC' and f.status=2 and f.is_deleted=0 <if test="query.confirmTimeBegin!=null"> and f.determine_time>=#{query.confirmTimeBegin} </if> <if test="query.confirmTimeEnd!=null"> and f.determine_time<=#{query.confirmTimeEnd} </if> </where> </select> </mapper> blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/service/MachineFileService.java
@@ -4,18 +4,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BizServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.utils.Charsets; import org.springblade.core.tool.utils.Func; import org.springblade.mdm.basesetting.machine.MachineService; import org.springblade.mdm.basesetting.machine.entity.Machine; import org.springblade.mdm.gkw.programnode.entity.MachineFile; import org.springblade.mdm.gkw.programnode.mapper.MachineFileMapper; import org.springblade.mdm.machineback.vo.MachineBackFileHandleQueryVO; import org.springblade.mdm.machineback.vo.MachineBackFileQueryVO; import org.springblade.mdm.machineback.vo.MachineBackFileVO; import org.springblade.mdm.utils.FileContentUtil; @@ -25,11 +23,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; /** * æºåºæä»¶ @@ -44,12 +40,14 @@ /** * æ£æµæä»¶æ¯å¦åå¨ * @param name æä»¶å * @param md5 æä»¶md5 * @param dirType æä»¶å¤¹ç±»å * @param machineCode æå±æºåº * @return æ¯å¦åå¨äºåºå */ public boolean fileExists(String name, String md5,String machineCode) { return this.lambdaQuery().eq(MachineFile::getName, name).eq(MachineFile::getMd5, md5).eq(MachineFile::getMachineCode, machineCode).count()>0; public boolean fileExists(String name, String dirType,String machineCode) { return this.lambdaQuery().eq(MachineFile::getName, name) .eq(MachineFile::getDirType, dirType) .eq(MachineFile::getMachineCode, machineCode).count()>0; } @Transactional(readOnly = true) @@ -102,7 +100,7 @@ } @Transactional public void saveFileConent(Long id, String content) throws IOException { public void saveFileContent(Long id, String content) throws IOException { MachineFile machineFile = getById(id); Machine machine = machineService.getByCode(machineFile.getMachineCode()); @@ -116,8 +114,22 @@ log.error("读åæä»¶ç¼ç 失败",e); throw new ServiceException("è·åæä»¶ç¼ç 失败"); } FileUtils.writeStringToFile(filePath.toFile(),content,charsetName); } /** * è·åæä»¶çè¾å ¥æµ * @param machineFile * @return * @throws IOException */ public InputStream getInputStream(MachineFile machineFile) throws IOException { Machine machine = machineService.getByCode(machineFile.getMachineCode()); String filePathStr = getBasePath(machine,machineFile.getDirType())+ File.separator+machineFile.getName(); Path filePath = Paths.get(filePathStr); return Files.newInputStream(filePath); } @@ -125,4 +137,20 @@ public IPage<MachineBackFileVO> machineBackFilePageQuery(MachineBackFileQueryVO query) { return this.baseMapper.machineBackFilePageQuery(Condition.getPage(query),query); } public MachineFile getExistsFile(String name, String dirType, String machineCode) { return this.lambdaQuery().eq(MachineFile::getName, name) .eq(MachineFile::getDirType, dirType) .eq(MachineFile::getMachineCode, machineCode).list().stream().findFirst().orElse(null); } /** * åä¼ ç¨åºå¤ç å页æ¥è¯¢ * @param query * @return */ public IPage<MachineBackFileVO> handlePageQuery(MachineBackFileHandleQueryVO query) { IPage<MachineBackFileVO> page = this.getBaseMapper().handlePageQuery(Condition.getPage(query),query); return page; } } blade-service/blade-mdm/src/main/java/org/springblade/mdm/gkw/programnode/vo/ProgramNameVO.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,35 @@ package org.springblade.mdm.gkw.programnode.vo; import lombok.Data; /** * è£ è½½ç¨åºåç»æ */ @Data public class ProgramNameVO { /** * é¶ç»ä»¶å· */ private String drawingNo; /** * å·¥åºå· */ private String processNo; /** * å·¥åºç次 */ private String processEdition; /** * æ®µæ° */ private int segmentCount; /** * æ®µå· */ private int segmentNo; public String logicProgramName(){ return this.drawingNo+"-"+this.processNo; } } blade-service/blade-mdm/src/main/java/org/springblade/mdm/machineback/controller/MachineBackFileController.java
@@ -70,7 +70,6 @@ IPage<MachineBackFileVO> pages = machineFileService.machineBackFilePageQuery(query); return R.data(pages); } /** * å页 */ blade-service/blade-mdm/src/main/java/org/springblade/mdm/machineback/controller/MachineBackFileHandleController.java
@@ -18,6 +18,7 @@ import org.springblade.mdm.basesetting.machine.vo.MachineQueryVO; import org.springblade.mdm.basesetting.machine.vo.MachineVO; import org.springblade.mdm.commons.vo.IdsVO; import org.springblade.mdm.gkw.programnode.service.MachineFileService; import org.springblade.mdm.machineback.service.MachineBackFileService; import org.springblade.mdm.machineback.service.NcProgramExportInnerService; import org.springblade.mdm.machineback.vo.MachineBackFileHandleExcelVO; @@ -40,30 +41,31 @@ public class MachineBackFileHandleController { private final MachineBackFileService service; private final MachineFileService machineFileService; private final NcProgramExportInnerService ncProgramExportInnerService; /** * å页 */ @Operation(summary = "å页æ¥è¯¢", description = "åç§°æç¼ç ") @Operation(summary = "å页æ¥è¯¢", description = "åç§°æç¼ç ,å·²æ¥åçæä»¶å表") @GetMapping("/page") public R<IPage<MachineBackFileVO>> page(MachineBackFileHandleQueryVO query) { IPage<MachineBackFileVO> pages = service.handlePageQuery(query); IPage<MachineBackFileVO> pages = machineFileService.handlePageQuery(query); return R.data(pages); } @GetMapping("export-to-inner") @ApiOperationSupport(order = 13) @Operation(summary = "导åºå°æ¶å¯ç½", description = "导åºå°æ¶å¯ç½") public void exportToInner(@RequestBody @Parameter(description = "审æ¹è¡¨idæ°ç»") IdsVO vo, HttpServletResponse response) { public void exportToInner(@Parameter(description = "审æ¹è¡¨idæ°ç»") String ids, HttpServletResponse response) { if(vo.getIds() == null || vo.getIds().length == 0) { if(Func.isBlank(ids)) { throw new ServiceException("æªéæ©æä»¶å¯¼åº"); } try { String filename = "toinnerexp-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; response.setHeader("Content-Disposition", "attachment; filename="+filename); response.setContentType("application/octet-stream"); ncProgramExportInnerService.exportToInner(vo.getIds(),response.getOutputStream()); ncProgramExportInnerService.exportToInner(Func.toLongList(ids),response.getOutputStream()); } catch (IOException e) { log.error("å·¥æ§ç½å¯¼åºåä¼ æä»¶å¼å¸¸", e); throw new RuntimeException(e); @@ -76,8 +78,8 @@ public void exportExcel(MachineBackFileHandleQueryVO query, HttpServletResponse response) { query.setCurrent(1); query.setSize(Integer.MAX_VALUE); IPage<MachineBackFileVO> pages = service.handlePageQuery(query); //IPage<MachineBackFileVO> pages = service.handlePageQuery(query); IPage<MachineBackFileVO> pages = machineFileService.handlePageQuery(query); List<MachineBackFileHandleExcelVO> list = new ArrayList<>(); pages.getRecords().forEach(vo ->{ MachineBackFileHandleExcelVO excelVO = new MachineBackFileHandleExcelVO(); blade-service/blade-mdm/src/main/java/org/springblade/mdm/machineback/service/MachineBackFileService.java
@@ -37,14 +37,14 @@ MachineFile mf; for(Long id : idList){ mf = macineFileService.getById(id); mf.setStatus(MachineFile.STATUS_ACCEPTED); mf.accept(); macineFileService.updateById(mf); /* MachineBackFile backFile = this.getById(id); backFile.setStatus(MachineBackFile.STATUS_ACCEPTED); backFile.setConfirmTime(DateUtil.now()); this.updateById(backFile); */ } } @@ -56,12 +56,19 @@ public void reject(String ids) { List<Long> idList = Func.toLongList(ids); MachineFile mf; for(Long id : idList){ mf = macineFileService.getById(id); mf.reject(); macineFileService.updateById(mf); } /* for(Long id : idList){ MachineBackFile backFile = this.getById(id); backFile.setStatus(MachineBackFile.STATUS_REJECTED); backFile.setConfirmTime(DateUtil.now()); this.updateById(backFile); } }*/ } @@ -81,10 +88,11 @@ * @param query æ¥è¯¢åæ°å¯¹è±¡ * @return åé¡µæ°æ® */ /* public IPage<MachineBackFileVO> handlePageQuery(MachineBackFileHandleQueryVO query) { IPage<MachineBackFileVO> page = this.getBaseMapper().handlePageQuery(Condition.getPage(query),query); return page; } */ } blade-service/blade-mdm/src/main/java/org/springblade/mdm/machineback/service/NcProgramExportInnerService.java
@@ -17,6 +17,8 @@ import org.springblade.core.tool.utils.Func; import org.springblade.mdm.flow.entity.ApproveRecord; import org.springblade.mdm.flow.service.ApproveRecordService; import org.springblade.mdm.gkw.programnode.entity.MachineFile; import org.springblade.mdm.gkw.programnode.service.MachineFileService; import org.springblade.mdm.machineback.entity.MachineBackFile; import org.springblade.mdm.program.entity.NcNode; import org.springblade.mdm.program.entity.NcProgram; @@ -27,6 +29,7 @@ import org.springblade.mdm.program.service.NcProgramApprovedService; import org.springblade.mdm.program.service.NcProgramService; import org.springblade.mdm.program.vo.DncSendBackData; import org.springblade.mdm.utils.ProgramFileNameParser; import org.springframework.stereotype.Service; import java.io.ByteArrayInputStream; @@ -34,8 +37,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.*; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -50,7 +53,7 @@ public class NcProgramExportInnerService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> { private final MachineBackFileService machineBackFileService; private final NcProgramService progService; private final MachineFileService machineFileService; private final NcNodeService ncNodeService; private final OssTemplate ossTemplate; @@ -61,182 +64,33 @@ /** * 导åºå°æ¶å¯ç½ * @param backFileIds * @param machineFileIds * @param os * @throws IOException */ public void exportToInner(Long[] backFileIds, ServletOutputStream os) throws IOException { public void exportToInner(List<Long> machineFileIds, ServletOutputStream os) throws IOException { //FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip"); try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os ArrayList<Long> programIdList = new ArrayList<Long>(); List<MachineFile> macineFiles = machineFileService.lambdaQuery().in(MachineFile::getId,machineFileIds).list(); Map<String,List<MachineFile>> map = macineFiles.stream() .collect(Collectors.groupingBy(s -> ProgramFileNameParser.parseProgramName(s.getName()).logicProgramName())); for (Long backId : backFileIds) { MachineBackFile backFile = machineBackFileService.getById(backId); programIdList.add(backFile.getNcProgramId()); NcProgram prog = progService.getById(backFile.getNcProgramId()); //1111ï¼éè¦è£ 卿件 String filename = prog.getOssName(); InputStream inputStream = ossTemplate.statFileStream(filename); addInputStreamToZip(zipOut, inputStream, prog.getName()); for (Map.Entry<String, List<MachineFile>> entry : map.entrySet()) { String programName = entry.getKey(); List<MachineFile> progMachineFiles = entry.getValue(); for (MachineFile mf : progMachineFiles) { try(InputStream ins = machineFileService.getInputStream(mf)) { addInputStreamToZip(zipOut,ins , programName + "/" + mf.getName()); } } } addDataJson(zipOut, programIdList); } os.close(); } /** * å¯¼å ¥æ°æ®æä»¶ * @param zipOut */ void addDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { addProgramDataJson(zipOut, programIdList); //addApproveRecordDataJson(zipOut, programIdList); addNcNodeDataJson(zipOut, programIdList); } /** * å¯¼å ¥ç¨åºè®°å½ * @param zipOut * @param programIdList */ void addProgramDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { LambdaQueryWrapper<NcProgram> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(NcProgram::getId, programIdList); List<NcProgram> programList = progService.list(queryWrapper); JSONArray jsonArray = new JSONArray(); for(NcProgram program : programList){ JSONObject recObj = new JSONObject(); recObj.put("id", program.getId()); recObj.put("code", program.getCode()); recObj.put("ossName",program.getOssName()); recObj.put("isTextFile",program.getIsTextFile()); recObj.put("isLastEdition",program.getIsLastEdition()); recObj.put("category",program.getCategory()); recObj.put("description",program.getDescription()); recObj.put("name",program.getName()); recObj.put("drawingNo",program.getDrawingNo()); recObj.put("ncNodeId",program.getNcNodeId()); recObj.put("bindNcNodeId",program.getBindNcNodeId()); recObj.put("url",program.getUrl()); recObj.put("isCured",program.getIsCured()); recObj.put("isLocked",program.getIsLocked()); recObj.put("isTest",program.getIsTest()); recObj.put("machineCode",program.getMachineCode()); recObj.put("processEdition",program.getProcessEdition()); recObj.put("taskAssignTime",program.getTaskAssignTime()); addSuperProperties(recObj,program); jsonArray.add(recObj); } addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),PROGRAM_JSON_FILE); } /** * å¯¼å ¥å®¡æ¹è®°å½ * @param zipOut * @param programIdList æ°æ§ç¨åºidå表 */ /* void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { LambdaQueryWrapper<ApproveRecord> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(ApproveRecord::getNcProgramId, programIdList); List<ApproveRecord> records = approveRecordService.list(queryWrapper); JSONArray jsonArray = new JSONArray(); for(ApproveRecord record : records){ JSONObject recObj = new JSONObject(); recObj.put("id", record.getId()); recObj.put("comment", record.getComment()); recObj.put("userId",record.getUserId()); recObj.put("userNickname",record.getUserNickname()); recObj.put("operateTime",record.getOperateTime()); recObj.put("operateResult",record.getOperateResult()); recObj.put("taskName",record.getTaskName()); recObj.put("ncProgramId",record.getNcProgramId()); recObj.put("processInstanceId",record.getProcessInstanceId()); addSuperProperties(recObj,record); jsonArray.add(recObj); } addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_approve_record.json"); } */ /** * å¯¼å ¥èç¹ * @param zipOut * @param programIdList */ void addNcNodeDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { LambdaQueryWrapper<NcProgram> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(NcProgram::getId, programIdList); List<NcProgram> programs = progService.list(queryWrapper); JSONArray jsonArray = new JSONArray(); ArrayList<Long> exportNodeIdList = new ArrayList<>(); for(NcProgram program : programs){ //JSONObject recObj = new JSONObject(); if(!exportNodeIdList.contains(program.getBindNcNodeId())){ exportNodeIdList.add(program.getBindNcNodeId()); } NcNode ncNode = ncNodeService.getById(program.getBindNcNodeId());//ä»ç»å®çèç¹æ¬èº«å¼å§å¯¼åº if(StringUtils.isNotEmpty(ncNode.getParentIds())){ List<Long> pids = Func.toLongList(ncNode.getParentIds()); for(Long nodeId : pids){ if(!exportNodeIdList.contains(nodeId)){ exportNodeIdList.add(nodeId); } } } } LambdaQueryWrapper<NcNode> nodeQueryWrapper = new LambdaQueryWrapper<>(); nodeQueryWrapper.in(NcNode::getId, exportNodeIdList); List<NcNode> nodeList =ncNodeService.list(nodeQueryWrapper); for(NcNode node : nodeList){ JSONObject recObj = new JSONObject(); recObj.put("id", node.getId()); recObj.put("nodeType", node.getNodeType()); recObj.put("machineCode",node.getMachineCode()); recObj.put("parentId",node.getParentId()); recObj.put("description",node.getDescription()); recObj.put("name",node.getName()); recObj.put("remark",node.getRemark()); recObj.put("drawingNo",node.getDrawingNo()); recObj.put("parentIds",node.getParentIds()); recObj.put("processName",node.getProcessName()); addSuperProperties(recObj,node); jsonArray.add(recObj); } addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_nc_node.json"); } void addSuperProperties(JSONObject recObj, BizEntity entity){ recObj.put("tenantId",entity.getTenantId()); recObj.put("createTime",entity.getCreateTime()); recObj.put("updateTime",entity.getUpdateTime()); recObj.put("createUser",entity.getCreateUser()); recObj.put("updateUser",entity.getUpdateUser()); recObj.put("status",entity.getStatus()); recObj.put("createDept",entity.getCreateDept()); } public void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) throws IOException { blade-service/blade-mdm/src/main/java/org/springblade/mdm/machineback/vo/MachineBackFileVO.java
@@ -21,4 +21,6 @@ private Integer isCured=0; @Schema(description = "æä»¶å°è¾¾æ¶é´") private Date arrivedTime; @Schema(description = "确认æ¶é´") private Date determineTime; } blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java
@@ -1,5 +1,6 @@ package org.springblade.mdm.task; import com.alibaba.excel.util.StringUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.springblade.core.secure.utils.AuthUtil; @@ -35,12 +36,15 @@ // æ¯5ç§æ§è¡ä¸æ¬¡ //@Scheduled(fixedRate = 1000000) //@Scheduled(cron = "0 1 0 * * ?") // æ¯å¤©ä¸å0ç¹1åæ§è¡ @Scheduled(cron = "0 15 19 * * ?") //test @Scheduled(cron = "0 */5 * * * ?") //@Scheduled(cron = "0 15 19 * * ?") //test public void executeEvery5Seconds() { scanMachineFile(); } /** * æ«ææææºåºçé ç½®ä¹ç®å½ */ public void scanMachineFile() { List<Machine> machines = machineService.lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).list(); for (Machine machine : machines) { @@ -106,10 +110,12 @@ byte[] buffer = new byte[2048]; boolean exists;//æä»¶æ¯å¦åå¨äºæ°æ®åºä¸ MachineFile existFileInDb; //boolean exists;//æä»¶æ¯å¦åå¨äºæ°æ®åºä¸ for (Path filePath : files) { exists = false; existFileInDb = null; //exists = false; MachineFile mf = new MachineFile(); @@ -129,7 +135,7 @@ mf.setFileCreateTime(creationDate); FileTime modifyTime = attrs.lastModifiedTime(); mf.setFileModifyDate(new Date(modifyTime.toMillis())); mf.setFileModifyTime(new Date(modifyTime.toMillis())); mf.setFileSize(Files.size(filePath)); try (InputStream inputStream = Files.newInputStream(filePath)) { // 使ç¨è¾å ¥æµè¯»åæä»¶å 容 @@ -140,15 +146,31 @@ continue;//æé误,æ è¿ } exists = machineFileService.fileExists(mf.getName(),mf.getMd5(),machine.getCode()); //exists = machineFileService.fileExists(mf.getName(),dirType,machine.getCode()); existFileInDb = machineFileService.getExistsFile(mf.getName(),dirType,machine.getCode()); System.out.println("æä»¶å建æ¶é´: " + creationDate); } catch (IOException e) { log.error("读åæä»¶ä¿¡æ¯å¤±è´¥",e); } if(!exists) { if(existFileInDb == null) { machineFileService.save(mf); }else{ log.info("æä»¶å·²å¦ææ è¿:{}",filePath.getFileName()); //å·²åå¨åæ´ã existFileInDb.setFileSize(mf.getFileSize()); existFileInDb.setFileCreateTime(mf.getFileCreateTime()); existFileInDb.setFileModifyTime(mf.getFileModifyTime()); if(!StringUtils.equals(existFileInDb.getMd5(),mf.getMd5())){ //æä»¶å 容åçååäº,è®¾ç½®ç¶æä¸ºåå§ç¶æ existFileInDb.setStatus(MachineFile.STATUS_NORMAL); } existFileInDb.setMd5(mf.getMd5()); machineFileService.updateById(existFileInDb); } } @@ -172,6 +194,10 @@ return; } Path dirPath = Paths.get(basePath); if(!dirPath.toFile().exists()){ log.warn("æ«æç®å½:{} ä¸åå¨",dirPath); return; } List<Path> files = Files.list(dirPath) .filter(Files::isRegularFile).toList(); @@ -180,7 +206,6 @@ long findCount = files.stream().filter(filePath -> filePath.toFile().getName().equals(mf.getName())).count(); if(findCount == 0){ //æä»¶å¤¹å 没æ¾å°ï¼éè¦å é¤è®°å½ //this.machineFileService.save(mf); mf.markFileDeleted(); this.machineFileService.updateById(mf); } blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/ProgramFileNameParser.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,56 @@ package org.springblade.mdm.utils; import org.apache.commons.lang3.StringUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.IResultCode; import org.springblade.core.tool.utils.Func; import org.springblade.mdm.flow.service.FlowProgramProperties; import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; import org.springblade.mdm.program.service.NcNodeService; public class ProgramFileNameParser { /** * 仿件ååæç¨åºåç§°åæ®µ * @param filename æä»¶å */ public static ProgramNameVO parseProgramName(String filename){ ProgramNameVO pname = new ProgramNameVO(); int idx = filename.lastIndexOf("."); String tempstr = filename.substring(0,idx);//廿æ©å±å idx = tempstr.lastIndexOf("-"); if(idx != -1){ String segNo = tempstr.substring(idx+1); pname.setSegmentNo(Func.toInt(segNo)); tempstr = tempstr.substring(0,idx); } idx = tempstr.lastIndexOf("-"); if(idx != -1){ String seg = tempstr.substring(idx+1); pname.setSegmentCount(Func.toInt(seg)); tempstr = tempstr.substring(0,idx); } //è§£æå·¥åºç次 idx = tempstr.lastIndexOf("-"); if(idx != -1){ String processEdition = tempstr.substring(idx+1); pname.setProcessEdition(processEdition); tempstr = tempstr.substring(0,idx); } //è§£æå·¥åºå¥½ String processNo = ""; idx = tempstr.lastIndexOf("-"); if(idx != -1){ processNo = tempstr.substring(idx+1); tempstr = tempstr.substring(0,idx); } pname.setProcessNo(processNo); pname.setDrawingNo(tempstr); return pname; } } blade-service/blade-mdm/src/test/java/org/springblade/mdm/utils/ProgramFileNameParserTest.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,30 @@ package org.springblade.mdm.utils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; public class ProgramFileNameParserTest { @Test public void testParseProgramName() { String fname = "CP1-1-1-A-2-1.txt"; ProgramNameVO vo = ProgramFileNameParser.parseProgramName(fname); Assertions.assertEquals(2,vo.getSegmentCount()); Assertions.assertEquals(1,vo.getSegmentNo()); Assertions.assertEquals("A",vo.getProcessEdition()); Assertions.assertEquals("1",vo.getProcessNo()); Assertions.assertEquals("CP1-1",vo.getDrawingNo()); fname = "T-9-B-5-3.txt"; vo = ProgramFileNameParser.parseProgramName(fname); Assertions.assertEquals(5,vo.getSegmentCount()); Assertions.assertEquals(3,vo.getSegmentNo()); Assertions.assertEquals("B",vo.getProcessEdition()); Assertions.assertEquals("9",vo.getProcessNo()); Assertions.assertEquals("T",vo.getDrawingNo()); } }