whyclxw
2025-03-25 a7fef2846505b08e0711345b17902e7381612d23
src/main/java/com/whyc/service/AuthiruzeInfService.java
@@ -5,8 +5,11 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.AreaUserMapper;
import com.whyc.mapper.AuthiruzeInfMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.mapper.UserInfMapper;
import com.whyc.pojo.db_area.AreaUser;
import com.whyc.pojo.db_area.AuthIdcard;
import com.whyc.pojo.db_area.AuthiruzeInf;
import com.whyc.pojo.db_area.LockInf;
@@ -21,6 +24,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
@Service
@@ -36,6 +40,10 @@
    @Autowired(required = false)
    private AuthIdcardService idcardService;
    @Autowired(required = false)
    private UserInfMapper uinfMapper;
    //查询所有授权信息
    public Response getAllAuthInf( String uname, int areaId,int pageNum, int pageSize) {
@@ -66,6 +74,7 @@
        List<LockInf> lockIdList=auth.getLockInfs();
        List<AuthiruzeInf> list=new ArrayList<>();
        List<AuthIdcard> idcards=new ArrayList<>();
        UserInf userInf=ActionUtil.getUser();
        if(lockIdList!=null){
            for (LockInf linf:lockIdList) {
                AuthiruzeInf authiruzeInf=new AuthiruzeInf();
@@ -81,6 +90,7 @@
                    authIdcard_add.setKeyId(auth.getKeyId());
                    authIdcard_add.setLockId(linf.getLockId());
                    authIdcard_add.setCreateTime(new Date());
                    authIdcard_add.setCtlUname(userInf.getUname());
                    authIdcard_add.setState(2);
                    idcards.add(authIdcard_add);
                }
@@ -140,6 +150,7 @@
        //再添加新的
        List<LockInf> lockIdList=auth.getLockInfs();
        List<AuthiruzeInf> list=new ArrayList<>();
        UserInf userInf=ActionUtil.getUser();
        if(lockIdList!=null){
            for (LockInf linf:lockIdList) {
                AuthiruzeInf authiruzeInf=new AuthiruzeInf();
@@ -157,6 +168,7 @@
                    authIdcard_add.setLockId(linf.getLockId());
                    authIdcard_add.setCreateTime(new Date());
                    authIdcard_add.setState(2);
                    authIdcard_add.setCtlUname(userInf.getUname());
                    idcards.add(authIdcard_add);
                }
@@ -169,14 +181,14 @@
        return new Response().set(1,true);
    }
    //根据mac检测蓝牙锁是否有权限
    public Response getAuthByUidAndMac(Integer mac) {
        UserInf uinf= ActionUtil.getUser();
        List areaList=areaInfService.getAllAreaUser(uinf.getUid(),uinf.getUrole());
    public Response getAuthByUidAndMac(String mac,String uname) {
        UserInf uinf=uinfMapper.getUinfByUname(uname);
        //List areaList=areaInfService.getAllAreaUser(uinf.getUid(),uinf.getUrole());
        //获取锁是否在人管理的区域下面
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("lock_mac",mac);
        wrapper.eq("lock_mac",mac.toUpperCase(Locale.ROOT));
        wrapper.eq("lock_online",1);
        wrapper.last("limit 1");
        wrapper.in("area_id",areaList);
        LockInf linf=lockInfMapper.selectOne(wrapper);
        if(linf==null){
            return new Response().set(1,false,"没有权限");
@@ -187,25 +199,22 @@
            wrapper1.eq("lock_id",linf.getLockId());
            wrapper1.last("limit 1");
            AuthiruzeInf auth=mapper.selectOne(wrapper1);
            return new Response().set(1,auth!=null,"有权限");
            return new Response().set(1,auth!=null,auth!=null?"有权限":"没有权限");
        }
    }
    //普通用户登录查看自己授权记录-----app
    public Response getAuthByUid() {
        UserInf uinf=ActionUtil.getUser();
    //普通用户登录查看自己授权锁记录-----app
    public Response getAuthByUid(String uname) {
        //UserInf uinf=uinfMapper.getUinfByUname(uname);
        //查询普通用户对应的区域
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("uname",uinf.getUname());
        wrapper.select("distinct lock_id");
        wrapper.eq("uname",uname);
        wrapper.eq("key_id",0);//蓝牙钥匙
        List<AuthiruzeInf> list=mapper.selectList(wrapper);
        if(list!=null){
            for (AuthiruzeInf auth:list) {
                QueryWrapper wrapper1=new QueryWrapper();
                wrapper1.eq("lock_id",auth.getLockId());
                wrapper1.last("limit 1");
                LockInf linf=lockInfMapper.selectOne(wrapper1);
                auth.setLinf(linf);
            }
        }
        return new Response().setII(1,list!=null,list,"普通用户登录查看自己授权记录-----app");
        List<Integer> lockIds=list.stream().map(AuthiruzeInf::getLockId) // 提取id
                .collect(Collectors.toList());
        //根据锁的lockIds查询锁的记录
        List<LockInf> linfs=lockInfMapper.selectlinfByLockIds(lockIds);
        return new Response().setII(1,linfs!=null,linfs,"普通用户登录查看自己授权记录-----app");
    }
}