/**
* 严肃声明:
* 开源版本请务必保留此注释头信息,若删除我方将保留所有法律责任追究!
* 本系统已申请软件著作权,受国家版权局知识产权以及国家计算机软件著作权保护!
* 可正常分享和学习源码,不得用于违法犯罪活动,违者必究!
* Copyright (c) 2019-2020 十三 all rights reserved.
* 版权所有,侵权必究!
*/
package ltd.newbee.mall.service.impl;
import ltd.newbee.mall.common.*;
import ltd.newbee.mall.controller.vo.*;
import ltd.newbee.mall.dao.NewBeeMallGoodsMapper;
import ltd.newbee.mall.dao.NewBeeMallOrderItemMapper;
import ltd.newbee.mall.dao.NewBeeMallOrderMapper;
import ltd.newbee.mall.dao.NewBeeMallShoppingCartItemMapper;
import ltd.newbee.mall.entity.NewBeeMallGoods;
import ltd.newbee.mall.entity.NewBeeMallOrder;
import ltd.newbee.mall.entity.NewBeeMallOrderItem;
import ltd.newbee.mall.entity.StockNumDTO;
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;
@Override
public PageResult getNewBeeMallOrdersPage(PageQueryUtil pageUtil) {
List<NewBeeMallOrder> newBeeMallOrders = newBeeMallOrderMapper.findNewBeeMallOrderList(pageUtil);
int total = newBeeMallOrderMapper.getTotalNewBeeMallOrders(pageUtil);
PageResult pageResult = new PageResult(newBeeMallOrders, total, pageUtil.getLimit(), pageUtil.getPage());
return pageResult;
}
@Override
@Transactional
public String updateOrderInfo(NewBeeMallOrder newBeeMallOrder) {
NewBeeMallOrder temp = newBeeMallOrderMapper.selectByPrimaryKey(newBeeMallOrder.getOrderId());
//不为空且orderStatus>=0且状态为出库之前可以修改部分信息
if (temp != null && temp.getOrderStatus() >= 0 && temp.getOrderStatus() < 3) {
temp.setTotalPrice(newBeeMallOrder.getTotalPrice());
temp.setUserAddress(newBeeMallOrder.getUserAddress());
temp.setUpdateTime(new Date());
if (newBeeMallOrderMapper.updateByPrimaryKeySelective(temp) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
}
return ServiceResultEnum.DB_ERROR.getResult();
}
return ServiceResultEnum.DATA_NOT_EXIST.getResult();
}
@Override
@Transactional
public String checkDone(Long[] ids) {
//查询所有的订单 判断状态 修改状态和更新时间
List<NewBeeMallOrder> orders = newBeeMallOrderMapper.selectByPrimaryKeys(Arrays.asList(ids));
String errorOrderNos = "";
if (!CollectionUtils.isEmpty(orders)) {
for (NewBeeMallOrder newBeeMallOrder : orders) {
if (newBeeMallOrder.getIsDeleted() == 1) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
continue;
}
if (newBeeMallOrder.getOrderStatus() != 1) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
}
}
if (!StringUtils.hasText(errorOrderNos)) {
//订单状态正常 可以执行配货完成操作 修改订单状态和更新时间
if (newBeeMallOrderMapper.checkDone(Arrays.asList(ids)) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return ServiceResultEnum.DB_ERROR.getResult();
}
} else {
//订单此时不可执行出库操作
if (errorOrderNos.length() > 0 && errorOrderNos.length() < 100) {
return errorOrderNos + "订单的状态不是支付成功无法执行出库操作";
} else {
return "你选择了太多状态不是支付成功的订单,无法执行配货完成操作";
}
}
}
//未查询到数据 返回错误提示
return ServiceResultEnum.DATA_NOT_EXIST.getResult();
}
@Override
@Transactional
public String checkOut(Long[] ids) {
//查询所有的订单 判断状态 修改状态和更新时间
List<NewBeeMallOrder> orders = newBeeMallOrderMapper.selectByPrimaryKeys(Arrays.asList(ids));
String errorOrderNos = "";
if (!CollectionUtils.isEmpty(orders)) {
for (NewBeeMallOrder newBeeMallOrder : orders) {
if (newBeeMallOrder.getIsDeleted() == 1) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
continue;
}
if (newBeeMallOrder.getOrderStatus() != 1 && newBeeMallOrder.getOrderStatus() != 2) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
}
}
if (!StringUtils.hasText(errorOrderNos)) {
//订单状态正常 可以执行出库操作 修改订单状态和更新时间
if (newBeeMallOrderMapper.checkOut(Arrays.asList(ids)) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return ServiceResultEnum.DB_ERROR.getResult();
}
} else {
//订单此时不可执行出库操作
if (errorOrderNos.length() > 0 && errorOrderNos.length() < 100) {
return errorOrderNos + "订单的状态不是支付成功或配货完成无法执行出库操作";
} else {
return "你选择了太多状态不是支付成功或配货完成的订单,无法执行出库操作";
}
}
}
//未查询到数据 返回错误提示
return ServiceResultEnum.DATA_NOT_EXIST.getResult();
}
@Override
@Transactional
public String closeOrder(Long[] ids) {
//查询所有的订单 判断状态 修改状态和更新时间
List<NewBeeMallOrder> orders = newBeeMallOrderMapper.selectByPrimaryKeys(Arrays.asList(ids));
String errorOrderNos = "";
if (!CollectionUtils.isEmpty(orders)) {
for (NewBeeMallOrder newBeeMallOrder : orders) {
// isDeleted=1 一定为已关闭订单
if (newBeeMallOrder.getIsDeleted() == 1) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
continue;
}
//已关闭或者已完成无法关闭订单
if (newBeeMallOrder.getOrderStatus() == 4 || newBeeMallOrder.getOrderStatus() < 0) {
errorOrderNos += newBeeMallOrder.getOrderNo() + " ";
}
}
if (!StringUtils.hasText(errorOrderNos)) {
//订单状态正常 可以执行关闭操作 修改订单状态和更新时间&&恢复库存
if (newBeeMallOrderMapper.closeOrder(Ar