From 518646badb078fe65c653ad6c999d6f026ca85b6 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期六, 17 五月 2025 15:08:57 +0800 Subject: [PATCH] 查询机房,电源,电池组信息 --- src/main/java/com/whyc/service/BattInfService.java | 140 ++++++++++++++++++---------------- src/main/java/com/whyc/controller/InfoContoller.java | 2 src/main/java/com/whyc/factory/InfoFactory.java | 71 ++++++++++++----- 3 files changed, 123 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/whyc/controller/InfoContoller.java b/src/main/java/com/whyc/controller/InfoContoller.java index 27c92d8..aab8b06 100644 --- a/src/main/java/com/whyc/controller/InfoContoller.java +++ b/src/main/java/com/whyc/controller/InfoContoller.java @@ -66,7 +66,7 @@ @ApiOperation(value = "鍒犻櫎鐢垫睜缁�") @GetMapping("delBatt") - public Response delBatt(@RequestParam Integer stationId,@RequestParam Integer powerId,@RequestParam Integer battgroupId){ + public Response delBatt(@RequestParam Integer stationId,@RequestParam Integer powerId,@RequestParam(required = false) Integer battgroupId){ return binfService.delBatt(stationId, powerId, battgroupId); } diff --git a/src/main/java/com/whyc/factory/InfoFactory.java b/src/main/java/com/whyc/factory/InfoFactory.java index 0f9e46e..0b7d20b 100644 --- a/src/main/java/com/whyc/factory/InfoFactory.java +++ b/src/main/java/com/whyc/factory/InfoFactory.java @@ -13,23 +13,11 @@ .setPowerModel(info.getPowerModel()) .setProtocol(info.getProtocol()) .setPowerIp(info.getPowerIp()); - if(info.getProvice()!=null){ - pinf.setProvice(info.getProvice()); - } - if(info.getCity()!=null){ - pinf.setCity(info.getCity()); - } - if(info.getCountry()!=null){ - pinf.setCountry(info.getCountry()); - } - if(info.getStationName()!=null){ - pinf.setStationName(info.getStationName()); - } - if(info.getStationId()!=null){ - pinf.setStationId(info.getStationId()); - } if(info.getPowerId()!=null){ pinf.setPowerId(info.getPowerId()); + } + if(info.getPowerName()!=null){ + pinf.setPowerName(info.getPowerName()); } StationInf sinf=new StationInf(); sinf.setProvice(info.getProvice()) @@ -39,26 +27,63 @@ .setStationType(info.getStationType()) .setLatitude(info.getLatitude()) .setLongitude(info.getLongitude()); + if(info.getProvice()!=null){ + sinf.setProvice(info.getProvice()); + } + if(info.getCity()!=null){ + sinf.setCity(info.getCity()); + } + if(info.getCountry()!=null){ + sinf.setCountry(info.getCountry()); + } + if(info.getStationName()!=null){ + sinf.setStationName(info.getStationName()); + } + if(info.getStationId()!=null){ + sinf.setStationId(info.getStationId()); + } pinf.setSinf(sinf); return pinf; } //灏唅nfo瀵硅薄杞负鐢垫睜缁勫璞� public static BattInf infoToBatt(InfoDto info) { BattInf binf = new BattInf(); - binf.setDevIp(info.getDevIp()) - .setDevType(info.getDevType()) - .setMoncapstd(info.getMoncapstd()) - .setMoncount(info.getMoncount()) - .setMonresstd(info.getMonresstd()) - .setMonvolstd(info.getMonvolstd()) - .setProduct(info.getProduct()) - .setBattModel(info.getBattModel()); + if(info.getDevType()!=null){ + binf.setDevType(info.getDevType()); + } + if(info.getMoncapstd()!=null){ + binf.setMoncapstd(info.getMoncapstd()); + } + if(info.getMoncount()!=null){ + binf.setMoncount(info.getMoncount()); + } + if(info.getMonresstd()!=null){ + binf.setMonresstd(info.getMonresstd()); + } + if(info.getMonvolstd()!=null){ + binf.setMonvolstd(info.getMonvolstd()); + } + if(info.getProduct()!=null){ + binf.setProduct(info.getProduct()); + } + if(info.getBattModel()!=null){ + binf.setBattModel(info.getBattModel()); + } + if(info.getDevIp()!=null){ + binf.setDevIp(info.getDevIp()); + } if(info.getBattgroupId()!=null){ binf.setBattgroupId(info.getBattgroupId()); } + if(info.getBattgroupName()!=null){ + binf.setBattgroupName(info.getBattgroupName()); + } if(info.getDevId()!=null){ binf.setDevId(info.getDevId()); } + if(info.getDevName()!=null){ + binf.setDevName(info.getDevName()); + } return binf; } } \ No newline at end of file diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java index f502949..f4fff5b 100644 --- a/src/main/java/com/whyc/service/BattInfService.java +++ b/src/main/java/com/whyc/service/BattInfService.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -110,24 +111,27 @@ //鍒犻櫎鐢垫睜缁� @Transactional public Response delBatt(Integer stationId, Integer powerId,Integer battgroupId) { - UpdateWrapper wrapper=new UpdateWrapper(); - wrapper.eq("battgroup_id",battgroupId); - mapper.delete(wrapper); - //妫�娴嬪鏋減owerId涓嬬數姹犵粍鍒犻櫎瀹屼簡,瑕佸皢鐢垫簮涔熷垹闄ゆ帀 - QueryWrapper wrapper1=new QueryWrapper(); - wrapper1.eq("power_id",powerId); - List<BattInf> binfList=mapper.selectList(wrapper1); - if(binfList==null){ + 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(wrapper); + pinfMapper.delete(wrapper2); //鍒犻櫎鎵�鏈夊寘鏈虹粍涓嬬殑鐢垫簮 bjService.delPowerInBaoji(powerId); //鍐嶆娴嬪鏋滄満鎴夸笅鐢垫簮涔熷叏鍒犻櫎浜嗭紝瑕佸皢鏈烘埧涔熷垹闄� QueryWrapper wrapper3=new QueryWrapper(); wrapper3.eq("station_id",stationId); List<PowerInf> pinfList=pinfMapper.selectList(wrapper3); - if(pinfList==null){ + if(pinfList==null||pinfList.size()==0){ UpdateWrapper wrapper4=new UpdateWrapper(); wrapper4.eq("station_id",stationId); sinfMapper.delete(wrapper4); @@ -159,7 +163,7 @@ wrapper1.set("latitude",sinf.getLatitude()); } wrapper1.eq("station_id",sinf.getStationId()); - sinfMapper.update((StationInf) ActionUtil.objeNull,wrapper1); + //鍐嶄慨鏀圭數婧愪俊鎭� UpdateWrapper wrapper2=new UpdateWrapper(); if(pinf.getCompany()!=null){ @@ -178,7 +182,7 @@ //妫�娴嬭鏈烘埧涓嬭淇敼鐨勭數婧愬悕鏄惁瀛樺湪 QueryWrapper queryWrapper=new QueryWrapper(); queryWrapper.eq("power_name",pinf.getPowerName()); - queryWrapper.eq("station_id",pinf.getStationId()); + queryWrapper.eq("station_id",sinf.getStationId()); queryWrapper.last("limit 1"); PowerInf juegep=pinfMapper.selectOne(queryWrapper); if(juegep!=null){ @@ -187,66 +191,70 @@ wrapper2.set("power_name",pinf.getPowerName()); } wrapper2.eq("power_id",pinf.getPowerId()); - pinfMapper.update((PowerInf) ActionUtil.objeNull,wrapper2); + //鏈�鍚庝慨鏀硅澶囦俊鎭� BattInf binf=InfoFactory.infoToBatt(info); - UpdateWrapper wrapper3=new UpdateWrapper(); - if(binf.getDevIp()!=null){ - wrapper3.set("dev_ip",binf.getDevIp()); - } - if(binf.getDevName()!=null){ - //妫�娴嬭鐢垫簮涓嬩慨鏀圭殑璁惧鍚嶆槸鍚﹀瓨鍦� - QueryWrapper queryWrapper1=new QueryWrapper(); - queryWrapper1.eq("dev_name",binf.getDevName()); - queryWrapper1.eq("power_id",pinf.getPowerId()); - queryWrapper1.last("limit 1"); - BattInf jueged=mapper.selectOne(queryWrapper1); - if(jueged!=null){ - return new Response().set(1,false,"璇ョ數婧愪笅宸插瓨鍦�"+binf.getDevName()+"鐨勮澶�"); + if(binf.getDevId()!=null) { + UpdateWrapper wrapper3 = new UpdateWrapper(); + if (binf.getDevIp() != null) { + wrapper3.set("dev_ip", binf.getDevIp()); } - wrapper3.set("dev_name",binf.getDevName()); - } - if(binf.getDevType()!=null){ - wrapper3.set("dev_type",binf.getDevType()); - } - wrapper3.eq("dev_id",binf.getDevId()); - mapper.update((BattInf) ActionUtil.objeNull,wrapper3); + if (binf.getDevName() != null) { + //妫�娴嬭鐢垫簮涓嬩慨鏀圭殑璁惧鍚嶆槸鍚﹀瓨鍦� + QueryWrapper queryWrapper1 = new QueryWrapper(); + queryWrapper1.eq("dev_name", binf.getDevName()); + queryWrapper1.eq("power_id", pinf.getPowerId()); + queryWrapper1.last("limit 1"); + BattInf jueged = mapper.selectOne(queryWrapper1); + 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 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()+"鐨勭數姹犵粍"); + //淇敼鐢垫睜缁勪俊鎭� + UpdateWrapper wrapper4 = new UpdateWrapper(); + 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() + "鐨勭數姹犵粍"); + } + wrapper4.set("battgroup_name", 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()); + } + wrapper4.eq("battgroup_id", binf.getBattgroupId()); + mapper.update((BattInf) ActionUtil.objeNull,wrapper3); + mapper.update((BattInf) ActionUtil.objeNull,wrapper4); } - 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()); - } - wrapper4.eq("battgroup_id",binf.getBattgroupId()); - mapper.update((BattInf) ActionUtil.objeNull,wrapper4); - return new Response().set(1,true); + sinfMapper.update((StationInf) ActionUtil.objeNull,wrapper1); + pinfMapper.update((PowerInf) ActionUtil.objeNull,wrapper2); + return new Response().set(1,true,"淇敼淇℃伅鎴愬姛"); } /*//淇敼鐢垫睜缁� public Response updateBatt(BattInf binf) { -- Gitblit v1.9.1