#
Junjie
2025-08-13 b40eab1e582d72ca2e71afb2f5604671f5193f22
#
4个文件已修改
6个文件已添加
214 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/entity/DeviceDataLog.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/mapper/DeviceDataLogMapper.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/DeviceDataLogService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/DeviceDataLogServiceImpl.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/ClearDeviceDataLogScheduler.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/protocol/CrnProtocol.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/protocol/RgvProtocol.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/RgvThread.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensCrnThread.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DeviceDataLogMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/DeviceDataLog.java
New file
@@ -0,0 +1,83 @@
package com.zy.asrs.entity;
import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableField;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.baomidou.mybatisplus.annotations.TableName;
import java.io.Serializable;
@Data
@TableName("wcs_device_data_log")
public class DeviceDataLog implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value= "")
    private Long id;
    /**
     * 设备类型
     */
    @ApiModelProperty(value= "设备类型")
    private String type;
    /**
     * 设备号
     */
    @ApiModelProperty(value= "设备号")
    @TableField("device_no")
    private Integer deviceNo;
    /**
     * 源数据
     */
    @ApiModelProperty(value= "源数据")
    @TableField("origin_data")
    private String originData;
    /**
     * 源数据解析后得到的wcs数据
     */
    @ApiModelProperty(value= "源数据解析后得到的wcs数据")
    @TableField("wcs_data")
    private String wcsData;
    /**
     * 采集时间
     */
    @ApiModelProperty(value= "采集时间")
    @TableField("create_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    public DeviceDataLog() {}
    public DeviceDataLog(String type,Integer deviceNo,String originData,String wcsData,Date createTime) {
        this.type = type;
        this.deviceNo = deviceNo;
        this.originData = originData;
        this.wcsData = wcsData;
        this.createTime = createTime;
    }
//    DeviceDataLog deviceDataLog = new DeviceDataLog(
//            null,    // 设备类型
//            null,    // 设备号
//            null,    // 源数据
//            null,    // 源数据解析后得到的wcs数据
//            null    // 采集时间
//    );
    public String getCreateTime$(){
        if (Cools.isEmpty(this.createTime)){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime);
    }
}
src/main/java/com/zy/asrs/mapper/DeviceDataLogMapper.java
New file
@@ -0,0 +1,16 @@
package com.zy.asrs.mapper;
import com.zy.asrs.entity.DeviceDataLog;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface DeviceDataLogMapper extends BaseMapper<DeviceDataLog> {
    @Delete("delete from wcs_device_data_log where create_time < DATEADD(HOUR, -24, GETDATE())")
    int clearLog();
}
src/main/java/com/zy/asrs/service/DeviceDataLogService.java
New file
@@ -0,0 +1,10 @@
package com.zy.asrs.service;
import com.zy.asrs.entity.DeviceDataLog;
import com.baomidou.mybatisplus.service.IService;
public interface DeviceDataLogService extends IService<DeviceDataLog> {
    int clearLog();//清理超过24小时日志数据
}
src/main/java/com/zy/asrs/service/impl/DeviceDataLogServiceImpl.java
New file
@@ -0,0 +1,17 @@
package com.zy.asrs.service.impl;
import com.zy.asrs.mapper.DeviceDataLogMapper;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.service.DeviceDataLogService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service("deviceDataLogService")
public class DeviceDataLogServiceImpl extends ServiceImpl<DeviceDataLogMapper, DeviceDataLog> implements DeviceDataLogService {
    @Override
    public int clearLog() {
        return this.baseMapper.clearLog();
    }
}
src/main/java/com/zy/asrs/task/ClearDeviceDataLogScheduler.java
New file
@@ -0,0 +1,24 @@
package com.zy.asrs.task;
import com.zy.asrs.service.DeviceDataLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ClearDeviceDataLogScheduler {
    @Autowired
    private DeviceDataLogService deviceDataLogService;
    /**
     * 每分钟清理24小时之前的日志
     */
    @Scheduled(cron = "1 * * * * ? ")
    public void clear() {
        deviceDataLogService.clearLog();
    }
}
src/main/java/com/zy/core/model/protocol/CrnProtocol.java
@@ -193,6 +193,11 @@
    private Integer crnLane = 1;
    /**
     * 日志采集时间
     */
    private Long deviceDataLog = System.currentTimeMillis();
    /**
     * 上一次指令下发时间
     */
    private Long lastCommandTime = System.currentTimeMillis();
src/main/java/com/zy/core/model/protocol/RgvProtocol.java
@@ -132,6 +132,11 @@
     */
    public Float xDuration;
    /**
     * 日志采集时间
     */
    private Long deviceDataLog = System.currentTimeMillis();
    public void setMode(Short mode) {
        this.mode = mode;
        this.modeType = RgvModeType.get(mode);
src/main/java/com/zy/core/thread/RgvThread.java
@@ -9,8 +9,10 @@
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasRgv;
import com.zy.asrs.entity.BasRgvOpt;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.service.BasRgvOptService;
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.common.utils.News;
import com.zy.core.RgvThread2;
import com.zy.core.cache.MessageQueue;
@@ -26,6 +28,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.Base64;
import java.util.Date;
/**
@@ -183,6 +186,22 @@
                    }
                }
                if (System.currentTimeMillis() - rgvProtocol.getDeviceDataLog() > 1000 * 5) {
                    //采集时间超过5s,保存一次数据记录
                    //保存数据记录
                    DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
                    DeviceDataLog deviceDataLog = new DeviceDataLog();
                    deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content));
                    deviceDataLog.setWcsData(JSON.toJSONString(rgvProtocol));
                    deviceDataLog.setType("rgv");
                    deviceDataLog.setDeviceNo(rgvProtocol.getRgvNo());
                    deviceDataLog.setCreateTime(new Date());
                    deviceDataLogService.insert(deviceDataLog);
                    //更新采集时间
                    rgvProtocol.setDeviceDataLog(System.currentTimeMillis());
                }
                try {
                    // 根据实时信息更新数据库
                    BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class);
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -10,8 +10,10 @@
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnOpt;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.service.BasCrnOptService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.common.utils.News;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
@@ -25,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.Base64;
import java.util.Date;
/**
@@ -205,6 +208,22 @@
                    }
                }
                if (System.currentTimeMillis() - crnProtocol.getDeviceDataLog() > 1000 * 5) {
                    //采集时间超过5s,保存一次数据记录
                    //保存数据记录
                    DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
                    DeviceDataLog deviceDataLog = new DeviceDataLog();
                    deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content));
                    deviceDataLog.setWcsData(JSON.toJSONString(crnProtocol));
                    deviceDataLog.setType("crn");
                    deviceDataLog.setDeviceNo(crnProtocol.getCrnNo());
                    deviceDataLog.setCreateTime(new Date());
                    deviceDataLogService.insert(deviceDataLog);
                    //更新采集时间
                    crnProtocol.setDeviceDataLog(System.currentTimeMillis());
                }
                try {
                    // 根据实时信息更新数据库
                    BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
src/main/resources/mapper/DeviceDataLogMapper.xml
New file
@@ -0,0 +1,16 @@
<?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.zy.asrs.mapper.DeviceDataLogMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.zy.asrs.entity.DeviceDataLog">
        <id column="id" property="id" />
        <result column="type" property="type" />
        <result column="device_no" property="deviceNo" />
        <result column="origin_data" property="originData" />
        <result column="wcs_data" property="wcsData" />
        <result column="create_time" property="createTime" />
    </resultMap>
</mapper>