code review:会员签到配置

This commit is contained in:
YunaiV 2023-08-20 10:14:28 +08:00
parent bfc72a9802
commit c7285da9a7
7 changed files with 27 additions and 37 deletions

View File

@ -12,18 +12,20 @@ import javax.validation.constraints.NotNull;
@Data
public class MemberPointConfigBaseVO {
@NotNull(message = "积分抵扣开发不能为空")
@Schema(description = "积分抵扣开关", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "积分抵扣开发不能为空")
private Boolean tradeDeductEnable;
@NotNull(message = "积分抵扣不能为空")
@Schema(description = "积分抵扣,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "13506")
@NotNull(message = "积分抵扣不能为空")
private Integer tradeDeductUnitPrice;
@NotNull(message = "积分抵扣最大值不能为空")
@Schema(description = "积分抵扣最大值", requiredMode = Schema.RequiredMode.REQUIRED, example = "32428")
@NotNull(message = "积分抵扣最大值不能为空")
private Integer tradeDeductMaxPrice;
@NotNull(message = "1元赠送积分不能为空")
@Schema(description = "1 元赠送多少分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
@NotNull(message = "1 元赠送积分不能为空")
private Integer tradeGivePoint;
}

View File

@ -1,12 +1,9 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* 积分签到规则 Base VO提供给添加修改详细的子 VO 使用
@ -14,14 +11,13 @@ import javax.validation.constraints.Pattern;
*/
@Data
public class MemberSignInConfigBaseVO {
@Schema(description = "签到第 x 天", requiredMode = Schema.RequiredMode.REQUIRED, example = "7")
@NotNull(message = "签到天数不能为空")
private Integer day;
@Schema(description = "签到天数对应分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@NotNull(message = "签到天数对应分数不能为空")
@Schema(description = "奖励积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@NotNull(message = "奖励积分不能为空")
private Integer point;
@NotNull

View File

@ -31,7 +31,7 @@ public class MemberSignInConfigDO extends BaseDO {
*/
private Integer day;
/**
* 签到天数对应分数
* 奖励积分
*/
private Integer point;

View File

@ -1,13 +1,9 @@
package cn.iocoder.yudao.module.member.dal.mysql.signin;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 积分签到规则 Mapper
*
@ -16,7 +12,6 @@ import java.util.List;
@Mapper
public interface MemberSignInConfigMapper extends BaseMapperX<MemberSignInConfigDO> {
default MemberSignInConfigDO selectByDay(Integer day) {
return selectOne(MemberSignInConfigDO::getDay, day);
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.member.service.point;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO;
import cn.iocoder.yudao.module.member.convert.point.MemberPointConfigConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO;
@ -26,22 +25,19 @@ public class MemberPointConfigServiceImpl implements MemberPointConfigService {
@Override
public void saveConfig(MemberPointConfigSaveReqVO saveReqVO) {
//获取当前记录
MemberPointConfigDO configDO = getConfig();
MemberPointConfigDO pointConfigDO = MemberPointConfigConvert.INSTANCE.convert(saveReqVO);
//当前存在记录则更新否则插入
if (configDO != null) {
pointConfigDO.setId(configDO.getId());
pointConfigMapper.updateById(pointConfigDO);
} else {
pointConfigDO.setId(null);
pointConfigMapper.insert(pointConfigDO);
// 存在则进行更新
MemberPointConfigDO dbConfig = getConfig();
if (dbConfig != null) {
pointConfigMapper.updateById(MemberPointConfigConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
return;
}
// 不存在则进行插入
pointConfigMapper.insert(MemberPointConfigConvert.INSTANCE.convert(saveReqVO));
}
@Override
public MemberPointConfigDO getConfig() {
List <MemberPointConfigDO> list = pointConfigMapper.selectList();
List<MemberPointConfigDO> list = pointConfigMapper.selectList();
return CollectionUtils.getFirst(list);
}

View File

@ -29,12 +29,13 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
@Resource
private MemberPointRecordMapper recordMapper;
@Resource
private MemberUserApi memberUserApi;
@Override
public PageResult<MemberPointRecordDO> getRecordPage(MemberPointRecordPageReqVO pageReqVO) {
// 根据用户昵称查询出用户ids
// 根据用户昵称查询出用户 ids
Set<Long> userIds = null;
if (StringUtils.isNotBlank(pageReqVO.getNickname())) {
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageReqVO.getNickname());
@ -44,6 +45,7 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
}
userIds = convertSet(users, MemberUserRespDTO::getId);
}
// 执行查询
return recordMapper.selectPage(pageReqVO, userIds);
}

View File

@ -11,10 +11,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
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;
/**
* 积分签到规则 Service 实现类
@ -91,10 +91,9 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
@Override
public List <MemberSignInConfigDO> getSignInConfigList() {
//查询出所有的配置记录
List<MemberSignInConfigDO> result = signInConfigMapper.selectList();
//业务侧排序后返回结果
return result.stream().sorted(Comparator.comparing(MemberSignInConfigDO::getDay)).collect(Collectors.toList());
List<MemberSignInConfigDO> list = signInConfigMapper.selectList();
list.sort(Comparator.comparing(MemberSignInConfigDO::getDay));
return list;
}
}