From ea0e6aeaad04e8762bb33ddad64fec1eb1d0e3b7 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期六, 21 六月 2025 10:07:04 +0800
Subject: [PATCH] 资产管理添加变更记录,查询时需要将最近2次的变更记录查询出来

---
 src/main/java/com/whyc/mapper/PowerInfChangeMapper.java      |    6 
 src/main/java/com/whyc/service/BattInfService.java           |   20 ++
 src/main/java/com/whyc/dto/InfoDto.java                      |   13 +
 src/main/java/com/whyc/mapper/BattInfChangeMapper.java       |    6 
 src/main/java/com/whyc/mapper/StationInfChangeMapper.java    |    6 
 src/main/java/com/whyc/pojo/db_station/BattInfChange.java    |   93 +++++++++++++
 src/main/java/com/whyc/pojo/db_station/StationInfChange.java |   75 ++++++++++
 src/main/java/com/whyc/pojo/db_station/PowerInfChange.java   |   75 ++++++++++
 src/main/java/com/whyc/service/InfoChangeService.java        |   78 +++++++++++
 9 files changed, 369 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/dto/InfoDto.java b/src/main/java/com/whyc/dto/InfoDto.java
index 0af0daf..6bb9a60 100644
--- a/src/main/java/com/whyc/dto/InfoDto.java
+++ b/src/main/java/com/whyc/dto/InfoDto.java
@@ -3,10 +3,15 @@
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.whyc.pojo.db_station.BattInf;
+import com.whyc.pojo.db_station.BattInfChange;
+import com.whyc.pojo.db_station.PowerInfChange;
+import com.whyc.pojo.db_station.StationInfChange;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 @Data
 public class InfoDto {
@@ -41,6 +46,8 @@
     @ApiModelProperty(value = "绔欑偣绫诲瀷[0-闈炶妭鐐圭珯锛�1-鑺傜偣绔橾")
     private Integer nodeStation;
 
+    private List<StationInfChange> sinfChangeList;
+
 
     @ApiModelProperty(value = "鐢垫簮id")
     private Integer powerId;
@@ -72,6 +79,7 @@
     @ApiModelProperty(value = "鏁存祦鍣ㄤ娇鑳絒bit0-妯″潡1 bit15-妯″潡16]銆�1-鍙敤 0-涓嶅彲浠ャ��")
     private Long modelCfg;
 
+    private List<PowerInfChange> pinfChangeList;
 
 
     @ApiModelProperty(value = "璁惧id")
@@ -124,4 +132,9 @@
 
     @ApiModelProperty(value = "鏍囪瘑鏄惁鍔犲叆鐢垫睜缁�1:娣诲姞锛�0涓嶆坊鍔�")
     private Integer addBinfFlag;
+
+    private List<BattInfChange> binfChangeList;
+
+    @ApiModelProperty(value = "鍙樻洿鍘熷洜")
+    private String updateReason;
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/mapper/BattInfChangeMapper.java b/src/main/java/com/whyc/mapper/BattInfChangeMapper.java
new file mode 100644
index 0000000..70e2704
--- /dev/null
+++ b/src/main/java/com/whyc/mapper/BattInfChangeMapper.java
@@ -0,0 +1,6 @@
+package com.whyc.mapper;
+
+import com.whyc.pojo.db_station.BattInfChange;
+
+public interface BattInfChangeMapper extends CustomMapper<BattInfChange>{
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/mapper/PowerInfChangeMapper.java b/src/main/java/com/whyc/mapper/PowerInfChangeMapper.java
new file mode 100644
index 0000000..217e339
--- /dev/null
+++ b/src/main/java/com/whyc/mapper/PowerInfChangeMapper.java
@@ -0,0 +1,6 @@
+package com.whyc.mapper;
+
+import com.whyc.pojo.db_station.PowerInfChange;
+
+public interface PowerInfChangeMapper extends CustomMapper<PowerInfChange>{
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/mapper/StationInfChangeMapper.java b/src/main/java/com/whyc/mapper/StationInfChangeMapper.java
new file mode 100644
index 0000000..8dc5cda
--- /dev/null
+++ b/src/main/java/com/whyc/mapper/StationInfChangeMapper.java
@@ -0,0 +1,6 @@
+package com.whyc.mapper;
+
+import com.whyc.pojo.db_station.StationInfChange;
+
+public interface StationInfChangeMapper extends CustomMapper<StationInfChange>{
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/pojo/db_station/BattInfChange.java b/src/main/java/com/whyc/pojo/db_station/BattInfChange.java
new file mode 100644
index 0000000..af2069a
--- /dev/null
+++ b/src/main/java/com/whyc/pojo/db_station/BattInfChange.java
@@ -0,0 +1,93 @@
+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;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 鐢垫睜淇℃伅鍙樻洿璁板綍琛�
+ * </p>
+ *
+ * @author lxw
+ * @since 2025-06-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName(schema = "db_station",value = "tb_batt_inf_change")
+@ApiModel(value="BattInfChange瀵硅薄", description="鐢垫睜淇℃伅鍙樻洿璁板綍琛�")
+public class BattInfChange implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "涓婚敭")
+    @TableId(value = "num", type = IdType.AUTO)
+    private Integer num;
+
+    @ApiModelProperty(value = "鏈烘埧Id")
+    private Integer stationId;
+
+    @ApiModelProperty(value = "鐢垫簮id")
+    private Integer powerId;
+
+    @ApiModelProperty(value = "璁惧id")
+    private Integer devId;
+
+    @ApiModelProperty(value = "璁惧ip")
+    private String devIp;
+
+    @ApiModelProperty(value = "璁惧鍚嶇О")
+    private String devName;
+
+    @ApiModelProperty(value = "鐢垫睜缁刬d")
+    private Integer battgroupId;
+
+    @ApiModelProperty(value = "鐢垫睜缁勫悕绉�")
+    private String battgroupName;
+
+    @ApiModelProperty(value = "鐢垫睜缁勭紪鍙�")
+    private Integer battgroupNum;
+
+    @ApiModelProperty(value = "鏍囩О鐢靛帇")
+    private Float monvolstd;
+
+    @ApiModelProperty(value = "鏍囩О瀹归噺")
+    private Float moncapstd;
+
+    @ApiModelProperty(value = "鏍囩О鍐呴樆")
+    private Float monresstd;
+
+    @ApiModelProperty(value = "鍝佺墝")
+    private String product;
+
+    @ApiModelProperty(value = "鍨嬪彿")
+    private String battModel;
+
+    @ApiModelProperty(value = "涓�缁勫崟浣撲釜鏁�")
+    private Integer moncount;
+
+    @ApiModelProperty(value = "璁惧缂栧彿")
+    private Integer devNum;
+
+    @ApiModelProperty(value = "璁惧绫诲瀷")
+    private String devType;
+
+    @ApiModelProperty(value = "鎶曞叆浣跨敤鏃堕棿")
+    private Date inuseTime;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "鍙樻洿鍘熷洜")
+    private String updateReason;
+
+
+}
diff --git a/src/main/java/com/whyc/pojo/db_station/PowerInfChange.java b/src/main/java/com/whyc/pojo/db_station/PowerInfChange.java
new file mode 100644
index 0000000..cbca746
--- /dev/null
+++ b/src/main/java/com/whyc/pojo/db_station/PowerInfChange.java
@@ -0,0 +1,75 @@
+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;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 鐢垫簮淇℃伅鍙樻洿璁板綍琛�
+ * </p>
+ *
+ * @author lxw
+ * @since 2025-06-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName(schema = "db_station",value = "tb_power_inf_change")
+@ApiModel(value="PowerInfChange瀵硅薄", description="鐢垫簮淇℃伅鍙樻洿璁板綍琛�")
+public class PowerInfChange implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "涓婚敭")
+    @TableId(value = "num", type = IdType.AUTO)
+    private Integer num;
+
+    @ApiModelProperty(value = "鏈烘埧Id")
+    private Integer stationId;
+
+    @ApiModelProperty(value = "鐢垫簮id")
+    private Integer powerId;
+
+    @ApiModelProperty(value = "鐢垫簮缂栧彿")
+    private Integer powerNum;
+
+    @ApiModelProperty(value = "鐢垫簮鍚嶇О")
+    private String powerName;
+
+    @ApiModelProperty(value = "鍘傚")
+    private String company;
+
+    @ApiModelProperty(value = "鍨嬪彿")
+    private String powerModel;
+
+    @ApiModelProperty(value = "鍗忚")
+    private String protocol;
+
+    @ApiModelProperty(value = "鐢垫簮ip")
+    private String powerIp;
+
+    @ApiModelProperty(value = "1:鐩存祦锛�2锛氶�氳锛�3閰嶇綉")
+    private Integer powerType;
+
+    @ApiModelProperty(value = "鐢垫簮鎶曞叆浣跨敤鏃堕棿")
+    private Date powerInuseTime;
+
+    @ApiModelProperty(value = "鏁存祦鍣ㄤ娇鑳絒bit0-妯″潡1 bit15-妯″潡16]銆�1-鍦ㄧ敤 0-涓嶅湪鐢ㄣ��")
+    private Long modelCfg;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "鍙樻洿鍘熷洜")
+    private String updateReason;
+
+
+}
diff --git a/src/main/java/com/whyc/pojo/db_station/StationInfChange.java b/src/main/java/com/whyc/pojo/db_station/StationInfChange.java
new file mode 100644
index 0000000..ba2d85d
--- /dev/null
+++ b/src/main/java/com/whyc/pojo/db_station/StationInfChange.java
@@ -0,0 +1,75 @@
+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;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 鏈烘埧淇℃伅鍙樻洿璁板綍琛�
+ * </p>
+ *
+ * @author lxw
+ * @since 2025-06-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName(schema = "db_station",value = "tb_station_inf_change")
+@ApiModel(value="StationInfChange瀵硅薄", description="鏈烘埧淇℃伅鍙樻洿璁板綍琛�")
+public class StationInfChange implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "涓婚敭")
+    @TableId(value = "num", type = IdType.AUTO)
+    private Integer num;
+
+    @ApiModelProperty(value = "鏈烘埧Id")
+    private Integer stationId;
+
+    @ApiModelProperty(value = "绔欑偣鍚嶇О")
+    private String stationName;
+
+    @ApiModelProperty(value = "鐪�")
+    private String provice;
+
+    @ApiModelProperty(value = "甯�")
+    private String city;
+
+    @ApiModelProperty(value = "鍖哄幙")
+    private String country;
+
+    @ApiModelProperty(value = "绔欑偣鐢靛帇绛夌骇[锛�35kv/110kv/220kv 瀛楃涓茬被鍨嬶級]")
+    private String stationType;
+
+    @ApiModelProperty(value = "鏈烘埧鍚嶇О[鎷兼帴鍚庣殑]")
+    private String fullName;
+
+    @ApiModelProperty(value = "缁忓害")
+    private Double longitude;
+
+    @ApiModelProperty(value = "绾害")
+    private Double latitude;
+
+    @ApiModelProperty(value = "鏈烘埧璇︾粏鍦板潃")
+    private String stationAddr;
+
+    @ApiModelProperty(value = "绔欑偣绫诲瀷[0-闈炶妭鐐圭珯锛�1-鑺傜偣绔橾")
+    private Integer nodeStation;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "鍙樻洿鍘熷洜")
+    private String updateReason;
+
+
+}
diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java
index dc13974..00043eb 100644
--- a/src/main/java/com/whyc/service/BattInfService.java
+++ b/src/main/java/com/whyc/service/BattInfService.java
@@ -15,9 +15,7 @@
 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;
+import com.whyc.pojo.db_station.*;
 import com.whyc.pojo.db_user.User;
 import com.whyc.util.ActionUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +41,8 @@
     @Autowired(required = false)
     private BaojigroupService bjService;
 
+    @Autowired(required = false)
+    private InfoChangeService changeService;
     /*鏂板缓鐢垫睜缁勶紙鏂扮殑璁惧鏂扮殑鐢垫睜缁勶級
      * @param binf
      * 1.鍦ㄧ數婧愪笅鏂板缓璁惧锛岃褰曡澶囩紪鍙凤紝devNum,璁惧鍚嶇О涓鸿澶囩被鍨�+devNum
@@ -310,6 +310,11 @@
         }
         sinfMapper.update((StationInf) ActionUtil.objeNull,wrapper1);
         pinfMapper.update((PowerInf) ActionUtil.objeNull,wrapper2);
+        //瀛樺叆鍙樻洿淇℃伅璁板綍
+        pinf.setStationId(sinf.getStationId());
+        binf.setStationId(sinf.getStationId());
+        binf.setPowerId(pinf.getPowerId());
+        changeService.addInfoChange(sinf,pinf,binf,info.getUpdateReason());
         return new Response().set(1,true,"淇敼淇℃伅鎴愬姛");
     }
     /*//淇敼鐢垫睜缁�
@@ -363,6 +368,15 @@
         dto.setUid(user.getId());
         PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
         List<InfoDto> list=mapper.getInfo(dto);
+        for (InfoDto infoDto:list) {
+            //鑾峰彇鏈烘埧锛岀數婧愶紝鐢垫睜缁勫彉鏇磋褰�
+            List<StationInfChange> sinfChangeList=changeService.getSinfChange(infoDto.getStationId());
+            infoDto.setSinfChangeList(sinfChangeList);
+            List<PowerInfChange> pinfChangeList=changeService.getPinfChange(infoDto.getPowerId());
+            infoDto.setPinfChangeList(pinfChangeList);
+            List<BattInfChange> binfChangeList=changeService.getBinfChange(infoDto.getBattgroupId());
+            infoDto.setBinfChangeList(binfChangeList);
+        }
         PageInfo pageInfo=new PageInfo(list);
         return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鐢垫睜");
     }
diff --git a/src/main/java/com/whyc/service/InfoChangeService.java b/src/main/java/com/whyc/service/InfoChangeService.java
new file mode 100644
index 0000000..13bd2e6
--- /dev/null
+++ b/src/main/java/com/whyc/service/InfoChangeService.java
@@ -0,0 +1,78 @@
+package com.whyc.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.whyc.mapper.BattInfChangeMapper;
+import com.whyc.mapper.PowerInfChangeMapper;
+import com.whyc.mapper.StationInfChangeMapper;
+import com.whyc.pojo.db_station.*;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class InfoChangeService {
+    @Autowired(required = false)
+    private StationInfChangeMapper sinfChangeMapper;
+
+    @Autowired(required = false)
+    private PowerInfChangeMapper pinfChangeMapper;
+
+    @Autowired(required = false)
+    private BattInfChangeMapper binfChangeMapper;
+
+    //瀛樺叆鍙樻洿淇℃伅璁板綍
+    public void addInfoChange(StationInf sinf, PowerInf pinf, BattInf binf,String updateReason) {
+        StationInfChange sinfChange = new StationInfChange();
+        PowerInfChange pinfChange = new PowerInfChange();
+        BattInfChange binfChange = new BattInfChange();
+        Date updateTime = new Date();
+        //灏嗕俊鎭嫹璐濊嚦瀵瑰簲鐨勫彉鏇翠俊鎭〃
+        BeanUtils.copyProperties(sinf,sinfChange);
+        String fullName=sinf.getProvice()+"_"+sinf.getCity()+"_"+sinf.getCountry()+"_"+sinf.getStationName();
+        sinfChange.setFullName(fullName);
+        sinfChange.setUpdateTime(updateTime);
+        sinfChange.setUpdateReason(updateReason);
+
+        BeanUtils.copyProperties(pinf,pinfChange);
+        pinfChange.setUpdateTime(updateTime);
+        pinfChange.setUpdateReason(updateReason);
+
+        BeanUtils.copyProperties(binf,binfChange);
+        binfChange.setUpdateTime(updateTime);
+        binfChange.setUpdateReason(updateReason);
+
+        //灏嗗彉鏇磋褰曞瓨鍏ュ彉鏇磋〃
+        sinfChangeMapper.insert(sinfChange);
+        pinfChangeMapper.insert(pinfChange);
+        binfChangeMapper.insert(binfChange);
+    }
+    //鑾峰彇鏈烘埧锛岀數婧愶紝鐢垫睜缁勫彉鏇磋褰�
+    public List<StationInfChange> getSinfChange(Integer stationId) {
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.eq("station_id",stationId);
+        wrapper.last("limit 0,2");
+        wrapper.orderByDesc("update_time");
+        List<StationInfChange> list=sinfChangeMapper.selectList(wrapper);
+        return list;
+    }
+    public List<PowerInfChange> getPinfChange(Integer powerId) {
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.eq("power_id",powerId);
+        wrapper.last("limit 0,2");
+        wrapper.orderByDesc("update_time");
+        List<PowerInfChange> list=pinfChangeMapper.selectList(wrapper);
+        return list;
+    }
+
+    public List<BattInfChange> getBinfChange(Integer battgroupId) {
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.eq("battgroup_id",battgroupId);
+        wrapper.last("limit 0,2");
+        wrapper.orderByDesc("update_time");
+        List<BattInfChange> list=binfChangeMapper.selectList(wrapper);
+        return list;
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1