| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.sun.corba.se.impl.protocol.giopmsgheaders.TargetAddress; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.AuthiruzeInfMapper; |
| | | import com.whyc.mapper.LockInfMapper; |
| | | import com.whyc.pojo.db_area.AreaUser; |
| | | 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 com.whyc.util.PageInfoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class LockInfService { |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private AuthiruzeInfMapper authMapper; |
| | | |
| | | @Autowired |
| | | private ProcessSurveyService processSurveyService; |
| | | //添加锁 |
| | | public Response addLock(Integer areaId, String lockName, Integer lockType,Integer num) { |
| | | public Response addLock(Integer num, LockInf lockInf) { |
| | | if(num==null){ |
| | | num=1; |
| | | } |
| | |
| | | for(int i=0;i<num;i++){ |
| | | LockInf linf=new LockInf(); |
| | | linf.setLockId(lockId+i); |
| | | linf.setLockId(lockId); |
| | | linf.setAreaId(areaId); |
| | | linf.setLockName(lockName); |
| | | linf.setLockType(lockType); |
| | | linf.setAreaId(lockInf.getAreaId()); |
| | | if(num>1){ |
| | | linf.setLockName(lockInf.getLockName()+(i+1)); |
| | | }else{ |
| | | linf.setLockName(lockInf.getLockName()); |
| | | } |
| | | linf.setLockType(lockInf.getLockType()); |
| | | linf.setLockState(-1); |
| | | linf.setLockAddress(""); |
| | | if(lockInf.getLockAddress()!=null){ |
| | | linf.setLockAddress(lockInf.getLockAddress()); |
| | | }else{ |
| | | linf.setLockAddress(""); |
| | | } |
| | | linf.setLockPath(""); |
| | | linf.setLatitude(lockInf.getLatitude()); |
| | | linf.setLongitude(lockInf.getLongitude()); |
| | | linf.setLockMac("FFFF"); |
| | | linf.setScreenBoxType(lockInf.getScreenBoxType()); |
| | | linf.setScreenBoxProduct(lockInf.getScreenBoxProduct()); |
| | | linf.setScreenFlag(lockInf.getScreenFlag()); |
| | | linf.setLockOnline(0); |
| | | linf.setLastUpdateTime(new Date()); |
| | | linf.setModel(0); |
| | | linf.setLockOpenCount(0); |
| | | list.add(linf); |
| | | } |
| | | mapper.insertBatchSomeColumn(list); |
| | | processSurveyService.setUpThreadRestart(); |
| | | return new Response().set(1,true); |
| | | } |
| | | //获取当前最大的锁 |
| | |
| | | } |
| | | |
| | | //查询所有锁信息 |
| | | public Response getAllLockInf(String lockName, String lockType, Integer lockState,Integer areaId, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | if(lockName!=null){ |
| | | wrapper.like("lock_name",lockName); |
| | | } |
| | | if(lockType!=null){ |
| | | wrapper.eq("lock_type",lockType); |
| | | } |
| | | if(lockState!=null){ |
| | | wrapper.eq("lock_state",lockState); |
| | | } |
| | | List areaList=new ArrayList(); |
| | | public Response getAllLockInf(String lockName, Integer lockType, Integer lockState,Integer areaId, int pageNum, int pageSize) { |
| | | List<Integer> areaList=new ArrayList(); |
| | | areaList.add(areaId); |
| | | areaInfService.getAllAreaId(areaId,areaList); |
| | | if(areaList!=null){ |
| | | wrapper.in("area_id",areaList); |
| | | } |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<LockInf> list=mapper.getAllLockInf(lockName,lockType,lockState,areaList); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询所有锁信息"); |
| | | } |
| | |
| | | return new Response().set(1,true); |
| | | } |
| | | //修改锁 |
| | | public Response updateLock(Integer lockId, Integer areaId, String lockName, String lockType) { |
| | | public Response updateLock(LockInf lockInf) { |
| | | 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); |
| | | wrapper.eq("lock_id",lockInf.getLockId()); |
| | | if(lockInf.getAreaId()!=null){ |
| | | wrapper.set("area_id",lockInf.getAreaId()); |
| | | } |
| | | if(lockInf.getLockName()!=null){ |
| | | wrapper.set("lock_name",lockInf.getLockName()); |
| | | } |
| | | if(lockInf.getLockType()!=null){ |
| | | wrapper.set("lock_type",lockInf.getLockType()); |
| | | } |
| | | if(lockInf.getScreenBoxType()!=null){ |
| | | wrapper.set("screen_box_type",lockInf.getScreenBoxType()); |
| | | } |
| | | if(lockInf.getScreenBoxProduct()!=null){ |
| | | wrapper.set("screen_box_product",lockInf.getScreenBoxProduct()); |
| | | } |
| | | if(lockInf.getScreenFlag()!=null){ |
| | | wrapper.set("screen_flag",lockInf.getScreenFlag()); |
| | | } |
| | | if(lockInf.getLongitude()!=null){ |
| | | wrapper.set("longitude",lockInf.getLongitude()); |
| | | } |
| | | if(lockInf.getLatitude()!=null){ |
| | | wrapper.set("latitude",lockInf.getLatitude()); |
| | | } |
| | | mapper.update((LockInf) ActionUtil.objeNull,wrapper); |
| | | return new Response().set(1,true); |
| | | } |
| | | //授权时查询所有蓝牙锁信息(不分页) |
| | | public Response getLockInfAuth() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("lock_type",1); |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | /* QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("lock_type",1);*/ |
| | | List<LockInf> list=mapper.selectList(null); |
| | | return new Response().setII(1,list!=null,list,"授权时查询所有蓝牙锁信息(不分页)"); |
| | | } |
| | | //获取区域下所有锁的状态 |
| | |
| | | } |
| | | 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,"查询所有锁名信息(用于下拉)"); |
| | | } |
| | | //查询区域管理员的所有区域下锁具(用于下拉) |
| | | public Response getAreaUserLock() { |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | List areaList=areaInfService.getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.in("area_id",areaList); |
| | | wrapper.orderByAsc("num"); |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"查询所有锁名信息(用于下拉)"); |
| | | } |
| | | //查询屏柜的全部类型(下拉) |
| | | public Response getScreenType() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("distinct screen_box_type"); |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | List<String> typeList = list.stream() |
| | | .map(LockInf::getScreenBoxType) // 提取名字 |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return new Response().setII(1,list!=null,typeList,"查询屏柜的全部类型(下拉)"); |
| | | } |
| | | //查询屏柜全部品牌(下拉) |
| | | public Response getScreenProduct() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("distinct screen_box_product"); |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | List<String> typeList = list.stream() |
| | | .map(LockInf::getScreenBoxProduct) // 提取名字 |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return new Response().setII(1,list!=null,typeList,"查询屏柜全部品牌(下拉)"); |
| | | } |
| | | //实时获取获取区域下所有锁的状态 |
| | | public Response getRealLock(Integer areaId, Integer pageNum, Integer pageSize) { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("sumLinf",0); |
| | | map.put("onlineNum",0); |
| | | map.put("offLineNum",0); |
| | | map.put("openNum",0); |
| | | map.put("closeNum",0); |
| | | map.put("unLoadNum",0); |
| | | List<Integer> areaList=new ArrayList(); |
| | | areaList.add(areaId); |
| | | areaInfService.getAllAreaId(areaId,areaList); |
| | | List<LockInf> linfs=mapper.getRealLock(areaList); |
| | | if(linfs!=null&&linfs.size()>0){ |
| | | map.put("sumLinf",linfs.size()); |
| | | Map<Integer, List<LockInf>> onlinemap = linfs.stream().collect(Collectors.groupingBy(LockInf::getLockOnline)); |
| | | for (Integer state : onlinemap.keySet()) { |
| | | if(state==0){ |
| | | map.put("offLineNum", onlinemap.get(0).size());//离线 |
| | | } |
| | | if(state==1){ |
| | | map.put("onlineNum", onlinemap.get(1).size());//在线 |
| | | } |
| | | } |
| | | Map<Integer, List<LockInf>> openmap = linfs.stream().collect(Collectors.groupingBy(LockInf::getLockState)); |
| | | for (Integer open : openmap.keySet()) { |
| | | if(open==0){ |
| | | map.put("closeNum", openmap.get(0).size());//闭锁 |
| | | } |
| | | if(open==1){ |
| | | map.put("openNum", openmap.get(1).size());//开锁 |
| | | } |
| | | if(open==-1){ |
| | | map.put("unLoadNum", openmap.get(-1).size());//未安装 |
| | | } |
| | | } |
| | | } |
| | | PageInfo pageInfo= PageInfoUtils.list2PageInfo(linfs,pageNum,pageSize); |
| | | map.put("pageInfo",pageInfo); |
| | | return new Response().setII(1,linfs!=null,map,"实时获取获取区域下所有锁的状态"); |
| | | } |
| | | } |