whyclxw
2025-01-10 8047368b0136b01b14d38121d9ec972b75f2fd89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.LockCtlLogMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_lock_ram.LockCtlLog;
import com.whyc.pojo.db_user.UserInf;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
@Service
public class LockCtlLogService {
    @Autowired(required = false)
    private LockCtlLogMapper mapper;
 
    @Autowired(required = false)
    private LockInfMapper linfmapper;
 
    //查询开锁日志
    public Response getLockLog(LockCtlLog log, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(log.getLockId()!=null){
            wrapper.eq("lock_id",log.getLockId());
        }
        if(log.getCtlResult()!=null){
            wrapper.eq("ctl_result",log.getCtlResult());
        }
        if(log.getCtlType()!=null){
            wrapper.eq("ctl_type",log.getCtlType());
        }
        if(log.getCtlUname()!=null){
            wrapper.eq("ctl_uname",log.getCtlUname());
        }
        if(log.getStartTime()!=null){
            wrapper.eq("ctl_time",log.getStartTime());
        }
        if(log.getEndTime()!=null){
            wrapper.eq("ctl_time",log.getEndTime());
        }
        wrapper.orderByDesc("ctl_time");
        List<LockCtlLog> list=mapper.selectList(wrapper);
        for (LockCtlLog l:list) {
            QueryWrapper wrapper1=new QueryWrapper();
            wrapper1.eq("lock_id",l.getLockId());
            wrapper1.last("limit 1");
            LockInf linf=linfmapper.selectOne(wrapper1);
            l.setLockName(linf.getLockName());
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询最近的开锁日志");
    }
    //获取开锁错误的日志
    public List getAllErrorLog(List lockIds) {
        List<LockCtlLog> list=mapper.getAllErrorLog(lockIds);
        return list;
    }
 
    //获取开锁日志
    public List getAllLog(List lockIds) {
        List<LockCtlLog> list=mapper.getAllLog(lockIds);
        return list;
    }
    //添加操作记录
    public void setLogByUid(Integer lockId, int result, String uname) {
        LockCtlLog log=new LockCtlLog();
        log.setLockId(lockId);
        log.setCtlType(7);//蓝牙开锁
        log.setCtlResult(result);
        log.setCtlTime(new Date());
        log.setCtlIdCard(0);
        log.setCtlUname(uname);
        mapper.insert(log);
    }
}