| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.A200RealstateMapper; |
| | | import com.whyc.mapper.ActmRealstateMapper; |
| | | import com.whyc.mapper.BattgroupBaojigroupMapper; |
| | | import com.whyc.mapper.DevInfMapper; |
| | | import com.whyc.pojo.db_lithium_ram_db.A200Realstate; |
| | | import com.whyc.pojo.db_lithium_ram_db.ActmRealstate; |
| | | import com.whyc.pojo.db_lithium_ram_db.DevInf; |
| | | import com.whyc.pojo.db_user.BattgroupBaojigroup; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | @Autowired(required = false) |
| | | private ActmRealstateMapper actmMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private BattgroupBaojigroupMapper battBjmapper; |
| | | |
| | | //添加设备 |
| | | @Transactional |
| | | public Response addDev(DevInf devInf) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | //判断设备类型生成devId |
| | | int devId=getDevId(devInf.getDevType()); |
| | | devInf.setDevId(devId); |
| | | devInf.setCreateTime(new Date()); |
| | | int bl=mapper.insert(devInf); |
| | | if(bl>0){ |
| | | if(devInf.getBaojiIdList()!=null){ |
| | | List<BattgroupBaojigroup> listBj=new ArrayList<>(); |
| | | for (int baojiId:devInf.getBaojiIdList()) { |
| | | BattgroupBaojigroup baojigroup=new BattgroupBaojigroup(); |
| | | baojigroup.setDevId(devId); |
| | | baojigroup.setBaojiGroupId(baojiId); |
| | | listBj.add(baojigroup); |
| | | } |
| | | //将设备添加进指定的包机组 |
| | | battBjmapper.insertBatchSomeColumn(listBj); |
| | | } |
| | | } |
| | | return new Response().set(1,bl>0); |
| | | } |
| | | //判断设备类型生成devId |
| | |
| | | public Response getAllInf(Integer uid, DevInfDto devInfDto) { |
| | | Map<String, Object> allMap = new HashMap<>(); |
| | | PageHelper.startPage(devInfDto.getPageNum(), devInfDto.getPageSize()); |
| | | List<DevInf> listype=mapper.getAllInf(uid,devInfDto.getDevType()); |
| | | devInfDto.setUid(uid); |
| | | List<DevInf> listype=mapper.getAllInf(devInfDto); |
| | | PageInfo pageInfo=new PageInfo(listype); |
| | | |
| | | List<DevInf> list=mapper.getLine(uid); |
| | |
| | | return new Response().setII(1,list!=null,list,"获取左侧列表"); |
| | | } |
| | | //获取左侧泪飙 |
| | | public Response getLine(int uid) { |
| | | public Response getDevType(int uid) { |
| | | Map<String, Object> allMap = new HashMap<>(); |
| | | List<DevInf> a200List=mapper.getLine(uid); |
| | | List<DevInf> a200List=mapper.getDevType(uid,1); |
| | | for (DevInf a200:a200List) { |
| | | QueryWrapper a200wrapper= Wrappers.query(); |
| | | a200wrapper.eq("dev_id",a200.getDevId()); |
| | | a200wrapper.last("limit 1"); |
| | | A200Realstate a200state=a200Mapper.selectOne(a200wrapper); |
| | | a200.setA200sTate(a200state); |
| | | //a200.setA200sTate(a200state); |
| | | a200.setState(a200state!=null?a200state:null); |
| | | } |
| | | List<DevInf> actmList=mapper.getLine(uid); |
| | | List<DevInf> actmList=mapper.getDevType(uid,2); |
| | | for (DevInf actm:actmList) { |
| | | QueryWrapper actmwrapper= Wrappers.query(); |
| | | actmwrapper.eq("dev_id",actm.getDevId()); |
| | | actmwrapper.last("limit 1"); |
| | | ActmRealstate actmstate=actmMapper.selectOne(actmwrapper); |
| | | actm.setActmsTate(actmstate); |
| | | List<ActmRealstate> actmstates=actmMapper.selectList(actmwrapper); |
| | | //actm.setActmsTate(actmstate); |
| | | actm.setActmstates(actmstates!=null?actmstates:null); |
| | | } |
| | | allMap.put("a200List",a200List); |
| | | allMap.put("actmList",actmList); |
| | | return new Response().setII(1,allMap.size()>0,allMap,"获取左侧列表"); |
| | | } |
| | | //编辑设备信息 |
| | | public Response updateInf(DevInf dinf) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("dev_id",dinf.getDevId()); |
| | | int flag=mapper.update(dinf,wrapper); |
| | | return new Response().set(1,flag>0,"编辑设备信息"); |
| | | } |
| | | //获取设备信息(不分页用于包机组) |
| | | public Response getDinf() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.orderByAsc("dev_id"); |
| | | List<DevInf> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"获取设备信息(不分页用于包机组)"); |
| | | } |
| | | |
| | | //根据设备id获取设备信息 |
| | | public Response getDinfById(Integer devId) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.last("limit 1"); |
| | | DevInf dinf=mapper.selectOne(wrapper); |
| | | return new Response().setII(1,dinf!=null,dinf,"根据设备id获取设备信息"); |
| | | } |
| | | //删除设备(同时删除实时和包机组信息) |
| | | @Transactional |
| | | public Response delDinf(Integer devId) { |
| | | //先删除包机组信息 |
| | | UpdateWrapper baojiWrapper=new UpdateWrapper(); |
| | | baojiWrapper.eq("dev_id",devId); |
| | | battBjmapper.delete(baojiWrapper); |
| | | //再删除实时信息 |
| | | if(devId/100000000==1){ |
| | | UpdateWrapper a200Wrapper=new UpdateWrapper(); |
| | | a200Wrapper.eq("dev_id",devId); |
| | | a200Mapper.delete(a200Wrapper); |
| | | }else{ |
| | | UpdateWrapper actmWrapper=new UpdateWrapper(); |
| | | actmWrapper.eq("dev_id",devId); |
| | | actmMapper.delete(actmWrapper); |
| | | } |
| | | //最后删除设备信息 |
| | | UpdateWrapper dinfWrapper=new UpdateWrapper(); |
| | | dinfWrapper.eq("dev_id",devId); |
| | | mapper.delete(dinfWrapper); |
| | | return new Response().set(1,true,"删除设备(同时删除实时和包机组信息)"); |
| | | } |
| | | //强制移除批量设备 |
| | | @Transactional |
| | | public Response cancelContPl(List<Integer> devIds) { |
| | | for (Integer devId:devIds) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.set("batch_state",0); |
| | | mapper.update(null,wrapper); |
| | | } |
| | | return new Response().set(1,true,"强制移除批量设备"); |
| | | } |
| | | //设备分类总数统计 |
| | | public Map<String,Object> getDevStaticByType(int userId) { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | Map<Integer,Integer> staticTypeMap=new HashMap<>(); |
| | | staticTypeMap.put(1,0); |
| | | staticTypeMap.put(2,0); |
| | | |
| | | Map<Integer,Integer> a200staticStateMap=new HashMap<>(); |
| | | a200staticStateMap.put(0,0); |
| | | a200staticStateMap.put(1,0); |
| | | Map<Integer,Integer> actmstaticStateMap=new HashMap<>(); |
| | | actmstaticStateMap.put(0,0); |
| | | actmstaticStateMap.put(1,0); |
| | | Map<String,Object> typestateMap=new HashMap<>(); |
| | | typestateMap.put("a200",a200staticStateMap); |
| | | typestateMap.put("actm",actmstaticStateMap); |
| | | List<DevInf> list=mapper.getDevStaticByType(userId); |
| | | Map<Integer, List<DevInf>> typeMap = list.stream().collect(Collectors.groupingBy(DevInf::getDevType)); |
| | | for (Integer type : typeMap.keySet()) { |
| | | staticTypeMap.put(type, typeMap.get(type).size()); |
| | | List<DevInf> typeList= typeMap.get(type); |
| | | Map<Integer, List<DevInf>> stateMap = typeList.stream().collect(Collectors.groupingBy(DevInf::getDevOnline)); |
| | | if(type==1){ |
| | | for (Integer state : stateMap.keySet()) { |
| | | a200staticStateMap.put(state, stateMap.get(state).size()); |
| | | } |
| | | typestateMap.put("a200", a200staticStateMap); |
| | | } |
| | | if(type==2){ |
| | | for (Integer state : stateMap.keySet()) { |
| | | actmstaticStateMap.put(state, stateMap.get(state).size()); |
| | | } |
| | | typestateMap.put("actm", actmstaticStateMap); |
| | | } |
| | | } |
| | | map.put("dinf",list!=null?list:null); |
| | | map.put("type",staticTypeMap); |
| | | map.put("state",typestateMap); |
| | | return map; |
| | | } |
| | | |
| | | //根据devId获取设备信息 |
| | | public DevInf getDinfByDevId(int devId){ |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.last("limit 1"); |
| | | DevInf dinf=mapper.selectOne(wrapper); |
| | | return dinf; |
| | | } |
| | | |
| | | } |