From 9b7851be1946bdef491aa8dbdd5ab73b12af8456 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期四, 19 十二月 2024 15:13:36 +0800
Subject: [PATCH] 记录出库调用agv接口日志
---
src/main/java/com/zy/asrs/entity/ApiLog.java | 193 ++++++++++++++++++++++++++++++++
src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java | 51 ++++++++
src/main/java/com/zy/asrs/mapper/ApiLogMapper.java | 14 ++
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 19 +++
src/main/java/com/zy/asrs/service/ApiLogService.java | 12 ++
src/main/resources/mapper/ApiLogMapper.xml | 32 +++++
6 files changed, 321 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/asrs/entity/ApiLog.java b/src/main/java/com/zy/asrs/entity/ApiLog.java
new file mode 100644
index 0000000..45101d1
--- /dev/null
+++ b/src/main/java/com/zy/asrs/entity/ApiLog.java
@@ -0,0 +1,193 @@
+package com.zy.asrs.entity;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.core.common.Cools;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+@Data
+@TableName("man_api_log")
+public class ApiLog implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * ID
+ */
+ @ApiModelProperty(value= "ID")
+ @TableId(value = "id", type = IdType.AUTO)
+ private Long id;
+
+ /**
+ * 鏃ュ織缂栧彿
+ */
+ @ApiModelProperty(value= "鏃ュ織缂栧彿")
+ private String uuid;
+
+ /**
+ * 鍚嶇О绌洪棿
+ */
+ @ApiModelProperty(value= "鍚嶇О绌洪棿")
+ private String namespace;
+
+ /**
+ * 鎺ュ彛鍦板潃
+ */
+ @ApiModelProperty(value= "鎺ュ彛鍦板潃")
+ private String url;
+
+ /**
+ * 骞冲彴瀵嗛挜
+ */
+ @ApiModelProperty(value= "骞冲彴瀵嗛挜")
+ private String appkey;
+
+ /**
+ * 鏃堕棿鎴�
+ */
+ @ApiModelProperty(value= "鏃堕棿鎴�")
+ private String timestamp;
+
+ /**
+ * 瀹㈡埛绔疘P
+ */
+ @ApiModelProperty(value= "瀹㈡埛绔疘P")
+ @TableField("client_ip")
+ private String clientIp;
+
+ /**
+ * 璇锋眰鍐呭
+ */
+ @ApiModelProperty(value= "璇锋眰鍐呭")
+ private String request;
+
+ /**
+ * 鍝嶅簲鍐呭
+ */
+ @ApiModelProperty(value= "鍝嶅簲鍐呭")
+ private String response;
+
+ /**
+ * 寮傚父鍐呭
+ */
+ @ApiModelProperty(value= "寮傚父鍐呭")
+ private String err;
+
+ /**
+ * 缁撴灉 1: 鎴愬姛 0: 澶辫触
+ */
+ @ApiModelProperty(value= "缁撴灉 1: 鎴愬姛 0: 澶辫触 ")
+ private Integer result;
+
+ /**
+ * 鐘舵�� 1: 姝e父 0: 绂佺敤
+ */
+ @ApiModelProperty(value= "鐘舵�� 1: 姝e父 0: 绂佺敤 ")
+ private Integer status;
+
+ /**
+ * 娣诲姞鏃堕棿
+ */
+ @ApiModelProperty(value= "娣诲姞鏃堕棿")
+ @TableField("create_time")
+ @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+ private Date createTime;
+
+ /**
+ * 淇敼鏃堕棿
+ */
+ @ApiModelProperty(value= "淇敼鏃堕棿")
+ @TableField("update_time")
+ @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+ private Date updateTime;
+
+ /**
+ * 澶囨敞
+ */
+ @ApiModelProperty(value= "澶囨敞")
+ private String memo;
+
+ public ApiLog() {}
+
+ public ApiLog(String uuid, String namespace, String url, String appkey, String timestamp, String clientIp, String request, String response, String err, Integer result, Integer status, Date createTime, Date updateTime, String memo) {
+ this.uuid = uuid;
+ this.namespace = namespace;
+ this.url = url;
+ this.appkey = appkey;
+ this.timestamp = timestamp;
+ this.clientIp = clientIp;
+ this.request = request;
+ this.response = response;
+ this.err = err;
+ this.result = result;
+ this.status = status;
+ this.createTime = createTime;
+ this.updateTime = updateTime;
+ this.memo = memo;
+ }
+
+// ApiLog apiLog = new ApiLog(
+// null, // 鏃ュ織缂栧彿
+// null, // 鍚嶇О绌洪棿
+// null, // 鎺ュ彛鍦板潃
+// null, // 骞冲彴瀵嗛挜
+// null, // 鏃堕棿鎴�
+// null, // 瀹㈡埛绔疘P
+// null, // 璇锋眰鍐呭
+// null, // 鍝嶅簲鍐呭
+// null, // 寮傚父鍐呭
+// null, // 缁撴灉
+// null, // 鐘舵��
+// null, // 娣诲姞鏃堕棿
+// null, // 淇敼鏃堕棿
+// null // 澶囨敞
+// );
+
+ public String getResult$(){
+ if (null == this.result){ return null; }
+ switch (this.result){
+ case 1:
+ return "鎴愬姛";
+ case 0:
+ return "澶辫触";
+ default:
+ return String.valueOf(this.result);
+ }
+ }
+
+ public String getStatus$(){
+ if (null == this.status){ return null; }
+ switch (this.status){
+ case 1:
+ return "姝e父";
+ case 0:
+ return "绂佺敤";
+ default:
+ return String.valueOf(this.status);
+ }
+ }
+
+ public String getCreateTime$(){
+ if (Cools.isEmpty(this.createTime)){
+ return "";
+ }
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime);
+ }
+
+ public String getUpdateTime$(){
+ if (Cools.isEmpty(this.updateTime)){
+ return "";
+ }
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime);
+ }
+
+
+}
diff --git a/src/main/java/com/zy/asrs/mapper/ApiLogMapper.java b/src/main/java/com/zy/asrs/mapper/ApiLogMapper.java
new file mode 100644
index 0000000..a20d98f
--- /dev/null
+++ b/src/main/java/com/zy/asrs/mapper/ApiLogMapper.java
@@ -0,0 +1,14 @@
+package com.zy.asrs.mapper;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.zy.asrs.entity.ApiLog;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+@Mapper
+@Repository
+public interface ApiLogMapper extends BaseMapper<ApiLog> {
+
+ int clearWeekBefore();
+
+}
diff --git a/src/main/java/com/zy/asrs/service/ApiLogService.java b/src/main/java/com/zy/asrs/service/ApiLogService.java
new file mode 100644
index 0000000..8e3c698
--- /dev/null
+++ b/src/main/java/com/zy/asrs/service/ApiLogService.java
@@ -0,0 +1,12 @@
+package com.zy.asrs.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.zy.asrs.entity.ApiLog;
+
+public interface ApiLogService extends IService<ApiLog> {
+
+ void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success);
+
+ boolean clearWeekBefore();
+
+}
diff --git a/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java
new file mode 100644
index 0000000..30a725f
--- /dev/null
+++ b/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java
@@ -0,0 +1,51 @@
+package com.zy.asrs.service.impl;
+
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.core.common.SnowflakeIdWorker;
+import com.zy.asrs.entity.ApiLog;
+import com.zy.asrs.mapper.ApiLogMapper;
+import com.zy.asrs.service.ApiLogService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+@Slf4j
+@Service("apiLogService")
+public class ApiLogServiceImpl extends ServiceImpl<ApiLogMapper, ApiLog> implements ApiLogService {
+
+ @Autowired
+ private SnowflakeIdWorker snowflakeIdWorker;
+
+ @Async
+ @Override
+ public void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success) {
+ Date now = new Date();
+ ApiLog apiLog = new ApiLog(
+ String.valueOf(snowflakeIdWorker.nextId()), // 鏃ュ織缂栧彿
+ namespace, // 鍚嶇О绌洪棿
+ url, // 鎺ュ彛鍦板潃
+ appkey, // 骞冲彴瀵嗛挜
+ String.valueOf(now.getTime()), // 鏃堕棿鎴�
+ ip, // 瀹㈡埛绔疘P
+ request, // 璇锋眰鍐呭
+ response,
+ null, // 寮傚父鍐呭
+ success?1:0 , // 缁撴灉
+ 1, // 鐘舵��
+ now, // 娣诲姞鏃堕棿
+ null, // 淇敼鏃堕棿
+ null // 澶囨敞
+ );
+ if (!this.insert(apiLog)) {
+ log.error("鎺ュ彛璋冪敤鏃ュ織淇濆瓨澶辫触锛�");
+ }
+ }
+
+ @Override
+ public boolean clearWeekBefore() {
+ return this.baseMapper.clearWeekBefore() > 0;
+ }
+}
diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 21950de..c79e81e 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -50,6 +50,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -100,6 +101,9 @@
private WrkMastService wrkMastService;
@Autowired
private BasRgvMapService basRgvMapService;
+
+ @Resource
+ private ApiLogService apiLogService;
@Value("${wms.url}")
private String wmsUrl;
@@ -2153,6 +2157,21 @@
// log.info("杞彂agv浠诲姟锛氳姹備綋:"+JSONObject.toJSONString(requestParam)+",杩斿洖鍊�:"+jsonObject);
}catch (Exception e){
+ } finally {
+ try {
+ // 淇濆瓨鎺ュ彛鏃ュ織
+ apiLogService.save(
+ "鍑哄簱鍛煎彨agv",
+ url + path,
+ null,
+ "127.0.0.1",
+ JSONObject.toJSONString(requestParam),
+ response,
+ success.equals("SUCCESS")
+ );
+ } catch (Exception e) {
+ log.error("", e);
+ }
}
return success;
}
diff --git a/src/main/resources/mapper/ApiLogMapper.xml b/src/main/resources/mapper/ApiLogMapper.xml
new file mode 100644
index 0000000..05e704e
--- /dev/null
+++ b/src/main/resources/mapper/ApiLogMapper.xml
@@ -0,0 +1,32 @@
+<?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.ApiLogMapper">
+
+ <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+ <resultMap id="BaseResultMap" type="com.zy.asrs.entity.ApiLog">
+ <id column="id" property="id" />
+ <result column="uuid" property="uuid" />
+ <result column="namespace" property="namespace" />
+ <result column="url" property="url" />
+ <result column="appkey" property="appkey" />
+ <result column="timestamp" property="timestamp" />
+ <result column="client_ip" property="clientIp" />
+ <result column="request" property="request" />
+ <result column="response" property="response" />
+ <result column="err" property="err" />
+ <result column="result" property="result" />
+ <result column="status" property="status" />
+ <result column="create_time" property="createTime" />
+ <result column="update_time" property="updateTime" />
+ <result column="memo" property="memo" />
+
+ </resultMap>
+
+ <delete id="clearWeekBefore">
+ delete from man_api_log
+ where 1=1
+ and datediff(week,create_time,getdate()) >= 1
+ and result != 1
+ </delete>
+
+</mapper>
--
Gitblit v1.9.1