From 3ea64cac3a5fe42c4eba0e54cad64d496093ba82 Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期一, 15 九月 2025 18:39:01 +0800 Subject: [PATCH] 拉卡拉支付 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 268 insertions(+), 2 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java index 90a53c9..8a4daf9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java @@ -1,10 +1,31 @@ package com.ruoyi.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.system.mapper.TErpGoodsMapper; -import com.ruoyi.system.model.TErpGoods; +import com.ruoyi.common.basic.PageInfo; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.system.dto.InventoryDto; +import com.ruoyi.system.dto.InventoryGoodsDto; +import com.ruoyi.system.mapper.*; +import com.ruoyi.system.model.*; +import com.ruoyi.system.query.TErpGoodsInventoryQuery; +import com.ruoyi.system.query.TErpGoodsQuery; import com.ruoyi.system.service.TErpGoodsService; +import com.ruoyi.system.service.TErpSupplierInventoryGoodsService; +import com.ruoyi.system.vo.TErpGoodsInventoryVO; +import com.ruoyi.system.vo.TErpGoodsVO; import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; /** * <p> @@ -17,4 +38,249 @@ @Service public class TErpGoodsServiceImpl extends ServiceImpl<TErpGoodsMapper, TErpGoods> implements TErpGoodsService { + @Resource + private TErpGoodsTypeMapper erpGoodsTypeMapper; + + @Resource + private TErpGoodsUnitMapper erpGoodsUnitMapper; + + @Resource + private TErpSupplierInventoryMapper erpSupplierInventoryMapper; + + @Resource + private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper; + + @Resource + private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper; + + @Resource + private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper; + + @Resource + private TErpSupplierOutboundMapper erpSupplierOutboundMapper; + + @Resource + private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper; + + @Resource + private TCrmClinicMapper crmClinicMapper; + + @Resource + private TCrmSupplierMapper crmSupplierMapper; + + + @Override + public PageInfo<TErpGoodsVO> pageList(TErpGoodsQuery query, SysUser user) { + PageInfo<TErpGoodsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); + List<TErpGoodsVO> list = this.baseMapper.pageList(query, pageInfo, user); + if (list.isEmpty()) { + return pageInfo; + } + List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList()); + if (!typeIds.isEmpty()) { + List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); + for (TErpGoodsVO tErpGoodsVO : list) { + typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); + } + } + + pageInfo.setRecords(list); + return pageInfo; + } + + @Override + public List<TErpGoodsVO> listExport(TErpGoodsQuery query, SysUser user) { + List<TErpGoodsVO> list = this.baseMapper.listExport(query, user); + if (list.isEmpty()) { + return list; + } + List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList()); + if (!typeIds.isEmpty()) { + List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); + for (TErpGoodsVO tErpGoodsVO : list) { + typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); + tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); + } + } + List<String> lowUnitIds = list.stream().map(TErpGoods::getLowUnitId).collect(Collectors.toList()); + if (!lowUnitIds.isEmpty()) { + List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(lowUnitIds); + for (TErpGoodsVO tErpGoodsVO : list) { + tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getLowUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setLowUnitName(t.getUnitName())); + } + } + List<String> packingUnitId = list.stream().map(TErpGoods::getPackingUnitId).collect(Collectors.toList()); + if (!packingUnitId.isEmpty()) { + List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId); + for (TErpGoodsVO tErpGoodsVO : list) { + tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName())); + } + } + return list; + } + + @Override + public boolean isExit(String goodsIdCode, String quasiNumber) { + Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).eq(TErpGoods::getGoodsIdCode, goodsIdCode).or().eq(TErpGoods::getQuasiNumber, quasiNumber)); + if (size > 0) { + return true; + } + + return false; + } + + @Override + public PageInfo<TErpGoodsInventoryVO> pageInventoryGoodsPageList(TErpGoodsInventoryQuery 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(); + } + + // 当前时间一个月后 + Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1); + + PageInfo<TErpGoodsInventoryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); + List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user,supplierClinicId,endDate); + if (list.isEmpty()) { + return pageInfo; + } + List<String> typeIds = list.stream().map(TErpGoodsInventoryVO::getTypeId).collect(Collectors.toList()); + if (!typeIds.isEmpty()) { + List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); + for (TErpGoodsInventoryVO tErpGoodsVO : list) { + typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); + tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); + } + } + List<String> packingUnitId = list.stream().map(TErpGoodsInventoryVO::getPackingUnitId).collect(Collectors.toList()); + if (!packingUnitId.isEmpty()) { + List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId); + for (TErpGoodsInventoryVO tErpGoodsVO : list) { + tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName())); + } + } + pageInfo.setRecords(list); + return pageInfo; + } + + @Override + public void inventoryGoods(InventoryDto 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(); + } + TErpSupplierInventory tErpSupplierInventory = new TErpSupplierInventory(); + String s = DateUtils.dateTimeNow(); + tErpSupplierInventory.setInventoryNumber("P" + s); + tErpSupplierInventory.setWarehouseId(dto.getWarehouseId()); + tErpSupplierInventory.setSupplierId(supplierClinicId); + erpSupplierInventoryMapper.insert(tErpSupplierInventory); + + List<InventoryGoodsDto> dtos = dto.getDtos(); + for (InventoryGoodsDto inventoryGoodsDto : dtos) { + // 根据入库批次id查询入库信息 + TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing(); + TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(inventoryGoodsDto.getId()); + String warehousingId = tErpSupplierWarehousingBatch.getWarehousingId(); + TErpSupplierWarehousing tErpSupplierWarehousing1 = erpSupplierWarehousingMapper.selectById(warehousingId); + TErpGoods erpGoods = this.getById(tErpSupplierWarehousing1.getGoodsId()); + + // 盘点是盘亏盘盈 赢 + if (inventoryGoodsDto.getNum() < inventoryGoodsDto.getInventoryCount()) { + // 添加入库信息 + tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId()); + tErpSupplierWarehousing.setSupplierId(supplierClinicId); + tErpSupplierWarehousing.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); + tErpSupplierWarehousing.setGoodsName(erpGoods.getGoodsName()); + tErpSupplierWarehousing.setGoodsCount(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum()); + tErpSupplierWarehousing.setUnitAmount(erpGoods.getSalesAmount()); + tErpSupplierWarehousing.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(tErpSupplierWarehousing.getGoodsCount()))); + // 当前年月日时分秒 + String time = DateUtils.dateTimeNow(); + tErpSupplierWarehousing.setWarehouseNo("G" + time); + tErpSupplierWarehousing.setType(2); + erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing); + + // 添加批次信息 + TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpSupplierWarehousingBatch(); + tErpSupplierWarehousingBatch1.setWarehousingId(tErpSupplierWarehousing.getId()); + tErpSupplierWarehousingBatch1.setWarehousingNumber(tErpSupplierWarehousing.getGoodsCount()); + tErpSupplierWarehousingBatch1.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber()); + tErpSupplierWarehousingBatch1.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate()); + tErpSupplierWarehousingBatch1.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate()); + erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch1); + + + // 添加盘点信息 + TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods(); + tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId()); + tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierWarehousing.getId()); + tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch1.getId()); + tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount()); + tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount()); + tErpSupplierInventoryGoods.setInventoryType(1); + tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); + erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods); + + } else { + + + TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound(); + tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); + tErpSupplierOutbound.setSupplierId(supplierClinicId); + tErpSupplierOutbound.setOutboundType(6); + tErpSupplierOutbound.setOutboundNumber("G" + s); + int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount(); + tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); + erpSupplierOutboundMapper.insert(tErpSupplierOutbound); + + + TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods(); + tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId()); + tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing.getId()); + tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId()); + tErpSupplierOutboundGoods.setOutboundCount(count); + tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); + erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods); + + + // 添加盘点信息 + TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods(); + tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId()); + tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierOutbound.getId()); + tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierOutboundGoods.getId()); + tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount()); + tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount()); + tErpSupplierInventoryGoods.setInventoryType(2); + tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); + erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods); + } + } + + + } } -- Gitblit v1.7.1