add Tag useCount
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.imyeyu.api.annotation.MultilingualField;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
@@ -40,4 +41,9 @@ public class Tag extends UUIDEntity {
|
||||
/// 中文名称
|
||||
@Transient
|
||||
protected String zhCN;
|
||||
|
||||
/// 当前查询业务下的使用量
|
||||
@Transient
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
protected Long useCount;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Tag;
|
||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -33,5 +35,23 @@ public interface TagMapper extends BaseMapper<Tag, String> {
|
||||
/// @return 标签列表
|
||||
List<Tag> selectByOwnerAndKeyword(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("keyword") String keyword, @Param("offset") long offset, @Param("limit") long limit);
|
||||
|
||||
/// 按归属和名称关键词分页查询标签,并统计指定业务的使用量
|
||||
///
|
||||
/// @param ownerType 归属类型
|
||||
/// @param ownerId 归属 ID
|
||||
/// @param keyword 名称关键词
|
||||
/// @param bizType 业务类型
|
||||
/// @param offset 分页偏移量
|
||||
/// @param limit 分页数量
|
||||
/// @return 标签列表
|
||||
List<Tag> selectByOwnerAndKeywordWithUseCount(@Param("page") Page<Tag> page, @Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("keyword") String keyword, @Param("bizType") TagApply.BizType bizType, @Param("offset") long offset, @Param("limit") long limit);
|
||||
|
||||
/// 查询指定标签在指定业务下的使用量
|
||||
///
|
||||
/// @param tagId 标签 ID
|
||||
/// @param bizType 业务类型
|
||||
/// @return 使用量
|
||||
long countUseByTagIdAndBizType(@Param("tagId") String tagId, @Param("bizType") TagApply.BizType bizType);
|
||||
|
||||
Tag selectByOwnerAndZhCN(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("zhCN") String zhCN);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,23 @@ public interface TagService extends BaseService<Tag, String> {
|
||||
/// @return 标签分页
|
||||
PageResult<Tag> pageByOwnerAndKeyword(Page<Tag> page, Tag.OwnerType ownerType, String ownerId, String keyword);
|
||||
|
||||
/// 按归属和名称关键词分页查询标签,并按指定业务的使用量排序
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @param ownerType 归属类型
|
||||
/// @param ownerId 归属 ID
|
||||
/// @param keyword 名称关键词
|
||||
/// @param bizType 业务类型
|
||||
/// @return 标签分页
|
||||
PageResult<Tag> pageByOwnerAndKeywordWithUseCount(Page<Tag> page, Tag.OwnerType ownerType, String ownerId, String keyword, TagApply.BizType bizType);
|
||||
|
||||
/// 查询指定标签在指定业务下的使用量
|
||||
///
|
||||
/// @param tagId 标签 ID
|
||||
/// @param bizType 业务类型
|
||||
/// @return 使用量
|
||||
long countUseByTagIdAndBizType(String tagId, TagApply.BizType bizType);
|
||||
|
||||
/// 按业务查询标签列表
|
||||
///
|
||||
/// @param bizType 业务类型
|
||||
|
||||
+16
@@ -7,6 +7,7 @@ import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.TagMapper;
|
||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||
import com.imyeyu.api.modules.common.service.TagService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
@@ -82,6 +83,21 @@ public class TagServiceImplement extends AbstractEntityService<Tag, String> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Tag> pageByOwnerAndKeywordWithUseCount(Page<Tag> page, Tag.OwnerType ownerType, String ownerId, String keyword, TagApply.BizType bizType) {
|
||||
PageResult<Tag> result = new PageResult<>();
|
||||
result.setTotal(TimiJava.isNotEmpty(keyword)
|
||||
? mapper.countByOwnerAndKeyword(ownerType, ownerId, keyword)
|
||||
: mapper.countByPage(page));
|
||||
result.setList(mapper.selectByOwnerAndKeywordWithUseCount(page, ownerType, ownerId, keyword, bizType, page.getOffset(), page.getLimit()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countUseByTagIdAndBizType(String tagId, TagApply.BizType bizType) {
|
||||
return mapper.countUseByTagIdAndBizType(tagId, bizType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listByBizType(TagApply.BizType bizType, String bizId) {
|
||||
return listByIdList(listApply(bizType, bizId).stream().map(TagApply::getTagId).toList());
|
||||
|
||||
@@ -50,18 +50,21 @@ public class GaoTagController {
|
||||
@PostMapping("/list")
|
||||
public PageResult<Tag> list(@RequestBody Page<Tag> page) {
|
||||
TimiException.required(page, "未找到分页参数");
|
||||
String ownerId = null;
|
||||
page.setEqualsExample(TimiJava.defaultIfNull(page.getEqualsExample(), new Tag()));
|
||||
page.getEqualsExample().setOwnerType(Tag.OwnerType.GAO_STORE);
|
||||
String ownerId = page.getEqualsExample().getOwnerId();
|
||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||
ownerId = storeService.getBelongIdByRequiredLoginUserId();
|
||||
page.getEqualsExample().setOwnerId(ownerId);
|
||||
}
|
||||
String keyword = page.getLikesExample() == null ? null : page.getLikesExample().getName();
|
||||
if (TimiJava.isNotEmpty(keyword)) {
|
||||
return service.pageByOwnerAndKeyword(page, Tag.OwnerType.GAO_STORE, ownerId, keyword.trim());
|
||||
}
|
||||
return service.page(page);
|
||||
return service.pageByOwnerAndKeywordWithUseCount(
|
||||
page,
|
||||
Tag.OwnerType.GAO_STORE,
|
||||
ownerId,
|
||||
TimiJava.isNotEmpty(keyword) ? keyword.trim() : null,
|
||||
TagApply.BizType.GAO_CUSTOMER
|
||||
);
|
||||
}
|
||||
|
||||
/// 查询标签详情
|
||||
@@ -73,7 +76,11 @@ public class GaoTagController {
|
||||
@RequireCorePermission(CorePermissionCode.TAG_READ)
|
||||
@PostMapping("/detail")
|
||||
public Tag detail(@RequestParam String id) {
|
||||
return service.get(id);
|
||||
Tag tag = service.get(id);
|
||||
if (tag != null) {
|
||||
tag.setUseCount(service.countUseByTagIdAndBizType(id, TagApply.BizType.GAO_CUSTOMER));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/// 创建标签
|
||||
|
||||
Reference in New Issue
Block a user