From 7616b34052f70384092dcff45cecb38c05c8d59e Mon Sep 17 00:00:00 2001 From: HuangHuiKang Date: Thu, 16 Apr 2026 09:46:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0app-=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E6=A6=82=E5=86=B5-=E4=BA=A7=E5=93=81=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/BaogongRecordTrendReqVO.java | 7 +- .../baogongrecord/BaogongRecordMapper.java | 8 +- .../mes/enums/BaogongTrendTypeEnum.java | 34 ++++++++ .../BaogongRecordServiceImpl.java | 59 ++++++++++++- .../baogongrecord/BaogongRecordMapper.xml | 82 ++++++++++++++++++- 5 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/enums/BaogongTrendTypeEnum.java diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/baogongrecord/vo/BaogongRecordTrendReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/baogongrecord/vo/BaogongRecordTrendReqVO.java index 55075dd47..8738fedc5 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/baogongrecord/vo/BaogongRecordTrendReqVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/baogongrecord/vo/BaogongRecordTrendReqVO.java @@ -1,5 +1,7 @@ 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 lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -12,6 +14,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data public class BaogongRecordTrendReqVO { + @Schema(description = "趋势类型:1-近一年,2-本月,3-本周,4-今日,5-自定义", example = "4") + @InEnum(BaogongTrendTypeEnum.class) + private Integer trendType; + @Schema(description = "开始时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime beginBaogongTime; @@ -21,4 +27,3 @@ public class BaogongRecordTrendReqVO { private LocalDateTime endBaogongTime; } - diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/baogongrecord/BaogongRecordMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/baogongrecord/BaogongRecordMapper.java index 39e434982..ce66ce18a 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/baogongrecord/BaogongRecordMapper.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/baogongrecord/BaogongRecordMapper.java @@ -37,4 +37,10 @@ public interface BaogongRecordMapper extends BaseMapperX { List selectTrendByDay(@Param("reqVO") BaogongRecordTrendReqVO reqVO); -} \ No newline at end of file + List selectTrendByMonth(@Param("reqVO") BaogongRecordTrendReqVO reqVO); + + List selectTrendByWeekday(@Param("reqVO") BaogongRecordTrendReqVO reqVO); + + List selectTrendByHour(@Param("reqVO") BaogongRecordTrendReqVO reqVO); + +} diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/enums/BaogongTrendTypeEnum.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/enums/BaogongTrendTypeEnum.java new file mode 100644 index 000000000..a553e4958 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/enums/BaogongTrendTypeEnum.java @@ -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()); + } + +} diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/baogongrecord/BaogongRecordServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/baogongrecord/BaogongRecordServiceImpl.java index a5b37c6f1..e8540c4d4 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/baogongrecord/BaogongRecordServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/baogongrecord/BaogongRecordServiceImpl.java @@ -8,12 +8,17 @@ import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.*; import cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.*; 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.PageParam; 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; @@ -85,6 +90,7 @@ public class BaogongRecordServiceImpl implements BaogongRecordService { @Override public BaogongRecordTrendRespVO getBaogongRecordTrend(BaogongRecordTrendReqVO reqVO) { + fillTrendTimeRange(reqVO); BaogongRecordTrendRespVO respVO = baogongRecordMapper.selectTrendSummary(reqVO); if (respVO == null) { respVO = new BaogongRecordTrendRespVO(); @@ -93,10 +99,59 @@ public class BaogongRecordServiceImpl implements BaogongRecordService { respVO.setNoPassNum(0L); respVO.setPassRate(BigDecimal.ZERO); } - List dayTrend = baogongRecordMapper.selectTrendByDay(reqVO); + List dayTrend = buildTrend(reqVO); respVO.setDayTrend(dayTrend); return respVO; } + private List 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)); + } + } + -} \ No newline at end of file +} diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/baogongrecord/BaogongRecordMapper.xml b/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/baogongrecord/BaogongRecordMapper.xml index 372d39dbc..61c883281 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/baogongrecord/BaogongRecordMapper.xml +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/baogongrecord/BaogongRecordMapper.xml @@ -96,5 +96,85 @@ ORDER BY day ASC + + + + + + - \ No newline at end of file +