Commit 9bf98be2 authored by zhangfeng's avatar zhangfeng

客户端礼品列表

parent 6cc0b7df
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 { ...@@ -48,4 +48,7 @@ public class UserRespDTO {
private Integer holdScore; private Integer holdScore;
private Integer country;
private Integer city;
} }
...@@ -55,7 +55,7 @@ public interface ErrorCodeConstants { ...@@ -55,7 +55,7 @@ public interface ErrorCodeConstants {
ErrorCode SCORE_RULE_NOT_EXISTS = new ErrorCode(1004008010, "score.rule.not.exists"); 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_DELETE_ERROR = new ErrorCode(1004008011, "score.rule.delete.error");
ErrorCode SCORE_RULE_UPDATE_ERROR = new ErrorCode(1004008012, "score.rule.update.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_NOT_EXISTS = new ErrorCode(1004008014, "user.address.not.exists");
ErrorCode USER_ADDRESS_FIELD_ERROR = new ErrorCode(1004008015, "user.address.field.error"); ErrorCode USER_ADDRESS_FIELD_ERROR = new ErrorCode(1004008015, "user.address.field.error");
......
...@@ -185,7 +185,7 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> { ...@@ -185,7 +185,7 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
"AND u.id = #{id} ", "AND u.id = #{id} ",
"</script>" "</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}") @Update("update ecw_customer_contacts set userid = null where userid = #{userId}")
void unbindingCustomer(@Param("userId") Long userId); void unbindingCustomer(@Param("userId") Long userId);
......
...@@ -55,7 +55,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -55,7 +55,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) { public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) { 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); verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType(); Integer scoreRuleType = scoreRule.getType();
...@@ -159,9 +159,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -159,9 +159,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
StringBuilder receiveAddr = new StringBuilder(); StringBuilder receiveAddr = new StringBuilder();
for (List<Long> integers : receiveAddrList) { for (List<Long> integers : receiveAddrList) {
try { try {
targetCountry.append(integers.get(1)).append(","); targetCountry.append(integers.get(0)).append(",");
targetCity.append(integers.get(2)).append(","); targetCity.append(integers.get(1)).append(",");
receiveAddr.append(integers.get(3)).append(","); receiveAddr.append(integers.get(2)).append(",");
} catch (Exception e) { } catch (Exception e) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
......
...@@ -258,7 +258,8 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -258,7 +258,8 @@ public class MemberUserServiceImpl implements MemberUserService {
@Override @Override
public MemberUserDO info(Long id) { public MemberUserDO info(Long id) {
return memberUserMapper.info(id); // 一个会员可能绑定了多个用户
return memberUserMapper.info(id).get(0);
} }
@Override @Override
......
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; ...@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.reward.convert.reward;
import java.util.*; import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.reward.vo.reward.*; import cn.iocoder.yudao.module.reward.vo.reward.*;
...@@ -38,6 +39,12 @@ public interface RewardConvert { ...@@ -38,6 +39,12 @@ public interface RewardConvert {
*/ */
RewardBackVO convert(RewardDO bean); RewardBackVO convert(RewardDO bean);
/***
* 实体转返回VO
* @param bean
* @return
*/
AppRewardBackVO convertAppVO(RewardDO bean);
/*** /***
* 实体列表转返回VO列表 * 实体列表转返回VO列表
* @param list * @param list
......
...@@ -82,7 +82,6 @@ public class RewardDO extends BaseDO { ...@@ -82,7 +82,6 @@ public class RewardDO extends BaseDO {
private Date endTime; private Date endTime;
/** /**
* 领取方式(1上门领取,2包邮到家,3邮寄到付) * 领取方式(1上门领取,2包邮到家,3邮寄到付)
* TODO :改为枚举
*/ */
private String pickMethod; private String pickMethod;
/** /**
...@@ -103,7 +102,6 @@ public class RewardDO extends BaseDO { ...@@ -103,7 +102,6 @@ public class RewardDO extends BaseDO {
private String remarkFr; private String remarkFr;
/** /**
* 礼品状态(1已启用,2未启用,3已关闭,4已过期) * 礼品状态(1已启用,2未启用,3已关闭,4已过期)
* TODO :改为枚举
*/ */
private Integer status; private Integer status;
......
...@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.reward.service.reward; ...@@ -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.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService; import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO; 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.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.vo.reward.*; import cn.iocoder.yudao.module.reward.vo.reward.*;
...@@ -75,4 +77,11 @@ public interface RewardService extends IService<RewardDO> { ...@@ -75,4 +77,11 @@ public interface RewardService extends IService<RewardDO> {
void delayReward(RewardDelayReqVO delayVO); void delayReward(RewardDelayReqVO delayVO);
void updateStatus(RewardStatusReqVO statusVO); void updateStatus(RewardStatusReqVO statusVO);
/**
* 客户端获得礼品列表
* @param reqVO
* @return
*/
List<AppRewardBackVO> getListByMemberInfo(AppRewardListReqVO reqVO);
} }
package cn.iocoder.yudao.module.reward.service.reward; 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.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery; 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.service.AbstractService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO; 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.convert.reward.RewardConvert;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO; 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.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.QuantitativeRelationSymbolEnum; import cn.iocoder.yudao.module.reward.enums.QuantitativeRelationSymbolEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum; import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.reward.vo.reward.*; 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.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -19,10 +24,11 @@ import org.springframework.validation.annotation.Validated; ...@@ -19,10 +24,11 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; 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.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants.*;
...@@ -38,6 +44,10 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -38,6 +44,10 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
@Resource @Resource
private RewardMapper rewardMapper; private RewardMapper rewardMapper;
@Resource
private NodeApi nodeApi;
@Resource
private MemberUserApi memberUserApi;
@Override @Override
public Long create(RewardCreateReqVO createReqVO) { public Long create(RewardCreateReqVO createReqVO) {
...@@ -268,6 +278,36 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -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 * 生成礼品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