whyclxw
2025-05-15 e8b154e63e9db8750407c218eb13937f584bda8c
电池组管理
4个文件已修改
2个文件已添加
208 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/BattInfController.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/BattDto.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BattInfMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_station/BattInf.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattInfService.java 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BattInfMapper.xml 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/BattInfController.java
@@ -1,5 +1,6 @@
package com.whyc.controller;
import com.whyc.dto.BattDto;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.pojo.db_station.BattInf;
@@ -18,28 +19,28 @@
    @Autowired
    private BattInfService service;
/*
    @ApiOperation(value = "添加电源")
    @ApiOperation(value = "添加电池组")
    @PostMapping("addBatt")
    public Response addBatt(@RequestBody BattInf binf){
        return service.addBatt(binf);
    }
    @ApiOperation(value = "删除电源")
    @ApiOperation(value = "删除电池组")
    @GetMapping("delBatt")
    public Response delBatt(@RequestParam Integer bid){
        return service.delBatt(bid);
    }
    @ApiOperation(value = "修改电源")
    @ApiOperation(value = "修改电池组")
    @PostMapping("updateBatt")
    public Response updateBatt(@RequestBody BattInf binf){
        return service.updateBatt(binf);
    }
    @ApiOperation(value = "查询电源")
    @ApiOperation(value = "查询电池组")
    @PostMapping("getBatt")
    public Response getBatt(@RequestBody PowerDto dto){
    public Response getBatt(@RequestBody BattDto dto){
        return service.getBatt(dto);
    }*/
    }
}
src/main/java/com/whyc/dto/BattDto.java
New file
@@ -0,0 +1,16 @@
package com.whyc.dto;
import lombok.Data;
@Data
public class BattDto {
    private String provice;
    private String city;
    private String country;
    private String stationName;
    private String powerName;
    private String battgroupName;
    private Integer pageNum;
    private Integer pageSize;
    private Integer uid;
}
src/main/java/com/whyc/mapper/BattInfMapper.java
@@ -1,6 +1,15 @@
package com.whyc.mapper;
import com.whyc.dto.BattDto;
import com.whyc.pojo.db_station.BattInf;
import java.util.List;
public interface BattInfMapper extends CustomMapper<BattInf>{
    //获取对应的设备id
    Integer getMaxdevId();
    //获取对应的电池组id
    Integer getMaxBattGroupId();
    //查询电池
    List<BattInf> getBatt(BattDto dto);
}
src/main/java/com/whyc/pojo/db_station/BattInf.java
@@ -1,6 +1,7 @@
package com.whyc.pojo.db_station;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -53,7 +54,7 @@
    private String battgroupName;
    @ApiModelProperty(value = "电池组编号")
    private Integer battfroupNum;
    private Integer battgroupNum;
    @ApiModelProperty(value = "标称电压")
    private Float monvolstd;
@@ -64,6 +65,9 @@
    @ApiModelProperty(value = "标称内阻")
    private Float monresstd;
    @ApiModelProperty(value = "每组单体个数")
    private Float moncount;
    @ApiModelProperty(value = "品牌")
    private String product;
@@ -71,7 +75,15 @@
    private String model;
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date createTime;
    @TableField(exist = false)
    private String stationName;
    @TableField(exist = false)
    private String powerName;
}
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,"查询电池");
    }
*/
}
src/main/resources/mapper/BattInfMapper.xml
New file
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.whyc.mapper.BattInfMapper">
    <select id="getMaxdevId" resultType="java.lang.Integer">
        select ifnull(max(dev_id),0) from  db_station.tb_batt_inf where dev_id>0;
    </select>
    <select id="getMaxBattGroupId" resultType="java.lang.Integer">
        select ifnull(max(battgroup_id),0) from  db_station.tb_batt_inf where battgroup_id>0;
    </select>
    <select id="getBatt" resultType="com.whyc.pojo.db_station.BattInf">
        select tb_batt_inf.*,tb_station_inf.station_name,tb_power_inf.power_name
        from db_station.tb_power_inf,db_station.tb_station_inf,db_station.tb_batt_inf
        where tb_batt_inf.station_id=tb_station_inf.station_id
          and tb_batt_inf.power_id=tb_power_inf.power_id
        <if test="provice!=null">
            and tb_station_inf.provice=#{provice}
        </if>
        <if test="city!=null">
            and tb_station_inf.city=#{city}
        </if>
        <if test="country!=null">
            and tb_station_inf.country=#{country}
        </if>
        <if test="stationName!=null">
            and tb_station_inf.station_name like concat('%',#{stationName},'%')
        </if>
        <if test="powerName!=null">
            and tb_power_inf.power_name like concat('%',#{powerName},'%')
        </if>
        <if test="battgroupName!=null">
            and tb_batt_inf.battgroup_name like concat('%',#{battgroupName},'%')
        </if>
        <if test="uid>100">
            and tb_power_inf.power_id in(
            select distinct power_id from db_user.tb_baojigroup_power,db_user.tb_baojigroup_usr
            where   tb_baojigroup_power.baoji_group_id=tb_baojigroup_usr.baoji_group_id
            and tb_baojigroup_usr.uid=#{uid}
            )
        </if>
    </select>
</mapper>