package com.whyc.service;
|
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.LockHisDto;
|
import com.whyc.dto.Response;
|
import com.whyc.pojo.plus_lock_his.LockHis;
|
import com.whyc.util.SubTablePageInfoUtil;
|
import com.whyc.util.ThreadLocalUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.ParseException;
|
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 {
|
@Autowired
|
private SubTablePageInfoUtil util;
|
//查询锁的历史状态
|
public Response getLockHis( LockHisDto dto) throws ParseException {
|
PageInfo pageInfo=util.getPageInfoWithOutDefault(dto.getPageNum(),dto.getPageSize(),dto.getStartTime(),dto.getEndTime()
|
,"plus_lock_his","tb_lock_his_"+dto.getLockId(),dto);
|
return new Response().setII(1,pageInfo.getList()!=null,pageInfo,"查询锁的历史状态");
|
}
|
|
//实时界面点击查看历史信息
|
public Response getLockHisWithReal(int lockId, String startTime, String endTime) throws ParseException {
|
LockHisDto his=new LockHisDto();
|
his.setLockId(lockId);
|
List<LockHis> list=util.getLockHisWithReal(ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1)
|
,"plus_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,"实时界面点击查看历史信息");
|
}
|
}
|