From 3d6bc69b482d6a82ef5d8da0b4d5c3ada3d70d92 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 22 Nov 2024 17:45:48 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=83=BD=E8=80=97=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=90=8C=E6=AF=94=E7=8E=AF=E6=AF=94=E6=8E=A5=E5=8F=A3=E7=BC=96?= =?UTF-8?q?=E5=86=99=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/EnergyDataController.java | 40 +++ .../com/mh/user/dto/EnergyMomYoyDataDTO.java | 167 ++++++++++++ .../com/mh/user/mapper/EnergyDataMapper.java | 25 ++ .../mapper/provider/EnergyDataProvider.java | 258 ++++++++++++------ .../mh/user/service/EnergyDataService.java | 4 + .../service/impl/EnergyDataServiceImpl.java | 97 +++++++ .../test/java/com/mh/user/DealDataTest.java | 22 ++ .../test/java/com/mh/user/TestJwtUtils.java | 37 ++- 能耗同比.sql | 255 +++++++++++++++++ 能耗环比.sql | 239 ++++++++++++++++ 10 files changed, 1054 insertions(+), 90 deletions(-) create mode 100644 user-service/src/main/java/com/mh/user/dto/EnergyMomYoyDataDTO.java create mode 100644 能耗同比.sql create mode 100644 能耗环比.sql diff --git a/user-service/src/main/java/com/mh/user/controller/EnergyDataController.java b/user-service/src/main/java/com/mh/user/controller/EnergyDataController.java index 83c811e..e042c23 100644 --- a/user-service/src/main/java/com/mh/user/controller/EnergyDataController.java +++ b/user-service/src/main/java/com/mh/user/controller/EnergyDataController.java @@ -1,7 +1,10 @@ package com.mh.user.controller; +import com.github.pagehelper.PageInfo; import com.mh.common.http.HttpResult; +import com.mh.common.page.PageResult; import com.mh.user.annotation.SysLogger; +import com.mh.user.dto.EnergyMomYoyDataDTO; import com.mh.user.entity.DeviceInstallEntity; import com.mh.user.entity.EnergyDataEntity; import com.mh.user.entity.EnergyEntity; @@ -38,4 +41,41 @@ public class EnergyDataController { } + @SysLogger(value="中央空调",optDesc = "按小时、天、月、年查询用水用电eer环比") + @PostMapping("/mom") + public HttpResult queryMomEnergyData(@RequestBody EnergyModel energyModel){ + try{ + String projectId=energyModel.getProjectId(); + if(projectId!=null && projectId.length()>0){ + PageResult result = energyDataService.queryMomEnergyData(energyModel); + return HttpResult.ok(result); + }else{ + return HttpResult.error(); + } + }catch (Exception e){ +// e.printStackTrace(); + return HttpResult.error("查询出错!"); + } + + } + + @SysLogger(value="中央空调",optDesc = "按小时、天、月、年查询用水用电eer同比") + @PostMapping("/yoy") + public HttpResult queryYoyEnergyData(@RequestBody EnergyModel energyModel){ + try{ + String projectId=energyModel.getProjectId(); + if(projectId!=null && projectId.length()>0){ + List list=energyDataService.queryEnergyData(energyModel); + int count=energyDataService.getEnergyDataCount(energyModel); + return HttpResult.ok(count,list); + }else{ + return HttpResult.error(); + } + }catch (Exception e){ +// e.printStackTrace(); + return HttpResult.error("查询出错!"); + } + + } + } diff --git a/user-service/src/main/java/com/mh/user/dto/EnergyMomYoyDataDTO.java b/user-service/src/main/java/com/mh/user/dto/EnergyMomYoyDataDTO.java new file mode 100644 index 0000000..9bb0437 --- /dev/null +++ b/user-service/src/main/java/com/mh/user/dto/EnergyMomYoyDataDTO.java @@ -0,0 +1,167 @@ +package com.mh.user.dto; + +import java.math.BigDecimal; + +public class EnergyMomYoyDataDTO { + + private String curDate; + + private BigDecimal elect; + + private BigDecimal cl; + + private BigDecimal cop; + + private BigDecimal lastElect; + + private BigDecimal lastCl; + + private BigDecimal lastCop; + + private String electRatio; + + private String clRatio; + + private String copRatio; + + private String projectId; + + private String projectName; + + private String ambTemp; + + private String humidity; + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getAmbTemp() { + return ambTemp; + } + + public void setAmbTemp(String ambTemp) { + this.ambTemp = ambTemp; + } + + public String getHumidity() { + return humidity; + } + + public void setHumidity(String humidity) { + this.humidity = humidity; + } + + public String getCurDate() { + return curDate; + } + + public void setCurDate(String curDate) { + this.curDate = curDate; + } + + public BigDecimal getElect() { + return elect; + } + + public void setElect(BigDecimal elect) { + this.elect = elect; + } + + public BigDecimal getCl() { + return cl; + } + + public void setCl(BigDecimal cl) { + this.cl = cl; + } + + public BigDecimal getCop() { + return cop; + } + + public void setCop(BigDecimal cop) { + this.cop = cop; + } + + public BigDecimal getLastElect() { + return lastElect; + } + + public void setLastElect(BigDecimal lastElect) { + this.lastElect = lastElect; + } + + public BigDecimal getLastCl() { + return lastCl; + } + + public void setLastCl(BigDecimal lastCl) { + this.lastCl = lastCl; + } + + public BigDecimal getLastCop() { + return lastCop; + } + + public void setLastCop(BigDecimal lastCop) { + this.lastCop = lastCop; + } + + public String getElectRatio() { + return electRatio; + } + + public void setElectRatio(String electRatio) { + this.electRatio = electRatio; + } + + public String getClRatio() { + return clRatio; + } + + public void setClRatio(String clRatio) { + this.clRatio = clRatio; + } + + public String getCopRatio() { + return copRatio; + } + + public void setCopRatio(String copRatio) { + this.copRatio = copRatio; + } + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + @Override + public String toString() { + return "EnergyMomYoyDataDTO{" + + "curDate='" + curDate + '\'' + + ", elect=" + elect + + ", cl=" + cl + + ", cop=" + cop + + ", lastElect=" + lastElect + + ", lastCl=" + lastCl + + ", lastCop=" + lastCop + + ", electRatio='" + electRatio + '\'' + + ", clRatio='" + clRatio + '\'' + + ", copRatio='" + copRatio + '\'' + + ", projectId='" + projectId + '\'' + + ", projectName='" + projectName + '\'' + + ", ambTemp='" + ambTemp + '\'' + + ", humidity='" + humidity + '\'' + + '}'; + } + +} diff --git a/user-service/src/main/java/com/mh/user/mapper/EnergyDataMapper.java b/user-service/src/main/java/com/mh/user/mapper/EnergyDataMapper.java index a1dd4d1..a785f19 100644 --- a/user-service/src/main/java/com/mh/user/mapper/EnergyDataMapper.java +++ b/user-service/src/main/java/com/mh/user/mapper/EnergyDataMapper.java @@ -1,6 +1,7 @@ package com.mh.user.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.user.dto.EnergyMomYoyDataDTO; import com.mh.user.entity.EnergyDataEntity; import com.mh.user.mapper.provider.EnergyDataProvider; import org.apache.ibatis.annotations.*; @@ -91,4 +92,28 @@ public interface EnergyDataMapper extends BaseMapper { @Param("endDate") String endDate, @Param("queryType") int queryType); + @SelectProvider(type = EnergyDataProvider.class, method = "queryMomEnergyHourAndDayData") + @Results(id = "mom_yoy", value = { + @Result(property = "curDate", column = "cur_date"), + @Result(property = "projectId", column = "project_id"), + @Result(property = "projectName", column = "project_name"), + @Result(property = "ambTemp", column = "amb_Temp"), + @Result(property = "humidity", column = "humidity"), + @Result(property = "elect", column = "elect"), + @Result(property = "cl", column = "cl"), + @Result(property = "cop", column = "cop"), + @Result(property = "last_elect", column = "lastElect"), + @Result(property = "last_cl", column = "lastCl"), + @Result(property = "last_cop", column = "lastCop"), + @Result(property = "elect_ratio", column = "electRatio"), + @Result(property = "cl_ratio", column = "clRatio"), + @Result(property = "cop_ratio", column = "copRatio") + }) + List queryMomEnergyHourAndDayData(@Param("tableName") String tableName, + @Param("projectId") String projectId, + @Param("startDate") String startDate, + @Param("endDate") String endDate, + @Param("lastStartDate") String lastStartDate, + @Param("lastEndDate") String lastEndDate, + @Param("dateType") String dateType); } diff --git a/user-service/src/main/java/com/mh/user/mapper/provider/EnergyDataProvider.java b/user-service/src/main/java/com/mh/user/mapper/provider/EnergyDataProvider.java index 01748ae..80ef5c6 100644 --- a/user-service/src/main/java/com/mh/user/mapper/provider/EnergyDataProvider.java +++ b/user-service/src/main/java/com/mh/user/mapper/provider/EnergyDataProvider.java @@ -1,31 +1,35 @@ package com.mh.user.mapper.provider; +import org.apache.ibatis.annotations.Param; + +import java.util.Map; + public class EnergyDataProvider { //按十分钟 - public String queryEnergyDataMi(String projectId,String curDate,int page, int limit){ + public String queryEnergyDataMi(String projectId, String curDate, int page, int limit) { StringBuffer sql = new StringBuffer(""); sql.append("select T.*,t2.*,T1.project_name from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_mi " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } - if(projectId.equals("所有")){ - if ((page != 0) && (limit != 0)){ + if (projectId.equals("所有")) { + if ((page != 0) && (limit != 0)) { sql.append(" )T where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T order by T.cur_date "); } - }else{ - if ((page != 0) && (limit != 0)){ + } else { + if ((page != 0) && (limit != 0)) { sql.append(" )T join project_info T1 ON T.project_id=T1.id where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T join project_info T1 ON T.project_id=T1.id order by T.cur_date "); } } @@ -34,22 +38,22 @@ public class EnergyDataProvider { } //记录数 - public String getEnergyDataMiCount(String projectId,String curDate){ + public String getEnergyDataMiCount(String projectId, String curDate) { StringBuffer sql = new StringBuffer(""); sql.append("select count(*) from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_mi " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } - if(projectId.equals("所有")){ + if (projectId.equals("所有")) { sql.append(" )T "); - }else{ + } else { sql.append(" )T join project_info T1 ON T.project_id=T1.id "); } // System.out.println(sql.toString()); @@ -57,30 +61,30 @@ public class EnergyDataProvider { } //按小时 - public String queryEnergyDataHour(String projectId,String curDate,int page, int limit){ + public String queryEnergyDataHour(String projectId, String curDate, int page, int limit) { StringBuffer sql = new StringBuffer(""); sql.append("select T.*,t2.*,T1.project_name from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_hour " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } assert projectId != null; - if(projectId.equals("所有")){ - if ((page != 0) && (limit != 0)){ + if (projectId.equals("所有")) { + if ((page != 0) && (limit != 0)) { sql.append(" )T where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T order by T.cur_date "); } - }else{ - if ((page != 0) && (limit != 0)){ + } else { + if ((page != 0) && (limit != 0)) { sql.append(" )T join project_info T1 ON T.project_id=T1.id join hour_temperature t2 on LEFT(T.cur_date,13)=CONVERT(VARCHAR(13),t2.cur_date,121) where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T join project_info T1 ON T.project_id=T1.id join hour_temperature t2 on LEFT(T.cur_date,13)=CONVERT(VARCHAR(13),t2.cur_date,121) order by T.cur_date "); } } @@ -89,23 +93,23 @@ public class EnergyDataProvider { } //按小时记录数 - public String getEnergyDataHourCount(String projectId,String curDate){ + public String getEnergyDataHourCount(String projectId, String curDate) { StringBuffer sql = new StringBuffer(""); sql.append("select count(*) from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_hour " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } - if(projectId.equals("所有")){ + if (projectId.equals("所有")) { sql.append(" )T "); - }else{ + } else { sql.append(" )T join project_info T1 ON T.project_id=T1.id join hour_temperature t2 on LEFT(T.cur_date,13)=CONVERT(VARCHAR(13),t2.cur_date,121)"); } @@ -114,33 +118,33 @@ public class EnergyDataProvider { } //按天 - public String queryEnergyDataDay(String projectId,String curDate,int queryType,int page, int limit){ + public String queryEnergyDataDay(String projectId, String curDate, int queryType, int page, int limit) { StringBuffer sql = new StringBuffer(""); sql.append("select T.*,t2.*,T1.project_name from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_day " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { - if (queryType==0){ + if (queryType == 0) { sql.append(" AND LEFT(cur_date,7)=#{curDate} "); - }else{ + } else { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } } - if(projectId.equals("所有")){ - if ((page != 0) && (limit != 0)){ + if (projectId.equals("所有")) { + if ((page != 0) && (limit != 0)) { sql.append(" )T where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T order by T.cur_date "); } - }else{ - if ((page != 0) && (limit != 0)){ + } else { + if ((page != 0) && (limit != 0)) { sql.append(" )T join project_info T1 ON T.project_id=T1.id join date_temperature t2 on LEFT(T.cur_date,10)=CONVERT(VARCHAR(10),t2.cur_date,121) where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T join project_info T1 ON T.project_id=T1.id join date_temperature t2 on LEFT(T.cur_date,10)=CONVERT(VARCHAR(10),t2.cur_date,121) order by T.cur_date "); } } @@ -149,26 +153,26 @@ public class EnergyDataProvider { } //记录数 - public String getEnergyDataDayCount(String projectId,String curDate,int queryType){ + public String getEnergyDataDayCount(String projectId, String curDate, int queryType) { StringBuffer sql = new StringBuffer(""); sql.append("select count(*) from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_day " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { - if (queryType==0){ + if (queryType == 0) { sql.append(" AND LEFT(cur_date,7)=#{curDate} "); - }else{ + } else { sql.append(" AND LEFT(cur_date,10)=#{curDate} "); } } - if(projectId.equals("所有")){ + if (projectId.equals("所有")) { sql.append(" )T "); - }else{ + } else { sql.append(" )T join project_info T1 ON T.project_id=T1.id join date_temperature t2 on LEFT(T.cur_date,10)=CONVERT(VARCHAR(10),t2.cur_date,121) "); } // System.out.println(sql.toString()); @@ -176,33 +180,33 @@ public class EnergyDataProvider { } //按月 - public String queryEnergyDataMonth(String projectId,String curDate,int queryType,int page, int limit){ + public String queryEnergyDataMonth(String projectId, String curDate, int queryType, int page, int limit) { StringBuffer sql = new StringBuffer(""); sql.append("select T.*,T1.project_name from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_month " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { - if(queryType==0){ + if (queryType == 0) { sql.append(" AND LEFT(cur_date,4)=#{curDate} "); - }else { + } else { sql.append(" AND LEFT(cur_date,7)=#{curDate} "); } } - if(projectId.equals("所有")){ - if ((page != 0) && (limit != 0)){ + if (projectId.equals("所有")) { + if ((page != 0) && (limit != 0)) { sql.append(" )T where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T order by T.cur_date "); } - }else{ - if ((page != 0) && (limit != 0)){ + } else { + if ((page != 0) && (limit != 0)) { sql.append(" )T join project_info T1 ON T.project_id=T1.id where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T join project_info T1 ON T.project_id=T1.id order by T.cur_date "); } } @@ -211,64 +215,64 @@ public class EnergyDataProvider { } //记录数 - public String getEnergyDataMonthCount(String projectId,String curDate,int queryType){ + public String getEnergyDataMonthCount(String projectId, String curDate, int queryType) { StringBuffer sql = new StringBuffer(""); sql.append("select count(*) from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_month " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } if (curDate != null && !curDate.equals("")) { - if(queryType==0){ + if (queryType == 0) { sql.append(" AND LEFT(cur_date,4)=#{curDate} "); - }else { + } else { sql.append(" AND LEFT(cur_date,7)=#{curDate} "); } } - if(projectId.equals("所有")){ + if (projectId.equals("所有")) { sql.append(" )T "); - }else{ + } else { sql.append(" )T join project_info T1 ON T.project_id=T1.id "); } // System.out.println(sql.toString()); return sql.toString(); } - public String queryEnergyDataYear(String projectId,String startDate,String endDate,int queryType,int page, int limit){ + public String queryEnergyDataYear(String projectId, String startDate, String endDate, int queryType, int page, int limit) { StringBuffer sql = new StringBuffer(""); sql.append("select T.*,T1.project_name from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_year " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } - if(queryType==0){ + if (queryType == 0) { if (startDate != null && !startDate.equals("")) { sql.append(" AND LEFT(cur_date,4)>=#{startDate} "); } if (endDate != null && !endDate.equals("")) { sql.append(" AND LEFT(cur_date,4)<=#{endDate} "); } - }else{ + } else { if (startDate != null && !startDate.equals("")) { sql.append(" AND LEFT(cur_date,4)=#{startDate} "); } } - if(projectId.equals("所有")){ - if ((page != 0) && (limit != 0)){ + if (projectId.equals("所有")) { + if ((page != 0) && (limit != 0)) { sql.append(" )T where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T order by T.cur_date "); } - }else{ - if ((page != 0) && (limit != 0)){ + } else { + if ((page != 0) && (limit != 0)) { sql.append(" )T join project_info T1 ON T.project_id=T1.id where T.rn>(#{page}-1)*#{limit} and T.rn<=#{page}*#{limit} order by T.cur_date "); - } else if (page == 0){ + } else if (page == 0) { sql.append(" )T join project_info T1 ON T.project_id=T1.id order by T.cur_date "); } } @@ -277,34 +281,124 @@ public class EnergyDataProvider { } //记录数 - public String getEnergyDataYearCount(String projectId,String startDate,String endDate,int queryType){ + public String getEnergyDataYearCount(String projectId, String startDate, String endDate, int queryType) { StringBuffer sql = new StringBuffer(""); sql.append("select count(*) from (" + " select *,ROW_NUMBER() over(order by id) as rn from energy_data_year " + " where 1=1 "); - if (projectId != null && !projectId.equals("")){ + if (projectId != null && !projectId.equals("")) { sql.append(" AND project_id = #{projectId} "); - }else{ + } else { sql.append(" AND project_id <>'所有' "); } - if(queryType==0){ + if (queryType == 0) { if (startDate != null && !startDate.equals("")) { sql.append(" AND LEFT(cur_date,4)>=#{startDate} "); } if (endDate != null && !endDate.equals("")) { sql.append(" AND LEFT(cur_date,4)<=#{endDate} "); } - }else{ + } else { if (startDate != null && !startDate.equals("")) { sql.append(" AND LEFT(cur_date,4)=#{startDate} "); } } - if(projectId.equals("所有")){ + if (projectId.equals("所有")) { sql.append(" )T "); - }else{ + } else { sql.append(" )T join project_info T1 ON T.project_id=T1.id "); } // System.out.println(sql.toString()); return sql.toString(); } + + public String queryMomEnergyHourAndDayData(Map params) { + StringBuilder sql = new StringBuilder(); + sql.append("select " + + " t1.cur_date, " + + " t1.elect, " + + " t1.cl, " + + " t1.cop, " + + " t1.project_id, " + + " pi2.project_name, " + + " t2.elect as last_elect, " + + " t2.cl as last_cl, " + + " t2.cop as last_cop, " + + " case " + + " when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') " + + " else '上期无数据' " + + " end elect_ratio, " + + " case " + + " when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') " + + " else '上期无数据' " + + " end cl_ratio, " + + " case " + + " when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') " + + " else '上期无数据' " + + " end cop_ratio, " + + " ht.amb_temp, " + + " ht.humidity " + + "from " + + " ( " + + " select " + + " cur_date, " + + " elect, " + + " cl, " + + " cop, " + + " project_id, " + + " convert(datetime, "); + if ("day".equals(params.get("dateType"))) { + sql.append(" concat(cur_date, ' 00:00:00')) as change_cur_date "); + } else if ("hour".equals(params.get("dateType"))) { + sql.append(" concat(cur_date, ':00:00')) as change_cur_date "); + } + sql.append( + " from " + + " ${tableName} " + + " where " + + " cur_date >= #{startDate} " + + " and cur_date <= #{endDate} " + + " and project_id = #{projectId} " + + " ) t1 " + + "left join " + + " ( " + + " select " + + " cur_date, " + + " elect, " + + " cl, " + + " cop, " + + " project_id, " + + " convert(datetime, "); + if ("day".equals(params.get("dateType"))) { + sql.append(" concat(cur_date, ' 00:00:00')) as change_cur_date "); + } else if ("hour".equals(params.get("dateType"))) { + sql.append(" concat(cur_date, ':00:00')) as change_cur_date "); + } + sql.append( + " from " + + " ${tableName} " + + " where " + + " cur_date >= #{lastStartDate} " + + " and cur_date <= #{lastEndDate} " + + " and project_id = 3 " + + " ) t2 " + + " on " + + " t1.change_cur_date = dateadd(${dateType}, 1, t2.change_cur_date) " + + "left join hour_temperature ht " + + "on " + + " ht.cur_date = t1.change_cur_date " + + "left join ( " + + " select " + + " id, " + + " project_name " + + " from " + + " project_info " + + " where " + + " id = #{projectId}) pi2 " + + "on " + + " pi2.id = t1.project_id " + + "order by " + + " t1.cur_date "); + return sql.toString(); + } } diff --git a/user-service/src/main/java/com/mh/user/service/EnergyDataService.java b/user-service/src/main/java/com/mh/user/service/EnergyDataService.java index 3b1ddf3..1d937c8 100644 --- a/user-service/src/main/java/com/mh/user/service/EnergyDataService.java +++ b/user-service/src/main/java/com/mh/user/service/EnergyDataService.java @@ -1,5 +1,8 @@ package com.mh.user.service; +import com.github.pagehelper.PageInfo; +import com.mh.common.page.PageResult; +import com.mh.user.dto.EnergyMomYoyDataDTO; import com.mh.user.entity.EnergyDataEntity; import com.mh.user.model.EnergyModel; import java.util.List; @@ -10,4 +13,5 @@ public interface EnergyDataService { int getEnergyDataCount(EnergyModel energyModel); + PageResult queryMomEnergyData(EnergyModel energyModel); } diff --git a/user-service/src/main/java/com/mh/user/service/impl/EnergyDataServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/EnergyDataServiceImpl.java index 174a567..85b3539 100644 --- a/user-service/src/main/java/com/mh/user/service/impl/EnergyDataServiceImpl.java +++ b/user-service/src/main/java/com/mh/user/service/impl/EnergyDataServiceImpl.java @@ -1,5 +1,12 @@ package com.mh.user.service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.mh.common.page.MybatisPageHelper; +import com.mh.common.page.PageRequest; +import com.mh.common.page.PageResult; +import com.mh.common.utils.StringUtils; +import com.mh.user.dto.EnergyMomYoyDataDTO; import com.mh.user.entity.EnergyDataEntity; import com.mh.user.mapper.EnergyDataMapper; import com.mh.user.model.EnergyModel; @@ -7,6 +14,10 @@ import com.mh.user.service.EnergyDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; import java.util.List; @Service @@ -63,4 +74,90 @@ public class EnergyDataServiceImpl implements EnergyDataService { } } + @Override + public PageResult queryMomEnergyData(EnergyModel energyModel) { + String projectId=energyModel.getProjectId(); + String startDate=energyModel.getStartDate(); + String endDate=energyModel.getEndDate(); + int page=energyModel.getPage(); + int limit=energyModel.getLimit(); + int type=energyModel.getType(); + int queryType=energyModel.getQueryType(); + + String lastStartDate = ""; + String lastEndDate = ""; + String tableName = "energy_data_hour"; + String dateType = "hour"; + + if (StringUtils.isBlank(endDate)) { + endDate = startDate; + } + + switch (type) { + case 1: + // 按十分钟查询 + break; + case 2: + // 按小时查询 + startDate = startDate + " 00"; + endDate = endDate + " 23"; + + // 定义日期时间格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); + + // startDate 减一个小时 + LocalDateTime startDateTime = LocalDateTime.parse(startDate, formatter); + LocalDateTime newStartDateTime = startDateTime.minusHours(1); + lastStartDate = newStartDateTime.format(formatter); + + + // endDate 减一个小时 + LocalDateTime endDateTime = LocalDateTime.parse(endDate, formatter); + LocalDateTime newEndDateTime = endDateTime.minusHours(1); + lastEndDate = newEndDateTime.format(formatter); + break; + case 3: + tableName = "energy_data_day"; + dateType = "day"; + // 按天查询 + YearMonth yearMonthStart = YearMonth.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM")); + LocalDate firstDayOfMonth = yearMonthStart.atDay(1); + LocalDate lastDayOfMonth = yearMonthStart.atEndOfMonth(); + + startDate = firstDayOfMonth.toString(); + endDate = lastDayOfMonth.toString(); + + // 定义日期时间格式 + DateTimeFormatter dayMatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // startDate 减一天 + LocalDateTime startDayDate = LocalDateTime.parse(startDate + "T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME); + LocalDateTime newStartDayDate = startDayDate.minusDays(1); + lastStartDate = newStartDayDate.format(dayMatter); + + // endDate 减一天 + LocalDateTime endDayDate = LocalDateTime.parse(endDate + "T23:59:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME); + LocalDateTime newEndDayDate = endDayDate.minusDays(1); + if (newEndDayDate.getDayOfMonth() == 1) { + newEndDayDate = newEndDayDate.minusDays(1).withHour(23).withMinute(59).withSecond(59); + } + lastEndDate = newEndDayDate.format(dayMatter); + default: + break; + } + PageRequest pageRequest = new PageRequest(); + if (page != 0) { + PageHelper.startPage(page, limit); + pageRequest.setPageNum(page); + pageRequest.setPageSize(limit); + } + List resultList = energyDataMapper.queryMomEnergyHourAndDayData(tableName, + projectId, + startDate, + endDate, + lastStartDate, + lastEndDate, + dateType); + return MybatisPageHelper.getPageResult(pageRequest, new PageInfo<>(resultList)); + } } diff --git a/user-service/src/test/java/com/mh/user/DealDataTest.java b/user-service/src/test/java/com/mh/user/DealDataTest.java index b2dfd97..aca9ed3 100644 --- a/user-service/src/test/java/com/mh/user/DealDataTest.java +++ b/user-service/src/test/java/com/mh/user/DealDataTest.java @@ -1,6 +1,11 @@ package com.mh.user; +import com.github.pagehelper.PageInfo; +import com.mh.common.page.PageResult; +import com.mh.user.dto.EnergyMomYoyDataDTO; import com.mh.user.mapper.chillers.DealDataMapper; +import com.mh.user.model.EnergyModel; +import com.mh.user.service.EnergyDataService; import com.mh.user.service.chillers.DealDataService; import com.mh.user.utils.ExchangeStringUtil; import lombok.extern.slf4j.Slf4j; @@ -42,4 +47,21 @@ public class DealDataTest extends UserServiceApplicationTests { log.error("能效监测定时汇总异常", e); } } + + @Autowired + private EnergyDataService energyDataService; + + @Test + public void queryEnergyData(){ + EnergyModel energyModel = new EnergyModel(); + energyModel.setPage(1); + energyModel.setLimit(10); + energyModel.setStartDate("2024-07"); + energyModel.setProjectId("3"); + energyModel.setQueryType(0); + energyModel.setType(3); + PageResult pageResult = energyDataService.queryMomEnergyData(energyModel); + System.out.println(pageResult); + + } } diff --git a/user-service/src/test/java/com/mh/user/TestJwtUtils.java b/user-service/src/test/java/com/mh/user/TestJwtUtils.java index cb68186..6ea21e9 100644 --- a/user-service/src/test/java/com/mh/user/TestJwtUtils.java +++ b/user-service/src/test/java/com/mh/user/TestJwtUtils.java @@ -6,6 +6,8 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -154,14 +156,33 @@ public class TestJwtUtils { // System.out.println("name:" + name); // // } - String receiveData = "58 03 04 E8 FF 00 10 37 6A".replaceAll(" ", ""); - String data = receiveData.substring(receiveData.length() - 8, receiveData.length() - 6) - + receiveData.substring(receiveData.length() - 6, receiveData.length() - 4) - + receiveData.substring(receiveData.length() - 12, receiveData.length() - 10) - + receiveData.substring(receiveData.length() - 10, receiveData.length() - 8); - System.out.println(data); - float c4FBC834 = ExchangeStringUtil.hexToSingle("C4FBC834"); - System.out.println(c4FBC834); +// String receiveData = "58 03 04 E8 FF 00 10 37 6A".replaceAll(" ", ""); +// String data = receiveData.substring(receiveData.length() - 8, receiveData.length() - 6) +// + receiveData.substring(receiveData.length() - 6, receiveData.length() - 4) +// + receiveData.substring(receiveData.length() - 12, receiveData.length() - 10) +// + receiveData.substring(receiveData.length() - 10, receiveData.length() - 8); +// System.out.println(data); +// float c4FBC834 = ExchangeStringUtil.hexToSingle("C4FBC834"); +// System.out.println(c4FBC834); + // 原始字符串 + String dateString = "2024-11-22 00"; + + // 定义日期时间格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); + + // 将字符串转换为 LocalDateTime + LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter); + + // 减去一个小时 + LocalDateTime newDateTime = dateTime.minusHours(1); + + // 将新的 LocalDateTime 转换为字符串 + String newDateTimeString = newDateTime.format(formatter); + + // 输出结果 + System.out.println("Original Date and Time: " + dateString); + System.out.println("New Date and Time: " + newDateTimeString); + } } diff --git a/能耗同比.sql b/能耗同比.sql new file mode 100644 index 0000000..e9ef6a2 --- /dev/null +++ b/能耗同比.sql @@ -0,0 +1,255 @@ +-- 小时同比 +select + t1.cur_date, + t2.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + when t2.elect = 0 then '0' + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + when t2.cl = 0 then '0' + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + when t2.cop = 0 then '0' + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ':00:00')) as change_cur_date + from + energy_data_hour edh1 + where + cur_date >= '2024-11-22 00' + and cur_date <= '2024-11-22 23' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ':00:00')) as change_cur_date + from + energy_data_hour + where + cur_date >= '2023-11-22 00' + and cur_date <= '2023-11-22 23' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) +order by t1.cur_date + +-- 日同比 +select + t1.cur_date, + t2.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + when t2.elect = 0 then '0' + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + when t2.cl = 0 then '0' + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + when t2.cop = 0 then '0' + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ' 00:00:00')) as change_cur_date + from + energy_data_day + where + cur_date >= '2024-07-01' + and cur_date <= '2024-07-22' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ' 00:00:00')) as change_cur_date + from + energy_data_day + where + cur_date >= '2023-07-01' + and cur_date <= '2023-07-22' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) +order by t1.cur_date + +-- 月同比 +select + t1.cur_date, + t2.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + when t2.elect = 0 then '0' + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + when t2.cl = 0 then '0' + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + when t2.cop = 0 then '0' + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01 00:00:00')) as change_cur_date + from + energy_data_month + where + cur_date >= '2024-01' + and cur_date <= '2024-11' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01 00:00:00')) as change_cur_date + from + energy_data_month + where + cur_date >= '2023-01' + and cur_date <= '2023-07' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) +order by t1.cur_date + +-- 年同比 +select + t1.cur_date, + t2.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + when t2.elect = 0 then '0' + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + when t2.cl = 0 then '0' + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + when t2.cop = 0 then '0' + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01-01 00:00:00')) as change_cur_date + from + energy_data_year + where + cur_date >= '2023' + and cur_date <= '2024' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01-01 00:00:00')) as change_cur_date + from + energy_data_year + where + cur_date >= '2022' + and cur_date <= '2023' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) +order by t1.cur_date \ No newline at end of file diff --git a/能耗环比.sql b/能耗环比.sql new file mode 100644 index 0000000..07864ed --- /dev/null +++ b/能耗环比.sql @@ -0,0 +1,239 @@ +-- 小时环比 +select + t1.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ':00:00')) as change_cur_date + from + energy_data_hour edh1 + where + cur_date >= '2024-11-22 00' + and cur_date <= '2024-11-22 23' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ':00:00')) as change_cur_date + from + energy_data_hour + where + cur_date >= '2024-11-21 23' + and cur_date <= '2024-11-22 22' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(hour, 1, t2.change_cur_date) +order by t1.cur_date + +-- 日环比 +select + t1.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ' 00:00:00')) as change_cur_date + from + energy_data_day + where + cur_date >= '2024-11-01' + and cur_date <= '2024-11-22' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, ' 00:00:00')) as change_cur_date + from + energy_data_day + where + cur_date >= '2024-10-31' + and cur_date <= '2024-11-21' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(day, 1, t2.change_cur_date) +order by t1.cur_date + +-- 月环比 +select + t1.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01 00:00:00')) as change_cur_date + from + energy_data_month + where + cur_date >= '2024-01' + and cur_date <= '2024-12' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01 00:00:00')) as change_cur_date + from + energy_data_month + where + cur_date >= '2023-12' + and cur_date <= '2024-11' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(month, 1, t2.change_cur_date) +order by t1.cur_date + +-- 年环比 +select + t1.cur_date, + t1.elect, + t1.cl, + t1.cop, + t1.project_id, + t2.elect as last_elect, + t2.cl as last_cl, + t2.cop as last_cop, + case + when t2.elect > 0 then concat(convert(decimal(18, 2),(t1.elect - t2.elect)/ t2.elect * 100), '%') + else '上期无数据' + end mom_elect, + case + when t2.cl > 0 then concat(convert(decimal(18, 2),(t1.cl - t2.cl)/ t2.cl * 100), '%') + else '上期无数据' + end mom_cl, + case + when t2.cop > 0 then concat(convert(decimal(18, 2),(t1.cop - t2.cop)/ t2.cop * 100), '%') + else '上期无数据' + end mom_cop +from + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01-01 00:00:00')) as change_cur_date + from + energy_data_year + where + cur_date >= '2023' + and cur_date <= '2024' + and project_id = 3 + ) t1 + left join + ( + select + cur_date, + elect, + cl, + cop, + project_id, + convert(datetime, + concat(cur_date, '-01-01 00:00:00')) as change_cur_date + from + energy_data_year + where + cur_date >= '2022' + and cur_date <= '2023' + and project_id = 3 + ) t2 + on + t1.change_cur_date = dateadd(year, 1, t2.change_cur_date) +order by t1.cur_date \ No newline at end of file