Commit 9a97bd5a authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score' into dev

parents 4f4ca8ce 3a84402f
package cn.iocoder.yudao.module.ecw.api.node;
import cn.iocoder.yudao.module.ecw.api.node.dto.NodeRespDTO;
import java.util.List;
public interface NodeApi {
List<NodeRespDTO> getNodesByCity(Long cityId,Long countryId);
}
package cn.iocoder.yudao.module.ecw.api.node.dto;
import lombok.Data;
@Data
public class NodeRespDTO {
private Long id;
/**
* 站点编号
*/
private String number;
/**
* 国家
*/
private Long guojia;
/**
* 市
*/
private Long shi;
/**
* 中文标题
*/
private String titleZh;
/**
* 英文标题
*/
private String titleEn;
}
package cn.iocoder.yudao.module.ecw.service.api;
import cn.iocoder.yudao.module.ecw.api.node.NodeApi;
import cn.iocoder.yudao.module.ecw.api.node.dto.NodeRespDTO;
import cn.iocoder.yudao.module.ecw.dal.dataobject.node.NodeDO;
import cn.iocoder.yudao.module.ecw.dal.mysql.node.NodeMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class NodeApiImpl implements NodeApi {
@Resource
private NodeMapper nodeMapper;
@Override
public List<NodeRespDTO> getNodesByCity(Long cityId, Long countryId) {
List<NodeDO> city = null;
if (cityId != null) {
city = nodeMapper.selectList("shi", cityId);
} else if (countryId != null) {
city = nodeMapper.selectList("guojia", countryId);
}
if (city != null && !city.isEmpty()) {
ArrayList<NodeRespDTO> nodeRespDTOS = new ArrayList<>();
for (NodeDO nodeDO : city) {
NodeRespDTO nodeRespDTO = new NodeRespDTO();
BeanUtils.copyProperties(nodeDO, nodeRespDTO);
nodeRespDTOS.add(nodeRespDTO);
}
return nodeRespDTOS;
}
return null;
}
}
......@@ -48,4 +48,7 @@ public class UserRespDTO {
private Integer holdScore;
private Integer country;
private Integer city;
}
......@@ -55,7 +55,7 @@ public interface ErrorCodeConstants {
ErrorCode SCORE_RULE_NOT_EXISTS = new ErrorCode(1004008010, "score.rule.not.exists");
ErrorCode SCORE_RULE_DELETE_ERROR = new ErrorCode(1004008011, "score.rule.delete.error");
ErrorCode SCORE_RULE_UPDATE_ERROR = new ErrorCode(1004008012, "score.rule.update.error");
ErrorCode SCORE_RULE_FIELD_ERROR = new ErrorCode(1004008013, "score.rule.field.error");
ErrorCode SCORE_RULE_FIELD_ERROR = new ErrorCode(1004008013, "score.rule.field.error:{}");
ErrorCode USER_ADDRESS_NOT_EXISTS = new ErrorCode(1004008014, "user.address.not.exists");
ErrorCode USER_ADDRESS_FIELD_ERROR = new ErrorCode(1004008015, "user.address.field.error");
......
......@@ -185,7 +185,7 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
"AND u.id = #{id} ",
"</script>"
})
MemberUserDO info(@Param("id") Long id);
List<MemberUserDO> info(@Param("id") Long id);
@Update("update ecw_customer_contacts set userid = null where userid = #{userId}")
void unbindingCustomer(@Param("userId") Long userId);
......
......@@ -55,7 +55,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR);
throw exception(SCORE_RULE_FIELD_ERROR, "状态只能是启用或未启用");
}
verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType();
......@@ -159,9 +159,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
StringBuilder receiveAddr = new StringBuilder();
for (List<Long> integers : receiveAddrList) {
try {
targetCountry.append(integers.get(1)).append(",");
targetCity.append(integers.get(2)).append(",");
receiveAddr.append(integers.get(3)).append(",");
targetCountry.append(integers.get(0)).append(",");
targetCity.append(integers.get(1)).append(",");
receiveAddr.append(integers.get(2)).append(",");
} catch (Exception e) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
......
......@@ -258,7 +258,8 @@ public class MemberUserServiceImpl implements MemberUserService {
@Override
public MemberUserDO info(Long id) {
return memberUserMapper.info(id);
// 一个会员可能绑定了多个用户
return memberUserMapper.info(id).get(0);
}
@Override
......
......@@ -10,6 +10,8 @@ public class RedeemRewardRespDTO {
@ApiModelProperty(value = "兑换操作结果")
private Boolean exchangeResult;
@ApiModelProperty(value = "兑换操作详情")
private String msg;
@ApiModelProperty(value = "兑换操作详情中文")
private String msgZh;
@ApiModelProperty(value = "兑换操作详情英文")
private String msgEn;
}
......@@ -61,28 +61,28 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品
RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId());
if (rewardDO == null) {
throw exception(REWARD_NOT_EXISTS);
return getRedeemResp(false, "礼品不存在", "reward do not exist!");
}
// 礼品未开启
if (rewardDO.getStatus() != 1) {
throw exception(REWARD_NOT_ENABLE);
return getRedeemResp(false, "礼品未开启", "reward do not enable!");
}
// 礼品数量不够
if (rewardDO.getQuantityRemain() < redeemRewardReqVO.getRewardCount()) {
throw exception(REWARD_COUNT_NOT_ENOUGH);
return getRedeemResp(false, "礼品数量不够", "reward do not enough!");
}
// 兑换方式不匹配
String pickMethod = rewardDO.getPickMethod();
String[] split = pickMethod.split(",");
if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) {
throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE);
return getRedeemResp(false, "兑换方式不支持", "redeem type do not support!");
}
verifyMemberUser(redeemRewardReqVO, rewardDO);
String lockKey = "reward:redeem:lock:" + redeemRewardReqVO.getRewardId();
RLock lock = redissonClient.getLock(lockKey);
try {
if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) {
throw exception(GET_LOCK_FAILED);
return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later");
}
// 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO);
......@@ -91,11 +91,19 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 更新礼品
redeemReward(rewardDO, redeemRewardReqVO.getRewardCount());
} catch (InterruptedException e) {
throw exception(GET_LOCK_FAILED);
return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later");
} finally {
lock.unlock();
}
return null;
return getRedeemResp(true, "兑换成功!", "redeem success!");
}
private RedeemRewardRespDTO getRedeemResp(Boolean exchangeResult, String msgZh, String msgEn) {
RedeemRewardRespDTO redeemRewardRespDTO = new RedeemRewardRespDTO();
redeemRewardRespDTO.setExchangeResult(false);
redeemRewardRespDTO.setMsgZh(msgZh);
redeemRewardRespDTO.setMsgEn(msgEn);
return redeemRewardRespDTO;
}
private void redeemReward(RewardDO reward, Integer rewardCount) {
......
package cn.iocoder.yudao.module.reward.controller.app.reward;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardBackVO;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardListReqVO;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.service.reward.RewardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
@RestController
@Api(tags = "客户端 - 礼品管理")
@RequestMapping("/ecw/reward/")
public class AppRewardController {
@Resource
private RewardService rewardService;
@GetMapping("/get")
@ApiOperation("获得礼品详情")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
public CommonResult<AppRewardBackVO> get(@RequestParam("id") Long id) {
RewardDO rewardDO = rewardService.get(id);
AppRewardBackVO appRewardBackVO = new AppRewardBackVO();
BeanUtils.copyProperties(rewardDO, appRewardBackVO);
return success(appRewardBackVO);
}
@PostMapping("/list")
@ApiOperation("会员获得礼品列表")
public CommonResult<List<AppRewardBackVO>> getListByMemberInfo(@RequestBody AppRewardListReqVO reqVO) {
List<AppRewardBackVO> list = rewardService.getListByMemberInfo(reqVO);
return success(list);
}
}
package cn.iocoder.yudao.module.reward.controller.app.reward.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 礼品 Response VO
* @author 系统管理员
*/
@Data
@ApiModel("客户端 - 礼品 Response VO")
public class AppRewardBackVO {
@ExcelProperty("")
@ApiModelProperty(value = "", required = true)
private Long id;
@ExcelProperty("礼品ID")
@ApiModelProperty(value = "礼品ID", required = true)
private String code;
@ExcelProperty("中文名称")
@ApiModelProperty(value = "中文名称")
private String titleZh;
@ExcelProperty("英文名称")
@ApiModelProperty(value = "英文名称")
private String titleEn;
//@ExcelProperty("法文名称")
//@ApiModelProperty(value = "法文名称")
//private String titleFr;
@ExcelProperty("中文礼品图片")
@ApiModelProperty(value = "中文礼品图片")
private String imgZh;
@ExcelProperty("英文礼品图片")
@ApiModelProperty(value = "英文礼品图片")
private String imgEn;
//@ExcelProperty("法文礼品图片")
//@ApiModelProperty(value = "法文礼品图片")
//private String imgFr;
@ExcelProperty("兑换所需积分")
@ApiModelProperty(value = "兑换所需积分", required = true)
private Integer pointsRequire;
@ExcelProperty("兑换网点")
@ApiModelProperty(value = "兑换网点", required = true)
private Integer nodeId;
@ExcelProperty("剩余数量")
@ApiModelProperty(value = "剩余数量", required = true)
private Integer quantityRemain;
@ExcelProperty("活动开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "活动开始时间")
private Date startTime;
@ExcelProperty("活动结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "活动结束时间")
private Date endTime;
@ExcelProperty("领取方式(1上门领取,2包邮到家,3邮寄到付)")
@ApiModelProperty(value = "领取方式(1上门领取,2包邮到家,3邮寄到付)", required = true)
private String pickMethod;
@ExcelProperty("允许兑换次数")
@ApiModelProperty(value = "允许兑换次数", required = true)
private Integer allowCount;
}
package cn.iocoder.yudao.module.reward.controller.app.reward.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel("客户端 - 礼品列表 Req VO")
public class AppRewardListReqVO {
@ApiModelProperty(value = "会员id", required = true)
@NotNull(message = "会员id不能为空")
private Long memberId;
@ApiModelProperty(value = "网点")
private Long nodeId;
}
......@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.reward.convert.reward;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardBackVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.reward.vo.reward.*;
......@@ -38,6 +39,12 @@ public interface RewardConvert {
*/
RewardBackVO convert(RewardDO bean);
/***
* 实体转返回VO
* @param bean
* @return
*/
AppRewardBackVO convertAppVO(RewardDO bean);
/***
* 实体列表转返回VO列表
* @param list
......
......@@ -82,7 +82,6 @@ public class RewardDO extends BaseDO {
private Date endTime;
/**
* 领取方式(1上门领取,2包邮到家,3邮寄到付)
* TODO :改为枚举
*/
private String pickMethod;
/**
......@@ -103,7 +102,6 @@ public class RewardDO extends BaseDO {
private String remarkFr;
/**
* 礼品状态(1已启用,2未启用,3已关闭,4已过期)
* TODO :改为枚举
*/
private Integer status;
......
......@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.reward.service.reward;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardBackVO;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardListReqVO;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.vo.reward.*;
......@@ -75,4 +77,11 @@ public interface RewardService extends IService<RewardDO> {
void delayReward(RewardDelayReqVO delayVO);
void updateStatus(RewardStatusReqVO statusVO);
/**
* 客户端获得礼品列表
* @param reqVO
* @return
*/
List<AppRewardBackVO> getListByMemberInfo(AppRewardListReqVO reqVO);
}
package cn.iocoder.yudao.module.reward.service.reward;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.ecw.api.node.NodeApi;
import cn.iocoder.yudao.module.ecw.api.node.dto.NodeRespDTO;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardBackVO;
import cn.iocoder.yudao.module.reward.controller.app.reward.vo.AppRewardListReqVO;
import cn.iocoder.yudao.module.reward.convert.reward.RewardConvert;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.QuantitativeRelationSymbolEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;
......@@ -19,10 +24,11 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
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.reward.enums.ErrorCodeConstants.*;
......@@ -38,6 +44,10 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
@Resource
private RewardMapper rewardMapper;
@Resource
private NodeApi nodeApi;
@Resource
private MemberUserApi memberUserApi;
@Override
public Long create(RewardCreateReqVO createReqVO) {
......@@ -268,6 +278,36 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
}
}
@Override
public List<AppRewardBackVO> getListByMemberInfo(AppRewardListReqVO reqVO) {
LambdaQuery<RewardDO> rewardDOLambdaQuery = new LambdaQuery<>();
rewardDOLambdaQuery.eq(RewardDO::getStatus, RewardStatusEnum.ENABLED.getValue())
.gt(RewardDO::getQuantityRemain, 0)
.le(RewardDO::getStartTime, new Date())
.ge(RewardDO::getEndTime, new Date());
// 如果有网点,直接根据网点查
if (reqVO.getNodeId() != null) {
rewardDOLambdaQuery.eq(RewardDO::getNodeId, reqVO.getNodeId());
} else {
UserRespDTO user = memberUserApi.getUser(reqVO.getMemberId());
List<NodeRespDTO> nodes = null;
// 如果用户没有填写国家或城市默认展示中国的礼品
if (user.getCity() == null || user.getCountry() == null) {
nodes = nodeApi.getNodesByCity(null,130L);
} else {
nodes = nodeApi.getNodesByCity(user.getCity().longValue(),null);
}
if (CollectionUtil.isNotEmpty(nodes)) {
rewardDOLambdaQuery.in(RewardDO::getNodeId, nodes.stream().map(NodeRespDTO::getId).collect(Collectors.toList()));
}
}
List<RewardDO> rewardDOS = rewardMapper.selectList(rewardDOLambdaQuery);
if (rewardDOS != null && !rewardDOS.isEmpty()) {
return rewardDOS.stream().map(RewardConvert.INSTANCE::convertAppVO).collect(Collectors.toList());
}
return Collections.EMPTY_LIST;
}
/**
* 生成礼品ID
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment