Commit 228c72ad authored by 332784038@qq.com's avatar 332784038@qq.com

Merge branch 'dev' into order-update

parents 6256ae58 ebfe53aa
......@@ -952,7 +952,7 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
if (Objects.isNull(consignorDO)) {//发货人客户
consignorDO = customerService.getCustomer(orderConsignorDO.getCustomerId());
}
if (Objects.isNull(consigneeDO)) {
if (Objects.isNull(consigneeDO) && Objects.nonNull(orderConsigneeDO)) {
consigneeDO = customerService.getCustomer(orderConsigneeDO.getCustomerId());//收货人客户
}
// 原客户经理
......
......@@ -3371,7 +3371,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
.collect(toList());
if (CollectionUtil.isNotEmpty(stepSpecialList)) {
Map<String, ProductPriceStepSpecialDO> stepSpecialMap = stepSpecialList.stream()
.collect(Collectors.toMap(ProductPriceStepSpecialDO::getSpecialDictType, v -> v));
.collect(Collectors.toMap(ProductPriceStepSpecialDO::getSpecialDictType, v -> v, (v1, v2) -> v2));
List<ProductPriceStepSpecialDO> dbStepSpecialList = stepSpecialGroupMap.get(dbStep.getId());
if (CollectionUtil.isEmpty(dbStepSpecialList)) continue;
for (ProductPriceStepSpecialDO dbStepSpecial : dbStepSpecialList) {
......@@ -3555,7 +3555,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
snapshotList.add(snapshot);
dbItem.setUpdater(String.valueOf(loginUserId));
updateColumn(dbItem, productPrice);
productPriceMapper.updateById(dbItem);
} else {
dbItem = ObjectUtil.clone(productPrice);
dbItem.setProductId(productDO.getId());
......@@ -3589,12 +3589,18 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
dbItem.setBlacklist(0);
dbItem.setStatus(0);
dbItem.setCreateTime(current);
productPriceMapper.insert(dbItem);
dbItem.setId(null);
}
dbItem.setUpdateTime(current);
String transportType = lineTransportTypeMap.get(lineId);
initBasePrice(dbItem, transportType);
if (Objects.isNull(dbItem.getId())){
productPriceMapper.insert(dbItem);
}else {
productPriceMapper.updateById(dbItem);
}
//添加修改日志,需要查询特需和阶梯,所以需要在修改之前执行
batchAddSnapshot(snapshotList);
......
......@@ -11,9 +11,50 @@ import java.util.List;
*/
public interface RedeemRewardApi {
/**
* 兑换礼品
*
* @param redeemRewardReqVO
* @return
*/
Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO);
/**
* 执行兑换事务
*
* @param redeemRewardReqVO
* @param pointsRequire
* @param rewardId
*/
void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId);
/**
* 批量兑换礼品
*
* @param redeemRewardReqVOList
* @return
*/
List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList);
/**
* 批量执行兑换事务
*
* @param redeemRewardReqVOList
* @param pointsRequire
* @param rewardId
*/
void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId);
/**
* 客户端获取礼品详情
* @param redeemId
* @return
*/
RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId);
/**
* 兑换礼品发送验证码
* @param memberId
*/
void sendSmsCode(Long memberId);
}
......@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
......@@ -70,7 +71,6 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
private SmsCodeApi smsCodeApi;
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO) {
UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
if (memberUser == null) {
......@@ -98,12 +98,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) {
throw exception(GET_LOCK_FAILED);
}
// 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO);
// 更新会员积分
updateMemberScore(redeemRewardReqVO, rewardDO, redeemId);
// 更新礼品
redeemReward(rewardDO, redeemRewardReqVO.getRewardCount());
RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy();
currentProxy.executeRedeem(redeemRewardReqVO, rewardDO.getPointsRequire(), rewardDO.getId());
} catch (InterruptedException e) {
throw exception(GET_LOCK_FAILED);
} finally {
......@@ -112,6 +108,17 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId) {
// 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, pointsRequire);
// 更新会员积分
updateMemberScore(redeemRewardReqVO, pointsRequire, redeemId);
// 更新礼品
redeemReward(rewardId, redeemRewardReqVO.getRewardCount());
}
private RewardDO getAndVerifyRewardDO(RedeemRewardReqVO redeemRewardReqVO) {
// 查询礼品
RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId());
......@@ -150,41 +157,42 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
}
}
private void redeemReward(RewardDO reward, Integer rewardCount) {
private void redeemReward(Long rewardId, Integer rewardCount) {
// 更新时校验礼品数量是否足够
RewardDO rewardDO = rewardMapper.selectById(reward.getId());
RewardDO rewardDO = rewardMapper.selectById(rewardId);
if (rewardDO.getQuantityRemain() < rewardCount) {
throw exception(REWARD_COUNT_NOT_ENOUGH);
}
reward.setExchangeCount(rewardDO.getExchangeCount() + 1);
reward.setQuantityRemain(rewardDO.getQuantityRemain() - rewardCount);
rewardMapper.updateById(reward);
RewardDO upReward = new RewardDO();
upReward.setId(rewardId);
upReward.setExchangeCount(rewardDO.getExchangeCount() + 1);
upReward.setQuantityRemain(rewardDO.getQuantityRemain() - rewardCount);
rewardMapper.updateById(upReward);
}
private void updateMemberScore(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO, Long redeemId) {
private void updateMemberScore(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long redeemId) {
Map<String, Object> extParam = new HashMap<>();
extParam.put("redeemId", redeemId);
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(redeemRewardReqVO.getMemberId())
.sourceType(ScoreSourceTypeEnum.EXCHANGE_REWARD)
.scoreCount(redeemRewardReqVO.getRewardCount() * rewardDO.getPointsRequire())
.scoreCount(redeemRewardReqVO.getRewardCount() * pointsRequire)
.releationId(String.valueOf(redeemId))
.uniqueId(String.valueOf(redeemId))
.extParam(extParam)
.build());
}
private Long addRedeemRecord(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO) {
private Long addRedeemRecord(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire) {
RewardRedeemDO rewardRedeemDO = BeanUtil.copyProperties(redeemRewardReqVO, RewardRedeemDO.class);
rewardRedeemDO.setId(snowflakeGenerator.next());
rewardRedeemDO.setStatus(RewardRedeemStatusEnum.REDEEMING.getValue());
rewardRedeemDO.setScoreCount(redeemRewardReqVO.getRewardCount() * rewardDO.getPointsRequire());
rewardRedeemDO.setScoreCount(redeemRewardReqVO.getRewardCount() * pointsRequire);
rewardRedeemMapper.insert(rewardRedeemDO);
return rewardRedeemDO.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList) {
// 批量兑换每次最多十条
if (redeemRewardReqVOList.size() > 10) {
......@@ -230,14 +238,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) {
throw exception(GET_LOCK_FAILED);
}
for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) {
// 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO);
// 更新会员积分
updateMemberScore(redeemRewardReqVO, rewardDO, redeemId);
// 更新礼品
redeemReward(rewardDO, redeemRewardReqVO.getRewardCount());
}
RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy();
currentProxy.batchExecuteRedeem(redeemRewardReqVOList, rewardDO.getPointsRequire(), rewardDO.getId());
} catch (ServiceException e) {
log.error("batch redeem rewards exception:{}", e.getMessage());
throw e;
......@@ -249,6 +251,14 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId) {
for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) {
executeRedeem(redeemRewardReqVO, pointsRequire, rewardId);
}
}
@Override
public RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId) {
RewardRedeemDO rewardRedeemDO = rewardRedeemMapper.selectById(redeemId);
......
......@@ -3,10 +3,12 @@ package cn.iocoder.yudao.server;
import cn.jasonone.ueditor.EnableUeditor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package}
//@EnableUeditor
@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}.server", "${yudao.info.base-package}.module"})
@EnableAspectJAutoProxy(exposeProxy = true)
public class YudaoServerApplication {
public static void main(String[] args) {
......
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