Ver Fonte

添加设备日志自动清除(删除三个月前的数据)

zhifei há 11 meses atrás
pai
commit
fb064cf7ec

+ 1 - 1
warewms-admin/src/main/resources/application-prod.yml

@@ -67,7 +67,7 @@ spring:
     druid:
       # 主库数据源
       master:
-        url: jdbc:mysql://localhost:3306/trace_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+        url: jdbc:mysql://172.20.2.8:3306/trace_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
         username: warewms
         password: warewms123
       # 从库数据源

+ 1 - 1
warewms-admin/src/main/resources/application.yml

@@ -1,7 +1,7 @@
 # 指定环境的默认配置
 spring:
   profiles:
-    active: test
+    active: prod
 
 # MES对接接口
 MES:

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader12Connect.java

@@ -237,7 +237,7 @@ public class CodeReader12Connect implements TCPConnectBase {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "识别到码:" + message, "1"));
             }
         }catch (Exception e){
-            log.error("大散盘4号行车读码任务执行异常,msg:{}",e.getMessage());
+            log.error("大散盘4号行车读码任务执行异常,msg:",e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-4-27.12", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java

@@ -194,7 +194,7 @@ public class CodeReader13Connect implements TCPConnectBase {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "识别到码:" + message, "1"));
             }
         }catch (Exception e){
-            log.error("退火上料读码任务执行异常,msg:{}",e.getMessage());
+            log.error("退火上料读码任务执行异常,msg:",e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java

@@ -196,7 +196,7 @@ public class CodeReader14Connect implements TCPConnectBase {
             }
             Thread.sleep(500);
         }catch (Exception e){
-            log.error("退货下料读码任务执行异常,msg:{}",e.getMessage());
+            log.error("退货下料读码任务执行异常,msg:",e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }

+ 1 - 2
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader3Connect.java

@@ -240,8 +240,7 @@ public class CodeReader3Connect implements TCPConnectBase {
             //添加日志
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "识别到码:" + message, "1"));
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("倒角读码任务执行异常,msg:{}", e.getMessage());
+            log.error("倒角读码任务执行异常,msg:",e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_DMQ-1-27.3", deviceName, "读码任务出错,msg:" + StringUtils.substring(e.getMessage(), 0, 2000), "2"));
         }
     }

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader5Connect.java

@@ -244,7 +244,7 @@ public class CodeReader5Connect implements TCPConnectBase {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "识别到码:" + message, "1"));
             }
         } catch (Exception e) {
-            log.error("铣面读码任务执行异常,msg:{}", e.getMessage());
+            log.error("铣面读码任务执行异常,msg:", e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_XiMian_DMQ-1-27.5", deviceName, "读码任务出错,msg:" + e.getMessage(), "2"));
         }
     }

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader6Connect.java

@@ -229,7 +229,7 @@ public class CodeReader6Connect implements TCPConnectBase {
                 redisCache.setCacheObject(DeviceNameEnum.ZHAZHIPLC.getDeviceName(),DeviceNameEnum.ZHAZHIPLC.getDeviceName(),30,TimeUnit.SECONDS);
             }
         }catch (Exception e){
-            log.error("轧制读码任务执行异常,msg:{}",e.getMessage());
+            log.error("轧制读码任务执行异常,msg:",e);
             SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_ZhaZhi_DMQ-1-27.6", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }

+ 2 - 1
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader8Connect.java

@@ -217,7 +217,8 @@ public class CodeReader8Connect implements TCPConnectBase {
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-2-27.8", deviceName, "读码器识别到码:" + message, "1"));
             }
         }catch (Exception e){
-            log.error("大散盘2号行车读码任务执行异常,msg:{}",e.getMessage());
+            log.error("大散盘2号行车读码任务执行异常,msg:",e);
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaSanPan_DMQ-2-27.8", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
         }
     }
 }

+ 11 - 0
warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java

@@ -5,6 +5,7 @@ import com.warewms.common.core.redis.RedisCache;
 import com.warewms.hailiang.enums.*;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import com.warewms.hailiang.init.TcpServiceRunner;
+import com.warewms.hailiang.service.DeviceLogService;
 import com.warewms.hailiang.service.ProcessRealizationService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +32,8 @@ public class TraceJob {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    DeviceLogService deviceLogService;
 
     /**
      * 测试
@@ -158,4 +161,12 @@ public class TraceJob {
             processRealizationService.CodeReadingProcess("CodeReader14");
         }
     }
+
+    /**
+     * 清空PLC信号日志
+     */
+    public void cleanPLCDeviceLog() {
+        int i = deviceLogService.cleanUpDataFromAWeekAgo();
+        log.info("已清除三个月前的数据,数量:{}",i);
+    }
 }

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/mapper/DeviceLogMapper.java

@@ -11,7 +11,7 @@ import com.warewms.hailiang.domain.DeviceLog;
 * @Entity  DeviceLog
 */
 public interface DeviceLogMapper extends BaseMapper<DeviceLog> {
-
+    int cleanUpDataFromAWeekAgo();
 }
 
 

+ 2 - 0
warewms-system/src/main/java/com/warewms/hailiang/service/DeviceLogService.java

@@ -20,4 +20,6 @@ public interface DeviceLogService extends IService<DeviceLog> {
     void createLog(DeviceLog deviceLog);
 
     List<DeviceLog> getList(DeviceLog deviceLog);
+
+    int cleanUpDataFromAWeekAgo();
 }

+ 4 - 0
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceLogServiceImpl.java

@@ -95,6 +95,10 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
         }).collect(Collectors.toList());
     }
 
+    @Override
+    public int cleanUpDataFromAWeekAgo() {
+        return  deviceLogMapper.cleanUpDataFromAWeekAgo();
+    }
 }
 
 

+ 4 - 0
warewms-system/src/main/resources/mapper/hailiang/DeviceLogMapper.xml

@@ -21,4 +21,8 @@
         content,status,create_time,
         update_by,update_time,remark
     </sql>
+
+    <delete id="cleanUpDataFromAWeekAgo">
+        delete from device_log where DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL 3 MONTH));
+    </delete>
 </mapper>