/**
* 严肃声明:
* 开源版本请务必保留此注释头信息,若删除我方将保留所有法律责任追究!
* 本软件已申请软件著作权,受国家版权局知识产权以及国家计算机软件著作权保护!
* 可正常分享和学习源码,不得用于违法犯罪活动,违者必究!
* Copyright (c) 2019-2021 十三 all rights reserved.
* 版权所有,侵权必究!
*/
package ltd.newbee.mall.service.impl;
import ltd.newbee.mall.api.mall.vo.NewBeeMallOrderDetailVO;
import ltd.newbee.mall.api.mall.vo.NewBeeMallOrderItemVO;
import ltd.newbee.mall.api.mall.vo.NewBeeMallOrderListVO;
import ltd.newbee.mall.api.mall.vo.NewBeeMallShoppingCartItemVO;
import ltd.newbee.mall.common.*;
import ltd.newbee.mall.dao.*;
import ltd.newbee.mall.entity.*;
import ltd.newbee.mall.service.NewBeeMallOrderService;
import ltd.newbee.mall.util.BeanUtil;
import ltd.newbee.mall.util.NumberUtil;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.groupingBy;
@Service
public class NewBeeMallOrderServiceImpl implements NewBeeMallOrderService {
@Autowired
private NewBeeMallOrderMapper newBeeMallOrderMapper;
@Autowired
private NewBeeMallOrderItemMapper newBeeMallOrderItemMapper;
@Autowired
private NewBeeMallShoppingCartItemMapper newBeeMallShoppingCartItemMapper;
@Autowired
private NewBeeMallGoodsMapper newBeeMallGoodsMapper;
@Autowired
private NewBeeMallOrderAddressMapper newBeeMallOrderAddressMapper;
@Override
public NewBeeMallOrderDetailVO getOrderDetailByOrderId(Long orderId) {
NewBeeMallOrder newBeeMallOrder = newBeeMallOrderMapper.selectByPrimaryKey(orderId);
if (newBeeMallOrder == null) {
NewBeeMallException.fail(ServiceResultEnum.DATA_NOT_EXIST.getResult());
}
List<NewBeeMallOrderItem> orderItems = newBeeMallOrderItemMapper.selectByOrderId(newBeeMallOrder.getOrderId());
//获取订单项数据
if (!CollectionUtils.isEmpty(orderItems)) {
List<NewBeeMallOrderItemVO> newBeeMallOrderItemVOS = BeanUtil.copyList(orderItems, NewBeeMallOrderItemVO.class);
NewBeeMallOrderDetailVO newBeeMallOrderDetailVO = new NewBeeMallOrderDetailVO();
BeanUtil.copyProperties(newBeeMallOrder, newBeeMallOrderDetailVO);
newBeeMallOrderDetailVO.setOrderStatusString(NewBeeMallOrderStatusEnum.getNewBeeMallOrderStatusEnumByStatus(newBeeMallOrderDetailVO.getOrderStatus()).getName());
newBeeMallOrderDetailVO.setPayTypeString(PayTypeEnum.getPayTypeEnumByType(newBeeMallOrderDetailVO.getPayType()).getName());
newBeeMallOrderDetailVO.setNewBeeMallOrderItemVOS(newBeeMallOrderItemVOS);
return newBeeMallOrderDetailVO;
} else {
NewBeeMallException.fail(ServiceResultEnum.ORDER_ITEM_NULL_ERROR.getResult());
return null;
}
}
@Override
public NewBeeMallOrderDetailVO getOrderDetailByOrderNo(String orderNo, Long userId) {
NewBeeMallOrder newBeeMallOrder = newBeeMallOrderMapper.selectByOrderNo(orderNo);
if (newBeeMallOrder == null) {
NewBeeMallException.fail(ServiceResultEnum.DATA_NOT_EXIST.getResult());
}
if (!userId.equals(newBeeMallOrder.getUserId())) {
NewBeeMallException.fail(ServiceResultEnum.REQUEST_FORBIDEN_ERROR.getResult());
}
List<NewBeeMallOrderItem> orderItems = newBeeMallOrderItemMapper.selectByOrderId(newBeeMallOrder.getOrderId());
//获取订单项数据
if (!CollectionUtils.isEmpty(orderItems)) {
List<NewBeeMallOrderItemVO> newBeeMallOrderItemVOS = BeanUtil.copyList(orderItems, NewBeeMallOrderItemVO.class);
NewBeeMallOrderDetailVO newBeeMallOrderDetailVO = new NewBeeMallOrderDetailVO();
BeanUtil.copyProperties(newBeeMallOrder, newBeeMallOrderDetailVO);
newBeeMallOrderDetailVO.setOrderStatusString(NewBeeMallOrderStatusEnum.getNewBeeMallOrderStatusEnumByStatus(newBeeMallOrderDetailVO.getOrderStatus()).getName());
newBeeMallOrderDetailVO.setPayTypeString(PayTypeEnum.getPayTypeEnumByType(newBeeMallOrderDetailVO.getPayType()).getName());
newBeeMallOrderDetailVO.setNewBeeMallOrderItemVOS(newBeeMallOrderItemVOS);
return newBeeMallOrderDetailVO;
} else {
NewBeeMallException.fail(ServiceResultEnum.ORDER_ITEM_NULL_ERROR.getResult());
return null;
}
}
@Override
public PageResult getMyOrders(PageQueryUtil pageUtil) {
int total = newBeeMallOrderMapper.getTotalNewBeeMallOrders(pageUtil);
List<NewBeeMallOrder> newBeeMallOrders = newBeeMallOrderMapper.findNewBeeMallOrderList(pageUtil);
List<NewBeeMallOrderListVO> orderListVOS = new ArrayList<>();
if (total > 0) {
//数据转换 将实体类转成vo
orderListVOS = BeanUtil.copyList(newBeeMallOrders, NewBeeMallOrderListVO.class);
//设置订单状态中文显示值
for (NewBeeMallOrderListVO newBeeMallOrderListVO : orderListVOS) {
newBeeMallOrderListVO.setOrderStatusString(NewBeeMallOrderStatusEnum.getNewBeeMallOrderStatusEnumByStatus(newBeeMallOrderListVO.getOrderStatus()).getName());
}
List<Long> orderIds = newBeeMallOrders.stream().map(NewBeeMallOrder::getOrderId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(orderIds)) {
List<NewBeeMallOrderItem> orderItems = newBeeMallOrderItemMapper.selectByOrderIds(orderIds);
Map<Long, List<NewBeeMallOrderItem>> itemByOrderIdMap = orderItems.stream().collect(groupingBy(NewBeeMallOrderItem::getOrderId));
for (NewBeeMallOrderListVO newBeeMallOrderListVO : orderListVOS) {
//封装每个订单列表对象的订单项数据
if (itemByOrderIdMap.containsKey(newBeeMallOrderListVO.getOrderId())) {
List<NewBeeMallOrderItem> orderItemListTemp = itemByOrderIdMap.get(newBeeMallOrderListVO.getOrderId());
//将NewBeeMallOrderItem对象列表转换成NewBeeMallOrderItemVO对象列表
List<NewBeeMallOrderItemVO> newBeeMallOrderItemVOS = BeanUtil.copyList(orderItemListTemp, NewBeeMallOrderItemVO.class);
newBeeMallOrderListVO.setNewBeeMallOrderItemVOS(newBeeMallOrderItemVOS);
}
}
}
}
PageResult pageResult = new PageResult(orderListVOS, total, pageUtil.getLimit(), pageUtil.getPage());
return pageResult;
}
@Override
public String cancelOrder(String orderNo, Long userId) {
NewBeeMallOrder newBeeMallOrder = newBeeMallOrderMapper.selectByOrderNo(orderNo);
if (newBeeMallOrder != null) {
//todo 验证是否是当前userId下的订单,否则报错
//todo 订单状态判断
if (newBeeMallOrderMapper.closeOrder(Collections.singletonList(newBeeMallOrder.getOrderId()), NewBeeMallOrderStatusEnum.ORDER_CLOSED_BY_MALLUSER.getOrderStatus()) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return ServiceResultEnum.DB_ERROR.getResult();
}
}
return ServiceResultEnum.ORDER_NOT_EXIST_ERROR.getResult();
}
@Override
public String finishOrder(String orderNo, Long userId) {
NewBeeMallOrder newBeeMallOrder = newBeeMallOrderMapper.selectByOrderNo(orderNo);
if (newBee
季风泯灭的季节
- 粉丝: 2052
- 资源: 3370
最新资源
- 【创新无忧】基于龙格库塔优化算法RUN优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于龙格库塔优化算法RUN优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于龙格库塔优化算法RUN优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于龙格库塔优化算法RUN优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于龙格库塔优化算法RUN优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于龙格库塔优化算法RUN优化相关向量机RVM实现数据多输入单输出回归预测附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于能量谷优化算法EVO优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于麻雀搜索优化算法SSA优化相关向量机RVM实现数据多输入单输出回归预测附matlab代码.rar
- 【创新无忧】基于能量谷优化算法EVO优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于能量谷优化算法EVO优化广义神经网络GRNN实现光伏预测附matlab代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈