parent
f46d7356b4
commit
6fc9618152
|
|
@ -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("请求出错了");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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("请求出错了");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<SjEnergyReduction> selectEnergyReduction(SjEnergyReduction o);
|
||||||
|
}
|
||||||
|
|
@ -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<SjMaxDevice> selectDeviceEcharts(SjMaxDevice o);
|
||||||
|
|
||||||
|
List<SjMaxDevice> selectWorkerEcharts(SjMaxDevice o);
|
||||||
|
|
||||||
|
List<SjMaxDevice> selectEfficiency(SjMaxDevice o);
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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<SjEnergyReduction> list = mapper.selectEnergyReduction(o);
|
||||||
|
Map<String, List<SjEnergyReduction>> groupedByProTypeEcharts = list.stream()
|
||||||
|
.collect(Collectors.groupingBy(SjEnergyReduction::getType));
|
||||||
|
|
||||||
|
//整体人员利用率和设备使用率
|
||||||
|
// 先过滤出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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<String, Object> result = new HashMap<>();
|
||||||
|
//设备的图
|
||||||
|
List<SjMaxDevice> 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<SjMaxDevice> 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<SjMaxDevice> efficiencyList = mapper.selectEfficiency(o);
|
||||||
|
result.put("efficiency", efficiencyList);
|
||||||
|
return AjaxResult.success("查询成功",result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ SELECT
|
||||||
ON date_list.dt = a_summary.dt
|
ON date_list.dt = a_summary.dt
|
||||||
AND p_summary.pro_type = a_summary.pro_type
|
AND p_summary.pro_type = a_summary.pro_type
|
||||||
WHERE date_list.dt BETWEEN #{startTime} AND #{endTime}
|
WHERE date_list.dt BETWEEN #{startTime} AND #{endTime}
|
||||||
ORDER BY date_list.dt, pro_type;
|
ORDER BY date_list.dt, pro_type
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getProgressWithPercent" resultMap="BaseResultMap">
|
<select id="getProgressWithPercent" resultMap="BaseResultMap">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.securitycontrol.screen.mapper.SjEnergyReductionMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.securitycontrol.screen.domain.SjEnergyReduction">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
<!--@Table sj_energy_reduction-->
|
||||||
|
<id column="id" jdbcType="BIGINT" property="id" />
|
||||||
|
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||||
|
<result column="create_time" jdbcType="DATE" property="createTime" />
|
||||||
|
<result column="data_num" jdbcType="VARCHAR" property="dataNum" />
|
||||||
|
<result column="date" property="date"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
id, `type`, create_time, data_num
|
||||||
|
</sql>
|
||||||
|
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from sj_energy_reduction
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</select>
|
||||||
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
delete from sj_energy_reduction
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</delete>
|
||||||
|
<insert id="insert" parameterType="com.securitycontrol.screen.domain.SjEnergyReduction">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
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>
|
||||||
|
<insert id="insertSelective" parameterType="com.securitycontrol.screen.domain.SjEnergyReduction">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
insert into sj_energy_reduction
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="id != null">
|
||||||
|
id,
|
||||||
|
</if>
|
||||||
|
<if test="type != null">
|
||||||
|
`type`,
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
create_time,
|
||||||
|
</if>
|
||||||
|
<if test="dataNum != null">
|
||||||
|
data_num,
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="id != null">
|
||||||
|
#{id,jdbcType=BIGINT},
|
||||||
|
</if>
|
||||||
|
<if test="type != null">
|
||||||
|
#{type,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
#{createTime,jdbcType=DATE},
|
||||||
|
</if>
|
||||||
|
<if test="dataNum != null">
|
||||||
|
#{dataNum,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
<update id="updateByPrimaryKeySelective" parameterType="com.securitycontrol.screen.domain.SjEnergyReduction">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
update sj_energy_reduction
|
||||||
|
<set>
|
||||||
|
<if test="type != null">
|
||||||
|
`type` = #{type,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
create_time = #{createTime,jdbcType=DATE},
|
||||||
|
</if>
|
||||||
|
<if test="dataNum != null">
|
||||||
|
data_num = #{dataNum,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</update>
|
||||||
|
<update id="updateByPrimaryKey" parameterType="com.securitycontrol.screen.domain.SjEnergyReduction">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
update sj_energy_reduction
|
||||||
|
set `type` = #{type,jdbcType=VARCHAR},
|
||||||
|
create_time = #{createTime,jdbcType=DATE},
|
||||||
|
data_num = #{dataNum,jdbcType=VARCHAR}
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="selectEnergyReduction" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
t.type,
|
||||||
|
date_list.dt AS date,
|
||||||
|
COALESCE(e.data_num, '0') AS data_num
|
||||||
|
FROM
|
||||||
|
-- 所有类型
|
||||||
|
(SELECT DISTINCT type FROM sj_energy_reduction WHERE type IS NOT NULL) t
|
||||||
|
CROSS JOIN
|
||||||
|
-- 生成日期序列
|
||||||
|
( #{sql} ) AS date_list
|
||||||
|
LEFT JOIN sj_energy_reduction e
|
||||||
|
ON t.type = e.type
|
||||||
|
AND date_list.dt = e.create_time
|
||||||
|
WHERE date_list.dt BETWEEN #{startTime} AND #{endTime}
|
||||||
|
ORDER BY t.type, date_list.dt
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.securitycontrol.screen.mapper.SjMaxDeviceMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.securitycontrol.screen.domain.SjMaxDevice">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
<!--@Table sj_max_device-->
|
||||||
|
<id column="id" jdbcType="BIGINT" property="id" />
|
||||||
|
<result column="dev_name" jdbcType="VARCHAR" property="devName" />
|
||||||
|
<result column="in_time" jdbcType="DATE" property="inTime" />
|
||||||
|
<result column="out_time" jdbcType="DATE" property="outTime" />
|
||||||
|
<result column="used_day" jdbcType="VARCHAR" property="usedDay" />
|
||||||
|
<result column="ein_day" property="einDay"/>
|
||||||
|
<result column="actual_count" property="actualCount"/>
|
||||||
|
<result column="date" property="date"/>
|
||||||
|
<result column="should_count" property="shouldCount"/>
|
||||||
|
<result column="team_leader" property="teamLeader"/>
|
||||||
|
<result column="team_name" property="teamName"/>
|
||||||
|
<result column="total_people" property="totalPeople"/>
|
||||||
|
<result column="utilization_rate" property="utilizationRate"/>
|
||||||
|
<result column="work_type" property="workType"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
id, dev_name, in_time, out_time, used_day
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectDeviceEcharts" resultMap="BaseResultMap">
|
||||||
|
SELECT dev_name,
|
||||||
|
-- 入场天数:如果未出场,则算到今天
|
||||||
|
sum(DATEDIFF(IF(out_time IS NOT NULL AND out_time < CURDATE(), out_time, CURDATE()), in_time) +
|
||||||
|
1) AS ein_day,
|
||||||
|
sum(used_day) AS used_day
|
||||||
|
FROM sj_max_device
|
||||||
|
WHERE
|
||||||
|
-- 确保有入场时间
|
||||||
|
in_time IS NOT NULL
|
||||||
|
-- 入场时间不能在未来
|
||||||
|
AND in_time <= CURDATE()
|
||||||
|
GROUP BY dev_name
|
||||||
|
ORDER BY ein_day DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectWorkerEcharts" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
date_list.dt AS date,
|
||||||
|
COALESCE(should.should_count, 0) AS should_count,
|
||||||
|
COALESCE(actual.actual_count, 0) AS actual_count
|
||||||
|
FROM (
|
||||||
|
#{sql}
|
||||||
|
) AS date_list
|
||||||
|
-- 应到人数:每天 = 班组总人数(固定)
|
||||||
|
CROSS JOIN (
|
||||||
|
SELECT
|
||||||
|
COUNT(*) AS should_count
|
||||||
|
FROM sj_team_people
|
||||||
|
WHERE team_id IS NOT NULL -- 可按 team_id 过滤
|
||||||
|
) AS should -- 每天都显示相同人数
|
||||||
|
-- 实到人数:按天统计 on_time 在当天的人数
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
DATE(o.on_time) AS duty_date,
|
||||||
|
COUNT(DISTINCT o.people_id) AS actual_count
|
||||||
|
FROM sj_on_duty o
|
||||||
|
WHERE o.on_time IS NOT NULL
|
||||||
|
AND DATE(o.on_time) BETWEEN #{startTime} AND #{endTime}
|
||||||
|
GROUP BY DATE(o.on_time)
|
||||||
|
) AS actual ON date_list.dt = actual.duty_date
|
||||||
|
ORDER BY date_list.dt
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectEfficiency" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
wt.work_type,
|
||||||
|
wt.team_name,
|
||||||
|
wt.team_leader,
|
||||||
|
tp_count.total_people,
|
||||||
|
ROUND(
|
||||||
|
COALESCE(SUM(actual.actual_count), 0) * 100.0 /
|
||||||
|
((DATEDIFF(#{startTime} , #{endTime}) + 1) * tp_count.total_people),
|
||||||
|
2
|
||||||
|
) AS utilization_rate -- 百分比形式(如 86.70)
|
||||||
|
FROM sj_work_team wt
|
||||||
|
INNER JOIN (
|
||||||
|
-- 每个班组的总人数
|
||||||
|
SELECT
|
||||||
|
team_id,
|
||||||
|
COUNT(*) AS total_people
|
||||||
|
FROM sj_team_people
|
||||||
|
WHERE team_id IS NOT NULL
|
||||||
|
GROUP BY team_id
|
||||||
|
) tp_count ON wt.id = tp_count.team_id
|
||||||
|
CROSS JOIN (
|
||||||
|
#{sql}
|
||||||
|
) AS date_list
|
||||||
|
-- 关联每天实到人数
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
o.team_id,
|
||||||
|
DATE(o.on_time) AS duty_date,
|
||||||
|
COUNT(DISTINCT o.people_id) AS actual_count
|
||||||
|
FROM sj_on_duty o
|
||||||
|
WHERE o.on_time IS NOT NULL
|
||||||
|
AND DATE(o.on_time) BETWEEN #{startTime} AND #{endTime}
|
||||||
|
GROUP BY o.team_id, DATE(o.on_time)
|
||||||
|
) AS actual
|
||||||
|
ON wt.id = actual.team_id
|
||||||
|
AND date_list.dt = actual.duty_date
|
||||||
|
-- 参数:开始日期、结束日期(共 6 个 ?)
|
||||||
|
WHERE DATE_ADD(#{startTime}, INTERVAL 0 DAY) BETWEEN #{startTime} AND #{endTime} -- 确保日期范围有效(可选)
|
||||||
|
GROUP BY
|
||||||
|
wt.id, wt.team_name, wt.team_leader, tp_count.total_people
|
||||||
|
ORDER BY utilization_rate DESC
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue