Browse Source

1、中央空调能耗管理:能源分析,能耗总览查询接口测试;

dev
mh 2 months ago
parent
commit
fecfb41985
  1. 6
      mh-admin/src/main/java/com/mh/web/controller/device/DeviceInOutManageController.java
  2. 35
      mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyQueryVO.java
  3. 12
      mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
  4. 188
      mh-system/src/main/java/com/mh/system/mapper/energy/EnergyAnalyzeMapper.java
  5. 82
      mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java
  6. 2
      mh-system/src/main/java/com/mh/system/service/device/IDeviceInOutManageService.java
  7. 41
      mh-system/src/main/java/com/mh/system/service/device/impl/DeviceInOutManageServiceImpl.java
  8. 14
      mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java
  9. 8
      mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java
  10. 293
      mh-system/src/main/resources/mapper/system/EnergyMapper.xml

6
mh-admin/src/main/java/com/mh/web/controller/device/DeviceInOutManageController.java

@ -56,11 +56,9 @@ public class DeviceInOutManageController extends BaseController {
@PreAuthorize("@ss.hasPermi('device:spareInOut:add')")
@Log(title = "备品/备件出入库管理流水记录管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody DeviceInOutManage deviceInOutManage)
public AjaxResult add(@Validated @RequestBody List<DeviceInOutManage> deviceInOutManage)
{
deviceInOutManage.setCreateBy(getUsername());
deviceInOutManage.setCreateTime(new Date());
return toAjax(deviceInOutManageService.insertDeviceInOutManage(deviceInOutManage));
return toAjax(deviceInOutManageService.insertDeviceInOutManage(deviceInOutManage, getUsername()));
}
// /**

35
mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyQueryVO.java

@ -1,9 +1,11 @@
package com.mh.common.core.domain.vo;
import com.mh.common.core.domain.BaseEntity;
import com.mh.common.core.domain.ColumnFilter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.Serializable;
import java.util.List;
/**
* @author LJF
@ -41,6 +43,36 @@ public class EnergyQueryVO extends BaseEntity implements Serializable {
*/
private String paramType;
private List<ColumnFilter> searchParams;
private int pageNum;
private int pageSize;
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List<ColumnFilter> getSearchParams() {
return searchParams;
}
public void setSearchParams(List<ColumnFilter> searchParams) {
this.searchParams = searchParams;
}
public String getTimeType() {
return timeType;
}
@ -89,6 +121,9 @@ public class EnergyQueryVO extends BaseEntity implements Serializable {
.append("endTime", endTime)
.append("deviceType", deviceType)
.append("paramType", paramType)
.append("searchParams", searchParams)
.append("pageNum", pageNum)
.append("pageSize", pageSize)
.toString();
}
}

12
mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java

@ -50,9 +50,17 @@ public interface CollectionParamsManageMapper extends BaseMapper<CollectionParam
"</script>")
List<CollectionParamsManage> getDeviceByOther(@Param("deviceNum") String deviceNum);
@Select("select count(1) from collection_params_manage where grade >= #{grade} and grade < #{grade}+20 and mt_type like concat('%',#{mtType},'%') ")
@Select("select " +
" count(1) " +
"from " +
" collection_params_manage cpm " +
" join device_ledger dl " +
" on cpm.device_ledger_id = dl.id " +
" and dl.device_type = #{deviceType} " +
" and cpm.grade = #{grade} " +
" and cpm.mt_is_sum = 0")
int selectSummary(@Param("grade") int grade,
@Param("mtType") String deviceType);
@Param("deviceType") String deviceType);
@Select("select id from collection_params_manage where mt_code = #{registerAddr} and mt_type = #{mtType} limit 1 ")
String selectIdByMtCodeAndType(@Param("registerAddr") String registerAddr,

188
mh-system/src/main/java/com/mh/system/mapper/energy/EnergyAnalyzeMapper.java

@ -122,32 +122,44 @@ public interface EnergyAnalyzeMapper {
@Param("paramType") String paramType);
@Select("<script>" +
"select " +
" sum(isnull(dh.calc_value, 0)) as calcValue, " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120) as timeStr, " +
" dh.device_num as deviceNum, " +
" dm.remark " +
"from " +
" ${lastTableName} dh " +
"join device_manage dm " +
"on " +
" dh.device_num = dm.device_num " +
"where " +
" dh.cur_time >= #{startTime} " +
" and dh.cur_time &lt;= #{endTime} " +
" and dh.device_num in " +
"<foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item} " +
"</foreach>" +
"group by " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120), " +
" dh.device_num, " +
" dm.remark " +
"</script>" )
"SELECT " +
" SUM(COALESCE(dh.calc_value, 0)) AS calcValue, " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ) AS timeStr, " +
" dh.device_num AS deviceNum, " +
" dm.other_name as remark " +
"FROM " +
" ${lastTableName} dh " +
"JOIN collection_params_manage dm ON dh.device_num = dm.mt_num " +
"WHERE " +
" dh.cur_time &gt;= #{startTime}::timestamp " +
" AND dh.cur_time &lt;= #{endTime}::timestamp " +
" AND dh.device_num IN " +
" <foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item} " +
" </foreach> " +
"GROUP BY " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ), " +
" dh.device_num, " +
" dm.other_name " +
"</script>")
List<DeviceTypeEnergy> queryDeviceOneTable(@Param("startTime") String startTime,
@Param("endTime") String endTime,
@Param("lastTableName") String lastTableName,
@ -156,57 +168,81 @@ public interface EnergyAnalyzeMapper {
@Param("params") List<Object> params);
@Select("<script>" +
"select " +
" sum(isnull(dh.calc_value, 0)) as calcValue, " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120) as timeStr, " +
" dh.device_num as deviceNum, " +
" dm.remark " +
"from " +
" ${lastTableName} dh " +
"join device_manage dm " +
"on " +
" dh.device_num = dm.device_num " +
"where " +
" dh.cur_time >= #{startTime} " +
" and dh.cur_time &lt;= #{endTime} " +
" and dh.device_num in " +
"<foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item.value} " +
"</foreach>" +
"group by " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120), " +
" dh.device_num, " +
" dm.remark " +
"SELECT " +
" SUM(COALESCE(dh.calc_value, 0)) AS calcValue, " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ) AS timeStr, " +
" dh.device_num AS deviceNum, " +
" dm.other_name as remark " +
"FROM " +
" ${lastTableName} dh " +
"JOIN collection_params_manage dm ON dh.device_num = dm.mt_num " +
"WHERE " +
" dh.cur_time &gt;= #{startTime}::timestamp " +
" AND dh.cur_time &lt;= #{endTime}::timestamp " +
" AND dh.device_num IN " +
" <foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item} " +
" </foreach> " +
"GROUP BY " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ), " +
" dh.device_num, " +
" dm.other_name " +
"union all " +
"select " +
" sum(isnull(dh.calc_value, 0)) as calcValue, " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120) as timeStr, " +
" dh.device_num as deviceNum, " +
" dm.remark " +
"from " +
" ${curTableName} dh " +
"join device_manage dm " +
"on " +
" dh.device_num = dm.device_num " +
"where " +
" dh.cur_time >= #{startTime} " +
" and dh.cur_time &lt;= #{endTime} " +
" and dh.device_num in " +
"<foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item} " +
"</foreach>" +
"group by " +
" convert(varchar(${len}), " +
" dh.cur_time, " +
" 120), " +
" dh.device_num, " +
" dm.remark " +
"SELECT " +
" SUM(COALESCE(dh.calc_value, 0)) AS calcValue, " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ) AS timeStr, " +
" dh.device_num AS deviceNum, " +
" dm.other_name as remark " +
"FROM " +
" ${curTableName} dh " +
"JOIN collection_params_manage dm ON dh.device_num = dm.mt_num " +
"WHERE " +
" dh.cur_time &gt;= #{startTime}::timestamp " +
" AND dh.cur_time &lt;= #{endTime}::timestamp " +
" AND dh.device_num IN " +
" <foreach collection='params' item='item' open='(' separator=',' close=')'>" +
" #{item} " +
" </foreach> " +
"GROUP BY " +
" TO_CHAR(dh.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ), " +
" dh.device_num, " +
" dm.other_name " +
"</script>" )
List<DeviceTypeEnergy> queryDeviceManyTable(@Param("startTime") String startTime,
@Param("endTime") String endTime,

82
mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java

@ -118,42 +118,52 @@ public interface EnergyQueryMapper {
* @return
*/
@Select("<script>" +
"select sum(calc_value) as curValue,device_type as deviceType,convert(varchar(${len}), cur_time, 120) as timeStr from ${lastTableName} dy " +
" where cur_time >= #{startTime} and cur_time &lt;= #{endTime} " +
"<if test='paramType != null and paramType != \"\"'>" +
" and device_type = #{paramType}" +
"</if>" +
"<if test='haveMeter==true and haveCloud == true'>" +
" and exists ( " +
" select " +
" 1 " +
" from " +
" device_manage " +
" where " +
" device_num = dy.device_num and grade &lt; 50 and grade >=40 and (device_type like '%meter%' or device_type like '%cloud%') " +
" )" +
"</if>" +
"<if test='haveCloud==true and haveMeter==false'>" +
" and exists ( " +
" select " +
" 1 " +
" from " +
" device_manage " +
" where " +
" device_num = dy.device_num and grade &lt; 50 and grade >=40 and device_type like '%cloud%' " +
" )" +
"</if>" +
"<if test='haveCloud==false and haveMeter==true'>" +
" and exists ( " +
" select " +
" 1 " +
" from " +
" device_manage " +
" where " +
" device_num = dy.device_num and grade &lt; 50 and grade >=40 and device_type like '%meter%' " +
" )" +
"</if>" +
" group by device_type,convert(varchar(${len}), cur_time, 120)" +
"select " +
" sum(dm.calc_value) as curValue, " +
" CASE dm.device_type " +
" WHEN '5' THEN 'meter' " +
" WHEN '6' THEN 'cloud' " +
" ELSE 'Unknown' " +
" END as deviceType," +
" TO_CHAR(dm.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ) AS timeStr " +
"from " +
" ${lastTableName} dm " +
"where " +
" dm.cur_time &gt;= #{startTime}::timestamp " +
" AND dm.cur_time &lt;= #{endTime}::timestamp " +
" and device_num in ( " +
" select " +
" device_num " +
" from " +
" collection_params_manage cpm " +
" join device_ledger dl " +
"on " +
" cpm.device_ledger_id = dl.id " +
" and dl.device_type in ('5', '6') " +
") " +
"group by " +
" device_type, " +
" TO_CHAR(dm.cur_time, " +
" <choose>" +
" <when test='len == 4'>'YYYY'</when>" +
" <when test='len == 7'>'YYYY-MM'</when>" +
" <when test='len == 10'>'YYYY-MM-DD'</when>" +
" <when test='len == 13'>'YYYY-MM-DD HH24'</when>" +
" <when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>" +
" <otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>" +
" </choose>" +
" ) " +
"order by " +
" timeStr " +
"</script>")
List<ConsumptionAnalyze> queryOneTable(@Param("startTime") String startTime,
@Param("endTime") String endTime,

2
mh-system/src/main/java/com/mh/system/service/device/IDeviceInOutManageService.java

@ -17,7 +17,7 @@ public interface IDeviceInOutManageService {
DeviceInOutManage selectDeviceInOutManageById(String spareId);
int insertDeviceInOutManage(DeviceInOutManage deviceInOutManage);
int insertDeviceInOutManage(List<DeviceInOutManage> deviceInOutManage, String createBy);
int updateDeviceInOutManage(DeviceInOutManage deviceInOutManage);

41
mh-system/src/main/java/com/mh/system/service/device/impl/DeviceInOutManageServiceImpl.java

@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
/**
@ -71,25 +72,31 @@ public class DeviceInOutManageServiceImpl implements IDeviceInOutManageService {
@Transactional
@Override
public int insertDeviceInOutManage(DeviceInOutManage deviceInOutManage) {
// 获取当前库存量
String sparePartsId = deviceInOutManage.getSparePartsId();
SparePartsManage sparePartsManage = sparePartsManageMapper.selectById(sparePartsId);
int inventoryLevels = 0;
if (sparePartsManage != null) {
inventoryLevels = sparePartsManage.getInventoryLevels();
}
// 修改配件的库存:operaType=0:入库;operaType=1:出库
int intOutNum = deviceInOutManage.getIntOutNum();
if (deviceInOutManage.getOperaType() == 0) {
inventoryLevels = inventoryLevels + intOutNum;
public int insertDeviceInOutManage(List<DeviceInOutManage> deviceInOutManageList, String createBy) {
Date date = new Date();
int result = 0;
for (DeviceInOutManage deviceInOutManage : deviceInOutManageList) {
deviceInOutManage.setCreateBy(createBy);
deviceInOutManage.setCreateTime(date);
// 获取当前库存量
String sparePartsId = deviceInOutManage.getSparePartsId();
SparePartsManage sparePartsManage = sparePartsManageMapper.selectById(sparePartsId);
int inventoryLevels = 0;
if (sparePartsManage != null) {
inventoryLevels = sparePartsManage.getInventoryLevels();
}
// 修改配件的库存:operaType=0:入库;operaType=1:出库
int intOutNum = deviceInOutManage.getIntOutNum();
if (deviceInOutManage.getOperaType() == 0) {
inventoryLevels = inventoryLevels + intOutNum;
} else if (deviceInOutManage.getOperaType() == 1) {
inventoryLevels = inventoryLevels - intOutNum;
}
sparePartsManageMapper.updateInventoryLevels(deviceInOutManage.getSparePartsId(), inventoryLevels, deviceInOutManage.getCreateBy());
} else if (deviceInOutManage.getOperaType() == 1) {
inventoryLevels = inventoryLevels - intOutNum;
sparePartsManageMapper.updateInventoryLevels(deviceInOutManage.getSparePartsId(), -intOutNum, deviceInOutManage.getCreateBy());
deviceInOutManage.setInventoryLevels(inventoryLevels);
result = result + deviceInOutManageMapper.insert(deviceInOutManage);
}
deviceInOutManage.setInventoryLevels(inventoryLevels);
return deviceInOutManageMapper.insert(deviceInOutManage);
return result;
}
@Override

14
mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java

@ -147,11 +147,11 @@ public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService {
public List<Map.Entry<String, Object>> deviceAnalyze(EnergyQueryVO vo) {
DateUtils.sysEnergyDateChange(vo);
// 获取参数
Map<String, Object> paramsMap = vo.getParams();
List<Object> params = new ArrayList<>(paramsMap.values());
if (params.isEmpty()) {
List<ColumnFilter> paramsMap = vo.getSearchParams();
if (paramsMap.isEmpty()) {
return List.of();
}
List<Object> params = paramsMap.stream().map(ColumnFilter::getValue).collect(Collectors.toList());
AtomicReference<String> lastTableName = new AtomicReference<>("data_" + vo.getTimeType());
AtomicReference<String> curTableName = new AtomicReference<>("data_" + vo.getTimeType());
String timeType = vo.getTimeType();
@ -196,8 +196,8 @@ public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService {
break;
}
}
int pageNum = Integer.parseInt(String.valueOf(vo.getParams().get("pageNum")));
int pageSize = Integer.parseInt(String.valueOf(vo.getParams().get("pageSize")));
int pageNum = Integer.parseInt(String.valueOf(vo.getPageNum()));
int pageSize = Integer.parseInt(String.valueOf(vo.getPageSize()));
if (pageNum != 0) {
int startIndex = (pageNum-1)*pageSize;
int endIndex = Math.min(pageNum * pageSize, timeStr.size());
@ -209,8 +209,8 @@ public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService {
columnData.add(column);
i++;
}
int pageNum = Integer.parseInt(String.valueOf(vo.getParams().get("pageNum")));
int pageSize = Integer.parseInt(String.valueOf(vo.getParams().get("pageSize")));
int pageNum = Integer.parseInt(String.valueOf(vo.getPageNum()));
int pageSize = Integer.parseInt(String.valueOf(vo.getPageSize()));
Map<String, Object> map = new JSONObject();
map.put("title", title);
if (pageNum == 0) {

8
mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java

@ -40,8 +40,8 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService {
AtomicReference<String> curTableName = new AtomicReference<>("data_" + vo.getTimeType());
String timeType = vo.getTimeType();
// 判断是否有总表
boolean haveMeter = collectionParamsManageMapper.selectSummary(40, "meter") != 0;
boolean haveCloud = collectionParamsManageMapper.selectSummary(40, "cloud") != 0;
boolean haveMeter = collectionParamsManageMapper.selectSummary(40, "5") != 0;
boolean haveCloud = collectionParamsManageMapper.selectSummary(40, "6") != 0;
List<ConsumptionAnalyze> consumptionAnalyzeEntities = null;
// 表格数据
if ("month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType)) {
@ -101,8 +101,8 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService {
}
// 表格数据
Map<String, Object> map = new HashMap<>();
int pageNum = Integer.parseInt(String.valueOf(vo.getParams().get("pageNum")));
int pageSize = Integer.parseInt(String.valueOf(vo.getParams().get("pageSize")));
int pageNum = vo.getPageNum();
int pageSize = vo.getPageSize();
if (pageNum == 0) {
map.put("coldArr", coldArr);
map.put("meterArr", meterArr);

293
mh-system/src/main/resources/mapper/system/EnergyMapper.xml

@ -489,119 +489,139 @@
<select id="queryDeviceOneTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
sum(calc_value) as curValue,
device_type as deviceType,
convert(varchar(${len}),
cur_time,
120) as timeStr
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${curTableName} dy
${curTableName} dm
where
cur_time >= #{startTime}
and cur_time &lt;= #{endTime}
and device_type = 'meter'
and exists (
select
1
from
device_manage
where
device_num = dy.device_num
<if test="deviceType != null and deviceType != '' and deviceType == 'chiller'">
and grade &lt; 10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'chilledWaterPump'">
and grade &lt; 20 and grade >=10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingPump'">
and grade &lt; 30 and grade >=20
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingTower'">
and grade &lt; 40 and grade >=30
</if>
)
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_type in(
select
cpm.mt_type
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
group by
device_type,
convert(varchar(${len}),
cur_time,
120)
cpm.mt_type
)
group by
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
order by timeStr
</select>
<select id="queryDeviceManyTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
<if test="lastTableName != curTableName">
select
sum(calc_value) as curValue,
convert(varchar(${len}),
cur_time,
120) as timeStr
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${lastTableName} dy
${lastTableName} dm
where
cur_time >= #{startTime}
and cur_time &lt;= #{endTime}
and device_type = 'meter'
and exists (
select
1
from
device_manage
where
device_num = dy.device_num
<if test="deviceType != null and deviceType != '' and deviceType == 'chiller'">
and grade &lt; 10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'chilledWaterPump'">
and grade &lt; 20 and grade >=10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingPump'">
and grade &lt; 30 and grade >=20
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingTower'">
and grade &lt; 40 and grade >=30
</if>
)
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_type in(
select
cpm.mt_type
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
group by
cpm.mt_type
)
group by
convert(varchar(${len}),
cur_time,
120)
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
)
union all
</if>
select
sum(calc_value) as curValue,
convert(varchar(${len}),
cur_time,
120) as timeStr
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${curTableName} dy
${curTableName} dm
where
cur_time >= #{startTime}
and cur_time &lt;= #{endTime}
and device_type = 'meter'
and exists (
select
1
from
device_manage
where
device_num = dy.device_num
<if test="deviceType != null and deviceType != '' and deviceType == 'chiller'">
and grade &lt; 10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'chilledWaterPump'">
and grade &lt; 20 and grade >=10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingPump'">
and grade &lt; 30 and grade >=20
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingTower'">
and grade &lt; 40 and grade >=30
</if>
)
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_type in(
select
cpm.mt_type
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
group by
cpm.mt_type
)
group by
convert(varchar(${len}),
cur_time,
120)
TO_CHAR(dm.cur_time,
<choose><when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
)
order by timeStr
</select>
@ -736,68 +756,57 @@
<select id="queryDeviceLineManyTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
<if test="lastTableName != curTableName">
select
sum(calc_value) as curValue,
cur_time as timeStr
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${lastTableName} dy
${lastTableName} dm
where
cur_time >= #{startTime}
and cur_time &lt;= #{endTime}
and device_type = 'meter'
and exists (
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_type in(
select
1
cpm.mt_type
from
device_manage
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
device_num = dy.device_num
<if test="deviceType != null and deviceType != '' and deviceType == 'chiller'">
and grade &lt; 10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'chilledWaterPump'">
and grade &lt; 20 and grade >=10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingPump'">
and grade &lt; 30 and grade >=20
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingTower'">
and grade &lt; 40 and grade >=30
</if>
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
group by
cpm.mt_type
)
group by cur_time
group by
dm.cur_time
union all
</if>
select
sum(calc_value) as curValue,
cur_time as timeStr
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${curTableName} dy
${curTableName} dm
where
cur_time >= #{startTime}
and cur_time &lt;= #{endTime}
and device_type = 'meter'
and exists (
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_type in(
select
1
cpm.mt_type
from
device_manage
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
device_num = dy.device_num
<if test="deviceType != null and deviceType != '' and deviceType == 'chiller'">
and grade &lt; 10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'chilledWaterPump'">
and grade &lt; 20 and grade >=10
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingPump'">
and grade &lt; 30 and grade >=20
</if>
<if test="deviceType != null and deviceType != '' and deviceType == 'coolingTower'">
and grade &lt; 40 and grade >=30
</if>
)
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
group by
cpm.mt_type
)
group by
cur_time
dm.cur_time
order by timeStr
</select>
</mapper>
Loading…
Cancel
Save