mh
2 months ago
19 changed files with 781 additions and 86 deletions
@ -0,0 +1,70 @@
|
||||
package com.mh.user.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.mh.common.http.HttpResult; |
||||
import com.mh.user.dto.ScreenRequestParamDTO; |
||||
import com.mh.user.service.ScreenService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 大屏接口类 |
||||
* @date 2024-09-24 11:40:15 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/screen") |
||||
public class ScreenController { |
||||
|
||||
@Resource |
||||
private ScreenService screenService; |
||||
|
||||
/** |
||||
* 能耗数据 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/energyData") |
||||
public HttpResult energyData(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) { |
||||
return HttpResult.ok(screenService.energyData(screenRequestParamDTO)); |
||||
} |
||||
|
||||
/** |
||||
* 节能量概况 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/savingEnergyData") |
||||
public HttpResult savingEnergy(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) { |
||||
return HttpResult.ok(screenService.savingEnergy(screenRequestParamDTO)); |
||||
} |
||||
|
||||
/** |
||||
* 节能量同比 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/savingYoyEnergyData") |
||||
public HttpResult savingYoyEnergyData(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) { |
||||
return HttpResult.ok(screenService.savingYoyEnergyData(screenRequestParamDTO)); |
||||
} |
||||
|
||||
/** |
||||
* 故障详情 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/faultList") |
||||
public HttpResult faultList() { |
||||
return HttpResult.ok(screenService.faultList()); |
||||
} |
||||
|
||||
/** |
||||
* 项目坐标数据 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/projectData") |
||||
public HttpResult projectData() { |
||||
return HttpResult.ok(screenService.projectData()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,64 @@
|
||||
package com.mh.user.dto; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 大屏请求参数 |
||||
* @date 2024-09-24 14:12:01 |
||||
*/ |
||||
public class ScreenRequestParamDTO { |
||||
|
||||
/** |
||||
* 查询类型:now:当前数据, day:日数据, week:周数据, month:月数据, year:年数据 |
||||
*/ |
||||
private String timeType; |
||||
|
||||
private String startTime; |
||||
|
||||
private String endTime; |
||||
|
||||
private String projectId; |
||||
|
||||
public String getProjectId() { |
||||
return projectId; |
||||
} |
||||
|
||||
public void setProjectId(String projectId) { |
||||
this.projectId = projectId; |
||||
} |
||||
|
||||
public String getTimeType() { |
||||
return timeType; |
||||
} |
||||
|
||||
public void setTimeType(String timeType) { |
||||
this.timeType = timeType; |
||||
} |
||||
|
||||
public String getStartTime() { |
||||
return startTime; |
||||
} |
||||
|
||||
public void setStartTime(String startTime) { |
||||
this.startTime = startTime; |
||||
} |
||||
|
||||
public String getEndTime() { |
||||
return endTime; |
||||
} |
||||
|
||||
public void setEndTime(String endTime) { |
||||
this.endTime = endTime; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "ScreenRequestParamDTO{" + |
||||
"timeType='" + timeType + '\'' + |
||||
", startTime='" + startTime + '\'' + |
||||
", endTime='" + endTime + '\'' + |
||||
", projectId='" + projectId + '\'' + |
||||
'}'; |
||||
} |
||||
} |
@ -0,0 +1,238 @@
|
||||
package com.mh.user.mapper; |
||||
|
||||
import com.mh.user.dto.ScreenRequestParamDTO; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 大屏服务mapper |
||||
* @date 2024-09-24 14:54:06 |
||||
*/ |
||||
public interface ScreenMapper { |
||||
|
||||
@Select("with projectmttypes as ( " + |
||||
" select " + |
||||
" project_id, " + |
||||
" count(distinct mt_type) as distinct_mt_types " + |
||||
" from " + |
||||
" meter_manage mm " + |
||||
" where " + |
||||
" mm.mt_type in (1, 2) " + |
||||
" and mt_is_sum = 1 " + |
||||
" and mm.grade between 40 and 49 " + |
||||
" and mm.system_id = 1 " + |
||||
" group by " + |
||||
" project_id " + |
||||
" having " + |
||||
" count(distinct mt_type) = 2 " + |
||||
") " + |
||||
"select " + |
||||
" pi2.id, " + |
||||
" pi2.project_name, " + |
||||
" t.mt_type, " + |
||||
" t.cur_value, " + |
||||
" t.cur_time " + |
||||
"from " + |
||||
" project_info pi2 " + |
||||
"left join projectmttypes pmt on pi2.id = pmt.project_id " + |
||||
"left join ( " + |
||||
" select " + |
||||
" project_id, " + |
||||
" mt_type, " + |
||||
" sum(isnull(cur_value, 0)) as cur_value, " + |
||||
" cur_time " + |
||||
" from " + |
||||
" meter_manage mm " + |
||||
" where " + |
||||
" mm.mt_type in (1, 2) " + |
||||
" and mt_is_sum = 1 " + |
||||
" and mm.grade between 140 and 149 " + |
||||
" and mm.system_id = 1 " + |
||||
" and datepart(hour, mm.cur_time) = datepart(hour, getdate()) " + |
||||
" group by " + |
||||
" project_id, " + |
||||
" mt_type, " + |
||||
" cur_time " + |
||||
") t on pi2.id = t.project_id " + |
||||
"where " + |
||||
" pmt.project_id is not null; ") |
||||
List<Map<String, Object>> queryNowData(); |
||||
|
||||
@Select("select " + |
||||
" pi2.project_name, " + |
||||
" pi2.longitude, " + |
||||
" pi2.latitude, " + |
||||
" isnull(t.fault, 0) as fault " + |
||||
"from " + |
||||
" project_info pi2 " + |
||||
"left join ( " + |
||||
"select " + |
||||
" project_id, " + |
||||
" system_id, " + |
||||
" case " + |
||||
" when sum(cur_value) > 0 then 1 " + |
||||
" else 0 " + |
||||
" end as fault " + |
||||
"from " + |
||||
" meter_manage mm " + |
||||
"where " + |
||||
" mm.system_id = 1 " + |
||||
" and mm.grade between 50 and 59 " + |
||||
" and system_id = 1 " + |
||||
"group by " + |
||||
" project_id, " + |
||||
" system_id " + |
||||
") t on pi2.id = t.project_id and pi2.system_id = t.system_id ") |
||||
List<Map<String, Object>> queryProjectData(); |
||||
|
||||
@Select("select " + |
||||
" cur_date as curDate, " + |
||||
" elect, " + |
||||
" cl, " + |
||||
" cop " + |
||||
"from " + |
||||
" energy_data_day edm " + |
||||
"where " + |
||||
" cur_date between #{startTime} and #{endTime} " + |
||||
" and project_id = #{projectId} " + |
||||
"order by " + |
||||
" cur_date") |
||||
List<Map<String, Object>> queryMonthData(ScreenRequestParamDTO screenRequestParamDTO); |
||||
|
||||
/** |
||||
* |
||||
* @param screenRequestParamDTO |
||||
* @return |
||||
*/ |
||||
@Select("<script>" + |
||||
"WITH ProjectMTType1 AS ( " + |
||||
"SELECT " + |
||||
" project_id " + |
||||
"FROM " + |
||||
" meter_manage mm " + |
||||
"WHERE " + |
||||
" mm.mt_type = 1 " + |
||||
" AND mt_is_sum = 1 " + |
||||
" AND mm.grade BETWEEN 40 AND 49 " + |
||||
" AND mm.system_id = 1 " + |
||||
"GROUP BY " + |
||||
" project_id " + |
||||
"HAVING " + |
||||
" COUNT(DISTINCT mt_type) = 1 " + |
||||
"), " + |
||||
"ProjectMTType2 AS ( " + |
||||
"SELECT " + |
||||
" project_id " + |
||||
"FROM " + |
||||
" meter_manage mm " + |
||||
"WHERE " + |
||||
" mm.mt_type = 2 " + |
||||
" AND mt_is_sum = 1 " + |
||||
" AND mm.grade BETWEEN 40 AND 49 " + |
||||
" AND mm.system_id = 1 " + |
||||
"GROUP BY " + |
||||
" project_id " + |
||||
"HAVING " + |
||||
" COUNT(DISTINCT mt_type) = 1 " + |
||||
") " + |
||||
"SELECT " + |
||||
" pi2.id, " + |
||||
" pi2.project_name as projectName, " + |
||||
" isnull(edd.elect, " + |
||||
" 0) as elect " + |
||||
"FROM " + |
||||
" ProjectMTType1 pmt1 " + |
||||
"left join project_info pi2 on " + |
||||
" pi2.id = pmt1.project_id " + |
||||
"left join energy_data_day edd on " + |
||||
" edd.project_id = pmt1.project_id " + |
||||
" and edd.cur_date between #{startTime} and #{endTime} " + |
||||
"WHERE " + |
||||
" NOT EXISTS ( " + |
||||
" SELECT " + |
||||
" 1 " + |
||||
" FROM " + |
||||
" ProjectMTType2 pmt2 " + |
||||
" WHERE " + |
||||
" pmt2.project_id = pmt1.project_id " + |
||||
" ) " + |
||||
"<if test='projectId != null and projectId != \"\"'>" + |
||||
" and pi2.id = #{projectId} " + |
||||
"</if>" + |
||||
"</script>") |
||||
List<Map<String, Object>> savingEnergy(ScreenRequestParamDTO screenRequestParamDTO); |
||||
|
||||
@Select("select " + |
||||
" t1.cur_date as curDate, " + |
||||
" t1.sumValue as curValue, " + |
||||
" isnull(t2.sumValue, 0) as lastValue, " + |
||||
" case " + |
||||
" when t2.sumValue > 0 then concat(convert(decimal(18, 2),(t1.sumValue - t2.sumValue)/ t2.sumValue * 100), '%') " + |
||||
" when (t1.sumValue - t2.sumValue) = 0 then '0.00%' " + |
||||
" else '同期无数据' " + |
||||
" end yoy " + |
||||
"from " + |
||||
" ( " + |
||||
" select " + |
||||
" cur_date, " + |
||||
" sum(elect) as sumValue " + |
||||
" from " + |
||||
" energy_data_day edd " + |
||||
" where " + |
||||
" edd.cur_date between #{startTime} and #{endTime} " + |
||||
" and edd.project_id = #{projectId} " + |
||||
" group by " + |
||||
" cur_date " + |
||||
") t1 " + |
||||
"left join ( " + |
||||
" select " + |
||||
" convert(varchar(10), " + |
||||
" dateadd(YEAR, 1, cur_date), " + |
||||
" 120) as cur_date , " + |
||||
" case " + |
||||
" when elect is null then '同期无数据' " + |
||||
" else sum(elect) " + |
||||
" end " + |
||||
" sumValue " + |
||||
" from " + |
||||
" energy_data_day edd " + |
||||
" where " + |
||||
" edd.cur_date between #{lastStartTime} and #{lastEndTime} " + |
||||
" and edd.project_id = #{projectId} " + |
||||
" group by " + |
||||
" cur_date, elect " + |
||||
") t2 on " + |
||||
" t1.cur_date = t2.cur_date order by cur_date ") |
||||
List<Map<String, Object>> savingYoyEnergyData(@Param("projectId") String projectId, |
||||
@Param("startTime") String startTime, |
||||
@Param("endTime") String endTime, |
||||
@Param("lastStartTime") String lastStartTime, |
||||
@Param("lastEndTime") String lastEndTime); |
||||
@Select("select " + |
||||
" pi2.project_name, " + |
||||
" t1.other_name " + |
||||
"from " + |
||||
" project_info pi2 " + |
||||
"join ( " + |
||||
" select " + |
||||
" project_id, " + |
||||
" other_name " + |
||||
" from " + |
||||
" meter_manage mm " + |
||||
" where " + |
||||
" grade between 50 and 59 " + |
||||
" and cur_value = 1 " + |
||||
" and day(cur_time) = day(getdate()) " + |
||||
" group by " + |
||||
" project_id, " + |
||||
" other_name " + |
||||
" ) t1 on " + |
||||
" pi2.id = t1.project_id ") |
||||
List<Map<String, Object>> queryFaultList(); |
||||
} |
@ -0,0 +1,48 @@
|
||||
package com.mh.user.service; |
||||
|
||||
import com.alibaba.fastjson2.JSONArray; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.mh.user.dto.ScreenRequestParamDTO; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 大屏服务类 |
||||
* @date 2024-09-24 14:02:44 |
||||
*/ |
||||
public interface ScreenService { |
||||
|
||||
/** |
||||
* 获取项目概况以及当月项目数据 |
||||
* @param screenRequestParamDTO |
||||
* @return |
||||
*/ |
||||
JSONArray energyData(ScreenRequestParamDTO screenRequestParamDTO); |
||||
|
||||
/** |
||||
* 项目坐标以及是否有故障 |
||||
* @return |
||||
*/ |
||||
JSONArray projectData(); |
||||
|
||||
/** |
||||
* 当日节能量概况 |
||||
* @param screenRequestParamDTO |
||||
* @return |
||||
*/ |
||||
JSONArray savingEnergy(ScreenRequestParamDTO screenRequestParamDTO); |
||||
|
||||
/** |
||||
* 获取节能量同比 |
||||
* @param screenRequestParamDTO |
||||
* @return |
||||
*/ |
||||
JSONArray savingYoyEnergyData(ScreenRequestParamDTO screenRequestParamDTO); |
||||
|
||||
/** |
||||
* 故障详情 |
||||
* @return |
||||
*/ |
||||
JSONArray faultList(); |
||||
} |
@ -0,0 +1,210 @@
|
||||
package com.mh.user.service.impl; |
||||
|
||||
import com.alibaba.fastjson2.JSONArray; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.mh.user.dto.ScreenRequestParamDTO; |
||||
import com.mh.user.mapper.ScreenMapper; |
||||
import com.mh.user.service.ScreenService; |
||||
import com.mh.user.utils.DateUtil; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.math.RoundingMode; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 大屏服务实现类 |
||||
* @date 2024-09-24 14:52:28 |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
public class ScreenServiceImpl implements ScreenService { |
||||
|
||||
@Resource |
||||
private ScreenMapper screenMapper; |
||||
|
||||
@Override |
||||
public JSONArray faultList() { |
||||
JSONArray resultJson = new JSONArray(); |
||||
List<Map<String, Object>> faultList = screenMapper.queryFaultList(); |
||||
if (faultList.isEmpty()) { |
||||
return resultJson; |
||||
} |
||||
// 根据项目名称分组
|
||||
Map<Object, List<Map<String, Object>>> projectIds = faultList.stream().collect(Collectors.groupingBy(map -> map.get("project_name"))); |
||||
for (Map.Entry<Object, List<Map<String, Object>>> entry : projectIds.entrySet()) { |
||||
String projectName = (String) entry.getKey(); |
||||
List<Map<String, Object>> projectId = faultList.stream().filter(map -> map.get("project_name").equals(projectName)).collect(Collectors.toList()); |
||||
JSONObject data = new JSONObject(); |
||||
data.put("projectName", projectName); |
||||
data.put("faultNum", projectId.size()); |
||||
String[] faultListStr = new String[projectId.size()]; |
||||
for (int i = 0; i < projectId.size(); i++) { |
||||
faultListStr[i] = (String) projectId.get(i).get("other_name"); |
||||
} |
||||
data.put("faultList", faultListStr); |
||||
resultJson.add(data); |
||||
} |
||||
return resultJson; |
||||
} |
||||
|
||||
@Override |
||||
public JSONArray savingYoyEnergyData(ScreenRequestParamDTO screenRequestParamDTO) { |
||||
// 判断类型
|
||||
JSONArray resultJson = new JSONArray(); |
||||
switch (screenRequestParamDTO.getTimeType()) { |
||||
case "day": |
||||
String projectId = screenRequestParamDTO.getProjectId(); |
||||
String startTime = screenRequestParamDTO.getStartTime(); |
||||
String endTime = screenRequestParamDTO.getEndTime(); |
||||
String lastStartTime = DateUtil.yoyDate(startTime + " 00:00:00").substring(0, 10); |
||||
String lastEndTime = DateUtil.yoyDate(endTime+ " 23:59:59").substring(0, 10); |
||||
List<Map<String, Object>> monthData = screenMapper.savingYoyEnergyData(projectId, startTime, endTime, lastStartTime, lastEndTime); |
||||
resultJson.add(monthData); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return resultJson; |
||||
} |
||||
|
||||
@Override |
||||
public JSONArray savingEnergy(ScreenRequestParamDTO screenRequestParamDTO) { |
||||
// 判断类型
|
||||
JSONArray resultJson = new JSONArray(); |
||||
switch (screenRequestParamDTO.getTimeType()) { |
||||
case "day": |
||||
screenRequestParamDTO.setStartTime(screenRequestParamDTO.getStartTime()); |
||||
screenRequestParamDTO.setEndTime(screenRequestParamDTO.getEndTime()); |
||||
List<Map<String, Object>> monthData = screenMapper.savingEnergy(screenRequestParamDTO); |
||||
resultJson.add(monthData); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return resultJson; |
||||
} |
||||
|
||||
@Override |
||||
public JSONArray projectData() { |
||||
JSONArray resultJson = new JSONArray(); |
||||
List<Map<String, Object>> projectData = screenMapper.queryProjectData(); |
||||
if (projectData.isEmpty()) { |
||||
return resultJson; |
||||
} |
||||
for (Map<String, Object> map : projectData) { |
||||
JSONObject data = new JSONObject(); |
||||
float[] ll = new float[2]; |
||||
data.put("name", map.get("project_name")); |
||||
ll[0] = Float.parseFloat(map.get("longitude").toString()); |
||||
ll[1] = Float.parseFloat(map.get("latitude").toString()); |
||||
data.put("value", ll); |
||||
data.put("fault", map.get("fault")); |
||||
resultJson.add(data); |
||||
} |
||||
return resultJson; |
||||
} |
||||
|
||||
@Override |
||||
public JSONArray energyData(ScreenRequestParamDTO screenRequestParamDTO) { |
||||
// 判断类型
|
||||
JSONArray resultJson = new JSONArray(); |
||||
switch (screenRequestParamDTO.getTimeType()) { |
||||
case "now": |
||||
getNowData(resultJson); |
||||
break; |
||||
case "day": |
||||
screenRequestParamDTO.setStartTime(screenRequestParamDTO.getStartTime()); |
||||
screenRequestParamDTO.setEndTime(screenRequestParamDTO.getEndTime()); |
||||
getMonthData(resultJson, screenRequestParamDTO); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return resultJson; |
||||
} |
||||
|
||||
private void getMonthData(JSONArray resultJson, ScreenRequestParamDTO screenRequestParamDTO) { |
||||
List<Map<String, Object>> monthData = screenMapper.queryMonthData(screenRequestParamDTO); |
||||
resultJson.add(monthData); |
||||
} |
||||
|
||||
private void getNowData(JSONArray resultJson) { |
||||
List<Map<String, Object>> nowData = screenMapper.queryNowData(); |
||||
if (nowData.isEmpty()) { |
||||
return; |
||||
} |
||||
|
||||
// 根据项目名进行分组
|
||||
Map<Object, List<Map<String, Object>>> projectIds = nowData.stream().collect(Collectors.groupingBy(map -> map.get("id"))); |
||||
// 根据项目名获取对应的冷量计、电表数据,计算EER
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> entry : projectIds.entrySet()) { |
||||
Long proId = (Long) entry.getKey(); |
||||
List<Map<String, Object>> projectId = nowData.stream().filter(map -> map.get("id").equals(proId)).collect(Collectors.toList()); |
||||
if (projectId.isEmpty()) { |
||||
continue; |
||||
} |
||||
String projectName = (String) projectId.get(0).get("project_name"); |
||||
log.info("项目名:{}", projectName); |
||||
String cooling = "未采集"; |
||||
String ele = "未采集"; |
||||
JSONObject data = new JSONObject(); |
||||
data.put("projectName", projectName); |
||||
for (Map<String, Object> map : projectId) { |
||||
// 获取冷量计:2、电表数据:1
|
||||
Long mtType = (Long) map.get("mt_type"); |
||||
if (null == mtType) { |
||||
continue; |
||||
} |
||||
if (1 == mtType) { |
||||
ele = ((BigDecimal) map.get("cur_value")).setScale(2, RoundingMode.HALF_UP).toString(); |
||||
} |
||||
if (2 == mtType) { |
||||
cooling = ((BigDecimal) map.get("cur_value")).setScale(2, RoundingMode.HALF_UP).toString(); |
||||
} |
||||
} |
||||
JSONObject dataDetail = new JSONObject(); |
||||
dataDetail.clear(); |
||||
|
||||
HashMap<String, Object> map = new HashMap<>(); |
||||
map.put("name", projectName); |
||||
map.put("value", ele); |
||||
dataDetail.put("ele", new HashMap<>(map)); |
||||
|
||||
map.clear(); |
||||
map.put("name", projectName); |
||||
map.put("value", cooling); |
||||
dataDetail.put("cooling", new HashMap<>(map)); |
||||
|
||||
// 计算EER
|
||||
map.clear(); |
||||
if ("未采集".equals(cooling) || "未采集".equals(ele)) { |
||||
map.put("name", projectName); |
||||
map.put("value", "未采集"); |
||||
dataDetail.put("eer", new HashMap<>(map)); |
||||
} else { |
||||
double coolingValue = Double.parseDouble(cooling); |
||||
double eleValue = Double.parseDouble(ele); |
||||
double eer = 0; |
||||
if (eleValue <= 0 || coolingValue <= 0) { |
||||
eer = 0; |
||||
} else { |
||||
eer = coolingValue / eleValue; |
||||
} |
||||
map.put("name", projectName); |
||||
map.put("value", (new BigDecimal(eer).setScale(2, RoundingMode.HALF_UP)).toString()); |
||||
dataDetail.put("eer", new HashMap<>(map)); |
||||
} |
||||
data.put("data", dataDetail); |
||||
resultJson.add(data); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue