Browse Source

2025-11-04

pc接口日志管理
master
fengyuan_yang 4 months ago
parent
commit
5134773e86
  1. 1
      src/main/java/com/gaotao/modules/boxManage/data/SoReceiveCasesData.java
  2. 1
      src/main/java/com/gaotao/modules/boxManage/entity/SoReceiveCases.java
  3. 72
      src/main/java/com/gaotao/modules/sys/controller/InterfaceLogController.java
  4. 25
      src/main/java/com/gaotao/modules/sys/dao/ApiLogValuesDetailDao.java
  5. 24
      src/main/java/com/gaotao/modules/sys/dao/ApiLogValuesHeadDao.java
  6. 32
      src/main/java/com/gaotao/modules/sys/dao/InterfaceLogDao.java
  7. 91
      src/main/java/com/gaotao/modules/sys/entity/ApiLogEntity.java
  8. 56
      src/main/java/com/gaotao/modules/sys/entity/ApiLogValuesDetailEntity.java
  9. 50
      src/main/java/com/gaotao/modules/sys/entity/ApiLogValuesHeadEntity.java
  10. 33
      src/main/java/com/gaotao/modules/sys/service/InterfaceLogService.java
  11. 150
      src/main/java/com/gaotao/modules/sys/service/impl/InterfaceLogServiceImpl.java
  12. 45
      src/main/resources/mapper/sys/ApiLogValuesDetailDao.xml
  13. 43
      src/main/resources/mapper/sys/ApiLogValuesHeadDao.xml
  14. 118
      src/main/resources/mapper/sys/InterfaceLogDao.xml

1
src/main/java/com/gaotao/modules/boxManage/data/SoReceiveCasesData.java

@ -44,4 +44,5 @@ public class SoReceiveCasesData extends SoReceiveCases {

1
src/main/java/com/gaotao/modules/boxManage/entity/SoReceiveCases.java

@ -187,4 +187,5 @@ public class SoReceiveCases {

72
src/main/java/com/gaotao/modules/sys/controller/InterfaceLogController.java

@ -0,0 +1,72 @@
package com.gaotao.modules.sys.controller;
import com.gaotao.common.utils.PageUtils;
import com.gaotao.common.utils.R;
import com.gaotao.modules.sys.service.InterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 接口日志管理
*/
@RestController
@RequestMapping("/sys/interfaceLog")
public class InterfaceLogController {
@Autowired
private InterfaceLogService interfaceLogService;
/**
* 查询接口日志列表
*/
@PostMapping("/list")
public R list(@RequestBody Map<String, Object> params) {
PageUtils page = interfaceLogService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 查询接口参数详情
*/
@PostMapping("/getParams")
public R getParams(@RequestBody Map<String, Object> params) {
String site = (String) params.get("site");
String buNo = (String) params.get("buNo");
String requestId = (String) params.get("requestId");
Integer requestGroupId = params.get("requestGroupId") != null ?
Integer.parseInt(params.get("requestGroupId").toString()) : null;
return interfaceLogService.getParams(site, buNo, requestId, requestGroupId);
}
/**
* 批量删除接口日志
*/
@PostMapping("/delete")
public R delete(@RequestBody Map<String, Object> params) {
Object[] idsObj = (Object[]) params.get("ids");
Long[] ids = new Long[idsObj.length];
for (int i = 0; i < idsObj.length; i++) {
ids[i] = Long.parseLong(idsObj[i].toString());
}
return interfaceLogService.deleteBatch(ids);
}
/**
* 批量重试接口
*/
@PostMapping("/retry")
public R retry(@RequestBody Map<String, Object> params) {
Object[] idsObj = (Object[]) params.get("ids");
Long[] ids = new Long[idsObj.length];
for (int i = 0; i < idsObj.length; i++) {
ids[i] = Long.parseLong(idsObj[i].toString());
}
return interfaceLogService.retryBatch(ids);
}
}

25
src/main/java/com/gaotao/modules/sys/dao/ApiLogValuesDetailDao.java

@ -0,0 +1,25 @@
package com.gaotao.modules.sys.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gaotao.modules.sys.entity.ApiLogValuesDetailEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 接口日志参数明细表DAO
*/
@Mapper
public interface ApiLogValuesDetailDao extends BaseMapper<ApiLogValuesDetailEntity> {
/**
* 查询接口参数明细列表
*/
List<Map<String, Object>> queryDetailList(@Param("site") String site,
@Param("buNo") String buNo,
@Param("requestId") String requestId,
@Param("requestGroupId") Integer requestGroupId);
}

24
src/main/java/com/gaotao/modules/sys/dao/ApiLogValuesHeadDao.java

@ -0,0 +1,24 @@
package com.gaotao.modules.sys.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gaotao.modules.sys.entity.ApiLogValuesHeadEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Map;
/**
* 接口日志参数主表DAO
*/
@Mapper
public interface ApiLogValuesHeadDao extends BaseMapper<ApiLogValuesHeadEntity> {
/**
* 查询接口参数主表
*/
Map<String, Object> queryHead(@Param("site") String site,
@Param("buNo") String buNo,
@Param("requestId") String requestId,
@Param("requestGroupId") Integer requestGroupId);
}

32
src/main/java/com/gaotao/modules/sys/dao/InterfaceLogDao.java

@ -0,0 +1,32 @@
package com.gaotao.modules.sys.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gaotao.modules.sys.entity.ApiLogEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 接口日志DAO
*/
@Mapper
public interface InterfaceLogDao extends BaseMapper<ApiLogEntity> {
/**
* 查询接口日志列表
*/
List<Map<String, Object>> queryList(Map<String, Object> params);
/**
* 查询接口日志总数
*/
int queryTotal(Map<String, Object> params);
/**
* 批量删除
*/
int deleteBatch(@Param("ids") Long[] ids);
}

91
src/main/java/com/gaotao/modules/sys/entity/ApiLogEntity.java

@ -0,0 +1,91 @@
package com.gaotao.modules.sys.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 接口日志
*/
@Data
@TableName("api_log")
public class ApiLogEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Long id;
// 站点
private String site;
// BU编号
private String buNo;
// 接口日志ID
private String requestId;
// 接口名称
private String interfaceName;
// 接口分组ID
private Integer requestGroupId;
// 关联单据号
private String reDocumentNo;
// 关联单据类型
private String reDocumentType;
// 关联单号
private String orderNo;
// 关联单行号
private String seqNo;
// 状态码
private String statusCode;
// 消息
private String message;
// 请求数据
private String requestData;
// 来源系统
private String sourceSystem;
// 目标系统
private String targetSystem;
// 是否需要重试
private Integer needRetryFlag;
// 已重试次数
private Integer retryCount;
// 最大重试次数
private Integer maxRetryCount;
// 重试间隔分钟
private Integer retryInterval;
// 下次重试时间
private Date nextRetryTime;
// 上次重试时间
private Date lastRetryTime;
// 上次返回内容
private String lastResponseData;
// 创建人
private String createdBy;
// 创建时间
private Date createdDate;
}

56
src/main/java/com/gaotao/modules/sys/entity/ApiLogValuesDetailEntity.java

@ -0,0 +1,56 @@
package com.gaotao.modules.sys.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 接口日志参数明细表
*/
@Data
@TableName("api_log_values_detail")
public class ApiLogValuesDetailEntity implements Serializable {
private static final long serialVersionUID = 1L;
// 站点
private String site;
// BU编号
private String buNo;
// 请求ID
private String requestId;
// 请求分组ID
private Integer requestGroupId;
// 接口参数1-20
private String orderref1;
private String orderref2;
private String orderref3;
private String orderref4;
private String orderref5;
private String orderref6;
private String orderref7;
private String orderref8;
private String orderref9;
private String orderref10;
private String orderref11;
private String orderref12;
private String orderref13;
private String orderref14;
private String orderref15;
private String orderref16;
private String orderref17;
private String orderref18;
private String orderref19;
private String orderref20;
// 分组ID
@TableId(type = IdType.AUTO)
private Integer groupId;
}

50
src/main/java/com/gaotao/modules/sys/entity/ApiLogValuesHeadEntity.java

@ -0,0 +1,50 @@
package com.gaotao.modules.sys.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 接口日志参数主表
*/
@Data
@TableName("api_log_values_head")
public class ApiLogValuesHeadEntity implements Serializable {
private static final long serialVersionUID = 1L;
// 站点
private String site;
// BU编号
private String buNo;
// 请求ID
private String requestId;
// 请求分组ID
private Integer requestGroupId;
// 接口参数1-20
private String orderref1;
private String orderref2;
private String orderref3;
private String orderref4;
private String orderref5;
private String orderref6;
private String orderref7;
private String orderref8;
private String orderref9;
private String orderref10;
private String orderref11;
private String orderref12;
private String orderref13;
private String orderref14;
private String orderref15;
private String orderref16;
private String orderref17;
private String orderref18;
private String orderref19;
private String orderref20;
}

33
src/main/java/com/gaotao/modules/sys/service/InterfaceLogService.java

@ -0,0 +1,33 @@
package com.gaotao.modules.sys.service;
import com.gaotao.common.utils.PageUtils;
import com.gaotao.common.utils.R;
import java.util.Map;
/**
* 接口日志服务
*/
public interface InterfaceLogService {
/**
* 查询接口日志列表分页
*/
PageUtils queryPage(Map<String, Object> params);
/**
* 查询接口参数主表+明细
*/
R getParams(String site, String buNo, String requestId, Integer requestGroupId);
/**
* 批量删除接口日志
*/
R deleteBatch(Long[] ids);
/**
* 批量重试接口
*/
R retryBatch(Long[] ids);
}

150
src/main/java/com/gaotao/modules/sys/service/impl/InterfaceLogServiceImpl.java

@ -0,0 +1,150 @@
package com.gaotao.modules.sys.service.impl;
import com.gaotao.common.utils.PageUtils;
import com.gaotao.common.utils.R;
import com.gaotao.modules.sys.dao.ApiLogValuesDetailDao;
import com.gaotao.modules.sys.dao.ApiLogValuesHeadDao;
import com.gaotao.modules.sys.dao.InterfaceLogDao;
import com.gaotao.modules.sys.service.InterfaceLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 接口日志服务实现
*/
@Service("interfaceLogService")
public class InterfaceLogServiceImpl implements InterfaceLogService {
private static final Logger logger = LoggerFactory.getLogger(InterfaceLogServiceImpl.class);
@Autowired
private InterfaceLogDao interfaceLogDao;
@Autowired
private ApiLogValuesHeadDao apiLogValuesHeadDao;
@Autowired
private ApiLogValuesDetailDao apiLogValuesDetailDao;
@Override
public PageUtils queryPage(Map<String, Object> params) {
// 获取分页参数
int page = Integer.parseInt(params.getOrDefault("page", 1).toString());
int limit = Integer.parseInt(params.getOrDefault("limit", 10).toString());
// 计算offset
int offset = (page - 1) * limit;
params.put("offset", offset);
params.put("limit", limit);
// 查询列表
List<Map<String, Object>> list = interfaceLogDao.queryList(params);
// 查询总数
int total = interfaceLogDao.queryTotal(params);
// 构造分页结果
PageUtils pageUtil = new PageUtils(list, total, limit, page);
return pageUtil;
}
@Override
public R getParams(String site, String buNo, String requestId, Integer requestGroupId) {
try {
// 查询主表数据
Map<String, Object> head = apiLogValuesHeadDao.queryHead(site, buNo, requestId, requestGroupId);
// 查询明细数据
List<Map<String, Object>> detailList = apiLogValuesDetailDao.queryDetailList(site, buNo, requestId, requestGroupId);
// 构造返回的JSON结构
Map<String, Object> result = new LinkedHashMap<>();
// 处理主表数据将orderref1-20映射为"接口参数1"-"接口参数20"
if (head != null) {
for (int i = 1; i <= 20; i++) {
String key = "orderref" + i;
Object value = head.get(key);
if (value != null && !value.toString().trim().isEmpty()) {
result.put("接口参数" + i, value);
}
}
}
// 处理明细数据
if (detailList != null && !detailList.isEmpty()) {
List<Map<String, Object>> detailResultList = new ArrayList<>();
for (Map<String, Object> detail : detailList) {
Map<String, Object> detailResult = new LinkedHashMap<>();
for (int i = 1; i <= 20; i++) {
String key = "orderref" + i;
Object value = detail.get(key);
if (value != null && !value.toString().trim().isEmpty()) {
detailResult.put("接口参数" + i, value);
}
}
if (!detailResult.isEmpty()) {
detailResultList.add(detailResult);
}
}
if (!detailResultList.isEmpty()) {
result.put("DetailList", detailResultList);
}
}
return R.ok().put("params", result);
} catch (Exception e) {
logger.error("查询接口参数失败", e);
return R.error("查询接口参数失败: " + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public R deleteBatch(Long[] ids) {
try {
if (ids == null || ids.length == 0) {
return R.error("请选择要删除的记录");
}
int count = interfaceLogDao.deleteBatch(ids);
return R.ok().put("count", count);
} catch (Exception e) {
logger.error("批量删除接口日志失败", e);
return R.error("批量删除失败: " + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public R retryBatch(Long[] ids) {
try {
if (ids == null || ids.length == 0) {
return R.error("请选择要重试的记录");
}
// TODO: 这里可以实现具体的重试逻辑
// 例如更新重试次数下次重试时间等
// 或者触发实际的接口调用
logger.info("批量重试接口,记录数: {}", ids.length);
return R.ok().put("message", "重试请求已提交");
} catch (Exception e) {
logger.error("批量重试接口失败", e);
return R.error("批量重试失败: " + e.getMessage());
}
}
}

45
src/main/resources/mapper/sys/ApiLogValuesDetailDao.xml

@ -0,0 +1,45 @@
<?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.gaotao.modules.sys.dao.ApiLogValuesDetailDao">
<!-- 查询接口参数明细列表 -->
<select id="queryDetailList" resultType="map">
SELECT
site,
bu_no AS buNo,
request_id AS requestId,
request_group_id AS requestGroupId,
orderref1,
orderref2,
orderref3,
orderref4,
orderref5,
orderref6,
orderref7,
orderref8,
orderref9,
orderref10,
orderref11,
orderref12,
orderref13,
orderref14,
orderref15,
orderref16,
orderref17,
orderref18,
orderref19,
orderref20,
group_id AS groupId
FROM api_log_values_detail
WHERE site = #{site}
AND bu_no = #{buNo}
AND request_id = #{requestId}
<if test="requestGroupId != null">
AND request_group_id = #{requestGroupId}
</if>
ORDER BY group_id
</select>
</mapper>

43
src/main/resources/mapper/sys/ApiLogValuesHeadDao.xml

@ -0,0 +1,43 @@
<?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.gaotao.modules.sys.dao.ApiLogValuesHeadDao">
<!-- 查询接口参数主表 -->
<select id="queryHead" resultType="map">
SELECT
site,
bu_no AS buNo,
request_id AS requestId,
request_group_id AS requestGroupId,
orderref1,
orderref2,
orderref3,
orderref4,
orderref5,
orderref6,
orderref7,
orderref8,
orderref9,
orderref10,
orderref11,
orderref12,
orderref13,
orderref14,
orderref15,
orderref16,
orderref17,
orderref18,
orderref19,
orderref20
FROM api_log_values_head
WHERE site = #{site}
AND bu_no = #{buNo}
AND request_id = #{requestId}
<if test="requestGroupId != null">
AND request_group_id = #{requestGroupId}
</if>
</select>
</mapper>

118
src/main/resources/mapper/sys/InterfaceLogDao.xml

@ -0,0 +1,118 @@
<?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.gaotao.modules.sys.dao.InterfaceLogDao">
<!-- 查询接口日志列表 -->
<select id="queryList" resultType="map">
SELECT
id,
site,
bu_no AS buNo,
request_id AS requestId,
interface_name AS interfaceName,
request_group_id AS requestGroupId,
re_document_no AS reDocumentNo,
re_document_type AS reDocumentType,
order_no AS orderNo,
seq_no AS seqNo,
status_code AS statusCode,
message,
source_system AS sourceSystem,
target_system AS targetSystem,
need_retry_flag AS needRetryFlag,
retry_count AS retryCount,
max_retry_count AS maxRetryCount,
retry_interval AS retryInterval,
next_retry_time AS nextRetryTime,
last_retry_time AS lastRetryTime,
created_by AS createdBy,
created_date AS createdDate
FROM api_log
<where>
<if test="interfaceName != null and interfaceName.trim() != ''">
AND interface_name LIKE '%' + #{interfaceName} + '%'
</if>
<if test="requestId != null and requestId.trim() != ''">
AND request_id = #{requestId}
</if>
<if test="reDocumentNo != null and reDocumentNo.trim() != ''">
AND re_document_no LIKE '%' + #{reDocumentNo} + '%'
</if>
<if test="reDocumentType != null and reDocumentType.trim() != ''">
AND re_document_type LIKE '%' + #{reDocumentType} + '%'
</if>
<if test="statusCode != null and statusCode.trim() != ''">
AND status_code = #{statusCode}
</if>
<if test="sourceSystem != null and sourceSystem.trim() != ''">
AND source_system = #{sourceSystem}
</if>
<if test="targetSystem != null and targetSystem.trim() != ''">
AND target_system = #{targetSystem}
</if>
<if test="needRetryFlag != null">
AND need_retry_flag = #{needRetryFlag}
</if>
<if test="startDate != null and startDate.trim() != ''">
AND CONVERT(varchar(10), created_date, 23) &gt;= #{startDate}
</if>
<if test="endDate != null and endDate.trim() != ''">
AND CONVERT(varchar(10), created_date, 23) &lt;= #{endDate}
</if>
</where>
ORDER BY created_date DESC
<if test="offset != null and limit != null">
OFFSET #{offset} ROWS
FETCH NEXT #{limit} ROWS ONLY
</if>
</select>
<!-- 查询接口日志总数 -->
<select id="queryTotal" resultType="int">
SELECT COUNT(*)
FROM api_log
<where>
<if test="interfaceName != null and interfaceName.trim() != ''">
AND interface_name LIKE '%' + #{interfaceName} + '%'
</if>
<if test="requestId != null and requestId.trim() != ''">
AND request_id = #{requestId}
</if>
<if test="reDocumentNo != null and reDocumentNo.trim() != ''">
AND re_document_no LIKE '%' + #{reDocumentNo} + '%'
</if>
<if test="reDocumentType != null and reDocumentType.trim() != ''">
AND re_document_type LIKE '%' + #{reDocumentType} + '%'
</if>
<if test="statusCode != null and statusCode.trim() != ''">
AND status_code = #{statusCode}
</if>
<if test="sourceSystem != null and sourceSystem.trim() != ''">
AND source_system = #{sourceSystem}
</if>
<if test="targetSystem != null and targetSystem.trim() != ''">
AND target_system = #{targetSystem}
</if>
<if test="needRetryFlag != null">
AND need_retry_flag = #{needRetryFlag}
</if>
<if test="startDate != null and startDate.trim() != ''">
AND CONVERT(varchar(10), created_date, 23) &gt;= #{startDate}
</if>
<if test="endDate != null and endDate.trim() != ''">
AND CONVERT(varchar(10), created_date, 23) &lt;= #{endDate}
</if>
</where>
</select>
<!-- 批量删除 -->
<delete id="deleteBatch">
DELETE FROM api_log WHERE id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save