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.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_RATE_TREND_PERIOD_INVALID; import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_RATE_TREND_PERIOD_INVALID;
/**
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum DeviceRateTrendPeriodEnum { public enum DeviceRateTrendPeriodEnum {
@ -44,6 +40,12 @@ public enum DeviceRateTrendPeriodEnum {
return new DateRange(start, start.with(TemporalAdjusters.lastDayOfMonth())); 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", "本月") { THIS_MONTH("THIS_MONTH", "本月") {
@Override @Override
public DateRange resolve(LocalDate today) { public DateRange resolve(LocalDate today) {

@ -7,6 +7,6 @@ import lombok.Data;
@Schema(description = "管理后台 - 生产计划质量概况 Request VO") @Schema(description = "管理后台 - 生产计划质量概况 Request VO")
public class PlanQualityOverviewReqVO { 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; 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.PlanPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityPageReqVO; 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.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.controller.admin.plan.vo.PlanStatusEnum;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO; import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -148,6 +149,15 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
List<Map<String, Object>> getLastSevenDaysCompletedCount(); 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, IPage<PlanProductCapacityRespVO> selectProductCapacityPage(Page<PlanProductCapacityRespVO> page,
@Param("reqVO") PlanProductCapacityPageReqVO reqVO, @Param("reqVO") PlanProductCapacityPageReqVO reqVO,
@Param("beginTime") LocalDateTime beginTime, @Param("beginTime") LocalDateTime beginTime,

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

@ -18,6 +18,47 @@
GROUP BY DATE(end_time) GROUP BY DATE(end_time)
</select> </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" <select id="selectProductCapacityPage"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityRespVO"> resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityRespVO">
SELECT SELECT

Loading…
Cancel
Save