whyclxw
2025-05-15 e8b154e63e9db8750407c218eb13937f584bda8c
src/main/java/com/whyc/service/BattInfService.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.BattDto;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.mapper.BattInfMapper;
@@ -16,69 +17,50 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
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();
        //判断机房是否存在
    public Response addBatt(BattInf addbinf) {
        //判断电池组是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("full_name",fullName);
        wrapper.eq("station_id",addbinf.getStationId());
        wrapper.eq("power_id",addbinf.getPowerId());
        wrapper.eq("dev_name",addbinf.getDevName());
        wrapper.eq("battgroup_name",addbinf.getBattgroupName());
        wrapper.last("limit 1");
        StationInf sinf=sinfMapper.selectOne(wrapper);
        int stationId=0;
        int powerId=0;
        if(sinf!=null){
            stationId=sinf.getStationId();
        BattInf binf=mapper.selectOne(wrapper);
        int devId=0;
        int battGroupId=0;
        if(binf!=null){
            return new Response().set(1,false,"当前电源机房下已添加过该电池组");
        }else {
            //获取对应的机房id
            stationId = sinfMapper.getMaxStationId();
            if (stationId == 0) {//数据库中没有站点
                stationId = 40000001;
            //获取对应的设备id,电池组
            devId = mapper.getMaxdevId();
            battGroupId=mapper.getMaxBattGroupId();
            if (devId == 0) {//数据库中没有站点
                devId = 10001;
            } else {
                stationId += 1;
                devId += 1;
            }
            addsinf.setFullName(fullName);
            addsinf.setStationId(stationId);
            sinfMapper.insert(addsinf);
            if (battGroupId == 0) {//数据库中没有站点
                battGroupId = 10001;
            } else {
                battGroupId += 1;
            }
            addbinf.setDevId(devId);
            addbinf.setBattgroupId(battGroupId);
            addbinf.setCreateTime(new Date());
            mapper.insert(addbinf);
            return new Response().set(1, true, "添加电池组");
        }
        //判断机房是否存在
        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) {
@@ -94,30 +76,36 @@
        if(binf.getBattgroupName()!=null){
            wrapper.set("battgroup_name",binf.getBattgroupName());
        }
        if(binf.getCompany()!=null){
            wrapper.set("company",pinf.getCompany());
        if(binf.getMonvolstd()!=null){
            wrapper.set("monvolstd",binf.getMonvolstd());
        }
        if(pinf.getModel()!=null){
            wrapper.set("model",pinf.getModel());
        if(binf.getMoncapstd()!=null){
            wrapper.set("moncapstd",binf.getMoncapstd());
        }
        if(pinf.getProtocol()!=null){
            wrapper.set("protocol",pinf.getProtocol());
        if(binf.getMonresstd()!=null){
            wrapper.set("monresstd",binf.getMonresstd());
        }
        if(pinf.getPowerIp()!=null){
            wrapper.set("power_ip",pinf.getPowerIp());
        if(binf.getProduct()!=null){
            wrapper.set("product",binf.getProduct());
        }
        mapper.update((PowerInf) ActionUtil.objeNull,wrapper);
        if(binf.getMoncount()!=null){
            wrapper.set("moncount",binf.getMoncount());
        }
        if(binf.getModel()!=null){
            wrapper.set("model",binf.getModel());
        }
        mapper.update((BattInf) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true);
    }
    //查询电源
    public Response getBatt(PowerDto dto) {
    //查询电池
    public Response getBatt(BattDto dto) {
        User user= ActionUtil.getUser();
        dto.setUid(user.getId());
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<PowerInf> list=mapper.getPower(dto);
        List<BattInf> list=mapper.getBatt(dto);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询电源");
        return new Response().setII(1,list!=null,pageInfo,"查询电池");
    }
*/
}