whyclxw
2025-02-12 c51df4155f0b97129d4783a15fd5837683c1c386
历史告警采用areaId不使用lockId
4个文件已修改
68 ■■■■ 已修改文件
src/main/java/com/whyc/controller/LockAlarmHisController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_lock_alarm/LockAlarmHis.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/LockAlarmHisService.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SubTableService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/LockAlarmHisController.java
@@ -21,9 +21,9 @@
    private LockAlarmHisService service;
    @ApiOperation("查询锁告警的历史状态")
    @GetMapping("getLockAlmHis")
    public Response getLockAlmHis(@RequestParam Integer lockId,@RequestParam Integer almId, @RequestParam String startTime, @RequestParam String endTime
    public Response getLockAlmHis(@RequestParam Integer areaId,@RequestParam Integer almId, @RequestParam String startTime, @RequestParam String endTime
            , @RequestParam int pageNum, @RequestParam int pageSize) throws ParseException, InterruptedException {
        Response res=service.getLockAlmHis(lockId,almId,startTime,endTime,pageNum,pageSize);
        Response res=service.getLockAlmHis(areaId,almId,startTime,endTime,pageNum,pageSize);
        return res;
    }
}
src/main/java/com/whyc/pojo/db_lock_alarm/LockAlarmHis.java
@@ -13,6 +13,7 @@
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * <p>
@@ -23,8 +24,6 @@
 * @since 2025-02-05
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="LockAlarmHis对象", description="2025年电子锁具历史告警表")
public class LockAlarmHis implements Serializable {
@@ -78,4 +77,8 @@
    @TableField(exist = false)
    private LockInf linf;
    @TableField(exist = false)
    private List<Integer> lids;
}
src/main/java/com/whyc/service/LockAlarmHisService.java
@@ -1,7 +1,10 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.LockInfMapper;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_lock_alarm.LockAlarmHis;
import com.whyc.pojo.db_lock_his.LockHis;
import com.whyc.util.SubTablePageInfoUtil;
@@ -10,16 +13,40 @@
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class LockAlarmHisService {
    @Autowired
    private SubTablePageInfoUtil util;
    @Autowired
    private AreaInfService areaInfService;
    @Autowired(required = false)
    private LockInfMapper lockInfMapper;
    //查询锁告警的历史状态
    public Response getLockAlmHis(Integer lockId, Integer almId,String startTime, String endTime, int pageNum, int pageSize) throws ParseException {
    public Response getLockAlmHis(Integer areaId, Integer almId,String startTime, String endTime, int pageNum, int pageSize) throws ParseException {
        LockAlarmHis his=new LockAlarmHis();
        his.setLockId(lockId);
        if(areaId!=null){
            List<Integer> areaList=new ArrayList();
            areaList.add(areaId);
            areaInfService.getAllAreaId(areaId,areaList);
            //根据区域查询所有的锁
            if(areaList!=null){
                QueryWrapper wrapper1=new QueryWrapper();
                wrapper1.in("area_id",areaList);
                List<LockInf> lockInfList=lockInfMapper.selectList(wrapper1);
                List<Integer> lockIdList = lockInfList.stream()
                        .map(LockInf::getLockId) // 提取id值
                        .collect(Collectors.toList()); // 转换为列表*/
                his.setLids(lockIdList);
            }
        }
        his.setAlmId(almId);
        PageInfo pageInfo=util.getPageInfo(pageNum,pageSize, ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1)
                ,"db_lock_alarm","tb_lock_alarm",his);
src/main/java/com/whyc/service/SubTableService.java
@@ -111,7 +111,18 @@
    //锁的告警历史记录总数
    public int getLockAlmHisCount(LockAlarmHis his) {
        String sql="SELECT  count(*) as number FROM db_lock_alarm."+ his.getRecordYear()+" history " +
                " where history.lock_id="+ his.getLockId() ;
                " where  1=1 ";
        if(his.getLids()!=null&&his.getLids().size()>0){
            List<Integer> lids=his.getLids();
            sql+=" and  history.lock_id in (";
            for (int i=0;i<lids.size();i++) {
                if(i==lids.size()-1){
                    sql=sql+lids.get(i)+") ";
                }else{
                    sql=sql+lids.get(i)+",";
                }
            }
        }
        if(his.getStartTime()!=null){
            sql+=" and alm_start_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
        }
@@ -140,7 +151,18 @@
    //锁的告警历史记录
    public List<LockAlarmHis> getLockAlmHisList(LockAlarmHis his) {
        String sql="SELECT * FROM db_lock_alarm."+ his.getRecordYear()+" history " +
                " where history.lock_id="+  his.getLockId() ;
                " where 1=1 " ;
        if(his.getLids()!=null&&his.getLids().size()>0){
            List<Integer> lids=his.getLids();
            sql+=" and  history.lock_id in (";
            for (int i=0;i<lids.size();i++) {
                if(i==lids.size()-1){
                    sql=sql+lids.get(i)+") ";
                }else{
                    sql=sql+lids.get(i)+",";
                }
            }
        }
        if(his.getStartTime()!=null){
            sql+=" and alm_start_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
        }