fix:添加app-生产概况-产品时间筛选

ck
HuangHuiKang 1 month ago
parent 6185639d4a
commit 7616b34052

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo; package cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.mes.enums.BaogongTrendTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@ -12,6 +14,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data @Data
public class BaogongRecordTrendReqVO { public class BaogongRecordTrendReqVO {
@Schema(description = "趋势类型1-近一年2-本月3-本周4-今日5-自定义", example = "4")
@InEnum(BaogongTrendTypeEnum.class)
private Integer trendType;
@Schema(description = "开始时间") @Schema(description = "开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime beginBaogongTime; private LocalDateTime beginBaogongTime;
@ -21,4 +27,3 @@ public class BaogongRecordTrendReqVO {
private LocalDateTime endBaogongTime; private LocalDateTime endBaogongTime;
} }

@ -37,4 +37,10 @@ public interface BaogongRecordMapper extends BaseMapperX<BaogongRecordDO> {
List<BaogongRecordTrendDayRespVO> selectTrendByDay(@Param("reqVO") BaogongRecordTrendReqVO reqVO); List<BaogongRecordTrendDayRespVO> selectTrendByDay(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
List<BaogongRecordTrendDayRespVO> selectTrendByMonth(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
List<BaogongRecordTrendDayRespVO> selectTrendByWeekday(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
List<BaogongRecordTrendDayRespVO> selectTrendByHour(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
} }

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.mes.enums;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
@Getter
@AllArgsConstructor
public enum BaogongTrendTypeEnum implements IntArrayValuable {
YEAR(1, "近一年"),
MONTH(2, "本月"),
WEEK(3, "本周"),
TODAY(4, "今日"),
CUSTOM(5, "自定义");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BaogongTrendTypeEnum::getType).toArray();
private final Integer type;
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
public static BaogongTrendTypeEnum valueOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
}

@ -8,12 +8,17 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*; import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.*; import cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.baogongrecord.BaogongRecordDO; import cn.iocoder.yudao.module.mes.dal.dataobject.baogongrecord.BaogongRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.enums.BaogongTrendTypeEnum;
import cn.iocoder.yudao.module.mes.dal.mysql.baogongrecord.BaogongRecordMapper; import cn.iocoder.yudao.module.mes.dal.mysql.baogongrecord.BaogongRecordMapper;
@ -85,6 +90,7 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
@Override @Override
public BaogongRecordTrendRespVO getBaogongRecordTrend(BaogongRecordTrendReqVO reqVO) { public BaogongRecordTrendRespVO getBaogongRecordTrend(BaogongRecordTrendReqVO reqVO) {
fillTrendTimeRange(reqVO);
BaogongRecordTrendRespVO respVO = baogongRecordMapper.selectTrendSummary(reqVO); BaogongRecordTrendRespVO respVO = baogongRecordMapper.selectTrendSummary(reqVO);
if (respVO == null) { if (respVO == null) {
respVO = new BaogongRecordTrendRespVO(); respVO = new BaogongRecordTrendRespVO();
@ -93,10 +99,59 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
respVO.setNoPassNum(0L); respVO.setNoPassNum(0L);
respVO.setPassRate(BigDecimal.ZERO); respVO.setPassRate(BigDecimal.ZERO);
} }
List<BaogongRecordTrendDayRespVO> dayTrend = baogongRecordMapper.selectTrendByDay(reqVO); List<BaogongRecordTrendDayRespVO> dayTrend = buildTrend(reqVO);
respVO.setDayTrend(dayTrend); respVO.setDayTrend(dayTrend);
return respVO; return respVO;
} }
private List<BaogongRecordTrendDayRespVO> buildTrend(BaogongRecordTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == BaogongTrendTypeEnum.CUSTOM) {
return Collections.emptyList();
}
if (trendType == BaogongTrendTypeEnum.YEAR) {
return baogongRecordMapper.selectTrendByMonth(reqVO);
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
return baogongRecordMapper.selectTrendByWeekday(reqVO);
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
return baogongRecordMapper.selectTrendByHour(reqVO);
}
return baogongRecordMapper.selectTrendByDay(reqVO);
}
private void fillTrendTimeRange(BaogongRecordTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == null) {
return;
}
LocalDateTime now = LocalDateTime.now();
if (trendType == BaogongTrendTypeEnum.YEAR) {
reqVO.setBeginBaogongTime(now.minusMonths(11).withDayOfMonth(1).toLocalDate().atStartOfDay());
reqVO.setEndBaogongTime(now.withDayOfMonth(now.toLocalDate().lengthOfMonth()).toLocalDate().atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.MONTH) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginBaogongTime(currentDate.withDayOfMonth(1).atStartOfDay());
reqVO.setEndBaogongTime(currentDate.withDayOfMonth(currentDate.lengthOfMonth()).atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
LocalDate currentDate = now.toLocalDate();
LocalDate weekStart = currentDate.with(DayOfWeek.MONDAY);
LocalDate weekEnd = currentDate.with(DayOfWeek.SUNDAY);
reqVO.setBeginBaogongTime(weekStart.atStartOfDay());
reqVO.setEndBaogongTime(weekEnd.atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginBaogongTime(currentDate.atStartOfDay());
reqVO.setEndBaogongTime(now.minusHours(1).withMinute(59).withSecond(59).withNano(999999999));
}
}
} }

@ -96,5 +96,85 @@
ORDER BY day ASC ORDER BY day ASC
</select> </select>
<select id="selectTrendByMonth"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
DATE_FORMAT(r.baogong_time, '%Y-%m') AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM mes_baogong_record r
WHERE r.deleted = b'0'
<if test="reqVO.beginBaogongTime != null">
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
</if>
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DATE_FORMAT(r.baogong_time, '%Y-%m')
ORDER BY day ASC
</select>
<select id="selectTrendByWeekday"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
CASE DAYOFWEEK(r.baogong_time)
WHEN 1 THEN '星期日'
WHEN 2 THEN '星期一'
WHEN 3 THEN '星期二'
WHEN 4 THEN '星期三'
WHEN 5 THEN '星期四'
WHEN 6 THEN '星期五'
WHEN 7 THEN '星期六'
END AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM mes_baogong_record r
WHERE r.deleted = b'0'
<if test="reqVO.beginBaogongTime != null">
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
</if>
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DAYOFWEEK(r.baogong_time)
ORDER BY DAYOFWEEK(r.baogong_time) ASC
</select>
<select id="selectTrendByHour"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
DATE_FORMAT(r.baogong_time, '%H:00') AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM mes_baogong_record r
WHERE r.deleted = b'0'
<if test="reqVO.beginBaogongTime != null">
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
</if>
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DATE_FORMAT(r.baogong_time, '%H')
ORDER BY DATE_FORMAT(r.baogong_time, '%H') ASC
</select>
</mapper> </mapper>
Loading…
Cancel
Save