Browse Source

更新设备状态变化记录功能接口

oyq28 10 months ago
parent
commit
41a8c98357

+ 8 - 4
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/collection/DeviceCollectionTaskJob.java

@@ -43,6 +43,7 @@ import org.springframework.web.client.RestTemplate;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -171,7 +172,7 @@ public class DeviceCollectionTaskJob {
         if(null == deviceCollection) return;
         if(null == deviceCollection) return;
         String nowDay = DateUtil.format(new Date(), "yyyy-MM-dd");
         String nowDay = DateUtil.format(new Date(), "yyyy-MM-dd");
         DeviceCollectionDetail deviceCollectionDetail = deviceCollectionDetailMapper.selectOne(new QueryWrap<DeviceCollectionDetail>().lambda().eq(DeviceCollectionDetail::getDeviceIp, ip).eq(DeviceCollectionDetail::getCreateDate, nowDay));
         DeviceCollectionDetail deviceCollectionDetail = deviceCollectionDetailMapper.selectOne(new QueryWrap<DeviceCollectionDetail>().lambda().eq(DeviceCollectionDetail::getDeviceIp, ip).eq(DeviceCollectionDetail::getCreateDate, nowDay));
-        DeviceStateRecord deviceStateRecord = DeviceStateRecord.builder().machineId(deviceCollection.getDeviceId()).createDate(nowDay).build();
+        DeviceStateRecord deviceStateRecord = DeviceStateRecord.builder().machineId(deviceCollection.getDeviceId()).createDate(nowDay).deviceIp(deviceCollection.getIp()).deviceName(deviceCollection.getDeviceName()).deviceCode(deviceCollection.getDeviceCode()).build();
         boolean addFlag = false;
         boolean addFlag = false;
         if(BeanUtil.isEmpty(deviceCollectionDetail)){
         if(BeanUtil.isEmpty(deviceCollectionDetail)){
             //当日第一条数据
             //当日第一条数据
@@ -190,7 +191,7 @@ public class DeviceCollectionTaskJob {
             deviceCollectionDetail.setTodayWorkTime(0);
             deviceCollectionDetail.setTodayWorkTime(0);
 
 
             //初始化日志信息 默认空闲状态
             //初始化日志信息 默认空闲状态
-            deviceStateRecord.setDeviceStatus(0);
+            deviceStateRecord.setDeviceStatus(0).setStartTime(LocalDateTime.now());
             deviceStateRecordService.save(deviceStateRecord);
             deviceStateRecordService.save(deviceStateRecord);
 
 
         }
         }
@@ -284,10 +285,13 @@ public class DeviceCollectionTaskJob {
             }
             }
         }
         }
         //获取上一条日志记录
         //获取上一条日志记录
-        DeviceStateRecord historyRecord = deviceStateRecordService.getOne(new LbqWrapper<DeviceStateRecord>().eq(DeviceStateRecord::getMachineId,deviceCollection.getDeviceId()).eq(DeviceStateRecord::getCreateDate, nowDay).orderByDesc(DeviceStateRecord::getCreateTime).last("limit 0"));
+        DeviceStateRecord historyRecord = deviceStateRecordService.getOne(new LbqWrapper<DeviceStateRecord>().eq(DeviceStateRecord::getMachineId,deviceCollection.getDeviceId()).eq(DeviceStateRecord::getCreateDate, nowDay).isNull(DeviceStateRecord::getEndTime).orderByDesc(DeviceStateRecord::getCreateTime).last("limit 1"));
         if(null != historyRecord && historyRecord.getDeviceStatus()!=currentState){
         if(null != historyRecord && historyRecord.getDeviceStatus()!=currentState){
+            //结束前日志记录完成时间
+            historyRecord.setEndTime(LocalDateTime.now());
+            deviceStateRecordService.updateById(historyRecord);
             //新增状态变化日志记录
             //新增状态变化日志记录
-            deviceStateRecord.setDeviceStatus(currentState);
+            deviceStateRecord.setDeviceStatus(currentState).setStartTime(LocalDateTime.now());
             deviceStateRecordService.save(deviceStateRecord);
             deviceStateRecordService.save(deviceStateRecord);
         }
         }
 
 

+ 1 - 1
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/CuttingToolSynRecordMapper.xml

@@ -26,7 +26,7 @@
         select
         select
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
         from (
         from (
-             select r.*, t.name from imcs_cutting_tool_syn_record r left join imcs_tenant_productionresource t
+             select r.*, t.name as cutting_tool_name from imcs_cutting_tool_syn_record r left join imcs_tenant_productionresource t
              on r.machine_id = t.id
              on r.machine_id = t.id
         ) s ${ew.customSqlSegment}
         ) s ${ew.customSqlSegment}
     </select>
     </select>

+ 3 - 2
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/DeviceCollectionMapper.xml

@@ -10,6 +10,7 @@
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="update_user" jdbcType="BIGINT" property="updateUser"/>
         <result column="update_user" jdbcType="BIGINT" property="updateUser"/>
         <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
         <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
+        <result column="device_code" jdbcType="VARCHAR" property="deviceCode"/>
         <result column="ip" jdbcType="VARCHAR" property="ip"/>
         <result column="ip" jdbcType="VARCHAR" property="ip"/>
         <result column="device_id" jdbcType="BIGINT" property="deviceId"/>
         <result column="device_id" jdbcType="BIGINT" property="deviceId"/>
         <result column="device_info" jdbcType="VARCHAR" property="deviceInfo"/>
         <result column="device_info" jdbcType="VARCHAR" property="deviceInfo"/>
@@ -19,7 +20,7 @@
     <!-- 通用查询结果列 -->
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
         id,create_time,create_user,update_time,update_user,
         id,create_time,create_user,update_time,update_user,
-        device_name,ip,device_id,device_info, error_info
+        device_name,device_code,ip,device_id,device_info, error_info
     </sql>
     </sql>
 
 
     <!-- 分页 -->
     <!-- 分页 -->
@@ -27,7 +28,7 @@
         select
         select
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
         from(
         from(
-           select d.*, t.name as device_name
+           select d.*, t.name as device_name, t.code as device_code
             from device_collection d left join imcs_tenant_productionresource t on d.device_id = t.id
             from device_collection d left join imcs_tenant_productionresource t on d.device_id = t.id
         ) s ${ew.customSqlSegment}
         ) s ${ew.customSqlSegment}
     </select>
     </select>

+ 7 - 4
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/DeviceStateRecordMapper.xml

@@ -9,15 +9,19 @@
         <result column="create_user" jdbcType="BIGINT" property="createUser"/>
         <result column="create_user" jdbcType="BIGINT" property="createUser"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="update_user" jdbcType="BIGINT" property="updateUser"/>
         <result column="update_user" jdbcType="BIGINT" property="updateUser"/>
-        <result column="name" jdbcType="VARCHAR" property="name"/>
+        <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
+        <result column="device_code" jdbcType="VARCHAR" property="deviceCode"/>
+        <result column="device_ip" jdbcType="VARCHAR" property="deviceIp"/>
         <result column="create_date" jdbcType="VARCHAR" property="createDate"/>
         <result column="create_date" jdbcType="VARCHAR" property="createDate"/>
+        <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
+        <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
         <result column="machine_id" jdbcType="BIGINT" property="machineId"/>
         <result column="machine_id" jdbcType="BIGINT" property="machineId"/>
         <result column="device_state" jdbcType="VARCHAR" property="deviceState"/>
         <result column="device_state" jdbcType="VARCHAR" property="deviceState"/>
     </resultMap>
     </resultMap>
 
 
     <!-- 通用查询结果列 -->
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
-        id,create_time,create_user,update_time,update_user,name,
+        id,create_time,create_user,update_time,update_user,device_name,device_ip,device_code,start_time,end_time,
         machine_id, create_date, device_state
         machine_id, create_date, device_state
     </sql>
     </sql>
 
 
@@ -26,8 +30,7 @@
         select
         select
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
         from (
         from (
-             select r.*, t.name from device_state_record r left join imcs_tenant_productionresource t
-             on r.machine_id = t.id
+             select r.* from device_state_record r
         ) s ${ew.customSqlSegment}
         ) s ${ew.customSqlSegment}
     </select>
     </select>
 
 

+ 4 - 0
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/entity/DeviceCollection.java

@@ -130,6 +130,10 @@ public class DeviceCollection{
     @TableField(exist = false)
     @TableField(exist = false)
     private Map<String, Object> deviceInfoMap;
     private Map<String, Object> deviceInfoMap;
 
 
+    @ApiModelProperty(value = "设备编号")
+    @TableField(exist = false)
+    private String deviceCode;
+
     @Builder
     @Builder
     public DeviceCollection(Long id, Date createTime, Date updateTime,String cuttingToolInfo, String status, String errorInfo,
     public DeviceCollection(Long id, Date createTime, Date updateTime,String cuttingToolInfo, String status, String errorInfo,
                             Long deviceId, String deviceInfo, String createUser, String updateUser, String ip) {
                             Long deviceId, String deviceInfo, String createUser, String updateUser, String ip) {

+ 43 - 1
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/entity/DeviceStateRecord.java

@@ -50,8 +50,44 @@ public class DeviceStateRecord extends Entity<Long> {
     private Integer deviceStatus;
     private Integer deviceStatus;
 
 
 
 
+    /**
+     * 设备IP
+     */
+    @ApiModelProperty(value = "设备IP")
+    @Size(max = 100, message = "设备IP长度不能超过50")
+    @TableField(value = "device_ip", condition = LIKE)
+    @Excel(name = "设备IP")
+    private String deviceIp;
+
+    /**
+     * 设备名称
+     */
+    @ApiModelProperty(value = "设备名称")
+    @Size(max = 255, message = "设备名称长度不能超过255")
+    @TableField(value = "device_name", condition = LIKE)
+    @Excel(name = "设备名称")
+    private String deviceName;
+
+    /**
+     * 设备名称
+     */
+    @ApiModelProperty(value = "设备编号")
+    @Size(max = 255, message = "设备编号长度不能超过255")
+    @TableField(value = "device_code", condition = LIKE)
+    @Excel(name = "设备编号")
+    private String deviceCode;
+
+    @ApiModelProperty(value = "开始时间")
+    @TableField(value = "start_time", condition = LIKE)
+    private LocalDateTime startTime;
+
+    @ApiModelProperty(value = "结束时间")
+    @TableField(value = "end_time", condition = LIKE)
+    private LocalDateTime endTime;
+
+
     @Builder
     @Builder
-    public DeviceStateRecord(Long id, Long machineId, String createDate, Integer deviceStatus, Long createUser, LocalDateTime createTime, Long updateUser, LocalDateTime updateTime) {
+    public DeviceStateRecord(Long id, Long machineId, String createDate, Integer deviceStatus, String deviceIp, String deviceName, String deviceCode, LocalDateTime startTime, LocalDateTime endTime, Long createUser, LocalDateTime createTime, Long updateUser, LocalDateTime updateTime) {
         this.id = id;
         this.id = id;
         this.machineId = machineId;
         this.machineId = machineId;
         this.createDate = createDate;
         this.createDate = createDate;
@@ -60,5 +96,11 @@ public class DeviceStateRecord extends Entity<Long> {
         this.updateUser = updateUser;
         this.updateUser = updateUser;
         this.createTime = createTime;
         this.createTime = createTime;
         this.updateTime = updateTime;
         this.updateTime = updateTime;
+        this.deviceIp = deviceIp;
+        this.deviceCode = deviceCode;
+        this.deviceName = deviceName;
+        this.startTime = startTime;
+        this.endTime = endTime;
+
     }
     }
 }
 }

+ 11 - 2
图南新增SQL/device_state_record.sql

@@ -11,7 +11,7 @@
  Target Server Version : 50728 (5.7.28-log)
  Target Server Version : 50728 (5.7.28-log)
  File Encoding         : 65001
  File Encoding         : 65001
 
 
- Date: 09/11/2024 13:54:13
+ Date: 13/11/2024 02:54:20
 */
 */
 
 
 SET NAMES utf8mb4;
 SET NAMES utf8mb4;
@@ -24,8 +24,13 @@ DROP TABLE IF EXISTS `device_state_record`;
 CREATE TABLE `device_state_record`  (
 CREATE TABLE `device_state_record`  (
   `id` bigint(24) NOT NULL,
   `id` bigint(24) NOT NULL,
   `machine_id` bigint(24) NOT NULL,
   `machine_id` bigint(24) NOT NULL,
-  `create_date` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
+  `device_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
+  `device_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
+  `device_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
+  `start_timne` datetime NULL DEFAULT NULL,
+  `end_time` datetime NULL DEFAULT NULL,
   `device_state` int(11) NOT NULL COMMENT '设备状态(0-空闲 1-加工 2-故障 3-离线)',
   `device_state` int(11) NOT NULL COMMENT '设备状态(0-空闲 1-加工 2-故障 3-离线)',
+  `create_date` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
   `create_time` datetime NULL DEFAULT NULL,
   `create_time` datetime NULL DEFAULT NULL,
   `create_user` bigint(20) NULL DEFAULT NULL,
   `create_user` bigint(20) NULL DEFAULT NULL,
   `update_time` datetime NULL DEFAULT NULL,
   `update_time` datetime NULL DEFAULT NULL,
@@ -33,4 +38,8 @@ CREATE TABLE `device_state_record`  (
   PRIMARY KEY (`id`) USING BTREE
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;
 
 
+-- ----------------------------
+-- Records of device_state_record
+-- ----------------------------
+
 SET FOREIGN_KEY_CHECKS = 1;
 SET FOREIGN_KEY_CHECKS = 1;