diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java new file mode 100644 index 00000000..9bdbd33f --- /dev/null +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java @@ -0,0 +1,122 @@ +package com.ruoyi.sip.controller; + +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.sip.domain.*; +import com.ruoyi.sip.dto.inventory.OmsPurchaseOrderItemDto; +import com.ruoyi.sip.mapper.InventoryInfoMapper; +import com.ruoyi.sip.mapper.OmsInventoryInnerMapper; +import com.ruoyi.sip.service.IOmsPayableBillService; +import com.ruoyi.sip.service.IOmsPurchaseOrderService; +import com.ruoyi.sip.service.IProductInfoService; +import com.ruoyi.sip.service.IVendorInfoService; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.mgt.DefaultSecurityManager; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.subject.Subject; +import org.apache.shiro.subject.SimplePrincipalCollection; +import org.apache.shiro.util.ThreadContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * 数据处理控制器 + */ +@RestController +@RequestMapping("/sip/dataProcess") +public class DataProcessController { + + @Autowired + private OmsInventoryInnerMapper omsInventoryInnerMapper; + + @Autowired + private InventoryInfoMapper inventoryInfoMapper; + + @Autowired + private IProductInfoService productInfoService; + + @Autowired + private IOmsPurchaseOrderService purchaseOrderService; + + @Autowired + private IOmsPayableBillService payableBillService; + + @Autowired + private IVendorInfoService vendorInfoService; + + @Value("${oms.inventory.innerTax:0.13}") + private String defaultTax; + + //入库单生成应付单 + @GetMapping("/inventoryInnerGeneratePayableBill") + void inventoryInnerGeneratePayableBill(@RequestParam("innerId") Long innerId) { + bindShiroUser(1L, "admin", "平台管理员"); + OmsInventoryInner omsInventoryInner = omsInventoryInnerMapper.selectOmsInventoryInnerById(innerId); + List inventoryInfoList = inventoryInfoMapper.selectInventoryInfoByInnerCodeList(Arrays.asList(omsInventoryInner.getInnerCode())); + List productCodeList = inventoryInfoList.stream().map(InventoryInfo::getProductCode).distinct().filter(StringUtils::isNotEmpty).collect(Collectors.toList()); + List productInfos = productInfoService.selectProductInfoByCodeList(productCodeList); + String vendorCode = productInfos.get(0).getVendorCode(); + OmsPayableBill payableBill = new OmsPayableBill(); + VendorInfo vendorInfo = vendorInfoService.selectVendorInfoByVendorCode(vendorCode); + + BigDecimal reduce = inventoryInfoList.stream().map(InventoryInfo::getInnerPrice).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add); + //服务金额为单价* 数量 没有具体的详情 + BigDecimal totalPriceWithTax = Arrays.asList("3", "22").contains(omsInventoryInner.getProductType()) ? + reduce.multiply(new BigDecimal(omsInventoryInner.getQuantity())).setScale(2, RoundingMode.HALF_UP) + : reduce; + //生成应付单 + payableBill.setInventoryCode(omsInventoryInner.getInnerCode()); + payableBill.setVendorCode(omsInventoryInner.getVendorCode()); + payableBill.setProductType(productInfos.get(0).getType()); + payableBill.setProductCode(omsInventoryInner.getProductCode()); + payableBill.setTotalPriceWithTax(totalPriceWithTax); + payableBill.setOrderCode(omsInventoryInner.getOrderCode()); + payableBill.setProjectCode(omsInventoryInner.getProductCode()); + payableBill.setProjectName(omsInventoryInner.getProjectName()); + String purchaseNo = omsInventoryInner.getPurchaseNo(); + BigDecimal taxRate = null; + if (StringUtils.isNotEmpty(purchaseNo)) { + OmsPurchaseOrderItemDto query = new OmsPurchaseOrderItemDto(); + query.setPurchaseNo(purchaseNo); + List omsPurchaseOrderItemDtos = purchaseOrderService.listItem(query); + Map decimalMap = omsPurchaseOrderItemDtos.stream().collect(Collectors.toMap(OmsPurchaseOrderItemDto::getProductCode, OmsPurchaseOrderItemDto::getTaxRate, (v1, v2) -> v1)); + taxRate = decimalMap.get(omsInventoryInner.getProductCode()); + + } + BigDecimal finalTaxRate = taxRate == null ? new BigDecimal(defaultTax) : taxRate; + BigDecimal withoutTax = inventoryInfoList.stream().reduce(BigDecimal.ZERO, (a, b) -> a.add(b.getInnerPrice().divide(BigDecimal.ONE.add(finalTaxRate), 2, RoundingMode.HALF_UP)), BigDecimal::add); + payableBill.setTotalPriceWithoutTax(withoutTax); + payableBill.setTaxRate(finalTaxRate); + payableBill.setTaxAmount(totalPriceWithTax); + payableBill.setTaxAmount(totalPriceWithTax.subtract(payableBill.getTotalPriceWithoutTax())); + payableBillService.insertOmsPayableBill(payableBill, vendorInfo.getPayConfigDay()); + } + + private void bindShiroUser(Long userId, String loginName, String userName) { + SecurityManager securityManager = new DefaultSecurityManager(); + SecurityUtils.setSecurityManager(securityManager); + ThreadContext.bind(securityManager); + + SysUser user = new SysUser(); + user.setUserId(userId); + user.setLoginName(loginName); + user.setUserName(userName); + Subject subject = new Subject.Builder(securityManager) + .principals(new SimplePrincipalCollection(user, "testRealm")) + .buildSubject(); + ThreadContext.bind(subject); + } + +} diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java index 859defe9..1d4632b4 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java @@ -336,17 +336,11 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService { return inventoryDeliveryMapper.deleteInventoryDeliveryById(id); } else { // 2026-03-19:新逻辑,仅修改发货单状态为撤回,不删除库存表 - int rows = 0; - List inventoryDeliveries = inventoryDeliveryMapper.selectQuantityByOrderCodeStatus(orderCode, InventoryDelivery.DeliveryStatusEnum.CONFIRM_DELIVERY.getCode()); - if (CollUtil.isNotEmpty(inventoryDeliveries)) { - for (InventoryDelivery inventoryDeliverie : inventoryDeliveries) { - InventoryDelivery updateDelivery = new InventoryDelivery(); - updateDelivery.setId(inventoryDeliverie.getId()); - updateDelivery.setDeliveryStatus(InventoryDelivery.DeliveryStatusEnum.RECALL_DELIVERY.getCode()); - updateDelivery.setUpdateTime(DateUtils.getNowDate()); - rows += inventoryDeliveryMapper.updateInventoryDelivery(updateDelivery); - } - } + InventoryDelivery updateDelivery = new InventoryDelivery(); + updateDelivery.setId(id); + updateDelivery.setDeliveryStatus(InventoryDelivery.DeliveryStatusEnum.RECALL_DELIVERY.getCode()); + updateDelivery.setUpdateTime(DateUtils.getNowDate()); + int rows = inventoryDeliveryMapper.updateInventoryDelivery(updateDelivery); return rows; } } diff --git a/ruoyi-sip/src/main/resources/mapper/sip/ProjectOrderInfoMapper.xml b/ruoyi-sip/src/main/resources/mapper/sip/ProjectOrderInfoMapper.xml index aef2dad7..478931f4 100644 --- a/ruoyi-sip/src/main/resources/mapper/sip/ProjectOrderInfoMapper.xml +++ b/ruoyi-sip/src/main/resources/mapper/sip/ProjectOrderInfoMapper.xml @@ -361,7 +361,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN agent_info t3 ON t2.agent_code = t3.agent_code LEFT JOIN customer_info t4 ON t2.customer_code = t4.customer_code where ( - CAST(ifnull(t1.version_code,0) + ifnull(t1.operation_version,0) AS SIGNED) > 1 or + (CAST(ifnull(t1.version_code,0) + ifnull(t1.operation_version,0) AS SIGNED) > 1 and t1.order_status = '2') or t1.order_code in ( select DISTINCT order_code from oms_inventory_outer where outer_code in (SELECT outer_code from oms_inventory_delivery where delivery_status=1)) )