| | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | 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.whyc.dto.Response; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.db_station.PowerInf; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | public void insertNeiZhi(Integer baojiId){ |
| | | List<BaojigroupUsr> list=new ArrayList<>(); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.lt("uid",99); |
| | | wrapper.lt("id",99); |
| | | List<User> uList=UserMapper.selectList(wrapper); |
| | | for (User uinf:uList) { |
| | | BaojigroupUsr baojiusr=new BaojigroupUsr(); |
| | |
| | | //验证包机组名是否重复 |
| | | //将内置用户加入到包机组下 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("baoji_name",baojiName); |
| | | wrapper.eq("baoji_group_name",baojiName); |
| | | wrapper.last("limit 1"); |
| | | Baojigroup baoji=mapper.selectOne(wrapper); |
| | | if(baoji!=null){ |
| | |
| | | baoji=new Baojigroup(); |
| | | baoji.setBaojiGroupName(baojiName); |
| | | int bl=mapper.insert(baoji); |
| | | if(bl>0){ |
| | | /*if(bl>0){ |
| | | //将内置用户加入到包机组下 |
| | | QueryWrapper wrapper1=new QueryWrapper(); |
| | | wrapper1.eq("baoji_name",baojiName); |
| | | wrapper1.eq("baoji_group_name",baojiName); |
| | | wrapper1.last("limit 1"); |
| | | baoji=mapper.selectOne(wrapper1); |
| | | insertNeiZhi(baoji.getBaojiGroupId()); |
| | | } |
| | | }*/ |
| | | return new Response().set(1,bl>0,"添加包机组成功"); |
| | | } |
| | | |
| | |
| | | //编辑包机组 |
| | | public Response updateBaoji(Integer id, String baojiName) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("id",id); |
| | | wrapper.set("baoji_name",baojiName); |
| | | wrapper.eq("baoji_group_id",id); |
| | | wrapper.set("baoji_group_name",baojiName); |
| | | int bl=mapper.update((Baojigroup) ActionUtil.objeNull,wrapper); |
| | | return new Response().set(1,bl>0,"编辑包机组成功"); |
| | | } |
| | |
| | | public Response delBaoji(Integer id) { |
| | | //先删除包机组对应人下的记录 |
| | | UpdateWrapper wrapper1=new UpdateWrapper(); |
| | | wrapper1.eq("baoji_id",id); |
| | | wrapper1.eq("baoji_group_id",id); |
| | | bjUsrmapper.delete(wrapper1); |
| | | //再删除包机组对应下的机房和锁 |
| | | //再删除包机组对应下的机房和电源 |
| | | UpdateWrapper wrapper2=new UpdateWrapper(); |
| | | wrapper2.eq("baoji_id",id); |
| | | wrapper2.eq("baoji_group_id",id); |
| | | bjPowermapper.delete(wrapper2); |
| | | //最后删除包机组 |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("id",id); |
| | | wrapper.eq("baoji_group_id",id); |
| | | int bl=mapper.delete(wrapper); |
| | | return new Response().set(1,bl>0,"删除包机组成功"); |
| | | } |
| | | //查询包机组及包机组对应的用户和对应机房和锁 |
| | | public Response getAllBaojiInf() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.orderByAsc("id"); |
| | | wrapper.orderByAsc("baoji_group_id"); |
| | | List<Baojigroup> baojiList=mapper.selectList(wrapper); |
| | | for (Baojigroup bj:baojiList) { |
| | | //查询包机组对应的用户信息 |
| | |
| | | List<User> relatedUserList = bjUsrmapper.getUserList(id); |
| | | //查询包机组未添加的用户信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("uid", "uname"); |
| | | wrapper.gt("uid",100); |
| | | wrapper.select("id", "name"); |
| | | wrapper.gt("id",100); |
| | | List<User> allUserList = UserMapper.selectList(wrapper); |
| | | List<User> notRelatedUserList = allUserList.stream().filter(User -> !relatedUserList.contains(User)).collect(Collectors.toList()); |
| | | |
| | |
| | | public Response getBaojiUserByUid(Integer uid) { |
| | | //查询当前人所在包机组 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("baoji_id"); |
| | | wrapper.select("baoji_group_id"); |
| | | if(uid>100){ |
| | | wrapper.eq("uid",uid); |
| | | } |
| | |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("uid",id); |
| | | List<BaojigroupUsr> list=bjUsrmapper.selectList(wrapper); |
| | | return list.size()>0?0:1 ; |
| | | return list.size()>0?1:0 ; |
| | | } |
| | | //设置包机组标记 |
| | | public Response updateTeamFlag(Integer baoJiGroupId, Integer flag) { |
| | | if(flag==1) { |
| | | //查询要设置的包机组的站点 |
| | | QueryWrapper<BaojigroupPower> query = Wrappers.query(); |
| | | query.select("baoji_group_id", "station_id").eq("baoji_group_id", baoJiGroupId); |
| | | List<BaojigroupPower> stationIdList = bjPowermapper.selectList(query); |
| | | stationIdList = stationIdList.stream().distinct().collect(Collectors.toList()); |
| | | //查询其他的组,包含的所有站点 |
| | | List<BaojigroupPower> stationIdListWithDischargePlanFlag = bjPowermapper.getStationIdListWithDischargePlanFlag(); |
| | | stationIdListWithDischargePlanFlag = stationIdListWithDischargePlanFlag.stream().distinct().collect(Collectors.toList()); |
| | | List<BaojigroupPower> repeatedStationIdList = new LinkedList<>(); |
| | | for (int i = 0; i < stationIdList.size(); i++) { |
| | | BaojigroupPower baojiGroupBattGroup = stationIdList.get(i); |
| | | for (int j = 0; j < stationIdListWithDischargePlanFlag.size(); j++) { |
| | | BaojigroupPower baojiGroupBattGroupWithFlag = stationIdListWithDischargePlanFlag.get(j); |
| | | if (baojiGroupBattGroupWithFlag.getStationId().equals(baojiGroupBattGroup.getStationId())) { |
| | | repeatedStationIdList.add(baojiGroupBattGroupWithFlag); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //查询重复站点的信息 |
| | | if (repeatedStationIdList.size() > 0) { |
| | | return new Response().setII(1, false, repeatedStationIdList, "设置失败"); |
| | | } |
| | | } |
| | | UpdateWrapper<Baojigroup> update = Wrappers.update(); |
| | | update.set("team_flag",flag).eq("baoji_group_id",baoJiGroupId); |
| | | mapper.update((Baojigroup) ActionUtil.objeNull,update); |
| | | return new Response().set(1,true,"设置完成"); |
| | | } |
| | | //删除包机组下的电源 |
| | | public void delPowerInBaoji(Integer pid) { |
| | | UpdateWrapper<BaojigroupPower> update = Wrappers.update(); |
| | | update.eq("power_id",pid); |
| | | bjPowermapper.delete(update); |
| | | } |
| | | |
| | | //删除包机组下的机房 |
| | | public void delStationInBaoji(Integer sid) { |
| | | UpdateWrapper<BaojigroupPower> update = Wrappers.update(); |
| | | update.eq("station_id",sid); |
| | | bjPowermapper.delete(update); |
| | | } |
| | | //查询机房所在的班组 |
| | | public String getGroupName(Integer powerId) { |
| | | String groupName = powerInfMapper.getGroupName(powerId); |
| | | if(groupName==null||groupName.length()<0){ |
| | | groupName="none"; |
| | | } |
| | | return groupName; |
| | | } |
| | | //查询所有的包机组名集合(班组) |
| | | public List<Baojigroup> getGroupList() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("team_flag",1); |
| | | List<Baojigroup> list=mapper.selectList(wrapper); |
| | | return list; |
| | | } |
| | | } |