feat:优化app概况接口

main
HuangHuiKang 1 week ago
parent 13183a6a2a
commit 4b08408511

@ -9,10 +9,6 @@ import java.time.temporal.TemporalAdjusters;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_RATE_TREND_PERIOD_INVALID;
/**
*/
@Getter
@AllArgsConstructor
public enum DeviceRateTrendPeriodEnum {
@ -44,6 +40,12 @@ public enum DeviceRateTrendPeriodEnum {
return new DateRange(start, start.with(TemporalAdjusters.lastDayOfMonth()));
}
},
LAST_YEAR("LAST_YEAR", "近一年") {
@Override
public DateRange resolve(LocalDate today) {
return new DateRange(today.minusYears(1), today.minusDays(1));
}
},
THIS_MONTH("THIS_MONTH", "本月") {
@Override
public DateRange resolve(LocalDate today) {

@ -7,6 +7,6 @@ import lombok.Data;
@Schema(description = "管理后台 - 生产计划质量概况 Request VO")
public class PlanQualityOverviewReqVO {
@Schema(description = "时间区间LAST_WEEK/THIS_WEEK/LAST_7_DAYS/LAST_MONTH/THIS_MONTH")
@Schema(description = "时间区间LAST_WEEK/THIS_WEEK/LAST_7_DAYS/LAST_MONTH/THIS_MONTH/LAST_YEAR")
private String period;
}

@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanStatusEnum;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -148,6 +149,15 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
List<Map<String, Object>> getLastSevenDaysCompletedCount();
PlanQualityOverviewRespVO selectQualityOverviewSummary(@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
List<PlanQualityOverviewRespVO.ProductPassRateItem> selectQualityOverviewProductStats(@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
List<PlanQualityOverviewRespVO.TrendItem> selectQualityOverviewTrendStats(@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
IPage<PlanProductCapacityRespVO> selectProductCapacityPage(Page<PlanProductCapacityRespVO> page,
@Param("reqVO") PlanProductCapacityPageReqVO reqVO,
@Param("beginTime") LocalDateTime beginTime,

@ -474,15 +474,11 @@ public class PlanServiceImpl implements PlanService {
LocalDateTime startTime = startDate.atStartOfDay();
LocalDateTime endTime = endDate.plusDays(1).atStartOfDay();
List<PlanDO> planList = planMapper.selectList(new LambdaQueryWrapper<PlanDO>()
.ge(PlanDO::getCreateTime, startTime)
.lt(PlanDO::getCreateTime, endTime));
PlanQualityOverviewRespVO respVO = new PlanQualityOverviewRespVO();
long totalWangongNumber = 0L;
long totalPassNumber = 0L;
long totalNoPassNumber = 0L;
Map<Long, PlanQualityOverviewRespVO.ProductPassRateItem> productMap = new HashMap<>();
PlanQualityOverviewRespVO respVO = Optional.ofNullable(planMapper.selectQualityOverviewSummary(startTime, endTime))
.orElseGet(PlanQualityOverviewRespVO::new);
long totalWangongNumber = Optional.ofNullable(respVO.getTotalWangongNumber()).orElse(0L);
long totalPassNumber = Optional.ofNullable(respVO.getTotalPassNumber()).orElse(0L);
long totalNoPassNumber = Optional.ofNullable(respVO.getTotalNoPassNumber()).orElse(0L);
Map<LocalDate, PlanQualityOverviewRespVO.TrendItem> trendMap = new LinkedHashMap<>();
for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
@ -493,46 +489,33 @@ public class PlanServiceImpl implements PlanService {
trendMap.put(date, trendItem);
}
for (PlanDO plan : planList) {
long wangongNumber = Optional.ofNullable(plan.getWangongNumber()).orElse(0L);
long passNumber = Optional.ofNullable(plan.getPassNumber()).orElse(0L);
long noPassNumber = Optional.ofNullable(plan.getNoPassNumber()).orElse(0L);
totalWangongNumber += wangongNumber;
totalPassNumber += passNumber;
totalNoPassNumber += noPassNumber;
if (plan.getProductId() != null) {
PlanQualityOverviewRespVO.ProductPassRateItem item = productMap.computeIfAbsent(plan.getProductId(), key -> {
PlanQualityOverviewRespVO.ProductPassRateItem value = new PlanQualityOverviewRespVO.ProductPassRateItem();
value.setProductId(key);
value.setWangongNumber(0L);
value.setPassNumber(0L);
value.setNoPassNumber(0L);
value.setPassRate(BigDecimal.ZERO);
return value;
});
item.setWangongNumber(item.getWangongNumber() + wangongNumber);
item.setPassNumber(item.getPassNumber() + passNumber);
item.setNoPassNumber(item.getNoPassNumber() + noPassNumber);
List<PlanQualityOverviewRespVO.TrendItem> dbTrendList = planMapper.selectQualityOverviewTrendStats(startTime, endTime);
for (PlanQualityOverviewRespVO.TrendItem item : dbTrendList) {
if (item == null || item.getDay() == null) {
continue;
}
LocalDate trendDate = Optional.ofNullable(plan.getCreateTime())
.map(LocalDateTime::toLocalDate)
.orElse(null);
if (trendDate != null && trendMap.containsKey(trendDate)) {
PlanQualityOverviewRespVO.TrendItem trendItem = trendMap.get(trendDate);
trendItem.setPassNumber(trendItem.getPassNumber() + passNumber);
trendItem.setNoPassNumber(trendItem.getNoPassNumber() + noPassNumber);
LocalDate trendDate = LocalDate.parse(item.getDay());
PlanQualityOverviewRespVO.TrendItem trendItem = trendMap.get(trendDate);
if (trendItem == null) {
continue;
}
trendItem.setPassNumber(Optional.ofNullable(item.getPassNumber()).orElse(0L));
trendItem.setNoPassNumber(Optional.ofNullable(item.getNoPassNumber()).orElse(0L));
}
Map<Long, ErpProductRespVO> productRespMap = erpProductService.getProductVOMap(productMap.keySet());
List<PlanQualityOverviewRespVO.ProductPassRateItem> productPassRateList = new ArrayList<>(productMap.values());
List<PlanQualityOverviewRespVO.ProductPassRateItem> productPassRateList = planMapper.selectQualityOverviewProductStats(startTime, endTime);
Map<Long, ErpProductRespVO> productRespMap = erpProductService.getProductVOMap(productPassRateList.stream()
.map(PlanQualityOverviewRespVO.ProductPassRateItem::getProductId)
.filter(Objects::nonNull)
.collect(Collectors.toSet()));
productPassRateList.forEach(item -> {
ErpProductRespVO product = productRespMap.get(item.getProductId());
if (product != null) {
item.setProductName(product.getName());
item.setProductName(StringUtils.isNotBlank(product.getBarCode())
? "【" + product.getBarCode() + "】" + product.getName()
: product.getName());
} else if (item.getProductId() != null) {
item.setProductName("产品[" + item.getProductId() + "]");
}
item.setPassRate(calculatePassRate(item.getPassNumber(), item.getWangongNumber()));
});

@ -18,6 +18,47 @@
GROUP BY DATE(end_time)
</select>
<select id="selectQualityOverviewSummary"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO">
SELECT
IFNULL(SUM(wangong_number), 0) AS totalWangongNumber,
IFNULL(SUM(pass_number), 0) AS totalPassNumber,
IFNULL(SUM(no_pass_number), 0) AS totalNoPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
</select>
<select id="selectQualityOverviewProductStats"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO$ProductPassRateItem">
SELECT
product_id AS productId,
IFNULL(SUM(wangong_number), 0) AS wangongNumber,
IFNULL(SUM(pass_number), 0) AS passNumber,
IFNULL(SUM(no_pass_number), 0) AS noPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
AND product_id IS NOT NULL
GROUP BY product_id
</select>
<select id="selectQualityOverviewTrendStats"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO$TrendItem">
SELECT
DATE(create_time) AS day,
IFNULL(SUM(pass_number), 0) AS passNumber,
IFNULL(SUM(no_pass_number), 0) AS noPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
GROUP BY DATE(create_time)
ORDER BY DATE(create_time)
</select>
<select id="selectProductCapacityPage"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityRespVO">
SELECT

Loading…
Cancel
Save