liujie
2025-10-13 f3813129107882ab77531a1d5f056824c401ca37
采购相关问题
4个文件已修改
164 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpProcurementController.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/TErpProcurementService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpProcurementController.java
@@ -182,22 +182,40 @@
        return R.ok( erpProcurementService.detailProcurement(clinicSupplierId, user, id));
    }
    @ApiOperation(value = "采购详情--仓库角色专用")
    @GetMapping(value = "/detailProcurementWarehouse/{id}")
    public R<DetailProcurementVO> detailProcurementWarehouse(@PathVariable String id) {
    @ApiOperation(value = "采购详情--发货(仓库角色)")
    @PostMapping(value = "/detailProcurementSend/{id}")
    public R<?> detailProcurementSend(@PathVariable String id) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String clinicSupplierId=null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            clinicSupplierId = crmClinic.getId();
            clinicSupplierId=crmSupplier.getId();
        }
        return R.ok( erpProcurementService.detailProcurementWarehouse(clinicSupplierId, user, id));
        erpProcurementService.detailProcurementSend(clinicSupplierId, user, id);
        return R.ok();
    }
//    @ApiOperation(value = "采购详情--仓库角色专用")
//    @GetMapping(value = "/detailProcurementWarehouse/{id}")
//    public R<DetailProcurementVO> detailProcurementWarehouse(@PathVariable String id) {
//        SysUser user = tokenService.getLoginUser().getUser();
//        Integer roleType = user.getRoleType();
//        String clinicSupplierId=null;
//        if(roleType == 5){
//            // 诊所
//            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
//                    .eq(TCrmClinic::getUserId, user.getUserId())
//                    .last("LIMIT 1"));
//            clinicSupplierId = crmClinic.getId();
//        }
//
//        return R.ok( erpProcurementService.detailProcurementWarehouse(clinicSupplierId, user, id));
//    }
@@ -216,7 +234,7 @@
            clinicSupplierId = crmClinic.getId();
        }
        ArrayList<DetailProcurementNextVO> detailProcurementNextVOS = new ArrayList<>();
        List<TErpProcurement> list1 = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getStatus, 1).orderByDesc(TErpProcurement::getCreateTime));
        List<TErpProcurement> list1 = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getClinicId, clinicSupplierId).eq(TErpProcurement::getStatus, 1).orderByDesc(TErpProcurement::getCreateTime));
        if(list1.isEmpty()){
            return R.ok(detailProcurementNextVOS);
        }
@@ -364,6 +382,9 @@
            tCrmChangePoints.setChangeValue(points);
            crmChangePointsService.save(tCrmChangePoints);
            branch.setUserPoints(branch.getUserPoints()+points);
            crmBranchService.updateById(branch);
            // 分佣
            BigDecimal commission = branch.getMoneyCommission().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_DOWN).multiply(payMoney).setScale(2, RoundingMode.HALF_UP);
@@ -389,6 +410,8 @@
            tCrmChangePoints.setChangeReason(1);
            tCrmChangePoints.setChangeValue(points);
            crmChangePointsService.save(tCrmChangePoints);
            salesperson.setUserPoints(salesperson.getUserPoints()+points);
            crmSalespersonService.updateById(salesperson);
ruoyi-system/src/main/java/com/ruoyi/system/service/TErpProcurementService.java
@@ -42,4 +42,6 @@
    void addProcurement(String clinicSupplierId, SysUser user, @Valid List<AddProcurementDto> dtos);
    DetailProcurementVO detailProcurement(String clinicSupplierId, SysUser user, String id);
    void detailProcurementSend(String clinicSupplierId, SysUser user, String id);
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -87,6 +87,18 @@
    @Autowired
    private TErpProcurementGoodsService erpProcurementGoodsService;
    @Resource
    private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper;
    @Resource
    private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper;
    @Resource
    private TErpSupplierOutboundMapper erpSupplierOutboundMapper;
    @Resource
    private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
    @Override
    public PageInfo<TErpProcurementVo> pageList(TErpProcurementQuery query, SysUser user) {
@@ -449,4 +461,105 @@
        return detailProcurementVO;
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void detailProcurementSend(String clinicSupplierId, SysUser user, String id) {
        // 查出这个采购的下级商品
        List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new QueryWrapper<TErpProcurementGoods>().eq("procurement_id", id));
        List<TErpSupplierWarehousing> tErpSupplierWarehousings = erpSupplierWarehousingMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousing>()
                .eq(TErpSupplierWarehousing::getSupplierId, clinicSupplierId).in(TErpSupplierWarehousing::getGoodsId, list.stream().map(TErpProcurementGoods::getGoodsId).collect(Collectors.toList()))
                .orderByAsc(BaseModel::getCreateTime));
        if(tErpSupplierWarehousings.isEmpty()){
            throw new RuntimeException("商品供应商未入库,请先入库");
        }
        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().in(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousings.stream().map(TErpSupplierWarehousing::getId).collect(Collectors.toList())));
        // 获取所有的出库记录
        List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoodsLists = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().in(TErpSupplierOutboundGoods::getWarehousingBatchId, tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList())));
        outer:for (TErpProcurementGoods tErpProcurementGoods : list) {
            // 分别入库
            String goodsId = tErpProcurementGoods.getGoodsId();
            // 查询这个供应商的 该商品是否入过库 未入库提示  出库判断库存 先找先入库的
            List<TErpSupplierWarehousing> collect = tErpSupplierWarehousings.stream().filter(e -> e.getGoodsId().equals(goodsId)).collect(Collectors.toList());
            if(collect.isEmpty()){
                throw new RuntimeException("商品供应商未入库,请先入库");
            }
            // 需要出库的数量
            Integer purchaseCount = tErpProcurementGoods.getPurchaseCount();
            if(purchaseCount==0){
                continue;
            }
            for (TErpSupplierWarehousing tErpSupplierWarehousing : collect) {
                List<TErpSupplierWarehousingBatch> warehousingBatches = tErpSupplierWarehousingBatches.stream().filter(e -> e.getWarehousingId().equals(tErpSupplierWarehousing.getId())).collect(Collectors.toList());
                for (TErpSupplierWarehousingBatch warehousingBatch : warehousingBatches) {
                    // 已出库数量
                    int sum = tErpSupplierOutboundGoodsLists.stream().filter(e -> e.getWarehousingBatchId().equals(warehousingBatch.getId())).mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
                    // 该批次剩余的数量
                    int count = warehousingBatch.getWarehousingNumber() - sum;
                    // 该批次没有数量 找下个批次
                    if(count==0 ){
                        continue;
                    }
                    // 如果大于这个数量 则使用这个批次
                    if(count>=purchaseCount){
                        // 添加出库记录
                        TErpSupplierOutbound tErpSupplierOutbound= new TErpSupplierOutbound();
                        tErpSupplierOutbound.setSupplierId(clinicSupplierId);
                        tErpSupplierOutbound.setWarehouseId(tErpSupplierWarehousing.getWarehouseId());
                        tErpSupplierOutbound.setOutboundType(7);
                        //TODO 确定这个是采购价还是销售价格
                        tErpSupplierOutbound.setTotalMoney(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow());
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                        tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
                        tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing.getId());
                        tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                        tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                        tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                        continue outer;
                    }
                    if(count<purchaseCount){
                        purchaseCount = purchaseCount - count;
                        // 添加出库记录
                        TErpSupplierOutbound tErpSupplierOutbound= new TErpSupplierOutbound();
                        tErpSupplierOutbound.setSupplierId(clinicSupplierId);
                        tErpSupplierOutbound.setWarehouseId(tErpSupplierWarehousing.getWarehouseId());
                        tErpSupplierOutbound.setOutboundType(7);
                        //TODO 确定这个是采购价还是销售价格
                        tErpSupplierOutbound.setTotalMoney(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow());
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                        tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
                        tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing.getId());
                        tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                        tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                        tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                    }
                }
            }
            if(purchaseCount>0){
                throw new RuntimeException("商品供应商库存不足,请先入库");
            }
        }
    }
}
ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml
@@ -82,7 +82,7 @@
               t1.procurement_code,
               t2.clinic_name,
               t2.clinic_address,
               t1.logistics_no,
               t1.logistics_number,
                t1.send_time,
               t1.clinic_id,
               t1.status
@@ -96,7 +96,7 @@
            and t2.clinic_name like concat('%',#{query.clinicName},'%')
        </if>
        <if test="query.logisticsNo != null and query.logisticsNo != ''">
            and t1.logistics_no = #{query.logisticsNo}
            and t1.logistics_number = #{query.logisticsNo}
        </if>
        <if test="sTime != null and eTime != ''">
            and t1.create_time between #{sTime} and #{eTime}