jinpengyong
2021-08-04 a740220c647a1bd4dd83f0751e5e1a73fb00226f
中间小时表update
6 files modified
59 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/WebController.java 8 ●●●● patch | view | raw | blame | history
screen-common/src/main/java/com/moral/constant/Constants.java 5 ●●●●● patch | view | raw | blame | history
screen-job/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml 2 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java 7 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java 21 ●●●● patch | view | raw | blame | history
screen-manage/src/main/resources/mapper/HistoryHourlyMapper.xml 16 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/WebController.java
@@ -114,7 +114,7 @@
    }
    /**
     * @param request 请求信息
     * @param params 请求信息
     * @return 返回请求成功后的对象信息
     */
    @PostMapping("getMacSensors")
@@ -132,16 +132,16 @@
    }
    /**
     * @param request 请求信息
     * @param params 请求信息
     * @return 返回请求成功后的对象信息
     */
    @PostMapping("getTrendChartData")
    @ApiOperation(value = "多设备单监测因子趋势图", notes = "多设备单监测因子趋势图.")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "macs", value = "设备mac,多个逗号隔开", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "macs", value = "设备mac,多个逗号隔开", required = true, paramType = "body", dataType = "list"),
            @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "数据类型,日(day),月(month),年(year)", required = true, paramType = "body", dataType = "List"),
            @ApiImplicitParam(name = "type", value = "数据类型,日(day),月(month),年(year)", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "times", value = "数据时间,日(2021-07-29),月(2021-07),年(2021),多个逗号隔开", required = true, paramType = "body", dataType = "List")
    })
    public ResultMessage getTrendChartData(@RequestBody Map<String,Object> params) {
screen-common/src/main/java/com/moral/constant/Constants.java
@@ -120,6 +120,11 @@
    public static final String UN_ADJUST = "unadjust";
    /*
     * 小时中间表后缀
     * */
    public static final String TRANSITION = "transition";
    /*
     * 离线设备状态码
     * */
    public static final String DEVICE_STATE_OFFLINE = "0";
screen-job/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
@@ -7,8 +7,6 @@
            `mac` VARCHAR (20) DEFAULT NULL COMMENT '设备mac',
            `time` datetime DEFAULT NULL COMMENT '数据时间',
            `value` json DEFAULT NULL COMMENT '数据',
            KEY `idx_mac` (`mac`),
            KEY `idx_time` (`time`),
            KEY `idx_mac_time` (`mac`,`time`)
            ) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT '5分钟数据表'
    </update>
screen-manage/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -18,11 +18,6 @@
 */
public interface HistoryHourlyMapper extends BaseMapper<HistoryHourly> {
    void insertHistoryHourlyUnAdjust(Map<String, Object> params);
    void insertHistoryHourly(Map<String, Object> params);
    int getCountByMacAndTime(@Param("mac") String mac, @Param("time") String time);
    void insertHistoryHourlyTransition(Map<String, Object> params);
    void updateHistoryTransition(@Param("mac") String mac, @Param("time") String time);
}
screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -48,26 +48,17 @@
        result.put("version", version);
        result.put("timeUnits", Constants.UN_ADJUST);
        result.put("value", JSONObject.toJSONString(data));
        //原始数据(未校准)
        historyHourlyMapper.insertHistoryHourlyUnAdjust(result);
        //未校准小时表insert
        historyHourlyMapper.insertHistoryHourly(result);
        //数据校准
        dataAdjust = deviceService.adjustDeviceData(dataAdjust);
        dataAdjust.remove("mac");
        dataAdjust.remove("DataTime");
        dataAdjust.remove("ver");
        int count = historyHourlyMapper.getCountByMacAndTime(mac, DateUtils.dateToDateString(time));
        //判断中间表有没有该mac,该小时的数据,有就更新,没有就新增
        if (count == 0) {
            //小时数据校准后存入小时中间表
            result.put("value", JSONObject.toJSONString(dataAdjust));
            //新增
            historyHourlyMapper.insertHistoryHourlyTransition(result);
        } else {
            //更新
            historyHourlyMapper.updateHistoryTransition(mac, DateUtils.dateToDateString(time));
        }
        result.put("timeUnits", Constants.TRANSITION);
        result.put("value", JSONObject.toJSONString(dataAdjust));
        //校准后中间小时表insert
        historyHourlyMapper.insertHistoryHourly(result);
    }
}
screen-manage/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -10,19 +10,9 @@
        <result column="version" property="version"/>
    </resultMap>
    <insert id="insertHistoryHourlyUnAdjust">
        INSERT INTO history_hourly_${timeUnits} VALUES (#{mac}, #{time}, #{value}, #{version})
    <insert id="insertHistoryHourly">
        INSERT INTO history_hourly_${timeUnits}
        VALUES (#{mac}, #{time}, #{value}, #{version})
    </insert>
    <select id="getCountByMacAndTime" resultType="java.lang.Integer">
        SELECT count(1) FROM history_hourly_transition WHERE mac = #{mac} AND `time` = #{time}
    </select>
    <insert id="insertHistoryHourlyTransition">
        INSERT INTO history_hourly_transition (mac, `time`, `value`, version) VALUES (#{mac}, #{time}, #{value}, #{version})
    </insert>
    <update id="updateHistoryTransition">
        UPDATE history_hourly_transition SET update_time = now() WHERE mac = #{mac} AND `time` = {time}
    </update>
</mapper>