Commit 2fa6a9fc by 杨卫

feat:标签分类、标签维度、标签枚举自测提交

1 parent 85dd2392
Showing 26 changed files with 725 additions and 18 deletions
...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -20,6 +21,7 @@ public class TagCategoryCreateReqDTO implements Serializable { ...@@ -20,6 +21,7 @@ public class TagCategoryCreateReqDTO implements Serializable {
* 类别名称 * 类别名称
*/ */
@NotBlank(message = "类别名称不能为空") @NotBlank(message = "类别名称不能为空")
@Size(max = 20, message = "类别名称不能超过{max}个字符")
private String categoryName; private String categoryName;
/** /**
...@@ -35,6 +37,7 @@ public class TagCategoryCreateReqDTO implements Serializable { ...@@ -35,6 +37,7 @@ public class TagCategoryCreateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "备注不能超过{max}个字符")
private String remark; private String remark;
/** /**
......
package cn.com.glsx.dj.strategy.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 根据分类代码查询维度及枚举请求DTO
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/17 10:00
*/
@Data
public class TagCategoryDimensionQueryReqDTO implements Serializable {
private static final long serialVersionUID = 7771688999049511198L;
/**
* 分类代码
*/
@NotBlank(message = "分类代码不能为空")
private String categoryCode;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 分类下维度及枚举响应DTO
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/17 10:00
*/
@Data
@ApiModel("分类下维度及枚举响应")
public class TagCategoryDimensionRespDTO implements Serializable {
private static final long serialVersionUID = -139502488401982203L;
@ApiModelProperty("分类ID")
private Integer id;
@ApiModelProperty("分类代码")
private String categoryCode;
@ApiModelProperty("分类名称")
private String categoryName;
@ApiModelProperty("父ID")
private Integer parentId;
@ApiModelProperty("层级")
private Integer level;
@ApiModelProperty("分类完整路径")
private String fullPath;
@ApiModelProperty("维度列表(含枚举)")
private List<TagDimensionRespDTO> dimensions;
}
...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -25,6 +26,7 @@ public class TagCategoryUpdateReqDTO implements Serializable { ...@@ -25,6 +26,7 @@ public class TagCategoryUpdateReqDTO implements Serializable {
/** /**
* 类别名称 * 类别名称
*/ */
@Size(max = 20, message = "类别名称不能超过{max}个字符")
private String categoryName; private String categoryName;
/** /**
...@@ -35,6 +37,7 @@ public class TagCategoryUpdateReqDTO implements Serializable { ...@@ -35,6 +37,7 @@ public class TagCategoryUpdateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "备注不能超过{max}个字符")
private String remark; private String remark;
/** /**
......
...@@ -4,6 +4,7 @@ import lombok.Data; ...@@ -4,6 +4,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -21,6 +22,7 @@ public class TagDimensionCreateReqDTO implements Serializable { ...@@ -21,6 +22,7 @@ public class TagDimensionCreateReqDTO implements Serializable {
* 维度名称 * 维度名称
*/ */
@NotBlank(message = "维度名称不能为空") @NotBlank(message = "维度名称不能为空")
@Size(max = 20, message = "维度名称不能超过{max}个字符")
private String dimensionName; private String dimensionName;
/** /**
...@@ -37,6 +39,7 @@ public class TagDimensionCreateReqDTO implements Serializable { ...@@ -37,6 +39,7 @@ public class TagDimensionCreateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "备注不能超过{max}个字符")
private String remark; private String remark;
/** /**
......
package cn.com.glsx.dj.strategy.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 根据维度代码查询枚举请求DTO
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/17 10:00
*/
@Data
public class TagDimensionEnumQueryReqDTO implements Serializable {
private static final long serialVersionUID = -7267991348884319064L;
/**
* 维度代码
*/
@NotBlank(message = "维度代码不能为空")
private String dimensionCode;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 维度及枚举响应DTO
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/17 10:00
*/
@Data
@ApiModel("维度及枚举响应")
public class TagDimensionEnumRespDTO implements Serializable {
private static final long serialVersionUID = 381299580795543364L;
@ApiModelProperty("维度ID")
private Integer id;
@ApiModelProperty("维度代码")
private String dimensionCode;
@ApiModelProperty("维度名称")
private String dimensionName;
@ApiModelProperty("所属分类ID")
private Integer categoryId;
@ApiModelProperty("所属分类名称")
private String categoryName;
@ApiModelProperty("分类完整路径")
private String categoryFullPath;
@ApiModelProperty("排序号")
private Integer sortOrder;
@ApiModelProperty("是否可编辑")
private Integer canEdit;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("枚举值列表")
private List<TagEnumRespDTO> enums;
}
...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* 查询标签维度请求DTO * 查询标签维度请求DTO
...@@ -16,11 +17,16 @@ public class TagDimensionQueryReqDTO implements Serializable { ...@@ -16,11 +17,16 @@ public class TagDimensionQueryReqDTO implements Serializable {
private static final long serialVersionUID = -5344898013694068878L; private static final long serialVersionUID = -5344898013694068878L;
/** /**
* 分类ID(可选,不传则查询全部) * 分类ID(可选,不传则查询全部;传一级分类时自动包含子分类下的维度)
*/ */
private Integer categoryId; private Integer categoryId;
/** /**
* 分类ID列表(内部使用,Service层根据categoryId递归收集后代分类ID后设置)
*/
private List<Integer> categoryIds;
/**
* 维度名称(模糊查询) * 维度名称(模糊查询)
*/ */
private String dimensionName; private String dimensionName;
......
...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -25,6 +26,7 @@ public class TagDimensionUpdateReqDTO implements Serializable { ...@@ -25,6 +26,7 @@ public class TagDimensionUpdateReqDTO implements Serializable {
/** /**
* 维度名称 * 维度名称
*/ */
@Size(max = 20, message = "维度名称不能超过{max}个字符")
private String dimensionName; private String dimensionName;
/** /**
...@@ -35,6 +37,7 @@ public class TagDimensionUpdateReqDTO implements Serializable { ...@@ -35,6 +37,7 @@ public class TagDimensionUpdateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "备注不能超过{max}个字符")
private String remark; private String remark;
/** /**
......
...@@ -2,8 +2,11 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -2,8 +2,11 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -27,12 +30,15 @@ public class TagEnumCreateReqDTO implements Serializable { ...@@ -27,12 +30,15 @@ public class TagEnumCreateReqDTO implements Serializable {
* 枚举名称 * 枚举名称
*/ */
@NotBlank(message = "枚举名称不能为空") @NotBlank(message = "枚举名称不能为空")
@Size(max = 20, message = "枚举名称不能超过{max}")
private String enumName; private String enumName;
/** /**
* 命中客户分数 * 命中客户分数
*/ */
@NotNull(message = "命中客户分数不能为空") @NotNull(message = "命中客户分数不能为空")
@Min(value = 0, message = "分数不能为负数")
@Max(value = 100, message = "分数不能超过{value}")
private Integer score; private Integer score;
/** /**
...@@ -43,6 +49,7 @@ public class TagEnumCreateReqDTO implements Serializable { ...@@ -43,6 +49,7 @@ public class TagEnumCreateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "枚举值描述不能超过{max}")
private String remark; private String remark;
/** /**
......
...@@ -2,7 +2,10 @@ package cn.com.glsx.dj.strategy.dto; ...@@ -2,7 +2,10 @@ package cn.com.glsx.dj.strategy.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -25,11 +28,14 @@ public class TagEnumUpdateReqDTO implements Serializable { ...@@ -25,11 +28,14 @@ public class TagEnumUpdateReqDTO implements Serializable {
/** /**
* 枚举名称 * 枚举名称
*/ */
@Size(max = 20, message = "枚举名称不能超过{max}个字符")
private String enumName; private String enumName;
/** /**
* 命中客户分数 * 命中客户分数
*/ */
@Min(value = 0, message = "分数不能为负数")
@Max(value = 100, message = "分数不能超过{value}")
private Integer score; private Integer score;
/** /**
...@@ -40,6 +46,7 @@ public class TagEnumUpdateReqDTO implements Serializable { ...@@ -40,6 +46,7 @@ public class TagEnumUpdateReqDTO implements Serializable {
/** /**
* 备注 * 备注
*/ */
@Size(max = 500, message = "备注不能超过{max}个字符")
private String remark; private String remark;
/** /**
......
...@@ -57,7 +57,16 @@ public enum TagErrorEnum implements ErrorEnum { ...@@ -57,7 +57,16 @@ public enum TagErrorEnum implements ErrorEnum {
ENUM_NAME_CANNOT_EDIT("11022002", "枚举名称不可修改"), ENUM_NAME_CANNOT_EDIT("11022002", "枚举名称不可修改"),
/** 枚举分数不可修改 */ /** 枚举分数不可修改 */
ENUM_SCORE_CANNOT_EDIT("11022003", "枚举分数不可修改"); ENUM_SCORE_CANNOT_EDIT("11022003", "枚举分数不可修改"),
/** 分类名称已存在 */
CATEGORY_NAME_DUPLICATE("11020006", "分类名称已存在"),
/** 维度名称已存在(同一分类下) */
DIMENSION_NAME_DUPLICATE("11021005", "维度名称已存在"),
/** 枚举名称已存在(同一维度下) */
ENUM_NAME_DUPLICATE("11022004", "枚举名称已存在");
private final String value; private final String value;
private final String displayName; private final String displayName;
......
...@@ -37,4 +37,9 @@ public interface TagCategoryRemote { ...@@ -37,4 +37,9 @@ public interface TagCategoryRemote {
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = false) @ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = false)
@ApiResponse("查询可新增子级的分类列表") @ApiResponse("查询可新增子级的分类列表")
RpcResponse<List<TagCategoryLeafRespDTO>> queryCategoryLeafList(); RpcResponse<List<TagCategoryLeafRespDTO>> queryCategoryLeafList();
@ApiMethod("根据分类代码查询分类下所有维度及其枚举")
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("根据分类代码查询分类下所有维度及其枚举")
RpcResponse<TagCategoryDimensionRespDTO> queryCategoryWithDimensions(TagCategoryDimensionQueryReqDTO request);
} }
...@@ -42,4 +42,9 @@ public interface TagDimensionRemote { ...@@ -42,4 +42,9 @@ public interface TagDimensionRemote {
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("更新标签维度") @ApiResponse("更新标签维度")
RpcResponse<Void> updateDimension(TagDimensionUpdateReqDTO request); RpcResponse<Void> updateDimension(TagDimensionUpdateReqDTO request);
@ApiMethod("根据维度代码查询枚举列表")
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("根据维度代码查询枚举列表")
RpcResponse<TagDimensionEnumRespDTO> queryDimensionWithEnums(TagDimensionEnumQueryReqDTO request);
} }
...@@ -40,4 +40,20 @@ public interface TagCategoryMapper extends OreMapper<TagCategory> { ...@@ -40,4 +40,20 @@ public interface TagCategoryMapper extends OreMapper<TagCategory> {
* 统计分类下是否存在标签维度 * 统计分类下是否存在标签维度
*/ */
int countDimensionsByCategoryId(Integer categoryId); int countDimensionsByCategoryId(Integer categoryId);
/**
* 根据名称统计分类数量(全局唯一,excludeId用于更新时排除自身)
*/
int countByCategoryName(@Param("categoryName") String categoryName, @Param("excludeId") Integer excludeId);
/**
* 查询全部分类中最大的sort_order
*/
Integer selectMaxSortOrder();
/**
* 根据分类代码查询分类
*/
TagCategory selectByCategoryCode(@Param("categoryCode") String categoryCode);
} }
...@@ -26,4 +26,19 @@ public interface TagDimensionMapper extends OreMapper<TagDimension> { ...@@ -26,4 +26,19 @@ public interface TagDimensionMapper extends OreMapper<TagDimension> {
* 统计维度下枚举数量 * 统计维度下枚举数量
*/ */
int countEnumByDimensionId(Integer dimensionId); int countEnumByDimensionId(Integer dimensionId);
/**
* 根据名称统计同一分类下维度数量(excludeId用于更新时排除自身)
*/
int countByDimensionName(@Param("categoryId") Integer categoryId, @Param("dimensionName") String dimensionName, @Param("excludeId") Integer excludeId);
/**
* 查询同一分类下最大的sort_order
*/
Integer selectMaxSortOrderByCategoryId(@Param("categoryId") Integer categoryId);
/**
* 根据维度代码查询维度
*/
TagDimension selectByDimensionCode(@Param("dimensionCode") String dimensionCode);
} }
...@@ -26,4 +26,19 @@ public interface TagEnumMapper extends OreMapper<TagEnum> { ...@@ -26,4 +26,19 @@ public interface TagEnumMapper extends OreMapper<TagEnum> {
* 根据维度ID列表批量查询枚举值 * 根据维度ID列表批量查询枚举值
*/ */
List<TagEnum> selectByDimensionIds(@Param("dimensionIds") List<Integer> dimensionIds); List<TagEnum> selectByDimensionIds(@Param("dimensionIds") List<Integer> dimensionIds);
/**
* 根据名称统计同一维度下枚举数量(excludeId用于更新时排除自身)
*/
int countByEnumName(@Param("dimensionId") Integer dimensionId, @Param("enumName") String enumName, @Param("excludeId") Integer excludeId);
/**
* 查询同一维度下最大的sort_order
*/
Integer selectMaxSortOrderByDimensionId(@Param("dimensionId") Integer dimensionId);
/**
* 根据维度ID查询所有枚举值(不分页)
*/
List<TagEnum> selectByDimensionId(@Param("dimensionId") Integer dimensionId);
} }
...@@ -75,4 +75,17 @@ public class TagCategoryRemoteImpl implements TagCategoryRemote { ...@@ -75,4 +75,17 @@ public class TagCategoryRemoteImpl implements TagCategoryRemote {
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<TagCategoryDimensionRespDTO> queryCategoryWithDimensions(TagCategoryDimensionQueryReqDTO request) {
try {
return RpcResponse.success(tagCategoryService.queryCategoryWithDimensions(request));
} catch (RpcServiceException e) {
log.error("根据分类代码查询维度及枚举 occur RpcServiceException", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("根据分类代码查询维度及枚举 occur Exception", e);
return RpcResponse.error(e);
}
}
} }
...@@ -103,4 +103,17 @@ public class TagDimensionRemoteImpl implements TagDimensionRemote { ...@@ -103,4 +103,17 @@ public class TagDimensionRemoteImpl implements TagDimensionRemote {
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<TagDimensionEnumRespDTO> queryDimensionWithEnums(TagDimensionEnumQueryReqDTO request) {
try {
return RpcResponse.success(tagDimensionService.queryDimensionWithEnums(request));
} catch (RpcServiceException e) {
log.error("根据维度代码查询枚举列表 occur RpcServiceException", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("根据维度代码查询枚举列表 occur Exception", e);
return RpcResponse.error(e);
}
}
} }
...@@ -4,7 +4,11 @@ import cn.com.glsx.dj.strategy.dto.*; ...@@ -4,7 +4,11 @@ import cn.com.glsx.dj.strategy.dto.*;
import cn.com.glsx.dj.strategy.enums.TagConstants; import cn.com.glsx.dj.strategy.enums.TagConstants;
import cn.com.glsx.dj.strategy.enums.TagErrorEnum; import cn.com.glsx.dj.strategy.enums.TagErrorEnum;
import cn.com.glsx.dj.strategy.mapper.TagCategoryMapper; import cn.com.glsx.dj.strategy.mapper.TagCategoryMapper;
import cn.com.glsx.dj.strategy.mapper.TagDimensionMapper;
import cn.com.glsx.dj.strategy.mapper.TagEnumMapper;
import cn.com.glsx.dj.strategy.model.TagCategory; import cn.com.glsx.dj.strategy.model.TagCategory;
import cn.com.glsx.dj.strategy.model.TagDimension;
import cn.com.glsx.dj.strategy.model.TagEnum;
import cn.com.glsx.dj.strategy.util.validation.BeanValidationUtils; import cn.com.glsx.dj.strategy.util.validation.BeanValidationUtils;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum; import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum;
...@@ -30,6 +34,8 @@ import java.util.stream.Collectors; ...@@ -30,6 +34,8 @@ import java.util.stream.Collectors;
public class TagCategoryService { public class TagCategoryService {
private final TagCategoryMapper tagCategoryMapper; private final TagCategoryMapper tagCategoryMapper;
private final TagDimensionMapper tagDimensionMapper;
private final TagEnumMapper tagEnumMapper;
/** 标签类别最大层级,默认2,可通过配置 tag.category.max.level 覆盖 */ /** 标签类别最大层级,默认2,可通过配置 tag.category.max.level 覆盖 */
@Value("${tag.category.max.level:2}") @Value("${tag.category.max.level:2}")
...@@ -42,6 +48,11 @@ public class TagCategoryService { ...@@ -42,6 +48,11 @@ public class TagCategoryService {
public TagCategoryRespDTO createCategory(TagCategoryCreateReqDTO request) { public TagCategoryRespDTO createCategory(TagCategoryCreateReqDTO request) {
BeanValidationUtils.validateAndThrow(request); BeanValidationUtils.validateAndThrow(request);
// 校验分类名称全局唯一
if (tagCategoryMapper.countByCategoryName(request.getCategoryName(), null) > 0) {
throw new RpcServiceException(TagErrorEnum.CATEGORY_NAME_DUPLICATE);
}
TagCategory entity = new TagCategory(); TagCategory entity = new TagCategory();
int level = 1; int level = 1;
...@@ -63,7 +74,13 @@ public class TagCategoryService { ...@@ -63,7 +74,13 @@ public class TagCategoryService {
entity.setCategoryName(request.getCategoryName()); entity.setCategoryName(request.getCategoryName());
entity.setLevel(level); entity.setLevel(level);
entity.setSortOrder(request.getSortOrder() != null ? request.getSortOrder() : TagConstants.CAN_FLAG_NO); // sortOrder未传入时取全局最大+1
if (request.getSortOrder() != null) {
entity.setSortOrder(request.getSortOrder());
} else {
Integer maxSort = tagCategoryMapper.selectMaxSortOrder();
entity.setSortOrder(maxSort != null ? maxSort + 1 : 1);
}
entity.setRemark(request.getRemark()); entity.setRemark(request.getRemark());
entity.setDeletedFlag(DeleteFlagEnum.N.getValue()); entity.setDeletedFlag(DeleteFlagEnum.N.getValue());
entity.setCanEdit(TagConstants.CAN_FLAG_YES); entity.setCanEdit(TagConstants.CAN_FLAG_YES);
...@@ -101,6 +118,10 @@ public class TagCategoryService { ...@@ -101,6 +118,10 @@ public class TagCategoryService {
} }
if (request.getCategoryName() != null) { if (request.getCategoryName() != null) {
// 校验分类名称全局唯一(排除自身)
if (tagCategoryMapper.countByCategoryName(request.getCategoryName(), request.getId()) > 0) {
throw new RpcServiceException(TagErrorEnum.CATEGORY_NAME_DUPLICATE);
}
category.setCategoryName(request.getCategoryName()); category.setCategoryName(request.getCategoryName());
} }
if (request.getSortOrder() != null) { if (request.getSortOrder() != null) {
...@@ -217,6 +238,102 @@ public class TagCategoryService { ...@@ -217,6 +238,102 @@ public class TagCategoryService {
return buildFullPath(parent, idMap) + "/" + category.getCategoryName(); return buildFullPath(parent, idMap) + "/" + category.getCategoryName();
} }
/**
* 根据分类代码查询分类下所有维度及其枚举(含子分类下的维度)
*/
public TagCategoryDimensionRespDTO queryCategoryWithDimensions(TagCategoryDimensionQueryReqDTO request) {
BeanValidationUtils.validateAndThrow(request);
TagCategory category = Optional.ofNullable(tagCategoryMapper.selectByCategoryCode(request.getCategoryCode()))
.filter(c -> DeleteFlagEnum.N.getValue().equals(c.getDeletedFlag()))
.orElseThrow(() -> new RpcServiceException(TagErrorEnum.CATEGORY_NOT_EXISTS));
// 一次性加载全部分类用于 buildFullPath 和子分类收集
Map<Integer, TagCategory> allCategoryMap = tagCategoryMapper.selectAllCategories().stream()
.collect(Collectors.toMap(TagCategory::getId, c -> c));
// 收集自身及所有后代分类ID
List<Integer> allCategoryIds = new ArrayList<>();
collectDescendantIds(category.getId(), allCategoryMap, allCategoryIds);
allCategoryIds.add(category.getId());
// 查询所有相关维度(不分页)
TagDimensionQueryReqDTO dimQuery = new TagDimensionQueryReqDTO();
dimQuery.setCategoryIds(allCategoryIds);
List<TagDimension> dimensions = tagDimensionMapper.queryDimensionList(dimQuery);
// 批量查询枚举值
List<TagDimensionRespDTO> dimensionDTOs;
if (dimensions.isEmpty()) {
dimensionDTOs = Collections.emptyList();
} else {
List<Integer> dimensionIds = dimensions.stream().map(TagDimension::getId).collect(Collectors.toList());
Map<Integer, List<TagEnum>> enumMap = tagEnumMapper.selectByDimensionIds(dimensionIds).stream()
.collect(Collectors.groupingBy(TagEnum::getDimensionId));
dimensionDTOs = dimensions.stream().map(dim -> {
TagDimensionRespDTO dto = new TagDimensionRespDTO();
dto.setId(dim.getId());
dto.setDimensionCode(dim.getDimensionCode());
dto.setDimensionName(dim.getDimensionName());
dto.setCategoryId(dim.getCategoryId());
TagCategory cat = allCategoryMap.get(dim.getCategoryId());
dto.setCategoryName(cat != null ? cat.getCategoryName() : null);
dto.setCategoryFullPath(cat != null ? buildFullPath(cat, allCategoryMap) : null);
dto.setEnumCount(dim.getEnumCount());
dto.setSortOrder(dim.getSortOrder());
dto.setCanEdit(dim.getCanEdit());
dto.setCanAddEnum(dim.getCanAddEnum());
List<TagEnum> dimEnums = enumMap.getOrDefault(dim.getId(), Collections.emptyList());
dto.setEnums(dimEnums.stream().map(this::convertTagEnumToRespDTO).collect(Collectors.toList()));
dto.setCreatedDate(dim.getCreatedDate());
dto.setUpdatedDate(dim.getUpdatedDate());
return dto;
}).collect(Collectors.toList());
}
TagCategoryDimensionRespDTO result = new TagCategoryDimensionRespDTO();
result.setId(category.getId());
result.setCategoryCode(category.getCategoryCode());
result.setCategoryName(category.getCategoryName());
result.setParentId(category.getParentId());
result.setLevel(category.getLevel());
result.setFullPath(buildFullPath(category, allCategoryMap));
result.setDimensions(dimensionDTOs);
return result;
}
/**
* 递归收集后代分类ID
*/
private void collectDescendantIds(Integer parentId, Map<Integer, TagCategory> allCategoryMap, List<Integer> result) {
for (TagCategory cat : allCategoryMap.values()) {
if (parentId.equals(cat.getParentId())) {
result.add(cat.getId());
collectDescendantIds(cat.getId(), allCategoryMap, result);
}
}
}
/**
* TagEnum 转 TagEnumRespDTO
*/
private TagEnumRespDTO convertTagEnumToRespDTO(TagEnum entity) {
TagEnumRespDTO dto = new TagEnumRespDTO();
dto.setId(entity.getId());
dto.setEnumCode(entity.getEnumCode());
dto.setEnumName(entity.getEnumName());
dto.setDimensionId(entity.getDimensionId());
dto.setScore(entity.getScore());
dto.setSortOrder(entity.getSortOrder());
dto.setEnumNameCanEdit(entity.getEnumNameCanEdit());
dto.setScoreCanEdit(entity.getScoreCanEdit());
dto.setRemark(entity.getRemark());
dto.setCreatedDate(entity.getCreatedDate());
dto.setUpdatedDate(entity.getUpdatedDate());
return dto;
}
private TagCategoryRespDTO convertToRespDTO(TagCategory entity) { private TagCategoryRespDTO convertToRespDTO(TagCategory entity) {
TagCategoryRespDTO dto = new TagCategoryRespDTO(); TagCategoryRespDTO dto = new TagCategoryRespDTO();
dto.setId(entity.getId()); dto.setId(entity.getId());
......
...@@ -57,10 +57,21 @@ public class TagDimensionService { ...@@ -57,10 +57,21 @@ public class TagDimensionService {
throw new RpcServiceException(TagErrorEnum.CATEGORY_CANNOT_ADD_DIMENSION); throw new RpcServiceException(TagErrorEnum.CATEGORY_CANNOT_ADD_DIMENSION);
} }
// 校验维度名称在同一分类下唯一
if (tagDimensionMapper.countByDimensionName(request.getCategoryId(), request.getDimensionName(), null) > 0) {
throw new RpcServiceException(TagErrorEnum.DIMENSION_NAME_DUPLICATE);
}
TagDimension entity = new TagDimension(); TagDimension entity = new TagDimension();
entity.setDimensionName(request.getDimensionName()); entity.setDimensionName(request.getDimensionName());
entity.setCategoryId(request.getCategoryId()); entity.setCategoryId(request.getCategoryId());
entity.setSortOrder(request.getSortOrder() != null ? request.getSortOrder() : TagConstants.CAN_FLAG_NO); // sortOrder未传入时取同分类下最大+1
if (request.getSortOrder() != null) {
entity.setSortOrder(request.getSortOrder());
} else {
Integer maxSort = tagDimensionMapper.selectMaxSortOrderByCategoryId(request.getCategoryId());
entity.setSortOrder(maxSort != null ? maxSort + 1 : 1);
}
entity.setRemark(request.getRemark()); entity.setRemark(request.getRemark());
entity.setCanEdit(TagConstants.CAN_FLAG_YES); entity.setCanEdit(TagConstants.CAN_FLAG_YES);
entity.setCanAddEnum(TagConstants.CAN_FLAG_YES); entity.setCanAddEnum(TagConstants.CAN_FLAG_YES);
...@@ -89,14 +100,22 @@ public class TagDimensionService { ...@@ -89,14 +100,22 @@ public class TagDimensionService {
if (request.getPageSize() == null) { if (request.getPageSize() == null) {
request.setPageSize(TagConstants.DEFAULT_PAGE_SIZE); request.setPageSize(TagConstants.DEFAULT_PAGE_SIZE);
} }
// 一次性加载全部分类,用于 buildFullPath、categoryName 查找、以及子分类维度收集
Map<Integer, TagCategory> allCategoryMap = tagCategoryMapper.selectAllCategories().stream()
.collect(Collectors.toMap(TagCategory::getId, c -> c));
// 若指定了categoryId,递归收集其下所有后代分类ID(含自身),使子分类的维度也被查询出来
if (request.getCategoryId() != null) {
List<Integer> allCategoryIds = new ArrayList<>();
collectDescendantCategoryIds(request.getCategoryId(), allCategoryMap, allCategoryIds);
allCategoryIds.add(request.getCategoryId());
request.setCategoryIds(allCategoryIds);
}
PageHelper.startPage(request.getPageNum(), request.getPageSize()); PageHelper.startPage(request.getPageNum(), request.getPageSize());
List<TagDimension> list = tagDimensionMapper.queryDimensionList(request); List<TagDimension> list = tagDimensionMapper.queryDimensionList(request);
PageInfo<TagDimension> pageInfo = new PageInfo<>(list); PageInfo<TagDimension> pageInfo = new PageInfo<>(list);
// 一次性加载全部分类,用于 buildFullPath 和 categoryName 查找
Map<Integer, TagCategory> allCategoryMap = tagCategoryMapper.selectAllCategories().stream()
.collect(Collectors.toMap(TagCategory::getId, c -> c));
// 批量查询所有维度的枚举值,按 dimensionId 分组 // 批量查询所有维度的枚举值,按 dimensionId 分组
List<Integer> dimensionIds = list.stream().map(TagDimension::getId).collect(Collectors.toList()); List<Integer> dimensionIds = list.stream().map(TagDimension::getId).collect(Collectors.toList());
Map<Integer, List<TagEnum>> enumMap = Collections.emptyMap(); Map<Integer, List<TagEnum>> enumMap = Collections.emptyMap();
...@@ -203,6 +222,10 @@ public class TagDimensionService { ...@@ -203,6 +222,10 @@ public class TagDimensionService {
} }
if (request.getDimensionName() != null) { if (request.getDimensionName() != null) {
// 校验维度名称在同一分类下唯一(排除自身)
if (tagDimensionMapper.countByDimensionName(dimension.getCategoryId(), request.getDimensionName(), request.getId()) > 0) {
throw new RpcServiceException(TagErrorEnum.DIMENSION_NAME_DUPLICATE);
}
dimension.setDimensionName(request.getDimensionName()); dimension.setDimensionName(request.getDimensionName());
} }
if (request.getSortOrder() != null) { if (request.getSortOrder() != null) {
...@@ -217,6 +240,42 @@ public class TagDimensionService { ...@@ -217,6 +240,42 @@ public class TagDimensionService {
} }
/** /**
* 根据维度代码查询维度及其所有枚举值
*/
public TagDimensionEnumRespDTO queryDimensionWithEnums(TagDimensionEnumQueryReqDTO request) {
BeanValidationUtils.validateAndThrow(request);
TagDimension dimension = Optional.ofNullable(tagDimensionMapper.selectByDimensionCode(request.getDimensionCode()))
.filter(d -> DeleteFlagEnum.N.getValue().equals(d.getDeletedFlag()))
.orElseThrow(() -> new RpcServiceException(TagErrorEnum.DIMENSION_NOT_EXISTS));
TagDimensionEnumRespDTO dto = new TagDimensionEnumRespDTO();
dto.setId(dimension.getId());
dto.setDimensionCode(dimension.getDimensionCode());
dto.setDimensionName(dimension.getDimensionName());
dto.setCategoryId(dimension.getCategoryId());
dto.setSortOrder(dimension.getSortOrder());
dto.setCanEdit(dimension.getCanEdit());
dto.setRemark(dimension.getRemark());
// 查询分类信息
TagCategory category = tagCategoryMapper.selectByPrimaryKey(dimension.getCategoryId());
if (category != null) {
dto.setCategoryName(category.getCategoryName());
// 加载全部分类用于 buildFullPath
Map<Integer, TagCategory> allCategoryMap = tagCategoryMapper.selectAllCategories().stream()
.collect(Collectors.toMap(TagCategory::getId, c -> c));
dto.setCategoryFullPath(tagCategoryService.buildFullPath(category, allCategoryMap));
}
// 查询该维度下所有枚举值
List<TagEnum> enums = tagEnumMapper.selectByDimensionId(dimension.getId());
dto.setEnums(enums.stream().map(this::convertToEnumRespDTO).collect(Collectors.toList()));
return dto;
}
/**
* TagEnum 实体转 TagEnumRespDTO * TagEnum 实体转 TagEnumRespDTO
*/ */
private TagEnumRespDTO convertToEnumRespDTO(TagEnum entity) { private TagEnumRespDTO convertToEnumRespDTO(TagEnum entity) {
...@@ -234,4 +293,16 @@ public class TagDimensionService { ...@@ -234,4 +293,16 @@ public class TagDimensionService {
dto.setUpdatedDate(entity.getUpdatedDate()); dto.setUpdatedDate(entity.getUpdatedDate());
return dto; return dto;
} }
/**
* 递归收集指定分类下的所有后代分类ID(不含自身),基于内存中的全量分类Map
*/
private void collectDescendantCategoryIds(Integer parentId, Map<Integer, TagCategory> allCategoryMap, List<Integer> result) {
for (TagCategory cat : allCategoryMap.values()) {
if (parentId.equals(cat.getParentId())) {
result.add(cat.getId());
collectDescendantCategoryIds(cat.getId(), allCategoryMap, result);
}
}
}
} }
...@@ -90,11 +90,22 @@ public class TagEnumService { ...@@ -90,11 +90,22 @@ public class TagEnumService {
throw new RpcServiceException(TagErrorEnum.DIMENSION_CANNOT_ADD_ENUM); throw new RpcServiceException(TagErrorEnum.DIMENSION_CANNOT_ADD_ENUM);
} }
// 校验枚举名称在同一维度下唯一
if (tagEnumMapper.countByEnumName(request.getDimensionId(), request.getEnumName(), null) > 0) {
throw new RpcServiceException(TagErrorEnum.ENUM_NAME_DUPLICATE);
}
TagEnum entity = new TagEnum(); TagEnum entity = new TagEnum();
entity.setEnumName(request.getEnumName()); entity.setEnumName(request.getEnumName());
entity.setDimensionId(request.getDimensionId()); entity.setDimensionId(request.getDimensionId());
entity.setScore(request.getScore()); entity.setScore(request.getScore());
entity.setSortOrder(request.getSortOrder() != null ? request.getSortOrder() : TagConstants.CAN_FLAG_NO); // sortOrder未传入时取同维度下最大+1
if (request.getSortOrder() != null) {
entity.setSortOrder(request.getSortOrder());
} else {
Integer maxSort = tagEnumMapper.selectMaxSortOrderByDimensionId(request.getDimensionId());
entity.setSortOrder(maxSort != null ? maxSort + 1 : 1);
}
entity.setRemark(request.getRemark()); entity.setRemark(request.getRemark());
entity.setEnumNameCanEdit(TagConstants.CAN_FLAG_YES); entity.setEnumNameCanEdit(TagConstants.CAN_FLAG_YES);
entity.setScoreCanEdit(TagConstants.CAN_FLAG_YES); entity.setScoreCanEdit(TagConstants.CAN_FLAG_YES);
...@@ -123,11 +134,14 @@ public class TagEnumService { ...@@ -123,11 +134,14 @@ public class TagEnumService {
.filter(e -> DeleteFlagEnum.N.getValue().equals(e.getDeletedFlag())) .filter(e -> DeleteFlagEnum.N.getValue().equals(e.getDeletedFlag()))
.orElseThrow(() -> new RpcServiceException(TagErrorEnum.ENUM_NOT_EXISTS)); .orElseThrow(() -> new RpcServiceException(TagErrorEnum.ENUM_NOT_EXISTS));
// 若修改了枚举名称,校验enum_name_can_edit // 若修改了枚举名称,校验enum_name_can_edit 和 同维度下名称唯一
if (StringUtils.hasText(request.getEnumName()) && !request.getEnumName().equals(tagEnum.getEnumName())) { if (StringUtils.hasText(request.getEnumName()) && !request.getEnumName().equals(tagEnum.getEnumName())) {
if (tagEnum.getEnumNameCanEdit() == TagConstants.CAN_FLAG_NO) { if (tagEnum.getEnumNameCanEdit() == TagConstants.CAN_FLAG_NO) {
throw new RpcServiceException(TagErrorEnum.ENUM_NAME_CANNOT_EDIT); throw new RpcServiceException(TagErrorEnum.ENUM_NAME_CANNOT_EDIT);
} }
if (tagEnumMapper.countByEnumName(tagEnum.getDimensionId(), request.getEnumName(), request.getId()) > 0) {
throw new RpcServiceException(TagErrorEnum.ENUM_NAME_DUPLICATE);
}
tagEnum.setEnumName(request.getEnumName()); tagEnum.setEnumName(request.getEnumName());
} }
......
...@@ -61,15 +61,17 @@ ...@@ -61,15 +61,17 @@
<!-- 查询叶子节点分类(无子分类且可挂载维度,用于维度挂载选项) --> <!-- 查询叶子节点分类(无子分类且可挂载维度,用于维度挂载选项) -->
<select id="selectLeafCategories" resultMap="BaseResultMap"> <select id="selectLeafCategories" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/> SELECT c.id, c.category_code, c.category_name, c.parent_id, c.level, c.sort_order,
FROM dj_car_life_tag_category c.can_edit, c.can_delete, c.can_add_child, c.can_add_dimension, c.remark, c.deleted_flag,
WHERE deleted_flag = 'N' c.created_by, c.created_date, c.updated_by, c.updated_date
AND can_add_dimension = 1 FROM dj_car_life_tag_category c
WHERE c.deleted_flag = 'N'
AND c.can_add_dimension = 1
AND NOT EXISTS ( AND NOT EXISTS (
SELECT 1 FROM dj_car_life_tag_category sub SELECT 1 FROM dj_car_life_tag_category sub
WHERE sub.parent_id = id AND sub.deleted_flag = 'N' WHERE sub.parent_id = c.id AND sub.deleted_flag = 'N'
) )
ORDER BY level ASC, sort_order ASC ORDER BY c.level ASC, c.sort_order ASC
</select> </select>
<!-- 统计分类下是否存在标签维度 --> <!-- 统计分类下是否存在标签维度 -->
...@@ -79,6 +81,30 @@ ...@@ -79,6 +81,30 @@
WHERE category_id = #{categoryId} AND deleted_flag = 'N' WHERE category_id = #{categoryId} AND deleted_flag = 'N'
</select> </select>
<!-- 查询全部分类中最大的sort_order -->
<select id="selectMaxSortOrder" resultType="java.lang.Integer">
SELECT IFNULL(MAX(sort_order), 0)
FROM dj_car_life_tag_category
WHERE deleted_flag = 'N'
</select>
<!-- 根据名称统计分类数量(全局唯一) -->
<select id="countByCategoryName" resultType="int">
SELECT COUNT(1)
FROM dj_car_life_tag_category
WHERE category_name = #{categoryName} AND deleted_flag = 'N'
<if test="excludeId != null">
AND id != #{excludeId}
</if>
</select>
<!-- 根据分类代码查询分类 -->
<select id="selectByCategoryCode" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM dj_car_life_tag_category
WHERE category_code = #{categoryCode} AND deleted_flag = 'N'
</select>
<!-- 查询所有叶子分类(无子分类的节点) --> <!-- 查询所有叶子分类(无子分类的节点) -->
<select id="selectLeafCategories" resultMap="BaseResultMap"> <select id="selectLeafCategories" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/> SELECT <include refid="Base_Column_List"/>
......
...@@ -38,8 +38,16 @@ ...@@ -38,8 +38,16 @@
FROM dj_car_life_tag_dimension d FROM dj_car_life_tag_dimension d
LEFT JOIN dj_car_life_tag_category c ON d.category_id = c.id LEFT JOIN dj_car_life_tag_category c ON d.category_id = c.id
WHERE d.deleted_flag = 'N' WHERE d.deleted_flag = 'N'
<if test="query.categoryId != null"> <if test="query.categoryIds != null and query.categoryIds.size() > 0">
AND d.category_id = #{query.categoryId} AND d.category_id IN
<foreach collection="query.categoryIds" item="cid" open="(" separator="," close=")">
#{cid}
</foreach>
</if>
<if test="query.categoryIds == null or query.categoryIds.size() == 0">
<if test="query.categoryId != null">
AND d.category_id = #{query.categoryId}
</if>
</if> </if>
<if test="query.dimensionName != null and query.dimensionName != ''"> <if test="query.dimensionName != null and query.dimensionName != ''">
AND d.dimension_name LIKE CONCAT('%', #{query.dimensionName}, '%') AND d.dimension_name LIKE CONCAT('%', #{query.dimensionName}, '%')
...@@ -61,4 +69,28 @@ ...@@ -61,4 +69,28 @@
WHERE dimension_id = #{dimensionId} AND deleted_flag = 'N' WHERE dimension_id = #{dimensionId} AND deleted_flag = 'N'
</select> </select>
<!-- 查询同一分类下最大的sort_order -->
<select id="selectMaxSortOrderByCategoryId" resultType="java.lang.Integer">
SELECT IFNULL(MAX(sort_order), 0)
FROM dj_car_life_tag_dimension
WHERE category_id = #{categoryId} AND deleted_flag = 'N'
</select>
<!-- 根据名称统计同一分类下维度数量 -->
<select id="countByDimensionName" resultType="int">
SELECT COUNT(1)
FROM dj_car_life_tag_dimension
WHERE category_id = #{categoryId} AND dimension_name = #{dimensionName} AND deleted_flag = 'N'
<if test="excludeId != null">
AND id != #{excludeId}
</if>
</select>
<!-- 根据维度代码查询维度 -->
<select id="selectByDimensionCode" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM dj_car_life_tag_dimension d
WHERE d.dimension_code = #{dimensionCode} AND d.deleted_flag = 'N'
</select>
</mapper> </mapper>
...@@ -51,4 +51,29 @@ ...@@ -51,4 +51,29 @@
ORDER BY dimension_id ASC, sort_order ASC ORDER BY dimension_id ASC, sort_order ASC
</select> </select>
<!-- 查询同一维度下最大的sort_order -->
<select id="selectMaxSortOrderByDimensionId" resultType="java.lang.Integer">
SELECT IFNULL(MAX(sort_order), 0)
FROM dj_car_life_tag_enum
WHERE dimension_id = #{dimensionId} AND deleted_flag = 'N'
</select>
<!-- 根据名称统计同一维度下枚举数量 -->
<select id="countByEnumName" resultType="int">
SELECT COUNT(1)
FROM dj_car_life_tag_enum
WHERE dimension_id = #{dimensionId} AND enum_name = #{enumName} AND deleted_flag = 'N'
<if test="excludeId != null">
AND id != #{excludeId}
</if>
</select>
<!-- 根据维度ID查询所有枚举值(不分页) -->
<select id="selectByDimensionId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM dj_car_life_tag_enum
WHERE dimension_id = #{dimensionId} AND deleted_flag = 'N'
ORDER BY sort_order ASC
</select>
</mapper> </mapper>
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.BaseServiceTest;
import cn.com.glsx.dj.strategy.dto.*;
import cn.com.glsx.dj.strategy.service.TagCategoryService;
import cn.com.glsx.dj.strategy.service.TagDimensionService;
import cn.com.glsx.dj.strategy.service.TagEnumService;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.List;
/**
* 标签管理 Service 层单元测试
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/17 10:00
*/
@Slf4j
public class TagManageRemoteTest extends BaseServiceTest {
@Resource
private TagCategoryService tagCategoryService;
@Resource
private TagDimensionService tagDimensionService;
@Resource
private TagEnumService tagEnumService;
// ==================== 标签类别 ====================
@Test
public void createCategoryTest() {
TagCategoryCreateReqDTO request = new TagCategoryCreateReqDTO();
request.setCategoryName("单元测试分类" + System.currentTimeMillis());
request.setParentId(0);
request.setCreatedBy("unittest");
TagCategoryRespDTO result = tagCategoryService.createCategory(request);
log.info("创建分类:{}", JSONUtil.toJsonStr(result));
}
@Test
public void updateCategoryTest() {
TagCategoryUpdateReqDTO request = new TagCategoryUpdateReqDTO();
request.setId(1);
request.setCategoryName("单元测试分类-已修改");
request.setUpdatedBy("unittest");
tagCategoryService.updateCategory(request);
log.info("更新分类成功");
}
@Test
public void queryCategoryTreeTest() {
List<TagCategoryTreeRespDTO> result = tagCategoryService.queryCategoryTree();
log.info("分类树:{}", JSONUtil.toJsonStr(result));
}
@Test
public void queryCategoryLeafListTest() {
List<TagCategoryLeafRespDTO> result = tagCategoryService.queryCategoryLeafList();
log.info("叶子分类列表:{}", JSONUtil.toJsonStr(result));
}
@Test
public void queryCategoryWithDimensionsTest() {
TagCategoryDimensionQueryReqDTO request = new TagCategoryDimensionQueryReqDTO();
request.setCategoryCode("INIT_C3");
TagCategoryDimensionRespDTO result = tagCategoryService.queryCategoryWithDimensions(request);
log.info("分类维度及枚举:{}", JSONUtil.toJsonStr(result));
}
// ==================== 标签维度 ====================
@Test
public void createDimensionTest() {
TagDimensionCreateReqDTO request = new TagDimensionCreateReqDTO();
request.setDimensionName("单元测试维度" + System.currentTimeMillis());
request.setCategoryId(4);
request.setCreatedBy("unittest");
tagDimensionService.createDimension(request);
log.info("创建维度成功");
}
@Test
public void queryDimensionTest() {
TagDimensionQueryReqDTO request = new TagDimensionQueryReqDTO();
request.setPageNum(1);
request.setPageSize(10);
PageInfo<TagDimensionRespDTO> result = tagDimensionService.queryDimension(request);
log.info("维度列表:{}", JSONUtil.toJsonStr(result.getList()));
}
@Test
public void queryCategoryOptionsTest() {
List<TagDimensionCategoryOptionsRespDTO> result = tagDimensionService.queryCategoryOptions();
log.info("可选分类列表:{}", JSONUtil.toJsonStr(result));
}
@Test
public void queryDimensionDetailTest() {
TagDimensionDetailRespDTO result = tagDimensionService.queryDimensionDetail(1);
log.info("维度详情:{}", JSONUtil.toJsonStr(result));
}
@Test
public void updateDimensionTest() {
TagDimensionUpdateReqDTO request = new TagDimensionUpdateReqDTO();
request.setId(1);
request.setDimensionName("单元测试维度-已修改");
request.setUpdatedBy("unittest");
tagDimensionService.updateDimension(request);
log.info("更新维度成功");
}
@Test
public void queryDimensionWithEnumsTest() {
TagDimensionEnumQueryReqDTO request = new TagDimensionEnumQueryReqDTO();
request.setDimensionCode("INIT_D12");
TagDimensionEnumRespDTO result = tagDimensionService.queryDimensionWithEnums(request);
log.info("维度及枚举:{}", JSONUtil.toJsonStr(result));
}
// ==================== 标签枚举 ====================
@Test
public void createEnumTest() {
TagEnumCreateReqDTO request = new TagEnumCreateReqDTO();
request.setEnumName("单元测试枚举" + System.currentTimeMillis());
request.setDimensionId(1);
request.setScore(10);
request.setCreatedBy("unittest");
tagEnumService.createEnum(request);
log.info("创建枚举成功");
}
@Test
public void pageEnumTest() {
TagEnumPageReqDTO request = new TagEnumPageReqDTO();
request.setDimensionId(1);
request.setPageNum(1);
request.setPageSize(10);
PageInfo<TagEnumRespDTO> result = tagEnumService.pageEnum(request);
log.info("枚举分页列表:{}", JSONUtil.toJsonStr(result.getList()));
}
@Test
public void updateEnumTest() {
TagEnumUpdateReqDTO request = new TagEnumUpdateReqDTO();
request.setId(1);
request.setScore(99);
request.setUpdatedBy("unittest");
tagEnumService.updateEnum(request);
log.info("更新枚举成功");
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!