From 8364b1730e17da228e45e0675bdf2d6f42bc0691 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期四, 15 五月 2025 10:39:50 +0800 Subject: [PATCH] 用户修改 --- src/main/java/com/whyc/service/BattInfService.java | 123 +++++++++++++++++++++++++++++++++++++++++ src/main/java/com/whyc/pojo/db_user/User.java | 2 src/main/java/com/whyc/mapper/BattInfMapper.java | 6 ++ src/main/java/com/whyc/controller/BattInfController.java | 45 +++++++++++++++ src/main/resources/mapper/UserMapper.xml | 2 5 files changed, 176 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/whyc/controller/BattInfController.java b/src/main/java/com/whyc/controller/BattInfController.java new file mode 100644 index 0000000..48dfe5a --- /dev/null +++ b/src/main/java/com/whyc/controller/BattInfController.java @@ -0,0 +1,45 @@ +package com.whyc.controller; + +import com.whyc.dto.PowerDto; +import com.whyc.dto.Response; +import com.whyc.pojo.db_station.BattInf; +import com.whyc.pojo.db_station.PowerInf; +import com.whyc.service.BattInfService; +import com.whyc.service.PowerInfService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@Api(tags = "鐢垫睜缁勭鐞�") +@RequestMapping("battInf") +public class BattInfController { + @Autowired + private BattInfService service; + +/* + @ApiOperation(value = "娣诲姞鐢垫簮") + @PostMapping("addBatt") + public Response addBatt(@RequestBody BattInf binf){ + return service.addBatt(binf); + } + + @ApiOperation(value = "鍒犻櫎鐢垫簮") + @GetMapping("delBatt") + public Response delBatt(@RequestParam Integer bid){ + return service.delBatt(bid); + } + + @ApiOperation(value = "淇敼鐢垫簮") + @PostMapping("updateBatt") + public Response updateBatt(@RequestBody BattInf binf){ + return service.updateBatt(binf); + } + + @ApiOperation(value = "鏌ヨ鐢垫簮") + @PostMapping("getBatt") + public Response getBatt(@RequestBody PowerDto dto){ + return service.getBatt(dto); + }*/ +} \ 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 new file mode 100644 index 0000000..49681d1 --- /dev/null +++ b/src/main/java/com/whyc/mapper/BattInfMapper.java @@ -0,0 +1,6 @@ +package com.whyc.mapper; + +import com.whyc.pojo.db_station.BattInf; + +public interface BattInfMapper extends CustomMapper<BattInf>{ +} \ No newline at end of file diff --git a/src/main/java/com/whyc/pojo/db_user/User.java b/src/main/java/com/whyc/pojo/db_user/User.java index 028b41a..a687da0 100644 --- a/src/main/java/com/whyc/pojo/db_user/User.java +++ b/src/main/java/com/whyc/pojo/db_user/User.java @@ -30,7 +30,7 @@ private String phoneNumber; @ApiModelProperty(value = "韬唤:1鏅�氱敤鎴凤紝2绠$悊灞傦紝3棰嗗灞傦紝4杩愮淮鐝粍") - private int role; + private Integer role; @ApiModelProperty(value = "璐﹀彿绫诲瀷 1:闀挎湡,2:涓存椂 ") private Integer type; diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java new file mode 100644 index 0000000..269edb3 --- /dev/null +++ b/src/main/java/com/whyc/service/BattInfService.java @@ -0,0 +1,123 @@ +package com.whyc.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.whyc.dto.PowerDto; +import com.whyc.dto.Response; +import com.whyc.mapper.BattInfMapper; +import com.whyc.pojo.db_station.BattInf; +import com.whyc.pojo.db_station.PowerInf; +import com.whyc.pojo.db_station.StationInf; +import com.whyc.pojo.db_user.User; +import com.whyc.util.ActionUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +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(); + //鍒ゆ柇鏈烘埧鏄惁瀛樺湪 + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("full_name",fullName); + wrapper.last("limit 1"); + StationInf sinf=sinfMapper.selectOne(wrapper); + int stationId=0; + int powerId=0; + if(sinf!=null){ + stationId=sinf.getStationId(); + }else { + //鑾峰彇瀵瑰簲鐨勬満鎴縤d + stationId = sinfMapper.getMaxStationId(); + if (stationId == 0) {//鏁版嵁搴撲腑娌℃湁绔欑偣 + stationId = 40000001; + } else { + stationId += 1; + } + addsinf.setFullName(fullName); + addsinf.setStationId(stationId); + sinfMapper.insert(addsinf); + } + //鍒ゆ柇鏈烘埧鏄惁瀛樺湪 + 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) { + UpdateWrapper wrapper=new UpdateWrapper(); + wrapper.eq("battgroup_id",bid); + mapper.delete(wrapper); + return new Response().set(1,true); + } + //淇敼鐢垫簮 + public Response updateBatt(BattInf binf) { + UpdateWrapper wrapper=new UpdateWrapper(); + wrapper.eq("battgroup_id",binf.getBattgroupId()); + if(binf.getBattgroupName()!=null){ + wrapper.set("battgroup_name",binf.getBattgroupName()); + } + if(binf.getCompany()!=null){ + wrapper.set("company",pinf.getCompany()); + } + if(pinf.getModel()!=null){ + wrapper.set("model",pinf.getModel()); + } + if(pinf.getProtocol()!=null){ + wrapper.set("protocol",pinf.getProtocol()); + } + if(pinf.getPowerIp()!=null){ + wrapper.set("power_ip",pinf.getPowerIp()); + } + mapper.update((PowerInf) ActionUtil.objeNull,wrapper); + return new Response().set(1,true); + } + //鏌ヨ鐢垫簮 + public Response getBatt(PowerDto dto) { + User user= ActionUtil.getUser(); + dto.setUid(user.getId()); + PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); + List<PowerInf> list=mapper.getPower(dto); + PageInfo pageInfo=new PageInfo(list); + return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鐢垫簮"); + } +*/ + +} \ No newline at end of file diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index e31c152..509ed74 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -27,7 +27,7 @@ select count(*) from db_user.tb_user where id>10000 </select> <select id="getAllUser" resultType="User"> - select distinct tb_user.id,tb_user.name,create_time,phone_number from db_user.tb_user + select distinct tb_user.id,tb_user.name,tb_user.role,create_time,phone_number from db_user.tb_user <where> tb_user.id>100 <if test="name!=null"> -- Gitblit v1.9.1