diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/controller/OilStatisticsController.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/controller/OilStatisticsController.java index 63e4d53..0050a1b 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/controller/OilStatisticsController.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/controller/OilStatisticsController.java @@ -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 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> 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 page = PageHelper.startPage(pageNum, pageSize); + List> 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> result = oilThDeviceService.selectDeptAvgByMonth(deptId, month); + return getDataTable(result); + } + + @GetMapping("/reportCenter") + public AjaxResult reportCenter(Long deptId, String month) { + List> resultCurrMonth = oilThDeviceService.selectAllAvgByMonth(deptId, month); + // 根据month获取上个月 字符串 month: 2024-09 -> lastMonth: 2024-08;1月份的上个月是12月份 + List> resultLastMonth = oilThDeviceService.selectAllAvgByMonth(deptId, getLastMonth(month)); + // 月度报表中的数据 + List> result = oilThDeviceService.selectDeptAvgByMonth(deptId, month); + // 将所有的数据放入一个map中 + Map 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); + } } diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/mapper/ThDeviceReportMapper.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/mapper/ThDeviceReportMapper.java index 7172dd4..258c0dd 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/mapper/ThDeviceReportMapper.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/mapper/ThDeviceReportMapper.java @@ -19,6 +19,37 @@ public interface ThDeviceReportMapper { */ List selectDeviceReport(ThDeviceReport thDeviceReport); + /** + * 按月度统计ds的平均值 + * + * @param deptId 部门ID + * @param startMonth 开始月份 + * @param endMonth 结束月份 + * @return 按月度统计的ds平均值 + */ @MapKey("report_month") List> 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> selectDeviceAvgByMonth(@Param("deptId") Long deptId, @Param("startMonth") String startMonth, @Param("endMonth") String endMonth); + + /** + * 按月度统计ds的平均值 + */ + @MapKey("dept_name") + List> selectDeptAvgByMonth(@Param("deptId") Long deptId, @Param("month") String month); + + /** + * 按月度统计ds, gbz ,dbz的平均值 + */ + @MapKey("month") + List> selectAllAvgByMonth(@Param("deptId") Long deptId, @Param("month") String month); } diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/IOilThDeviceService.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/IOilThDeviceService.java index f4ba1a5..817ca1c 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/IOilThDeviceService.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/IOilThDeviceService.java @@ -17,12 +17,43 @@ public interface IOilThDeviceService { * 根据thDeviceReport查询设备列表 */ List selectDeviceReport(ThDeviceReport thDeviceReport); + + /** * 按月度统计ds的平均值 - * @param deptId 部门ID + * + * @param deptId 部门ID * @param startMonth 开始月份 - * @param endMonth 结束月份 + * @param endMonth 结束月份 * @return 按月度统计的ds平均值 */ List> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth); + + /** + * 按月度统计device的平均值 + * + * @param deptId 部门ID + * @param startMonth 开始月份 + * @param endMonth 结束月份 + * @return 按月度统计的device平均值 + */ + List> selectDeviceAvgByMonth(Long deptId, String startMonth, String endMonth); + + /** + * 按月度统计ds, gbz ,dbz的平均值 + * + * @param deptId 部门ID + * @param month 月份 + * @return 按月度统计的ds平均值 + */ + List> selectDeptAvgByMonth(Long deptId, String month); + + /** + * 按月度统计ds, gbz ,dbz的平均值 + * + * @param deptId 部门ID + * @param month 月份 + * @return 按月度统计的ds平均值 + */ + List> selectAllAvgByMonth(Long deptId, String month); } diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/OilThDeviceServiceImpl.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/OilThDeviceServiceImpl.java index ef9a226..d7f16cb 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/OilThDeviceServiceImpl.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/oil/service/impl/OilThDeviceServiceImpl.java @@ -31,6 +31,7 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService { public List selectDeviceReport(ThDeviceReport thDeviceReport) { return thDeviceReportMapper.selectDeviceReport(thDeviceReport); } + @Override public List> selectAvgDsByMonth(Long deptId, String startMonth, String endMonth) { List> result = new ArrayList<>(); @@ -45,4 +46,49 @@ public class OilThDeviceServiceImpl implements IOilThDeviceService { return result; } + + @Override + public List> selectDeviceAvgByMonth(Long deptId, String startMonth, String endMonth) { + List> result = new ArrayList<>(); + List> list = thDeviceReportMapper.selectDeviceAvgByMonth(deptId, startMonth, endMonth); + for (Map map : list) { + Map lowerCaseMap = new HashMap<>(); + for (String key : map.keySet()) { + lowerCaseMap.put(key.toLowerCase(), map.get(key)); + } + result.add(lowerCaseMap); + } + + return result; + } + + @Override + public List> selectDeptAvgByMonth(Long deptId, String month) { + List> result = new ArrayList<>(); + List> list = thDeviceReportMapper.selectDeptAvgByMonth(deptId, month); + for (Map map : list) { + Map lowerCaseMap = new HashMap<>(); + for (String key : map.keySet()) { + lowerCaseMap.put(key.toLowerCase(), map.get(key)); + } + result.add(lowerCaseMap); + } + + return result; + } + + @Override + public List> selectAllAvgByMonth(Long deptId, String month) { + List> result = new ArrayList<>(); + List> list = thDeviceReportMapper.selectAllAvgByMonth(deptId, month); + for (Map map : list) { + Map lowerCaseMap = new HashMap<>(); + for (String key : map.keySet()) { + lowerCaseMap.put(key.toLowerCase(), map.get(key)); + } + result.add(lowerCaseMap); + } + + return result; + } } diff --git a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMapper.xml b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMapper.xml index 0ef6b16..39fde94 100644 --- a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMapper.xml +++ b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMapper.xml @@ -3,46 +3,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - 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 + + + + + + +