Ver código fonte

Merge remote-tracking branch 'origin/master'

2507040827 3 semanas atrás
pai
commit
b763498b14

+ 14 - 19
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/aop/ApiLogAspect.java

@@ -3,6 +3,7 @@ package cn.com.yusys.yusp.aop;
 import cn.com.yusys.yusp.annotation.ApiOperationType;
 import cn.com.yusys.yusp.annotation.ApiOperationType;
 import cn.com.yusys.yusp.domain.entity.AitagApiLog;
 import cn.com.yusys.yusp.domain.entity.AitagApiLog;
 import cn.com.yusys.yusp.service.AitagApiLogService;
 import cn.com.yusys.yusp.service.AitagApiLogService;
+import cn.com.yusys.yusp.util.SessionCommonUtil;
 import cn.com.yusys.yusp.util.AuthContextUtil;
 import cn.com.yusys.yusp.util.AuthContextUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
@@ -24,9 +25,6 @@ public class ApiLogAspect {
     @Autowired
     @Autowired
     private AitagApiLogService apiLogService;
     private AitagApiLogService apiLogService;
 
 
-    @Value("${auth.enabled:false}")
-    private boolean authEnabled;
-
     @Around("@annotation(cn.com.yusys.yusp.annotation.ApiOperationType)")
     @Around("@annotation(cn.com.yusys.yusp.annotation.ApiOperationType)")
     public Object logApiCall(ProceedingJoinPoint joinPoint) throws Throwable {
     public Object logApiCall(ProceedingJoinPoint joinPoint) throws Throwable {
         long startTime = System.currentTimeMillis();
         long startTime = System.currentTimeMillis();
@@ -35,7 +33,7 @@ public class ApiLogAspect {
         apiLog.setId(apiLogService.generateLogId());
         apiLog.setId(apiLogService.generateLogId());
         apiLog.setCreateDate(new Date());
         apiLog.setCreateDate(new Date());
 
 
-        // 设置用户信息 - 根据认证状态决定
+        // 设置用户信息 - 通过 SessionCommonUtil 获取
         setUserInfo(apiLog);
         setUserInfo(apiLog);
 
 
         // 获取操作类型
         // 获取操作类型
@@ -110,30 +108,27 @@ public class ApiLogAspect {
 
 
     /**
     /**
      * 设置用户信息
      * 设置用户信息
-     * @param apiLog API日志对象
+     * @param apiLog API 日志对象
      */
      */
     private void setUserInfo(AitagApiLog apiLog) {
     private void setUserInfo(AitagApiLog apiLog) {
-        if (authEnabled) {
-            // 认证启用时,使用当前登录用户信息
-            String currentUserId = AuthContextUtil.getCurrentUser();
-            String currentUserName = AuthContextUtil.getCurrentUserName();
-
-            if (currentUserId != null) {
-                apiLog.setUserId(currentUserId);
-                // 如果有用户名就用用户名,否则用用户ID
-                apiLog.setUserName(currentUserName != null ? currentUserName : currentUserId);
+        try {
+            String userId = SessionCommonUtil.getUserId();
+            String userName = SessionCommonUtil.getUserInfo();
+
+            if (userId != null && !userId.isEmpty()) {
+                apiLog.setUserId(userId);
+                apiLog.setUserName(userName != null ? userName : userId);
             } else {
             } else {
-                // fallback到默认值
                 apiLog.setUserId("unknown");
                 apiLog.setUserId("unknown");
                 apiLog.setUserName("unknown");
                 apiLog.setUserName("unknown");
             }
             }
-        } else {
-            // 认证关闭时,使用固定测试值
-            apiLog.setUserId("testID");
-            apiLog.setUserName("testName");
+        } catch (Exception e) {
+            apiLog.setUserId("unknown");
+            apiLog.setUserName("unknown");
         }
         }
     }
     }
 
 
+
     /**
     /**
      * 隐藏敏感数据
      * 隐藏敏感数据
      * @param jsonStr 原始JSON字符串
      * @param jsonStr 原始JSON字符串

+ 13 - 0
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/domain/entity/AitagTagCategory.java

@@ -5,6 +5,7 @@ import javax.validation.constraints.Size;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.NotNull;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
+import java.util.Date;
 
 
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Data;
@@ -64,4 +65,16 @@ public class AitagTagCategory implements Serializable {
     @ApiModelProperty("0未删除;1删除")
     @ApiModelProperty("0未删除;1删除")
     private Integer isDelete;
     private Integer isDelete;
 
 
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    @ApiModelProperty("更新时间")
+    private Date updateTime;
+
 }
 }

+ 10 - 0
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/domain/vo/AitagTagCategoryVo.java

@@ -4,6 +4,9 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Data;
 
 
+import java.time.LocalDateTime;
+import java.util.Date;
+
 @Data
 @Data
 @ApiModel("标签体系视图对象")
 @ApiModel("标签体系视图对象")
 public class AitagTagCategoryVo {
 public class AitagTagCategoryVo {
@@ -30,4 +33,11 @@ public class AitagTagCategoryVo {
 
 
     @ApiModelProperty("标签数量(临时字段)")
     @ApiModelProperty("标签数量(临时字段)")
     private Integer tagNum;
     private Integer tagNum;
+
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+
+    @ApiModelProperty("更新时间")
+    private Date updateTime;
+
 }
 }

+ 0 - 6
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/mapper/AitagTagCategoryMapper.java

@@ -9,9 +9,6 @@ import java.util.List;
 @Mapper
 @Mapper
 public interface AitagTagCategoryMapper {
 public interface AitagTagCategoryMapper {
 
 
-    // 分页查询(偏移量 + 限制)
-    List<AitagTagCategory> selectPageCategories(@Param("offset") int offset, @Param("limit") int limit);
-
     // 带模糊筛选的分页查询
     // 带模糊筛选的分页查询
     List<AitagTagCategory> selectPageCategoriesWithFilter(
     List<AitagTagCategory> selectPageCategoriesWithFilter(
             @Param("categoryNm") String categoryNm,
             @Param("categoryNm") String categoryNm,
@@ -21,9 +18,6 @@ public interface AitagTagCategoryMapper {
     // 带模糊筛选的总数
     // 带模糊筛选的总数
     long selectCountWithFilter(@Param("categoryNm") String categoryNm);
     long selectCountWithFilter(@Param("categoryNm") String categoryNm);
 
 
-    // 模糊查询(按名称)
-    List<AitagTagCategory> selectByCategoryNmLike(@Param("categoryNm") String categoryNm);
-
     // 按名称查重(未删除)
     // 按名称查重(未删除)
     int selectCountByNameAndNotDeleted(@Param("categoryNm") String categoryNm);
     int selectCountByNameAndNotDeleted(@Param("categoryNm") String categoryNm);
 
 

+ 2 - 3
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/service/impl/AitagApiLogServiceImpl.java

@@ -44,10 +44,9 @@ public class AitagApiLogServiceImpl implements AitagApiLogService {
     public void recordApiLog(AitagApiLog apiLog) {
     public void recordApiLog(AitagApiLog apiLog) {
         try {
         try {
             apiLogMapper.insertApiLog(apiLog);
             apiLogMapper.insertApiLog(apiLog);
-            logger.info("API调用日志记录成功: {} - {}", apiLog.getId(), apiLog.getOperationType());
+            logger.info("API 调用日志记录成功:{} - {}", apiLog.getId(), apiLog.getOperationType());
         } catch (Exception e) {
         } catch (Exception e) {
-            logger.error("记录API调用日志失败: {}", e.getMessage(), e);
-            // 不抛出异常,避免影响主业务流程
+            logger.error("记录 API 调用日志失败:{}", e.getMessage(), e);
         }
         }
     }
     }
 
 

+ 12 - 1
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/service/impl/AitagTagCategoryServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.util.Date;
 import java.util.List;
 import java.util.List;
 import java.util.UUID;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -36,6 +37,8 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
             vo.setVisibilityLevel(category.getVisibilityLevel());
             vo.setVisibilityLevel(category.getVisibilityLevel());
             vo.setState(category.getState());
             vo.setState(category.getState());
             vo.setIsDelete(category.getIsDelete());
             vo.setIsDelete(category.getIsDelete());
+            vo.setCreateTime(category.getCreateTime());
+            vo.setUpdateTime(category.getUpdateTime());
 
 
             // 动态计算 tagNum
             // 动态计算 tagNum
             int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
             int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
@@ -63,6 +66,9 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
         category.setCategoryDesc(dto.getCategoryDesc());
         category.setCategoryDesc(dto.getCategoryDesc());
         category.setState(1); // 默认停用
         category.setState(1); // 默认停用
         category.setIsDelete(0); // 未删除
         category.setIsDelete(0); // 未删除
+        Date now = new Date();
+        category.setCreateTime(now);
+        category.setUpdateTime(now);
 
 
         aiTagCategoryMapper.insertCategory(category);
         aiTagCategoryMapper.insertCategory(category);
         return category;
         return category;
@@ -84,6 +90,7 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
 
 
         existing.setCategoryNm(dto.getCategoryNm());
         existing.setCategoryNm(dto.getCategoryNm());
         existing.setCategoryDesc(dto.getCategoryDesc());
         existing.setCategoryDesc(dto.getCategoryDesc());
+        existing.setUpdateTime(new Date());
 
 
         aiTagCategoryMapper.updateCategory(existing);
         aiTagCategoryMapper.updateCategory(existing);
         return existing;
         return existing;
@@ -134,7 +141,7 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
             throw new RuntimeException("标签体系不存在");
             throw new RuntimeException("标签体系不存在");
         }
         }
 
 
-        // 判断标签数量是否为0
+        // 判断标签数量是否为 0
         int tagCount = aiTagCategoryMapper.countTagsByCategoryId(id);
         int tagCount = aiTagCategoryMapper.countTagsByCategoryId(id);
         if (tagCount > 0) {
         if (tagCount > 0) {
             throw new RuntimeException("该标签体系下仍有标签,无法删除");
             throw new RuntimeException("该标签体系下仍有标签,无法删除");
@@ -159,6 +166,8 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
             vo.setVisibilityLevel(category.getVisibilityLevel());
             vo.setVisibilityLevel(category.getVisibilityLevel());
             vo.setState(category.getState());
             vo.setState(category.getState());
             vo.setIsDelete(category.getIsDelete());
             vo.setIsDelete(category.getIsDelete());
+            vo.setCreateTime(category.getCreateTime());
+            vo.setUpdateTime(category.getUpdateTime());
 
 
             // 动态计算 tagNum
             // 动态计算 tagNum
             int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
             int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
@@ -187,6 +196,8 @@ public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
         vo.setVisibilityLevel(category.getVisibilityLevel());
         vo.setVisibilityLevel(category.getVisibilityLevel());
         vo.setState(category.getState());
         vo.setState(category.getState());
         vo.setIsDelete(category.getIsDelete());
         vo.setIsDelete(category.getIsDelete());
+        vo.setCreateTime(category.getCreateTime());
+        vo.setUpdateTime(category.getUpdateTime());
 
 
         // 计算标签数量
         // 计算标签数量
         int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
         int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());

+ 5 - 17
server/yusp-tagging-core/src/main/resources/mapper/AitagTagCategoryMapper.xml

@@ -2,13 +2,6 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.yusys.yusp.mapper.AitagTagCategoryMapper">
 <mapper namespace="cn.com.yusys.yusp.mapper.AitagTagCategoryMapper">
 
 
-    <!-- 分页查询 -->
-    <select id="selectPageCategories" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
-        SELECT * FROM aitag_tag_category
-        WHERE is_delete = 0
-            LIMIT #{offset}, #{limit}
-    </select>
-
     <!-- 带模糊筛选的分页查询 -->
     <!-- 带模糊筛选的分页查询 -->
     <select id="selectPageCategoriesWithFilter" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
     <select id="selectPageCategoriesWithFilter" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
         SELECT * FROM aitag_tag_category
         SELECT * FROM aitag_tag_category
@@ -16,6 +9,7 @@
         <if test="categoryNm != null and categoryNm != ''">
         <if test="categoryNm != null and categoryNm != ''">
             AND category_nm LIKE CONCAT('%', #{categoryNm}, '%')
             AND category_nm LIKE CONCAT('%', #{categoryNm}, '%')
         </if>
         </if>
+        ORDER BY state ASC, update_time DESC
         LIMIT #{offset}, #{limit}
         LIMIT #{offset}, #{limit}
     </select>
     </select>
 
 
@@ -28,13 +22,6 @@
         </if>
         </if>
     </select>
     </select>
 
 
-    <!-- 模糊查询 -->
-    <select id="selectByCategoryNmLike" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
-        SELECT * FROM aitag_tag_category
-        WHERE is_delete = 0 AND category_nm LIKE CONCAT('%', #{categoryNm}, '%')
-            LIMIT 5
-    </select>
-
     <!-- 按名称查重(未删除) -->
     <!-- 按名称查重(未删除) -->
     <select id="selectCountByNameAndNotDeleted" resultType="int">
     <select id="selectCountByNameAndNotDeleted" resultType="int">
         SELECT COUNT(*) FROM aitag_tag_category
         SELECT COUNT(*) FROM aitag_tag_category
@@ -43,8 +30,8 @@
 
 
     <!-- 新增 -->
     <!-- 新增 -->
     <insert id="insertCategory">
     <insert id="insertCategory">
-        INSERT INTO aitag_tag_category (id, category_nm, category_desc, state, is_delete)
-        VALUES (#{id}, #{categoryNm}, #{categoryDesc}, 1, 0)
+        INSERT INTO aitag_tag_category (id, category_nm, category_desc, state, is_delete, create_time, update_time)
+        VALUES (#{id}, #{categoryNm}, #{categoryDesc}, 1, 0, #{createTime}, #{updateTime})
     </insert>
     </insert>
 
 
     <!-- 按 ID 查询 -->
     <!-- 按 ID 查询 -->
@@ -55,7 +42,7 @@
     <!-- 更新 -->
     <!-- 更新 -->
     <update id="updateCategory">
     <update id="updateCategory">
         UPDATE aitag_tag_category
         UPDATE aitag_tag_category
-        SET category_nm = #{categoryNm}, category_desc = #{categoryDesc}
+        SET category_nm = #{categoryNm}, category_desc = #{categoryDesc}, update_time = #{updateTime}
         WHERE id = #{id}
         WHERE id = #{id}
     </update>
     </update>
 
 
@@ -83,6 +70,7 @@
     <select id="selectPageEnabledCategories" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
     <select id="selectPageEnabledCategories" resultType="cn.com.yusys.yusp.domain.entity.AitagTagCategory">
         SELECT * FROM aitag_tag_category
         SELECT * FROM aitag_tag_category
         WHERE is_delete = 0 AND state = 0
         WHERE is_delete = 0 AND state = 0
+        ORDER BY update_time DESC
             LIMIT #{offset}, #{limit}
             LIMIT #{offset}, #{limit}
     </select>
     </select>