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 com.whyc.util.ActionUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.swing.*;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class AuthiruzeInfService {
|
@Autowired(required = false)
|
private AuthiruzeInfMapper mapper;
|
@Autowired(required = false)
|
private LockInfMapper lockInfMapper;
|
|
@Autowired(required = false)
|
private AreaInfService areaInfService;
|
|
//查询所有授权信息
|
public Response getAllAuthInf(Integer state, String uname, int areaId,int pageNum, int pageSize) {
|
PageHelper.startPage(pageNum,pageSize);
|
QueryWrapper wrapper=new QueryWrapper();
|
if(state!=null){
|
wrapper.eq("state",state);
|
}
|
if(uname!=null){
|
wrapper.like("uname",uname);
|
}
|
List 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()); // 转换为列表*/
|
wrapper.in("lock_id",lockIdList);
|
}
|
List<LockInf> list=mapper.selectList(wrapper);
|
PageInfo pageInfo=new PageInfo(list);
|
return new Response().setII(1,list!=null,pageInfo,"查询所有钥匙信息");
|
}
|
//添加授权
|
public Response addAuth(AuthiruzeInf auth) {
|
List<LockInf> lockIdList=auth.getLockInfs();
|
List<AuthiruzeInf> list=new ArrayList<>();
|
if(lockIdList!=null){
|
for (LockInf linf:lockIdList) {
|
AuthiruzeInf authiruzeInf=new AuthiruzeInf();
|
BeanUtils.copyProperties(auth,authiruzeInf);
|
authiruzeInf.setLockId(linf.getLockId());
|
authiruzeInf.setLockName(linf.getLockName());
|
list.add(authiruzeInf);
|
}
|
}
|
mapper.insertBatchSomeColumn(list);
|
return new Response().set(1,true);
|
}
|
//删除授权
|
public Response delAuth(List<Integer> ids) {
|
for (Integer id:ids) {
|
UpdateWrapper wrapper=new UpdateWrapper();
|
wrapper.eq("id",id);
|
mapper.delete(wrapper);
|
}
|
return new Response().set(1,true);
|
}
|
//修改授权
|
public Response updateAuth(AuthiruzeInf auth) {
|
UpdateWrapper wrapper=new UpdateWrapper();
|
wrapper.eq("id",auth.getId());
|
if(auth.getStartTime()!=null){
|
wrapper.set("start_time",auth.getStartTime());
|
}
|
if(auth.getStopTime()!=null){
|
wrapper.set("stop_time",auth.getStopTime());
|
}
|
if(auth.getDescript()!=null){
|
wrapper.set("descript",auth.getDescript());
|
}
|
mapper.update(null,wrapper);
|
return new Response().set(1,true);
|
}
|
//根据mac检测蓝牙锁是否有权限
|
public Response getAuthByUidAndMac(Integer mac) {
|
UserInf uinf= ActionUtil.getUser();
|
//获取锁的id
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("lock_mac",mac);
|
wrapper.last("limit 1");
|
LockInf linf=lockInfMapper.selectOne(wrapper);
|
//检测是否有权限
|
QueryWrapper wrapper1=new QueryWrapper();
|
wrapper1.eq("uname",uinf.getUname());
|
wrapper1.eq("lock_id",linf.getLockId());
|
wrapper1.last("limit 1");
|
AuthiruzeInf auth=mapper.selectOne(wrapper1);
|
return new Response().set(1,auth!=null,"根据mac检测蓝牙锁是否有权限");
|
}
|
}
|