liujie
2025-10-14 08892731ebf9a4a6004700d5b3710f7ea3c7b5b5
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -44,6 +44,7 @@
import java.math.RoundingMode;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -99,6 +100,8 @@
    @Resource
    private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
    @Resource
    private TCrmWarehouseMapper crmWarehouseMapper;
    @Override
    public PageInfo<TErpProcurementVo> pageList(TErpProcurementQuery query, SysUser user) {
@@ -170,9 +173,13 @@
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
        if (roleType == 6) {
            TCrmWarehouse warehouse = crmWarehouseMapper.selectOne(Wrappers.lambdaQuery(TCrmWarehouse.class)
                    .eq(TCrmWarehouse::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .eq(TCrmSupplier::getWarehouseId, warehouse.getId())
                    .last("LIMIT 1"));
            supplierClinicId = crmSupplier.getId();
@@ -377,7 +384,7 @@
            BigDecimal all = BigDecimal.ZERO;
            for (AddProcurementDto addProcurementDto : value) {
                BigDecimal multiply = addProcurementDto.getSalesAmount().multiply(BigDecimal.valueOf(addProcurementDto.getPurchaseCount()));
                BigDecimal multiply = addProcurementDto.getGoodsSalesAmount().multiply(BigDecimal.valueOf(addProcurementDto.getPurchaseCount()));
                all = all.add(multiply);
            }
            tErpProcurement.setPayMoney(all);
@@ -391,6 +398,9 @@
            BigDecimal add = BigDecimal.ZERO;
            BigDecimal supplierCommissionPrice = BigDecimal.ZERO;
            for (AddProcurementDto dto : value) {
                TErpProcurementGoods tErpProcurementGoods = new TErpProcurementGoods();
                tErpProcurementGoods.setProcurementId(tErpProcurement.getId());
@@ -401,7 +411,9 @@
                tErpProcurementGoods.setQuasiNumber(goods.getQuasiNumber());
                TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
                tErpProcurementGoods.setUnitName(tErpGoodsUnit.getUnitName());
                if(tErpGoodsUnit!=null){
                    tErpProcurementGoods.setUnitName(tErpGoodsUnit.getUnitName());
                }
                tErpProcurementGoods.setPurchasePrice(dto.getGoodsSalesAmount());
                tErpProcurementGoods.setSalesAmount(dto.getSalesAmount());
                tErpProcurementGoods.setTotalPrice(dto.getGoodsSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
@@ -410,6 +422,7 @@
                tErpProcurementGoods.setSupplierId(supplierClinicId);
                tErpProcurementGoods.setRecvMerchantNo(supplier.getRecvMerchantNo());
                tErpProcurementGoods.setSupplierMoney(dto.getSalesAmount().subtract(dto.getPlatformCommissionPrice()));
                supplierCommissionPrice = supplierCommissionPrice.add(tErpProcurementGoods.getSupplierMoney().multiply(BigDecimal.valueOf(dto.getPurchaseCount())));
                if (tErpProcurementGoods.getSupplierMoney().doubleValue() < 0) {
                    throw new RuntimeException("平台抽成不能大于售卖价格");
                }
@@ -422,6 +435,7 @@
            if (tErpProcurement.getMoney().doubleValue() < 0) {
                throw new RuntimeException("金额设置错误,请联系平台管理员");
            }
            tErpProcurement.setSupplierMoney(supplierCommissionPrice);
            this.save(tErpProcurement);
            tErpProcurementGoods1.forEach(e -> e.setProcurementId(tErpProcurement.getId()));
            erpProcurementGoodsService.saveBatch(tErpProcurementGoods1);
@@ -455,6 +469,25 @@
            detailProcurementNextVO.setTotalPrice(tErpProcurement.getPayMoney());
            detailProcurementNextVO.setId(tErpProcurementGoods.getId());
            detailProcurementNextVO.setPurchasePrice(tErpProcurementGoods.getPurchasePrice());
            List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getProcurementGoodsId, tErpProcurementGoods.getId()));
            if(!tErpSupplierOutboundGoods.isEmpty()){
                ArrayList<DetailProcurementNextThreeVO> detailProcurementNextThreeVOS = new ArrayList<>();
                List<String> collect = tErpSupplierOutboundGoods.stream().map(TErpSupplierOutboundGoods::getWarehousingBatchId).collect(Collectors.toList());
                List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectBatchIds(collect);
                for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
                    List<TErpSupplierWarehousingBatch> collect1 = tErpSupplierWarehousingBatches.stream().filter(e -> e.getId().equals(tErpSupplierOutboundGood.getWarehousingBatchId())).collect(Collectors.toList());
                    for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : collect1) {
                        DetailProcurementNextThreeVO detailProcurementNextThreeVO = new DetailProcurementNextThreeVO();
                        detailProcurementNextThreeVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                        detailProcurementNextThreeVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
                        detailProcurementNextThreeVO.setExpirationDate(tErpSupplierWarehousingBatch.getExpiryDate());
                        detailProcurementNextThreeVO.setNum(tErpSupplierOutboundGood.getOutboundCount());
                        detailProcurementNextThreeVOS.add(detailProcurementNextThreeVO);
                    }
                }
                detailProcurementNextVO.setDetailProcurementNextThreeVOS(detailProcurementNextThreeVOS);
            }
            detailProcurementNextVOS.add(detailProcurementNextVO);
        }
        detailProcurementVO.setList(detailProcurementNextVOS);
@@ -463,7 +496,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void detailProcurementSend(String clinicSupplierId, SysUser user, String id) {
    public void detailProcurementSend(String clinicSupplierId, SysUser user, String id,String logisticsNumber) {
        // 查出这个采购的下级商品
        List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new QueryWrapper<TErpProcurementGoods>().eq("procurement_id", id));
        List<TErpSupplierWarehousing> tErpSupplierWarehousings = erpSupplierWarehousingMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousing>()
@@ -525,6 +558,7 @@
                        tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                        tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                        tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutboundGoods.setProcurementGoodsId(tErpProcurementGoods.getId());
                        erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                        continue outer;
                    }
@@ -547,6 +581,7 @@
                        tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                        tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                        tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutboundGoods.setProcurementGoodsId(tErpProcurementGoods.getId());
                        erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                    }
@@ -559,6 +594,11 @@
        }
        TErpProcurement byId = this.getById(id);
        byId.setStatus(4);
        byId.setSendTime(LocalDateTime.now());
        byId.setLogisticsNumber(logisticsNumber);
        this.updateById(byId);
    }