whycxzp
2025-03-25 bf60848c0d97d3f440eee20719010e49bc2aae2d
src/main/java/com/whyc/service/PowerInfService.java
@@ -7,10 +7,13 @@
import com.whyc.dto.Response;
import com.whyc.mapper.*;
import com.whyc.pojo.db_batt.PowerInf;
import com.whyc.pojo.db_batt.StationInf;
import com.whyc.pojo.db_batt.StationPowerRelation;
import com.whyc.pojo.db_power_alarm.PowerAlarm;
import com.whyc.pojo.db_real_batt.RtData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
@@ -36,6 +39,12 @@
    @Autowired(required = false)
    private PowerAlarmMapper pAlarmMapper;
    @Autowired
    private StationPowerRelationService stationPowerRelationService;
    @Autowired
    private StationInfService stationInfService;
    //根据id获取电源信息
    public  Map<String,Object> getInfById(int powerId) {
@@ -83,6 +92,7 @@
        return list;
    }
    @Transactional
    public Response add(PowerInf powerInf) {
        powerInf.setCreateTime(new Date());
        //对powerInf的 devType进行判断
@@ -98,6 +108,21 @@
        if(powerInf.getChannelCount() == null){
            powerInf.setChannelCount(1);
        }
        //电源id查询最大值
        int powerId = mapper.getMaxPowerId();
        powerInf.setPowerId(powerId);
        //对站点名称进行查询,如果存在则直接绑定关系
        //如果不存在,则新增后,再绑定关系
        StationInf stationInf = stationInfService.getByStationName(powerInf.getStationName());
        if(stationInf == null){
            StationInf stationNew = new StationInf();
            stationNew.setSinfName(powerInf.getStationName());
            int stationId = stationInfService.getMaxStationId();
            stationNew.setSinfId(stationId+1);
            stationInfService.add(stationNew);
            //站点和电源id关联
            stationPowerRelationService.add(stationId,powerId);
        }
        mapper.insert(powerInf);
        return new Response().setII(1,"新增完成");
    }