From e1b1f32ad968da303fbd4827ace995704743cdda Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期三, 17 九月 2025 09:41:32 +0800 Subject: [PATCH] 拉卡拉支付 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java | 202 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 187 insertions(+), 15 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java index 18317e6..49a3e7b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java @@ -1,10 +1,14 @@ package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.system.dto.OutboundGoodsDto; +import com.ruoyi.system.dto.OutboundGoodsNextDto; import com.ruoyi.system.dto.WarehousingGoodsDto; import com.ruoyi.system.dto.WarehousingGoodsNextDto; import com.ruoyi.system.mapper.*; @@ -13,6 +17,8 @@ import com.ruoyi.system.query.TErpGoodsWarehouseQuery; import com.ruoyi.system.query.TErpInventoryQuery; import com.ruoyi.system.query.ValidityPeriodWarningQuery; +import com.ruoyi.system.service.TCrmClinicService; +import com.ruoyi.system.service.TCrmSupplierService; import com.ruoyi.system.service.TErpSupplierWarehousingService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.system.vo.*; @@ -70,6 +76,11 @@ @Resource private TErpGoodsUnitMapper erpGoodsUnitMapper; + @Resource + private TCrmClinicMapper crmClinicMapper; + + @Resource + private TCrmSupplierMapper crmSupplierMapper; @Override public PageInfo<TErpGoodsVO> pageList(TErpGoodsQuery query, SysUser user) { @@ -92,6 +103,23 @@ @Override public List<TErpGoodsWarehouseLastVO> detail(String id, String warehouseName, SysUser user) { + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } + TErpGoods goods = erpGoodsMapper.selectById(id); @@ -99,7 +127,7 @@ if(tCrmWarehouses.isEmpty()){ return Collections.emptyList(); } - List<TErpSupplierWarehousing> tErpSupplierWarehousings = erpSupplierWarehousingMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousing>().in(TErpSupplierWarehousing::getWarehouseId, tCrmWarehouses.stream().map(TCrmWarehouse::getId).collect(Collectors.toList())).eq(TErpSupplierWarehousing::getSupplierId, user.getUserId()).eq(TErpSupplierWarehousing::getGoodsId, id)); + List<TErpSupplierWarehousing> tErpSupplierWarehousings = erpSupplierWarehousingMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousing>().in(TErpSupplierWarehousing::getWarehouseId, tCrmWarehouses.stream().map(TCrmWarehouse::getId).collect(Collectors.toList())).eq(TErpSupplierWarehousing::getSupplierId, supplierClinicId).eq(TErpSupplierWarehousing::getGoodsId, id)); if(tErpSupplierWarehousings.isEmpty()){ return Collections.emptyList(); } @@ -155,6 +183,27 @@ @Override public PageInfo<TErpGoodsWarehouseRecordLastVO> pageWarehouseList(TErpGoodsWarehouseQuery query, SysUser user) { + + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } + query.setSupplierClinicId(supplierClinicId); + + + TErpGoods goods = erpGoodsMapper.selectById(query.getGoodsId()); PageInfo<TErpGoodsWarehouseRecordLastVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); @@ -202,12 +251,28 @@ @Override public void warehousingGoods(List<WarehousingGoodsDto> dtos, SysUser user) { + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } for (WarehousingGoodsDto dto : dtos) { TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing(); // 当前年月日时分秒 String time = DateUtils.dateTimeNow(); tErpSupplierWarehousing.setWarehouseNo("G"+time); - tErpSupplierWarehousing.setSupplierId(user.getUserId().toString()); + tErpSupplierWarehousing.setSupplierId(supplierClinicId); tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId()); tErpSupplierWarehousing.setGoodsId(dto.getGoodsId()); TErpGoods goods = erpGoodsMapper.selectById(dto.getGoodsId()); @@ -228,7 +293,7 @@ if(goods.getMaintenanceInterval()!=null){ TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder(); - tErpMaintenanceReminder.setClinicSupplierId(user.getUserId().toString()); + tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId); tErpMaintenanceReminder.setMaintenanceType(1); tErpMaintenanceReminder.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId()); Integer day = Integer.valueOf(goods.getMaintenanceInterval()); @@ -245,17 +310,52 @@ @Override public PageInfo<ValidityPeriodWarningVo> validityPeriodWarning(ValidityPeriodWarningQuery query, SysUser user) { + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } // 获取当前时间后9个月的时间 LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(9); PageInfo<ValidityPeriodWarningVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); - return this.baseMapper.validityPeriodWarning(pageInfo,query,user,nineMonthLater); + + + + return this.baseMapper.validityPeriodWarning(pageInfo,query,user,nineMonthLater,supplierClinicId); } @Override public PageInfo<PageInventoryListVo> pageInventoryList(TErpInventoryQuery query, SysUser user) { + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } String sTime=null; String eTime =null; if(query.getTime()!=null && !query.getTime().isEmpty()){ @@ -264,7 +364,7 @@ eTime = split[1] + " 23:59:59"; } PageInfo<PageInventoryListVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); - List<PageInventoryListVo> list = this.baseMapper.pageInventoryList(pageInfo,query,user,sTime,eTime); + List<PageInventoryListVo> list = this.baseMapper.pageInventoryList(pageInfo,query,user,sTime,eTime,supplierClinicId); if(list.isEmpty()){ return pageInfo; } @@ -281,32 +381,43 @@ BigDecimal subtract = BigDecimal.ZERO; List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoodsList = tErpSupplierInventoryGoods.stream().filter(t -> t.getInventoryId().equals(pageInventoryListVo.getId())).collect(Collectors.toList()); for (TErpSupplierInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) { + + if(tErpSupplierInventoryGoods1!=null){ // 盘盈 查入库 if(tErpSupplierInventoryGoods1.getInventoryType()==1){ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId()); - List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId())); - int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum(); +// List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId())); +// int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum(); String goodsId = tErpSupplierWarehousing.getGoodsId(); TErpGoods goods = erpGoodsMapper.selectById(goodsId); - BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum)); + int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); + BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); add = add.add(multiply); }else { // 盘亏 查出库 TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId()); List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId())); - int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); - String goodsId = tErpSupplierOutbound.getGoodsId(); - TErpGoods goods = erpGoodsMapper.selectById(goodsId); - BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum)); - subtract = subtract.add(multiply); + for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) { + TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId()); + String goodsId = tErpSupplierWarehousing.getGoodsId(); + TErpGoods goods = erpGoodsMapper.selectById(goodsId); + int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); + BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); + add = add.add(multiply); + } +// int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); +// String goodsId = tErpSupplierOutbound.getGoodsId(); +// TErpGoods goods = erpGoodsMapper.selectById(goodsId); +// BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum)); +// subtract = subtract.add(multiply); } } } int size = tErpSupplierInventoryGoodsList.stream().map(TErpSupplierInventoryGoods::getGoodsId).collect(Collectors.toSet()).size(); pageInventoryListVo.setNum(size); - pageInventoryListVo.setTotalPrice(add.subtract(subtract)); + pageInventoryListVo.setTotalPrice(add); } @@ -354,10 +465,71 @@ return inventoryDetailVos; - } return Collections.emptyList(); } + + @Override + public void outbountGoods(OutboundGoodsDto dto, SysUser user) { + Integer roleType = user.getRoleType(); + String supplierClinicId = null; + if(roleType == 4){ + // 供应商 + TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) + .eq(TCrmSupplier::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmSupplier.getId(); + } + if(roleType == 5){ + // 诊所 + TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) + .eq(TCrmClinic::getUserId, user.getUserId()) + .last("LIMIT 1")); + supplierClinicId =crmClinic.getId(); + } + BigDecimal add = new BigDecimal(0); + ArrayList<TErpSupplierOutboundGoods> arrayList = new ArrayList<>(); + // 1 判断库存是否足够 2添加出库记录 3添加出库子记录 + List<OutboundGoodsNextDto> outboundGoodsNextDtos = dto.getOutboundGoodsNextDtos(); + for (OutboundGoodsNextDto outboundGoodsNextDto : outboundGoodsNextDtos) { + TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(outboundGoodsNextDto.getBatchId()); + List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, outboundGoodsNextDto.getBatchId())); + int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); + + int count = tErpSupplierWarehousingBatch.getWarehousingNumber() - sum; + if(count<outboundGoodsNextDto.getNum()){ + throw new ServiceException("批次号:"+tErpSupplierWarehousingBatch.getBatchNumber()+"库存不足"); + } + TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierWarehousingBatch.getWarehousingId()); + TErpGoods goods = erpGoodsMapper.selectById(tErpSupplierWarehousing.getGoodsId()); + BigDecimal multiply = goods.getSalesAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum())); + + TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 = new TErpSupplierOutboundGoods(); + tErpSupplierOutboundGoods1.setWarehousingId(dto.getWarehouseId()); + tErpSupplierOutboundGoods1.setWarehousingBatchId(outboundGoodsNextDto.getBatchId()); + tErpSupplierOutboundGoods1.setOutboundCount(outboundGoodsNextDto.getNum()); + tErpSupplierOutboundGoods1.setTotalPrice(multiply); + arrayList.add(tErpSupplierOutboundGoods1); + add = add.add(multiply); + } + + TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound(); + tErpSupplierOutbound.setOutboundType(dto.getOutboundType()); + tErpSupplierOutbound.setOutboundReason(dto.getOutboundReason()); + tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); + tErpSupplierOutbound.setSupplierId(supplierClinicId); + tErpSupplierOutbound.setTotalMoney(add); + String s = DateUtils.dateTimeNow(); + tErpSupplierOutbound.setOutboundNumber("G" + s); + erpSupplierOutboundMapper.insert(tErpSupplierOutbound); + + for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods : arrayList) { + tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId()); + erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods); + } + + + } } -- Gitblit v1.7.1