feat(用户标签): 新增用户标签管理功能
新增用户标签管理模块,包括用户标签的增删改查功能。涉及实体类、服务类、控制器及相关查询、命令类的实现。通过Ab98UserTagApplicationService提供业务逻辑处理,Ab98UserTagController提供RESTful接口,支持用户标签的列表查询、新增、修改和删除操作。
This commit is contained in:
parent
14e7a934de
commit
3ef4c71258
|
@ -0,0 +1,68 @@
|
|||
package com.agileboot.admin.controller.ab98.tag;
|
||||
|
||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.ab98.tag.Ab98UserTagApplicationService;
|
||||
import com.agileboot.domain.ab98.tag.command.AddAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.command.UpdateAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import com.agileboot.domain.ab98.tag.dto.Ab98UserTagDTO;
|
||||
import com.agileboot.domain.ab98.tag.query.SearchAb98UserTagQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/ab98/userTags")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class Ab98UserTagController extends BaseController {
|
||||
|
||||
private final Ab98UserTagApplicationService ab98UserTagApplicationService;
|
||||
|
||||
@Operation(summary = "用户标签列表")
|
||||
@GetMapping
|
||||
public ResponseDTO<PageDTO<Ab98UserTagDTO>> list(SearchAb98UserTagQuery<Ab98UserTagEntity> query) {
|
||||
PageDTO<Ab98UserTagDTO> page = ab98UserTagApplicationService.getAb98UserTagList(query);
|
||||
return ResponseDTO.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增用户标签")
|
||||
@AccessLog(title = "用户标签管理", businessType = BusinessTypeEnum.ADD)
|
||||
@PostMapping
|
||||
public ResponseDTO<Void> add(@Validated @RequestBody AddAb98UserTagCommand command) {
|
||||
ab98UserTagApplicationService.addAb98UserTag(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改用户标签")
|
||||
@AccessLog(title = "用户标签管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PutMapping("/{id}")
|
||||
public ResponseDTO<Void> edit(@PathVariable Long id, @Validated @RequestBody UpdateAb98UserTagCommand command) {
|
||||
command.setTagId(id);
|
||||
ab98UserTagApplicationService.updateAb98UserTag(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除用户标签")
|
||||
@AccessLog(title = "用户标签管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
|
||||
ab98UserTagApplicationService.deleteAb98UserTag(new BulkOperationCommand<>(ids));
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.agileboot.domain.ab98.tag;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.ab98.tag.command.AddAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.command.UpdateAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagService;
|
||||
import com.agileboot.domain.ab98.tag.dto.Ab98UserTagDTO;
|
||||
import com.agileboot.domain.ab98.tag.model.Ab98UserTagModel;
|
||||
import com.agileboot.domain.ab98.tag.model.Ab98UserTagModelFactory;
|
||||
import com.agileboot.domain.ab98.tag.query.SearchAb98UserTagQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class Ab98UserTagApplicationService {
|
||||
private final Ab98UserTagService ab98UserTagService;
|
||||
private final Ab98UserTagModelFactory ab98UserTagModelFactory;
|
||||
|
||||
public PageDTO<Ab98UserTagDTO> getAb98UserTagList(SearchAb98UserTagQuery<Ab98UserTagEntity> query) {
|
||||
Page<Ab98UserTagEntity> page = ab98UserTagService.getUserTagList(query);
|
||||
List<Ab98UserTagDTO> dtoList = page.getRecords().stream()
|
||||
.map(Ab98UserTagDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
return new PageDTO<>(dtoList, page.getTotal());
|
||||
}
|
||||
|
||||
public void addAb98UserTag(AddAb98UserTagCommand command) {
|
||||
Ab98UserTagModel model = ab98UserTagModelFactory.create();
|
||||
model.loadAddCommand(command);
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void updateAb98UserTag(UpdateAb98UserTagCommand command) {
|
||||
Ab98UserTagModel model = ab98UserTagModelFactory.loadById(command.getTagId());
|
||||
model.loadUpdateCommand(command);
|
||||
model.updateById();
|
||||
}
|
||||
|
||||
public void deleteAb98UserTag(BulkOperationCommand<Long> command) {
|
||||
for (Long tagId : command.getIds()) {
|
||||
Ab98UserTagModel model = ab98UserTagModelFactory.loadById(tagId);
|
||||
model.deleteById();
|
||||
}
|
||||
}
|
||||
|
||||
public Ab98UserTagEntity getFirstEnabledTag() {
|
||||
return ab98UserTagService.getFirstEnabledTag();
|
||||
}
|
||||
|
||||
public Ab98UserTagEntity getByTagId(Long tagId) {
|
||||
return ab98UserTagService.getByTagId(tagId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.agileboot.domain.ab98.tag.command;
|
||||
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class AddAb98UserTagCommand extends Ab98UserTagEntity {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.agileboot.domain.ab98.tag.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateAb98UserTagCommand extends AddAb98UserTagCommand {
|
||||
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long tagId;
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.agileboot.domain.ab98.tag.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户标签表
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-22
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("ab98_user_tag")
|
||||
@ApiModel(value = "Ab98UserTagEntity对象", description = "用户标签表")
|
||||
public class Ab98UserTagEntity extends BaseEntity<Ab98UserTagEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("标签ID")
|
||||
@TableId(value = "tag_id", type = IdType.AUTO)
|
||||
private Long tagId;
|
||||
|
||||
@ApiModelProperty("关联用户ID")
|
||||
@TableField("ab98_user_id")
|
||||
private Long ab98UserId;
|
||||
|
||||
@ApiModelProperty("标签名称")
|
||||
@TableField("tag_name")
|
||||
private String tagName;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.tagId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.agileboot.domain.ab98.tag.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户标签表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-22
|
||||
*/
|
||||
public interface Ab98UserTagMapper extends BaseMapper<Ab98UserTagEntity> {
|
||||
@Select("SELECT tag_id, ab98_user_id, tag_name " +
|
||||
"FROM ab98_user_tag " +
|
||||
"${ew.customSqlSegment}")
|
||||
Page<Ab98UserTagEntity> getUserTagList(
|
||||
Page<Ab98UserTagEntity> page,
|
||||
@Param(Constants.WRAPPER) Wrapper<Ab98UserTagEntity> queryWrapper
|
||||
);
|
||||
|
||||
@Select("SELECT * " +
|
||||
"FROM ab98_user_tag " +
|
||||
"ORDER BY create_time DESC")
|
||||
List<Ab98UserTagEntity> selectAll();
|
||||
|
||||
@Select("SELECT * FROM ab98_user_tag WHERE ab98_user_id = #{userId}")
|
||||
List<Ab98UserTagEntity> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("SELECT * FROM ab98_user_tag WHERE tag_id = #{tagId} LIMIT 1")
|
||||
Ab98UserTagEntity selectByTagId(@Param("tagId") Long tagId);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.agileboot.domain.ab98.tag.db;
|
||||
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户标签表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-22
|
||||
*/
|
||||
public interface Ab98UserTagService extends IService<Ab98UserTagEntity> {
|
||||
Page<Ab98UserTagEntity> getUserTagList(AbstractPageQuery<Ab98UserTagEntity> query);
|
||||
|
||||
List<Ab98UserTagEntity> selectAll();
|
||||
|
||||
Ab98UserTagEntity getFirstEnabledTag();
|
||||
|
||||
Ab98UserTagEntity getByTagId(Long tagId);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.agileboot.domain.ab98.tag.db;
|
||||
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户标签表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-22
|
||||
*/
|
||||
@Service
|
||||
public class Ab98UserTagServiceImpl extends ServiceImpl<Ab98UserTagMapper, Ab98UserTagEntity> implements Ab98UserTagService {
|
||||
|
||||
@Override
|
||||
public Page<Ab98UserTagEntity> getUserTagList(AbstractPageQuery<Ab98UserTagEntity> query) {
|
||||
return this.page(query.toPage(), query.toQueryWrapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ab98UserTagEntity> selectAll() {
|
||||
return baseMapper.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ab98UserTagEntity getFirstEnabledTag() {
|
||||
LambdaQueryWrapper<Ab98UserTagEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Ab98UserTagEntity::getDeleted, false)
|
||||
.orderByDesc(Ab98UserTagEntity::getCreateTime);
|
||||
return getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ab98UserTagEntity getByTagId(Long tagId) {
|
||||
return baseMapper.selectByTagId(tagId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.ab98.tag.dto;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@ExcelSheet(name = "AB98用户标签列表")
|
||||
@Data
|
||||
public class Ab98UserTagDTO {
|
||||
|
||||
public Ab98UserTagDTO(Ab98UserTagEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ExcelColumn(name = "标签ID")
|
||||
private Long tagId;
|
||||
|
||||
@ExcelColumn(name = "关联用户ID")
|
||||
private Long ab98UserId;
|
||||
|
||||
@ExcelColumn(name = "标签名称")
|
||||
private String tagName;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.agileboot.domain.ab98.tag.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.domain.ab98.tag.command.AddAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.command.UpdateAb98UserTagCommand;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Ab98UserTagModel extends Ab98UserTagEntity {
|
||||
|
||||
private Ab98UserTagService ab98UserTagService;
|
||||
|
||||
public Ab98UserTagModel(Ab98UserTagEntity entity, Ab98UserTagService ab98UserTagService) {
|
||||
this(ab98UserTagService);
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public Ab98UserTagModel(Ab98UserTagService ab98UserTagService) {
|
||||
this.ab98UserTagService = ab98UserTagService;
|
||||
}
|
||||
|
||||
public void loadAddCommand(AddAb98UserTagCommand command) {
|
||||
if (command != null) {
|
||||
BeanUtil.copyProperties(command, this, "id");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUpdateCommand(UpdateAb98UserTagCommand command) {
|
||||
if (command != null) {
|
||||
loadAddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.ab98.tag.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagEntity;
|
||||
import com.agileboot.domain.ab98.tag.db.Ab98UserTagService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class Ab98UserTagModelFactory {
|
||||
|
||||
private final Ab98UserTagService ab98UserTagService;
|
||||
|
||||
public Ab98UserTagModel loadById(Long tagId) {
|
||||
Ab98UserTagEntity entity = ab98UserTagService.getById(tagId);
|
||||
if (entity == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, tagId, "用户标签");
|
||||
}
|
||||
return new Ab98UserTagModel(entity, ab98UserTagService);
|
||||
}
|
||||
|
||||
public Ab98UserTagModel create() {
|
||||
return new Ab98UserTagModel(ab98UserTagService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.agileboot.domain.ab98.tag.query;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchAb98UserTagQuery<T> extends AbstractPageQuery<T> {
|
||||
|
||||
private Long ab98UserId;
|
||||
private String tagName;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
queryWrapper
|
||||
.eq(ab98UserId != null, "ab98_user_id", ab98UserId)
|
||||
.like(StrUtil.isNotEmpty(tagName), "tag_name", tagName)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
||||
this.timeRangeColumn = "create_time";
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.agileboot.domain.ab98.tag.db.Ab98UserTagMapper">
|
||||
|
||||
</mapper>
|
|
@ -61,7 +61,7 @@ public class CodeGenerator {
|
|||
//生成的类 放在orm子模块下的/target/generated-code目录底下
|
||||
.module("/agileboot-orm/target/generated-code")
|
||||
.parentPackage("com.agileboot")
|
||||
.tableName("cabinet_mainboard")
|
||||
.tableName("ab98_user_tag")
|
||||
// 决定是否继承基类
|
||||
.isExtendsFromBaseEntity(true)
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue