whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/BattInfService.java
@@ -7,14 +7,10 @@
import com.github.pagehelper.PageInfo;
import com.whyc.dto.BattInfAndEnduranceDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.BattinfUpdateRecordMapper;
import com.whyc.mapper.CommonMapper;
import com.whyc.pojo.Battinf;
import com.whyc.pojo.BattinfUpdateRecord;
import com.whyc.pojo.PowerInf;
import com.whyc.pojo.StationInf;
import com.whyc.mapper.*;
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
@@ -28,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import static com.whyc.util.ActionUtil.createFilefolderIFNotExist;
@@ -55,6 +52,15 @@
    private ProcessSurveyService processSurveyService;
    @Autowired
    private BatttestdataInfService testInfService;
    @Autowired(required = false)
    private StationInfMapper sinfMapper;
    @Autowired(required = false)
    private BaoJiGroupBattGroupMapper bjBattMapper;
    @Autowired(required = false)
    private DevalarmDataMapper devAlmMapper;
    public int searchMaxBattgroupId_zj() {
        Integer id = battInfMapper.getMaxBattGroupId_zj();
@@ -167,6 +173,11 @@
        return new Response().set(1,list,"查询成功");
    }
    public Response searchStationNameInGroup2(Integer uId,String stationName1){
        List<Battinf> list = battInfMapper.getStationNameInGroup2(uId,stationName1);
        return new Response().set(1,list,"查询成功");
    }
    @Transactional
    public Response add(Battinf battinf,Integer userId){
        int battGroupId = searchMaxBattgroupId_zj();//BattinfGroupFactory.searchMaxBattgroupId();
@@ -195,8 +206,8 @@
            station.setStationName3(battinf.getStationName3());
            station.setStationName4(battinf.getStationName4());
            station.setStationName5(battinf.getStationName5());
            station.setTogetherFlag(sinfMapper.getMaxTogetherFlag());
            stationInfService.insertStation(station);
            battinf.setStationId(stationId);
            battinf.setFBSDeviceId((long) dev_id);
        }
@@ -286,6 +297,10 @@
    public void deleteByBattgroupId(Integer battgroupId){
        QueryWrapper<Battinf> wrapper = new QueryWrapper<Battinf>().eq("battgroupId",battgroupId);
        battInfMapper.delete(wrapper);
        //删除包机组下电池组
        QueryWrapper<BaojiGroupBattGroup> bjWrapper = new QueryWrapper<BaojiGroupBattGroup>().eq("battgroupId",battgroupId);
        bjBattMapper.delete(bjWrapper);
        //删除电池组后操作
        doAfterBattGroupChange(battgroupId);
    }
@@ -385,7 +400,7 @@
    public List<Battinf> getBattGroupInfoByFBSDeviceId(int fbsDeviceId) {
        QueryWrapper<Battinf> queryWrapper = Wrappers.query();
        queryWrapper.select("BattGroupId","BattGroupName").eq("FBSDeviceId",fbsDeviceId);
        queryWrapper.select("BattGroupId","stationName1","stationName2","stationName3","stationName4","stationName5","BattGroupName","GroupIndexInFBSDevice","MonVolStd","MonCapStd","MonResStd","MonSerStd","MonTmpStd").eq("FBSDeviceId",fbsDeviceId);
        return battInfMapper.selectList(queryWrapper);
    }
@@ -476,7 +491,9 @@
    //取出电池组信息构建excel文件的名称
    public String serchExcelName(int battGroupId) {
        Battinf binf = battInfMapper.serchExcelName(battGroupId);
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + ActionUtil.sdfwithOutday.format(binf.getBattProductDate()).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName();
        //String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + ActionUtil.sdfwithOutday.format(binf.getBattProductDate()).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName();
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3()+ "-" + binf.getStationName4()
                + "-" + ThreadLocalUtil.format(binf.getBattProductDate(),2).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName();
        return excelName;
    }
@@ -484,14 +501,14 @@
    public String serchExcelNameA059(int battGroupId, String stateFlag) {
        Battinf binf = battInfMapper.serchExcelName(battGroupId);
        //导出格式:内蒙古自治区-鄂尔多斯市-东胜区-中心局-理士400AH1组-2022-04-21-第1次放电
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" +
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + binf.getStationName4() + "-" +
                binf.getBattProducer() + binf.getMonCapStd() + "AH" + (binf.getGroupIndexInFBSDevice() + 1) + "组" + "-" + stateFlag;
        return excelName;
    }
    public Response uploadPicOfStation(List<MultipartFile> file, String stationId) {
        //过滤特殊字符,避免路径遍历攻击
        //过滤特殊字符,避免路径遍历攻击
        stationId = ActionUtil.filterFileName(stationId);
        String fileDirName = "";
        int configType = Integer.parseInt(environment.getProperty("configFile.type"));
@@ -598,7 +615,7 @@
    public Battinf getBattGroupInfoByBattGroupId(int battGroupId) {
        QueryWrapper<Battinf> queryWrapper = Wrappers.query();
        queryWrapper.select("MonVolStd", "MonCount", "cellShowType","NomCapWH","NomCapAH").eq("BattGroupId", battGroupId);
        queryWrapper.select("MonVolStd", "MonCount", "cellShowType","NomCapWH","NomCapAH","acdc_secuity_flag","Load_curr").eq("BattGroupId", battGroupId);
        return battInfMapper.selectOne(queryWrapper);
    }
@@ -607,12 +624,16 @@
        Float nomCapAH = nomCapWH*1000/53.5f;
        UpdateWrapper<Battinf> update = Wrappers.update();
        update.set("NomCapWH",nomCapWH).set("NomCapAH",nomCapAH).eq("battGroupId",inf.getBattGroupId());
        battInfMapper.update(null,update);
        battInfMapper.update((Battinf) ActionUtil.objeNull,update);
        return new Response().setII(1,"修改完成");
    }
    /**
     * 获取电池,设备,电源,机房站点 计数/管理元首页:基础资源信息
     *
     * 设备的数量统计和设备状态的统计,逻辑是不同的,数据库筛选的时候条件逻辑必定是不同的: TODO
     *  通常情况下,设备数量统计,要排除掉一个设备两个id的一拖二情况;
     *  而设备状态统计,只需要区分一个设备的字段,一个设备有多条记录也是正常合理的,通过状态优先级覆盖来定义整个设备的状态
     *
     * @param userId
     * @return
@@ -632,14 +653,65 @@
            map.put("stationNum",stationNum);
            map.put("stationInfList",stationInfList);
            map.put("checkCapNum",hrDisNum);
            return new Response().setII(1,true, map,null);
            return new Response().setII(1,true, map,"");
        }catch (Exception e){
            return new Response<>().set(1,false,"发生异常:"+e.getCause());
        }
    }
    public Response getDevCountMapForSZ(int userId) {
        try {
            Map<String, Object> map = new HashMap<>();
            int battGroupCount = battInfMapper.getBattGroupNum(userId);
            //电池单体总数
            int battGroupMonCount = battInfMapper.getBattGroupMonNum(userId);
            int devCount = battInfMapper.getDevNum(userId);
            int powerNum = powerInfService.getNum(userId);
            List<StationInf> stationInfList = stationInfService.getStationInfList(userId);
            int stationNum = stationInfService.getStation(userId);
            int hrDisNum = testInfService.getHrQuarterZC(userId);
            map.put("battGroupCount", battGroupCount);
            map.put("battGroupMonCount", battGroupMonCount);
            map.put("devCount", devCount);
            map.put("powerNum", powerNum);
            map.put("stationNum",stationNum);
            map.put("stationInfList",stationInfList);
            map.put("checkCapNum",hrDisNum);
            return new Response().setII(1,true, map,"");
        }catch (Exception e){
            return new Response<>().set(1,false,"发生异常:"+e.getCause());
        }
    }
    //山西晋源特定接口
    public Response getDevCountMapJY() {
        try {
            Map<String, Object> map = new HashMap<>();
            int battGroupCount = battInfMapper.getBattGroupNumJY();
            int devCount = battInfMapper.getDevNumJY();
            int powerNum = powerInfService.getNumJY();
            List<StationInf> stationInfList = stationInfService.getStationInfListJY();
            int stationNum = stationInfService.getStationJY();
            int hrDisNum = testInfService.getHrQuarterZCJY();
            map.put("battGroupCount", battGroupCount);
            map.put("devCount", devCount);
            map.put("powerNum", powerNum);
            map.put("stationNum",stationNum);
            map.put("stationInfList",stationInfList);
            map.put("checkCapNum",hrDisNum);
            return new Response().setII(1,true, map,"");
        }catch (Exception e){
            return new Response<>().set(1,false,"发生异常:"+e.getCause());
        }
    }
    //大屏
    public List<Battinf> getBattGroupList(int userId) {
        return battInfMapper.getBattGroupList(userId);
    }
    //山西晋源特定接口
    public List<Battinf> getBattGroupListJY() {
        return battInfMapper.getBattGroupListJY();
    }
    //管理员首页:基础资源信息
@@ -845,4 +917,132 @@
        List<Battinf> list=battInfMapper.selectTydc3DRealTimeInfo(uId);
        return new Response().setII(1,list!=null,list,"用户管理的电池组实时数据");
    }
    public List<String> getStationIds() {
        QueryWrapper<Battinf> query = Wrappers.query();
        query.select("distinct StationId as StationId");
        List<Battinf> battinfs = battInfMapper.selectList(query);
        return battinfs.stream().map(Battinf::getStationId).collect(Collectors.toList());
    }
    public List<Battinf> getBattListByStatoinId(String stationId) {
        QueryWrapper<Battinf> query = Wrappers.query();
        query.eq("StationId",stationId);
        return battInfMapper.selectList(query);
    }
    //取第一组电池信息
    public Response getPowerHr6159(int devId) {
        QueryWrapper<Battinf> query = Wrappers.query();
        query.eq("FBSDeviceId",devId).last(" limit 1").orderByAsc("battGroupId");
        Battinf binf=battInfMapper.selectOne(query);
        return new Response().setII(1,binf!=null,binf,"取第一组电池信息");
    }
   //keyid绑定设备id
    public Response setKeyIdWithDeviceId(Integer devId, String keyId) {
        //1.检测是否存在keyid的设备
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("KeyID",keyId);
        wrapper.last(" limit 1");
        Battinf binf=battInfMapper.selectOne(wrapper);
        int flag=0;
        if(binf!=null){
            //查询devId对应设备的ip
            QueryWrapper wrapper1=new QueryWrapper();
            wrapper1.eq("FBSDeviceId",devId);
            wrapper1.last(" limit 1");
            Battinf binf1=battInfMapper.selectOne(wrapper1);
            if(binf.getFBSDeviceIp().equals(binf1.getFBSDeviceIp())){
                flag=1;
            }else{
                flag=0;
            }
        }else{
            flag=1;
        }
        if(flag==1){
            UpdateWrapper updateWrapper=new UpdateWrapper();
            updateWrapper.set("KeyID",keyId);
            updateWrapper.eq("FBSDeviceId",devId);
            battInfMapper.update((Battinf) ActionUtil.objeNull,updateWrapper);
            return new Response().set(1,true,"keyid绑定设备id");
        }else {
            return new Response().set(1,false,"改ukey已绑定");
        }
    }
    //插入初始数据
    public void setDefalut( Map<String,Object> map){
        Map<String,Object> mapNum=new HashMap<>();
        mapNum.put("stionNum",0);
        mapNum.put("devNum",0);
        mapNum.put("battNum",0);
        map.put("3",mapNum);
        map.put("5",mapNum);
        map.put("6",mapNum);
        map.put("7",mapNum);
        map.put("8",mapNum);
    }
    //1统计机房个数,设备个数,电池组个数(苏州地铁)
    public Response getAllInfInSz2(Integer userId) {
        Map<String,Object> map=new HashMap<>();
        //setDefalut(map);
        Map<String,Object> allmap=new HashMap<>();
        int stionNum=0;
        int devNum=0;
        int battNum=0;
        try {
            //查询battinf表中所有电池组信息
            List<Battinf> list=battInfMapper.getAllInfInSz2(userId);
            Map<String, List<Battinf>> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9));
            for (String stationName9 : ListMap.keySet()) {
                Map<String, Object> battInfoMap = new HashMap<>();
                battInfoMap.put("stionNum",0);
                battInfoMap.put("devNum",0);
                battInfoMap.put("battNum",0);
                List<Battinf> name9List=ListMap.get(stationName9);
                Map<String, List<Battinf>> stationMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getStationId));
                battInfoMap.put("stionNum",stationMap.size());
                stionNum+=stationMap.size();
                Map<Long, List<Battinf>> devMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getFBSDeviceId));
                battInfoMap.put("devNum",devMap.size());
                devNum+=devMap.size();
                Map<Integer, List<Battinf>> battMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getBattGroupId));
                battInfoMap.put("battNum",battMap.size());
                map.put(stationName9,battInfoMap);
                battNum+=battMap.size();
            }
            allmap.put("stionNum",stionNum);
            allmap.put("devNum",devNum);
            allmap.put("battNum",battNum);
            map.put("allmap",allmap);
            return new Response<>().setII(1,true,map,"");
        } catch (Exception e) {
            return new Response<>().set(1,false,"");
        }
    }
    //4.中间地图
    public Response getAllStationInSz2(Integer userId) {
        Map<String,Object> map=new HashMap<>();
        try {
            //查询battinf表中所有机房信息
            List<Battinf> list=battInfMapper.getAllStationInSz2(userId);
            Map<String, List<Battinf>> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9));
            for (String stationName9 : ListMap.keySet())  {
                List<Battinf> name9List=ListMap.get(stationName9);
                for (Battinf binf:name9List) {
                    //判断机房下的设备告警是否都存在通讯告警 119020
                    int flag=devAlmMapper.judgeCommErr(binf.getStationId(),119020);
                    if(flag>0){
                        binf.setNote("0");
                    }else{
                        binf.setNote("1");
                    }
                }
                map.put(stationName9,name9List);
            }
            return new Response<>().setII(1,true,map,"");
        } catch (Exception e) {
            return new Response<>().set(1,false,"");
        }
    }
}