Merge branch 'member_dev' of https://gitee.com/CrazyWorld/ruoyi-vue-pro into feature/mall_product

 Conflicts:
	yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java
This commit is contained in:
YunaiV 2023-08-20 09:02:16 +08:00
commit 8191d9e141
25 changed files with 849 additions and 17 deletions

71
sql/mysql/member_tag.sql Normal file
View File

@ -0,0 +1,71 @@
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 '会员标签';
alter table member_user add column tag_ids varchar(255) null 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如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @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
);

View File

@ -36,4 +36,9 @@ public interface ErrorCodeConstants {
ErrorCode SIGN_IN_RECORD_NOT_EXISTS = new ErrorCode(1004005006, "用户签到积分不存在"); ErrorCode SIGN_IN_RECORD_NOT_EXISTS = new ErrorCode(1004005006, "用户签到积分不存在");
//========== 会员标签 1004006000 ==========
ErrorCode TAG_NOT_EXISTS = new ErrorCode(1004006000, "会员标签不存在");
ErrorCode TAG_NAME_EXISTS = new ErrorCode(1004006001, "会员标签已经存在");
} }

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,23 +1,29 @@
package cn.iocoder.yudao.module.member.controller.admin.user; package cn.iocoder.yudao.module.member.controller.admin.user;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.tag.MemberTagService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService; import cn.iocoder.yudao.module.member.service.user.MemberUserService;
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.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@Tag(name = "管理后台 - 会员用户") @Tag(name = "管理后台 - 会员用户")
@RestController @RestController
@ -27,6 +33,8 @@ public class MemberUserController {
@Resource @Resource
private MemberUserService memberUserService; private MemberUserService memberUserService;
@Resource
private MemberTagService memberTagService;
@PutMapping("/update") @PutMapping("/update")
@Operation(summary = "更新会员用户") @Operation(summary = "更新会员用户")
@ -50,7 +58,17 @@ public class MemberUserController {
@PreAuthorize("@ss.hasPermission('member:user:query')") @PreAuthorize("@ss.hasPermission('member:user:query')")
public CommonResult<PageResult<MemberUserRespVO>> getUserPage(@Valid MemberUserPageReqVO pageVO) { public CommonResult<PageResult<MemberUserRespVO>> getUserPage(@Valid MemberUserPageReqVO pageVO) {
PageResult<MemberUserDO> pageResult = memberUserService.getUserPage(pageVO); PageResult<MemberUserDO> pageResult = memberUserService.getUserPage(pageVO);
return success(MemberUserConvert.INSTANCE.convertPage(pageResult));
// 处理会员标签返显
Set<Long> tagIds = pageResult.getList().stream()
.map(MemberUserDO::getTagIds)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
List<MemberTagDO> tags = memberTagService.getTagList(tagIds);
Map<Long, String> tagNameMap = convertMap(tags, MemberTagDO::getId, MemberTagDO::getName);
return success(MemberUserConvert.INSTANCE.convertPage(pageResult, tagNameMap));
} }
} }

View File

@ -7,6 +7,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@ -49,4 +50,7 @@ public class MemberUserBaseVO {
@Schema(description = "会员备注", example = "我是小备注") @Schema(description = "会员备注", example = "我是小备注")
private String mark; private String mark;
@Schema(description = "会员标签")
private List<Long> tagIds;
} }

View File

@ -8,6 +8,7 @@ import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -31,4 +32,7 @@ public class MemberUserPageReqVO extends PageParam {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime; private LocalDateTime[] createTime;
@Schema(description = "会员标签")
private List<Long> tagIds;
} }

View File

@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 会员用户 Response VO") @Schema(description = "管理后台 - 会员用户 Response VO")
@Data @Data
@ -28,4 +29,9 @@ public class MemberUserRespVO extends MemberUserBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime; private LocalDateTime createTime;
// ========== 其它信息 ==========
@Schema(description = "会员标签")
private List<String> tagNames;
} }

View File

@ -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);
}

View File

@ -10,6 +10,9 @@ import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Mapper @Mapper
public interface MemberUserConvert { public interface MemberUserConvert {
@ -28,4 +31,12 @@ public interface MemberUserConvert {
MemberUserRespVO convert03(MemberUserDO bean); MemberUserRespVO convert03(MemberUserDO bean);
default PageResult<MemberUserRespVO> convertPage(PageResult<MemberUserDO> pageResult,
Map<Long, String> tagMap) {
PageResult<MemberUserRespVO> result = convertPage(pageResult);
for (MemberUserRespVO vo : result.getList()) {
vo.setTagNames(convertList(vo.getTagIds(), tagMap::get));
}
return result;
}
} }

View File

@ -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") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MemberTagDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 标签名称
*/
private String name;
}

View File

@ -2,15 +2,18 @@ package cn.iocoder.yudao.module.member.dal.dataobject.user;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import cn.iocoder.yudao.module.system.enums.common.SexEnum; import cn.iocoder.yudao.module.system.enums.common.SexEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* 会员用户 DO * 会员用户 DO
@ -107,6 +110,11 @@ public class MemberUserDO extends TenantBaseDO {
*/ */
private Integer point; private Integer point;
// TODO 积分成长值会员等级等等 /**
* 会员标签列表以逗号分隔
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> tagIds;
// TODO 成长值会员等级等等
} }

View File

@ -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));
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.member.dal.mysql.user; package cn.iocoder.yudao.module.member.dal.mysql.user;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -8,6 +10,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 会员 User Mapper * 会员 User Mapper
@ -27,11 +30,19 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
} }
default PageResult<MemberUserDO> selectPage(MemberUserPageReqVO reqVO) { default PageResult<MemberUserDO> selectPage(MemberUserPageReqVO reqVO) {
String tagIdSql = "";
if (CollUtil.isNotEmpty(reqVO.getTagIds())) {
tagIdSql = reqVO.getTagIds().stream()
.map(tagId -> "FIND_IN_SET(" + tagId + ", tag_ids)")
.collect(Collectors.joining(" OR "));
}
return selectPage(reqVO, new LambdaQueryWrapperX<MemberUserDO>() return selectPage(reqVO, new LambdaQueryWrapperX<MemberUserDO>()
.likeIfPresent(MemberUserDO::getMobile, reqVO.getMobile()) .likeIfPresent(MemberUserDO::getMobile, reqVO.getMobile())
.betweenIfPresent(MemberUserDO::getLoginDate, reqVO.getLoginDate()) .betweenIfPresent(MemberUserDO::getLoginDate, reqVO.getLoginDate())
.likeIfPresent(MemberUserDO::getNickname, reqVO.getNickname()) .likeIfPresent(MemberUserDO::getNickname, reqVO.getNickname())
.betweenIfPresent(MemberUserDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(MemberUserDO::getCreateTime, reqVO.getCreateTime())
.apply(StrUtil.isNotEmpty(tagIdSql), tagIdSql)
.orderByDesc(MemberUserDO::getId)); .orderByDesc(MemberUserDO::getId));
} }

View File

@ -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);
}

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.member.service.tag;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
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) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
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);
}
}

View File

@ -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));
}
}

View File

@ -1,2 +1,3 @@
DELETE FROM "member_user"; DELETE FROM "member_user";
DELETE FROM "member_address"; DELETE FROM "member_address";
DELETE FROM "member_tag";

View File

@ -33,3 +33,15 @@ CREATE TABLE IF NOT EXISTS "member_address" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '用户收件地址'; ) 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 '会员标签';