From 685f5f2f1855d27bf8ee6304da184ef2e2d2907a Mon Sep 17 00:00:00 2001 From: wuzeyu <1223318623@qq.com> Date: 星期三, 28 八月 2024 17:26:06 +0800 Subject: [PATCH] 优化代码 --- pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java | 95 +++++++++++++++++++++++++++-------------------- 1 files changed, 55 insertions(+), 40 deletions(-) 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 704e2c0..1b116c0 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,8 @@ import org.springframework.stereotype.Service; import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Calendar; import java.util.List; @@ -62,13 +64,16 @@ */ String timeStart = qo.getTimeStart(); String timeStop = qo.getTimeStop(); - if(timeStart != null) { - timeStart = timeStart + " 00:00:00"; - }else { - timeStart = LocalDate.now() + " 00:00:00"; - } + if(timeStop != null) { timeStop = timeStop + " 23:59:59"; + if(timeStart != null) { + timeStart = timeStart + " 00:00:00"; + }else { + timeStart = LocalDate.now() + " 00:00:00"; + } + }else { + timeStart = null; } qo.setTimeStart(timeStart); qo.setTimeStop(timeStop); @@ -304,39 +309,47 @@ */ public VoCountOfOpenType getCountByOpenType(OpenTypeQO qo) { /** - * 琛ラ綈璧锋鏃堕棿锛屽鏋滃紑濮嬫椂闂翠负绌猴紝鍒欓粯璁や负褰撳墠鏃ユ湡 + * 琛ラ綈璧锋鏃堕棿锛屽鏋滃紑濮嬫椂闂翠负绌猴紝鍒欓粯璁や负褰撳墠鏃ユ湡锛屽鏋滅粨鏉熸椂闂翠负绌猴紝鍒欐煡璇㈡椂闂翠负绌� */ String timeStart = qo.getTimeStart(); String timeStop = qo.getTimeStop(); - if(timeStart != null) { - timeStart = timeStart + " 00:00:00"; - }else { - timeStart = LocalDate.now() + " 00:00:00"; - } if(timeStop != null) { timeStop = timeStop + " 23:59:59"; + if(timeStart != null) { + timeStart = timeStart + " 00:00:00"; + }else { + timeStart = LocalDate.now() + " 00:00:00"; + } + }else { + timeStart = null; } qo.setTimeStart(timeStart); qo.setTimeStop(timeStop); Integer openType = qo.getOpenType(); String openTypeName = ""; - switch (openType) { - case 1: - openTypeName = "鍒峰崱寮�闃�"; - break; - case 3: - openTypeName = "涓績绔欏紑闃�"; - break; - case 8: - openTypeName = "鐢ㄦ埛杩滅▼寮�闃�"; - break; - case 11: - openTypeName = "寮�鍏抽榾鍗″紑闃�"; - break; - case 13: - openTypeName = "寮�鍏抽榾鍗″紑闃�"; - break; + if (openType == null){ + openTypeName = "鏈煡"; + }else { + switch (openType) { + case 1: + openTypeName = "鍒峰崱寮�闃�"; + break; + case 3: + openTypeName = "涓績绔欏紑闃�"; + break; + case 8: + openTypeName = "鐢ㄦ埛杩滅▼寮�闃�"; + break; + case 11: + openTypeName = "寮�鍏抽榾鍗″紑闃�"; + break; + case 13: + openTypeName = "寮�鍏抽榾鍗″紑闃�"; + break; + default: + openTypeName = "鏈煡"; + } } // 鐢熸垚鏌ヨ鍙傛暟 @@ -456,7 +469,6 @@ return rsVo ; } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按閲忚秴杩囨寚瀹氬�肩殑鍙栨按鍙� * @param qo @@ -483,7 +495,6 @@ qo.setValue(0.0); } - Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo); Long itemTotal = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakesCount(params); @@ -495,8 +506,6 @@ rsVo.obj = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakes(params); return rsVo ; } - - /** * 鎸囧畾鏃堕棿娈靛唴娑堣垂閲戦瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -535,7 +544,6 @@ rsVo.obj = rmOpenCloseValveHistoryMapper.getExpenseGtValueIntakes(params); return rsVo ; } - /** * 鎸囧畾鏃堕棿娈靛唴鐢ㄦ按鏃堕暱瓒呰繃鎸囧畾鍊肩殑鍙栨按鍙� @@ -647,10 +655,14 @@ * @param qo * @return */ - public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(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)); + public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(IntakeAmountQO qo) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String yearMonth = qo.getYearMonth(); + yearMonth = yearMonth + "-01"; + yearMonth = dateFormat.format(dateFormat.parse(yearMonth)); + + Integer year = Integer.parseInt(yearMonth.substring(0,4)); + Integer month = Integer.parseInt(yearMonth.substring(5,7)); qo.setYear(year); qo.setMonth(month); @@ -701,10 +713,13 @@ * @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)); + public QueryResultVo<List<VoDayLoss>> getDayLossAmount(IntakeAmountQO qo) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String yearMonth = qo.getYearMonth(); + yearMonth = yearMonth + "-01"; + yearMonth = dateFormat.format(dateFormat.parse(yearMonth)); + Integer year = Integer.parseInt(yearMonth.substring(0,4)); + Integer month = Integer.parseInt(yearMonth.substring(5,7)); qo.setYear(year); qo.setMonth(month); -- Gitblit v1.8.0