| | |
| | | import com.moral.api.mapper.HistoryHourlyMapper; |
| | | import com.moral.api.mapper.HistoryMinutelyMapper; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.SensorService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | |
| | | * @since 2021-06-28 |
| | | */ |
| | | @Service |
| | | public class HistoryHourlyServiceImpl extends ServiceImpl<HistoryHourlyMapper, HistoryHourly> implements HistoryHourlyService { |
| | | public class HistoryHourlyServiceImpl implements HistoryHourlyService { |
| | | |
| | | @Autowired |
| | | private HistoryHourlyMapper historyHourlyMapper; |
| | |
| | | private SensorService sensorService; |
| | | |
| | | @Override |
| | | public void createTable(String timeUnits) { |
| | | historyHourlyMapper.createTable(timeUnits); |
| | | } |
| | | |
| | | @Override |
| | | public void insertHistoryHourly() { |
| | | //时间格式化:yyyy-MM-dd HH:mm |
| | | String format = DateUtils.yyyy_MM_dd_HH_EN; |
| | |
| | | Date now = new Date(); |
| | | String time = DateUtils.dateToDateString(now, format) + ":00:00"; |
| | | |
| | | QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("time", time); |
| | | //查询数据库当前小时的条数,如果比macs小,说明需要数据补充 |
| | | Integer count = historyHourlyMapper.selectCount(queryWrapper); |
| | | if (macs.size() > count) { |
| | | Map<String, Object> prop = new HashMap<>(); |
| | | prop.put("timeUnits", DateUtils.getDateStringOfMon(0, DateUtils.yyyyMM_EN)); |
| | | prop.put("time", time); |
| | | Integer count = historyHourlyMapper.selectCountByTime(prop); |
| | | |
| | | if (macs.size() <= count) { |
| | | return; |
| | | } else { |
| | | macs.removeIf(mac -> { |
| | | queryWrapper.clear(); |
| | | queryWrapper.eq("time", time); |
| | | queryWrapper.eq("mac", mac); |
| | | Integer num = historyHourlyMapper.selectCount(queryWrapper); |
| | | prop.put("mac", mac); |
| | | Integer num = historyHourlyMapper.selectCountByTime(prop); |
| | | return num != 0; |
| | | }); |
| | | } |
| | |
| | | //存入小时表 |
| | | historyHourlyMapper.insertHistoryHourly(insertData); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> selectDailyData(Map<String, Object> params) { |
| | | return historyHourlyMapper.selectDailyData(params); |
| | | } |
| | | } |