| | |
| | | package com.mes.damage.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.mapper.DamageMapper; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.mapper.GlassInfoMapper; |
| | | import com.mes.pp.entity.ReportingWork; |
| | | import com.mes.work_assignment.entity.WorkAssignment; |
| | | import com.mes.work_assignment.mapper.WorkAssignmentMapper; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void submitDamage(List<Damage> damageList) { |
| | | Map<String, Map<String, Map<String, Map<String, List<Damage>>>>> resultMap = damageList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | Damage::getProcessId, |
| | | Collectors.groupingBy( |
| | | Damage::getWorkingProcedure, |
| | | Collectors.groupingBy( |
| | | Damage::getDeviceName, |
| | | Collectors.groupingBy(Damage::getTeamsGroupsName) |
| | | ) |
| | | ) |
| | | )); |
| | | // 遍历 resultMap |
| | | for (Map.Entry<String, Map<String, Map<String, Map<String, List<Damage>>>>> processEntry : resultMap.entrySet()) { |
| | | String processId = processEntry.getKey(); |
| | | System.out.println("ProcessId: " + processId); |
| | | Map<String, List<Damage>> firstMap = damageList.stream().collect(Collectors.groupingBy(e -> e.getProcessId() + ":" |
| | | + e.getWorkingProcedure() + ":" + e.getDeviceName() + ":" + e.getTeamsGroupsName())); |
| | | |
| | | // 获取第二层的 Map,按 workingProcedure 分组的结果 |
| | | Map<String, Map<String, Map<String, List<Damage>>>> workingProcedureMap = processEntry.getValue(); |
| | | for (Map.Entry<String, List<Damage>> entry : firstMap.entrySet()) { |
| | | String key = entry.getKey(); |
| | | List<Damage> damages = entry.getValue(); |
| | | |
| | | // 遍历 workingProcedureMap |
| | | for (Map.Entry<String, Map<String, Map<String, List<Damage>>>> workingProcedureEntry : workingProcedureMap.entrySet()) { |
| | | String workingProcedure = workingProcedureEntry.getKey(); |
| | | System.out.println(" WorkingProcedure: " + workingProcedure); |
| | | System.out.println("Key: " + key); |
| | | |
| | | // 获取第三层的 Map,按 deviceName 分组的结果 |
| | | Map<String, Map<String, List<Damage>>> deviceNameMap = workingProcedureEntry.getValue(); |
| | | Map<String, List<Damage>> secondMap = damageList.stream().collect(Collectors.groupingBy(e -> e.getProcessId() + ":" |
| | | + e.getWorkingProcedure() + ":" + e.getDeviceName() + ":" + e.getTeamsGroupsName())); |
| | | |
| | | // 遍历 deviceNameMap |
| | | for (Map.Entry<String, Map<String, List<Damage>>> deviceNameEntry : deviceNameMap.entrySet()) { |
| | | String deviceName = deviceNameEntry.getKey(); |
| | | System.out.println(" DeviceName: " + deviceName); |
| | | for (Map.Entry<String, List<Damage>> entrys : secondMap.entrySet()) { |
| | | |
| | | // 获取第四层的 Map,按 teamsGroupsName 分组的结果 |
| | | Map<String, List<Damage>> teamsGroupsNameMap = deviceNameEntry.getValue(); |
| | | |
| | | // 遍历 teamsGroupsNameMap |
| | | for (Map.Entry<String, List<Damage>> teamsGroupsNameEntry : teamsGroupsNameMap.entrySet()) { |
| | | String teamsGroupsName = teamsGroupsNameEntry.getKey(); |
| | | System.out.println(" TeamsGroupsName: " + teamsGroupsName); |
| | | |
| | | // 获取 Damage 列表 |
| | | List<Damage> damageListForTeamsGroupsName = teamsGroupsNameEntry.getValue(); |
| | | //报工主表数据 |
| | | ReportingWork reportingWork = new ReportingWork(); |
| | | reportingWork.setProcessId(processId); |
| | | reportingWork.setThisProcess(workingProcedure); |
| | | reportingWork.setDeviceName(deviceName); |
| | | reportingWork.setTeamsGroupsName(teamsGroupsName); |
| | | |
| | | Map<Integer, Map<Integer, Map<String, List<Damage>>>> groupedByOrderTechBreakage = damageListForTeamsGroupsName.stream() |
| | | .map(damage -> Optional.ofNullable(damage)) // 使用Optional处理可能为null的元素 |
| | | .filter(Optional::isPresent) // 过滤掉空的Optional |
| | | .map(Optional::get) // 获取非空的Damage对象 |
| | | .collect(Collectors.groupingBy( |
| | | damage -> Optional.ofNullable(damage.getOrderNumber()).orElse(0), // 使用orElse设置默认值,以处理null值 |
| | | Collectors.groupingBy( |
| | | damage -> Optional.ofNullable(damage.getTechnologyNumber()).orElse(0), // 同样处理technologyNumber可能为null的情况 |
| | | Collectors.groupingBy( |
| | | damage -> Optional.ofNullable(damage.getBreakageType()).orElse("Unknown"), // 处理breakageType可能为null的情况 |
| | | Collectors.toList() |
| | | ) |
| | | ) |
| | | )); |
| | | |
| | | // 遍历 groupedByOrderTechBreakage |
| | | for (Map.Entry<Integer, Map<Integer, Map<String, List<Damage>>>> orderEntry : groupedByOrderTechBreakage.entrySet()) { |
| | | Integer orderNumber = orderEntry.getKey(); |
| | | System.out.println(" OrderNumber: " + orderNumber); |
| | | |
| | | // 获取第二层的 Map,按 technologyNumber 分组的结果 |
| | | Map<Integer, Map<String, List<Damage>>> technologyNumberMap = orderEntry.getValue(); |
| | | |
| | | // 遍历 technologyNumberMap |
| | | for (Map.Entry<Integer, Map<String, List<Damage>>> technologyEntry : technologyNumberMap.entrySet()) { |
| | | Integer technologyNumber = technologyEntry.getKey(); |
| | | System.out.println(" TechnologyNumber: " + technologyNumber); |
| | | |
| | | // 获取第三层的 Map,按 breakageType 分组的结果 |
| | | Map<String, List<Damage>> breakageTypeMap = technologyEntry.getValue(); |
| | | |
| | | // 遍历 breakageTypeMap |
| | | for (Map.Entry<String, List<Damage>> breakageTypeEntry : breakageTypeMap.entrySet()) { |
| | | String breakageType = breakageTypeEntry.getKey(); |
| | | System.out.println(" BreakageType: " + breakageType); |
| | | |
| | | |
| | | // 获取 Damage 列表 |
| | | List<Damage> damageListForBreakageType = breakageTypeEntry.getValue(); |
| | | int completedQuantity = 0; |
| | | int breakageQuantity = 0; |
| | | // 遍历 Damage 列表 |
| | | for (Damage damage : damageListForBreakageType) { |
| | | // 打印或处理每个 Damage 对象 |
| | | System.out.println(" Damage: " + damage.toString()); |
| | | if (damage.getType() == 1) { |
| | | completedQuantity += 1; |
| | | } else if (damage.getType() == 2) { |
| | | breakageQuantity += 1; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | damage.setOrderNumber(glassInfo.getGlassType()); |
| | | damage.setTechnologyNumber(glassInfo.getLayer()); |
| | | damage.setDamageTime(Timestamp.valueOf(LocalDateTime.now())); |
| | | damage.setType(2); |
| | | baseMapper.insert(damage); |
| | | } |
| | | |
| | | /** |
| | | * 添加报工信息 |
| | | */ |
| | | @Override |
| | | public void batchInsertDamage(List<Damage> damageList) { |
| | | WorkAssignment workAssignment = workAssignmentMapper.selectOne(new LambdaQueryWrapper<WorkAssignment>() |
| | | .eq(WorkAssignment::getLine, damageList.get(0).getLine()) |
| | | .eq(WorkAssignment::getWorkProcesses, damageList.get(0).getWorkingProcedure())); |
| | | |
| | | List<String> glassList = damageList.stream().map(Damage::getGlassId).collect(Collectors.toList()); |
| | | List<GlassInfo> glassInfoList = glassInfoMapper.selectList(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, glassList)); |
| | | Map<String, List<GlassInfo>> listMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getGlassId)); |
| | | for (Damage damage : damageList) { |
| | | GlassInfo glassInfo = listMap.get(damage.getGlassId()).get(0); |
| | | BeanUtils.copyProperties(glassInfo, damage); |
| | | if (workAssignment != null) { |
| | | damage.setTeamsGroupsName(workAssignment.getTeamsGroupsName()); |
| | | damage.setDeviceName(workAssignment.getDeviceName()); |
| | | } |
| | | damage.setProcessId(glassInfo.getFlowCardId()); |
| | | damage.setOrderNumber(glassInfo.getGlassType()); |
| | | damage.setTechnologyNumber(glassInfo.getLayer()); |
| | | damage.setDamageTime(Timestamp.valueOf(LocalDateTime.now())); |
| | | } |
| | | this.saveBatch(damageList); |
| | | } |
| | | } |