whyclxw
2025-01-02 8845ebb030f4e81c932393369e7dbccb7e88845a
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.AuthiruzeInfMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.pojo.db_area.AuthiruzeInf;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_user.UserInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class LockInfService {
    @Autowired(required = false)
    private LockInfMapper mapper;
 
    @Autowired(required = false)
    private AreaInfService areaInfService;
 
    @Autowired(required = false)
    private AuthiruzeInfMapper authMapper;
    //添加锁
    public Response addLock(Integer areaId, String lockName, Integer lockType,Integer num) {
        if(num==null){
            num=1;
        }
        List list=new ArrayList();
        //获取当前最大的锁
        int lockId=getMaxLockId()+1;
        for(int i=0;i<num;i++){
            LockInf linf=new LockInf();
            linf.setLockId(lockId+i);
            linf.setAreaId(areaId);
            linf.setLockName(lockName+(i+1));
            linf.setLockType(lockType);
            linf.setLockState(-1);
            linf.setLockAddress("");
            linf.setLockPath("");
            linf.setLockMac("FFFF");
            list.add(linf);
        }
        mapper.insertBatchSomeColumn(list);
        return new Response().set(1,true);
    }
    //获取当前最大的锁
    private int getMaxLockId() {
        int keyId=mapper.getMaxLockId();
        return keyId;
    }
 
    //查询所有锁信息
    public Response getAllLockInf(String lockName, Integer lockType, Integer lockState,Integer areaId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Integer> areaList=new ArrayList();
        areaList.add(areaId);
        areaInfService.getAllAreaId(areaId,areaList);
        List<LockInf> list=mapper.getAllLockInf(lockName,lockType,lockState,areaList);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询所有锁信息");
    }
    //删除锁
    public Response delLock(Integer lockId) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("lock_id",lockId);
        mapper.delete(wrapper);
        return new Response().set(1,true);
    }
   //修改锁
    public Response updateLock(Integer lockId, Integer areaId, String lockName, String lockType) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("lock_id",lockId);
        wrapper.set("area_id",areaId);
        wrapper.set("lock_name",lockName);
        wrapper.set("lock_type",lockType);
        mapper.update(null,wrapper);
        return new Response().set(1,true);
    }
    //授权时查询所有蓝牙锁信息(不分页)
    public Response getLockInfAuth() {
       /* QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("lock_type",1);*/
        List<LockInf> list=mapper.selectList(null);
        return new Response().setII(1,list!=null,list,"授权时查询所有蓝牙锁信息(不分页)");
    }
    //获取区域下所有锁的状态
    public Response getLockRt(int areaId) {
        //获取获取id下所有的区域id
        List areaList=new ArrayList();
        areaList.add(areaId);
        areaInfService.getAllAreaId(areaId,areaList);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.in("area_id",areaList);
        List<LockInf> list=mapper.selectList(wrapper);
        for (LockInf linf:list) {
            QueryWrapper wrapper1=new QueryWrapper();
            wrapper1.eq("lock_id",linf.getLockId());
            List<AuthiruzeInf>  authList=authMapper.selectList(wrapper1);
            linf.setAuthList(authList);
        }
        return new Response().setII(1,list!=null,list,"获取区域下所有锁的状态");
    }
    //查询所有锁名信息(用于下拉)
    public Response getLinf() {
        List<LockInf> list=mapper.selectList(null);
        List<String> lnameList = list.stream()
                .map(LockInf::getLockName) // 提取名字
                .collect(Collectors.toList()); // 转换为列表*/
        return new Response().setII(1,list!=null,lnameList,"查询所有锁名信息(用于下拉)");
    }
}