package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.whyc.dto.BattInfAndEnduranceDTO; import com.whyc.dto.Response; 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; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; import static com.whyc.util.ActionUtil.createFilefolderIFNotExist; @Service public class BattInfService { @Resource private BattInfMapper battInfMapper; @Resource private BattinfUpdateRecordMapper battinfUpdateRecordMapper; @Resource private Environment environment; @Resource private PowerInfService powerInfService; @Autowired private StationInfService stationInfService; @Resource private CommonMapper commonMapper; @Autowired private BattRtdataService battRtdataService; @Autowired private BattRsalarmService battRsalarmService; @Autowired private BattRtalarmService battRtalarmService; @Autowired 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(); if (id == null) { id = 0; } return id + 1; } public String searchMaxId_zj() { Integer id = battInfMapper.getMaxStationId_zj(); id = id == null ? id = 0 : id; return (id + 1) + ""; } /** * 获取下个站点编号,替代 searchMaxId_zj * @return */ public String getNextStationId() { String maxStationId = stationInfService.getMaxStationId(); return (Integer.parseInt(maxStationId) + 1) + ""; } public int searchMaxDevId(Integer fbsDeviceId){ Integer devId = battInfMapper.getMaxDevId(fbsDeviceId); if(devId == null){ int length = String.valueOf(fbsDeviceId).length(); switch (length){ case 3: devId = fbsDeviceId*1000000;break; case 4: devId = fbsDeviceId*100000;break; case 5: devId = fbsDeviceId*10000;break; case 6: devId = fbsDeviceId*1000;break; /*case 9100: case 9110: case 9120: case 9605: devId = fbsDeviceId*100000;break; case 61850: case 71850: devId = fbsDeviceId*10000;break; default: devId= fbsDeviceId*100000;break;*/ } //设备从未添加,则末位从10开始 devId+=9; } devId+=1; return devId; } //从数据库读取最大的电源设备id+1作为新增设备的id,设备id为8位数 public int getPowerDeviceId(Integer powerDeviceType) { Integer devId = battInfMapper.getMaxPowerDeviceId(powerDeviceType); if(devId==null||devId==0){ /*switch (powerDeviceType){ //电源系统 case 110: //绝缘装置 case 111: //充电机 case 112: //空调系统 case 113: //视频系统 case 114: devId = powerDeviceType*1000000;break; }*/ devId = powerDeviceType*1000000; } devId+=1; return devId; } public Response searchAllStationName1 (Integer uId){ List list = battInfMapper.getStationName1ByUserId(uId); return new Response().set(1,list,"查询成功"); } public Response searchAllStationName2 (Integer uId,String stationName1){ List list = battInfMapper.getStationName2ByUseridAndSt1(uId,stationName1); return new Response().set(1,list,"查询成功"); } public Response searchAllStationName5 (Integer uId,String stationName1,String stationName2){ List list = battInfMapper.getStationName5ByUseridAndSt1AndSt2(stationName1,stationName2,uId); return new Response().set(1,list,"查询成功"); } public Response searchAllStationName(Integer uId,String stationName1,String stationName2,String stationName5){ List list = battInfMapper.getAllStationName(uId,stationName1,stationName2,stationName5); return new Response().set(1,list,"查询成功"); } public Response searchBattGroupByStationName (Integer uId,String stationName1,String stationName){ List list = battInfMapper.getBattgroupListByStationNameAndStationName1(uId,stationName1,stationName); return new Response().set(1,list,"查询成功"); } public Response searchStationNameInGroup(Integer uId,String stationName1){ List list = battInfMapper.getStationNameInGroup(uId,stationName1); return new Response().set(1,list,"查询成功"); } public Response searchStationNameInGroup2(Integer uId,String stationName1){ List 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(); battinf.setBattGroupId(battGroupId); //String stationId = searchMaxId_zj();//BattinfGroupFactory.searchStationId(); //从站点表中获取下个站点id String stationId = getNextStationId();//BattinfGroupFactory.searchStationId(); battinf.setStationId(stationId); int dev_id = searchMaxDevId(battinf.getFBSDeviceId().intValue()); Battinf bst3 = battInfMapper.judgeBattStationName3(battinf); if (bst3!=null){ //存在,无需新建站点记录 battinf.setStationId(bst3.getStationId()); Battinf bst = battInfMapper.judgeBattStationName(battinf.getStationName(),battinf.getFBSDeviceName()); if (bst!=null){ battinf.setFBSDeviceId(bst.getFBSDeviceId()); }else { battinf.setFBSDeviceId((long) dev_id); } }else { //站点不存在,需要新建站点记录 StationInf station = new StationInf(); station.setStationId(stationId); station.setStationName(battinf.getStationName()); station.setStationName1(battinf.getStationName1()); station.setStationName2(battinf.getStationName2()); station.setStationName3(battinf.getStationName3()); station.setStationName4(battinf.getStationName4()); station.setStationName5(battinf.getStationName5()); station.setTogetherFlag(sinfMapper.getMaxTogetherFlag()); if(battinf.getStationName9()!=null){//苏州地铁标注为几号线地铁线路(3.5.6.7.8) } stationInfService.insertStation(station); battinf.setStationId(stationId); battinf.setFBSDeviceId((long) dev_id); } battInfMapper.insert(battinf); battInfMapper.insertUserBattgroupBaojigroupBattgroup(battinf.getStationId(),battinf.getBattGroupId()); battInfMapper.insertUserBattgroupBaojigroupBattgroupSelect(battinf.getStationId(),battinf.getBattGroupId(),userId); doAfterBattGroupChange(battinf.getBattGroupId()); //run_cmd(); return new Response().set(1,battinf,"添加成功"); } /** * 新:从站点表校验站点是否存在 * 旧:电源添加前校验是否站点存在,从电池表+电源表查询,弃用 * */ public Battinf judgeBattStationName3(PowerInf powerInf){ Battinf battinf = new Battinf(); battinf.setStationName1(powerInf.getStationName1()); battinf.setStationName2(powerInf.getStationName2()); battinf.setStationName3(powerInf.getStationName3()); battinf.setStationName5(powerInf.getStationName5()); return battInfMapper.judgeBattStationName3(battinf); } public void insertUserBattgroupBaojigroupBattgroupSelect(String stationId,int battGroupId,int userId){ battInfMapper.insertUserBattgroupBaojigroupBattgroupSelect(stationId,battGroupId,userId); } //启动创建数据库的jar文件 public void run_cmd() { int configType = Integer.parseInt(environment.getProperty("configFile.type")); ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); String path = ""; //测试版 if (configType == 1) { path = jarFile.getParentFile().toString(); } else { //打包版 path = jarFile.toString(); } //识别服务器的系统类型 String OS = System.getProperty("os.name").toLowerCase(); String strcmd = ""; if (OS.contains("window")) { //String batPath = path + File.separator + "cmd" + File.separator + "cmd_BTSE_DB_Builder.cmd"; String jarPath = path + File.separator + "BTSE_DB_Builder.exe"; //主程序中jar的目录 strcmd = ("cmd /c start ") + jarPath.replaceAll(" ", "\" \""); } else { strcmd = "java -jar /app/BTSE_DB_Builder.jar"; } //System.out.println(path); //修复绝对路径中存在空格时执行不成功bug Process child = null; InputStream in = null; try { //System.out.println(strcmd); child = Runtime.getRuntime().exec(strcmd); in = child.getInputStream(); int c; while ((c = in.read()) != -1) { //System.out.print((char)c); } in.close(); try { child.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } //System.out.println("Run Bat OK...."); } catch (IOException e) { e.printStackTrace(); } } public Response searchInfo(int pageNum,int pageSize,Integer userId,String stationName1,String stationName2,String stationName5,String stationName3){ PageHelper.startPage(pageNum,pageSize); List list = battInfMapper.searchInform(userId, stationName1, stationName2,stationName5, stationName3); PageInfo pageInfo = new PageInfo<>(list); return new Response().set(1,pageInfo,"查询成功"); } @Transactional public void deleteByBattgroupId(Integer battgroupId){ QueryWrapper wrapper = new QueryWrapper().eq("battgroupId",battgroupId); battInfMapper.delete(wrapper); //删除包机组下电池组 QueryWrapper bjWrapper = new QueryWrapper().eq("battgroupId",battgroupId); bjBattMapper.delete(bjWrapper); //删除电池组后操作 doAfterBattGroupChange(battgroupId); } @Transactional public Response update(Battinf battinf) { //1.查询更新前的记录 QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("battGroupId", battinf.getBattGroupId()); wrapper.last("limit 1"); Battinf binf = battInfMapper.selectOne(wrapper); binf.setUpdateReason(battinf.getUpdateReason()); if (battInfMapper.updateById(battinf) > 0) { doAfterBattGroupChange(battinf.getBattGroupId()); //run_cmd(); //将更新前的记录记录下来BattinfUpdateRecord BattinfUpdateRecord binBattinfUpdateRecord = new BattinfUpdateRecord(); BeanUtils.copyProperties(binf, binBattinfUpdateRecord); binBattinfUpdateRecord.setRecordTime(new Date()); binBattinfUpdateRecord.setUpdateName(ActionUtil.getUser().getUName()); battinfUpdateRecordMapper.insert(binBattinfUpdateRecord); return new Response().set(1, "更新成功"); } else { return new Response().set(0, "更新失败"); } } public Response updateList(List battinfs){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("dev_num",battinfs.get(0).getDevNum()); List list = battInfMapper.selectList(queryWrapper); for (Battinf batt:list) { batt.setDevNum(0+""); battInfMapper.updateById(batt); } for (Battinf battinf:battinfs) { battInfMapper.updateById(battinf); } //run_cmd(); return new Response().set(1,"更新成功"); } public Response updateIp(Battinf battinf){ UpdateWrapper updateWrapper = new UpdateWrapper(); updateWrapper.eq("FBSDeviceId",battinf.getFBSDeviceId()); int affectRows = battInfMapper.update(battinf,updateWrapper); if (affectRows>0){ return new Response().set(1,true,"更新成功"); }else { return new Response().set(1, false, "更新失败"); } } public Response findByBattGroupId(int battGroupId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("battgroupid", battGroupId); List list = battInfMapper.selectList(queryWrapper); return new Response().set(1, list, "查询成功"); } //根据电池组id获取设备id历史数据导出报表使用 public Battinf getdevIdByBattGroupId(int battGroupId) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("battgroupid", battGroupId); queryWrapper.last("limit 1"); Battinf binf = battInfMapper.selectOne(queryWrapper); return binf; } public Response searchBattProducer() { List list = battInfMapper.getAllBattProducer(); return new Response().set(1, list); } public Response updatePublicKeyByDevId(String publicKey, Integer deviceId) { if (battInfMapper.updatePublicKeyByDevId(publicKey, deviceId) > 0) { return new Response().set(1, true, "更新成功"); } else { return new Response().set(1, false, "更新失败"); } } public void addBatch(List battInfList) { battInfMapper.insertBatchSomeColumn(battInfList); } public List getStationList(int userId) { return battInfMapper.getStationList(userId); } public Response searchNotInBattMapByUid(int uId){ List list = battInfMapper.searchNotInBattMapByUid(uId); return new Response().set(1,list,"查询成功"); } public List getBattGroupInfoByFBSDeviceId(int fbsDeviceId) { QueryWrapper queryWrapper = Wrappers.query(); queryWrapper.select("BattGroupId","stationName1","stationName2","stationName3","stationName4","stationName5","BattGroupName","GroupIndexInFBSDevice","MonVolStd","MonCapStd","MonResStd","MonSerStd","MonTmpStd").eq("FBSDeviceId",fbsDeviceId); return battInfMapper.selectList(queryWrapper); } public Response findUseYear(int uId){ HashMap map = new HashMap<>(); int yearBelowThree = 0; int yearBetweenThreeAndFive = 0; int yearBetweenFiveAndSeven = 0; int yearAboveSeven = 0; List list = battInfMapper.findUseYear(uId); //查询1年内~7年内,7年以上,含头不含尾 map.put("1年内", (int) list.stream().filter(item -> item <1).count()); map.put("2年内", (int) list.stream().filter(item -> item < 2).count()); map.put("3年内", (int) list.stream().filter(item -> item < 3).count()); map.put("4年内", (int) list.stream().filter(item -> item < 4).count()); map.put("5年内", (int) list.stream().filter(item -> item < 5).count()); map.put("6年内", (int) list.stream().filter(item -> item < 6).count()); map.put("7年内", (int) list.stream().filter(item -> item < 7).count()); map.put("7年以上", (int) list.stream().filter(item -> item >= 7).count()); /*for (int year:list){ if(year<3){ yearBelowThree+=1; }else if(year<5){ yearBetweenThreeAndFive+=1; }else if(year<7){ yearBetweenFiveAndSeven+=1; }else{ yearAboveSeven+=1; } } map.put("3年内",yearBelowThree); map.put("3-5年",yearBetweenThreeAndFive); map.put("5-7年",yearBetweenFiveAndSeven); map.put("7年以上",yearAboveSeven);*/ return new Response().set(1,map,"查询成功"); } public Response findBattProducer(int uId){ List list = battInfMapper.findBattProducer(uId); return new Response().set(1,list,"查询成功"); } public Response findBattProducerInfoByProducerName(String battProducer,int uId){ List list = battInfMapper.findBattProducerInfoByProducerName(battProducer,uId); return new Response().set(1,list,"查询成功"); } /** * yearCode: * 1:1年以内 * ... * 7:7年以内 * 8:7年以上 * @param year * @param uId * @return */ public Response findBattProducerInfoByYearCode(int year,int uId){ List list = battInfMapper.findBattProducerInfoByYearCode(year,uId); return new Response().set(1,list,"查询成功"); } public Response findBattProducerInfoByTime(Date startTime,Date endTime, int uId){ List list = battInfMapper.findBattProducerInfoByTime(startTime,endTime,uId); return new Response().set(1,list,"查询成功"); } public Response findBattInfoByStationId(String stationId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("stationId",stationId); List list = battInfMapper.selectList(queryWrapper); return new Response().set(1,list,"查询成功"); } //-----------根据蓄电池组查不重复的MonCount(monNum)(单体编号) public Response searchByMonNum(int battGroupId){ List list = battInfMapper.searchByMonNum(battGroupId); for (Battinf inf:list) { inf.setMonNum(Integer.parseInt(inf.getSignalName().split("#")[0])); } return new Response().set(1,list,"查询成功"); } public List getStationList8059(Long uId) { return battInfMapper.getStationList8059(uId); } //取出电池组信息构建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()+ "-" + binf.getStationName4() + "-" + ThreadLocalUtil.format(binf.getBattProductDate(),2).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName(); return excelName; } //取出电池组信息构建excel文件的名称A059 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() + "-" + binf.getStationName4() + "-" + binf.getBattProducer() + binf.getMonCapStd() + "AH" + (binf.getGroupIndexInFBSDevice() + 1) + "组" + "-" + stateFlag; return excelName; } public Response uploadPicOfStation(List file, String stationId) { //过滤特殊字符,避免路径遍历攻击 stationId = ActionUtil.filterFileName(stationId); String fileDirName = ""; int configType = Integer.parseInt(environment.getProperty("configFile.type")); ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); //测试版 if (configType == 1) { fileDirName = jarFile.getParentFile().toString(); } else { //打包版 fileDirName = jarFile.toString(); } String root=fileDirName+"/fg_photo/stationsrc/"+ stationId + "/"; List filePathList = new ArrayList<>(); boolean isSuccess = false; try { for (int i = 0; i < file.size() && stationId != null; i++) { String fileFileName = file.get(i).getOriginalFilename(); String filePath = root + fileFileName; createFilefolderIFNotExist(filePath); file.get(i).transferTo(new File(filePath)); isSuccess = true; filePathList.add(filePath); } } catch (IOException e) { e.printStackTrace(); } if (isSuccess) { return new Response().set(1,filePathList,"上传成功"); } else { return new Response().set(0,false,"上传失败"); } } public Response deletePic(String stationId,List fileNames){ String fileDirName = ""; int configType = Integer.parseInt(environment.getProperty("configFile.type")); ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); //测试版 if(configType==1){ fileDirName = jarFile.getParentFile().toString(); }else{ //打包版 fileDirName = jarFile.toString(); } boolean deleted = false; //过滤特殊字符,避免路径遍历攻击 stationId = ActionUtil.filterFileName(stationId); String root=fileDirName+"/fg_photo/stationsrc/"+ stationId + "/"; for (int i = 0; i < fileNames.size(); i++) { String fileName = fileNames.get(i); //过滤特殊字符,避免路径遍历攻击 fileName = ActionUtil.filterFileName(fileName); File file = new File(root+ fileName); if (file.exists()&&file.isFile()){ deleted = file.delete(); }else { continue; } } if(deleted){ return new Response().set(1,true,"删除成功"); }else { return new Response().set(1,false,"删除失败"); } } public Response getStationPic(String stationId){ //过滤特殊字符,避免路径遍历攻击 stationId = ActionUtil.filterFileName(stationId); String fileDirName = ""; int configType = Integer.parseInt(environment.getProperty("configFile.type")); ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); //测试版 if(configType==1){ fileDirName = jarFile.getParentFile().toString(); }else{ //打包版 fileDirName = jarFile.toString(); } String root=fileDirName+"/fg_photo/stationsrc/"+ stationId ; File f = new File(root); System.out.println("文件路径"+root); // 路径不存在 if(!f.exists()){ return new Response().set(1,false,stationId+"站点暂未上传图片"); } File result[] = f.listFiles(); List fileNames = new ArrayList<>(); // 循环遍历 for(int i = 0; i queryWrapper = Wrappers.query(); queryWrapper.select("MonVolStd", "MonCount", "cellShowType","NomCapWH","NomCapAH","acdc_secuity_flag","Load_curr").eq("BattGroupId", battGroupId); return battInfMapper.selectOne(queryWrapper); } public Response updateMonCapWH(Battinf inf) { Float nomCapWH = inf.getNomCapWH(); Float nomCapAH = nomCapWH*1000/53.5f; UpdateWrapper update = Wrappers.update(); update.set("NomCapWH",nomCapWH).set("NomCapAH",nomCapAH).eq("battGroupId",inf.getBattGroupId()); battInfMapper.update((Battinf) ActionUtil.objeNull,update); return new Response().setII(1,"修改完成"); } /** * 获取电池,设备,电源,机房站点 计数/管理元首页:基础资源信息 * * 设备的数量统计和设备状态的统计,逻辑是不同的,数据库筛选的时候条件逻辑必定是不同的: TODO * 通常情况下,设备数量统计,要排除掉一个设备两个id的一拖二情况; * 而设备状态统计,只需要区分一个设备的字段,一个设备有多条记录也是正常合理的,通过状态优先级覆盖来定义整个设备的状态 * * @param userId * @return */ public Response getDevCountMap(int userId) { try { Map map = new HashMap<>(); int battGroupCount = battInfMapper.getBattGroupNum(userId); int devCount = battInfMapper.getDevNum(userId); int powerNum = powerInfService.getNum(userId); List stationInfList = stationInfService.getStationInfList(userId); int stationNum = stationInfService.getStation(userId); int hrDisNum = testInfService.getHrQuarterZC(userId); 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 Response getDevCountMapForSZ(int userId) { try { Map map = new HashMap<>(); int battGroupCount = battInfMapper.getBattGroupNum(userId); //电池单体总数 int battGroupMonCount = battInfMapper.getBattGroupMonNum(userId); int devCount = battInfMapper.getDevNum(userId); int powerNum = powerInfService.getNum(userId); List 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 map = new HashMap<>(); int battGroupCount = battInfMapper.getBattGroupNumJY(); int devCount = battInfMapper.getDevNumJY(); int powerNum = powerInfService.getNumJY(); List 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 getBattGroupList(int userId) { return battInfMapper.getBattGroupList(userId); } //山西晋源特定接口 public List getBattGroupListJY() { return battInfMapper.getBattGroupListJY(); } //管理员首页:基础资源信息 @Transactional public Response getBattInfoAnalysis(int userId) { try { Map map = new HashMap<>(); int battGroupCount = battInfMapper.getBattGroupNum(userId); //电源机房总数 int powerNum = powerInfService.getNum(userId); //int monNum = battInfMapper.getMonCount(userId); //电池机房总数 //int battStationNum = battInfMapper.geStationCount(userId); //总机房 int stationNum = stationInfService.getStation(userId); //设备数 int deviceNum = battInfMapper.getDevNum(userId); /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3) int hrDisNum = testInfService.getHrQuarter(userId); * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下: stop_type: 2-放电时间到终止并且放电时间超过2小时 3-放电容量到终止 4-单体电压下限到终止 6-组端电压下限到终止*/ int hrDisNum = testInfService.getHrQuarterZC(userId); //map.put("monNum", monNum);//单体 //map.put("battStationNum", battStationNum);//站点 map.put("battGroupCount", battGroupCount);//电池组 map.put("powerNum", powerNum);//电源 map.put("stationNum", stationNum);//总机房 map.put("hrDisNum", hrDisNum);//本年度核容放电电池组 map.put("deviceNum", deviceNum);//本年度核容放电电池组 return new Response().setII(1, true, map, "基础资源信息"); } catch (Exception e) { return new Response<>().set(1, false, "发生异常:" + e.getCause()); } } //管理员首页:站点信息 public List getSateAnalysis(int userId) { List list = battInfMapper.getSateAnalysis(userId); return list; } /** * 电池组 新增/编辑/删除后执行 */ public void doAfterBattGroupChange(int battGroupId){ createBattState_RT_RamDB_Table(); createBattData_RT_RamDB_Table(battGroupId); createTb_Batt_RSAlarm_Table(); createTb_Batt_RTAlarm_Table(battGroupId); setUpThreadRestart(); updateTb_App_Sys_AppServerTable(); } /** * 创建tb_batt_rtstate数据库表,并且将bd_al数组中的BattGroupId数据插入到表中" `db_ram_db`.tb_batt_rtstate" */ public void createBattState_RT_RamDB_Table() { //添加未录入电池组的组端信息 commonMapper.createBattState_RT_RamDB_Table(); } /** * 创建tb_batt_rtdata表并且根据集合bd_al,向表中添加电池组id和mon_num 值 "`db_ram_db`.tb_batt_rtdata" * @param battGroupId */ public void createBattData_RT_RamDB_Table(int battGroupId) { List battInfList = getBattInfList(battGroupId); for (Battinf battInf : battInfList) { int bg_id = battInf.getBattGroupId(); System.out.println("执行到了:"+bg_id); int mon_cnt = battInf.getMonCount(); int pack_count = battInf.getPackCount(); int FBSDeviceId = battInf.getFBSDeviceId().intValue(); if (checkLiBTSDevType(FBSDeviceId) && pack_count > 0) { mon_cnt = mon_cnt * pack_count; } if (mon_cnt > 0) { //当前电池组在 tb_batt_rtdata 表中的最大单体个数 int max_monnum = battRtdataService.seachBattMaxMonNum(bg_id); if (mon_cnt > max_monnum) { //需要从max_monnum开始添加单体记录 List monNumList = new LinkedList<>(); for (int mc = max_monnum; mc < mon_cnt; mc++) { monNumList.add(mc + 1); } battRtdataService.insertMonRecord(bg_id, monNumList); } else if (mon_cnt < max_monnum) { //删除当前电池组中超过单体个数的数据 battRtdataService.deleteWhenMonNumBeyond(bg_id, mon_cnt); } } } } private List getBattInfList(int battGroupId) { QueryWrapper query = Wrappers.query(); query.select("BattGroupId","MonCount","FBSDeviceId","PackCount").eq("BattGroupId",battGroupId); return battInfMapper.selectList(query); } /** * 创建组端信息告警记录表 `db_ram_db`.`tb_batt_rsalarm` */ public void createTb_Batt_RSAlarm_Table() { //添加未录入电池组的组端信息 battRsalarmService.addBattGroupIdsNoRecorded(); } /** * 创建单体信息告警记录表 "`db_ram_db`.`tb_batt_rtalarm`" * @param battGroupId */ public void createTb_Batt_RTAlarm_Table(int battGroupId) { List battInfList = getBattInfList(battGroupId); for (Battinf battInf : battInfList) { int bg_id = battInf.getBattGroupId(); int mon_cnt = battInf.getMonCount(); int pack_count = battInf.getPackCount(); int FBSDeviceId = battInf.getFBSDeviceId().intValue(); if (checkLiBTSDevType(FBSDeviceId) && pack_count > 0) { mon_cnt = mon_cnt * pack_count; } if (mon_cnt > 0) { //当前电池组在 tb_batt_rtalarm 表中的最大单体个数 int max_monnum = battRtalarmService.seachBattRTAlarmMaxMonNum(bg_id); if (mon_cnt > max_monnum) { //需要从max_monnum开始添加单体记录 List monNumList = new LinkedList<>(); for (int mc = max_monnum; mc < mon_cnt; mc++) { monNumList.add(mc + 1); } battRtalarmService.insertMonRecord(bg_id, monNumList); } else if (mon_cnt < max_monnum) { //删除当前电池组中超过单体个数的数据 battRtalarmService.deleteWhenMonNumBeyond(bg_id, mon_cnt); } } } } /** * 设置指定的线程重启[ 告警线程; ] "`web_site`.`tb_process_survey`" */ public void setUpThreadRestart() { processSurveyService.setUpThreadRestart(); } /** * 让主程序重新导入单体数据关键字改成true db_app_sys.tb_app_sys */ public void updateTb_App_Sys_AppServerTable() { String tableName = commonMapper.existTable("db_app_sys", "tb_app_sys"); if(tableName!=null) { //存在表 commonMapper.updateTb_App_Sys_AppServerTable(); } } /** * 校验当前设备是否是锂电BTS * * @param fbsDeviceId * @return */ private boolean checkLiBTSDevType(int fbsDeviceId) { if (fbsDeviceId / 100000 == 9131) { return true; } return false; } //查询标称电压类别 public Response searchMonVol() { List list = battInfMapper.searchMonVol(); return new Response().setII(1, list.size() > 0 ? true : false, list, "查询标称电压类别"); } //根据设备id查询电池组id(取第一个) public Response searchBattGroupIdByDevId(int devId) { String battGroupId = battInfMapper.searchBattGroupIdByDevId(devId); return new Response().setII(1, battGroupId != null, battGroupId != null ? battGroupId : "0", "返回电池组id"); } public String getStationIdByBattGroupId(Integer battGroupId) { QueryWrapper query = Wrappers.query(); query.eq("BattGroupId",battGroupId).last(" limit 1"); return battInfMapper.selectOne(query).getStationId(); } public String getStationIdByDeviceId(Integer deviceId) { QueryWrapper query = Wrappers.query(); query.eq("FBSDeviceId",deviceId).last(" limit 1"); return battInfMapper.selectOne(query).getStationId(); } //天一电厂获取用户管理的电池组实时数据 public Response selectTydc3DRealTimeInfo(Long uId) { List list=battInfMapper.selectTydc3DRealTimeInfo(uId); return new Response().setII(1,list!=null,list,"用户管理的电池组实时数据"); } public List getStationIds() { QueryWrapper query = Wrappers.query(); query.select("distinct StationId as StationId"); List battinfs = battInfMapper.selectList(query); return battinfs.stream().map(Battinf::getStationId).collect(Collectors.toList()); } public List getBattListByStatoinId(String stationId) { QueryWrapper query = Wrappers.query(); query.eq("StationId",stationId); return battInfMapper.selectList(query); } //取第一组电池信息 public Response getPowerHr6159(int devId) { QueryWrapper 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 map){ Map 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 map=new HashMap<>(); //setDefalut(map); Map allmap=new HashMap<>(); int stionNum=0; int devNum=0; int battNum=0; try { //查询battinf表中所有电池组信息 List list=battInfMapper.getAllInfInSz2(userId); Map> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9)); for (String stationName9 : ListMap.keySet()) { Map battInfoMap = new HashMap<>(); battInfoMap.put("stionNum",0); battInfoMap.put("devNum",0); battInfoMap.put("battNum",0); List name9List=ListMap.get(stationName9); Map> stationMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getStationId)); battInfoMap.put("stionNum",stationMap.size()); stionNum+=stationMap.size(); Map> devMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getFBSDeviceId)); battInfoMap.put("devNum",devMap.size()); devNum+=devMap.size(); Map> 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 map=new HashMap<>(); try { //查询battinf表中所有机房信息 List list=battInfMapper.getAllStationInSz2(userId); Map> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9)); for (String stationName9 : ListMap.keySet()) { List 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,""); } } }