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.PowerDto; import com.whyc.dto.Response; import com.whyc.mapper.BattInfMapper; import com.whyc.pojo.db_station.BattInf; import com.whyc.pojo.db_station.PowerInf; import com.whyc.pojo.db_station.StationInf; import com.whyc.pojo.db_user.User; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service public class BattInfService { @Autowired(required = false) private BattInfMapper mapper; /* //添加电源 @Transactional public Response addBatt(BattInf binf) { //先校验当前用户是否存在包机组不存在则不让添加电源 User user= ActionUtil.getUser(); int flag=bjService.checkUserBaojiGroup(user.getId()); if(flag==0){ return new Response().set(1,false,"当前用户不存在包机组"); } //机房信息 StationInf addsinf= addpinf.getSinf(); //判断添加锁的时候机房是不是新机房 String fullName=addsinf.getProvice()+"_"+addsinf.getCity()+"_"+addsinf.getCountry()+"_"+addsinf.getStationName(); //判断机房是否存在 QueryWrapper wrapper=new QueryWrapper(); wrapper.eq("full_name",fullName); wrapper.last("limit 1"); StationInf sinf=sinfMapper.selectOne(wrapper); int stationId=0; int powerId=0; if(sinf!=null){ stationId=sinf.getStationId(); }else { //获取对应的机房id stationId = sinfMapper.getMaxStationId(); if (stationId == 0) {//数据库中没有站点 stationId = 40000001; } else { stationId += 1; } addsinf.setFullName(fullName); addsinf.setStationId(stationId); sinfMapper.insert(addsinf); } //判断机房是否存在 QueryWrapper wrapper1=new QueryWrapper(); wrapper1.eq("power_name",addpinf.getPowerName()); wrapper1.eq("station_id",stationId); wrapper1.last("limit 1"); PowerInf juegep=mapper.selectOne(wrapper); if(juegep==null){ return new Response().set(1, false, "当前机房下已添加过该电源"); } //再添加电源信息 addpinf.setStationId(stationId); //获取对应的电源id powerId = mapper.getMaxPowerId(); if (powerId == 0) {//数据库中没有站点 powerId = 10001; } else { powerId += 1; } addpinf.setPowerId(powerId); mapper.insert(addpinf); return new Response().set(1, true, "添加电源"); } //删除电源 public Response delBatt(Integer bid) { UpdateWrapper wrapper=new UpdateWrapper(); wrapper.eq("battgroup_id",bid); mapper.delete(wrapper); return new Response().set(1,true); } //修改电源 public Response updateBatt(BattInf binf) { UpdateWrapper wrapper=new UpdateWrapper(); wrapper.eq("battgroup_id",binf.getBattgroupId()); if(binf.getBattgroupName()!=null){ wrapper.set("battgroup_name",binf.getBattgroupName()); } if(binf.getCompany()!=null){ wrapper.set("company",pinf.getCompany()); } if(pinf.getModel()!=null){ wrapper.set("model",pinf.getModel()); } if(pinf.getProtocol()!=null){ wrapper.set("protocol",pinf.getProtocol()); } if(pinf.getPowerIp()!=null){ wrapper.set("power_ip",pinf.getPowerIp()); } mapper.update((PowerInf) ActionUtil.objeNull,wrapper); return new Response().set(1,true); } //查询电源 public Response getBatt(PowerDto dto) { User user= ActionUtil.getUser(); dto.setUid(user.getId()); PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); List list=mapper.getPower(dto); PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list!=null,pageInfo,"查询电源"); } */ }