2507040827 před 4 týdny
rodič
revize
cbfbe9a10e

+ 35 - 0
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/config/GlobalExceptionHandler.java

@@ -0,0 +1,35 @@
+package cn.com.yusys.yusp.config;
+
+
+import cn.com.yusys.yusp.commons.exception.BizException;
+import cn.com.yusys.yusp.commons.exception.ExceptionMessage;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.annotation.Order;
+import org.springframework.validation.BindException;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.validation.ConstraintViolationException;
+
+/**
+ * 异常处理
+ * @author zky
+ */
+@RestControllerAdvice
+@Order(0)
+@Slf4j
+public class GlobalExceptionHandler {
+
+    @ExceptionHandler(BizException.class)
+    public ExceptionMessage handleValidationExceptions(BizException ex) {
+        ExceptionMessage exceptionMessage = new ExceptionMessage();
+        exceptionMessage.setCode(ex.getErrorCode());
+        exceptionMessage.setMessage(ex.getMessage());
+        return exceptionMessage;
+    }
+
+
+
+}

+ 11 - 12
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/controller/AitagTagInfoController.java

@@ -5,10 +5,7 @@ import cn.com.yusys.yusp.commons.exception.BizException;
 import cn.com.yusys.yusp.commons.module.adapter.web.rest.ResultDto;
 import cn.com.yusys.yusp.domain.dto.TagInfoDto;
 import cn.com.yusys.yusp.domain.entity.AitagTagInfoEntity;
-import cn.com.yusys.yusp.domain.vo.AitagTagInfoQueryVo;
-import cn.com.yusys.yusp.domain.vo.GenerateRegexVo;
-import cn.com.yusys.yusp.domain.vo.TagNodeVo;
-import cn.com.yusys.yusp.domain.vo.VersionRollbackVo;
+import cn.com.yusys.yusp.domain.vo.*;
 import cn.com.yusys.yusp.domain.vo.fastapivo.AiTaggingResponseVo;
 import cn.com.yusys.yusp.service.AitagTagInfoService;
 import com.alibaba.fastjson.JSON;
@@ -16,7 +13,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
@@ -27,6 +23,7 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.validation.Valid;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
@@ -111,13 +108,14 @@ public class AitagTagInfoController {
     /**
      * 保存
      *
-     * @param aitagTagInfoEntity
+     * @param tagSaveVo
      * @return ResultDto
      */
     @ApiOperationType("标签保存")
     @PostMapping("/save")
-    public ResultDto save(@RequestBody AitagTagInfoEntity aitagTagInfoEntity) {
-        String id = aitagTagInfoService.saveTag(aitagTagInfoEntity);
+    public ResultDto save(@Valid @RequestBody TagSaveVo tagSaveVo) {
+        AitagTagInfoEntity aitagTagInfo = JSON.parseObject(JSON.toJSONString(tagSaveVo), AitagTagInfoEntity.class);
+        String id = aitagTagInfoService.saveTag(aitagTagInfo);
         HashMap<String, Object> body = new HashMap<>();
         String[] ids = {id};
         body.put("tag_ids",ids);
@@ -128,15 +126,16 @@ public class AitagTagInfoController {
     /**
      * 修改
      *
-     * @param aitagTagInfoEntity
+     * @param updateVo
      * @return ResultDto
      */
     @ApiOperationType("标签修改")
     @PostMapping("/update")
-    public ResultDto update(@RequestBody AitagTagInfoEntity aitagTagInfoEntity) {
-        aitagTagInfoService.updateTag(aitagTagInfoEntity);
+    public ResultDto update(@Valid @RequestBody TagUpdateVo updateVo) {
+        AitagTagInfoEntity aitagTagInfo = JSON.parseObject(JSON.toJSONString(updateVo), AitagTagInfoEntity.class);
+        aitagTagInfoService.updateTag(aitagTagInfo);
         HashMap<String, Object> body = new HashMap<>();
-        String[] ids = {aitagTagInfoEntity.getId()};
+        String[] ids = {aitagTagInfo.getId()};
         body.put("tag_ids",ids);
         aitagTagInfoService.callAiTag(body,"/api/aitag/admin/v1/synchronize_tag");
         return ResultDto.success();

+ 5 - 3
server/yusp-tagging-core/src/main/java/cn/com/yusys/yusp/domain/entity/AitagTagInfoEntity.java

@@ -1,8 +1,6 @@
 package cn.com.yusys.yusp.domain.entity;
 
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.*;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -30,18 +28,21 @@ public class AitagTagInfoEntity {
      * 所属大类
      **/
     @ApiModelProperty(value = "所属大类")
+    @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
     private String categoryId;
 
     /**
      * 标签名称
      **/
     @ApiModelProperty(value = "标签名称")
+    @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
     private String tagNm;
 
     /**
      * 标签代码
      **/
     @ApiModelProperty(value = "标签代码")
+    @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
     private String tagCode;
 
     /**
@@ -54,6 +55,7 @@ public class AitagTagInfoEntity {
      * 父级ID
      **/
     @ApiModelProperty(value = "父级ID")
+    @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
     private String parentId;
 
     /**

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

@@ -0,0 +1,77 @@
+package cn.com.yusys.yusp.domain.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+
+/**
+ * 标签新增
+ * @author zky
+ */
+
+@Data
+public class TagSaveVo {
+
+
+    /**
+     * 所属大类
+     **/
+    @ApiModelProperty(value = "所属大类")
+    @NotBlank(message = "所属大类不能为空")
+    private String categoryId;
+
+
+    /**
+     * 标签名称
+     **/
+    @NotBlank(message = "标签名称不能为空")
+    @ApiModelProperty(value = "标签名称", required = true)
+    private String tagNm;
+
+    /**
+     * 标签代码
+     **/
+    @NotBlank(message = "标签代码不能为空")
+    @ApiModelProperty(value = "标签代码", required = true)
+    private String tagCode;
+
+    /**
+     * 标签备注
+     **/
+    @ApiModelProperty(value = "标签备注")
+    private String tagRemark;
+
+    /**
+     * 父级ID
+     **/
+    @NotBlank(message = "上级标签不能为空")
+    @ApiModelProperty(value = "父级ID", required = true)
+    private String parentId;
+
+    /**
+     * 标签规则
+     **/
+    @ApiModelProperty(value = "标签规则")
+    private String reg;
+
+    /**
+     * 标签等级
+     **/
+    @ApiModelProperty(value = "标签等级")
+    private Integer tagLevel;
+
+    /**
+     * tag1/tag2/tag3/...
+     **/
+    @ApiModelProperty(value = "tag1/tag2/tag3/...")
+    private String tagPath;
+
+    /**
+     * 标签提示词
+     **/
+    @ApiModelProperty(value = "标签提示词")
+    private String tagPrompt;
+
+}

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

@@ -0,0 +1,81 @@
+package cn.com.yusys.yusp.domain.vo;
+
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+
+/**
+ * 标签修改实体磊
+ */
+@Data
+public class TagUpdateVo {
+
+
+    /**
+     * id
+     **/
+    @ApiModelProperty(value="id")
+    @NotBlank(message = "标签主键")
+    private String id;
+
+    /**
+     * 所属大类
+     **/
+    @ApiModelProperty(value = "所属大类")
+    private String categoryId;
+
+    /**
+     * 标签名称
+     **/
+    @ApiModelProperty(value = "标签名称", required = true)
+    private String tagNm;
+
+    /**
+     * 标签代码
+     **/
+    @ApiModelProperty(value = "标签代码", required = true)
+    private String tagCode;
+
+    /**
+     * 标签备注
+     **/
+    @ApiModelProperty(value = "标签备注")
+    private String tagRemark;
+
+    /**
+     * 父级ID
+     **/
+    @ApiModelProperty(value = "父级ID", required = true)
+    private String parentId;
+
+    /**
+     * 标签规则
+     **/
+    @ApiModelProperty(value = "标签规则")
+    private String reg;
+
+    /**
+     * 标签等级
+     **/
+    @ApiModelProperty(value = "标签等级")
+    private Integer tagLevel;
+
+    /**
+     * tag1/tag2/tag3/...
+     **/
+    @ApiModelProperty(value = "tag1/tag2/tag3/...")
+    private String tagPath;
+
+    /**
+     * 标签提示词
+     **/
+    @ApiModelProperty(value = "标签提示词")
+    private String tagPrompt;
+
+
+}

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

@@ -123,6 +123,13 @@ public class AitagTagInfoServiceImpl extends ServiceImpl<AitagTagInfoDao, AitagT
     public String saveTag(AitagTagInfoEntity aitagTagInfo){
         aitagTagInfo.setId(StringUtils.getUUID());
         String parentId = aitagTagInfo.getParentId();
+
+        LambdaQueryWrapper<AitagTagInfoEntity> queryTagInfo = new LambdaQueryWrapper<>();
+        queryTagInfo.eq(AitagTagInfoEntity::getTagCode,aitagTagInfo.getTagCode());
+        if(this.baseMapper.selectCount(queryTagInfo) > 0){
+            throw BizException.of("E010");
+        }
+
         if(!StringUtils.isBlank(parentId)){
             LambdaQueryWrapper<AitagTagInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
             queryWrapper.eq(AitagTagInfoEntity::getParentId,parentId);
@@ -179,14 +186,34 @@ public class AitagTagInfoServiceImpl extends ServiceImpl<AitagTagInfoDao, AitagT
     @Transactional(rollbackFor = Exception.class)
     public void updateTag(AitagTagInfoEntity aitagTagInfoEntity) {
         AitagTagInfoEntity tagInfo = this.baseMapper.selectById(aitagTagInfoEntity.getId());
+        String newTagCode = aitagTagInfoEntity.getTagCode();
+        String oldTagCode = tagInfo.getTagCode();
+        if(!StringUtils.isEmpty(newTagCode) && !StringUtils.equals(oldTagCode,newTagCode)){
+            LambdaQueryWrapper<AitagTagInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(AitagTagInfoEntity::getTagCode,newTagCode);
+            if(this.baseMapper.selectCount(queryWrapper) > 0 ){
+                throw BizException.of("E010");
+            }
+        }
         AitagTagInfoVersionEntity aitagTagInfoVersionEntity = JSON.parseObject(JSON.toJSONString(tagInfo), AitagTagInfoVersionEntity.class);
         aitagTagInfoVersionEntity.setId(StringUtils.getUUID());
         this.aitagTagInfoVersionDao.insert(aitagTagInfoVersionEntity);
         aitagTagInfoEntity.setRevisionTime(DateUtils.getCurrDateTimeStr());
         aitagTagInfoEntity.setTagVersion(Integer.parseInt(tagInfo.getTagVersion())+1+"");
-        AitagTagInfoEntity parentTagInfo = this.baseMapper.selectById(aitagTagInfoEntity.getParentId());
-        aitagTagInfoEntity.setTagPath(parentTagInfo.getTagPath()+"/"+aitagTagInfoEntity.getTagNm());
-        aitagTagInfoEntity.setTagLevel(parentTagInfo.getTagLevel()+1);
+        if(!StringUtils.isBlank(aitagTagInfoEntity.getParentId())){
+            AitagTagInfoEntity parentTagInfo = this.baseMapper.selectById(aitagTagInfoEntity.getParentId());
+            if(parentTagInfo !=null){
+                aitagTagInfoEntity.setTagPath(parentTagInfo.getTagPath()+"/"+aitagTagInfoEntity.getTagNm());
+                aitagTagInfoEntity.setTagLevel(parentTagInfo.getTagLevel()+1);
+            }else{
+                aitagTagInfoEntity.setTagPath(aitagTagInfoEntity.getTagNm());
+                aitagTagInfoEntity.setTagLevel(1);
+            }
+        }else{
+            aitagTagInfoEntity.setTagPath(aitagTagInfoEntity.getTagNm());
+            aitagTagInfoEntity.setTagLevel(1);
+        }
+
         aitagTagInfoEntity.setReviser(SessionCommonUtil.getUserInfo());
         this.baseMapper.updateById(aitagTagInfoEntity);
     }

+ 2 - 1
server/yusp-tagging-core/src/main/resources/messages/yusp_input_msg.properties

@@ -106,4 +106,5 @@ E005=\u53D1\u73B0\u91CD\u590D\u7684\u6807\u7B7E\u540D\u79F0:[{0}]
 E006=\u6821\u9A8C\u5931\u8D25\uFF1A\u6807\u7B7E [{0}] \u7684\u7236\u6807\u7B7E [{1}] \u4E0D\u5B58\u5728\u4E8E\u6587\u4EF6\u4E2D\u3002
 E007=\u68C0\u6D4B\u5230\u6807\u7B7E\u5C42\u7EA7\u73AF\u8DEF:{0}
 E008=\u8C03\u7528AI\u6253\u6807\u63A5\u53E3\u5931\u8D25
-E009=\u83B7\u53D6\u7528\u6237\u767B\u9646\u4FE1\u606F\u4E3A\u7A7A
+E009=\u83B7\u53D6\u7528\u6237\u767B\u9646\u4FE1\u606F\u4E3A\u7A7A
+E010=\u6807\u7B7E\u7F16\u7801\u91CD\u590D\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165