代码添加
This commit is contained in:
parent
3c5fff108c
commit
08d70afa99
|
@ -1,7 +1,11 @@
|
|||
package com.ruoyi.project.oil.controller;
|
||||
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.AjaxResult;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.oil.domain.monitor.ThDevice;
|
||||
import com.ruoyi.project.oil.domain.monitor.ThDeviceReport;
|
||||
|
@ -12,7 +16,12 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/statistics")
|
||||
|
@ -36,9 +45,54 @@ public class OilStatisticsController extends BaseController {
|
|||
List<ThDeviceReport> thDeviceReportList = oilThDeviceService.selectDeviceReport(thDeviceReport);
|
||||
return getDataTable(thDeviceReportList);
|
||||
}
|
||||
|
||||
@GetMapping("/getAvgDsByMonth")
|
||||
public TableDataInfo getAvgDsByMonth(Long deptId, String startMonth, String endMonth) {
|
||||
List result = oilThDeviceService.selectAvgDsByMonth(deptId, startMonth, endMonth);
|
||||
List<Map<String, Object>> result = oilThDeviceService.selectAvgDsByMonth(deptId, startMonth, endMonth);
|
||||
return getDataTable(result);
|
||||
}
|
||||
|
||||
@GetMapping("/getDeviceAvgByMonth")
|
||||
public TableDataInfo getDeviceAvgByMonth(Long deptId, String startMonth, String endMonth, int pageNum, int pageSize) {
|
||||
|
||||
Page<Object> page = PageHelper.startPage(pageNum, pageSize);
|
||||
List<Map<String, Object>> result = oilThDeviceService.selectDeviceAvgByMonth(deptId, startMonth, endMonth);
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setRows(result);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setTotal(page.getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
@GetMapping("/getDeptAvgByMonth")
|
||||
public TableDataInfo getDeptAvgByMonth(Long deptId, String month) {
|
||||
List<Map<String, Object>> result = oilThDeviceService.selectDeptAvgByMonth(deptId, month);
|
||||
return getDataTable(result);
|
||||
}
|
||||
|
||||
@GetMapping("/reportCenter")
|
||||
public AjaxResult reportCenter(Long deptId, String month) {
|
||||
List<Map<String, Object>> resultCurrMonth = oilThDeviceService.selectAllAvgByMonth(deptId, month);
|
||||
// 根据month获取上个月 字符串 month: 2024-09 -> lastMonth: 2024-08;1月份的上个月是12月份
|
||||
List<Map<String, Object>> resultLastMonth = oilThDeviceService.selectAllAvgByMonth(deptId, getLastMonth(month));
|
||||
// 月度报表中的数据
|
||||
List<Map<String, Object>> result = oilThDeviceService.selectDeptAvgByMonth(deptId, month);
|
||||
// 将所有的数据放入一个map中
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("currMonth", resultCurrMonth);
|
||||
resultMap.put("lastMonth", resultLastMonth);
|
||||
resultMap.put("deptAvg", result);
|
||||
return success(resultMap);
|
||||
}
|
||||
|
||||
public static String getLastMonth(String month) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
if (month.length() == 6) {
|
||||
month = month.substring(0, 5) + "0" + month.substring(5);
|
||||
}
|
||||
LocalDate date = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
LocalDate lastMonthDate = date.minus(1, ChronoUnit.MONTHS);
|
||||
return lastMonthDate.format(formatter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,37 @@ public interface ThDeviceReportMapper {
|
|||
*/
|
||||
List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport);
|
||||
|
||||
/**
|
||||
* 按月度统计ds的平均值
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param startMonth 开始月份
|
||||
* @param endMonth 结束月份
|
||||
* @return 按月度统计的ds平均值
|
||||
*/
|
||||
@MapKey("report_month")
|
||||
List<Map<String, Object>> selectAvgDsByMonth(@Param("deptId") Long deptId, @Param("startMonth") String startMonth, @Param("endMonth") String endMonth);
|
||||
|
||||
/**
|
||||
* 按月度统计device的平均值
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param startMonth 开始月份
|
||||
* @param endMonth 结束月份
|
||||
* @return 按月度统计的device平均值
|
||||
*/
|
||||
@MapKey("sn")
|
||||
List<Map<String, Object>> selectDeviceAvgByMonth(@Param("deptId") Long deptId, @Param("startMonth") String startMonth, @Param("endMonth") String endMonth);
|
||||
|
||||
/**
|
||||
* 按月度统计ds的平均值
|
||||
*/
|
||||
@MapKey("dept_name")
|
||||
List<Map<String, Object>> selectDeptAvgByMonth(@Param("deptId") Long deptId, @Param("month") String month);
|
||||
|
||||
/**
|
||||
* 按月度统计ds, gbz ,dbz的平均值
|
||||
*/
|
||||
@MapKey("month")
|
||||
List<Map<String, Object>> selectAllAvgByMonth(@Param("deptId") Long deptId, @Param("month") String month);
|
||||
}
|
||||
|
|
|
@ -17,12 +17,43 @@ public interface IOilThDeviceService {
|
|||
* 根据thDeviceReport查询设备列表
|
||||
*/
|
||||
List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport);
|
||||
|
||||
|
||||
/**
|
||||
* 按月度统计ds的平均值
|
||||
* @param deptId 部门ID
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param startMonth 开始月份
|
||||
* @param endMonth 结束月份
|
||||
* @param endMonth 结束月份
|
||||
* @return 按月度统计的ds平均值
|
||||
*/
|
||||
List<Map<String, Object>> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth);
|
||||
|
||||
/**
|
||||
* 按月度统计device的平均值
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param startMonth 开始月份
|
||||
* @param endMonth 结束月份
|
||||
* @return 按月度统计的device平均值
|
||||
*/
|
||||
List<Map<String, Object>> selectDeviceAvgByMonth(Long deptId, String startMonth, String endMonth);
|
||||
|
||||
/**
|
||||
* 按月度统计ds, gbz ,dbz的平均值
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param month 月份
|
||||
* @return 按月度统计的ds平均值
|
||||
*/
|
||||
List<Map<String, Object>> selectDeptAvgByMonth(Long deptId, String month);
|
||||
|
||||
/**
|
||||
* 按月度统计ds, gbz ,dbz的平均值
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param month 月份
|
||||
* @return 按月度统计的ds平均值
|
||||
*/
|
||||
List<Map<String, Object>> selectAllAvgByMonth(Long deptId, String month);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService {
|
|||
public List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport) {
|
||||
return thDeviceReportMapper.selectDeviceReport(thDeviceReport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
@ -45,4 +46,49 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectDeviceAvgByMonth(Long deptId, String startMonth, String endMonth) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
List<Map<String, Object>> list = thDeviceReportMapper.selectDeviceAvgByMonth(deptId, startMonth, endMonth);
|
||||
for (Map<String, Object> map : list) {
|
||||
Map<String, Object> lowerCaseMap = new HashMap<>();
|
||||
for (String key : map.keySet()) {
|
||||
lowerCaseMap.put(key.toLowerCase(), map.get(key));
|
||||
}
|
||||
result.add(lowerCaseMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectDeptAvgByMonth(Long deptId, String month) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
List<Map<String, Object>> list = thDeviceReportMapper.selectDeptAvgByMonth(deptId, month);
|
||||
for (Map<String, Object> map : list) {
|
||||
Map<String, Object> lowerCaseMap = new HashMap<>();
|
||||
for (String key : map.keySet()) {
|
||||
lowerCaseMap.put(key.toLowerCase(), map.get(key));
|
||||
}
|
||||
result.add(lowerCaseMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectAllAvgByMonth(Long deptId, String month) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
List<Map<String, Object>> list = thDeviceReportMapper.selectAllAvgByMonth(deptId, month);
|
||||
for (Map<String, Object> map : list) {
|
||||
Map<String, Object> lowerCaseMap = new HashMap<>();
|
||||
for (String key : map.keySet()) {
|
||||
lowerCaseMap.put(key.toLowerCase(), map.get(key));
|
||||
}
|
||||
result.add(lowerCaseMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,46 +3,45 @@
|
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.project.oil.mapper.ThDeviceReportMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ruoyi.project.oil.domain.monitor.ThDeviceReport">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="sn" column="sn" jdbcType="VARCHAR"/>
|
||||
<result property="reportTime" column="report_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="reportContent" column="report_content" jdbcType="OTHER"/>
|
||||
<result property="power" column="power" jdbcType="VARCHAR"/>
|
||||
<result property="sos" column="sos" jdbcType="VARCHAR"/>
|
||||
<result property="qb" column="qb" jdbcType="VARCHAR"/>
|
||||
<result property="wd" column="wd" jdbcType="VARCHAR"/>
|
||||
<result property="sd" column="sd" jdbcType="VARCHAR"/>
|
||||
<result property="yl" column="yl" jdbcType="VARCHAR"/>
|
||||
<result property="latitude" column="latitude" jdbcType="VARCHAR"/>
|
||||
<result property="longitude" column="longitude" jdbcType="VARCHAR"/>
|
||||
<result property="cgq" column="cgq" jdbcType="INTEGER"/>
|
||||
<result property="source" column="source" jdbcType="VARCHAR"/>
|
||||
<result property="ds" column="ds" jdbcType="VARCHAR"/>
|
||||
<result property="dbz" column="dbz" jdbcType="VARCHAR"/>
|
||||
<result property="gbz" column="gbz" jdbcType="VARCHAR"/>
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="sn" column="sn" jdbcType="VARCHAR"/>
|
||||
<result property="reportTime" column="report_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="reportContent" column="report_content" jdbcType="OTHER"/>
|
||||
<result property="power" column="power" jdbcType="VARCHAR"/>
|
||||
<result property="sos" column="sos" jdbcType="VARCHAR"/>
|
||||
<result property="qb" column="qb" jdbcType="VARCHAR"/>
|
||||
<result property="wd" column="wd" jdbcType="VARCHAR"/>
|
||||
<result property="sd" column="sd" jdbcType="VARCHAR"/>
|
||||
<result property="yl" column="yl" jdbcType="VARCHAR"/>
|
||||
<result property="latitude" column="latitude" jdbcType="VARCHAR"/>
|
||||
<result property="longitude" column="longitude" jdbcType="VARCHAR"/>
|
||||
<result property="cgq" column="cgq" jdbcType="INTEGER"/>
|
||||
<result property="source" column="source" jdbcType="VARCHAR"/>
|
||||
<result property="ds" column="ds" jdbcType="VARCHAR"/>
|
||||
<result property="dbz" column="dbz" jdbcType="VARCHAR"/>
|
||||
<result property="gbz" column="gbz" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
SELECT d.id,
|
||||
d.sn,
|
||||
d.report_time,
|
||||
d.report_content,
|
||||
d.power,
|
||||
d.sos,
|
||||
d.qb,
|
||||
d.wd,
|
||||
d.sd,
|
||||
d.yl,
|
||||
d.latitude,
|
||||
d.longitude,
|
||||
d.cgq,
|
||||
d.source,
|
||||
d.ds,
|
||||
d.dbz,
|
||||
d.gbz
|
||||
FROM th_device_report d
|
||||
SELECT d.id,
|
||||
d.sn,
|
||||
d.report_time,
|
||||
d.report_content,
|
||||
d.power,
|
||||
d.sos,
|
||||
d.qb,
|
||||
d.wd,
|
||||
d.sd,
|
||||
d.yl,
|
||||
d.latitude,
|
||||
d.longitude,
|
||||
d.cgq,
|
||||
d.source,
|
||||
d.ds,
|
||||
d.dbz,
|
||||
d.gbz
|
||||
FROM th_device_report d
|
||||
</sql>
|
||||
<select id="selectDeviceReport" parameterType="com.ruoyi.project.oil.domain.monitor.ThDeviceReport" resultMap="BaseResultMap">
|
||||
<include refid="Base_Column_List"/>
|
||||
|
@ -58,10 +57,11 @@
|
|||
</if>
|
||||
ORDER BY d.report_time ASC
|
||||
</select>
|
||||
|
||||
<select id="selectAvgDsByMonth" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
AVG(TO_NUMBER(d.ds)) AS avg_ds
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
|
||||
FROM
|
||||
th_device_report d
|
||||
WHERE
|
||||
|
@ -86,4 +86,69 @@
|
|||
ORDER BY
|
||||
month
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT d.sn,
|
||||
td.name,
|
||||
td.address,
|
||||
td.longitude,
|
||||
td.latitude,
|
||||
p.dept_name,
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds,
|
||||
ROUND(AVG(TO_NUMBER(d.dbz)), 8) AS avg_dbz,
|
||||
ROUND(AVG(TO_NUMBER(d.gbz)), 8) AS avg_gbz
|
||||
FROM th_device_report d
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||
WHERE td.dept_id IN (SELECT dept_id
|
||||
FROM sys_dept
|
||||
START WITH dept_id = #{deptId}
|
||||
CONNECT BY PRIOR dept_id = parent_id)
|
||||
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||
GROUP BY d.sn, p.dept_name, td.name, td.address, td.longitude, td.latitude
|
||||
ORDER BY p.dept_name
|
||||
</select>
|
||||
|
||||
<select id="selectDeptAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT p.dept_name,
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds,
|
||||
ROUND(AVG(TO_NUMBER(d.dbz)), 8) AS avg_dbz,
|
||||
ROUND(AVG(TO_NUMBER(d.gbz)), 8) AS avg_gbz
|
||||
FROM th_device_report d
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept START WITH dept_id = #{deptId} CONNECT BY PRIOR dept_id = parent_id)
|
||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||
GROUP BY p.dept_name
|
||||
ORDER BY p.dept_name
|
||||
</select>
|
||||
|
||||
<select id="selectAllAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds,
|
||||
ROUND(AVG(TO_NUMBER(d.dbz)), 8) AS avg_dbz,
|
||||
ROUND(AVG(TO_NUMBER(d.gbz)), 8) AS avg_gbz
|
||||
FROM
|
||||
th_device_report d
|
||||
WHERE
|
||||
d.sn IN (
|
||||
SELECT
|
||||
td.sn
|
||||
FROM
|
||||
th_device td
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||
WHERE
|
||||
td.dept_id IN (
|
||||
SELECT dept_id
|
||||
FROM sys_dept
|
||||
START WITH dept_id = #{deptId}
|
||||
CONNECT BY PRIOR dept_id = parent_id
|
||||
)
|
||||
)
|
||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||
GROUP BY
|
||||
TO_CHAR(d.report_time, 'YYYY-MM')
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue