| | |
| | | import com.whyc.dto.LockInfDto; |
| | | import com.whyc.dto.RealDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BaojigroupLockMapper; |
| | | import com.whyc.mapper.LockIdcardMapper; |
| | | import com.whyc.mapper.LockInfMapper; |
| | | import com.whyc.mapper.StationInfMapper; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.plus_inf.LockAddress; |
| | | import com.whyc.pojo.plus_inf.LockInf; |
| | | import com.whyc.pojo.plus_inf.StationInf; |
| | | import com.whyc.pojo.plus_lock_ram.LockIdcard; |
| | | import com.whyc.pojo.plus_user.Baojigroup; |
| | | import com.whyc.pojo.plus_user.BaojigroupLock; |
| | | import com.whyc.pojo.plus_user.BaojigroupUsr; |
| | | import com.whyc.pojo.plus_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 org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | private BaojigroupLockMapper bjLockMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private BaojigroupUsrMapper bjUserMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private BaojigroupService baojiService; |
| | | |
| | | @Autowired(required = false) |
| | | private BaojigroupMapper bjMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private LockIdcardMapper idcardMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private LockAddressMapper addressMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private ProcessSurveyService processSurveyService; |
| | |
| | | int lockId=0; |
| | | if(sinf!=null){ |
| | | stationId=sinf.getStationId(); |
| | | //根据锁名判断机房下是否存在同名锁 |
| | | QueryWrapper wrapper1=new QueryWrapper(); |
| | | wrapper1.eq("station_id",stationId); |
| | | wrapper1.eq("lock_name",lockInf.getLockName()); |
| | | wrapper1.eq("del_flag",0); |
| | | wrapper1.last("limit 1"); |
| | | LockInf judgeLock=mapper.selectOne(wrapper1); |
| | | if (judgeLock!=null){ |
| | | return new Response().set(1,false,"当前机房下已经存在同名锁"); |
| | | } |
| | | //获取当前最大的锁 |
| | | lockId=getMaxLockId(stationId); |
| | | if(lockId==0){ |
| | |
| | | linf.setLastUpdateTime(new Date()); |
| | | linf.setModel(0); |
| | | linf.setLockOpenCount(0); |
| | | mapper.insert(linf); |
| | | processSurveyService.setUpThreadRestart(); |
| | | linf.setLockIp(lockInf.getLockIp()); |
| | | int flag=mapper.insert(linf); |
| | | if(flag==1){//添加成功(包机组操作) |
| | | insertInbaoji(stationId,lockId); |
| | | //锁的默认位置插入为0 |
| | | LockAddress lockAddress=new LockAddress(); |
| | | lockAddress.setStationId(stationId); |
| | | lockAddress.setLockId(lockId); |
| | | lockAddress.setScreenFlag(0); |
| | | lockAddress.setAddressFlag(0); |
| | | addressMapper.insert(lockAddress); |
| | | } |
| | | return new Response().set(1,true); |
| | | } |
| | | //包机组操作 |
| | | public void insertInbaoji(Integer stationId,Integer lockId){ |
| | | //重启线程并将锁加到当前人的包机组 |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | QueryWrapper wrapper1=new QueryWrapper(); |
| | | wrapper1.eq("uid",uinf.getUid()); |
| | | List<BaojigroupUsr> groupIdList=bjUserMapper.selectList(wrapper1); |
| | | List<BaojigroupLock> baojigroupList=new ArrayList(); |
| | | if(groupIdList!=null&&groupIdList.size()>0){ |
| | | BaojigroupLock bjLock=new BaojigroupLock(); |
| | | bjLock.setStationId(stationId); |
| | | bjLock.setLockId(lockId); |
| | | bjLock.setBaojiId(groupIdList.get(0).getBaojiId()); |
| | | baojigroupList.add(bjLock); |
| | | }else{//人对应没有包机组先创建自己的默认包机组 |
| | | QueryWrapper wrapper3=new QueryWrapper(); |
| | | wrapper3.eq("baoji_name","默认包机组"); |
| | | wrapper3.last("limit 1"); |
| | | Baojigroup group=bjMapper.selectOne(wrapper3); |
| | | if(group==null){ |
| | | Baojigroup bj=new Baojigroup(); |
| | | bj.setBaojiName("默认包机组"); |
| | | bjMapper.insert(bj); |
| | | QueryWrapper wrapper4=new QueryWrapper(); |
| | | wrapper4.eq("baoji_name","默认包机组"); |
| | | wrapper4.last("limit 1"); |
| | | group=bjMapper.selectOne(wrapper4); |
| | | baojiService.insertNeiZhi(group.getId()); |
| | | } |
| | | BaojigroupUsr bjUsr=new BaojigroupUsr(); |
| | | bjUsr.setUid(uinf.getUid()); |
| | | bjUsr.setBaojiId(group.getId()); |
| | | bjUserMapper.insert(bjUsr); |
| | | |
| | | BaojigroupLock bjLock=new BaojigroupLock(); |
| | | bjLock.setStationId(stationId); |
| | | bjLock.setLockId(lockId); |
| | | bjLock.setBaojiId(group.getId()); |
| | | baojigroupList.add(bjLock); |
| | | } |
| | | bjLockMapper.insertBatchSomeColumn(baojigroupList); |
| | | processSurveyService.setUpThreadRestart(); |
| | | } |
| | | //获取当前及放下最大的锁id |
| | | private int getMaxLockId(Integer stationId) { |
| | | public int getMaxLockId(Integer stationId) { |
| | | int lockId=mapper.getMaxLockId(stationId); |
| | | return lockId; |
| | | } |
| | |
| | | public Response getAllLockInf(LockInfDto dto) { |
| | | PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); |
| | | List<LockInf> list=mapper.getAllLockInf(dto); |
| | | for (LockInf linf:list) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("lock_id",linf.getLockId()); |
| | | wrapper.last("limit 1"); |
| | | LockIdcard idcard=idcardMapper.selectOne(wrapper); |
| | | linf.setLockIdcard(idcard); |
| | | } |
| | | 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); |
| | | wrapper.set("del_flag",1);//删除时标记为1 |
| | | int flag=mapper.update((LockInf) ActionUtil.objeNull,wrapper); |
| | | if(flag==1){ |
| | | //删除包机组下记录 |
| | | UpdateWrapper wrapper1=new UpdateWrapper(); |
| | | wrapper1.eq("lock_id",lockId); |
| | | bjLockMapper.delete(wrapper1); |
| | | //移除address |
| | | UpdateWrapper wrapper2=new UpdateWrapper(); |
| | | wrapper2.eq("lock_id",lockId); |
| | | addressMapper.delete(wrapper2); |
| | | } |
| | | return new Response().set(1,true); |
| | | } |
| | | //修改锁 |
| | |
| | | if(lockInf.getScreenFlag()!=null){ |
| | | wrapper.set("screen_flag",lockInf.getScreenFlag()); |
| | | } |
| | | |
| | | if(lockInf.getLongitude()!=null){ |
| | | wrapper.set("longitude",lockInf.getLongitude()); |
| | | } |
| | |
| | | wrapper.set("latitude",lockInf.getLatitude()); |
| | | } |
| | | mapper.update((LockInf) ActionUtil.objeNull,wrapper); |
| | | if(lockInf.getLockIp()!=null){ |
| | | UpdateWrapper wrapper1=new UpdateWrapper(); |
| | | wrapper1.set("lock_ip",lockInf.getLockIp()); |
| | | wrapper1.eq("station_id",lockInf.getStationId()); |
| | | mapper.update((LockInf) ActionUtil.objeNull,wrapper1); |
| | | processSurveyService.setUpThreadRestart(); |
| | | } |
| | | return new Response().set(1,true); |
| | | } |
| | | //查询所有锁名信息(用于下拉) |
| | | /*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 getScreenType(Integer uid) { |
| | |
| | | map.put("closeNum",0); |
| | | map.put("unLoadNum",0); |
| | | //根据dto中stationid和包机组id查询出管理的lockid |
| | | List<Integer> lockIdList=bjLockMapper.getLocIdByStationidAndBjId(dto.getStationId(),dto.getBaojiId()); |
| | | List<LockInf> linfs=mapper.getRealLock(lockIdList); |
| | | 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());//离线 |
| | | try { |
| | | List<Integer> lockIdList=bjLockMapper.getLocIdByStationidAndBjId(dto.getStationId(),dto.getBaojiId()); |
| | | List<LockInf> linfs=mapper.getRealLock(lockIdList); |
| | | //包机组下锁的位置信息 |
| | | List<LockAddress> addressList=addressMapper.getAddressList(lockIdList); |
| | | //机房下所有锁的位置 |
| | | List<LockAddress> AllAddressList=addressMapper.getAllAddress(dto.getStationId()); |
| | | 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());//在线 |
| | | } |
| | | } |
| | | 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());//未安装 |
| | | } |
| | | } |
| | | } |
| | | 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, dto.getPageNum(), dto.getPageSize()); |
| | | map.put("pageInfo",pageInfo); |
| | | return new Response().setIV(1,linfs!=null,map,addressList,AllAddressList,"实时获取获取区域下所有锁的状态"); |
| | | } catch (Exception e) { |
| | | return new Response().set(1,false,"实时获取获取区域下所有锁的状态"); |
| | | } |
| | | PageInfo pageInfo= PageInfoUtils.list2PageInfo(linfs, dto.getPageNum(), dto.getPageSize()); |
| | | map.put("pageInfo",pageInfo); |
| | | return new Response().setII(1,linfs!=null,map,"实时获取获取区域下所有锁的状态"); |
| | | } |
| | | //查询锁的信息和id卡 |
| | | public Response getLockId(LockIdDto dto) { |
| | |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询锁的信息和id卡"); |
| | | } |
| | | //历史界面查询锁(下拉) |
| | | public Response getLockInHis(Integer stationId, Integer baojiId) { |
| | | //根据dto中stationid和包机组id查询出管理的lockid |
| | | List<Integer> lockIdList=bjLockMapper.getLocIdByStationidAndBjId(stationId,baojiId); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.in("lock_id",lockIdList); |
| | | wrapper.orderByAsc("lock_id"); |
| | | List<LockInf> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"历史界面查询锁(下拉)"); |
| | | } |
| | | } |