Commit 03a7d578 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score' into dev

parents 3e7053ff a7340da0
......@@ -10,9 +10,12 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.CustomerContactsDO;
import cn.iocoder.yudao.module.customer.service.customerContacts.CustomerContactsService;
import cn.iocoder.yudao.module.ecw.api.paramValid.ParamValidatorApi;
import cn.iocoder.yudao.module.ecw.dal.dataobject.region.RegionDO;
import cn.iocoder.yudao.module.ecw.service.internalMessage.InternalMessageService;
import cn.iocoder.yudao.module.ecw.service.internalMessage.WebInternalMessageService;
import cn.iocoder.yudao.module.ecw.service.region.RegionService;
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppEmailUpdateReqVO;
import cn.iocoder.yudao.module.member.service.level.MemberUserLevelConfigService;
import cn.iocoder.yudao.module.member.vo.member.MemberUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.*;
import cn.iocoder.yudao.module.member.convert.user.UserConvert;
......@@ -35,6 +38,8 @@ import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseCreateReqV
import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseUpdateReqVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthBackVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthCreateReqVO;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserLevelConfigBaseRespVO;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserScoreLevelVO;
import cn.iocoder.yudao.module.product.service.coupon.CouponService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
......@@ -98,6 +103,12 @@ public class AppUserController {
@Resource
private PasswordEncoder passwordEncoder;
@Resource
private MemberUserLevelConfigService memberUserLevelConfigService;
@Resource
private RegionService regionService;
@PutMapping("/update-nickname")
@ApiOperation("修改用户昵称")
......@@ -146,6 +157,26 @@ public class AppUserController {
if (passwordEncoder.matches("88888888", user.getPassword())) {
respVO.setIsSimplePassword(Boolean.TRUE);
}
MemberUserLevelConfigBaseRespVO userScoreLevelVO = memberUserLevelConfigService.getLevelByCount(user.getTotalScore());
MemberUserScoreLevelVO scoreLevelVO = MemberUserScoreLevelVO.builder().memberId(user.getId())
.memberCode(user.getMemberCode())
.holdScore(user.getHoldScore())
.expiredScore(user.getExpiredScore())
.usedScore(user.getUsedScore())
.levelIcon(userScoreLevelVO.getIcon())
.levelName(userScoreLevelVO.getName())
.build();
respVO.setUserScoreLevelInfo(scoreLevelVO);
if (user.getCountry() != null) {
RegionDO region = regionService.getRegion(Long.valueOf(user.getCountry()));
respVO.setCountryTitleEn(region.getTitleEn());
respVO.setCountryTitleZh(region.getTitleZh());
}
if (user.getCity() != null) {
RegionDO region = regionService.getRegion(Long.valueOf(user.getCity()));
respVO.setCityTitleEn(region.getTitleEn());
respVO.setCityTitleZh(region.getTitleZh());
}
return success(respVO);
}
......
package cn.iocoder.yudao.module.member.controller.app.user.vo;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserScoreLevelVO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -67,4 +68,14 @@ public class AppUserInfoRespVO {
@ApiModelProperty(value = "是否简单密码", example = "false")
private Boolean isSimplePassword = Boolean.FALSE;
@ApiModelProperty(value = "会员积分信息")
private MemberUserScoreLevelVO userScoreLevelInfo;
@ApiModelProperty(value = "会员国家中文")
private String countryTitleZh;
@ApiModelProperty(value = "会员国家英文")
private String countryTitleEn;
@ApiModelProperty(value = "会员城市中文")
private String cityTitleZh;
@ApiModelProperty(value = "会员国家英文")
private String cityTitleEn;
}
......@@ -10,6 +10,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 会员积分规则 Redis DAO
......@@ -57,7 +58,7 @@ public class ScoreRuleRedisDao {
ScoreRuleOrderVExtraVO scoreRuleOrderVExtraVO = JsonUtils.parseObject(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), scoreRuleOrderVExtraVO.getTransportType()), JsonUtils.toJsonString(scoreRuleDO));
}
stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), null), JsonUtils.toJsonString(scoreRuleDO));
stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), null), JsonUtils.toJsonString(scoreRuleDO),24L, TimeUnit.HOURS);
}
public void deleteEnableScoreRule(Integer type) {
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.boot.module.order.api.OrderApi;
import cn.iocoder.boot.module.order.api.dto.OrderItemRespDTO;
import cn.iocoder.boot.module.order.api.dto.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import cn.iocoder.boot.module.order.enums.OrderStatusApiEnum;
......@@ -20,14 +21,13 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
/**
* @author zhangfeng
......@@ -40,14 +40,15 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
@Resource
private CustomerContactsService customerContactsService;
public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService,MemberUserScoreApi memberUserScoreApi) {
super(scoreRuleService, memberUserScoreLogService, memberUserService,memberUserScoreApi);
public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService, MemberUserScoreApi memberUserScoreApi) {
super(scoreRuleService, memberUserScoreLogService, memberUserService, memberUserScoreApi);
}
@Override
public void addScore(ScoreMessage message) {
log.info("Received order V message,orderID:{}", message.getOrderId());
Long orderId = message.getOrderId();
// 获取订单信息
OrderRespDTO order;
try {
order = orderApi.getOrder(orderId, "");
......@@ -63,116 +64,215 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
if (!Objects.equals(order.getStatus(), OrderStatusApiEnum.IN_SHIPPING.getValue())) {
return;
}
// 判断海运空运
// 获取订单规则
Integer transportId = order.getTransportId();
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.ORDER_V, TransportTypeEnum.parseByValue(transportId));
if (Objects.isNull(scoreRuleDO)) {
log.info("Order in shipping listener: No score rule match,orderID:{}", orderId);
return;
}
// 目的地信息
// 规则是否包含目的地提货点
OrderObjectiveApiDO orderObjectiveDO = order.getOrderObjectiveDO();
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
// 提货点是否包含
String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
return;
}
// 获取需要添加积分的用户
List<Long> userIds = getAddScoreUser(order, extraInfo, scoreRuleDO);
if (CollectionUtil.isEmpty(userIds)) {
log.info("Order in shipping listener: The customer is not bound to the member or have default userId, customerId:{}", order.getCustomerId());
return;
}
// 计算积分
List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules = extraInfo.getOrderVRule();
Integer scoreCount = getScoreCount(transportId, order.getChannelId(), extraInfo.getChannel(), extraInfo.getOrderVRule(), orderId);
if (scoreCount == 0) {
log.info("Order in shipping listener: The score count is less than or equal to 0,orderId:{}", orderId);
return;
}
// 增加积分
for (Long userId : userIds) {
try {
HashMap<String, Object> map = new HashMap<>();
map.put("orderId", orderId);
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(userId)
.scoreCount(scoreCount)
.sourceType(ScoreSourceTypeEnum.ORDER_V)
.ruleId(scoreRuleDO.getId())
.expireDays(scoreRuleDO.getScorePeriod())
.releationId(String.valueOf(orderId))
.uniqueId(orderId + "_" + userId)
.extParam(map)
.build()
);
log.info("Order V rule add score success,ruleID:{},orderID:{},userID:{}", scoreRuleDO.getId(), message.getOrderId(), userId);
} catch (Exception e) {
log.error("Order in shipping listener: operateScore error", e);
}
}
}
/**
* 根据规则获得要加多少分
*
* @param transportId
* @param channelId
* @param allowChannels
* @param orderVRules
* @param orderId
* @return
*/
private Integer getScoreCount(Integer transportId, Long channelId, String allowChannels, List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules, Long orderId) {
Integer scoreCount = 0;
// TODO:体积和重量取的字段确认
List<OrderItemRespDTO> orderItems = orderApi.getOrderItemsByOrderId(orderId);
if (orderItems == null) {
log.info("Order in shipping listener: The order item is null,orderId:{}", orderId);
return 0;
}
BigDecimal totalWeight = BigDecimal.ZERO;
BigDecimal totalVolume = BigDecimal.ZERO;
for (OrderItemRespDTO orderItem : orderItems) {
totalWeight = totalWeight.add(orderItem.getChargeWeight());
totalVolume = totalVolume.add(orderItem.getChargeVolume());
}
if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
// 海运算重量
BigDecimal orgVWeight = order.getOrgVWeight();
scoreCount = computeScoreCount(orgVWeight, orderVRules);
// 海运算体积
scoreCount = computeScoreCount(totalVolume, orderVRules);
} else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
// 空运校验渠道
// 渠道id
Long channelId = order.getChannelId();
String[] channels = extraInfo.getChannel().split(",");
String[] channels = allowChannels.split(",");
if (!ArrayUtil.contains(channels, channelId.toString())) {
return;
return 0;
}
// 空运算体积
BigDecimal orgWVolume = order.getOrgWVolume();
scoreCount = computeScoreCount(orgWVolume, orderVRules);
}
if (scoreCount <= 0) {
log.info("Order in shipping listener: The score count is less than or equal to 0,orderId:{}", orderId);
return;
// 空运算重量
scoreCount = computeScoreCount(totalWeight, orderVRules);
}
return scoreCount;
}
// 会员id
/**
* 获取需要加分的用户
*
* @param order
* @param extraInfo
* @param scoreRuleDO
* @return
*/
private List<Long> getAddScoreUser(OrderRespDTO order, ScoreRuleOrderVExtraVO extraInfo, ScoreRuleDO scoreRuleDO) {
ArrayList<Long> users = new ArrayList<>();
// 发货人和收货人都要判断给分
Long userId = order.getUserId();
// 订单入口
String orderEntryString = extraInfo.getOrderEntry();
if (StringUtils.isBlank(orderEntryString)) {
log.info("Order in shipping listener: orderEntry is null,scoreRuleID:{}", scoreRuleDO.getId());
return;
Long consigneeId = order.getOrderConsigneeDO().getCustomerId();
Long consigneeMemberId;
boolean isBackendOrder = userId <= 0;
// 校验订单入口
if (!isOrderEntryValid(extraInfo.getOrderEntry(), isBackendOrder)) {
return null;
}
String[] orderEntry = orderEntryString.split(",");
if (userId <= 0) {
// 后台下单
if (!ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.BACKEND.getValue()))) {
log.info("Order in shipping listener: The order is placed by the background, userId:{}", userId);
return;
}
// 查询客户绑定会员
List<CustomerContactsDO> customerContacts = customerContactsService.getCustomerContactsListByCustomerId(order.getCustomerId());
if (CollectionUtil.isEmpty(customerContacts)) {
log.info("Order in shipping listener: The customer is not bound to the member, customerId:{}", order.getCustomerId());
return;
// 如果是后台下单,重新获取用户ID
if (isBackendOrder) {
userId = getCustomerMemberId(order.getCustomerId());
if (userId == null) {
userId = 0L;
}
for (CustomerContactsDO customerContact : customerContacts) {
if (customerContact.getIsDefault() == 1 && customerContact.getUserid() != null) {
userId = customerContact.getUserid();
}
}
if (userId <= 0) {
log.info("Order in shipping listener: The customer is not have default userId, customerId:{}", order.getCustomerId());
return;
}
// 校验首单
if (!isFirstOrderValid(userId, extraInfo)) {
return null;
}
// 校验积分上限,添加加分用户列表
if (isBackendOrder && isUserScoreMaxed(userId, scoreRuleDO)) {
log.info("Order in shipping listener: The user has reached the maximum score, userId:{}, scoreRuleId:{}", userId, scoreRuleDO.getId());
} else {
addValidUser(users, userId);
}
consigneeMemberId = getCustomerMemberId(consigneeId);
if (consigneeMemberId != null && consigneeMemberId > 0) {
if (consigneeMemberId.equals(userId)) {
log.info("Order in shipping listener: The consignee is the same as the sender, userId:{}", userId);
} else if (isBackendOrder && isUserScoreMaxed(consigneeMemberId, scoreRuleDO)) {
log.info("Order in shipping listener: The consignee has reached the maximum score, userId:{}, scoreRuleId:{}", consigneeMemberId, scoreRuleDO.getId());
} else {
users.add(consigneeMemberId);
}
} else if (!ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.APP.getValue())) && !ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.WEB.getValue()))) {
log.info("Order in shipping listener: The order is placed by the app or web, userId:{}", userId);
return;
}
// 是否首单,首单只加一次
return users;
}
/**
* 校验订单入口是否有效
*/
private boolean isOrderEntryValid(String orderEntryString, boolean isBackendOrder) {
if (StringUtils.isBlank(orderEntryString)) {
log.info("Order in shipping listener: orderEntry is null");
return false;
}
String[] orderEntry = orderEntryString.split(",");
if (isBackendOrder) {
return ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.BACKEND.getValue()));
} else {
return ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.APP.getValue())) ||
ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.WEB.getValue()));
}
}
/**
* 校验是否为首单且首单是否有效
*/
private boolean isFirstOrderValid(Long userId, ScoreRuleOrderVExtraVO extraInfo) {
if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()) {
if (userId == null || userId <= 0) {
log.info("Order in shipping listener: The user is not member,userId:{}", userId);
return false;
}
if (!orderApi.isFirstOrder(userId)) {
log.info("Order in shipping listener: Not first orderuserId:{}", userId);
return;
log.info("Order in shipping listener: Not first order,userId:{}", userId);
return false;
}
}
// 校验累计最高分
// maxScoreTotal为0时为不限制积分
Integer userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
if (scoreRuleDO.getMaxScoreTotal() > 0 && userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal()) {
log.info("Order in shipping listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId());
return;
return true;
}
/**
* 校验用户积分是否达到上限
*/
private boolean isUserScoreMaxed(Long userId, ScoreRuleDO scoreRuleDO) {
if (scoreRuleDO.getMaxScoreTotal() > 0) {
int userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
return userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal();
}
//if (userScoreTotalCount + scoreCount > scoreRuleDO.getMaxScoreTotal()) {
// scoreCount = scoreRuleDO.getMaxScoreTotal() - userScoreTotalCount;
//}
// 增加积分
try {
HashMap<String, Object> map = new HashMap<>();
map.put("orderId", orderId);
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(userId)
.scoreCount(scoreCount)
.sourceType(ScoreSourceTypeEnum.ORDER_V)
.ruleId(scoreRuleDO.getId())
.expireDays(scoreRuleDO.getScorePeriod())
.releationId(String.valueOf(orderId))
.uniqueId(String.valueOf(orderId))
.extParam(map)
.build()
);
} catch (Exception e) {
log.error("Order in shipping listener: operateScore error", e);
return false;
}
/**
* 添加符合条件的用户到列表
*/
private void addValidUser(List<Long> users, Long userId) {
if (userId != null && userId > 0) {
users.add(userId);
}
}
/**
* 根据客户id获取会员id
*
* @param customerId
* @return
*/
private Long getCustomerMemberId(Long customerId) {
List<CustomerContactsDO> customerContacts = customerContactsService.getCustomerContactsListByCustomerId(customerId);
if (!CollectionUtil.isEmpty(customerContacts)) {
log.info("Order in shipping listener: The customer is not bound to the member, customerId:{}", customerId);
for (CustomerContactsDO customerContact : customerContacts) {
if (customerContact.getIsDefault() == 1 && customerContact.getUserid() != null) {
return customerContact.getUserid();
}
}
}
log.info("Order V rule add score success,ruleID:{},orderID:{},userID:{}", scoreRuleDO.getId(), message.getOrderId(), userId);
return null;
}
@Override
......
......@@ -415,15 +415,11 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (enableScoreRule == null) {
return null;
}
// 校验一下活动开始结束时间
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
scoreRuleRedisDao.setEnableScoreRule(enableScoreRule);
} else {
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
// 校验一下活动开始结束时间
}
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
return enableScoreRule;
}
......@@ -439,14 +435,10 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (enableScoreRule == null) {
return null;
}
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
scoreRuleRedisDao.setEnableScoreRule(enableScoreRule);
} else {
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
}
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
return enableScoreRule;
case RECOMMEND:
......
package cn.iocoder.boot.module.order.api;
import cn.iocoder.boot.module.order.api.dto.OrderItemRespDTO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import java.util.List;
/**
* 订单 api
*/
......@@ -14,4 +17,8 @@ public interface OrderApi {
* 判断是否用户首单
*/
boolean isFirstOrder(Long userId);
/**
* 根据订单id获取所有订单项
*/
List<OrderItemRespDTO> getOrderItemsByOrderId(Long orderId);
}
package cn.iocoder.boot.module.order.api.dto;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
/**
* 订单收货人信息 DO
*
* @author 系统管理员
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OrderConsigneeApiDO extends BaseDO {
/**
* 主键ID
*/
@TableId
private Long id;
/**
* 下单用户id
*/
private Long relationId;
/**
* 订单id
*/
private Long orderId;
/**
* 收货人姓名
*/
private String name;
/**
* 收货人姓名(英文)
*/
private String nameEn;
/**
* 手机
*/
private String phone;
/**
* 邮箱
*/
private String email;
/**
* 公司
*/
private String company;
/**
* 公司(英文)
*/
private String companyEn;
@ApiModelProperty(value = "收获方式:1 自提 2 送货上门 ")
private Integer harvestMethod;
@ApiModelProperty(value = "送货时间", required = true)
private String deliveryDate;
/**
* 地址
*/
private String address;
@ApiModelProperty(value = "国家")
private Long country;
@ApiModelProperty(value = "省")
private Long province;
@ApiModelProperty(value = "市")
private Long city;
/**
* 国家简称
*/
private String countryAbbreviation;
/**
* 国家区号
*/
private String countryCode;
/**
* 客户id
*/
private Long customerId;
/**
* 客户联系人id
*/
private Long customerContactsId;
public void setCountryCode(String countryCode) {
if (StringUtils.isNotBlank(countryCode)) {
this.countryCode = countryCode.replace("+", "");
}else {
this.countryCode = countryCode;
}
}
}
package cn.iocoder.boot.module.order.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderItemRespDTO {
@ApiModelProperty(value = "收费重量")
private BigDecimal chargeWeight;
@ApiModelProperty(value = "收费体积")
private BigDecimal chargeVolume;
}
......@@ -278,6 +278,11 @@ public class OrderRespDTO {
@NotNull(message = "目的地信息不能为空")
private OrderObjectiveApiDO orderObjectiveDO;
@TableField(exist = false)
@ApiModelProperty(value = "收货人信息")
@NotNull(message = "收货人信息不能为空")
private OrderConsigneeApiDO orderConsigneeDO;
@TableField(exist = false)
@ApiModelProperty(value = "目的地ID")
private Long objectiveId;
......
package cn.iocoder.yudao.module.order.api;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.boot.module.order.api.OrderApi;
import cn.iocoder.boot.module.order.api.dto.OrderConsigneeApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderItemRespDTO;
import cn.iocoder.boot.module.order.api.dto.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderConsignee.OrderConsigneeDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderItem.OrderItemDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO;
import cn.iocoder.yudao.module.order.service.order.OrderConsigneeService;
import cn.iocoder.yudao.module.order.service.order.OrderObjectiveService;
import cn.iocoder.yudao.module.order.service.order.OrderService;
import cn.iocoder.yudao.module.order.service.order.impl.OrderItemServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Validated
......@@ -21,6 +30,10 @@ public class OrderApiImpl implements OrderApi {
private OrderService orderService;
@Resource
private OrderObjectiveService objectiveService;
@Resource
private OrderConsigneeService orderConsigneeService;
@Resource
private OrderItemServiceImpl orderItemService;
@Override
public OrderRespDTO getOrder(Long id, String orderNo) {
......@@ -36,13 +49,22 @@ public class OrderApiImpl implements OrderApi {
OrderRespDTO orderRespDTO = new OrderRespDTO();
BeanUtils.copyProperties(orderDO, orderRespDTO);
// 设置目的地信息
OrderObjectiveDO orderObjectiveDO = objectiveService.getByOrderId(id);
if (orderObjectiveDO == null) {
return orderRespDTO;
if (orderObjectiveDO != null) {
OrderObjectiveApiDO orderObjectiveApiDO = new OrderObjectiveApiDO();
BeanUtils.copyProperties(orderObjectiveDO, orderObjectiveApiDO);
orderRespDTO.setOrderObjectiveDO(orderObjectiveApiDO);
}
OrderObjectiveApiDO orderObjectiveApiDO = new OrderObjectiveApiDO();
BeanUtils.copyProperties(orderObjectiveDO, orderObjectiveApiDO);
orderRespDTO.setOrderObjectiveDO(orderObjectiveApiDO);
// 设置收货人信息
OrderConsigneeDO orderConsigneeByOrderId = orderConsigneeService.getOrderConsigneeByOrderId(id);
if (orderConsigneeByOrderId != null) {
OrderConsigneeApiDO orderConsigneeApiDO = new OrderConsigneeApiDO();
BeanUtils.copyProperties(orderConsigneeByOrderId, orderConsigneeApiDO);
orderRespDTO.setOrderConsigneeDO(orderConsigneeApiDO);
}
return orderRespDTO;
}
......@@ -51,4 +73,13 @@ public class OrderApiImpl implements OrderApi {
Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, userId));
return count <= 0;
}
@Override
public List<OrderItemRespDTO> getOrderItemsByOrderId(Long orderId) {
List<OrderItemDO> orderItemDOS = orderItemService.selectList("order_id", orderId);
if (CollectionUtil.isNotEmpty(orderItemDOS)) {
return orderItemDOS.stream().map(orderItemDO -> new OrderItemRespDTO(orderItemDO.getChargeWeight(), orderItemDO.getChargeVolume())).collect(Collectors.toList());
}
return null;
}
}
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