| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moral.entity.History; |
| | | import com.moral.service.DeviceService; |
| | | import com.moral.service.HistoryDailyService; |
| | | import com.moral.service.HistoryHourlyService; |
| | | import com.moral.service.HistoryMinutelyService; |
| | | import com.moral.service.HistoryService; |
| | | import com.moral.service.SensorService; |
| | | import com.xxl.job.core.biz.model.ReturnT; |
| | | import com.xxl.job.core.handler.annotation.XxlJob; |
| | |
| | | |
| | | @Resource |
| | | private DeviceService deviceService; |
| | | |
| | | @Resource |
| | | private HistoryService historyService; |
| | | |
| | | @Resource |
| | | private HistoryMinutelyService historyMinutelyService; |
| | |
| | | return returnT; |
| | | } |
| | | |
| | | @XxlJob("historySpecial") |
| | | public ReturnT insertHistorySpecialTable(String params) { |
| | | Map macMap = JSON.parseObject(params); |
| | | List<String> macList = (List<String>) macMap.get("mac"); |
| | | LocalDateTime value = LocalDateTime.now(); |
| | | LocalDateTime time = value.truncatedTo(ChronoUnit.SECONDS); |
| | | LocalDateTime tenSecondsAgo = time.minusSeconds(10); |
| | | Map<String, Object> devices = new HashMap<>(); |
| | | devices.put("macList", macList); |
| | | devices.put("time", tenSecondsAgo); |
| | | try { |
| | | List<History> historyData = historyService.selectByMacAndTime(devices); |
| | | if (!CollectionUtils.isEmpty(historyData)) { |
| | | int count = historyService.insertHistorySpecialTable(devices); |
| | | XxlJobLogger.log("insertHistorySpecialTable:" + count); |
| | | ReturnT returnT = new ReturnT(200, "插入historySpecial表成功"); |
| | | return returnT; |
| | | } |
| | | } catch (Exception e) { |
| | | XxlJobLogger.log("insertHistorySpecialTableException:" + e.getMessage()); |
| | | logger.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | ReturnT returnT = new ReturnT(500, "插入historySpecial表失败"); |
| | | return returnT; |
| | | } |
| | | |
| | | } |