From 628e79d294458459648235cd435bbf613b159dac Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 12 八月 2024 11:36:44 +0800 Subject: [PATCH] 2024-08-12 朱宝民 代码优化(yearMonth参数类型) --- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntkeCtrl.java | 31 +++++++++++---- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java | 23 ++++------- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java | 5 +- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/ClientAmountQO.java | 4 - pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/IntakeAmountQO.java | 6 -- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java | 16 ++++++-- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/result/StatisticlResultCode.java | 3 + 7 files changed, 50 insertions(+), 38 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java index 6b3e977..2d43649 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientCtrl.java @@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -141,8 +143,17 @@ @GetMapping(path = "/getDayAmountAndMoney") @SsoAop() public BaseResponse<QueryResultVo<List<VoDayClient>>> getDayAmountAndMoney(ClientAmountQO qo) { - if(qo.getYearMonth() == null) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String yearMonth = qo.getYearMonth(); + if(yearMonth == null) { return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_AND_MONTH_CANNOT_BE_NULL.getMessage()); + }else { + yearMonth = yearMonth + "-01"; + try { + Date date = dateFormat.parse(yearMonth); + } catch (Exception e) { + return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_OR_MONTH_IS_ERROR.getMessage()); + } } try { @@ -172,7 +183,6 @@ } } - /** * 鎸囧畾鏃堕棿娈靛唴寮�鐗╃悊鍗″啘鎴� * @@ -190,8 +200,6 @@ return BaseResponseUtils.buildException(e.getMessage()); } } - - /** * 鎸囧畾鏃堕棿娈靛唴姣忎釜鍐滄埛鍏呭�煎悎璁★紙鐗╃悊鍗★級 diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java index 458abc2..1625593 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java @@ -343,8 +343,9 @@ * @return */ public QueryResultVo<List<VoDayClient>> getDayAmountAndMoney(ClientAmountQO qo) { - Integer year = qo.getYearMonth().getYear(); - Integer month = qo.getYearMonth().getMonthValue(); + String yearMonth = qo.getYearMonth(); + Integer year = Integer.parseInt(yearMonth.substring(0,4)); + Integer month = Integer.parseInt(yearMonth.substring(5,7)); qo.setYear(year); qo.setMonth(month); diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java index f92bb82..5d50de4 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.text.DecimalFormat; +import java.text.ParseException; import java.time.LocalDate; import java.util.Calendar; import java.util.List; @@ -456,7 +457,6 @@ return rsVo ; } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按閲忚秴杩囨寚瀹氬�肩殑鍙栨按鍙� * @param qo @@ -483,7 +483,6 @@ qo.setValue(0.0); } - Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo); Long itemTotal = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakesCount(params); @@ -495,8 +494,6 @@ rsVo.obj = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakes(params); return rsVo ; } - - /** * 鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -535,7 +532,6 @@ rsVo.obj = rmOpenCloseValveHistoryMapper.getExpenseGtValueIntakes(params); return rsVo ; } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -647,9 +643,10 @@ * @param qo * @return */ - public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(IntakeAmountQO qo) { - Integer year = qo.getYearMonth().getYear(); - Integer month = qo.getYearMonth().getMonthValue(); + public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(IntakeAmountQO qo) throws ParseException { + String yearMonth = qo.getYearMonth(); + Integer year = Integer.parseInt(yearMonth.substring(0,4)); + Integer month = Integer.parseInt(yearMonth.substring(5,7)); qo.setYear(year); qo.setMonth(month); @@ -700,12 +697,10 @@ * @param qo * @return */ - public QueryResultVo<List<VoDayLoss>> getDayLossAmount(IntakeAmountQO qo) { - //Calendar calendar = Calendar.getInstance(); - //Integer year = Optional.ofNullable(qo.getYear()).orElse(calendar.get(Calendar.YEAR)); - //Integer month = Optional.ofNullable(qo.getMonth()).orElse(calendar.get(Calendar.MONTH)); - Integer year = qo.getYearMonth().getYear(); - Integer month = qo.getYearMonth().getMonthValue(); + public QueryResultVo<List<VoDayLoss>> getDayLossAmount(IntakeAmountQO qo) throws ParseException { + String yearMonth = qo.getYearMonth(); + Integer year = Integer.parseInt(yearMonth.substring(0,4)); + Integer month = Integer.parseInt(yearMonth.substring(5,7)); qo.setYear(year); qo.setMonth(month); diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntkeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntkeCtrl.java index 0525e6f..ad73d73 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntkeCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntkeCtrl.java @@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -167,7 +169,6 @@ } } - /** * 鑾峰彇浠庢湭寮�杩囬榾鐨勫彇姘村彛 * @param @@ -203,7 +204,6 @@ } } - /** * 鑾峰彇鎸囧畾鏃堕棿娈靛唴寮�闃�娆℃暟浣庝簬鎸囧畾鍊肩殑鍙栨按鍙� * @param @@ -220,7 +220,6 @@ return BaseResponseUtils.buildException(e.getMessage()) ; } } - /** * 鎸囧畾鏃堕棿娈靛唴绱Н娴侀噺(瀹氭椂鎶ラ噷鐨勭疮绉祦閲�)瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -239,7 +238,6 @@ } } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按閲忚秴杩囨寚瀹氬�肩殑鍙栨按鍙� * @param @@ -256,7 +254,6 @@ return BaseResponseUtils.buildException(e.getMessage()) ; } } - /** * 鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -276,7 +273,6 @@ } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� * @param @@ -293,7 +289,6 @@ return BaseResponseUtils.buildException(e.getMessage()) ; } } - /** * 鎸囧畾鏃堕棿娈� 鏈夊紑闃� 鏃犲叧闃�鐨勫彇姘村彛 @@ -337,8 +332,17 @@ @GetMapping(path = "/getDayIntakeAmount") @SsoAop() public BaseResponse<QueryResultVo<List<VoDayIntakeAmount>>> getDayIntakeAmount(@NotNull IntakeAmountQO qo) { - if(qo.getYearMonth() == null) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String yearMonth = qo.getYearMonth(); + if(yearMonth == null) { return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_AND_MONTH_CANNOT_BE_NULL.getMessage()); + }else { + yearMonth = yearMonth + "-01"; + try { + Date date = dateFormat.parse(yearMonth); + } catch (Exception e) { + return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_OR_MONTH_IS_ERROR.getMessage()); + } } try { @@ -376,8 +380,17 @@ @GetMapping(path = "/getDayLossAmount") @SsoAop() public BaseResponse<QueryResultVo<List<VoDayLoss>>> getDayLossAmount(IntakeAmountQO qo) { - if(qo.getYearMonth() == null) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String yearMonth = qo.getYearMonth(); + if(yearMonth == null) { return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_AND_MONTH_CANNOT_BE_NULL.getMessage()); + }else { + yearMonth = yearMonth + "-01"; + try { + Date date = dateFormat.parse(yearMonth); + } catch (Exception e) { + return BaseResponseUtils.buildErrorMsg(StatisticlResultCode.YEAR_OR_MONTH_IS_ERROR.getMessage()); + } } try { diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/ClientAmountQO.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/ClientAmountQO.java index bfe9e00..7ce722c 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/ClientAmountQO.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/ClientAmountQO.java @@ -4,8 +4,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; -import java.time.LocalDate; - /** * @author ZhuBaoMin * @date 2024-08-09 11:18 @@ -19,7 +17,7 @@ /** * 缁熻骞存湀 */ - private LocalDate yearMonth; + private String yearMonth; /** * 骞� diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/IntakeAmountQO.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/IntakeAmountQO.java index c133b24..da40a5a 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/IntakeAmountQO.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/qo/IntakeAmountQO.java @@ -1,11 +1,8 @@ package com.dy.pipIrrStatistics.intake.qo; import com.dy.common.webUtil.QueryConditionVo; -import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; - -import java.time.LocalDate; /** * @author ZhuBaoMin @@ -21,8 +18,7 @@ /** * 缁熻骞存湀 */ - @NotNull(message = "缁熻骞存湀涓嶈兘涓虹┖") - private LocalDate yearMonth; + private String yearMonth; /** * 骞� diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/result/StatisticlResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/result/StatisticlResultCode.java index b5c298e..05dc589 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/result/StatisticlResultCode.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/result/StatisticlResultCode.java @@ -15,7 +15,8 @@ public enum StatisticlResultCode { NO_RECORDS(10001, "娌℃湁绗﹀悎鏉′欢鐨勮褰�"), YEAR_AND_MONTH_CANNOT_BE_NULL(10002, "骞翠唤鍜屾湀浠戒笉鑳戒负绌�"), - YEAR_CANNOT_BE_NULL(10003, "骞翠唤涓嶈兘涓虹┖"); + YEAR_OR_MONTH_IS_ERROR(10003, "骞翠唤鎴栨湀浠介敊璇�"), + YEAR_CANNOT_BE_NULL(10004, "骞翠唤涓嶈兘涓虹┖"); private final Integer code; private final String message; -- Gitblit v1.8.0