From 3470b33466cfd9ce423a46220ff81f734fae9fb7 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期五, 20 六月 2025 11:32:34 +0800 Subject: [PATCH] 预警分析管理-主属性和配置属性 --- src/main/java/com/whyc/service/BattInfService.java | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 385 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java index da95a13..3aa72bf 100644 --- a/src/main/java/com/whyc/service/BattInfService.java +++ b/src/main/java/com/whyc/service/BattInfService.java @@ -4,10 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.whyc.constant.BattCapperformanceEnum; import com.whyc.dto.BattDto; -import com.whyc.dto.PowerDto; +import com.whyc.dto.InfoDto; +import com.whyc.dto.Param.ParamAlmDto; +import com.whyc.dto.Real.QuarterDto; import com.whyc.dto.Response; +import com.whyc.dto.Statistic.*; +import com.whyc.factory.InfoFactory; import com.whyc.mapper.BattInfMapper; +import com.whyc.mapper.PowerInfMapper; +import com.whyc.mapper.StationInfMapper; import com.whyc.pojo.db_station.BattInf; import com.whyc.pojo.db_station.PowerInf; import com.whyc.pojo.db_station.StationInf; @@ -17,20 +24,31 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; @Service public class BattInfService { @Autowired(required = false) private BattInfMapper mapper; + @Autowired(required = false) + private PowerInfMapper pinfMapper; + + @Autowired(required = false) + private StationInfMapper sinfMapper; + + @Autowired(required = false) + private BaojigroupService bjService; + /*鏂板缓鐢垫睜缁勶紙鏂扮殑璁惧鏂扮殑鐢垫睜缁勶級 * @param binf * 1.鍦ㄧ數婧愪笅鏂板缓璁惧锛岃褰曡澶囩紪鍙凤紝devNum,璁惧鍚嶇О涓鸿澶囩被鍨�+devNum */ @Transactional - public Response addDev(BattInf adddinf) { + public void addDev(BattInf adddinf) { //妫�娴嬬數婧愪笅鏄惁瀛樺湪璁惧 int devNum=mapper.getMaxDevNum(adddinf.getPowerId()); if(devNum==0){ @@ -59,23 +77,43 @@ adddinf.setBattgroupNum(1); adddinf.setCreateTime(new Date()); mapper.insert(adddinf); - return new Response().set(1, true, "鏂板缓鐢垫睜缁勶紙鏂扮殑璁惧鏂扮殑鐢垫睜缁勶級"); } //璁惧涓嬫坊鍔犵數姹犵粍 @Transactional - public Response addBatt(BattInf addbinf) { - //鑾峰彇璁惧鐨勯�氱敤淇℃伅 - QueryWrapper wrapper=new QueryWrapper(); - wrapper.eq("dev_id",addbinf.getDevId()); - wrapper.select("dev_name","dev_type","dev_num","dev_ip","power_id","station_id"); - wrapper.last("limit 1"); - BattInf binf=mapper.selectOne(wrapper); - addbinf.setPowerId(binf.getPowerId()); - addbinf.setStationId(binf.getStationId()); - addbinf.setDevName(binf.getDevName()); - addbinf.setDevType(binf.getDevType()); - addbinf.setDevNum(binf.getDevNum()); - addbinf.setDevIp(binf.getDevIp()); + public void addBatt(BattInf addbinf) { + if(addbinf.getAddBinfFlag()==0){ + //鑾峰彇璁惧鐨勯�氱敤淇℃伅 + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("dev_id",addbinf.getDevId()); + wrapper.select("dev_name","dev_type","dev_num","dev_ip","power_id","station_id"); + wrapper.last("limit 1"); + BattInf binf=mapper.selectOne(wrapper); + addbinf.setPowerId(binf.getPowerId()); + addbinf.setStationId(binf.getStationId()); + addbinf.setDevName(binf.getDevName()); + addbinf.setDevType(binf.getDevType()); + addbinf.setDevNum(binf.getDevNum()); + addbinf.setDevIp(binf.getDevIp()); + }else{//鐢垫簮涓嬫柊寤轰竴涓澶� + //妫�娴嬬數婧愪笅鏄惁瀛樺湪璁惧 + int devNum=mapper.getMaxDevNum(addbinf.getPowerId()); + if(devNum==0){ + devNum=1; + }else{ + devNum+=1; + } + addbinf.setDevNum(devNum); + addbinf.setDevName(addbinf.getDevType()+devNum); + //鑾峰彇瀵瑰簲鐨勮澶噄d,鐢垫睜缁� + int devId = mapper.getMaxdevId(); + int battGroupId=mapper.getMaxBattGroupId(); + if (devId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 + devId = 10001; + } else { + devId += 1; + } + addbinf.setDevId(devId); + } //妫�娴嬭澶囦笅鏄惁瀛樺湪鐢垫睜缁� int battgroupNum=mapper.getMaxBattgroupNum(addbinf.getDevId()); if(battgroupNum==0){ @@ -95,20 +133,207 @@ addbinf.setBattgroupNum(battgroupNum); addbinf.setCreateTime(new Date()); mapper.insert(addbinf); - return new Response().set(1, true, "璁惧涓嬫坊鍔犵數姹犵粍"); } - //鍒犻櫎鐢垫簮 - public Response delBatt(Integer bid) { - UpdateWrapper wrapper=new UpdateWrapper(); - wrapper.eq("battgroup_id",bid); - mapper.delete(wrapper); + //鍒犻櫎鐢垫睜缁� + @Transactional + public Response delBatt(Integer stationId, Integer powerId,Integer battgroupId) { + List<BattInf> binfList=new ArrayList<>(); + if(battgroupId!=null){ + UpdateWrapper wrapper=new UpdateWrapper(); + wrapper.eq("battgroup_id",battgroupId); + mapper.delete(wrapper); + //妫�娴嬪鏋減owerId涓嬬數姹犵粍鍒犻櫎瀹屼簡,瑕佸皢鐢垫簮涔熷垹闄ゆ帀 + QueryWrapper wrapper1=new QueryWrapper(); + wrapper1.eq("power_id",powerId); + binfList=mapper.selectList(wrapper1); + } + if(binfList==null||binfList.size()==0){ + UpdateWrapper wrapper2=new UpdateWrapper(); + wrapper2.eq("power_id",powerId); + pinfMapper.delete(wrapper2); + //鍒犻櫎鎵�鏈夊寘鏈虹粍涓嬬殑鐢垫簮 + bjService.delPowerInBaoji(powerId); + //鍐嶆娴嬪鏋滄満鎴夸笅鐢垫簮涔熷叏鍒犻櫎浜嗭紝瑕佸皢鏈烘埧涔熷垹闄� + QueryWrapper wrapper3=new QueryWrapper(); + wrapper3.eq("station_id",stationId); + List<PowerInf> pinfList=pinfMapper.selectList(wrapper3); + if(pinfList==null||pinfList.size()==0){ + UpdateWrapper wrapper4=new UpdateWrapper(); + wrapper4.eq("station_id",stationId); + sinfMapper.delete(wrapper4); + //鍒犻櫎鎵�鏈夊寘鏈虹粍涓嬬殑鏈烘埧 + bjService.delStationInBaoji(stationId); + } + } return new Response().set(1,true); } - //淇敼鐢垫簮 + //缂栬緫鏈烘埧锛岀數婧愶紝鐢垫睜缁勪俊鎭� + @Transactional + public Response updateInfo(InfoDto info) { + //鍏堜慨鏀规満鎴夸俊鎭� + PowerInf pinf=InfoFactory.infoToPower(info); + StationInf sinf=pinf.getSinf(); + UpdateWrapper wrapper1=new UpdateWrapper(); + if(sinf.getStationName()!=null){ + //鍏堟煡鐪嬫満鎴垮悕鍜宻tationid鏄笉鏄尮閰嶇殑 + QueryWrapper wrapper2=new QueryWrapper(); + wrapper2.eq("station_id",sinf.getStationId()); + wrapper2.last("limit 1"); + StationInf s=sinfMapper.selectOne(wrapper2); + if(!s.getStationName().equalsIgnoreCase(sinf.getStationName())){ + wrapper1.set("station_name",sinf.getStationName()); + String fullName=sinf.getProvice()+"_"+sinf.getCity()+"_"+sinf.getCountry()+"_"+sinf.getStationName(); + //妫�娴嬭鏈烘埧涓嬭淇敼鐨勭數婧愬悕鏄惁瀛樺湪 + QueryWrapper queryWrapper=new QueryWrapper(); + queryWrapper.eq("full_name",fullName); + queryWrapper.last("limit 1"); + StationInf jueges=sinfMapper.selectOne(queryWrapper); + if(jueges!=null){ + return new Response().set(1,false,"宸插瓨鍦�"+fullName+"鐨勬満鎴�"); + } + wrapper1.set("full_name",fullName); + } + } + if(sinf.getStationType()!=null){ + wrapper1.set("station_type",sinf.getStationType()); + } + if(sinf.getLongitude()!=null){ + wrapper1.set("longitude",sinf.getLongitude()); + } + if(sinf.getLatitude()!=null){ + wrapper1.set("latitude",sinf.getLatitude()); + } + if(sinf.getNodeStation()!=null){ + wrapper1.set("node_station",sinf.getNodeStation()); + } + wrapper1.eq("station_id",sinf.getStationId()); + + //鍐嶄慨鏀圭數婧愪俊鎭� + UpdateWrapper wrapper2=new UpdateWrapper(); + if(pinf.getCompany()!=null){ + wrapper2.set("company",pinf.getCompany()); + } + if(pinf.getPowerModel()!=null){ + wrapper2.set("power_model",pinf.getPowerModel()); + } + if(pinf.getProtocol()!=null){ + wrapper2.set("protocol",pinf.getProtocol()); + } + if(pinf.getPowerIp()!=null){ + wrapper2.set("power_ip",pinf.getPowerIp()); + } + if(pinf.getPowerType()!=null){ + wrapper2.set("power_type",pinf.getPowerType()); + } + if(pinf.getPowerInuseTime()!=null){ + wrapper2.set("power_inuse_time",pinf.getPowerInuseTime()); + } + if(pinf.getModelCfg()!=null){ + wrapper2.set("model_cfg",pinf.getModelCfg()); + } + /*if(pinf.getPowerName()!=null){ + //妫�娴嬭鏈烘埧涓嬭淇敼鐨勭數婧愬悕鏄惁瀛樺湪 + QueryWrapper queryWrapper1=new QueryWrapper(); + queryWrapper1.eq("power_name",pinf.getPowerName()); + queryWrapper1.eq("station_id",sinf.getStationId()); + queryWrapper1.last("limit 1"); + PowerInf juegep=pinfMapper.selectOne(queryWrapper1); + if(juegep!=null){ + return new Response().set(1,false,"璇ユ満鎴夸笅宸插瓨鍦�"+pinf.getPowerName()+"鐨勭數婧�"); + } + wrapper2.set("power_name",pinf.getPowerName()); + }*/ + wrapper2.eq("power_id",pinf.getPowerId()); + + //鏈�鍚庝慨鏀硅澶囦俊鎭� + BattInf binf=InfoFactory.infoToBatt(info); + if(binf.getDevId()!=null) { + UpdateWrapper wrapper3 = new UpdateWrapper(); + if (binf.getDevIp() != null) { + wrapper3.set("dev_ip", binf.getDevIp()); + } + /* if (binf.getDevName() != null) { + //妫�娴嬭鐢垫簮涓嬩慨鏀圭殑璁惧鍚嶆槸鍚﹀瓨鍦� + QueryWrapper queryWrapper2 = new QueryWrapper(); + queryWrapper2.eq("dev_name", binf.getDevName()); + queryWrapper2.eq("power_id", pinf.getPowerId()); + queryWrapper2.last("limit 1"); + BattInf jueged = mapper.selectOne(queryWrapper2); + if (jueged != null) { + return new Response().set(1, false, "璇ョ數婧愪笅宸插瓨鍦�" + binf.getDevName() + "鐨勮澶�"); + } + wrapper3.set("dev_name", binf.getDevName()); + }*/ + /*if(binf.getDevType()!=null){ + wrapper3.set("dev_type",binf.getDevType()); + }*/ + wrapper3.eq("dev_id", binf.getDevId()); + + //淇敼鐢垫睜缁勪俊鎭� + UpdateWrapper wrapper4 = new UpdateWrapper(); + /*if (binf.getBattgroupName() != null) { + //妫�娴嬭鏈烘埧涓嬭淇敼鐨勭數婧愬悕鏄惁绮楀湪 + QueryWrapper queryWrapper3 = new QueryWrapper(); + queryWrapper3.eq("battgroup_name", binf.getBattgroupName()); + queryWrapper3.eq("dev_id", binf.getDevId()); + queryWrapper3.last("limit 1"); + BattInf juegeb = mapper.selectOne(queryWrapper3); + if (juegeb != null) { + return new Response().set(1, false, "璇ヨ澶囦笅宸插瓨鍦�" + binf.getBattgroupName() + "鐨勭數姹犵粍"); + } + wrapper4.set("battgroup_name", binf.getBattgroupName()); + }*/ + if (binf.getMonvolstd() != null) { + wrapper4.set("monvolstd", binf.getMonvolstd()); + } + if (binf.getMoncapstd() != null) { + wrapper4.set("moncapstd", binf.getMoncapstd()); + } + if (binf.getMonresstd() != null) { + wrapper4.set("monresstd", binf.getMonresstd()); + } + if (binf.getProduct() != null) { + wrapper4.set("product", binf.getProduct()); + } + if (binf.getMoncount() != null) { + wrapper4.set("moncount", binf.getMoncount()); + } + if (binf.getBattModel() != null) { + wrapper4.set("batt_model", binf.getBattModel()); + } + if (binf.getInuseTime() != null) { + wrapper4.set("inuse_time", binf.getInuseTime()); + } + wrapper4.eq("battgroup_id", binf.getBattgroupId()); + mapper.update((BattInf) ActionUtil.objeNull,wrapper3); + mapper.update((BattInf) ActionUtil.objeNull,wrapper4); + } + sinfMapper.update((StationInf) ActionUtil.objeNull,wrapper1); + pinfMapper.update((PowerInf) ActionUtil.objeNull,wrapper2); + return new Response().set(1,true,"淇敼淇℃伅鎴愬姛"); + } + /*//淇敼鐢垫睜缁� public Response updateBatt(BattInf binf) { + UpdateWrapper wrapper1=new UpdateWrapper(); + wrapper1.eq("dev_id",binf.getDevId()); + if(binf.getDevIp()!=null){ + wrapper1.set("dev_ip",binf.getDevIp()); + } + if(binf.getDevName()!=null){ + wrapper1.set("dev_name",binf.getDevName()); + } UpdateWrapper wrapper=new UpdateWrapper(); wrapper.eq("battgroup_id",binf.getBattgroupId()); if(binf.getBattgroupName()!=null){ + //妫�娴嬭鏈烘埧涓嬭淇敼鐨勭數婧愬悕鏄惁绮楀湪 + QueryWrapper queryWrapper=new QueryWrapper(); + queryWrapper.eq("battgroup_name",binf.getBattgroupName()); + queryWrapper.eq("dev_id",binf.getDevId()); + queryWrapper.last("limit 1"); + BattInf juegeb=mapper.selectOne(queryWrapper); + if(juegeb!=null){ + return new Response().set(1,false,"璇ヨ澶囦笅宸插瓨鍦�"+binf.getBattgroupName()+"鐨勭數姹犵粍"); + } wrapper.set("battgroup_name",binf.getBattgroupName()); } if(binf.getMonvolstd()!=null){ @@ -126,25 +351,151 @@ if(binf.getMoncount()!=null){ wrapper.set("moncount",binf.getMoncount()); } - if(binf.getModel()!=null){ - wrapper.set("model",binf.getModel()); + if(binf.getBattModel()!=null){ + wrapper.set("batt_model",binf.getBattModel()); } mapper.update((BattInf) ActionUtil.objeNull,wrapper); return new Response().set(1,true); - } - //鏌ヨ鐢垫睜 - public Response getBatt(BattDto dto) { + }*/ + //鏌ヨ鏈烘埧锛岀數婧愶紝鐢垫睜缁勪俊鎭� + public Response getInfo(BattDto dto) { User user= ActionUtil.getUser(); dto.setUid(user.getId()); PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); - List<BattInf> list=mapper.getBatt(dto); + List<InfoDto> list=mapper.getInfo(dto); PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鐢垫睜"); } - //鍒犻櫎鐢垫簮涓嬬殑鐢垫睜缁� - public void delBattInPower(Integer pid) { - UpdateWrapper wrapper=new UpdateWrapper(); - wrapper.eq("power_id",pid); - mapper.delete(wrapper); + + //鑾峰彇鐢垫睜鍝佺墝(涓嬫媺) + public Response getProductByUid(Integer uid) { + List<String> list=mapper.getProductByUid(uid); + return new Response().setII(1,list.size()>0,list,"鑾峰彇鐢垫睜鍝佺墝(涓嬫媺)"); + } + //鑾峰彇鏍囩О鍗曚綋鐢靛帇(涓嬫媺) + public Response getMonVolByUid(Integer uid) { + List<Float> list=mapper.getMonVolByUid(uid); + return new Response().setII(1,list.size()>0,list,"鑾峰彇鏍囩О鍗曚綋鐢靛帇(涓嬫媺)"); + } + + //鑾峰彇鏍囩О瀹归噺(涓嬫媺) + public Response getMonCapByUid(Integer uid) { + List<Float> list=mapper.getMonCapByUid(uid); + return new Response().setII(1,list.size()>0,list,"鑾峰彇鏍囩О瀹归噺(涓嬫媺)"); + } + + //鑾峰彇鏍囩О鍐呴樆(涓嬫媺) + public Response getMonResByUid(Integer uid) { + List<Float> list=mapper.getMonResByUid(uid); + return new Response().setII(1,list.size()>0,list,"鑾峰彇鏍囩О鍐呴樆(涓嬫媺)"); + } + //鑾峰彇璁惧鍨嬪彿(涓嬫媺) + public Response getDevTypeByUid(Integer uid) { + List<String> list=mapper.getDevTypeByUid(uid); + return new Response().setII(1,list.size()>0,list,"鑾峰彇璁惧鍨嬪彿(涓嬫媺)"); + } + + //鏍规嵁鐢垫睜缁刬d鑾峰彇鐢垫睜缁勪俊鎭� + public BattInf getBinfByBattgroupId(Integer battgroupId) { + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("battgroup_id",battgroupId); + wrapper.last("limit 1"); + BattInf binf=mapper.selectOne(wrapper); + return binf; + } + //褰撴病鏈夊唴鍔╂祴璇曟椂鍒濆鍐呴樆鍊间负鏍囩О鍐呴樆 + public List<QuarterDto> getBinfResStd(Integer battgroupId) { + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("battgroup_id",battgroupId); + wrapper.last("limit 1"); + BattInf binf=mapper.selectOne(wrapper); + Float monresstd=binf.getMonresstd(); + List<QuarterDto> list=new ArrayList<>(); + for(int i=0;i<binf.getMoncount();i++){ + QuarterDto dto=new QuarterDto(); + dto.setRecordTime(binf.getCreateTime()); + dto.setMonNum(i+1); + dto.setNumValue(monresstd); + } + return list; + } + + //璁惧淇℃伅缁熻 + public Response getDevStatistic(StationStic stic) { + PageHelper.startPage(stic.getPageNum(),stic.getPageSize()); + List<BattInf> list=mapper.getDevStatistic(stic); + for (BattInf binf:list) { + //鑾峰彇璁惧涓嬬數姹犵粍涓暟 + int battCount=mapper.getBattCountBydevId(binf.getDevId()); + binf.setBattCount(battCount); + } + PageInfo<BattInf> pageInfo=new PageInfo<>(list); + return new Response().setII(1,list.size()>0,pageInfo,"璁惧淇℃伅缁熻"); + } + //钃勭數姹犵粍淇℃伅缁熻 + public Response getBattStatistic(StationStic stic) { + PageHelper.startPage(stic.getPageNum(),stic.getPageSize()); + List<BattInf> list=mapper.getBattStatistic(stic); + PageInfo<BattInf> pageInfo=new PageInfo<>(list); + return new Response().setII(1,list.size()>0,pageInfo,"钃勭數姹犵粍淇℃伅缁熻"); + } + //鍗曚綋缁熻鏌ヨ绗﹀悎鏉′欢鐨勭數姹犵粍 + public List<BattInf> getMonStatistic(MonStic stic) { + return mapper.getMonStatistic(stic); + } + //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰15 + public List<BattInf> getBattCompare15Statistic(BattCompareStic stic) { + return mapper.getBattCompare15Statistic(stic); + } + //鑾峰彇瀹归噺鎬ц兘(涓嬫媺) + public Response getCapperformance() { + Map<Integer,String> map= BattCapperformanceEnum.getOpInfo(); + return new Response().setII(1,true,map,"鑾峰彇瀹归噺鎬ц兘(涓嬫媺)"); + } + //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰16 + public List<BattInf> getBattCompare16Statistic(BattCompareStic stic) { + return mapper.getBattCompare16Statistic(stic); + } + //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰17 + public List<BattInf> getBattCompare17Statistic(BattCompareStic stic) { + return mapper.getBattCompare17Statistic(stic); + } + //鏈勾搴﹀凡鏀剧數鏁伴噺缁熻(1.2.5) + public List<BattInf> getDischr5Statistic(DisChargeStic stic) { + return mapper.getDischr5Statistic(stic); + } + //鏈勾搴﹀凡鏀剧數鏁伴噺缁熻(1.2.6) + public List<BattInf> getDischr6Statistic(DisChargeStic stic) { + return mapper.getDischr6Statistic(stic); + } + //鐢垫睜缁勭數姹犳�ц兘缁熻锛堟湭鏀剧數锛屼紭绉�锛屽姡鍖栵紝鎹熷潖锛夌粺璁�(1.2.8/9/10) + public List<BattInf> getPerformanceStatistic(PerformanceStic stic) { + return mapper.getPerformanceStatistic(stic); + } + //鏈勾搴﹀凡/鏈斁鐢垫暟閲忕粺璁″彸渚у浘琛�(1.2.5) + public List<BattInf> getDischrChart(Integer uid) { + return mapper.getDischrChart(uid); + } + + public List<BattInf> getListByUserId(Integer userId) { + return mapper.getListByUserId(userId); + } + + public List<BattInf> getListByCondition(Integer userId, BattInf battInf) { + return mapper.getListByCondition(userId, battInf); + } + + //鑾峰彇绔欑偣涓嬬殑鐢垫睜缁�(涓嬫媺) + public Response getBattByUid(Integer uid, String provice, String city, String country, String stationName) { + List<BattInf> list=mapper.getBattByUid(uid,provice,city,country,stationName); + return new Response().setII(1,list.size()>0,list,"鑾峰彇绔欑偣涓嬬殑鐢垫睜缁�(涓嬫媺)"); + } + //鏍规嵁鏌ヨ鏉′欢鑾峰彇鐢垫睜缁� + public BattInf getBattgroupIdInf(Integer battgroupId) { + return mapper.getBattgroupIdInf(battgroupId); + } + //鏌ヨ鐢垫簮涓嬫墍鏈夌殑鐢垫睜缁刬d + public List<Integer> getBattgroupIdList(Integer powerId) { + return mapper.getBattgroupIdList(powerId); } } \ No newline at end of file -- Gitblit v1.9.1