From 5e3133a216bbf47db064f8d7c68cf18ac073bc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Mon, 9 Feb 2026 17:32:40 +0800 Subject: [PATCH] 1 --- .../gaotao/common/utils/ErrorLogUtils.java | 134 ++++++++++++++- .../utils/ImportantErrorConfigService.java | 33 ++++ .../SysImportantErrorConfigController.java | 77 +++++++++ .../dao/SysImportantErrorConfigMapper.java | 40 +++++ .../modules/api/entity/SysErrorLog.java | 27 ++++ .../api/entity/SysImportantErrorConfig.java | 134 +++++++++++++++ .../entity/SysImportantErrorConfigData.java | 76 +++++++++ .../SysImportantErrorConfigService.java | 47 ++++++ .../SysImportantErrorConfigServiceImpl.java | 153 ++++++++++++++++++ .../mapper/api/SysErrorLogMapper.xml | 4 + .../api/SysImportantErrorConfigMapper.xml | 61 +++++++ 11 files changed, 782 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/gaotao/common/utils/ImportantErrorConfigService.java create mode 100644 src/main/java/com/gaotao/modules/api/controller/SysImportantErrorConfigController.java create mode 100644 src/main/java/com/gaotao/modules/api/dao/SysImportantErrorConfigMapper.java create mode 100644 src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfig.java create mode 100644 src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfigData.java create mode 100644 src/main/java/com/gaotao/modules/api/service/SysImportantErrorConfigService.java create mode 100644 src/main/java/com/gaotao/modules/api/service/impl/SysImportantErrorConfigServiceImpl.java create mode 100644 src/main/resources/mapper/api/SysImportantErrorConfigMapper.xml diff --git a/src/main/java/com/gaotao/common/utils/ErrorLogUtils.java b/src/main/java/com/gaotao/common/utils/ErrorLogUtils.java index d9748877..c27c4fcd 100644 --- a/src/main/java/com/gaotao/common/utils/ErrorLogUtils.java +++ b/src/main/java/com/gaotao/common/utils/ErrorLogUtils.java @@ -1,6 +1,7 @@ package com.gaotao.common.utils; import com.gaotao.modules.api.entity.SysErrorLog; +import com.gaotao.modules.api.entity.SysImportantErrorConfig; import com.gaotao.modules.sys.entity.SysUserEntity; import jakarta.annotation.PostConstruct; import org.apache.shiro.SecurityUtils; @@ -11,13 +12,17 @@ import org.springframework.stereotype.Component; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.Date; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * 错误日志工具类 * 提供简单易用的静态方法记录错误日志 * - * 特点:使用独立事务保存日志,不会被外层事务回滚 + * 特点: + * 1. 使用独立事务保存日志,不会被外层事务回滚 + * 2. 自动判断是否重要错误(根据sys_important_error_config表配置) + * 3. 使用缓存机制提高性能(避免每次都查询配置表) * * 使用示例: * 1. 业务错误:ErrorLogUtils.log("55", "立库自动化", "直接组盘", "W00250", "栈板不存在"); @@ -35,13 +40,128 @@ public class ErrorLogUtils { private static final Logger logger = LoggerFactory.getLogger(ErrorLogUtils.class); private static ErrorLogService errorLogService; + private static ImportantErrorConfigService configService; @Autowired private ErrorLogService service; + @Autowired + private ImportantErrorConfigService importantErrorConfigService; + @PostConstruct public void init() { ErrorLogUtils.errorLogService = this.service; + ErrorLogUtils.configService = this.importantErrorConfigService; + } + + // ==================== 缓存管理 ==================== + + /** + * 配置缓存 - 站点 -> 配置列表 + * 使用ConcurrentHashMap保证线程安全 - rqrq + */ + private static final Map> configCache = new ConcurrentHashMap<>(); + + /** + * 缓存更新时间 - 站点 -> 更新时间戳 + */ + private static final Map cacheUpdateTime = new ConcurrentHashMap<>(); + + /** + * 缓存有效期(毫秒)- 5分钟 - rqrq + */ + private static final long CACHE_EXPIRE_TIME = 5 * 60 * 1000; + + /** + * 获取重要错误配置(带缓存)- rqrq + * @param site 工厂编码 + * @return 配置列表 + */ + private static List getImportantErrorConfigs(String site) { + if (site == null || site.isEmpty()) { + return new ArrayList<>(); + } + + try { + Long lastUpdateTime = cacheUpdateTime.get(site); + long currentTime = System.currentTimeMillis(); + + // 缓存不存在或已过期,重新加载 - rqrq + if (lastUpdateTime == null || (currentTime - lastUpdateTime) > CACHE_EXPIRE_TIME) { + if (configService != null) { + List configs = configService.getActiveConfigsBySite(site); + configCache.put(site, configs); + cacheUpdateTime.put(site, currentTime); + logger.debug("重要错误配置缓存已更新 - rqrq,site={}, 配置数量={}", site, configs.size()); + return configs; + } + } + + // 返回缓存数据 - rqrq + List cachedConfigs = configCache.get(site); + return cachedConfigs != null ? cachedConfigs : new ArrayList<>(); + } catch (Exception e) { + logger.warn("获取重要错误配置失败 - rqrq,site={}, error={}", site, e.getMessage()); + return new ArrayList<>(); + } + } + + /** + * 清空指定站点的缓存 - rqrq + * @param site 工厂编码 + */ + public static void clearCache(String site) { + configCache.remove(site); + cacheUpdateTime.remove(site); + logger.info("已清空重要错误配置缓存 - rqrq,site={}", site); + } + + /** + * 清空所有缓存 - rqrq + */ + public static void clearAllCache() { + configCache.clear(); + cacheUpdateTime.clear(); + logger.info("已清空所有重要错误配置缓存 - rqrq"); + } + + /** + * 判断是否为重要错误 - rqrq + * @param site 工厂编码 + * @param errorMessage 错误信息 + * @return Y-重要错误 N-普通错误 + */ + private static String checkIsImportantError(String site, String errorMessage) { + // 错误信息为空,默认为普通错误 - rqrq + if (errorMessage == null || errorMessage.isEmpty()) { + return SysErrorLog.IMPORTANT_NO; + } + + try { + // 获取配置列表(带缓存)- rqrq + List configs = getImportantErrorConfigs(site); + + // 没有配置,默认为普通错误 - rqrq + if (configs == null || configs.isEmpty()) { + return SysErrorLog.IMPORTANT_NO; + } + + // 遍历配置,判断错误信息是否包含任一配置的error_desc - rqrq + for (SysImportantErrorConfig config : configs) { + if (config.getErrorDesc() != null && !config.getErrorDesc().isEmpty()) { + if (errorMessage.contains(config.getErrorDesc())) { + logger.debug("匹配到重要错误配置 - rqrq,site={}, errorDesc={}", site, config.getErrorDesc()); + return SysErrorLog.IMPORTANT_YES; + } + } + } + + // 未匹配到任何配置,为普通错误 - rqrq + return SysErrorLog.IMPORTANT_NO; + } catch (Exception e) { + logger.warn("判断重要错误失败 - rqrq,默认为普通错误,error={}", e.getMessage()); + return SysErrorLog.IMPORTANT_NO; + } } // ==================== 业务错误记录 ==================== @@ -166,9 +286,11 @@ public class ErrorLogUtils { return; } - SysErrorLog log = new SysErrorLog(); // site为null时自动获取 - rqrq - log.setSite(site != null ? site : getSite()); + String finalSite = site != null ? site : getSite(); + + SysErrorLog log = new SysErrorLog(); + log.setSite(finalSite); log.setModuleName(moduleName); log.setFunctionName(functionName); log.setBusinessKey(businessKey); @@ -182,6 +304,10 @@ public class ErrorLogUtils { log.setUsername(getUsername()); log.setCreatedTime(new Date()); + // 判断是否为重要错误 - rqrq + String isImportantError = checkIsImportantError(finalSite, errorMessage); + log.setIsImportantError(isImportantError); + // 使用独立事务保存,避免被外层事务回滚 - rqrq errorLogService.saveInNewTransaction(log); } catch (Exception ex) { diff --git a/src/main/java/com/gaotao/common/utils/ImportantErrorConfigService.java b/src/main/java/com/gaotao/common/utils/ImportantErrorConfigService.java new file mode 100644 index 00000000..73dbe000 --- /dev/null +++ b/src/main/java/com/gaotao/common/utils/ImportantErrorConfigService.java @@ -0,0 +1,33 @@ +package com.gaotao.common.utils; + +import com.gaotao.modules.api.dao.SysImportantErrorConfigMapper; +import com.gaotao.modules.api.entity.SysImportantErrorConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 重要错误配置查询组件 - rqrq + * 用于ErrorLogUtils查询配置,独立于业务Service + * + * @author rqrq + * @date 2026/02/09 + */ +@Component +public class ImportantErrorConfigService { + + @Autowired + private SysImportantErrorConfigMapper configMapper; + + /** + * @Description 查询指定站点的启用配置 - rqrq + * @param site 工厂编码 + * @return List 启用的配置列表 + * @author rqrq + * @date 2026/02/09 + */ + public List getActiveConfigsBySite(String site) { + return configMapper.getActiveConfigsBySite(site); + } +} diff --git a/src/main/java/com/gaotao/modules/api/controller/SysImportantErrorConfigController.java b/src/main/java/com/gaotao/modules/api/controller/SysImportantErrorConfigController.java new file mode 100644 index 00000000..03255f40 --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/controller/SysImportantErrorConfigController.java @@ -0,0 +1,77 @@ +package com.gaotao.modules.api.controller; + +import com.gaotao.common.utils.PageUtils; +import com.gaotao.common.utils.R; +import com.gaotao.modules.api.entity.SysImportantErrorConfigData; +import com.gaotao.modules.api.service.SysImportantErrorConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @Description 重要错误配置管理Controller - rqrq + * @Author rqrq + * @Date 2026/02/09 + */ +@RestController +@RequestMapping("/api/importantErrorConfig") +public class SysImportantErrorConfigController { + + @Autowired + private SysImportantErrorConfigService configService; + + /** + * @Description 查询重要错误配置列表 - rqrq + * @param data 查询条件 + * @return R + * @author rqrq + * @date 2026/02/09 + */ + @PostMapping(value="/list") + @ResponseBody + public R list(@RequestBody SysImportantErrorConfigData data) throws Exception { + PageUtils page = configService.queryPage(data); + return R.ok().put("page", page); + } + + /** + * @Description 新增重要错误配置 - rqrq + * @param data 配置信息 + * @return R + * @author rqrq + * @date 2026/02/09 + */ + @PostMapping(value="/add") + @ResponseBody + public R add(@RequestBody SysImportantErrorConfigData data) throws Exception { + configService.addConfig(data); + return R.ok(); + } + + /** + * @Description 修改重要错误配置 - rqrq + * @param data 配置信息 + * @return R + * @author rqrq + * @date 2026/02/09 + */ + @PostMapping(value="/update") + @ResponseBody + public R update(@RequestBody SysImportantErrorConfigData data) throws Exception { + configService.updateConfig(data); + return R.ok(); + } + + /** + * @Description 删除重要错误配置 - rqrq + * @param data 配置信息(包含id) + * @return R + * @author rqrq + * @date 2026/02/09 + */ + @PostMapping(value="/delete") + @ResponseBody + public R delete(@RequestBody SysImportantErrorConfigData data) throws Exception { + configService.deleteConfig(data.getId()); + return R.ok(); + } +} diff --git a/src/main/java/com/gaotao/modules/api/dao/SysImportantErrorConfigMapper.java b/src/main/java/com/gaotao/modules/api/dao/SysImportantErrorConfigMapper.java new file mode 100644 index 00000000..773acfa5 --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/dao/SysImportantErrorConfigMapper.java @@ -0,0 +1,40 @@ +package com.gaotao.modules.api.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.gaotao.modules.api.entity.SysImportantErrorConfig; +import com.gaotao.modules.api.entity.SysImportantErrorConfigData; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Description 重要错误配置Mapper - rqrq + * @Author rqrq + * @Date 2026/02/09 + */ +@Mapper +public interface SysImportantErrorConfigMapper extends BaseMapper { + + /** + * @Description 查询指定站点的启用配置 - rqrq + *

查询条件:site = #{site} AND active = 'Y'

+ * @param site 工厂编码 + * @return List 启用的配置列表 + * @author rqrq + * @date 2026/02/09 + */ + List getActiveConfigsBySite(@Param("site") String site); + + /** + * @Description 分页查询重要错误配置列表 - rqrq + * @param page 分页对象 + * @param data 查询条件 + * @return IPage + * @author rqrq + * @date 2026/02/09 + */ + IPage queryConfigPage(Page page, @Param("query") SysImportantErrorConfigData data); +} diff --git a/src/main/java/com/gaotao/modules/api/entity/SysErrorLog.java b/src/main/java/com/gaotao/modules/api/entity/SysErrorLog.java index 974b931a..73ab0206 100644 --- a/src/main/java/com/gaotao/modules/api/entity/SysErrorLog.java +++ b/src/main/java/com/gaotao/modules/api/entity/SysErrorLog.java @@ -121,6 +121,23 @@ public class SysErrorLog implements Serializable { @TableField("error_detail") private String errorDetail; + /** + * 是否重要错误 - rqrq + *

枚举值说明:

+ *
    + *
  • Y = 重要错误(error_message包含sys_important_error_config表中的error_desc)
  • + *
  • N = 普通错误
  • + *
+ *

判断逻辑:

+ *
+     * 1. 根据site查询sys_important_error_config表中active='Y'的配置
+     * 2. 遍历配置,判断error_message是否包含任一error_desc
+     * 3. 如果包含,则标记为重要错误(Y),否则标记为普通错误(N)
+     * 
+ */ + @TableField("is_important_error") + private String isImportantError; + // ========== 其他信息 ========== /** @@ -134,4 +151,14 @@ public class SysErrorLog implements Serializable { */ @TableField(value = "created_time", fill = FieldFill.INSERT) private Date createdTime; + + /** + * 重要错误常量 - 是 + */ + public static final String IMPORTANT_YES = "Y"; + + /** + * 重要错误常量 - 否 + */ + public static final String IMPORTANT_NO = "N"; } diff --git a/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfig.java b/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfig.java new file mode 100644 index 00000000..93ddaaeb --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfig.java @@ -0,0 +1,134 @@ +package com.gaotao.modules.api.entity; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.ibatis.type.Alias; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +/** + * 重要错误配置实体类 - rqrq + * + *

数据库表名:sys_important_error_config

+ * + *

表索引:

+ *
    + *
  • PRIMARY KEY: id (自增主键)
  • + *
  • INDEX: idx_important_error_site (site, active) - 常用于按站点查询启用的配置
  • + *
+ * + *

核心字段说明:

+ *
    + *
  • site:工厂编码,用于区分不同站点的重要错误配置
  • + *
  • error_desc:错误描述关键词,用于匹配error_message判断是否为重要错误
  • + *
  • active:是否启用,Y-启用 N-禁用
  • + *
+ * + *

业务用途:

+ *
+ * // 判断错误是否为重要错误
+ * List<SysImportantErrorConfig> configs = mapper.getActiveConfigs(site);
+ * for (SysImportantErrorConfig config : configs) {
+ *     if (errorMessage.contains(config.getErrorDesc())) {
+ *         // 是重要错误
+ *         isImportant = "Y";
+ *         break;
+ *     }
+ * }
+ * 
+ * + * @author rqrq + * @date 2026/02/09 + */ +@Data +@TableName("sys_important_error_config") +@Alias("SysImportantErrorConfig") +public class SysImportantErrorConfig implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + @TableId(type = IdType.AUTO) + @TableField("id") + private Long id; + + /** + * 工厂编码 + *

如:55

+ */ + @TableField("site") + private String site; + + /** + * 错误描述关键词 + *

用于匹配error_message判断是否为重要错误

+ *

示例:

+ *
    + *
  • 栈板不存在
  • + *
  • WCS返回失败
  • + *
  • 库存不足
  • + *
  • 数据库连接失败
  • + *
+ */ + @TableField("error_desc") + private String errorDesc; + + /** + * 是否启用 + *

枚举值说明:

+ *
    + *
  • Y = 启用(会参与重要错误判断)
  • + *
  • N = 禁用(不参与重要错误判断)
  • + *
+ */ + @TableField("active") + private String active; + + /** + * 备注说明 + */ + @TableField("remark") + private String remark; + + /** + * 创建人 + */ + @TableField("created_by") + private String createdBy; + + /** + * 创建时间(自动填充) + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(value = "created_time", fill = FieldFill.INSERT) + private Date createdTime; + + /** + * 修改人 + */ + @TableField("updated_by") + private String updatedBy; + + /** + * 修改时间(自动填充) + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE) + private Date updatedTime; + + /** + * 状态常量 - 启用 + */ + public static final String ACTIVE_YES = "Y"; + + /** + * 状态常量 - 禁用 + */ + public static final String ACTIVE_NO = "N"; +} diff --git a/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfigData.java b/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfigData.java new file mode 100644 index 00000000..c836fb42 --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/entity/SysImportantErrorConfigData.java @@ -0,0 +1,76 @@ +package com.gaotao.modules.api.entity; + +import lombok.Data; +import org.apache.ibatis.type.Alias; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + +/** + * @Description 重要错误配置业务实体类 - 用于业务查询和操作 - rqrq + * + *

继承关系:继承 SysImportantErrorConfig 基础实体类

+ * + *

用途:

+ *
    + *
  • 用于分页查询接口的参数和返回值
  • + *
  • 包含额外的查询条件字段
  • + *
  • 包含分页参数
  • + *
+ * + *

常用查询逻辑:

+ *
+ * // 示例1:按站点查询
+ * WHERE site = #{query.site}
+ * 
+ * // 示例2:按错误描述模糊查询
+ * WHERE error_desc LIKE '%' + #{query.searchErrorDesc} + '%'
+ * 
+ * // 示例3:按启用状态过滤
+ * WHERE active = #{query.active}
+ * 
+ * // 示例4:日期范围查询
+ * WHERE created_time BETWEEN #{query.startDate} AND #{query.endDate}
+ * 
+ * + * @author rqrq + * @date 2026/02/09 + */ +@Data +@Alias("SysImportantErrorConfigData") +public class SysImportantErrorConfigData extends SysImportantErrorConfig { + + // ==================== 分页参数(必需)==================== + + /** + * 分页参数 - 当前页码 + */ + private Integer page; + + /** + * 分页参数 - 每页数量 + */ + private Integer limit; + + // ==================== 查询条件字段 ==================== + + /** + * 查询条件 - 错误描述(模糊查询) + *

SQL示例:WHERE error_desc LIKE '%' + #{query.searchErrorDesc} + '%'

+ */ + private String searchErrorDesc; + + /** + * 查询条件 - 查询开始日期 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startDate; + + /** + * 查询条件 - 查询结束日期 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endDate; +} diff --git a/src/main/java/com/gaotao/modules/api/service/SysImportantErrorConfigService.java b/src/main/java/com/gaotao/modules/api/service/SysImportantErrorConfigService.java new file mode 100644 index 00000000..68af6835 --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/service/SysImportantErrorConfigService.java @@ -0,0 +1,47 @@ +package com.gaotao.modules.api.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gaotao.common.utils.PageUtils; +import com.gaotao.modules.api.entity.SysImportantErrorConfig; +import com.gaotao.modules.api.entity.SysImportantErrorConfigData; + +/** + * @Description 重要错误配置服务接口 - rqrq + * @Author rqrq + * @Date 2026/02/09 + */ +public interface SysImportantErrorConfigService extends IService { + + /** + * @Description 分页查询重要错误配置列表 - rqrq + * @param data 查询条件 + * @return PageUtils + * @author rqrq + * @date 2026/02/09 + */ + PageUtils queryPage(SysImportantErrorConfigData data) throws Exception; + + /** + * @Description 新增重要错误配置 - rqrq + * @param data 配置信息 + * @author rqrq + * @date 2026/02/09 + */ + void addConfig(SysImportantErrorConfigData data) throws Exception; + + /** + * @Description 修改重要错误配置 - rqrq + * @param data 配置信息 + * @author rqrq + * @date 2026/02/09 + */ + void updateConfig(SysImportantErrorConfigData data) throws Exception; + + /** + * @Description 删除重要错误配置 - rqrq + * @param id 配置ID + * @author rqrq + * @date 2026/02/09 + */ + void deleteConfig(Long id) throws Exception; +} diff --git a/src/main/java/com/gaotao/modules/api/service/impl/SysImportantErrorConfigServiceImpl.java b/src/main/java/com/gaotao/modules/api/service/impl/SysImportantErrorConfigServiceImpl.java new file mode 100644 index 00000000..f742c4e8 --- /dev/null +++ b/src/main/java/com/gaotao/modules/api/service/impl/SysImportantErrorConfigServiceImpl.java @@ -0,0 +1,153 @@ +package com.gaotao.modules.api.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gaotao.common.utils.ErrorLogUtils; +import com.gaotao.common.utils.PageUtils; +import com.gaotao.modules.api.dao.SysImportantErrorConfigMapper; +import com.gaotao.modules.api.entity.SysImportantErrorConfig; +import com.gaotao.modules.api.entity.SysImportantErrorConfigData; +import com.gaotao.modules.api.service.SysImportantErrorConfigService; +import com.gaotao.modules.sys.entity.SysUserEntity; +import org.apache.shiro.SecurityUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.Date; + +/** + * @Description 重要错误配置服务实现类 - rqrq + * @Author rqrq + * @Date 2026/02/09 + */ +@Service +public class SysImportantErrorConfigServiceImpl extends ServiceImpl + implements SysImportantErrorConfigService { + + /** + * @Description 分页查询重要错误配置列表 - rqrq + * @param data 查询条件 + * @return PageUtils + * @author rqrq + * @date 2026/02/09 + */ + @Override + public PageUtils queryPage(SysImportantErrorConfigData data) throws Exception { + System.out.println("开始查询重要错误配置列表 - rqrq"); + + // 使用MyBatis-Plus分页方式 - rqrq + int page = data.getPage() != null ? data.getPage() : 1; + int limit = data.getLimit() != null ? data.getLimit() : 20; + + IPage pageResult = this.baseMapper.queryConfigPage( + new Page<>(page, limit), + data + ); + + System.out.println("查询重要错误配置列表完成 - rqrq,共" + pageResult.getTotal() + "条记录"); + + return new PageUtils(pageResult); + } + + /** + * @Description 新增重要错误配置 - rqrq + * @param data 配置信息 + * @author rqrq + * @date 2026/02/09 + */ + @Override + public void addConfig(SysImportantErrorConfigData data) throws Exception { + System.out.println("开始新增重要错误配置 - rqrq,site=" + data.getSite() + ", errorDesc=" + data.getErrorDesc()); + + // 校验必填参数 - rqrq + if (!StringUtils.hasText(data.getSite())) { + throw new RuntimeException("工厂编码不能为空"); + } + if (!StringUtils.hasText(data.getErrorDesc())) { + throw new RuntimeException("错误描述不能为空"); + } + + // 设置默认值 - rqrq + if (!StringUtils.hasText(data.getActive())) { + data.setActive(SysImportantErrorConfig.ACTIVE_YES); + } + String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); + + data.setCreatedTime(new Date()); + data.setCreatedBy( username); + // 保存到数据库 - rqrq + this.save(data); + + // 清空该站点的缓存 - rqrq + ErrorLogUtils.clearCache(data.getSite()); + + System.out.println("新增重要错误配置完成 - rqrq"); + } + + /** + * @Description 修改重要错误配置 - rqrq + * @param data 配置信息 + * @author rqrq + * @date 2026/02/09 + */ + @Override + public void updateConfig(SysImportantErrorConfigData data) throws Exception { + System.out.println("开始修改重要错误配置 - rqrq,id=" + data.getId()); + + // 校验ID - rqrq + if (data.getId() == null) { + throw new RuntimeException("配置ID不能为空"); + } + + // 查询原配置 - rqrq + SysImportantErrorConfig oldConfig = this.getById(data.getId()); + if (oldConfig == null) { + throw new RuntimeException("配置不存在,ID:" + data.getId()); + } + String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); + data.setUpdatedTime(new Date()); + data.setUpdatedBy( username); + // 更新到数据库 - rqrq + this.updateById(data); + + // 清空该站点的缓存 - rqrq + ErrorLogUtils.clearCache(oldConfig.getSite()); + // 如果站点改变了,也要清空新站点的缓存 - rqrq + if (data.getSite() != null && !data.getSite().equals(oldConfig.getSite())) { + ErrorLogUtils.clearCache(data.getSite()); + } + + System.out.println("修改重要错误配置完成 - rqrq"); + } + + /** + * @Description 删除重要错误配置 - rqrq + * @param id 配置ID + * @author rqrq + * @date 2026/02/09 + */ + @Override + public void deleteConfig(Long id) throws Exception { + System.out.println("开始删除重要错误配置 - rqrq,id=" + id); + + // 校验ID - rqrq + if (id == null) { + throw new RuntimeException("配置ID不能为空"); + } + + // 查询配置 - rqrq + SysImportantErrorConfig config = this.getById(id); + if (config == null) { + throw new RuntimeException("配置不存在,ID:" + id); + } + + // 删除配置 - rqrq + this.removeById(id); + + // 清空该站点的缓存 - rqrq + ErrorLogUtils.clearCache(config.getSite()); + + System.out.println("删除重要错误配置完成 - rqrq"); + } +} diff --git a/src/main/resources/mapper/api/SysErrorLogMapper.xml b/src/main/resources/mapper/api/SysErrorLogMapper.xml index e444fbbb..cf3f7b95 100644 --- a/src/main/resources/mapper/api/SysErrorLogMapper.xml +++ b/src/main/resources/mapper/api/SysErrorLogMapper.xml @@ -19,6 +19,7 @@ method_name AS methodName, error_message AS errorMessage, error_detail AS errorDetail, + is_important_error AS isImportantError, username, created_time AS createdTime FROM sys_error_log WITH (NOLOCK) @@ -41,6 +42,9 @@ AND interface_type = #{params.interfaceType} + + AND is_important_error = #{params.isImportantError} + AND interface_name LIKE '%' + #{params.interfaceName} + '%' diff --git a/src/main/resources/mapper/api/SysImportantErrorConfigMapper.xml b/src/main/resources/mapper/api/SysImportantErrorConfigMapper.xml new file mode 100644 index 00000000..1b38a2c0 --- /dev/null +++ b/src/main/resources/mapper/api/SysImportantErrorConfigMapper.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + +