修改部分 bug

This commit is contained in:
gongjiale 2025-02-18 17:33:37 +08:00
parent 84b24e8f0a
commit fcf644323f
6 changed files with 62 additions and 23 deletions

View File

@ -26,9 +26,14 @@ public class ThDeviceReportMonthServiceImpl implements ThDeviceReportMonthServic
@Override
public List<Map<String, Object>> selectThDeviceReportMonthList(Long deptId, String year, String month) {
return camelCaseMapListKey(thDeviceReportMonthMapper.selectThDeviceReportMonthList(deptId, year, month));
String month1=formatMonth(Integer.parseInt(month));
return camelCaseMapListKey(thDeviceReportMonthMapper.selectThDeviceReportMonthList(deptId, year, month1));
}
// 格式化月份确保是两位数
public static String formatMonth(int month) {
return String.format("%02d", month);
}
@Override
public int updateThDeviceReportMonth(ThDeviceReportMonth thDeviceReportMonth) {
return thDeviceReportMonthMapper.updateThDeviceReportMonth(thDeviceReportMonth);

View File

@ -7,6 +7,10 @@ import com.ruoyi.project.outside.service.OutSideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/outside")
public class OutSideController extends BaseController {
@ -46,17 +50,28 @@ public class OutSideController extends BaseController {
}
}
// @GetMapping("/updateData")
// public AjaxResult updateData(@RequestBody String date) {
// try {
// Integer succ=outSideService.updateData(date);
// return AjaxResult.success(succ);
// } catch (Exception e) {
// System.out.println(e);
// return AjaxResult.error();
// }
//
// }
@GetMapping("/updateData")
public AjaxResult updateData(@RequestBody String date) {
try {
Integer succ=outSideService.updateData(date);
return AjaxResult.success(succ);
} catch (Exception e) {
System.out.println(e);
return AjaxResult.error();
}
}
@GetMapping("/getMonthData")
public AjaxResult getMonthData(@RequestBody String date) {
try {
List<Map<String, Object>> alarmCount = outSideService.getMonthData(date);
return AjaxResult.success(alarmCount);
} catch (Exception e) {
System.out.println(e);
return AjaxResult.error();
}
}
}

View File

@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface OutSideMapper {
/**
@ -35,4 +36,6 @@ public interface OutSideMapper {
void deleteSampleDevice(@Param("sn")String sn,@Param("reportTime") String reportTime);
Integer updateData(@Param("date") String date);
List<Map<String, Object>> getMonthData(@Param("date") String date);
}

View File

@ -2,6 +2,9 @@ package com.ruoyi.project.outside.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import java.util.Map;
public interface OutSideService {
/**
@ -26,4 +29,6 @@ public interface OutSideService {
Integer insertOldDeviceData(String data) throws JsonProcessingException;
Integer updateData(String date);
List<Map<String, Object>> getMonthData(String date);
}

View File

@ -18,6 +18,7 @@ import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
@Service
@ -112,6 +113,11 @@ public class OutSideServiceImpl implements OutSideService {
return outSideMapper.updateData(date);
}
@Override
public List<Map<String, Object>> getMonthData(String date) {
return outSideMapper.getMonthData(date);
}
private static SensorData insertOldData(JsonNode node) {
/**
* sn: equipmentUId

View File

@ -39,21 +39,20 @@
<select id="queryMonth" resultMap="SensorMonthResultMap">
SELECT
r.SN,
AVG(DS) AS "avg_value",
t.SN,
COALESCE(AVG(r.DS), 0) AS "avg_value", -- 如果没有数据,返回 0
dept.dept_id,
TO_CHAR(r.REPORT_TIME, 'YYYY') AS year,
TO_CHAR(r.REPORT_TIME, 'MM') AS month
TO_CHAR(TO_DATE(#{lastMonth}, 'YYYY-MM'), 'YYYY') AS year,
TO_CHAR(TO_DATE(#{lastMonth}, 'YYYY-MM'), 'MM') AS month
FROM
th_device_report r JOIN th_device t on r.sn=t.sn join sys_dept dept on t.dept_id=dept.dept_id
WHERE
TO_CHAR(r.REPORT_TIME, 'YYYY-MM') = #{lastMonth}
th_device t
LEFT JOIN th_device_report r ON t.sn = r.sn AND TO_CHAR(r.REPORT_TIME, 'YYYY-MM') = #{lastMonth}
LEFT JOIN sys_dept dept ON t.dept_id = dept.dept_id
GROUP BY
r.SN,
t.SN,
dept.dept_id,
TO_CHAR(r.REPORT_TIME, 'YYYY'),
TO_CHAR(r.REPORT_TIME, 'MM')
TO_CHAR(TO_DATE(#{lastMonth}, 'YYYY-MM'), 'YYYY'),
TO_CHAR(TO_DATE(#{lastMonth}, 'YYYY-MM'), 'MM')
</select>
<insert id="insertMonth">
@ -72,4 +71,10 @@
<update id="updateData">
${date}
</update>
<select id="getMonthData" resultType="java.util.Map">
select * from th_device_report_month1
WHERE
TO_CHAR(REPORT_TIME, 'YYYY-MM') = #{date}
</select>
</mapper>