| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.*; |
| | | import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProFeedbackTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProWorkOrderTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.feedback.MesProFeedbackDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | return respVO; |
| | | } |
| | | |
| | | @Override |
| | | public MesProFeedbackSummaryRespVO getFeedbackSummary(LocalDate beginDate, LocalDate endDate, |
| | | Integer workOrderType) { |
| | | // 1. 查询有效报工(已批准:待检验 + 已完成) |
| | | LambdaQueryWrapperX<MesProFeedbackDO> query = new LambdaQueryWrapperX<MesProFeedbackDO>() |
| | | .in(MesProFeedbackDO::getStatus, List.of( |
| | | MesProFeedbackStatusEnum.UNCHECK.getStatus(), |
| | | MesProFeedbackStatusEnum.FINISHED.getStatus())) |
| | | .betweenIfPresent(MesProFeedbackDO::getFeedbackTime, |
| | | beginDate != null ? beginDate.atStartOfDay() : null, |
| | | endDate != null ? endDate.plusDays(1).atStartOfDay() : null); |
| | | List<MesProFeedbackDO> feedbackList = feedbackMapper.selectList(query); |
| | | if (CollUtil.isEmpty(feedbackList)) { |
| | | MesProFeedbackSummaryRespVO empty = new MesProFeedbackSummaryRespVO(); |
| | | empty.setTotalFeedbackQuantity(BigDecimal.ZERO); |
| | | empty.setTotalQualifiedQuantity(BigDecimal.ZERO); |
| | | empty.setTotalFeedbackCount(0); |
| | | empty.setByType(Collections.emptyList()); |
| | | empty.setByDate(Collections.emptyList()); |
| | | return empty; |
| | | } |
| | | |
| | | // 2. 加载工单信息,映射 工单ID -> 工单类型 |
| | | Set<Long> workOrderIds = feedbackList.stream() |
| | | .map(MesProFeedbackDO::getWorkOrderId).filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap(workOrderIds); |
| | | |
| | | // 3. 过滤工单类型 |
| | | List<MesProFeedbackDO> filteredList = feedbackList.stream() |
| | | .filter(feedback -> { |
| | | if (workOrderType == null) { |
| | | return true; |
| | | } |
| | | MesProWorkOrderDO workOrder = workOrderMap.get(feedback.getWorkOrderId()); |
| | | return workOrder != null && Objects.equals(workOrder.getType(), workOrderType); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 4. 汇总 |
| | | BigDecimal totalFeedbackQuantity = BigDecimal.ZERO; |
| | | BigDecimal totalQualifiedQuantity = BigDecimal.ZERO; |
| | | int totalCount = 0; |
| | | for (MesProFeedbackDO feedback : filteredList) { |
| | | totalFeedbackQuantity = totalFeedbackQuantity.add(nullToZero(feedback.getFeedbackQuantity())); |
| | | totalQualifiedQuantity = totalQualifiedQuantity.add(nullToZero(feedback.getQualifiedQuantity())); |
| | | totalCount++; |
| | | } |
| | | |
| | | // 5. 按工单类型分组 |
| | | Map<Integer, MesProFeedbackSummaryRespVO.TypeSummaryItem> typeMap = new LinkedHashMap<>(); |
| | | // 6. 按日期分组 |
| | | Map<LocalDate, MesProFeedbackSummaryRespVO.DateSummaryItem> dateMap = new LinkedHashMap<>(); |
| | | for (MesProFeedbackDO feedback : filteredList) { |
| | | MesProWorkOrderDO workOrder = workOrderMap.get(feedback.getWorkOrderId()); |
| | | Integer type = workOrder != null ? workOrder.getType() : null; |
| | | if (type != null) { |
| | | MesProFeedbackSummaryRespVO.TypeSummaryItem item = typeMap.computeIfAbsent(type, key -> { |
| | | MesProFeedbackSummaryRespVO.TypeSummaryItem t = new MesProFeedbackSummaryRespVO.TypeSummaryItem(); |
| | | t.setWorkOrderType(key); |
| | | t.setWorkOrderTypeName(MesProWorkOrderTypeEnum.valueOf(key) != null |
| | | ? MesProWorkOrderTypeEnum.valueOf(key).getName() : String.valueOf(key)); |
| | | t.setFeedbackQuantity(BigDecimal.ZERO); |
| | | t.setQualifiedQuantity(BigDecimal.ZERO); |
| | | t.setFeedbackCount(0); |
| | | return t; |
| | | }); |
| | | item.setFeedbackQuantity(item.getFeedbackQuantity().add(nullToZero(feedback.getFeedbackQuantity()))); |
| | | item.setQualifiedQuantity(item.getQualifiedQuantity().add(nullToZero(feedback.getQualifiedQuantity()))); |
| | | item.setFeedbackCount(item.getFeedbackCount() + 1); |
| | | } |
| | | if (feedback.getFeedbackTime() != null) { |
| | | LocalDate date = feedback.getFeedbackTime().toLocalDate(); |
| | | MesProFeedbackSummaryRespVO.DateSummaryItem item = dateMap.computeIfAbsent(date, key -> { |
| | | MesProFeedbackSummaryRespVO.DateSummaryItem d = new MesProFeedbackSummaryRespVO.DateSummaryItem(); |
| | | d.setDate(key); |
| | | d.setFeedbackQuantity(BigDecimal.ZERO); |
| | | d.setQualifiedQuantity(BigDecimal.ZERO); |
| | | d.setFeedbackCount(0); |
| | | return d; |
| | | }); |
| | | item.setFeedbackQuantity(item.getFeedbackQuantity().add(nullToZero(feedback.getFeedbackQuantity()))); |
| | | item.setQualifiedQuantity(item.getQualifiedQuantity().add(nullToZero(feedback.getQualifiedQuantity()))); |
| | | item.setFeedbackCount(item.getFeedbackCount() + 1); |
| | | } |
| | | } |
| | | |
| | | // 7. 组装响应 |
| | | MesProFeedbackSummaryRespVO respVO = new MesProFeedbackSummaryRespVO(); |
| | | respVO.setTotalFeedbackQuantity(totalFeedbackQuantity); |
| | | respVO.setTotalQualifiedQuantity(totalQualifiedQuantity); |
| | | respVO.setTotalFeedbackCount(totalCount); |
| | | respVO.setByType(new ArrayList<>(typeMap.values())); |
| | | respVO.setByDate(new ArrayList<>(dateMap.values())); |
| | | return respVO; |
| | | } |
| | | |
| | | private static BigDecimal nullToZero(BigDecimal value) { |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |
| | | |
| | | } |