数据分析模块开发

This commit is contained in:
haozq 2025-10-28 09:28:13 +08:00
parent 967abac3e7
commit d87253cab2
16 changed files with 353 additions and 110 deletions

View File

@ -32,6 +32,14 @@ public class SjProjectProgress {
* 结束时间
*/
private String endTime;
/**
* 计划进度
*/
private String planAccess;
/**
* 实际进度
*/
private String exeAccess;

View File

@ -4,20 +4,21 @@
<insert id="addData">
insert into sj_construction_progress(
pro_type ,pro_gx , plan_start_time , plan_end_time ,start_time , end_time
)values (#{proType},#{proGx},#{planStartTime},#{planEndTime},#{startTime},#{endTime})
pro_type ,pro_gx , plan_start_time , plan_end_time ,start_time , end_time,plan_access,exe_access
)values (#{proType},#{proGx},#{planStartTime},#{planEndTime},#{startTime},#{endTime},#{planAccess},#{exeAccess})
</insert>
<update id="updateData">
update sj_construction_progress
set pro_type=#{proType} ,pro_gx =#{proGx},
plan_start_time =#{planStartTime}, plan_end_time =#{planEndTime},start_time =#{startTime}, end_time =#{endTime}
plan_start_time =#{planStartTime}, plan_end_time =#{planEndTime},start_time =#{startTime}, end_time =#{endTime},
plan_access=#{planAccess},exe_access=#{exeAccess}
where id=#{id}
</update>
<delete id="delete">
delete from sj_construction_progress where id=#{id}
</delete>
<select id="getList" resultType="com.securitycontrol.entity.background.vo.SjProjectProgress">
select id, pro_type proType,pro_gx proGx,
select id, pro_type proType,pro_gx proGx,plan_access planAccess,exe_access exeAccess,
plan_start_time planStartTime, plan_end_time planEndTime,start_time startTime, end_time endTime
from sj_construction_progress
<where>
@ -30,7 +31,7 @@
</where>
</select>
<select id="getDetails" resultType="com.securitycontrol.entity.background.vo.SjProjectProgress">
select id, pro_type proType,pro_gx proGx,
select id, pro_type proType,pro_gx proGx,plan_access planAccess,exe_access exeAccess,
plan_start_time planStartTime, plan_end_time planEndTime,start_time startTime, end_time endTime
from sj_construction_progress
where id=#{id}

View File

@ -43,4 +43,24 @@ public class SjConstructionProgressController extends BaseController {
}
}
@GetMapping("getTjProgressList")
public AjaxResult getTjProgressList(SjConstructionProgress o) {
try {
return service.getTjProgressList(o);
} catch (Exception e) {
log.error(e.toString(),e);
return error("请求出错了");
}
}
@GetMapping("getDqProgressList")
public AjaxResult getDqProgressList(SjConstructionProgress o) {
try {
return service.getDqProgressList(o);
} catch (Exception e) {
log.error(e.toString(),e);
return error("请求出错了");
}
}
}

View File

@ -44,4 +44,36 @@ public class SjEnergyReductionController extends BaseController {
}
}
/**
* 节能减排分析
*
* @param o 传参
* @return 节能减排分析控制层
*/
@GetMapping("getWaterList")
public AjaxResult getWaterList(SjEnergyReduction o) {
try {
return service.getWaterList(o);
} catch (Exception e) {
log.error(e.toString(),e);
return error("请求出错了");
}
}
/**
* 节能减排分析
*
* @param o 传参
* @return 节能减排分析控制层
*/
@GetMapping("getEnergyList")
public AjaxResult getEnergyList(SjEnergyReduction o) {
try {
return service.getEnergyList(o);
} catch (Exception e) {
log.error(e.toString(),e);
return error("请求出错了");
}
}
}

View File

@ -47,18 +47,39 @@ public class SjConstructionProgress {
*/
private String endTime;
/**
* 计划进度
*/
private String planAccess;
/**
* 实际进度
*/
private String exeAccess;
private String sql;
//统计数据
private String date;
private String plannedCount;
private String actualCount;
//进度数据
private String actualDays;
private String actualPercent;
private String planDays;
private String planDay;
private String exeDay;
private String planPercent;
}

View File

@ -32,10 +32,13 @@ public class SjEnergyReduction {
*/
private Integer dataNum;
private String num;
private String startTime;
private String endTime;
private String sql;
private String date;
}

View File

@ -32,6 +32,10 @@ public class SjProjectEnvironment {
private String deviceCode;
private String isWarn;
/**
* 单位
*/
private String unit;
}

View File

@ -2,6 +2,7 @@ package com.securitycontrol.screen.mapper;
import com.securitycontrol.screen.domain.SjConstructionProgress;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -11,4 +12,17 @@ public interface SjConstructionProgressMapper {
List<SjConstructionProgress> selectProProgress(SjConstructionProgress o);
List<SjConstructionProgress> getProgressWithPercent(SjConstructionProgress o);
/**
* 查询计划和飞机哈数量
* @param day
* @return
*/
List<String> getProPlanNum(@Param("day") String day);
/**
* 计划到今天数据
* @return
*/
List<SjConstructionProgress> getPlanList(@Param("type")String type,@Param("startTime")String startTime,@Param("ednTime")String ednTime);
}

View File

@ -2,6 +2,7 @@ package com.securitycontrol.screen.mapper;
import com.securitycontrol.screen.domain.SjEnergyReduction;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -10,4 +11,25 @@ public interface SjEnergyReductionMapper {
List<SjEnergyReduction> selectEnergyReduction(SjEnergyReduction o);
/**
* 获取 全部发电 蓄水量
* @param o
* @return
*/
List<String> getAllSdList(SjEnergyReduction o);
/**
* 查询启用睡了
* @param day
* @return
*/
List<String> getEnergyList(@Param("day") String day);
/**
* 蓄水 用水
* @param day
* @return
*/
List<String> getWaterList(@Param("day")String day);
}

View File

@ -5,4 +5,18 @@ import com.securitycontrol.screen.domain.SjConstructionProgress;
public interface SjConstructionProgressService{
AjaxResult selectProProgress(SjConstructionProgress o);
/**
* 土建
* @param o
* @return
*/
AjaxResult getTjProgressList(SjConstructionProgress o);
/**
* 电气
* @param o
* @return
*/
AjaxResult getDqProgressList(SjConstructionProgress o);
}

View File

@ -5,4 +5,18 @@ import com.securitycontrol.screen.domain.SjEnergyReduction;
public interface SjEnergyReductionService{
AjaxResult selectEnergyReduction(SjEnergyReduction o);
/**
* 水数据集合
* @param o
* @return
*/
AjaxResult getWaterList(SjEnergyReduction o);
/**
* 电数据集合
* @param o
* @return
*/
AjaxResult getEnergyList(SjEnergyReduction o);
}

View File

@ -1,7 +1,9 @@
package com.securitycontrol.screen.service.impl;
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.screen.domain.SjProjectQuality;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,13 +13,11 @@ import com.securitycontrol.screen.domain.SjConstructionProgress;
import com.securitycontrol.screen.service.SjConstructionProgressService;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class SjConstructionProgressServiceImpl implements SjConstructionProgressService{
@Resource
@ -26,38 +26,62 @@ public class SjConstructionProgressServiceImpl implements SjConstructionProgress
@Override
public AjaxResult selectProProgress(SjConstructionProgress o) {
String sql = "SELECT DATE_ADD("+o.getStartTime()+", INTERVAL (ones.a + tens.a * 10) DAY) AS dt\n" +
" FROM\n" +
" (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n" +
" UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
" UNION ALL SELECT 8 UNION ALL SELECT 9) AS ones\n" +
" CROSS JOIN\n" +
" (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n" +
" UNION ALL SELECT 4 UNION ALL SELECT 5) AS tens\n" +
" WHERE DATE_ADD("+o.getStartTime()+", INTERVAL (ones.a + tens.a * 10) DAY) <= "+o.getEndTime();
o.setSql(sql);
List<SjConstructionProgress> echartsList = mapper.selectProProgress(o);
Map<String, List<SjConstructionProgress>> groupedByProTypeEcharts = echartsList.stream()
.collect(Collectors.groupingBy(SjConstructionProgress::getProType));
List<SjConstructionProgress> percentList = mapper.getProgressWithPercent(o);
Map<String, List<SjConstructionProgress>> groupedByProTypePercent = percentList.stream()
.collect(Collectors.groupingBy(SjConstructionProgress::getProType));
//
Map<String,Object> map = new HashMap<>();
List<String> dayList=new ArrayList<>();
List<String> tjplanNum=new ArrayList<>();
List<String> tjexeNum=new ArrayList<>();
List<String> dqplanNum=new ArrayList<>();
List<String> dqexeNum=new ArrayList<>();
String startTime=o.getStartTime();
String endTime=o.getEndTime();
long num= DateTimeHelper.getDayDifference(startTime,endTime);
if(num>31){
return AjaxResult.error("日期天数不能超过31天");
}
dayList.add(startTime);
for (int i = 1; i <num; i++) {
String nextDay= DateTimeHelper.getDayAddOrReduce(startTime,i);
dayList.add(nextDay);
}
//添加到土建
for (String day : dayList) {
List<String> proCessNum=mapper.getProPlanNum(day);
tjplanNum.add(proCessNum.get(0));
tjexeNum.add(proCessNum.get(1));
dqplanNum.add(proCessNum.get(2));
dqexeNum.add(proCessNum.get(3));
}
map.put("day",dayList);
map.put("tjplanNum",tjplanNum);
map.put("tjexeNum",tjexeNum);
map.put("dqplanNum",dqplanNum);
map.put("dqexeNum",dqexeNum);
//将数据组合一下
Map<String, Map<String, List<SjConstructionProgress>>> mergedMap = groupedByProTypeEcharts.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey, // 保持相同的 key
entry -> {
String key = entry.getKey();
List<SjConstructionProgress> echartsList2 = entry.getValue();
List<SjConstructionProgress> percentList2 = groupedByProTypePercent.getOrDefault(key, Collections.emptyList());
// 将两个列表放入一个 Map 中返回
Map<String, List<SjConstructionProgress>> combined = new HashMap<>();
combined.put("echarts", echartsList2);
combined.put("percent", percentList2);
return combined;
}
));
return AjaxResult.success("查询成功",mergedMap);
return AjaxResult.success(map);
}
@Override
public AjaxResult getTjProgressList(SjConstructionProgress o) {
try{
List<SjConstructionProgress> tjList=mapper.getPlanList("土建",o.getStartTime(),o.getEndTime());
return AjaxResult.success(tjList);
}catch (Exception e){
log.error(e.toString(),e);
}
return AjaxResult.success(new ArrayList<>());
}
@Override
public AjaxResult getDqProgressList(SjConstructionProgress o) {
try{
List<SjConstructionProgress> dqList=mapper.getPlanList("电气",o.getStartTime(),o.getEndTime());
return AjaxResult.success(dqList);
}catch (Exception e){
log.error(e.toString(),e);
}
return AjaxResult.success(new ArrayList<>());
}
}

View File

@ -1,8 +1,10 @@
package com.securitycontrol.screen.service.impl;
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.screen.domain.SjConstructionProgress;
import com.securitycontrol.screen.domain.SjMaxDevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,12 +14,14 @@ import com.securitycontrol.screen.mapper.SjEnergyReductionMapper;
import com.securitycontrol.screen.service.SjEnergyReductionService;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
public class SjEnergyReductionServiceImpl implements SjEnergyReductionService{
@Resource
@ -26,40 +30,79 @@ public class SjEnergyReductionServiceImpl implements SjEnergyReductionService{
@Override
public AjaxResult selectEnergyReduction(SjEnergyReduction o) {
String sql = "SELECT DATE_ADD("+o.getStartTime()+", INTERVAL (ones.a + tens.a * 10) DAY) AS dt\n" +
" FROM\n" +
" (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n" +
" UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
" UNION ALL SELECT 8 UNION ALL SELECT 9) AS ones\n" +
" CROSS JOIN\n" +
" (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n" +
" UNION ALL SELECT 4 UNION ALL SELECT 5) AS tens\n" +
" WHERE DATE_ADD("+o.getStartTime()+", INTERVAL (ones.a + tens.a * 10) DAY) <= "+o.getEndTime();
o.setSql(sql);
List<SjEnergyReduction> list = mapper.selectEnergyReduction(o);
Map<String, List<SjEnergyReduction>> groupedByProTypeEcharts = list.stream()
.collect(Collectors.groupingBy(SjEnergyReduction::getType));
Map<String,Object> map = new HashMap<>();
//整体人员利用率和设备使用率
// 先过滤出type为'蓄水量'的数据
List<SjEnergyReduction> storageList = list.stream()
.filter(item -> "蓄水量".equals(item.getType()))
.collect(Collectors.toList());
// 然后计算总和
double totalWater = storageList.stream()
.mapToDouble(SjEnergyReduction::getDataNum)
.sum();
List<SjEnergyReduction> energyList = list.stream()
.filter(item -> "发电量".equals(item.getType()))
.collect(Collectors.toList());
// 然后计算总和
double totalEnergy = energyList.stream()
.mapToDouble(SjEnergyReduction::getDataNum)
.sum();
Map<String, Object> result = new HashMap<>();
result.put("echarts", groupedByProTypeEcharts);
result.put("waterUtilization", totalWater);
result.put("energyUtilization", totalEnergy);
return AjaxResult.success("查询成功",result);
List<String> list=mapper.getAllSdList(o);
map.put("waterUtilization", list.get(0));
map.put("energyUtilization", list.get(1));
return AjaxResult.success("查询成功",map);
}
@Override
public AjaxResult getWaterList(SjEnergyReduction o) {
Map<String,Object> map = new HashMap<>();
try{
List<String> xsList=new ArrayList<>();
List<String> ysList=new ArrayList<>();
List<String> dayList=new ArrayList<>();
String startTime=o.getStartTime();
String endTime=o.getEndTime();
long num= DateTimeHelper.getDayDifference(startTime,endTime);
if(num>31){
return AjaxResult.error("日期天数不能超过31天");
}
dayList.add(startTime);
for (int i = 1; i <num; i++) {
String nextDay= DateTimeHelper.getDayAddOrReduce(startTime,i);
dayList.add(nextDay);
}
for (String day : dayList) {
List<String> proCessNum=mapper.getWaterList(day);
xsList.add(proCessNum.get(0));
ysList.add(proCessNum.get(1));
}
map.put("dayList", dayList);
map.put("xsList", xsList);
map.put("ysList", ysList);
}catch (Exception e){
log.error(e.toString(),e);
}
return AjaxResult.success(map);
}
@Override
public AjaxResult getEnergyList(SjEnergyReduction o) {
Map<String,Object> map = new HashMap<>();
try{
List<String> fdList=new ArrayList<>();
List<String> ydList=new ArrayList<>();
List<String> dayList=new ArrayList<>();
String startTime=o.getStartTime();
String endTime=o.getEndTime();
long num= DateTimeHelper.getDayDifference(startTime,endTime);
if(num>31){
return AjaxResult.error("日期天数不能超过31天");
}
dayList.add(startTime);
for (int i = 1; i <num; i++) {
String nextDay= DateTimeHelper.getDayAddOrReduce(startTime,i);
dayList.add(nextDay);
}
for (String day : dayList) {
List<String> proCessNum=mapper.getEnergyList(day);
fdList.add(proCessNum.get(0));
ydList.add(proCessNum.get(1));
}
map.put("dayList", dayList);
map.put("fdList", fdList);
map.put("ydList", ydList);
}catch (Exception e){
log.error(e.toString(),e);
}
return AjaxResult.success(map);
}
}

View File

@ -25,40 +25,6 @@
</sql>
<!-- 不按pro_type分组
SELECT
date_list.dt AS date,
COALESCE(planned_count, 0) AS planned_count,
COALESCE(actual_count, 0) AS actual_count
FROM (
#{sql}
) AS date_list
LEFT JOIN (
SELECT
dl_inner.dt,
COUNT(p.id) AS planned_count
FROM (
#{sql}
) AS dl_inner
LEFT JOIN sj_construction_progress p
ON dl_inner.dt BETWEEN p.plan_start_time AND p.plan_end_time
GROUP BY dl_inner.dt
) AS planned ON date_list.dt = planned.dt
LEFT JOIN (
SELECT
dl_inner.dt,
COUNT(a.id) AS actual_count
FROM (
#{sql}
) AS dl_inner
LEFT JOIN sj_construction_progress a
ON dl_inner.dt BETWEEN a.start_time AND a.end_time
GROUP BY dl_inner.dt
) AS actual ON date_list.dt = actual.dt
WHERE date_list.dt BETWEEN #{startTime} AND #{endTime}
ORDER BY date_list.dt; -->
<select id="selectProProgress" resultMap="BaseResultMap">
SELECT
date_list.dt AS date,
@ -159,4 +125,33 @@ SELECT
FROM sj_construction_progress
ORDER BY id
</select>
<select id="getProPlanNum" resultType="java.lang.String">
SELECT IFNULL(count(1),0)
FROM
sj_construction_progress
WHERE #{day} BETWEEN plan_start_time and plan_end_time and pro_type like concat('%土建%')
union ALL
SELECT IFNULL(count(1),0)
FROM
sj_construction_progress
WHERE #{day} BETWEEN start_time and end_time and pro_type like concat('%土建%')
union all
SELECT IFNULL(count(1),0)
FROM
sj_construction_progress
WHERE #{day} BETWEEN plan_start_time and plan_end_time and pro_type like concat('%电气%')
union ALL
SELECT IFNULL(count(1),0)
FROM
sj_construction_progress
WHERE #{day} BETWEEN start_time and end_time and pro_type like concat('%电气%')
</select>
<select id="getPlanList" resultType="com.securitycontrol.screen.domain.SjConstructionProgress">
select pro_gx proType,plan_start_time planStartTime,plan_end_time planEndTime,CURRENT_DATE() today ,
DATEDIFF(plan_end_time, plan_start_time) planDay ,
start_time startTime,end_time endTime,
DATEDIFF(end_time, start_time) exeDay,plan_access planAccess,exe_access exeAccess
from sj_construction_progress
where pro_type like concat('%',#{type},'%')
</select>
</mapper>

View File

@ -115,4 +115,31 @@
WHERE date_list.dt BETWEEN #{startTime} AND #{endTime}
ORDER BY t.type, date_list.dt
</select>
<select id="getAllSdList" resultType="java.lang.String">
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%发电%') and create_time between #{startTime} and #{endTime}
union All
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%蓄水%') and create_time between #{startTime} and #{endTime}
</select>
<select id="getEnergyList" resultType="java.lang.String">
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%发电%') and create_time=#{day}
union All
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%用电%') and create_time=#{day}
</select>
<select id="getWaterList" resultType="java.lang.String">
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%发电%') and create_time=#{day}
union All
select IFNULL(sum(data_num),0)
from sj_energy_reduction
where type like('%用电%') and create_time=#{day}
</select>
</mapper>

View File

@ -14,6 +14,7 @@
<result column="mode_name" property="modeName"/>
<result column="val" property="val"/>
<result column="is_warn" property="isWarn"/>
<result column="unit" property="unit"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
@ -29,7 +30,7 @@
tdd.mode_name,
DATE(thdv.create_time) AS `currentDay`,
HOUR(thdv.create_time) AS `hour`,
thdv.val,
thdv.val,thdv.unit,
thdv.is_warn
FROM
tb_pro_bd tpd