¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.modules.dnc.entity.Cutter; |
| | | import org.jeecg.modules.dnc.entity.DocFile; |
| | | import org.jeecg.modules.dnc.entity.DocInfo; |
| | | import org.jeecg.modules.dnc.entity.GuideCardBatch; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.CutterMapper; |
| | | import org.jeecg.modules.dnc.response.CommonCode; |
| | | import org.jeecg.modules.dnc.service.ICutterService; |
| | | import org.jeecg.modules.dnc.service.IDocFileService; |
| | | import org.jeecg.modules.dnc.service.IDocInfoService; |
| | | import org.jeecg.modules.dnc.service.IGuideCardBatchService; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.tms.entity.PreparationOrderDetail; |
| | | import org.jeecg.modules.tms.entity.dto.PreparationOrderAndDetailDto; |
| | | import org.jeecg.modules.tms.service.IPreparationOrderService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class CutterServiceImpl extends ServiceImpl<CutterMapper, Cutter> implements ICutterService { |
| | | |
| | | @Autowired |
| | | private IDocInfoService docInfoService; |
| | | |
| | | @Autowired |
| | | private IDocFileService docFileService; |
| | | |
| | | @Autowired |
| | | private IGuideCardBatchService guideCardBatchService; |
| | | |
| | | @Autowired |
| | | private IPreparationOrderService preparationOrderService; |
| | | /** |
| | | * æ°å¢åå
·ä¿¡æ¯ |
| | | * @param cutter |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> add(Cutter cutter){ |
| | | if(cutter == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(cutter.getAttributionId())) |
| | | Result.error("æ æçåå
·"); |
| | | List<Cutter> cutterList =this.checkCutterNo(cutter); |
| | | if (cutterList != null && !cutterList.isEmpty()) { |
| | | return Result.error("å·²åå¨ç¸åçåå
·ç¼å·"); |
| | | } |
| | | boolean save = this.save(cutter); |
| | | if(save){ |
| | | return Result.OK("æ·»å åå
·æå"); |
| | | } |
| | | return Result.error("æ°å¢åå
·å¤±è´¥"); |
| | | } |
| | | |
| | | /** |
| | | * ç¼è¾åå
·ä¿¡æ¯ |
| | | * @param cutter |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> edit(Cutter cutter){ |
| | | // æ£æ¥ä¼ å
¥çåå
·å¯¹è±¡æ¯å¦ä¸ºç©º |
| | | if (cutter == null) { |
| | | return Result.OK("åå
·å¯¹è±¡ä¸è½ä¸ºç©º"); |
| | | } |
| | | // æ£æ¥åå
·åç§°æ¯å¦ææ |
| | | if (!ValidateUtil.validateString(cutter.getCutterName())) { |
| | | return Result.OK("åå
·åç§°æ æ"); |
| | | } |
| | | // æ ¹æ®åå
· ID è·ååå
·ä¿¡æ¯ |
| | | Cutter existingCutter = super.getById(cutter.getId()); |
| | | if (existingCutter == null) { |
| | | return Result.OK("åå
·ä¸åå¨"); |
| | | } |
| | | // è¿æ»¤æå½åè¦ç¼è¾çåå
·ï¼æ£æ¥æ¯å¦æå
¶ä»åå
·åå¨ç¸åç¼å· |
| | | List<Cutter> otherCuttersWithSameNo = this.checkCutterNo(cutter).stream() |
| | | .filter(cut -> !cut.getId().equals(cutter.getId())) |
| | | .collect(Collectors.toList()); |
| | | if (!otherCuttersWithSameNo.isEmpty()) { |
| | | // 妿åå¨é¤å½ååå
·å¤çå
¶ä»åå
·ç¼å·éå¤ |
| | | return Result.error("å·²åå¨ç¸åçåå
·ç¼å·"); |
| | | } |
| | | // å°è¯æ´æ°åå
·ä¿¡æ¯ |
| | | boolean updated = this.updateById(cutter); |
| | | if (updated) { |
| | | return Result.OK("åå
·ä¿¡æ¯ç¼è¾æå"); |
| | | } else { |
| | | return Result.error("åå
·ä¿¡æ¯ç¼è¾å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤åå
·ä¿¡æ¯ |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> delete(String id){ |
| | | if(!ValidateUtil.validateString(id)) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | Cutter en = super.getById(id); |
| | | if(en == null) |
| | | return Result.error("æ æçåå
·"); |
| | | boolean b=super.removeById(id); |
| | | if(!b) { |
| | | return Result.error("å é¤åå
·å¤±è´¥"); |
| | | } |
| | | return Result.OK("å é¤åå
·æå"); |
| | | } |
| | | |
| | | /** |
| | | * éªè¯åç»æä¸åå
·ç¼å·æ¯å¦éå¤ |
| | | * @param cutter |
| | | * @return |
| | | */ |
| | | public List<Cutter> checkCutterNo(Cutter cutter){ |
| | | QueryWrapper<Cutter> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getAttributionId()),"attribution_id",cutter.getAttributionId()); |
| | | queryWrapper.eq("attribution_type",cutter.getAttributionType()); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getCutterCode()),"cutter_code",cutter.getCutterCode()); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getCutterType()),"cutter_type",cutter.getCutterType()); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getCutterSpacing()),"cutter_spacing",cutter.getCutterSpacing()); |
| | | return baseMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸å¡idä¸çåå
·å表 |
| | | * @param cutter |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> query(Cutter cutter, Integer pageNo, Integer pageSize){ |
| | | QueryWrapper<Cutter> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getAttributionId()),"attribution_id",cutter.getAttributionId()); |
| | | if (cutter.getAttributionType() != null){ |
| | | queryWrapper.eq("attribution_type",cutter.getAttributionType()); |
| | | } |
| | | queryWrapper.eq(StrUtil.isNotEmpty(cutter.getDocId()),"doc_id",cutter.getDocId()); |
| | | queryWrapper.like(StrUtil.isNotEmpty(cutter.getCutterCode()),"cutter_code",cutter.getCutterCode()); |
| | | queryWrapper.like(StrUtil.isNotEmpty(cutter.getCutterName()),"cutter_name",cutter.getCutterName()); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | Page<Cutter> page = new Page<>(pageNo,pageSize); |
| | | IPage<Cutter> cutterIPage = baseMapper.selectPage(page, queryWrapper); |
| | | return Result.OK(cutterIPage); |
| | | } |
| | | |
| | | /** |
| | | * ä»NCæä»¶å
容æååå
·ä¿¡æ¯å¹¶ä¿å |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result<?> extractAndSaveFromContent(String docId,String attributionId,Integer attributionType){ |
| | | DocInfo docInfo=docInfoService.getById(docId); |
| | | if (docInfo == null) { |
| | | return Result.error("æªæ¾å°å¯¹åºææ¡£ä¿¡æ¯ï¼æ æ³æååå
·ä¿¡æ¯"); |
| | | } |
| | | docInfo.setAttributionId(attributionId); |
| | | docInfo.setAttributionType(attributionType); |
| | | DocFile docFile=docFileService.getById(docInfo.getPublishFileId()); |
| | | if (docFile == null) { |
| | | return Result.error("æªæ¾å°å¯¹åºæä»¶ä¿¡æ¯ï¼æ æ³æååå
·ä¿¡æ¯"); |
| | | } |
| | | String filePath = docFile.getFilePath(); |
| | | String fileEncodeName = docFile.getFileEncodeName(); |
| | | //ææ¡£å
容 |
| | | List<String> list = FileUtilS.readFile(fileEncodeName, filePath); |
| | | if (list == null || list.isEmpty()) { |
| | | return Result.error("ææ¡£å
å®¹ä¸ºç©ºï¼æ æ³æååå
·ä¿¡æ¯"); |
| | | } |
| | | List<Cutter> cutterList = extractToolAfterM6(docInfo,list); |
| | | // ä¿ååå
· |
| | | if (!cutterList.isEmpty()) { |
| | | List<Cutter> newCutterList = new ArrayList<>(); |
| | | //éªè¯åå
·æ¯å¦å·²ç»åå¨ |
| | | cutterList.forEach(item -> { |
| | | List<Cutter> otherCuttersWithSameNo = checkCutterNo(item); |
| | | if (otherCuttersWithSameNo == null || otherCuttersWithSameNo.isEmpty()) { |
| | | newCutterList.add(item); |
| | | } |
| | | }); |
| | | if (newCutterList.isEmpty()) { |
| | | return Result.error("æªåç°åå
·çåæ°ä¿¡æ¯æ³¨éï¼æ æ³æååå
·ä¿¡æ¯"); |
| | | } |
| | | this.saveBatch(newCutterList); |
| | | return Result.OK("æååå
·ä¿¡æ¯æå"); |
| | | }else { |
| | | return Result.error("æªåç°åå
·çåæ°ä¿¡æ¯æ³¨éï¼æ æ³æååå
·ä¿¡æ¯"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Result<?> sendToCutterSystem(String docId,String attributionId,Integer attributionType){ |
| | | List<Cutter> cutterList = this.list(new QueryWrapper<Cutter>() |
| | | .eq("doc_id", docId) |
| | | .eq(StrUtil.isNotEmpty(attributionId),"attribution_id",attributionId) |
| | | .eq("attribution_type",attributionType)); |
| | | if (cutterList == null || cutterList.isEmpty()) { |
| | | return Result.error("æªåç°åå
·ä¿¡æ¯ï¼æ æ³åéå°åå
·ç³»ç»"); |
| | | } |
| | | if (cutterList.stream().anyMatch(item -> item.getCutterCode() == null)) { |
| | | return Result.error("æªåç°åå
·ç¼å·ä¿¡æ¯ï¼æ æ³åéå°åå
·ç³»ç»"); |
| | | } |
| | | //è·åææ°æ°æ§ç¨åºå 工确认表 |
| | | List<GuideCardBatch> guideCardBatchList = guideCardBatchService.list(new QueryWrapper<GuideCardBatch>() |
| | | .eq("doc_id", docId) |
| | | .isNotNull("serial_number") |
| | | .orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)")); |
| | | if (guideCardBatchList == null || guideCardBatchList.isEmpty()) { |
| | | return Result.error("æªåç°ç¨åºå 工确认表信æ¯ï¼æ æ³åéå°åå
·ç³»ç»"); |
| | | } |
| | | GuideCardBatch guideCardBatch = guideCardBatchList.get(0); |
| | | PreparationOrderAndDetailDto dto = new PreparationOrderAndDetailDto(); |
| | | dto.setPartDrawingNo(guideCardBatch.getPartsCode()); |
| | | dto.setPartName(guideCardBatch.getPartsName()); |
| | | dto.setPartMaterial(guideCardBatch.getMaterielDesp()); |
| | | dto.setProductionProcessesNo(guideCardBatch.getProcessWorkCode()); |
| | | dto.setBatchCode(guideCardBatch.getProcessingBatch()); |
| | | dto.setMachiningCount(guideCardBatch.getProcessingQuantity()); |
| | | dto.setEquipmentCode(guideCardBatch.getProcessingEquipment()); |
| | | dto.setNcName(guideCardBatch.getDocName()); |
| | | List<PreparationOrderDetail> detailList = new ArrayList<>(); |
| | | cutterList.forEach(item -> { |
| | | PreparationOrderDetail detail = new PreparationOrderDetail(); |
| | | detail.setToolCode(item.getCutterCode()); |
| | | detail.setToolId(item.getToolsId()); |
| | | detailList.add(detail); |
| | | }); |
| | | dto.setPreparationOrderDetailList(detailList); |
| | | preparationOrderService.addPreparationOrderFromDnc(dto); |
| | | return Result.OK("åéå°åå
·ç³»ç»æå"); |
| | | } |
| | | |
| | | public List<Cutter> extractToolAfterM6(DocInfo docInfo, List<String> ncLines) { |
| | | List<Cutter> cutterList = new ArrayList<>(); |
| | | String currentToolCode = null; // ç¨äºè¿½è¸ªå½åæ¢åæä»¤çåå
·å· |
| | | |
| | | for (String line : ncLines) { |
| | | String trimmedLine = line.trim(); |
| | | |
| | | // 1. å¹é
M6 æ¢åæä»¤ï¼æå T代ç ï¼å¦ T01 M06 æ T 02 M06ï¼ |
| | | if (trimmedLine.contains("M6")||trimmedLine.contains("M06")) { |
| | | currentToolCode = extractToolCodeFromM6Line(trimmedLine); |
| | | } |
| | | |
| | | // 2. å¹é
åå
·åæ°æ³¨éï¼ç´§è·å¨ M6 åçæ¬å·å
å®¹ï¼ |
| | | if (currentToolCode != null && trimmedLine.startsWith("(") && trimmedLine.endsWith(")")) { |
| | | String toolDescription = trimmedLine.substring(1, trimmedLine.length() - 1).trim(); |
| | | if (!toolDescription.isEmpty()) { |
| | | Cutter cutter = new Cutter(); |
| | | cutter.setDocId(docInfo.getDocId()); |
| | | cutter.setAttributionId(docInfo.getAttributionId()); |
| | | cutter.setAttributionType(docInfo.getAttributionType()); |
| | | cutter.setDescription(toolDescription); |
| | | |
| | | // ä»åå
·æè¿°ä¸æå cutterCode (ä¾å¦ä» "90E-10A" 䏿å "E") |
| | | extractToolInfoFromDescription(toolDescription, cutter); |
| | | |
| | | // 设置åå
·é´è·ï¼ä½¿ç¨Tä»£ç æå
¶ä»é»è¾ï¼ |
| | | cutter.setCutterSpacing(currentToolCode); |
| | | |
| | | // æååå
·åç§°ä¸è§æ ¼ï¼ç®åæç©ºæ ¼åå²ï¼åé¨å为åç§°ï¼åé¨åä¸ºè§æ ¼ï¼ |
| | | String[] parts = toolDescription.split(" ", 2); |
| | | if (parts.length >= 1) { |
| | | cutter.setCutterName(parts[0]); |
| | | } |
| | | cutterList.add(cutter); |
| | | currentToolCode = null; // éç½®ï¼é¿å
éå¤å¹é
|
| | | } |
| | | } |
| | | } |
| | | |
| | | return cutterList; |
| | | } |
| | | |
| | | /** |
| | | * ä»åå
·æè¿°ä¸æå cutterType å cutterCode |
| | | * ä¾å¦: "8CH-90A" -> cutterType="CH", cutterCode="90A" |
| | | */ |
| | | private void extractToolInfoFromDescription(String description, Cutter cutter) { |
| | | // æååå
·åå·ï¼ä¸ä¸ªæå¤ä¸ªè¿ç»ç大ååæ¯ï¼ |
| | | String cutterType = extractCutterType(description); |
| | | cutter.setCutterType(cutterType); |
| | | // æåç ´æå·åçè§æ ¼é¨å |
| | | String cutterSpec = ""; |
| | | int dashIndex = description.indexOf('-'); |
| | | if (dashIndex != -1 && dashIndex < description.length() - 1) { |
| | | cutterSpec = description.substring(dashIndex + 1).trim(); |
| | | cutter.setCutterSpec(cutterSpec); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æååå
·åå·ï¼ä¸ä¸ªæå¤ä¸ªè¿ç»ç大ååæ¯ï¼ |
| | | */ |
| | | private String extractCutterType(String description) { |
| | | Pattern pattern = Pattern.compile("[A-Z]+"); |
| | | Matcher matcher = pattern.matcher(description); |
| | | |
| | | if (matcher.find()) { |
| | | return matcher.group(); |
| | | } |
| | | |
| | | return description; |
| | | } |
| | | |
| | | // è¾
婿¹æ³ï¼ä» M6 è¡æå T代ç ï¼æ¯æ T01 æ T 01 æ ¼å¼ï¼ |
| | | private String extractToolCodeFromM6Line(String line) { |
| | | Matcher matcher = Pattern.compile("T(\\d+)").matcher(line); |
| | | return matcher.find() ? "T" + matcher.group(1).trim() : null; |
| | | } |
| | | } |
| | | |