|
|
@@ -2825,7 +2825,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
Date date = new Date();
|
|
|
if (!"线上".equals(order.getOrderSource())) {
|
|
|
-
|
|
|
if ("234557".equals(AuthUtil.getTenantId())) {
|
|
|
if ("XSJH".equals(order.getBillType())) {
|
|
|
// 保存订单主表信息
|
|
|
@@ -4360,7 +4359,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
pathsActs = iCheckClient.getActsByActId(1105, "status");
|
|
|
//获取审批信息
|
|
|
- auditPathsLevels = iCheckClient.listLevelsByActId(1105,"status");
|
|
|
+ auditPathsLevels = iCheckClient.listLevelsByActId(1105, "status");
|
|
|
|
|
|
auditProecessDTO.setProcessType("财务退款审批");
|
|
|
/* 洗箱审批流程 */
|
|
|
@@ -4718,40 +4717,29 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if (ObjectUtils.isNull(billOrder)) {
|
|
|
throw new RuntimeException("未找到订单单据信息");
|
|
|
}
|
|
|
- if ("234557".equals(AuthUtil.getTenantId())){
|
|
|
- LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- orderLambdaQueryWrapper.eq(Order::getSrcId, billOrder.getId())
|
|
|
- .eq(Order::getIsDeleted, 0)
|
|
|
- .eq(Order::getTenantId, AuthUtil.getTenantId());
|
|
|
- selectOrder = baseMapper.selectOne(orderLambdaQueryWrapper);
|
|
|
- if (ObjectUtils.isNull(selectOrder)) {
|
|
|
- throw new RuntimeException("未找到发货单据信息");
|
|
|
- }
|
|
|
- selectOrder.setStatus(4);
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper.eq(Order::getSrcId, billOrder.getId())
|
|
|
+ .eq(Order::getIsDeleted, 0)
|
|
|
+ .eq(Order::getTenantId, AuthUtil.getTenantId());
|
|
|
+ selectOrder = baseMapper.selectOne(orderLambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNull(selectOrder)) {
|
|
|
+ throw new RuntimeException("未找到发货单据信息");
|
|
|
}
|
|
|
+ selectOrder.setStatus(4);
|
|
|
billOrder.setStatus(4);
|
|
|
text = "已确认收货!";
|
|
|
} else {
|
|
|
- if ("234557".equals(AuthUtil.getTenantId())){
|
|
|
- selectOrder = baseMapper.selectById(order.getId());
|
|
|
- if (ObjectUtils.isNull(selectOrder)) {
|
|
|
- throw new RuntimeException("未找到发货单据信息");
|
|
|
- }
|
|
|
- billOrder = baseMapper.selectById(selectOrder.getSrcId());
|
|
|
- if (ObjectUtils.isNull(billOrder)) {
|
|
|
- throw new RuntimeException("未找到订单单据信息");
|
|
|
- }
|
|
|
- selectOrder.setStatus(3);
|
|
|
- billOrder.setStatus(3);
|
|
|
- text = "已发货,请注意接收!";
|
|
|
- }else{
|
|
|
- billOrder = baseMapper.selectById(order.getId());
|
|
|
- if (ObjectUtils.isNull(billOrder)) {
|
|
|
- throw new RuntimeException("未找到订单单据信息");
|
|
|
- }
|
|
|
- billOrder.setStatus(3);
|
|
|
- text = "已发货,请注意接收!";
|
|
|
+ selectOrder = baseMapper.selectById(order.getId());
|
|
|
+ if (ObjectUtils.isNull(selectOrder)) {
|
|
|
+ throw new RuntimeException("未找到发货单据信息");
|
|
|
+ }
|
|
|
+ billOrder = baseMapper.selectById(selectOrder.getSrcId());
|
|
|
+ if (ObjectUtils.isNull(billOrder)) {
|
|
|
+ throw new RuntimeException("未找到订单单据信息");
|
|
|
}
|
|
|
+ selectOrder.setStatus(3);
|
|
|
+ billOrder.setStatus(3);
|
|
|
+ text = "已发货,请注意接收!";
|
|
|
|
|
|
LambdaQueryWrapper<OrderItems> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.eq(OrderItems::getPid, billOrder.getId())
|
|
|
@@ -4835,12 +4823,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if ("234557".equals(AuthUtil.getTenantId())){
|
|
|
- selectOrder.setUpdateTime(new Date());
|
|
|
- selectOrder.setUpdateUserName(AuthUtil.getUserName());
|
|
|
- selectOrder.setUpdateUser(AuthUtil.getUserId());
|
|
|
- baseMapper.updateById(selectOrder);
|
|
|
- }
|
|
|
+ selectOrder.setUpdateTime(new Date());
|
|
|
+ selectOrder.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ selectOrder.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ baseMapper.updateById(selectOrder);
|
|
|
billOrder.setUpdateTime(new Date());
|
|
|
billOrder.setUpdateUserName(AuthUtil.getUserName());
|
|
|
billOrder.setUpdateUser(AuthUtil.getUserId());
|
|
|
@@ -4916,7 +4902,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if (3 == billOrder.getStatus()) {
|
|
|
throw new RuntimeException("订单取消失败!该订单已发货,请申请退货");
|
|
|
}
|
|
|
- if ("234557".equals(AuthUtil.getTenantId())){
|
|
|
+ if ("234557".equals(AuthUtil.getTenantId())) {
|
|
|
LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
orderLambdaQueryWrapper.eq(Order::getSrcId, billOrder.getId())
|
|
|
.eq(Order::getIsDeleted, 0)
|
|
|
@@ -4931,7 +4917,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
billOrder.setUpdateUserName(AuthUtil.getUserName());
|
|
|
billOrder.setUpdateUser(AuthUtil.getUserId());
|
|
|
baseMapper.updateById(billOrder);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
baseMapper.deleteById(billOrder.getId());
|
|
|
}
|
|
|
return R.data("操作成功");
|
|
|
@@ -5375,6 +5361,580 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public R quickBillingWX(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 (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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (AuthUtil.getUserRole().equals("客户")) {
|
|
|
+ CorpsAttn corpsAttn = corpsAttnClient.getUser(AuthUtil.getUserId());
|
|
|
+ if (ObjectUtils.isNull(corpsAttn)) {
|
|
|
+ throw new RuntimeException("未查到用户信息");
|
|
|
+ } else {
|
|
|
+ CorpsDesc corpsDesc = corpsDescClient.getCorpId(corpsAttn.getPid());
|
|
|
+ if (ObjectUtils.isNull(corpsDesc)) {
|
|
|
+ throw new RuntimeException("未查到用户信息");
|
|
|
+ } else {
|
|
|
+ order.setCorpId(corpsDesc.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("234557".equals(AuthUtil.getTenantId())) {
|
|
|
+ if ("XSJH".equals(order.getBillType())) {
|
|
|
+ // 保存订单主表信息
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ order.setClient(AuthUtil.getUser().getRoleName());
|
|
|
+ R<User> r = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) {
|
|
|
+ order.setClientAttn(r.getData().getPhone());
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ BigDecimal costAmount = new BigDecimal("0.00");
|
|
|
+ BigDecimal grossProfit = new BigDecimal("0.00");
|
|
|
+ // 保存订单明细
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderItemsList())) {
|
|
|
+ for (OrderItems orderItems : order.getOrderItemsList()) {
|
|
|
+ if ("XS".equals(order.getBillType())) {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPrice(), MathContext.DECIMAL32));
|
|
|
+ } else {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32));
|
|
|
+ }
|
|
|
+ orderItems.setPurchaseCost(orderItems.getPurchasePrice());
|
|
|
+ }
|
|
|
+ List<OrderItems> orderItemsList = orderItemsService.saveOrderItemsMessage(order.getOrderItemsList(), date, order.getId());
|
|
|
+ order.setOrderItemsList(orderItemsList);
|
|
|
+ //应收账款
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ //入库出库金额
|
|
|
+ order.setStorageAmount(order.getOrderItemsList().stream().map(OrderItems::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //入库出库数量
|
|
|
+ order.setStorageQuantity(order.getOrderItemsList().stream().map(OrderItems::getStorageInQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getThisUsedProfit())) {
|
|
|
+ order.setThisUsedProfit(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getOrderAmount())) {
|
|
|
+ order.setOrderAmount((order.getStorageAmount() == null ? new BigDecimal("0.00") : order.getStorageAmount()).subtract((order.getThisUsedProfit() == null ? new BigDecimal("0.00") : order.getThisUsedProfit())));
|
|
|
+ }
|
|
|
+ order.setCostAmount(costAmount);
|
|
|
+ order.setGrossProfit(grossProfit);
|
|
|
+ order.setConfirmStatus(1);
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ order.setBalanceAmount(order.getOrderAmount());
|
|
|
+ order.setPurchaseAmount(order.getOrderAmount());
|
|
|
+
|
|
|
+ order.setSettlmentAmount(order.getOrderAmount().subtract(order.getOrderAmount()));
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ // 保存订单文件信息
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderFilesList())) {
|
|
|
+ List<OrderFiles> orderFilesList = orderFilesService.saveOrderFileMessage(order.getOrderFilesList(), date, order.getId());
|
|
|
+ order.setOrderFilesList(orderFilesList);
|
|
|
+ }
|
|
|
+ //审批数据
|
|
|
+ AuditProecessDTO auditProecessDTO = new AuditProecessDTO();
|
|
|
+ //获取审批级次
|
|
|
+ List<AuditPathsLevels> auditPathsLevels;
|
|
|
+ // 判断是否有审批流,如果审批流已开启就进入审批流,否则直接走申请通过
|
|
|
+ AuditPathsActs pathsActs;
|
|
|
+ //修箱审批流程
|
|
|
+ if ("XSJH".equals(order.getBillType())) {
|
|
|
+ //是否开启流程
|
|
|
+ pathsActs = iCheckClient.getActsByActId(1003, "status");
|
|
|
+ //获取审批信息
|
|
|
+ auditPathsLevels = iCheckClient.listLevelsByActId(1003, "status");
|
|
|
+
|
|
|
+ auditProecessDTO.setProcessType("销售订单审批");
|
|
|
+ auditProecessDTO.setCheckType("YPJ-XSJH");
|
|
|
+ auditProecessDTO.setUrl("/salesOrderTwo/index");
|
|
|
+ auditProecessDTO.setPageLabel("销售计划单");
|
|
|
+ // 追加跳转路由url
|
|
|
+ auditProecessDTO.setPageStatus("this.$store.getters.pjxsStatus");
|
|
|
+ /* 洗箱审批流程 */
|
|
|
+ } else {
|
|
|
+ throw new SecurityException("请核失败:请核标识设置不正确");
|
|
|
+ }
|
|
|
+ // 没开启审批流直接走 通过流程
|
|
|
+ if (pathsActs == null || pathsActs.getIsEnable() == 2) {
|
|
|
+ throw new SecurityException("当前租户未查询到审批流配置");
|
|
|
+ } else {
|
|
|
+ if (CollectionUtils.isEmpty(auditPathsLevels)) {
|
|
|
+ throw new SecurityException("开启审批失败:未查询到审批信息");
|
|
|
+ }
|
|
|
+ //数量
|
|
|
+ auditProecessDTO.setOrderQuantity(order.getStorageQuantity());
|
|
|
+ //单据金额
|
|
|
+ auditProecessDTO.setAmount(order.getDebitAmount());
|
|
|
+ auditProecessDTO.setPayAmount(order.getDebitAmount());
|
|
|
+ //审批数据
|
|
|
+ auditProecessDTO.setMorderNo(order.getSysNo());
|
|
|
+ auditProecessDTO.setOrderRemark(order.getOrderRemark());
|
|
|
+ auditProecessDTO.setCorpId(order.getCorpId());
|
|
|
+ auditProecessDTO.setPathsLevelsList(auditPathsLevels);
|
|
|
+ auditProecessDTO.setActId(1);
|
|
|
+ auditProecessDTO.setSrcBillId(order.getId());
|
|
|
+ auditProecessDTO.setBillId(order.getId());
|
|
|
+ auditProecessDTO.setBillNo(order.getSysNo());
|
|
|
+ auditProecessDTO.setSendUserId(AuthUtil.getUserId());
|
|
|
+ auditProecessDTO.setSendName(AuthUtil.getUserName());
|
|
|
+ auditProecessDTO.setSendTime(new Date());
|
|
|
+ auditProecessDTO.setReferenceNo(order.getBillNo());
|
|
|
+ R financeProcess = iCheckClient.createFinanceProcess(auditProecessDTO);
|
|
|
+ if (!financeProcess.isSuccess()) {
|
|
|
+ throw new SecurityException("操作失败,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ order.setStatus(11);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ order.setClient(AuthUtil.getUser().getRoleName());
|
|
|
+ R<User> r = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) {
|
|
|
+ order.setClientAttn(r.getData().getPhone());
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ LandOrder landOrder = new LandOrder();
|
|
|
+ landOrder.setCorpId(order.getCorpId());
|
|
|
+ R<List<LandOrder>> res = landClient.listLandOrder(landOrder);
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ List<LandOrder> landOrderList = res.getData();
|
|
|
+ BigDecimal freightPay = landOrderList.stream().map(LandOrder::getFreightPay).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal freight = landOrderList.stream().map(LandOrder::getFreight).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if ((order.getDebitAmount().multiply(new BigDecimal(OFFSET_RATIO))).compareTo((freightPay.add(freight))) > 0) {
|
|
|
+ throw new SecurityException("订单单号:" + order.getSysNo() + "订单金额大于运费抵消金额");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal costAmount = new BigDecimal("0.00");
|
|
|
+ BigDecimal grossProfit = new BigDecimal("0.00");
|
|
|
+ // 保存订单明细
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderItemsList())) {
|
|
|
+ for (OrderItems orderItems : order.getOrderItemsList()) {
|
|
|
+ if ("XS".equals(order.getBillType())) {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPrice(), MathContext.DECIMAL32));
|
|
|
+ } else {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32));
|
|
|
+ }
|
|
|
+ BigDecimal stockPrice = new BigDecimal("0.00");
|
|
|
+ BigDecimal surplusRouteQuantity = new BigDecimal("0.00");
|
|
|
+ BigDecimal balanceQuantity = new BigDecimal("0.00");
|
|
|
+ BigDecimal balanceAmount = new BigDecimal("0.00");
|
|
|
+ orderItems.setPurchaseCost(orderItems.getPurchasePrice());
|
|
|
+ //获取本商品库存
|
|
|
+ R<StockGoodsVO> r = stockGoodsClient.selectStockParts(null, orderItems.getStorageId(), orderItems.getItemId(), null, null, null, null, null, null);
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) {
|
|
|
+ if ("XS".equals(order.getBillType())) {
|
|
|
+ surplusRouteQuantity = surplusRouteQuantity.add(r.getData().getSurplusRouteQuantity().subtract(orderItems.getStorageInQuantity()));
|
|
|
+ balanceQuantity = balanceQuantity.add(surplusRouteQuantity);
|
|
|
+
|
|
|
+
|
|
|
+ if (new BigDecimal("0.00").equals(r.getData().getSurplusRouteQuantity())) {
|
|
|
+ costAmount = costAmount.add(orderItems.getPurchasePrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ } else {
|
|
|
+ costAmount = costAmount.add(r.getData().getStockPrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ balanceAmount = balanceAmount.add(balanceQuantity.multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32));
|
|
|
+ stockPrice = stockPrice.add(balanceAmount.divide(balanceQuantity, MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ r.getData().setOutQuantity(r.getData().getOutQuantity().add(orderItems.getStorageInQuantity()));
|
|
|
+ r.getData().setOutAmount(r.getData().getOutAmount().add(costAmount));
|
|
|
+
|
|
|
+ BigDecimal grossProfits = orderItems.getPrice().subtract(orderItems.getPurchasePrice());
|
|
|
+ grossProfit = grossProfit.add(orderItems.getStorageInQuantity().multiply(grossProfits));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ surplusRouteQuantity = surplusRouteQuantity.add(r.getData().getSurplusRouteQuantity().add(orderItems.getStorageInQuantity()));
|
|
|
+ balanceQuantity = balanceQuantity.add(surplusRouteQuantity);
|
|
|
+ balanceAmount = balanceAmount.add(balanceQuantity.multiply(orderItems.getPrice(), MathContext.DECIMAL32));
|
|
|
+ stockPrice = stockPrice.add(balanceAmount.divide(balanceQuantity, MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ r.getData().setInQuantity(r.getData().getInQuantity().add(orderItems.getStorageInQuantity()));
|
|
|
+ r.getData().setInAmount(r.getData().getInAmount().add(orderItems.getAmount()));
|
|
|
+
|
|
|
+ costAmount = costAmount.add(orderItems.getPurchasePrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ grossProfit = grossProfit.add(new BigDecimal("0.00"));
|
|
|
+
|
|
|
+ }
|
|
|
+ r.getData().setSurplusRouteQuantity(surplusRouteQuantity);
|
|
|
+ r.getData().setBalanceQuantity(balanceQuantity);
|
|
|
+ r.getData().setBalanceAmount(balanceAmount);
|
|
|
+ r.getData().setStockPrice(stockPrice);
|
|
|
+ stockGoodsClient.updateStock(r.getData());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ StockGoods stockGoods = new StockGoods();
|
|
|
+ if ("CG".equals(order.getBillType())) {
|
|
|
+ stockGoods.setGoodsId(orderItems.getItemId());
|
|
|
+ stockGoods.setStorageId(orderItems.getStorageId());
|
|
|
+ stockGoods.setPurchasePrice(orderItems.getPrice());
|
|
|
+ stockGoods.setStockPrice(orderItems.getPrice());
|
|
|
+ stockGoods.setBalanceQuantity(orderItems.getStorageInQuantity());
|
|
|
+ stockGoods.setBalanceAmount(stockGoods.getBalanceQuantity().multiply(orderItems.getPrice()));
|
|
|
+ stockGoods.setSurplusRouteQuantity(orderItems.getStorageInQuantity());
|
|
|
+ stockGoodsClient.saveStock(stockGoods);
|
|
|
+ } else {
|
|
|
+ stockGoods.setGoodsId(orderItems.getItemId());
|
|
|
+ stockGoods.setStorageId(orderItems.getStorageId());
|
|
|
+ stockGoods.setPurchasePrice(orderItems.getPrice());
|
|
|
+ stockGoods.setStockPrice(orderItems.getPrice());
|
|
|
+ stockGoods.setBalanceQuantity(new BigDecimal("0.00").subtract(orderItems.getStorageInQuantity()));
|
|
|
+ stockGoods.setBalanceAmount(new BigDecimal("0.00").subtract(stockGoods.getBalanceQuantity().multiply(orderItems.getPrice())));
|
|
|
+ stockGoods.setSurplusRouteQuantity(new BigDecimal("0.00").subtract(orderItems.getStorageInQuantity()));
|
|
|
+ stockGoodsClient.saveStock(stockGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<OrderItems> orderItemsList = orderItemsService.saveOrderItemsMessage(order.getOrderItemsList(), date, order.getId());
|
|
|
+ order.setOrderItemsList(orderItemsList);
|
|
|
+ //应收账款
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ //入库出库金额
|
|
|
+ order.setStorageAmount(order.getOrderItemsList().stream().map(OrderItems::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //入库出库数量
|
|
|
+ order.setStorageQuantity(order.getOrderItemsList().stream().map(OrderItems::getStorageInQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getThisUsedProfit())) {
|
|
|
+ order.setThisUsedProfit(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getOrderAmount())) {
|
|
|
+ order.setOrderAmount((order.getStorageAmount() == null ? new BigDecimal("0.00") : order.getStorageAmount()).subtract((order.getThisUsedProfit() == null ? new BigDecimal("0.00") : order.getThisUsedProfit())));
|
|
|
+ }
|
|
|
+ order.setCostAmount(costAmount);
|
|
|
+ order.setGrossProfit(grossProfit);
|
|
|
+ order.setConfirmStatus(1);
|
|
|
+ this.paymentApply(order, order.getBillType(), order.getTradeType());
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ order.setBalanceAmount(order.getOrderAmount());
|
|
|
+ order.setPurchaseAmount(order.getOrderAmount());
|
|
|
+
|
|
|
+ order.setSettlmentAmount(order.getOrderAmount().subtract(order.getOrderAmount()));
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ // 保存订单文件信息
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderFilesList())) {
|
|
|
+ List<OrderFiles> orderFilesList = orderFilesService.saveOrderFileMessage(order.getOrderFilesList(), date, order.getId());
|
|
|
+ order.setOrderFilesList(orderFilesList);
|
|
|
+ }
|
|
|
+ CorpsDesc corpsDesc = corpsDescClient.getCorpId(order.getCorpId());
|
|
|
+ if (ObjectUtils.isNull(corpsDesc)) {
|
|
|
+ throw new RuntimeException("未找到客户信息");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(corpsDesc.getAdminProfiles())) {
|
|
|
+ String[] arrs = corpsDesc.getAdminProfiles().split(",");
|
|
|
+ for (String arr : arrs) {
|
|
|
+ //信息
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(String.valueOf(order.getId()));
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(AuthUtil.getUserId());
|
|
|
+ sendMessage.setToUserId(Long.parseLong(arr));
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(AuthUtil.getUserId());
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl(order.getUrl());
|
|
|
+ sendMessage.setPageLabel(order.getPageLabel());
|
|
|
+ sendMessage.setPageStatus(order.getPageStatus());
|
|
|
+ sendMessage.setMessageBody("您的单号:" + order.getSysNo() + "发货成功!");
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 订单时间
|
|
|
+ order.setStatus(1);
|
|
|
+ order.setBusinesDate(new Date());
|
|
|
+ order.setSalesName(AuthUtil.getUserId() + "");
|
|
|
+ // 保存订单主表信息
|
|
|
+ // 获取系统编号
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ order.setClient(AuthUtil.getUser().getRoleName());
|
|
|
+ R<User> userR = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (userR.isSuccess() && ObjectUtils.isNotNull(userR.getData())) {
|
|
|
+ order.setClientAttn(userR.getData().getPhone());
|
|
|
+ }
|
|
|
+ baseMapper.insert(order);
|
|
|
+ BigDecimal costAmount = new BigDecimal("0.00");
|
|
|
+ BigDecimal grossProfit = new BigDecimal("0.00");
|
|
|
+ // 保存订单明细
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderItemsList())) {
|
|
|
+ for (OrderItems orderItems : order.getOrderItemsList()) {
|
|
|
+ if ("XS".equals(order.getBillType())) {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPrice(), MathContext.DECIMAL32));
|
|
|
+ } else {
|
|
|
+ orderItems.setAmount(orderItems.getStorageInQuantity().multiply(orderItems.getPurchasePrice(), MathContext.DECIMAL32));
|
|
|
+ }
|
|
|
+ orderItems.setPurchaseCost(orderItems.getPurchasePrice());
|
|
|
+ //获取本商品库存
|
|
|
+ R<StockGoodsVO> r = stockGoodsClient.selectStockParts(null, orderItems.getStorageId(), orderItems.getItemId(), null, null, null, null, null, null);
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) {
|
|
|
+ if ("XS".equals(order.getBillType())) {
|
|
|
+ if (new BigDecimal("0.00").equals(r.getData().getSurplusRouteQuantity())) {
|
|
|
+ costAmount = costAmount.add(orderItems.getPurchasePrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ } else {
|
|
|
+ costAmount = costAmount.add(r.getData().getStockPrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ }
|
|
|
+ BigDecimal grossProfits = orderItems.getPrice().subtract(orderItems.getPurchasePrice());
|
|
|
+ grossProfit = grossProfit.add(orderItems.getStorageInQuantity().multiply(grossProfits));
|
|
|
+ } else {
|
|
|
+ costAmount = costAmount.add(orderItems.getPurchasePrice().multiply(orderItems.getStorageInQuantity()));
|
|
|
+ grossProfit = grossProfit.add(new BigDecimal("0.00"));
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ StockGoods stockGoods = new StockGoods();
|
|
|
+ if ("CG".equals(order.getBillType())) {
|
|
|
+ stockGoods.setGoodsId(orderItems.getItemId());
|
|
|
+ stockGoods.setStorageId(orderItems.getStorageId());
|
|
|
+ stockGoods.setPurchasePrice(orderItems.getPrice());
|
|
|
+ stockGoods.setStockPrice(orderItems.getPrice());
|
|
|
+ stockGoods.setBalanceQuantity(orderItems.getStorageInQuantity());
|
|
|
+ stockGoods.setBalanceAmount(stockGoods.getBalanceQuantity().multiply(orderItems.getPrice()));
|
|
|
+ stockGoods.setSurplusRouteQuantity(orderItems.getStorageInQuantity());
|
|
|
+ stockGoodsClient.saveStock(stockGoods);
|
|
|
+ } else {
|
|
|
+ stockGoods.setGoodsId(orderItems.getItemId());
|
|
|
+ stockGoods.setStorageId(orderItems.getStorageId());
|
|
|
+ stockGoods.setPurchasePrice(orderItems.getPrice());
|
|
|
+ stockGoods.setStockPrice(orderItems.getPrice());
|
|
|
+ stockGoods.setBalanceQuantity(new BigDecimal("0.00").subtract(orderItems.getStorageInQuantity()));
|
|
|
+ stockGoods.setBalanceAmount(new BigDecimal("0.00").subtract(stockGoods.getBalanceQuantity().multiply(orderItems.getPrice())));
|
|
|
+ stockGoods.setSurplusRouteQuantity(new BigDecimal("0.00").subtract(orderItems.getStorageInQuantity()));
|
|
|
+ stockGoodsClient.saveStock(stockGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<OrderItems> orderItemsList = orderItemsService.saveOrderItemsMessage(order.getOrderItemsList(), date, order.getId());
|
|
|
+ order.setOrderItemsList(orderItemsList);
|
|
|
+ //应收账款
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ //入库出库金额
|
|
|
+ order.setStorageAmount(order.getOrderItemsList().stream().map(OrderItems::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //入库出库数量
|
|
|
+ order.setStorageQuantity(order.getOrderItemsList().stream().map(OrderItems::getStorageInQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getThisUsedProfit())) {
|
|
|
+ order.setThisUsedProfit(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(order.getOrderAmount())) {
|
|
|
+ order.setOrderAmount((order.getStorageAmount() == null ? new BigDecimal("0.00") : order.getStorageAmount()).subtract((order.getThisUsedProfit() == null ? new BigDecimal("0.00") : order.getThisUsedProfit())));
|
|
|
+ }
|
|
|
+ order.setCostAmount(costAmount);
|
|
|
+ order.setGrossProfit(grossProfit);
|
|
|
+ order.setConfirmStatus(1);
|
|
|
+ this.paymentApply(order, order.getBillType(), order.getTradeType());
|
|
|
+ order.setDebitAmount(order.getOrderAmount());
|
|
|
+ order.setBalanceAmount(order.getOrderAmount());
|
|
|
+ order.setPurchaseAmount(order.getOrderAmount());
|
|
|
+ order.setSettlmentAmount(order.getOrderAmount().subtract(order.getOrderAmount()));
|
|
|
+ baseMapper.updateById(order);
|
|
|
+
|
|
|
+ // 保存订单文件信息
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getOrderFilesList())) {
|
|
|
+ List<OrderFiles> orderFilesList = orderFilesService.saveOrderFileMessage(order.getOrderFilesList(), date, order.getId());
|
|
|
+ order.setOrderFilesList(orderFilesList);
|
|
|
+ }
|
|
|
+ CorpsDesc corpsDesc = corpsDescClient.getCorpId(order.getCorpId());
|
|
|
+ if (ObjectUtils.isNull(corpsDesc)) {
|
|
|
+ throw new RuntimeException("未找到客户信息");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(corpsDesc.getAdminProfiles())) {
|
|
|
+ String[] arrs = corpsDesc.getAdminProfiles().split(",");
|
|
|
+ for (String arr : arrs) {
|
|
|
+ //信息
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(String.valueOf(order.getId()));
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(AuthUtil.getUserId());
|
|
|
+ sendMessage.setToUserId(Long.parseLong(arr));
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(AuthUtil.getUserId());
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl(order.getUrl());
|
|
|
+ sendMessage.setPageLabel(order.getPageLabel());
|
|
|
+ sendMessage.setPageStatus(order.getPageStatus());
|
|
|
+ sendMessage.setMessageBody("您的单号:" + order.getSysNo() + "下单成功!");
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //通联支付下单处理
|
|
|
+ R r = this.payPrepay(order.getId());
|
|
|
+ if (!r.isSuccess() || r.getCode() != 200) {
|
|
|
+ throw new RuntimeException("支付失败!原因:" + r.getData());
|
|
|
+ } else {
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public MonthSales monthSales(OrderVO order) {
|
|
|
MonthSales monthSales = new MonthSales();
|
|
|
if (AuthUtil.getTenantId().equals("673511")) {
|