| | |
| | | } |
| | | |
| | | /** |
| | | * @param request 请求信息 |
| | | * @param params 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | */ |
| | | @PostMapping("getMacSensors") |
| | |
| | | } |
| | | |
| | | /** |
| | | * @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) { |
| | |
| | | public static final String UN_ADJUST = "unadjust"; |
| | | |
| | | /* |
| | | * 小时中间表后缀 |
| | | * */ |
| | | public static final String TRANSITION = "transition"; |
| | | |
| | | /* |
| | | * 离线设备状态码 |
| | | * */ |
| | | public static final String DEVICE_STATE_OFFLINE = "0"; |
| | |
| | | `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> |
| | |
| | | */ |
| | | 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); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | <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> |