code review:积分模块的实现

This commit is contained in:
YunaiV 2023-08-11 23:49:20 +08:00
parent 4177071758
commit be2ee905df
36 changed files with 293 additions and 457 deletions

View File

@ -29,7 +29,7 @@ public interface MemberUserApi {
* @param ids 用户编号的数组
* @return 用户信息们
*/
List<MemberUserRespDTO> getUsers(Collection<Long> ids);
List<MemberUserRespDTO> getUserList(Collection<Long> ids);
/**
* 获得会员用户 Map
@ -38,7 +38,7 @@ public interface MemberUserApi {
* @return 会员用户 Map
*/
default Map<Long, MemberUserRespDTO> getUserMap(Collection<Long> ids) {
return convertMap(getUsers(ids), MemberUserRespDTO::getId);
return convertMap(getUserList(ids), MemberUserRespDTO::getId);
}
/**

View File

@ -30,7 +30,7 @@ public class MemberUserApiImpl implements MemberUserApi {
}
@Override
public List<MemberUserRespDTO> getUsers(Collection<Long> ids) {
public List<MemberUserRespDTO> getUserList(Collection<Long> ids) {
return UserConvert.INSTANCE.convertList2(userService.getUserList(ids));
}

View File

@ -17,6 +17,7 @@ import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
// TODO @xiaqingurl 使用 member 作为前缀
@Tag(name = "管理后台 - 会员积分设置")
@RestController
@RequestMapping("/point/config")

View File

@ -8,24 +8,24 @@ import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPoi
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordRespVO;
import cn.iocoder.yudao.module.member.convert.point.MemberPointRecordConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
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.convertSet;
// TODO @xiaqingurl 使用 member 作为前缀
@Tag(name = "管理后台 - 用户积分记录")
@RestController
@RequestMapping("/point/record")
@ -33,35 +33,25 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class MemberPointRecordController {
@Resource
private MemberPointRecordService recordService;
private MemberPointRecordService pointRecordService;
@Resource
MemberUserApi memberUserApi;
private MemberUserApi memberUserApi;
@GetMapping("/page")
@Operation(summary = "获得用户积分记录分页")
@PreAuthorize("@ss.hasPermission('point:record:query')")
public CommonResult <PageResult <MemberPointRecordRespVO>> getRecordPage(@Valid MemberPointRecordPageReqVO pageVO) {
//根据用户昵称查询出用户ids
List <Long> userIds = null;
if (StringUtils.isNotBlank(pageVO.getNickName())) {
List <MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageVO.getNickName());
//如果查询用户结果为空直接返回无需继续查询
if (CollectionUtils.isEmpty(users)) {
return success(new PageResult <>());
}
userIds=users.stream().map(user->user.getId()).collect(Collectors.toList());
pageVO.setUserIds(userIds);
public CommonResult<PageResult<MemberPointRecordRespVO>> getRecordPage(@Valid MemberPointRecordPageReqVO pageVO) {
// 执行分页查询
PageResult<MemberPointRecordDO> pageResult = pointRecordService.getRecordPage(pageVO);
if (CollectionUtils.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
PageResult <MemberPointRecordDO> pageResult = recordService.getRecordPage(pageVO);
//根据查询的userId转换成nickName
List <MemberPointRecordDO> result = pageResult.getList();
List <MemberUserRespDTO> users = null;
if (!CollectionUtils.isEmpty(result)) {
List <Long> ids = result.stream().map(user -> user.getUserId()).collect(Collectors.toList());
users = memberUserApi.getUsers(ids);
}
return success(MemberPointRecordConvert.INSTANCE.convertPage(pageResult,users));
// 拼接结果返回
List<MemberUserRespDTO> users = memberUserApi.getUserList(
convertSet(pageResult.getList(), MemberPointRecordDO::getUserId));
return success(MemberPointRecordConvert.INSTANCE.convertPage(pageResult, users));
}
}

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.member.controller.admin.point.vo.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
* 会员积分配置 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
@ -12,18 +10,18 @@ import java.math.BigDecimal;
@Data
public class MemberPointConfigBaseVO {
private Long id;
// TODO @xiaqing参数校验注解
@Schema(description = "积分抵扣开关", required = true, example = "true")
@Schema(description = "积分抵扣开关", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean tradeDeductEnable;
@Schema(description = "积分抵扣,单位:分", example = "13506")
@Schema(description = "积分抵扣,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "13506")
private Integer tradeDeductUnitPrice;
@Schema(description = "积分抵扣最大值", example = "32428")
@Schema(description = "积分抵扣最大值", requiredMode = Schema.RequiredMode.REQUIRED, example = "32428")
private Integer tradeDeductMaxPrice;
@Schema(description = "1 元赠送多少分")
@Schema(description = "1 元赠送多少分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer tradeGivePoint;
}

View File

@ -10,4 +10,8 @@ import lombok.ToString;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MemberPointConfigRespVO extends MemberPointConfigBaseVO {
@Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
}

View File

@ -1,56 +0,0 @@
package cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 用户积分记录 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class MemberPointRecordBaseVO {
@Schema(description = "业务编码", example = "22706")
@NotNull(message = "业务编码不能为空")
private String bizId;
@Schema(description = "业务类型", example = "1")
@NotNull(message = "业务类型不能为空")
private String bizType;
@Schema(description = "积分标题")
@NotNull(message = "积分标题不能为空")
private String title;
@Schema(description = "积分描述", example = "你猜")
private String description;
@Schema(description = "积分")
@NotNull(message = "操作积分不能为空")
private Integer point;
@Schema(description = "变动后的积分", requiredMode = Schema.RequiredMode.REQUIRED)
// @NotNull(message = "变动后的积分不能为空")
private Integer totalPoint;
@Schema(description = "状态1-订单创建2-冻结期3-完成4-失效(订单退款) ", example = "1")
@NotNull(message = "积分状态不能为空")
private Integer status;
@Schema(description = "冻结时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotNull(message = "冻结时间不能为空")
private LocalDateTime freezingTime;
@Schema(description = "解冻时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotNull(message = "解冻时间不能为空")
private LocalDateTime thawingTime;
}

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.util.List;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 用户积分记录分页 Request VO")
@Data
@ -13,19 +13,15 @@ import java.util.List;
public class MemberPointRecordPageReqVO extends PageParam {
@Schema(description = "用户昵称", example = "张三")
private String nickName;
//用户id集合用户将nickName查询转换成user_ids查询
private List<Long> userIds;
private String nickname;
@Schema(description = "业务类型", example = "1")
private String bizType;
@Schema(description = "积分标题")
@Schema(description = "积分标题", example = "呵呵")
private String title;
@Schema(description = "状态1-订单创建2-冻结期3-完成4-失效(订单退款) ", example = "1")
@Schema(description = "积分状态", example = "1")
private Integer status;
}

View File

@ -2,21 +2,56 @@ package cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 用户积分记录 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MemberPointRecordRespVO extends MemberPointRecordBaseVO {
public class MemberPointRecordRespVO {
@Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "31457")
private Long id;
@Schema(description = "发生时间")
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userId;
@Schema(description = "昵称", example = "张三")
private String nickname;
@Schema(description = "业务编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "22706")
private String bizId;
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String bizType;
@Schema(description = "积分标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "你猜")
private String title;
@Schema(description = "积分描述", example = "你猜")
private String description;
@Schema(description = "积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer point;
@Schema(description = "变动后的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
private Integer totalPoint;
@Schema(description = "积分状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "冻结时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime freezingTime;
@Schema(description = "解冻时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime thawingTime;
@Schema(description = "发生时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
//昵称
private String nickName;
}

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.module.member.controller.admin.signin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.convert.signin.MemberSignInConfigConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO;
import cn.iocoder.yudao.module.member.service.signin.MemberSignInConfigService;
@ -17,11 +16,11 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
// TODO @xiaqingurl 使用 member 作为前缀
@Tag(name = "管理后台 - 积分签到规则")
@RestController
@RequestMapping("/point/sign-in-config")
@ -29,20 +28,20 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class MemberSignInConfigController {
@Resource
private MemberSignInConfigService memberSignInConfigService;
private MemberSignInConfigService signInConfigService;
@PostMapping("/create")
@Operation(summary = "创建积分签到规则")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:create')")
public CommonResult<Integer> createSignInConfig(@Valid @RequestBody MemberSignInConfigCreateReqVO createReqVO) {
return success(memberSignInConfigService.createSignInConfig(createReqVO));
public CommonResult<Long> createSignInConfig(@Valid @RequestBody MemberSignInConfigCreateReqVO createReqVO) {
return success(signInConfigService.createSignInConfig(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新积分签到规则")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:update')")
public CommonResult<Boolean> updateSignInConfig(@Valid @RequestBody MemberSignInConfigUpdateReqVO updateReqVO) {
memberSignInConfigService.updateSignInConfig(updateReqVO);
signInConfigService.updateSignInConfig(updateReqVO);
return success(true);
}
@ -50,8 +49,8 @@ public class MemberSignInConfigController {
@Operation(summary = "删除积分签到规则")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('point:sign-in-config:delete')")
public CommonResult<Boolean> deleteSignInConfig(@RequestParam("id") Integer id) {
memberSignInConfigService.deleteSignInConfig(id);
public CommonResult<Boolean> deleteSignInConfig(@RequestParam("id") Long id) {
signInConfigService.deleteSignInConfig(id);
return success(true);
}
@ -59,16 +58,16 @@ public class MemberSignInConfigController {
@Operation(summary = "获得积分签到规则")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:query')")
public CommonResult<MemberSignInConfigRespVO> getSignInConfig(@RequestParam("id") Integer id) {
MemberSignInConfigDO signInConfig = memberSignInConfigService.getSignInConfig(id);
public CommonResult<MemberSignInConfigRespVO> getSignInConfig(@RequestParam("id") Long id) {
MemberSignInConfigDO signInConfig = signInConfigService.getSignInConfig(id);
return success(MemberSignInConfigConvert.INSTANCE.convert(signInConfig));
}
@GetMapping("/list")
@Operation(summary = "获得积分签到规则分页")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:query')")
public CommonResult<List<MemberSignInConfigRespVO>> getSignInConfigPage() {
List<MemberSignInConfigDO> pageResult = memberSignInConfigService.getSignInConfigList();
public CommonResult<List<MemberSignInConfigRespVO>> getSignInConfigList() {
List<MemberSignInConfigDO> pageResult = signInConfigService.getSignInConfigList();
return success(MemberSignInConfigConvert.INSTANCE.convertList(pageResult));
}

View File

@ -4,30 +4,28 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInRecordRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordRespVO;
import cn.iocoder.yudao.module.member.convert.signin.MemberSignInRecordConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
import cn.iocoder.yudao.module.member.service.signin.MemberSignInRecordService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
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.convertSet;
// TODO @xiaqingurl 使用 member 作为前缀
@Tag(name = "管理后台 - 用户签到积分")
@RestController
@RequestMapping("/point/sign-in-record")
@ -35,34 +33,24 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class MemberSignInRecordController {
@Resource
private MemberSignInRecordService memberSignInRecordService;
@Resource
MemberUserApi memberUserApi;
private MemberSignInRecordService signInRecordService;
@Resource
private MemberUserApi memberUserApi;
@GetMapping("/page")
@Operation(summary = "获得用户签到积分分页")
@PreAuthorize("@ss.hasPermission('point:sign-in-record:query')")
public CommonResult <PageResult <MemberSignInRecordRespVO>> getSignInRecordPage(@Valid MemberSignInRecordPageReqVO pageVO) {
//请求中如果有nickName需要根据nickName查询出userId
if(StringUtils.isNotBlank(pageVO.getNickName())){
List<Long> users= memberUserApi.getUserListByNickname(pageVO.getNickName()).stream()
.map(user->user.getId()).collect(Collectors.toList());
//如果根据昵称查出来的用户为空则无需继续查找
if(CollectionUtils.isEmpty(users)){
return success(new PageResult <>());
}
pageVO.setUserIds(users);
}
//处理查询结果首先将数据信息查询然后将userId转换为nickName
PageResult <MemberSignInRecordDO> pageResult = memberSignInRecordService.getSignInRecordPage(pageVO);
List <MemberSignInRecordDO> result = pageResult.getList();
//设置获取的用户信息
List <MemberUserRespDTO> users = null;
if (!CollectionUtils.isEmpty(result)) {
List <Long> ids = result.stream().map(user -> user.getUserId()).collect(Collectors.toList());
users = memberUserApi.getUsers(ids);
public CommonResult<PageResult<MemberSignInRecordRespVO>> getSignInRecordPage(@Valid MemberSignInRecordPageReqVO pageVO) {
// 执行分页查询
PageResult<MemberSignInRecordDO> pageResult = signInRecordService.getSignInRecordPage(pageVO);
if (CollectionUtils.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
// 拼接结果返回
List<MemberUserRespDTO> users = memberUserApi.getUserList(
convertSet(pageResult.getList(), MemberSignInRecordDO::getUserId));
return success(MemberSignInRecordConvert.INSTANCE.convertPage(pageResult, users));
}
}

View File

@ -1,22 +0,0 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 用户签到积分 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class MemberSignInRecordBaseVO {
@Schema(description = "签到用户", example = "6507")
private Long userId;
@Schema(description = "第几天签到")
private Integer day;
@Schema(description = "签到的分数")
private Integer point;
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.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 MemberSignInRecordCreateReqVO extends MemberSignInRecordBaseVO {
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.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 MemberSignInRecordRespVO extends MemberSignInRecordBaseVO {
@Schema(description = "签到自增id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11903")
private Long id;
@Schema(description = "签到时间")
private LocalDateTime createTime;
//昵称用于前台展示
private String nickName;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.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 MemberSignInRecordUpdateReqVO extends MemberSignInRecordBaseVO {
@Schema(description = "签到自增id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11903")
@NotNull(message = "签到自增id不能为空")
private Long id;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -10,14 +10,16 @@ import lombok.*;
@Data
public class MemberSignInConfigBaseVO {
@Schema(description = "签到第 x 天", example = "7")
// TODO @xiaqing必须的参数校验注解
@Schema(description = "签到第 x 天", requiredMode = Schema.RequiredMode.REQUIRED, example = "7")
private Integer day;
@Schema(description = "签到天数对应分数", example = "10")
@Schema(description = "签到天数对应分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Integer point;
@Schema(description = "是否启用", example = "1")
// TODO @xiaqingenable
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Boolean isEnable;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -13,6 +13,6 @@ public class MemberSignInConfigUpdateReqVO extends MemberSignInConfigBaseVO {
@Schema(description = "规则自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "13653")
@NotNull(message = "规则自增主键不能为空")
private Integer id;
private Long id;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo;
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.record;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
@ -8,7 +8,6 @@ import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
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;
@ -18,13 +17,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class MemberSignInRecordPageReqVO extends PageParam {
//用户前台模糊查询
@Schema(description = "签到用户", example = "6507")
private String nickName;
@Schema(description = "签到用户", example = "土豆")
private String nickname;
private List<Long>userIds;
@Schema(description = "第几天签到")
@Schema(description = "第几天签到", example = "10")
private Integer day;
@Schema(description = "签到时间")

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.record;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 用户签到积分 Response VO")
@Data
public class MemberSignInRecordRespVO {
@Schema(description = "签到自增 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11903")
private Long id;
@Schema(description = "签到用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "6507")
private Long userId;
@Schema(description = "昵称", example = "张三")
private String nickname;
@Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer day;
@Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Integer point;
@Schema(description = "签到时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -20,5 +20,4 @@ public interface MemberPointConfigConvert {
MemberPointConfigDO convert(MemberPointConfigSaveReqVO bean);
}

View File

@ -1,17 +1,17 @@
package cn.iocoder.yudao.module.member.convert.point;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 用户积分记录 Convert
@ -23,62 +23,14 @@ public interface MemberPointRecordConvert {
MemberPointRecordConvert INSTANCE = Mappers.getMapper(MemberPointRecordConvert.class);
default PageResult <MemberPointRecordRespVO> convertPage(PageResult <MemberPointRecordDO> page, List <MemberUserRespDTO> users) {
if (page == null) {
return null;
}
PageResult <MemberPointRecordRespVO> pageResult = new PageResult <MemberPointRecordRespVO>();
pageResult.setList(memberPointRecordDOListToMemberPointRecordRespVOList(page.getList(), users));
pageResult.setTotal(page.getTotal());
return pageResult;
default PageResult<MemberPointRecordRespVO> convertPage(PageResult<MemberPointRecordDO> pageResult, List<MemberUserRespDTO> users) {
PageResult<MemberPointRecordRespVO> voPageResult = convertPage(pageResult);
// user 拼接
Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId);
voPageResult.getList().forEach(record -> MapUtils.findAndThen(userMap, record.getUserId(),
memberUserRespDTO -> record.setNickname(memberUserRespDTO.getNickname())));
return voPageResult;
}
default List <MemberPointRecordRespVO> memberPointRecordDOListToMemberPointRecordRespVOList(List <MemberPointRecordDO> list, List <MemberUserRespDTO> users) {
if (list == null) {
return null;
}
Map <Long, String> maps = null;
//是否需要转换用户标志
boolean userNickFlag = !CollectionUtils.isEmpty(users);
if (userNickFlag) {
maps = users.stream()
.collect(Collectors.toMap(MemberUserRespDTO::getId, MemberUserRespDTO::getNickname, (key1, key2) -> key2));
}
List <MemberPointRecordRespVO> list1 = new ArrayList <MemberPointRecordRespVO>(list.size());
for (MemberPointRecordDO memberPointRecordDO : list) {
MemberPointRecordRespVO recordRespVO = memberPointRecordDOToMemberPointRecordRespVO(memberPointRecordDO);
recordRespVO.setNickName(maps.get(memberPointRecordDO.getUserId()));
list1.add(recordRespVO);
}
return list1;
}
default MemberPointRecordRespVO memberPointRecordDOToMemberPointRecordRespVO(MemberPointRecordDO memberPointRecordDO) {
if (memberPointRecordDO == null) {
return null;
}
MemberPointRecordRespVO memberPointRecordRespVO = new MemberPointRecordRespVO();
memberPointRecordRespVO.setBizId(memberPointRecordDO.getBizId());
memberPointRecordRespVO.setBizType(memberPointRecordDO.getBizType());
memberPointRecordRespVO.setType(memberPointRecordDO.getType());
memberPointRecordRespVO.setTitle(memberPointRecordDO.getTitle());
memberPointRecordRespVO.setDescription(memberPointRecordDO.getDescription());
memberPointRecordRespVO.setPoint(memberPointRecordDO.getPoint());
memberPointRecordRespVO.setTotalPoint(memberPointRecordDO.getTotalPoint());
memberPointRecordRespVO.setStatus(memberPointRecordDO.getStatus());
memberPointRecordRespVO.setFreezingTime(memberPointRecordDO.getFreezingTime());
memberPointRecordRespVO.setThawingTime(memberPointRecordDO.getThawingTime());
memberPointRecordRespVO.setId(memberPointRecordDO.getId());
memberPointRecordRespVO.setCreateTime(memberPointRecordDO.getCreateTime());
return memberPointRecordRespVO;
}
PageResult<MemberPointRecordRespVO> convertPage(PageResult<MemberPointRecordDO> pageResult);
}

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.member.convert.signin;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -28,6 +27,4 @@ public interface MemberSignInConfigConvert {
List<MemberSignInConfigRespVO> convertList(List<MemberSignInConfigDO> list);
PageResult<MemberSignInConfigRespVO> convertPage(PageResult<MemberSignInConfigDO> page);
}

View File

@ -1,19 +1,17 @@
package cn.iocoder.yudao.module.member.convert.signin;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInRecordRespVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 用户签到积分 Convert
@ -25,57 +23,14 @@ public interface MemberSignInRecordConvert {
MemberSignInRecordConvert INSTANCE = Mappers.getMapper(MemberSignInRecordConvert.class);
default public MemberSignInRecordRespVO convert(MemberSignInRecordDO bean) {
if (bean == null) {
return null;
}
MemberSignInRecordRespVO memberSignInRecordRespVO = new MemberSignInRecordRespVO();
memberSignInRecordRespVO.setUserId(bean.getUserId());
memberSignInRecordRespVO.setDay(bean.getDay());
memberSignInRecordRespVO.setPoint(bean.getPoint());
memberSignInRecordRespVO.setId(bean.getId());
memberSignInRecordRespVO.setCreateTime(bean.getCreateTime());
return memberSignInRecordRespVO;
default PageResult<MemberSignInRecordRespVO> convertPage(PageResult<MemberSignInRecordDO> pageResult, List<MemberUserRespDTO> users) {
PageResult<MemberSignInRecordRespVO> voPageResult = convertPage(pageResult);
// user 拼接
Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId);
voPageResult.getList().forEach(record -> MapUtils.findAndThen(userMap, record.getUserId(),
memberUserRespDTO -> record.setNickname(memberUserRespDTO.getNickname())));
return voPageResult;
}
default PageResult <MemberSignInRecordRespVO> convertPage(PageResult <MemberSignInRecordDO> page, List <MemberUserRespDTO> userRespDTOS) {
if (page == null) {
return null;
}
PageResult <MemberSignInRecordRespVO> pageResult = new PageResult <MemberSignInRecordRespVO>();
pageResult.setList(memberSignInRecordDOListToMemberSignInRecordRespVOList(page.getList(),userRespDTOS));
pageResult.setTotal(page.getTotal());
return pageResult;
}
default List <MemberSignInRecordRespVO> memberSignInRecordDOListToMemberSignInRecordRespVOList(List <MemberSignInRecordDO> list,List <MemberUserRespDTO> userRespDTOS) {
if (list == null) {
return null;
}
Map <Long, String> maps=null;
//是否需要转换用户标志
boolean userNickFlag = !CollectionUtils.isEmpty(userRespDTOS);
if(userNickFlag){
maps = userRespDTOS.stream()
.collect(Collectors.toMap(MemberUserRespDTO::getId, MemberUserRespDTO::getNickname, (key1, key2) -> key2));
}
List <MemberSignInRecordRespVO> list1 = new ArrayList <MemberSignInRecordRespVO>(list.size());
for (MemberSignInRecordDO memberSignInRecordDO : list) {
MemberSignInRecordRespVO recordRespVO = convert(memberSignInRecordDO);
if(userNickFlag){
recordRespVO.setNickName(maps.get(recordRespVO.getUserId()));
}
list1.add(recordRespVO);
}
return list1;
}
PageResult<MemberSignInRecordRespVO> convertPage(PageResult<MemberSignInRecordDO> pageResult);
}

View File

@ -28,6 +28,13 @@ public class MemberPointRecordDO extends BaseDO {
*/
@TableId
private Long id;
/**
* 用户编号
*
* 对应 MemberUserDO id 属性
*/
private Long userId;
/**
* 业务编码
*/
@ -36,6 +43,7 @@ public class MemberPointRecordDO extends BaseDO {
* 业务类型
*
* 枚举 {@link TODO biz_type 对应枚举然后改成 int 类型哈}
* TODO @qingxia这个改成 Integer然后搞个枚举
*/
private String bizType;
/**
@ -58,12 +66,10 @@ public class MemberPointRecordDO extends BaseDO {
* 状态1-订单创建2-冻结期3-完成4-失效订单退款
*
* 枚举 {@link point_status 对应的类}
* TODO @qingxia搞个枚举
*/
private Integer status;
/**
* 用户id
*/
private Long userId;
/**
* 冻结时间
*/

View File

@ -25,7 +25,7 @@ public class MemberSignInConfigDO extends BaseDO {
* 规则自增主键
*/
@TableId
private Integer id;
private Long id;
/**
* 签到第x天
*/
@ -34,8 +34,11 @@ public class MemberSignInConfigDO extends BaseDO {
* 签到天数对应分数
*/
private Integer point;
// TODO @puhui999enable不用 is 开头
/**
* 是否启用
*/
private Boolean isEnable;
}

View File

@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPoi
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Set;
/**
* 用户积分记录 Mapper
*
@ -15,11 +17,10 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MemberPointRecordMapper extends BaseMapperX<MemberPointRecordDO> {
default PageResult<MemberPointRecordDO> selectPage(MemberPointRecordPageReqVO reqVO) {
default PageResult<MemberPointRecordDO> selectPage(MemberPointRecordPageReqVO reqVO, Set<Long> userIds) {
return selectPage(reqVO, new LambdaQueryWrapperX<MemberPointRecordDO>()
.inIfPresent(MemberPointRecordDO::getUserId,reqVO.getUserIds())
.inIfPresent(MemberPointRecordDO::getUserId, userIds)
.eqIfPresent(MemberPointRecordDO::getBizType, reqVO.getBizType())
.eqIfPresent(MemberPointRecordDO::getType, reqVO.getType())
.eqIfPresent(MemberPointRecordDO::getTitle, reqVO.getTitle())
.eqIfPresent(MemberPointRecordDO::getStatus, reqVO.getStatus())
.orderByDesc(MemberPointRecordDO::getId));

View File

@ -16,11 +16,7 @@ import java.util.List;
@Mapper
public interface MemberSignInConfigMapper extends BaseMapperX<MemberSignInConfigDO> {
/**
* 描述 :选择性更新对象属性如果不为空则更新
* Author :xiaqing
* Date :2023-08-08 23:38:48
*/
// TODO @qingxia是不是不用这个方法直接 updateById 即可
default int updateIfPresent(MemberSignInConfigDO updateObj){
LambdaUpdateWrapper <MemberSignInConfigDO> wrapper = new LambdaUpdateWrapper <>();
wrapper.eq(MemberSignInConfigDO::getId, updateObj.getId())
@ -30,18 +26,13 @@ public interface MemberSignInConfigMapper extends BaseMapperX<MemberSignInConfig
return update(null,wrapper);
}
default List <MemberSignInConfigDO> getList(){
// TODO @qingxia不用这个方法selectList业务层自己排序即可
default List<MemberSignInConfigDO> getList() {
return selectList(new LambdaQueryWrapperX <MemberSignInConfigDO>().orderByAsc(MemberSignInConfigDO::getDay));
}
/**
* 描述 :根据天数查询对应记录
* Date :2023-08-09 00:07:11
*/
default MemberSignInConfigDO selectByDay(Integer day){
return selectOne(new LambdaQueryWrapperX <MemberSignInConfigDO>()
.eq(MemberSignInConfigDO::getDay,day));
default MemberSignInConfigDO selectByDay(Integer day) {
return selectOne(MemberSignInConfigDO::getDay, day);
}
}

View File

@ -3,10 +3,12 @@ package cn.iocoder.yudao.module.member.dal.mysql.signin;
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.signin.vo.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Set;
/**
* 用户签到积分 Mapper
*
@ -15,9 +17,9 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecordDO> {
default PageResult<MemberSignInRecordDO> selectPage(MemberSignInRecordPageReqVO reqVO) {
default PageResult<MemberSignInRecordDO> selectPage(MemberSignInRecordPageReqVO reqVO, Set<Long> userIds) {
return selectPage(reqVO, new LambdaQueryWrapperX<MemberSignInRecordDO>()
.inIfPresent(MemberSignInRecordDO::getUserId, reqVO.getUserIds())
.inIfPresent(MemberSignInRecordDO::getUserId, userIds)
.eqIfPresent(MemberSignInRecordDO::getDay, reqVO.getDay())
.betweenIfPresent(MemberSignInRecordDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MemberSignInRecordDO::getId));

View File

@ -1,13 +1,21 @@
package cn.iocoder.yudao.module.member.service.point;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointRecordMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
/**
@ -22,9 +30,22 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
@Resource
private MemberPointRecordMapper recordMapper;
@Resource
private MemberUserApi memberUserApi;
@Override
public PageResult<MemberPointRecordDO> getRecordPage(MemberPointRecordPageReqVO pageReqVO) {
return recordMapper.selectPage(pageReqVO);
// 根据用户昵称查询出用户ids
Set<Long> userIds = null;
if (StringUtils.isNotBlank(pageReqVO.getNickname())) {
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageReqVO.getNickname());
// 如果查询用户结果为空直接返回无需继续查询
if (CollectionUtils.isEmpty(users)) {
return PageResult.empty();
}
userIds = convertSet(users, MemberUserRespDTO::getId);
}
return recordMapper.selectPage(pageReqVO, userIds);
}
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.member.service.signin;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO;
import javax.validation.Valid;
@ -20,7 +20,7 @@ public interface MemberSignInConfigService {
* @param createReqVO 创建信息
* @return 编号
*/
Integer createSignInConfig(@Valid MemberSignInConfigCreateReqVO createReqVO);
Long createSignInConfig(@Valid MemberSignInConfigCreateReqVO createReqVO);
/**
* 更新积分签到规则
@ -34,7 +34,7 @@ public interface MemberSignInConfigService {
*
* @param id 编号
*/
void deleteSignInConfig(Integer id);
void deleteSignInConfig(Long id);
/**
* 获得积分签到规则
@ -42,7 +42,7 @@ public interface MemberSignInConfigService {
* @param id 编号
* @return 积分签到规则
*/
MemberSignInConfigDO getSignInConfig(Integer id);
MemberSignInConfigDO getSignInConfig(Long id);
/**
* 获得积分签到规则分页

View File

@ -1,23 +1,18 @@
package cn.iocoder.yudao.module.member.service.signin;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigCreateReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.config.MemberSignInConfigUpdateReqVO;
import cn.iocoder.yudao.module.member.convert.signin.MemberSignInConfigConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO;
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInConfigMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CONFIG_EXISTS;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CONFIG_NOT_EXISTS;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
/**
* 积分签到规则 Service 实现类
@ -29,16 +24,16 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CO
public class MemberSignInConfigServiceImpl implements MemberSignInConfigService {
@Resource
private MemberSignInConfigMapper memberSignInConfigMapper;
private MemberSignInConfigMapper signInConfigMapper;
@Override
public Integer createSignInConfig(MemberSignInConfigCreateReqVO createReqVO) {
public Long createSignInConfig(MemberSignInConfigCreateReqVO createReqVO) {
// 判断是否重复插入签到天数
validateSignInConfigExistsDay(createReqVO.getDay());
validateSignInConfigDayDuplicate(createReqVO.getDay(), null);
// 插入
MemberSignInConfigDO signInConfig = MemberSignInConfigConvert.INSTANCE.convert(createReqVO);
memberSignInConfigMapper.insert(signInConfig);
signInConfigMapper.insert(signInConfig);
// 返回
return signInConfig.getId();
}
@ -47,52 +42,54 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
public void updateSignInConfig(MemberSignInConfigUpdateReqVO updateReqVO) {
// 校验存在
validateSignInConfigExists(updateReqVO.getId());
//判断是否重复插入签到天数
validateSignInConfigSameDayNotSelf(updateReqVO);
// 判断是否重复插入签到天数
validateSignInConfigDayDuplicate(updateReqVO.getDay(), updateReqVO.getId());
// 判断更新
MemberSignInConfigDO updateObj = MemberSignInConfigConvert.INSTANCE.convert(updateReqVO);
memberSignInConfigMapper.updateIfPresent(updateObj);
signInConfigMapper.updateIfPresent(updateObj);
}
@Override
public void deleteSignInConfig(Integer id) {
public void deleteSignInConfig(Long id) {
// 校验存在
validateSignInConfigExists(id);
// 删除
memberSignInConfigMapper.deleteById(id);
signInConfigMapper.deleteById(id);
}
private void validateSignInConfigExists(Integer id) {
if (memberSignInConfigMapper.selectById(id) == null) {
private void validateSignInConfigExists(Long id) {
if (signInConfigMapper.selectById(id) == null) {
throw exception(SIGN_IN_CONFIG_NOT_EXISTS);
}
}
//根据签到天数判断是否存在一个相同的天数
private void validateSignInConfigExistsDay(Integer day) {
MemberSignInConfigDO configDO = memberSignInConfigMapper.selectByDay(day);
if (configDO != null) {
/**
* 校验 day 是否重复
*
* @param day
* @param id 编号只有更新的时候会传递
*/
private void validateSignInConfigDayDuplicate(Integer day, Long id) {
MemberSignInConfigDO configDO = signInConfigMapper.selectByDay(day);
// 1. 新增时configDO 非空则说明重复
if (id == null && configDO != null) {
throw exception(SIGN_IN_CONFIG_EXISTS);
}
}
// 更新天数时判断是否有重复的天数需要去除自己
private void validateSignInConfigSameDayNotSelf(MemberSignInConfigUpdateReqVO reqVO) {
MemberSignInConfigDO configDO = memberSignInConfigMapper.selectByDay(reqVO.getDay());
if (configDO != null && configDO.getId() != reqVO.getId()) {
// 2. 更新时如果 configDO 非空 id 不相等则说明重复
if (id != null && configDO != null && !configDO.getId().equals(id)) {
throw exception(SIGN_IN_CONFIG_EXISTS);
}
}
@Override
public MemberSignInConfigDO getSignInConfig(Integer id) {
return memberSignInConfigMapper.selectById(id);
public MemberSignInConfigDO getSignInConfig(Long id) {
return signInConfigMapper.selectById(id);
}
@Override
public List <MemberSignInConfigDO> getSignInConfigList() {
return memberSignInConfigMapper.getList();
return signInConfigMapper.getList();
}
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.member.service.signin;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
/**
@ -11,8 +11,6 @@ import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO
*/
public interface MemberSignInRecordService {
/**
* 获得用户签到积分分页
*
@ -21,5 +19,4 @@ public interface MemberSignInRecordService {
*/
PageResult<MemberSignInRecordDO> getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO);
}

View File

@ -1,17 +1,21 @@
package cn.iocoder.yudao.module.member.service.signin;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO;
import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInRecordMapper;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_RECORD_NOT_EXISTS;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
/**
* 用户签到积分 Service 实现类
@ -23,15 +27,24 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_RE
public class MemberSignInRecordServiceImpl implements MemberSignInRecordService {
@Resource
private MemberSignInRecordMapper memberSignInRecordMapper;
private MemberSignInRecordMapper signInRecordMapper;
@Resource
AdminUserApi adminUserApi;
private MemberUserApi memberUserApi;
@Override
public PageResult<MemberSignInRecordDO> getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) {
return memberSignInRecordMapper.selectPage(pageReqVO);
// 根据用户昵称查询出用户ids
Set<Long> userIds = null;
if (StringUtils.isNotBlank(pageReqVO.getNickname())) {
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageReqVO.getNickname());
// 如果查询用户结果为空直接返回无需继续查询
if (CollectionUtils.isEmpty(users)) {
return PageResult.empty();
}
userIds = convertSet(users, MemberUserRespDTO::getId);
}
return signInRecordMapper.selectPage(pageReqVO, userIds);
}
}

View File

@ -51,7 +51,7 @@ spring:
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例
username: root
password: 1qaz!QAZ
password: 123456
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
slave: # 模拟从库,可根据自己需要修改
@ -62,13 +62,13 @@ spring:
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例
username: root
password: 1qaz!QAZ
password: 123456
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
host: 10.211.55.5 # 地址
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 0 # 数据库索引
# password: dev # 密码,建议生产环境开启