From e8b154e63e9db8750407c218eb13937f584bda8c Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期四, 15 五月 2025 11:12:37 +0800 Subject: [PATCH] 电池组管理 --- src/main/java/com/whyc/service/BattInfService.java | 112 ++++++++++++--------------- src/main/java/com/whyc/dto/BattDto.java | 16 ++++ src/main/java/com/whyc/pojo/db_station/BattInf.java | 14 +++ src/main/java/com/whyc/mapper/BattInfMapper.java | 9 ++ src/main/resources/mapper/BattInfMapper.xml | 42 ++++++++++ src/main/java/com/whyc/controller/BattInfController.java | 15 ++- 6 files changed, 138 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/whyc/controller/BattInfController.java b/src/main/java/com/whyc/controller/BattInfController.java index 48dfe5a..17cdae7 100644 --- a/src/main/java/com/whyc/controller/BattInfController.java +++ b/src/main/java/com/whyc/controller/BattInfController.java @@ -1,5 +1,6 @@ package com.whyc.controller; +import com.whyc.dto.BattDto; import com.whyc.dto.PowerDto; import com.whyc.dto.Response; import com.whyc.pojo.db_station.BattInf; @@ -18,28 +19,28 @@ @Autowired private BattInfService service; -/* - @ApiOperation(value = "娣诲姞鐢垫簮") + + @ApiOperation(value = "娣诲姞鐢垫睜缁�") @PostMapping("addBatt") public Response addBatt(@RequestBody BattInf binf){ return service.addBatt(binf); } - @ApiOperation(value = "鍒犻櫎鐢垫簮") + @ApiOperation(value = "鍒犻櫎鐢垫睜缁�") @GetMapping("delBatt") public Response delBatt(@RequestParam Integer bid){ return service.delBatt(bid); } - @ApiOperation(value = "淇敼鐢垫簮") + @ApiOperation(value = "淇敼鐢垫睜缁�") @PostMapping("updateBatt") public Response updateBatt(@RequestBody BattInf binf){ return service.updateBatt(binf); } - @ApiOperation(value = "鏌ヨ鐢垫簮") + @ApiOperation(value = "鏌ヨ鐢垫睜缁�") @PostMapping("getBatt") - public Response getBatt(@RequestBody PowerDto dto){ + public Response getBatt(@RequestBody BattDto dto){ return service.getBatt(dto); - }*/ + } } \ No newline at end of file diff --git a/src/main/java/com/whyc/dto/BattDto.java b/src/main/java/com/whyc/dto/BattDto.java new file mode 100644 index 0000000..0e75a51 --- /dev/null +++ b/src/main/java/com/whyc/dto/BattDto.java @@ -0,0 +1,16 @@ +package com.whyc.dto; + +import lombok.Data; + +@Data +public class BattDto { + private String provice; + private String city; + private String country; + private String stationName; + private String powerName; + private String battgroupName; + private Integer pageNum; + private Integer pageSize; + private Integer uid; +} \ No newline at end of file diff --git a/src/main/java/com/whyc/mapper/BattInfMapper.java b/src/main/java/com/whyc/mapper/BattInfMapper.java index 49681d1..332cd27 100644 --- a/src/main/java/com/whyc/mapper/BattInfMapper.java +++ b/src/main/java/com/whyc/mapper/BattInfMapper.java @@ -1,6 +1,15 @@ package com.whyc.mapper; +import com.whyc.dto.BattDto; import com.whyc.pojo.db_station.BattInf; +import java.util.List; + public interface BattInfMapper extends CustomMapper<BattInf>{ + //鑾峰彇瀵瑰簲鐨勮澶噄d + Integer getMaxdevId(); + //鑾峰彇瀵瑰簲鐨勭數姹犵粍id + Integer getMaxBattGroupId(); + //鏌ヨ鐢垫睜 + List<BattInf> getBatt(BattDto dto); } \ No newline at end of file diff --git a/src/main/java/com/whyc/pojo/db_station/BattInf.java b/src/main/java/com/whyc/pojo/db_station/BattInf.java index bef7ff6..d144c34 100644 --- a/src/main/java/com/whyc/pojo/db_station/BattInf.java +++ b/src/main/java/com/whyc/pojo/db_station/BattInf.java @@ -1,6 +1,7 @@ package com.whyc.pojo.db_station; import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -53,7 +54,7 @@ private String battgroupName; @ApiModelProperty(value = "鐢垫睜缁勭紪鍙�") - private Integer battfroupNum; + private Integer battgroupNum; @ApiModelProperty(value = "鏍囩О鐢靛帇") private Float monvolstd; @@ -64,6 +65,9 @@ @ApiModelProperty(value = "鏍囩О鍐呴樆") private Float monresstd; + @ApiModelProperty(value = "姣忕粍鍗曚綋涓暟") + private Float moncount; + @ApiModelProperty(value = "鍝佺墝") private String product; @@ -71,7 +75,15 @@ private String model; @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") private Date createTime; + @TableField(exist = false) + private String stationName; + + @TableField(exist = false) + private String powerName; + + } diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java index 269edb3..36fa164 100644 --- a/src/main/java/com/whyc/service/BattInfService.java +++ b/src/main/java/com/whyc/service/BattInfService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.whyc.dto.BattDto; import com.whyc.dto.PowerDto; import com.whyc.dto.Response; import com.whyc.mapper.BattInfMapper; @@ -16,69 +17,50 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; import java.util.List; @Service public class BattInfService { @Autowired(required = false) private BattInfMapper mapper; -/* + //娣诲姞鐢垫簮 @Transactional - public Response addBatt(BattInf binf) { - //鍏堟牎楠屽綋鍓嶇敤鎴锋槸鍚﹀瓨鍦ㄥ寘鏈虹粍涓嶅瓨鍦ㄥ垯涓嶈娣诲姞鐢垫簮 - User user= ActionUtil.getUser(); - int flag=bjService.checkUserBaojiGroup(user.getId()); - if(flag==0){ - return new Response().set(1,false,"褰撳墠鐢ㄦ埛涓嶅瓨鍦ㄥ寘鏈虹粍"); - } - //鏈烘埧淇℃伅 - StationInf addsinf= addpinf.getSinf(); - //鍒ゆ柇娣诲姞閿佺殑鏃跺�欐満鎴挎槸涓嶆槸鏂版満鎴� - String fullName=addsinf.getProvice()+"_"+addsinf.getCity()+"_"+addsinf.getCountry()+"_"+addsinf.getStationName(); - //鍒ゆ柇鏈烘埧鏄惁瀛樺湪 + public Response addBatt(BattInf addbinf) { + //鍒ゆ柇鐢垫睜缁勬槸鍚﹀瓨鍦� QueryWrapper wrapper=new QueryWrapper(); - wrapper.eq("full_name",fullName); + wrapper.eq("station_id",addbinf.getStationId()); + wrapper.eq("power_id",addbinf.getPowerId()); + wrapper.eq("dev_name",addbinf.getDevName()); + wrapper.eq("battgroup_name",addbinf.getBattgroupName()); wrapper.last("limit 1"); - StationInf sinf=sinfMapper.selectOne(wrapper); - int stationId=0; - int powerId=0; - if(sinf!=null){ - stationId=sinf.getStationId(); + BattInf binf=mapper.selectOne(wrapper); + int devId=0; + int battGroupId=0; + if(binf!=null){ + return new Response().set(1,false,"褰撳墠鐢垫簮鏈烘埧涓嬪凡娣诲姞杩囪鐢垫睜缁�"); }else { - //鑾峰彇瀵瑰簲鐨勬満鎴縤d - stationId = sinfMapper.getMaxStationId(); - if (stationId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 - stationId = 40000001; + //鑾峰彇瀵瑰簲鐨勮澶噄d,鐢垫睜缁� + devId = mapper.getMaxdevId(); + battGroupId=mapper.getMaxBattGroupId(); + if (devId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 + devId = 10001; } else { - stationId += 1; + devId += 1; } - addsinf.setFullName(fullName); - addsinf.setStationId(stationId); - sinfMapper.insert(addsinf); + if (battGroupId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 + battGroupId = 10001; + } else { + battGroupId += 1; + } + addbinf.setDevId(devId); + addbinf.setBattgroupId(battGroupId); + addbinf.setCreateTime(new Date()); + mapper.insert(addbinf); + return new Response().set(1, true, "娣诲姞鐢垫睜缁�"); } - //鍒ゆ柇鏈烘埧鏄惁瀛樺湪 - QueryWrapper wrapper1=new QueryWrapper(); - wrapper1.eq("power_name",addpinf.getPowerName()); - wrapper1.eq("station_id",stationId); - wrapper1.last("limit 1"); - PowerInf juegep=mapper.selectOne(wrapper); - if(juegep==null){ - return new Response().set(1, false, "褰撳墠鏈烘埧涓嬪凡娣诲姞杩囪鐢垫簮"); - } - //鍐嶆坊鍔犵數婧愪俊鎭� - addpinf.setStationId(stationId); - //鑾峰彇瀵瑰簲鐨勭數婧恑d - powerId = mapper.getMaxPowerId(); - if (powerId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 - powerId = 10001; - } else { - powerId += 1; - } - addpinf.setPowerId(powerId); - mapper.insert(addpinf); - return new Response().set(1, true, "娣诲姞鐢垫簮"); } //鍒犻櫎鐢垫簮 public Response delBatt(Integer bid) { @@ -94,30 +76,36 @@ if(binf.getBattgroupName()!=null){ wrapper.set("battgroup_name",binf.getBattgroupName()); } - if(binf.getCompany()!=null){ - wrapper.set("company",pinf.getCompany()); + if(binf.getMonvolstd()!=null){ + wrapper.set("monvolstd",binf.getMonvolstd()); } - if(pinf.getModel()!=null){ - wrapper.set("model",pinf.getModel()); + if(binf.getMoncapstd()!=null){ + wrapper.set("moncapstd",binf.getMoncapstd()); } - if(pinf.getProtocol()!=null){ - wrapper.set("protocol",pinf.getProtocol()); + if(binf.getMonresstd()!=null){ + wrapper.set("monresstd",binf.getMonresstd()); } - if(pinf.getPowerIp()!=null){ - wrapper.set("power_ip",pinf.getPowerIp()); + if(binf.getProduct()!=null){ + wrapper.set("product",binf.getProduct()); } - mapper.update((PowerInf) ActionUtil.objeNull,wrapper); + if(binf.getMoncount()!=null){ + wrapper.set("moncount",binf.getMoncount()); + } + if(binf.getModel()!=null){ + wrapper.set("model",binf.getModel()); + } + mapper.update((BattInf) ActionUtil.objeNull,wrapper); return new Response().set(1,true); } - //鏌ヨ鐢垫簮 - public Response getBatt(PowerDto dto) { + //鏌ヨ鐢垫睜 + public Response getBatt(BattDto dto) { User user= ActionUtil.getUser(); dto.setUid(user.getId()); PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); - List<PowerInf> list=mapper.getPower(dto); + List<BattInf> list=mapper.getBatt(dto); PageInfo pageInfo=new PageInfo(list); - return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鐢垫簮"); + return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鐢垫睜"); } -*/ + } \ No newline at end of file diff --git a/src/main/resources/mapper/BattInfMapper.xml b/src/main/resources/mapper/BattInfMapper.xml new file mode 100644 index 0000000..7c8475a --- /dev/null +++ b/src/main/resources/mapper/BattInfMapper.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.whyc.mapper.BattInfMapper"> + + <select id="getMaxdevId" resultType="java.lang.Integer"> + select ifnull(max(dev_id),0) from db_station.tb_batt_inf where dev_id>0; + </select> + <select id="getMaxBattGroupId" resultType="java.lang.Integer"> + select ifnull(max(battgroup_id),0) from db_station.tb_batt_inf where battgroup_id>0; + </select> + <select id="getBatt" resultType="com.whyc.pojo.db_station.BattInf"> + select tb_batt_inf.*,tb_station_inf.station_name,tb_power_inf.power_name + from db_station.tb_power_inf,db_station.tb_station_inf,db_station.tb_batt_inf + where tb_batt_inf.station_id=tb_station_inf.station_id + and tb_batt_inf.power_id=tb_power_inf.power_id + <if test="provice!=null"> + and tb_station_inf.provice=#{provice} + </if> + <if test="city!=null"> + and tb_station_inf.city=#{city} + </if> + <if test="country!=null"> + and tb_station_inf.country=#{country} + </if> + <if test="stationName!=null"> + and tb_station_inf.station_name like concat('%',#{stationName},'%') + </if> + <if test="powerName!=null"> + and tb_power_inf.power_name like concat('%',#{powerName},'%') + </if> + <if test="battgroupName!=null"> + and tb_batt_inf.battgroup_name like concat('%',#{battgroupName},'%') + </if> + <if test="uid>100"> + and tb_power_inf.power_id in( + select distinct power_id from db_user.tb_baojigroup_power,db_user.tb_baojigroup_usr + where tb_baojigroup_power.baoji_group_id=tb_baojigroup_usr.baoji_group_id + and tb_baojigroup_usr.uid=#{uid} + ) + </if> + </select> +</mapper> \ No newline at end of file -- Gitblit v1.9.1