|
|
@@ -17,6 +17,7 @@
|
|
|
package org.springblade.salesPart.order.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -34,12 +35,14 @@ import org.springblade.salesPart.corps.mapper.CorpsDescMapper;
|
|
|
import org.springblade.salesPart.entity.*;
|
|
|
import org.springblade.salesPart.enums.OrderTypeEnum;
|
|
|
import org.springblade.salesPart.goods.mapper.GoodsDescMapper;
|
|
|
+import org.springblade.salesPart.history.mapper.HistoryMapper;
|
|
|
import org.springblade.salesPart.order.mapper.OrderItemsMapper;
|
|
|
import org.springblade.salesPart.order.mapper.OrderMapper;
|
|
|
import org.springblade.salesPart.order.service.IOrderService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springblade.salesPart.payment.mapper.PaymentMapper;
|
|
|
import org.springblade.salesPart.productLaunch.mapper.ProductLaunchMapper;
|
|
|
+import org.springblade.salesPart.ship.mapper.ShipItemsMapper;
|
|
|
import org.springblade.salesPart.ship.mapper.ShipMapper;
|
|
|
import org.springblade.salesPart.stock.mapper.StockDescMapper;
|
|
|
import org.springblade.salesPart.storage.mapper.StorageDescMapper;
|
|
|
@@ -52,9 +55,14 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.MathContext;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+import static org.springblade.core.secure.utils.AuthUtil.getUser;
|
|
|
|
|
|
/**
|
|
|
* 配件销售采购表 服务实现类
|
|
|
@@ -74,6 +82,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
|
|
|
private final OrderItemsMapper orderItemsMapper;
|
|
|
private final ShipMapper shipMapper;
|
|
|
+ private final ShipItemsMapper shipItemsMapper;
|
|
|
private final CorpsDescMapper corpsDescMapper;
|
|
|
private final StorageDescMapper storageDescMapper;
|
|
|
private final PaymentMapper paymentMapper;
|
|
|
@@ -81,6 +90,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
private final ProductLaunchMapper productLaunchMapper;
|
|
|
private final GoodsDescMapper goodsDescMapper;
|
|
|
private final ISysClient sysClient;
|
|
|
+ private final HistoryMapper historyMapper;
|
|
|
|
|
|
/**
|
|
|
* 获取销售订单详情
|
|
|
@@ -528,9 +538,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
throw new SecurityException("操作失败,请联系管理员");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- declare.setStatus("退款中");
|
|
|
- order.setCheckStatus("审核请核");
|
|
|
+ declare.setOriginalStatus(declare.getStatus());
|
|
|
+ declare.setStatus("退款请核");
|
|
|
+ declare.setCheckStatus("审核请核");
|
|
|
baseMapper.updateById(declare);
|
|
|
|
|
|
return declare;
|
|
|
@@ -540,16 +550,185 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
* 退款审批通过
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R passCheck(Long id) {
|
|
|
PjOrder order = baseMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
throw new SecurityException("审批通过失败");
|
|
|
}
|
|
|
- if (order.getStatus() == "已取消") {
|
|
|
- throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ if (OrderTypeEnum.SHIPED.getType().equals(order.getOriginalStatus())){//已发货
|
|
|
+ if ("退款中".equals(order.getStatus())) {
|
|
|
+ throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OrderTypeEnum.WEB.getType().equals(order.getBusinessSource())){
|
|
|
+ order.setStatus("退款中");
|
|
|
+ }else {
|
|
|
+ order.setStatus("退款中");
|
|
|
+ order.setXcxStatus("退款中");
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成退货入库单
|
|
|
+ PjShip pjShip = new PjShip();
|
|
|
+ // 获取系统编号
|
|
|
+ R billNo = serialClient.getBillNo(OrderTypeEnum.TKSHGD.getType(), OrderTypeEnum.TKSHGD.getType(), OrderTypeEnum.TKSHGD.getType());
|
|
|
+ if (billNo.getCode() != 200) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(order,pjShip);
|
|
|
+ pjShip.setId(null);
|
|
|
+ pjShip.setBillno((String) billNo.getData());
|
|
|
+ pjShip.setOrdNo(order.getOrdNo());
|
|
|
+ pjShip.setOrdId(order.getId());
|
|
|
+ pjShip.setSrcOrdNo(order.getSrcOrdNo());
|
|
|
+ pjShip.setStatusName(OrderTypeEnum.TREATWAREHOUSING.getType());
|
|
|
+ pjShip.setBsType(order.getBusinessSource());
|
|
|
+ pjShip.setTenantId(AuthUtil.getTenantId());
|
|
|
+ pjShip.setBizTypeName(OrderTypeEnum.TKSHGD.getType());
|
|
|
+ pjShip.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ pjShip.setCreateUser(AuthUtil.getUserId());
|
|
|
+ pjShip.setCreateTime(new Date());
|
|
|
+ shipMapper.insert(pjShip);
|
|
|
+
|
|
|
+ //根据主表id获得明细数据
|
|
|
+ List<PjOrderItems> list = orderItemsMapper.selectList(new QueryWrapper<PjOrderItems>()
|
|
|
+ .eq("pid", order.getId())
|
|
|
+ .eq("is_deleted", 0)
|
|
|
+ .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(list)){
|
|
|
+ list.forEach(e -> {
|
|
|
+ //根据销售明细创建入库工单明细
|
|
|
+ PjShipItems shipItems = new PjShipItems();
|
|
|
+ BeanUtil.copyProperties(e, shipItems);
|
|
|
+
|
|
|
+ shipItems.setId(null);
|
|
|
+ shipItems.setPid(pjShip.getId());
|
|
|
+ shipItems.setSrcItemId(e.getId());
|
|
|
+ shipItems.setCreateTime(new Date());
|
|
|
+ shipItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ shipItems.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ shipItems.setSendNum(e.getGoodsNum());
|
|
|
+ shipItemsMapper.insert(shipItems);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成历史记录
|
|
|
+ saveHistory(order.getId(), "退款中");
|
|
|
+
|
|
|
+ }else {//未发货
|
|
|
+ if ("已取消".equals(order.getStatus()) && OrderTypeEnum.WEB.getType().equals(order.getBusinessSource())) {
|
|
|
+ throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ }else if ("已退款".equals(order.getStatus()) && OrderTypeEnum.XCX.getType().equals(order.getBusinessSource())) {
|
|
|
+ throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改库存账信息
|
|
|
+ //根据主表id获得明细数据
|
|
|
+ List<PjOrderItems> list = orderItemsMapper.selectList(new QueryWrapper<PjOrderItems>()
|
|
|
+ .eq("pid", order.getId())
|
|
|
+ .eq("is_deleted", 0)
|
|
|
+ .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ list.forEach(item -> {
|
|
|
+ if (item.getId() == null){
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(order.getId());
|
|
|
+ item.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItemsMapper.insert(item);
|
|
|
+ }else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(order.getId());
|
|
|
+ orderItemsMapper.updateById(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)){
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, order.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, goodsDesc.getId())
|
|
|
+ .eq(PjStockDesc::getStorageId, order.getStorageId());
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && goodsDesc.getWhether().equals("1")){//管理批次号
|
|
|
+ if (ObjectUtil.isEmpty(item.getDot())){
|
|
|
+ throw new RuntimeException(goodsDesc.getCname() + "已开启批次号管理,请填写批次号");
|
|
|
+ }
|
|
|
+ lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ }else {
|
|
|
+ lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ }
|
|
|
+
|
|
|
+ PjStockDesc stockOne = stockDescMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (ObjectUtil.isEmpty(stockOne)){
|
|
|
+ throw new RuntimeException("获取库存账失败");
|
|
|
+ }else {
|
|
|
+ stockOne.setUpdateTime(new Date());
|
|
|
+ stockOne.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ stockOne.setBalanceQuantity(stockOne.getBalanceQuantity().add(item.getSendNum()));
|
|
|
+ stockOne.setStoreInventory(stockOne.getBalanceQuantity());
|
|
|
+
|
|
|
+ BigDecimal inventoryAmount = item.getSendNum().multiply(item.getPrice());
|
|
|
+ stockOne.setInventoryAmount(stockOne.getInventoryAmount().add(inventoryAmount));
|
|
|
+
|
|
|
+ stockOne.setInventoryCostPrice(stockOne.getInventoryAmount().divide(stockOne.getBalanceQuantity(), MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ stockDescMapper.updateById(stockOne);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** ----------------------修改上架库存---------------------- */
|
|
|
+
|
|
|
+ //查询所有该商品的库存
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperList = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapperList.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, order.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, goodsDesc.getId());
|
|
|
+ List<PjStockDesc> stockDescList = stockDescMapper.selectList(lambdaQueryWrapperList);
|
|
|
+
|
|
|
+ //库存总数量
|
|
|
+ BigDecimal balanceQuantity = stockDescList.stream().map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, order.getSalesCompanyId())
|
|
|
+ .eq(PjProductLaunch::getGoodsId, stockOne.getGoodsId());
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchMapper.selectList(productLaunchQueryWrapper);
|
|
|
+
|
|
|
+ //修改上架数量
|
|
|
+ if (ObjectUtil.isNotEmpty(productLaunch)){
|
|
|
+ productLaunch.forEach(e -> {
|
|
|
+ e.setInventory(balanceQuantity);
|
|
|
+ productLaunchMapper.updateById(e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** ----------------------修改上架库存---------------------- */
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成历史记录
|
|
|
+ saveHistory(order.getId(), "已退款");
|
|
|
+
|
|
|
+ if (OrderTypeEnum.WEB.getType().equals(order.getBusinessSource())){
|
|
|
+ order.setStatus("已取消");
|
|
|
+ }else {
|
|
|
+ order.setStatus("已退款");
|
|
|
+ order.setXcxStatus("已退款");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- order.setStatus("已取消");
|
|
|
order.setCheckStatus("审核完成");
|
|
|
baseMapper.updateById(order);
|
|
|
|
|
|
@@ -560,12 +739,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
* 审核中
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R underReview(Long id) {
|
|
|
PjOrder order = baseMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
throw new SecurityException("审批通过失败");
|
|
|
}
|
|
|
|
|
|
+ order.setStatus("审批中");
|
|
|
order.setCheckStatus("审批中");
|
|
|
baseMapper.updateById(order);
|
|
|
|
|
|
@@ -576,17 +758,55 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
* 审核不通过
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R passCancel(Long id) {
|
|
|
PjOrder order = baseMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
throw new SecurityException("审批驳回失败");
|
|
|
}
|
|
|
|
|
|
- order.setStatus("审批驳回");
|
|
|
+ order.setStatus(order.getOriginalStatus());
|
|
|
order.setCheckStatus("审批驳回");
|
|
|
baseMapper.updateById(order);
|
|
|
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 销售确认退款
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void confirmRefund(PjOrder order) {
|
|
|
+ if (order.getId() == null){
|
|
|
+ throw new RuntimeException("确认退款失败,数据异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OrderTypeEnum.WEB.getType().equals(order.getBusinessSource())){
|
|
|
+ order.setStatus("已取消");
|
|
|
+ }else {
|
|
|
+ order.setStatus("已退款");
|
|
|
+ order.setXcxStatus("已退款");
|
|
|
+ }
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成工单历史记录
|
|
|
+ */
|
|
|
+ public void saveHistory(Long pid, String status){
|
|
|
+ //生成出库工单历史记录
|
|
|
+ PjHistory history = new PjHistory();
|
|
|
+ history.setTenantId(AuthUtil.getTenantId());
|
|
|
+ history.setCreateUser(AuthUtil.getUserId());
|
|
|
+ history.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ history.setCreateTime(new Date());
|
|
|
+ history.setPid(pid);
|
|
|
+ history.setOperatorId(AuthUtil.getUserId());
|
|
|
+ history.setOperatorName(getUser().getUserName());
|
|
|
+ history.setOperateTime(new Date());
|
|
|
+ history.setOperateStatus(status);
|
|
|
+ historyMapper.insert(history);
|
|
|
+ }
|
|
|
+
|
|
|
}
|