| | |
| | | Response res=service.getLockHis(lockId,startTime,endTime,pageNum,pageSize); |
| | | return res; |
| | | } |
| | | |
| | | |
| | | @ApiOperation("实时界面点击查看历史信息") |
| | | @GetMapping("getLockHisWithReal") |
| | | public Response getLockHisWithReal(@RequestParam int lockId, @RequestParam String startTime, @RequestParam String endTime) throws ParseException, InterruptedException { |
| | | Response res=service.getLockHisWithReal(lockId,startTime,endTime); |
| | | return res; |
| | | } |
| | | } |
| | |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_area.LockInf; |
| | | import com.whyc.pojo.db_lock_his.LockHis; |
| | | import com.whyc.util.SubTablePageInfoUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.ParseException; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class LockHisService { |
| | |
| | | ,"db_lock_his","tb_lock_his_"+lockId,his); |
| | | return new Response().setII(1,pageInfo.getList()!=null,pageInfo,"查询锁的历史状态"); |
| | | } |
| | | |
| | | //实时界面点击查看历史信息 |
| | | public Response getLockHisWithReal(int lockId, String startTime, String endTime) throws ParseException { |
| | | LockHis his=new LockHis(); |
| | | his.setLockId(lockId); |
| | | List<LockHis> list=util.getLockHisWithReal(ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1) |
| | | ,"db_lock_his","tb_lock_his_"+lockId,his); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("openNum", 0); |
| | | map.put("closeNum", 0); |
| | | map.put("nowopenNum", 0); |
| | | map.put("nowcloseNum", 0); |
| | | map.put("hisList", list); |
| | | Map<Integer, List<LockHis>> statemap = list.stream().collect(Collectors.groupingBy(LockHis::getLockState)); |
| | | for (Integer state : statemap.keySet()) { |
| | | if (state == 0) { |
| | | map.put("closeNum", statemap.get(0).size());//关锁 |
| | | } |
| | | if (state == 1) { |
| | | map.put("openNum", statemap.get(1).size());//开锁 |
| | | } |
| | | } |
| | | Date date = new Date(); |
| | | //获取当天得开始时间 |
| | | Date nowstartTime = new Date(date.getYear(), date.getMonth(), date.getDate(), 0, 0, 0); |
| | | //获取当天的结束时间 |
| | | Date nowendTime = new Date(date.getYear(), date.getMonth(), date.getDate(), 23, 59, 59); |
| | | List<LockHis> nowList =util.getLockHisWithReal(nowstartTime,nowendTime |
| | | ,"db_lock_his","tb_lock_his_"+lockId,his); |
| | | Map<Integer, List<LockHis>> nowstatemap = nowList.stream().collect(Collectors.groupingBy(LockHis::getLockState)); |
| | | for (Integer state : nowstatemap.keySet()) { |
| | | if (state == 0) { |
| | | map.put("nowcloseNum", nowstatemap.get(0).size());//关锁 |
| | | } |
| | | if (state == 1) { |
| | | map.put("nowopenNum", nowstatemap.get(1).size());//开锁 |
| | | } |
| | | } |
| | | return new Response().setII(1,list!=null,map,"实时界面点击查看历史信息"); |
| | | } |
| | | } |
| | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | //锁的历史记录 |
| | | public List<LockHis> getLockHisWithReal(LockHis his) { |
| | | String sql="SELECT * FROM db_lock_his."+ his.getRecordYear()+" history " + |
| | | " where history.lock_id="+ his.getLockId() ; |
| | | if(his.getStartTime()!=null){ |
| | | sql+=" and record_time >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' "; |
| | | } |
| | | if(his.getEndTime()!=null){ |
| | | sql+=" and record_time <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' "; |
| | | } |
| | | sql+=" ORDER BY record_time asc "; |
| | | List<LockHis> list=sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List list=new ArrayList(); |
| | | while (rs.next()){ |
| | | LockHis data=new LockHis(); |
| | | data.setNum(rs.getInt("num")); |
| | | data.setLockId(rs.getInt("lock_id")); |
| | | data.setRecordTime(rs.getTimestamp("record_time")); |
| | | data.setLockState(rs.getInt("lock_state")); |
| | | data.setUnlockType(rs.getInt("unlock_type")); |
| | | data.setUnlockId(rs.getString("unlock_id")); |
| | | list.add(data); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | //锁的告警历史记录总数 |
| | | public int getLockAlmHisCount(LockAlarmHis his) { |
| | | String sql="SELECT count(*) as number FROM db_lock_alarm."+ his.getRecordYear()+" history " + |
| | |
| | | } |
| | | return resultTableList; |
| | | } |
| | | //实时界面点击查看历史信息 |
| | | public List getLockHisWithReal(Date startTime,Date endTime, |
| | | String dbName,String tablePrefix, |
| | | Object pojo) throws ParseException { |
| | | Map<String, List<Date>> queryTimeForSubTables = DateUtil.getQueryTimeForSubTablesDescWithOutDefault(startTime, endTime); |
| | | Set<String> tableYearKeySet = queryTimeForSubTables.keySet(); |
| | | List<Object> dataList = new LinkedList<>(); |
| | | for (String tableYear : tableYearKeySet) { |
| | | List<Date> queryTime = queryTimeForSubTables.get(tableYear); |
| | | |
| | | //数值 |
| | | String tableName = tablePrefix+"_"+tableYear; |
| | | String existTableName = commonMapper.existTable(dbName, tableName); |
| | | if(existTableName == null){ |
| | | continue; |
| | | } |
| | | //====== 根据不同类型类型对象对应调整 ====== |
| | | if(pojo instanceof LockHis) { |
| | | LockHis his = new LockHis(); |
| | | BeanUtils.copyProperties(pojo, his); |
| | | his.setStartTime(queryTime.get(0)); |
| | | his.setEndTime(queryTime.get(1)); |
| | | his.setRecordYear(tableName); |
| | | List<LockHis> list = service.getLockHisWithReal(his); |
| | | dataList.addAll(list); |
| | | } |
| | | } |
| | | return dataList; |
| | | } |
| | | } |