diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjEnergyReductionController.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjEnergyReductionController.java new file mode 100644 index 0000000..eb04943 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjEnergyReductionController.java @@ -0,0 +1,47 @@ +package com.securitycontrol.screen.controller; +import com.securitycontrol.common.core.web.controller.BaseController; +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjEnergyReduction; +import com.securitycontrol.screen.domain.SjMaxDevice; +import com.securitycontrol.screen.service.SjEnergyReductionService; +import com.securitycontrol.screen.service.impl.SjEnergyReductionServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.Resource; + +/** +* 节能减排分析控制层 +* +* @author fly +*/ +@RestController +@RequestMapping("/energyReduction") +@Slf4j +public class SjEnergyReductionController extends BaseController { +/** +* 服务对象 +*/ + @Resource + private SjEnergyReductionService service; + + + /** + * 节能减排分析 + * + * @param o 传参 + * @return 查询工程质量验收项 + */ + @GetMapping("selectEnergyReduction") + public AjaxResult selectEnergyReduction(SjEnergyReduction o) { + try { + return service.selectEnergyReduction(o); + } catch (Exception e) { + log.error(e.toString(),e); + return error("请求出错了"); + } + } + +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjMaxDeviceController.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjMaxDeviceController.java new file mode 100644 index 0000000..8dae421 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/controller/SjMaxDeviceController.java @@ -0,0 +1,48 @@ +package com.securitycontrol.screen.controller; +import com.securitycontrol.common.core.web.controller.BaseController; +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjMaxDevice; +import com.securitycontrol.screen.domain.SjProjectQuality; +import com.securitycontrol.screen.service.SjMaxDeviceService; +import com.securitycontrol.screen.service.impl.SjMaxDeviceServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.Resource; + +/** +* 资源应用利率分析表-大型设备(sj_max_device)表控制层 +* +* @author xxxxx +*/ +@RestController +@RequestMapping("/resourceUtilization") +@Slf4j +public class SjMaxDeviceController extends BaseController { +/** +* 服务对象 +*/ + @Resource + private SjMaxDeviceService service; + + + /** + * 查询工程质量验收项 + * + * @param o 传参 + * @return 查询工程质量验收项 + */ + @GetMapping("selectDeviceEcharts") + public AjaxResult selectDeviceEcharts(SjMaxDevice o) { + try { + return service.selectDeviceEcharts(o); + } catch (Exception e) { + log.error(e.toString(),e); + return error("请求出错了"); + } + } + + +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjEnergyReduction.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjEnergyReduction.java new file mode 100644 index 0000000..63dea78 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjEnergyReduction.java @@ -0,0 +1,41 @@ +package com.securitycontrol.screen.domain; + +import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 节能减排分析表 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SjEnergyReduction { + /** + * 主键 + */ + private Long id; + + /** + * 类型 + */ + private String type; + + /** + * 日期 + */ + private String createTime; + + /** + * 数量 + */ + private Integer dataNum; + + private String startTime; + private String endTime; + + private String sql; + private String date; + +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjMaxDevice.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjMaxDevice.java new file mode 100644 index 0000000..44f4527 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/domain/SjMaxDevice.java @@ -0,0 +1,59 @@ +package com.securitycontrol.screen.domain; + +import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 资源应用利率分析表-大型设备 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SjMaxDevice { + /** + * 主键 + */ + private Long id; + + /** + * 设备名称 + */ + private String devName; + + /** + * 设备入场时间 + */ + private String inTime; + + /** + * 设备出场时间 + */ + private String outTime; + + /** + * 设备使用天数 + */ + private Integer usedDay; + private Integer einDay; + + + //人员到岗数据 + private String date; + private Integer shouldCount; + private Integer actualCount; + + + private String startTime; + private String endTime; + + private String sql; + + private String teamLeader; + private String totalPeople; + private String utilizationRate; + private String teamName; + private String workType; + +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjEnergyReductionMapper.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjEnergyReductionMapper.java new file mode 100644 index 0000000..75d232b --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjEnergyReductionMapper.java @@ -0,0 +1,13 @@ +package com.securitycontrol.screen.mapper; + +import com.securitycontrol.screen.domain.SjEnergyReduction; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SjEnergyReductionMapper { + + + List selectEnergyReduction(SjEnergyReduction o); +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjMaxDeviceMapper.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjMaxDeviceMapper.java new file mode 100644 index 0000000..99d8a33 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/mapper/SjMaxDeviceMapper.java @@ -0,0 +1,17 @@ +package com.securitycontrol.screen.mapper; + +import com.securitycontrol.screen.domain.SjMaxDevice; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SjMaxDeviceMapper { + + + List selectDeviceEcharts(SjMaxDevice o); + + List selectWorkerEcharts(SjMaxDevice o); + + List selectEfficiency(SjMaxDevice o); +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjEnergyReductionService.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjEnergyReductionService.java new file mode 100644 index 0000000..0dad352 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjEnergyReductionService.java @@ -0,0 +1,8 @@ +package com.securitycontrol.screen.service; + +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjEnergyReduction; +public interface SjEnergyReductionService{ + + AjaxResult selectEnergyReduction(SjEnergyReduction o); +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjMaxDeviceService.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjMaxDeviceService.java new file mode 100644 index 0000000..0b4dcbf --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/SjMaxDeviceService.java @@ -0,0 +1,9 @@ +package com.securitycontrol.screen.service; + +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjMaxDevice; +public interface SjMaxDeviceService{ + + + AjaxResult selectDeviceEcharts(SjMaxDevice o); +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjEnergyReductionServiceImpl.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjEnergyReductionServiceImpl.java new file mode 100644 index 0000000..bd11038 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjEnergyReductionServiceImpl.java @@ -0,0 +1,65 @@ +package com.securitycontrol.screen.service.impl; + +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjConstructionProgress; +import com.securitycontrol.screen.domain.SjMaxDevice; +import org.springframework.stereotype.Service; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.securitycontrol.screen.domain.SjEnergyReduction; +import com.securitycontrol.screen.mapper.SjEnergyReductionMapper; +import com.securitycontrol.screen.service.SjEnergyReductionService; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class SjEnergyReductionServiceImpl implements SjEnergyReductionService{ + + @Resource + private SjEnergyReductionMapper mapper; + + + @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 list = mapper.selectEnergyReduction(o); + Map> groupedByProTypeEcharts = list.stream() + .collect(Collectors.groupingBy(SjEnergyReduction::getType)); + + //整体人员利用率和设备使用率 + // 先过滤出type为'蓄水量'的数据 + List storageList = list.stream() + .filter(item -> "蓄水量".equals(item.getType())) + .collect(Collectors.toList()); + // 然后计算总和 + double totalWater = storageList.stream() + .mapToDouble(SjEnergyReduction::getDataNum) + .sum(); + List energyList = list.stream() + .filter(item -> "发电量".equals(item.getType())) + .collect(Collectors.toList()); + // 然后计算总和 + double totalEnergy = energyList.stream() + .mapToDouble(SjEnergyReduction::getDataNum) + .sum(); + Map result = new HashMap<>(); + result.put("echarts", groupedByProTypeEcharts); + result.put("waterUtilization", totalWater); + result.put("energyUtilization", totalEnergy); + return AjaxResult.success("查询成功",result); + } +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjMaxDeviceServiceImpl.java b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjMaxDeviceServiceImpl.java new file mode 100644 index 0000000..7e8be3e --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/java/com/securitycontrol/screen/service/impl/SjMaxDeviceServiceImpl.java @@ -0,0 +1,86 @@ +package com.securitycontrol.screen.service.impl; + +import com.securitycontrol.common.core.web.domain.AjaxResult; +import com.securitycontrol.screen.domain.SjConstructionProgress; +import org.springframework.stereotype.Service; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.securitycontrol.screen.domain.SjMaxDevice; +import com.securitycontrol.screen.mapper.SjMaxDeviceMapper; +import com.securitycontrol.screen.service.SjMaxDeviceService; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class SjMaxDeviceServiceImpl implements SjMaxDeviceService{ + + @Resource + private SjMaxDeviceMapper mapper; + + @Override + public AjaxResult selectDeviceEcharts(SjMaxDevice o) { + Map result = new HashMap<>(); + //设备的图 + List list = mapper.selectDeviceEcharts(o); + result.put("deviceEcharts", list); + //一周到岗率 + LocalDate endDate = LocalDate.now(); // 今天 + LocalDate startDate = endDate.minusDays(6); // 7天前 + String startTime = startDate.toString(); // 格式:yyyy-MM-dd + String endTime = endDate.toString(); + o.setStartTime(startTime); + o.setEndTime(endTime); + String sql = "SELECT DATE_ADD("+startTime+", 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("+startTime+", INTERVAL (ones.a + tens.a * 10) DAY) <= "+endTime; + o.setSql(sql); + List workerList = mapper.selectWorkerEcharts(o); + result.put("workerEcharts", workerList); + result.put("todayDutyRate", 0); + result.put("yesterdayDutyRate", 0); + if(workerList != null && !workerList.isEmpty()){ + result.put("todayDutyRate", workerList.get(workerList.size()-1).getActualCount()/workerList.get(workerList.size()-1).getShouldCount()*100); + if(workerList.size()>1){ + result.put("yesterdayDutyRate", workerList.get(workerList.size()-2).getActualCount()/workerList.get(workerList.size()-2).getShouldCount()*100); + } + } + //整体人员利用率和设备使用率 + double totalActualCount = list.stream() + .mapToDouble(SjMaxDevice::getActualCount) + .sum(); + double totalShouldCount = list.stream() + .mapToDouble(SjMaxDevice::getShouldCount) + .sum(); + double workerUtilization = 0; + if (totalShouldCount > 0) { + workerUtilization = (totalActualCount / totalShouldCount) * 100; + } + result.put("workerUtilization", workerUtilization); + double totalUsedDay = list.stream() + .mapToDouble(SjMaxDevice::getUsedDay) + .sum(); + double totalEinDay = list.stream() + .mapToDouble(SjMaxDevice::getEinDay) + .sum(); + double deviceUtilization = 0; + if (totalShouldCount > 0) { + deviceUtilization = (totalUsedDay / totalEinDay) * 100; + } + result.put("deviceUtilization", deviceUtilization); + //效率分析 + List efficiencyList = mapper.selectEfficiency(o); + result.put("efficiency", efficiencyList); + return AjaxResult.success("查询成功",result); + } +} diff --git a/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjConstructionProgressMapper.xml b/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjConstructionProgressMapper.xml index 25b0f00..c5cf558 100644 --- a/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjConstructionProgressMapper.xml +++ b/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjConstructionProgressMapper.xml @@ -95,7 +95,7 @@ SELECT ON date_list.dt = a_summary.dt AND p_summary.pro_type = a_summary.pro_type WHERE date_list.dt BETWEEN #{startTime} AND #{endTime} - ORDER BY date_list.dt, pro_type; + ORDER BY date_list.dt, pro_type + + select + + from sj_energy_reduction + where id = #{id,jdbcType=BIGINT} + + + + delete from sj_energy_reduction + where id = #{id,jdbcType=BIGINT} + + + + insert into sj_energy_reduction (id, `type`, create_time, + data_num) + values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createTime,jdbcType=DATE}, + #{dataNum,jdbcType=VARCHAR}) + + + + insert into sj_energy_reduction + + + id, + + + `type`, + + + create_time, + + + data_num, + + + + + #{id,jdbcType=BIGINT}, + + + #{type,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=DATE}, + + + #{dataNum,jdbcType=VARCHAR}, + + + + + + update sj_energy_reduction + + + `type` = #{type,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=DATE}, + + + data_num = #{dataNum,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + + update sj_energy_reduction + set `type` = #{type,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=DATE}, + data_num = #{dataNum,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + + + diff --git a/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjMaxDeviceMapper.xml b/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjMaxDeviceMapper.xml new file mode 100644 index 0000000..0618490 --- /dev/null +++ b/securitycontrol-model/securitycontrol-screen/src/main/resources/mapper/SjMaxDeviceMapper.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + id, dev_name, in_time, out_time, used_day + + + + + + + +