| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.common.config.ConstSysConfig; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.entity.request.DamageRequest; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | |
| | | import com.mes.hollow.service.HollowGlassRelationInfoService; |
| | | import com.mes.order.entity.HollowGlassDetailsDTO; |
| | | import com.mes.order.entity.OrderDetailsDTO; |
| | | import com.mes.order.entity.ProcessCardReport; |
| | | import com.mes.order.service.OrdersService; |
| | | import com.mes.sysconfig.service.SysConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<Integer, List<LackDetailsDTO>> queryLackByFlowCardByERP(String flowCardId) { |
| | | List<ProcessCardReport> processCardReports = ordersService.queryLackByERP(flowCardId); |
| | | if (CollectionUtil.isEmpty(processCardReports)) { |
| | | return null; |
| | | } |
| | | List<HollowBigStorageCageDetails> hollowBigStorageCageDetails = hollowBigStorageCageDetailsService.list( |
| | | new LambdaQueryWrapper<HollowBigStorageCageDetails>() |
| | | .eq(HollowBigStorageCageDetails::getFlowCardId, flowCardId) |
| | | .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL) |
| | | ); |
| | | // 1. 统计每个 (glassType, layer) 组合的出现次数 |
| | | Map<String, Long> typeLayerCountMap = hollowBigStorageCageDetails.stream() |
| | | .map(detail -> detail.getGlassType() + "_" + detail.getLayer()) |
| | | .collect(Collectors.groupingBy( |
| | | key -> key, // 以复合键为分组依据 |
| | | Collectors.counting() // 统计每个键的出现次数 |
| | | )); |
| | | // 2. 遍历并按次数减 quantity(避免负数) |
| | | processCardReports.forEach(report -> { |
| | | String reportPair = report.getOrderNumber() + "_" + report.getTechnologyNumber(); |
| | | Long count = typeLayerCountMap.getOrDefault(reportPair, 0L); |
| | | if (count > 0) { |
| | | int newQuantity = Math.max(0, report.getLackQuantity() - count.intValue()); |
| | | report.setLackQuantity(newQuantity); |
| | | } |
| | | }); |
| | | List<LackDetailsDTO> detailsDTOS = baseMapper.queryLackByFlowCardByERP(processCardReports); |
| | | List<Damage> damages = damageService.queryUnTempByFlowCardId(flowCardId); |
| | | // 1. 按(orderNumber+layer)分组,同时缓存DTO的其他字段作为模板 |
| | | Map<String, List<Damage>> damageMap = new HashMap<>(); |
| | | Map<String, LackDetailsDTO> dtoTemplateMap = new HashMap<>(); // 存储分组对应的DTO模板 |
| | | |
| | | // 1.1 初始化damage分组和DTO模板 |
| | | damages.forEach(damage -> { |
| | | if (damage.getOrderNumber() == null || damage.getTechnologyNumber() == null) { |
| | | return; |
| | | } |
| | | String key = damage.getOrderNumber() + "_" + damage.getTechnologyNumber(); |
| | | damageMap.computeIfAbsent(key, k -> new ArrayList<>()).add(damage); |
| | | }); |
| | | |
| | | detailsDTOS.forEach(dto -> { |
| | | if (dto.getGlassType() == null || dto.getLayer() == null) { |
| | | return; |
| | | } |
| | | String key = dto.getGlassType() + "_" + dto.getLayer(); |
| | | // 缓存第一个DTO作为模板(包含其他字段值) |
| | | dtoTemplateMap.putIfAbsent(key, dto); |
| | | }); |
| | | |
| | | // 2. 匹配并更新原始DTO |
| | | detailsDTOS.forEach(dto -> { |
| | | if (dto.getGlassType() == null || dto.getLayer() == null) { |
| | | return; |
| | | } |
| | | String key = dto.getGlassType() + "_" + dto.getLayer(); |
| | | List<Damage> damagess = damageMap.get(key); |
| | | if (damagess != null && !damagess.isEmpty()) { |
| | | Damage damage = damagess.remove(0); |
| | | dto.setGlassId(damage.getGlassId()); |
| | | dto.setWorkingProcedure(damage.getWorkingProcedure()); |
| | | } |
| | | }); |
| | | |
| | | // 3. 处理剩余damage:复用同组DTO模板的其他字段 |
| | | damageMap.values().forEach(damagess -> damagess.forEach(damage -> { |
| | | String key = damage.getOrderNumber() + "_" + damage.getTechnologyNumber(); |
| | | LackDetailsDTO template = dtoTemplateMap.get(key); // 获取同组模板 |
| | | if (template == null) return; // 无模板则跳过(理论上不会出现) |
| | | |
| | | LackDetailsDTO newDto = new LackDetailsDTO(); |
| | | // 1. 复制模板中的其他字段(除了glassId和workproduce) |
| | | BeanUtils.copyProperties(template, newDto); // 用Spring的工具类复制属性 |
| | | // 2. 覆盖glassId和workproduce为当前damage的值 |
| | | newDto.setGlassId(damage.getGlassId()); |
| | | newDto.setWorkingProcedure("未知"); |
| | | detailsDTOS.add(newDto); |
| | | })); |
| | | return detailsDTOS.stream().collect(Collectors.groupingBy(item -> item.getLayer())); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getGlassGapByThickness(Double thickness) { |
| | | int sysKey = 0; |
| | | if (thickness >= 12) { |
| | |
| | | |
| | | |
| | | private void sortFlowCardIdList(List<HollowAllFlowCardVO> list) { |
| | | Pattern pattern = Pattern.compile("^NG(\\d+)([A-Za-z]+)(\\d+)$"); |
| | | Pattern pattern = Pattern.compile("^(NG|R)(\\d+)([A-Za-z]+)(\\d+)$"); |
| | | |
| | | list.sort((v1, v2) -> { |
| | | Matcher m1 = pattern.matcher(v1.getFlowCardId()); |
| | | Matcher m2 = pattern.matcher(v2.getFlowCardId()); |
| | | |
| | | if (!m1.find() || !m2.find()) { |
| | | throw new IllegalArgumentException("获取到的流程卡不符合校验规则"); |
| | | log.info("获取到的流程卡不符合校验规则:流程卡A:{},流程卡B:{}", v1.getFlowCardId(), v2.getFlowCardId()); |
| | | return -1; |
| | | } |
| | | |
| | | // 提取部分 |
| | | BigInteger order1 = new BigInteger(m1.group(1)); |
| | | BigInteger order2 = new BigInteger(m2.group(1)); |
| | | String layer1 = m1.group(2); |
| | | String layer2 = m2.group(2); |
| | | BigInteger seq1 = new BigInteger(m1.group(3)); |
| | | BigInteger seq2 = new BigInteger(m2.group(3)); |
| | | BigInteger order1 = new BigInteger(m1.group(2)); |
| | | BigInteger order2 = new BigInteger(m2.group(2)); |
| | | String layer1 = m1.group(3); |
| | | String layer2 = m2.group(3); |
| | | BigInteger seq1 = new BigInteger(m1.group(4)); |
| | | BigInteger seq2 = new BigInteger(m2.group(4)); |
| | | |
| | | // 优先级排序 |
| | | int cmp = order1.compareTo(order2); |