parent
a4e2cacc46
commit
9b6e2114c7
|
@ -0,0 +1,70 @@
|
|||
create table member_tag
|
||||
(
|
||||
id bigint auto_increment comment '编号'
|
||||
primary key,
|
||||
name varchar(30) default '' not null comment '标签名称',
|
||||
creator varchar(64) default '' null comment '创建者',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
updater varchar(64) default '' null comment '更新者',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
deleted bit default b'0' not null comment '是否删除',
|
||||
tenant_id bigint default 0 not null comment '租户编号'
|
||||
)
|
||||
comment '会员标签';
|
||||
|
||||
|
||||
-- 菜单 SQL
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status, component_name
|
||||
)
|
||||
VALUES (
|
||||
'会员标签管理', '', 2, 3, 2262,
|
||||
'tag', '', 'member/tag/index', 0, 'MemberTag'
|
||||
);
|
||||
|
||||
-- 按钮父菜单ID
|
||||
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
|
||||
SELECT @parentId := LAST_INSERT_ID();
|
||||
|
||||
-- 按钮 SQL
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status
|
||||
)
|
||||
VALUES (
|
||||
'会员标签查询', 'member:tag:query', 3, 1, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status
|
||||
)
|
||||
VALUES (
|
||||
'会员标签创建', 'member:tag:create', 3, 2, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status
|
||||
)
|
||||
VALUES (
|
||||
'会员标签更新', 'member:tag:update', 3, 3, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status
|
||||
)
|
||||
VALUES (
|
||||
'会员标签删除', 'member:tag:delete', 3, 4, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
INSERT INTO system_menu(
|
||||
name, permission, type, sort, parent_id,
|
||||
path, icon, component, status
|
||||
)
|
||||
VALUES (
|
||||
'会员标签导出', 'member:tag:export', 3, 5, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
|
@ -34,4 +34,9 @@ public interface ErrorCodeConstants {
|
|||
|
||||
ErrorCode SIGN_IN_RECORD_NOT_EXISTS = new ErrorCode(1004005006, "用户签到积分不存在");
|
||||
|
||||
|
||||
//========== 会员标签 1004006000 ==========
|
||||
ErrorCode TAG_NOT_EXISTS = new ErrorCode(1004006000, "会员标签不存在");
|
||||
ErrorCode TAG_NAME_EXISTS = new ErrorCode(1004006001, "会员标签已经存在");
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.*;
|
||||
import cn.iocoder.yudao.module.member.convert.tag.MemberTagConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
import cn.iocoder.yudao.module.member.service.tag.MemberTagService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - 会员标签")
|
||||
@RestController
|
||||
@RequestMapping("/member/tag")
|
||||
@Validated
|
||||
public class MemberTagController {
|
||||
|
||||
@Resource
|
||||
private MemberTagService tagService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建会员标签")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:create')")
|
||||
public CommonResult<Long> createTag(@Valid @RequestBody MemberTagCreateReqVO createReqVO) {
|
||||
return success(tagService.createTag(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新会员标签")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:update')")
|
||||
public CommonResult<Boolean> updateTag(@Valid @RequestBody MemberTagUpdateReqVO updateReqVO) {
|
||||
tagService.updateTag(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除会员标签")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:delete')")
|
||||
public CommonResult<Boolean> deleteTag(@RequestParam("id") Long id) {
|
||||
tagService.deleteTag(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得会员标签")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:query')")
|
||||
public CommonResult<MemberTagRespVO> getMemberTag(@RequestParam("id") Long id) {
|
||||
MemberTagDO tag = tagService.getTag(id);
|
||||
return success(MemberTagConvert.INSTANCE.convert(tag));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得会员标签列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:query')")
|
||||
public CommonResult<List<MemberTagRespVO>> getMemberTagList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<MemberTagDO> list = tagService.getTagList(ids);
|
||||
return success(MemberTagConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得会员标签分页")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:query')")
|
||||
public CommonResult<PageResult<MemberTagRespVO>> getTagPage(@Valid MemberTagPageReqVO pageVO) {
|
||||
PageResult<MemberTagDO> pageResult = tagService.getTagPage(pageVO);
|
||||
return success(MemberTagConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出会员标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('member:tag:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportTagExcel(@Valid MemberTagExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<MemberTagDO> list = tagService.getTagList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<MemberTagExcelVO> datas = MemberTagConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "会员标签.xls", "数据", MemberTagExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 会员标签 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class MemberTagBaseVO {
|
||||
|
||||
@Schema(description = "标签名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotNull(message = "标签名称不能为空")
|
||||
private String name;
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 会员标签创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MemberTagCreateReqVO extends MemberTagBaseVO {
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 会员标签 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class MemberTagExcelVO {
|
||||
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("标签名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 会员标签 Excel 导出 Request VO,参数和 MemberTagPageReqVO 是一致的")
|
||||
@Data
|
||||
public class MemberTagExportReqVO {
|
||||
|
||||
@Schema(description = "标签名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 会员标签分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MemberTagPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "标签名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 会员标签 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MemberTagRespVO extends MemberTagBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "907")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 会员标签更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MemberTagUpdateReqVO extends MemberTagBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "907")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.yudao.module.member.convert.tag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.*;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
|
||||
/**
|
||||
* 会员标签 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface MemberTagConvert {
|
||||
|
||||
MemberTagConvert INSTANCE = Mappers.getMapper(MemberTagConvert.class);
|
||||
|
||||
MemberTagDO convert(MemberTagCreateReqVO bean);
|
||||
|
||||
MemberTagDO convert(MemberTagUpdateReqVO bean);
|
||||
|
||||
MemberTagRespVO convert(MemberTagDO bean);
|
||||
|
||||
List<MemberTagRespVO> convertList(List<MemberTagDO> list);
|
||||
|
||||
PageResult<MemberTagRespVO> convertPage(PageResult<MemberTagDO> page);
|
||||
|
||||
List<MemberTagExcelVO> convertList02(List<MemberTagDO> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.yudao.module.member.dal.dataobject.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 会员标签 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("member_tag")
|
||||
@KeySequence("member_tag_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MemberTagDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package cn.iocoder.yudao.module.member.dal.mysql.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagExportReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员标签 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface MemberTagMapper extends BaseMapperX<MemberTagDO> {
|
||||
|
||||
default PageResult<MemberTagDO> selectPage(MemberTagPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<MemberTagDO>()
|
||||
.likeIfPresent(MemberTagDO::getName, reqVO.getName())
|
||||
.betweenIfPresent(MemberTagDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(MemberTagDO::getId));
|
||||
}
|
||||
|
||||
default List<MemberTagDO> selectList(MemberTagExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<MemberTagDO>()
|
||||
.likeIfPresent(MemberTagDO::getName, reqVO.getName())
|
||||
.betweenIfPresent(MemberTagDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(MemberTagDO::getId));
|
||||
}
|
||||
|
||||
default boolean exists(Long id, String name) {
|
||||
return exists(new LambdaQueryWrapperX<MemberTagDO>()
|
||||
.neIfPresent(MemberTagDO::getId, id)
|
||||
.eq(MemberTagDO::getName, name));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package cn.iocoder.yudao.module.member.service.tag;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.*;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 会员标签 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface MemberTagService {
|
||||
|
||||
/**
|
||||
* 创建会员标签
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createTag(@Valid MemberTagCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新会员标签
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTag(@Valid MemberTagUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除会员标签
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTag(Long id);
|
||||
|
||||
/**
|
||||
* 获得会员标签
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 会员标签
|
||||
*/
|
||||
MemberTagDO getTag(Long id);
|
||||
|
||||
/**
|
||||
* 获得会员标签列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 会员标签列表
|
||||
*/
|
||||
List<MemberTagDO> getTagList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得会员标签分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 会员标签分页
|
||||
*/
|
||||
PageResult<MemberTagDO> getTagPage(MemberTagPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得会员标签列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 会员标签列表
|
||||
*/
|
||||
List<MemberTagDO> getTagList(MemberTagExportReqVO exportReqVO);
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package cn.iocoder.yudao.module.member.service.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagCreateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagExportReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.tag.MemberTagConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.tag.MemberTagMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.TAG_NAME_EXISTS;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.TAG_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 会员标签 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class MemberTagServiceImpl implements MemberTagService {
|
||||
|
||||
@Resource
|
||||
private MemberTagMapper tagMapper;
|
||||
|
||||
@Override
|
||||
public Long createTag(MemberTagCreateReqVO createReqVO) {
|
||||
// 校验名称唯一
|
||||
validateTagNameUnique(null, createReqVO.getName());
|
||||
// 插入
|
||||
MemberTagDO tag = MemberTagConvert.INSTANCE.convert(createReqVO);
|
||||
tagMapper.insert(tag);
|
||||
// 返回
|
||||
return tag.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTag(MemberTagUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTagExists(updateReqVO.getId());
|
||||
// 校验名称唯一
|
||||
validateTagNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
||||
// 更新
|
||||
MemberTagDO updateObj = MemberTagConvert.INSTANCE.convert(updateReqVO);
|
||||
tagMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTag(Long id) {
|
||||
// 校验存在
|
||||
validateTagExists(id);
|
||||
// 删除
|
||||
tagMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateTagExists(Long id) {
|
||||
if (tagMapper.selectById(id) == null) {
|
||||
throw exception(TAG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTagNameUnique(Long id, String name) {
|
||||
boolean exists = tagMapper.exists(id, name);
|
||||
if (exists) {
|
||||
throw exception(TAG_NAME_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemberTagDO getTag(Long id) {
|
||||
return tagMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MemberTagDO> getTagList(Collection<Long> ids) {
|
||||
return tagMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MemberTagDO> getTagPage(MemberTagPageReqVO pageReqVO) {
|
||||
return tagMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MemberTagDO> getTagList(MemberTagExportReqVO exportReqVO) {
|
||||
return tagMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package cn.iocoder.yudao.module.member.service.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagCreateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagExportReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.tag.MemberTagMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.TAG_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link MemberTagServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(MemberTagServiceImpl.class)
|
||||
public class MemberTagServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private MemberTagServiceImpl tagService;
|
||||
|
||||
@Resource
|
||||
private MemberTagMapper tagMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateTag_success() {
|
||||
// 准备参数
|
||||
MemberTagCreateReqVO reqVO = randomPojo(MemberTagCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long tagId = tagService.createTag(reqVO);
|
||||
// 断言
|
||||
assertNotNull(tagId);
|
||||
// 校验记录的属性是否正确
|
||||
MemberTagDO tag = tagMapper.selectById(tagId);
|
||||
assertPojoEquals(reqVO, tag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTag_success() {
|
||||
// mock 数据
|
||||
MemberTagDO dbTag = randomPojo(MemberTagDO.class);
|
||||
tagMapper.insert(dbTag);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
MemberTagUpdateReqVO reqVO = randomPojo(MemberTagUpdateReqVO.class, o -> {
|
||||
o.setId(dbTag.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
tagService.updateTag(reqVO);
|
||||
// 校验是否更新正确
|
||||
MemberTagDO tag = tagMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, tag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTag_notExists() {
|
||||
// 准备参数
|
||||
MemberTagUpdateReqVO reqVO = randomPojo(MemberTagUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> tagService.updateTag(reqVO), TAG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTag_success() {
|
||||
// mock 数据
|
||||
MemberTagDO dbTag = randomPojo(MemberTagDO.class);
|
||||
tagMapper.insert(dbTag);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbTag.getId();
|
||||
|
||||
// 调用
|
||||
tagService.deleteTag(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(tagMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTag_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> tagService.deleteTag(id), TAG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTagPage() {
|
||||
// mock 数据
|
||||
MemberTagDO dbTag = randomPojo(MemberTagDO.class, o -> { // 等会查询到
|
||||
o.setName("test");
|
||||
o.setCreateTime(buildTime(2023, 2, 18));
|
||||
});
|
||||
tagMapper.insert(dbTag);
|
||||
// 测试 name 不匹配
|
||||
tagMapper.insert(cloneIgnoreId(dbTag, o -> o.setName("ne")));
|
||||
// 测试 createTime 不匹配
|
||||
tagMapper.insert(cloneIgnoreId(dbTag, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
MemberTagPageReqVO reqVO = new MemberTagPageReqVO();
|
||||
reqVO.setName("test");
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<MemberTagDO> pageResult = tagService.getTagPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbTag, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTagList() {
|
||||
// mock 数据
|
||||
MemberTagDO dbTag = randomPojo(MemberTagDO.class, o -> { // 等会查询到
|
||||
o.setName("test");
|
||||
o.setCreateTime(buildTime(2023, 2, 18));
|
||||
});
|
||||
tagMapper.insert(dbTag);
|
||||
// 测试 name 不匹配
|
||||
tagMapper.insert(cloneIgnoreId(dbTag, o -> o.setName("ne")));
|
||||
// 测试 createTime 不匹配
|
||||
tagMapper.insert(cloneIgnoreId(dbTag, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
MemberTagExportReqVO reqVO = new MemberTagExportReqVO();
|
||||
reqVO.setName("test");
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
List<MemberTagDO> list = tagService.getTagList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbTag, list.get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
DELETE FROM "member_user";
|
||||
DELETE FROM "member_address";
|
||||
DELETE FROM "member_tag";
|
|
@ -33,3 +33,15 @@ CREATE TABLE IF NOT EXISTS "member_address" (
|
|||
PRIMARY KEY ("id")
|
||||
) COMMENT '用户收件地址';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "member_tag"
|
||||
(
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar NOT NULL,
|
||||
"creator" varchar DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL default '0',
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '会员标签';
|
Loading…
Reference in New Issue