|
|
@@ -82,6 +82,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import javax.sql.rowset.serial.SerialException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.math.MathContext;
|
|
|
@@ -2525,6 +2526,122 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
@Override
|
|
|
public R saveOrderconfirm(Order order) {
|
|
|
+ // 校验单号重复-新增
|
|
|
+ if (order.getId() == null && StringUtils.isNotBlank(order.getOrderNo())) {
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper
|
|
|
+ .eq(Order::getOrderNo, order.getOrderNo())
|
|
|
+ .eq(Order::getTradeType, order.getTradeType())
|
|
|
+ .eq(Order::getBillType, order.getBillType())
|
|
|
+ .eq(Order::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Order::getIsDeleted, 0);
|
|
|
+ Integer count = baseMapper.selectCount(orderLambdaQueryWrapper);
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new SecurityException("合同号:" + order.getOrderNo() + "已存在,禁止重复添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验单号重复-编辑
|
|
|
+ else {
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper
|
|
|
+ .ne(Order::getId, order.getId())
|
|
|
+ .eq(Order::getOrderNo, order.getOrderNo())
|
|
|
+ .eq(Order::getTradeType, order.getTradeType())
|
|
|
+ .eq(Order::getBillType, order.getBillType())
|
|
|
+ .eq(Order::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Order::getIsDeleted, 0);
|
|
|
+ Integer count = baseMapper.selectCount(orderLambdaQueryWrapper);
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new SecurityException("合同号:" + order.getOrderNo() + "已存在,禁止重复添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 订单时间
|
|
|
+ Date date = new Date();
|
|
|
+ // 保存订单主表信息
|
|
|
+ if (order.getId() == null) {
|
|
|
+ // 获取系统编号
|
|
|
+ R billNo = serialClient.getBillNo(order.getBillType(), order.getTradeType(), order.getBillType());
|
|
|
+ if (billNo.getCode() != 200) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ order.setSysNo((String) billNo.getData());
|
|
|
+ R clientBillNo = serialClient.getBillNo(order.getBillType(), order.getTradeType(), order.getBillType());
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成订单编号失败");
|
|
|
+ }
|
|
|
+ order.setOrderNo((String) clientBillNo.getData());
|
|
|
+ // 进口的orgOrderNo 存的是采购订单号 出口国内存的是本身的订单号码
|
|
|
+ if (!order.getBillType().equals(OrderTypeEnum.IMPORT.getType())) {
|
|
|
+ order.setOrgOrderNo((String) clientBillNo.getData());
|
|
|
+ }
|
|
|
+
|
|
|
+ order.setTenantId(SecureUtil.getTenantId());
|
|
|
+ order.setCreateTime(date);
|
|
|
+ order.setCreateUser(SecureUtil.getUserId());
|
|
|
+ if (order.getBusinesDate() == null) {
|
|
|
+ order.setBusinesDate(date);
|
|
|
+ }
|
|
|
+ baseMapper.insert(order);
|
|
|
+ } else {
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper
|
|
|
+ .eq(Order::getId, order.getId())
|
|
|
+ .eq(Order::getCorpId, order.getCorpId())
|
|
|
+ .eq(Order::getTradeType, order.getTradeType())
|
|
|
+ .eq(Order::getBillType, order.getBillType())
|
|
|
+ .eq(Order::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Order::getIsDeleted, 0);
|
|
|
+ Integer count = baseMapper.selectCount(orderLambdaQueryWrapper);
|
|
|
+ if (count <= 0) {
|
|
|
+ R clientBillNo = serialClient.getBillNo(order.getBillType(), order.getTradeType(), order.getBillType());
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成订单编号失败");
|
|
|
+ }
|
|
|
+ order.setOrderNo((String) clientBillNo.getData());
|
|
|
+ // 进口的orgOrderNo 存的是采购订单号 出口国内存的是本身的订单号码
|
|
|
+ if (!order.getBillType().equals(OrderTypeEnum.IMPORT.getType())) {
|
|
|
+ order.setOrgOrderNo((String) clientBillNo.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setTenantId(SecureUtil.getTenantId());
|
|
|
+ order.setUpdateTime(date);
|
|
|
+ order.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(order.getCorpId())) {
|
|
|
+ CorpsDesc corpsDesc = corpsDescClient.getCorpId(order.getCorpId());
|
|
|
+ if (ObjectUtils.isNotNull(corpsDesc)) {
|
|
|
+ if (ObjectUtils.isNotNull(corpsDesc.getCorpsAddrList()) && corpsDesc.getCorpsAddrList().size() > 0) {
|
|
|
+ order.setArrivalAddress(corpsDesc.getCorpsAddrList().get(0).getDetailedAddress());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存订单明细
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderItemsList())) {
|
|
|
+ for (OrderItems orderItems : order.getOrderItemsList()) {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPrice(), MathContext.DECIMAL32));
|
|
|
+ }
|
|
|
+ List<OrderItems> orderItemsList = orderItemsService.saveOrderItemsMessage(order.getOrderItemsList(), date, order.getId());
|
|
|
+ order.setOrderItemsList(orderItemsList);
|
|
|
+ //应收账款
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ //入库出库金额
|
|
|
+ order.setStorageAmount(orderItemsList.stream().map(OrderItems::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //入库出库数量
|
|
|
+ order.setStorageQuantity(orderItemsList.stream().map(OrderItems::getStorageInQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getOrderAmount())) {
|
|
|
+ order.setOrderAmount(order.getStorageAmount());
|
|
|
+ }
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ order.setBalanceAmount(order.getOrderAmount());
|
|
|
+ order.setPurchaseAmount(order.getOrderAmount());
|
|
|
+ baseMapper.updateById(order);
|
|
|
+
|
|
|
+ //原提交代码
|
|
|
Order selectOrder = baseMapper.selectById(order.getId());
|
|
|
BigDecimal costAmount = new BigDecimal("0.00");
|
|
|
BigDecimal grossProfit = new BigDecimal("0.00");
|
|
|
@@ -2706,8 +2823,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
} else {
|
|
|
surplusRouteQuantity = surplusRouteQuantity.add(r.getData().getSurplusRouteQuantity().subtract(orderItems.getStorageInQuantity()));
|
|
|
balanceQuantity = balanceQuantity.add(surplusRouteQuantity);
|
|
|
- if (balanceQuantity.compareTo(BigDecimal.ZERO) != 0){
|
|
|
- balanceAmount = balanceAmount.add(r.getData().getBalanceAmount().add(orderItems.getStorageInQuantity().multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32)));
|
|
|
+ if (balanceQuantity.compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ throw new SecurityException("明细数量大于库存数量,禁止撤销");
|
|
|
+ }else if(balanceQuantity.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ balanceAmount = balanceAmount.add(r.getData().getBalanceAmount().subtract(orderItems.getStorageInQuantity().multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32)));
|
|
|
stockPrice = stockPrice.add(balanceAmount.divide(balanceQuantity, MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
r.getData().setInQuantity(r.getData().getInQuantity().subtract(orderItems.getStorageInQuantity()));
|