代码添加

This commit is contained in:
gongjiale 2024-09-03 22:41:34 +08:00
parent 3c5fff108c
commit 08d70afa99
5 changed files with 267 additions and 40 deletions

View File

@ -1,7 +1,11 @@
package com.ruoyi.project.oil.controller; 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.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.oil.domain.monitor.ThDevice; import com.ruoyi.project.oil.domain.monitor.ThDevice;
import com.ruoyi.project.oil.domain.monitor.ThDeviceReport; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; 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.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("/statistics") @RequestMapping("/statistics")
@ -36,9 +45,54 @@ public class OilStatisticsController extends BaseController {
List<ThDeviceReport> thDeviceReportList = oilThDeviceService.selectDeviceReport(thDeviceReport); List<ThDeviceReport> thDeviceReportList = oilThDeviceService.selectDeviceReport(thDeviceReport);
return getDataTable(thDeviceReportList); return getDataTable(thDeviceReportList);
} }
@GetMapping("/getAvgDsByMonth") @GetMapping("/getAvgDsByMonth")
public TableDataInfo getAvgDsByMonth(Long deptId, String startMonth, String endMonth) { 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); 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-081月份的上个月是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);
}
} }

View File

@ -19,6 +19,37 @@ public interface ThDeviceReportMapper {
*/ */
List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport); List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport);
/**
* 按月度统计ds的平均值
*
* @param deptId 部门ID
* @param startMonth 开始月份
* @param endMonth 结束月份
* @return 按月度统计的ds平均值
*/
@MapKey("report_month") @MapKey("report_month")
List<Map<String, Object>> selectAvgDsByMonth(@Param("deptId") Long deptId, @Param("startMonth") String startMonth, @Param("endMonth") String endMonth); 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);
} }

View File

@ -17,12 +17,43 @@ public interface IOilThDeviceService {
* 根据thDeviceReport查询设备列表 * 根据thDeviceReport查询设备列表
*/ */
List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport); List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport);
/** /**
* 按月度统计ds的平均值 * 按月度统计ds的平均值
*
* @param deptId 部门ID * @param deptId 部门ID
* @param startMonth 开始月份 * @param startMonth 开始月份
* @param endMonth 结束月份 * @param endMonth 结束月份
* @return 按月度统计的ds平均值 * @return 按月度统计的ds平均值
*/ */
List<Map<String, Object>> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth); 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);
} }

View File

@ -31,6 +31,7 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService {
public List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport) { public List<ThDeviceReport> selectDeviceReport(ThDeviceReport thDeviceReport) {
return thDeviceReportMapper.selectDeviceReport(thDeviceReport); return thDeviceReportMapper.selectDeviceReport(thDeviceReport);
} }
@Override @Override
public List<Map<String, Object>> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth) { public List<Map<String, Object>> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth) {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
@ -45,4 +46,49 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService {
return result; 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;
}
} }

View File

@ -3,7 +3,6 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.oil.mapper.ThDeviceReportMapper"> <mapper namespace="com.ruoyi.project.oil.mapper.ThDeviceReportMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.project.oil.domain.monitor.ThDeviceReport"> <resultMap id="BaseResultMap" type="com.ruoyi.project.oil.domain.monitor.ThDeviceReport">
<id property="id" column="id" jdbcType="BIGINT"/> <id property="id" column="id" jdbcType="BIGINT"/>
<result property="sn" column="sn" jdbcType="VARCHAR"/> <result property="sn" column="sn" jdbcType="VARCHAR"/>
@ -58,10 +57,11 @@
</if> </if>
ORDER BY d.report_time ASC ORDER BY d.report_time ASC
</select> </select>
<select id="selectAvgDsByMonth" parameterType="map" resultType="map"> <select id="selectAvgDsByMonth" parameterType="map" resultType="map">
SELECT SELECT
TO_CHAR(d.report_time, 'YYYY-MM') AS month, 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 FROM
th_device_report d th_device_report d
WHERE WHERE
@ -86,4 +86,69 @@
ORDER BY ORDER BY
month month
</select> </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 &gt;= TO_DATE(#{startMonth}, 'YYYY-MM')
AND d.report_time &lt;= 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> </mapper>