From 72aaf45389cd09c206ee1b90f0c7f5bf59782930 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 22 十月 2025 18:27:49 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java | 620 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 618 insertions(+), 2 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 a03c6e5..868a4a4 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,42 @@
package com.ruoyi.system.service.impl;
-import com.ruoyi.system.model.TErpSupplierWarehousing;
-import com.ruoyi.system.mapper.TErpSupplierWarehousingMapper;
+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.BaseModel;
+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.*;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TErpGoodsQuery;
+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.*;
+import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* <p>
@@ -17,4 +49,588 @@
@Service
public class TErpSupplierWarehousingServiceImpl extends ServiceImpl<TErpSupplierWarehousingMapper, TErpSupplierWarehousing> implements TErpSupplierWarehousingService {
+ @Resource
+ private TErpGoodsTypeMapper erpGoodsTypeMapper;
+
+ @Resource
+ private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper;
+
+ @Resource
+ private TErpGoodsMapper erpGoodsMapper;
+
+ @Resource
+ private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
+
+ @Resource
+ private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper;
+
+ @Resource
+ private TCrmWarehouseMapper crmWarehouseMapper;
+
+ @Resource
+ private TErpMaintenanceReminderMapper tErpMaintenanceReminderMapper;
+
+ @Resource
+ private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper;
+
+ @Resource
+ private TErpSupplierOutboundMapper erpSupplierOutboundMapper;
+
+ @Resource
+ private TErpGoodsUnitMapper erpGoodsUnitMapper;
+
+ @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()));
+ tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName());
+ }
+ }
+ pageInfo.setRecords(list);
+ return pageInfo;
+ }
+
+ @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);
+ List<TCrmWarehouse> tCrmWarehouses = crmWarehouseMapper.selectList(new LambdaQueryWrapper<TCrmWarehouse>().eq(warehouseName != null && !warehouseName.isEmpty(), TCrmWarehouse::getWarehouseName, warehouseName));
+ 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, supplierClinicId).eq(TErpSupplierWarehousing::getGoodsId, id));
+ if(tErpSupplierWarehousings.isEmpty()){
+ return Collections.emptyList();
+ }
+
+ // 出库详情
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().in(TErpSupplierOutboundGoods::getWarehousingId, tErpSupplierWarehousings.stream().map(TErpSupplierWarehousing::getId).collect(Collectors.toList())));
+
+ // 入库批次
+ List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().in(!tErpSupplierWarehousings.isEmpty(), TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousings.stream().map(TErpSupplierWarehousing::getId).collect(Collectors.toList())));
+
+ ArrayList<TErpGoodsWarehouseLastVO> tErpGoodsWarehouseLastVOS = new ArrayList<>();
+
+ // 通过WarehouseId分组
+
+ Map<String, List<TErpSupplierWarehousing>> collect = tErpSupplierWarehousings.stream().collect(Collectors.groupingBy(TErpSupplierWarehousing::getWarehouseId));
+ for (Map.Entry<String, List<TErpSupplierWarehousing>> entry : collect.entrySet()) {
+ TErpGoodsWarehouseLastVO tErpGoodsWarehouseLastVO = new TErpGoodsWarehouseLastVO();
+ // 获取key
+ String houseId = entry.getKey();
+ List<TErpSupplierWarehousing> list = entry.getValue();
+ tErpGoodsWarehouseLastVO.setHouseId( houseId);
+ tCrmWarehouses.stream().filter(t -> t.getId().equals(houseId)).findFirst().ifPresent(t -> tErpGoodsWarehouseLastVO.setHouseName(t.getWarehouseName()));
+ List<String> warehousingIds = list.stream().map(TErpSupplierWarehousing::getId).collect(Collectors.toList());
+
+ // 当前仓库的入库批次信息
+ List<TErpSupplierWarehousingBatch> warehousingBatchesList = tErpSupplierWarehousingBatches.stream().filter(t -> warehousingIds.contains(t.getWarehousingId())).collect(Collectors.toList());
+ ArrayList<TErpGoodsWarehouseVO> tErpGoodsWarehouseVOS = new ArrayList<>();
+ for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : warehousingBatchesList) {
+ TErpSupplierWarehousing tErpSupplierWarehousing = list.stream().filter(e -> e.getId().equals(tErpSupplierWarehousingBatch.getWarehousingId())).findFirst().get();
+ TErpGoodsWarehouseVO tErpGoodsWarehouseVO = new TErpGoodsWarehouseVO();
+ tErpGoodsWarehouseVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+ tErpGoodsWarehouseVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
+ tErpGoodsWarehouseVO.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods1 = tErpSupplierOutboundGoods.stream().filter(t -> t.getWarehousingBatchId().equals(tErpSupplierWarehousingBatch.getId())).collect(Collectors.toList());
+ if(!tErpSupplierOutboundGoods1.isEmpty()){
+ tErpGoodsWarehouseVO.setNowNum(tErpSupplierWarehousingBatch.getWarehousingNumber()-tErpSupplierOutboundGoods1.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum());
+ }else {
+ tErpGoodsWarehouseVO.setNowNum(tErpSupplierWarehousingBatch.getWarehousingNumber());
+ }
+
+ tErpGoodsWarehouseVO.setUnitAmount(tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(tErpGoodsWarehouseVO.getNowNum())).setScale(2, RoundingMode.HALF_UP).doubleValue());
+ tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
+ }
+ tErpGoodsWarehouseLastVO.setAllNum(tErpGoodsWarehouseVOS.stream().mapToInt(TErpGoodsWarehouseVO::getNowNum).sum());
+ tErpGoodsWarehouseLastVO.setAllTotalPrice(tErpGoodsWarehouseVOS.stream().mapToDouble(TErpGoodsWarehouseVO::getUnitAmount).sum());
+ tErpGoodsWarehouseLastVO.setAllTotalPrice(BigDecimal.valueOf(tErpGoodsWarehouseLastVO.getAllTotalPrice()).setScale(2,RoundingMode.HALF_UP).doubleValue());
+ tErpGoodsWarehouseLastVO.setList(tErpGoodsWarehouseVOS);
+ tErpGoodsWarehouseLastVO.setWarningInventory(goods.getWarningInventory());
+ tErpGoodsWarehouseLastVOS.add(tErpGoodsWarehouseLastVO);
+
+ }
+ return tErpGoodsWarehouseLastVOS;
+ }
+
+ @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());
+ String sTime=null;
+ String eTime =null;
+ if(query.getTime()!=null && !query.getTime().isEmpty()){
+ String[] split = query.getTime().split(" - ");
+ sTime = split[0] + " 00:00:00";
+ eTime = split[1] + " 23:59:59";
+ }
+ List<TErpGoodsWarehouseRecordLastVO> list = this.baseMapper.pageWarehouseList(query,pageInfo,user,sTime,eTime);
+ for (TErpGoodsWarehouseRecordLastVO tErpGoodsWarehouseRecordLastVO : list) {
+ ArrayList<TErpGoodsWarehouseVO> tErpGoodsWarehouseVOS = new ArrayList<>();
+ if(tErpGoodsWarehouseRecordLastVO.getCategory()==1){
+ List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpGoodsWarehouseRecordLastVO.getId()));
+ for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : tErpSupplierWarehousingBatches) {
+ TErpGoodsWarehouseVO tErpGoodsWarehouseVO = new TErpGoodsWarehouseVO();
+ tErpGoodsWarehouseVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+ tErpGoodsWarehouseVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
+ tErpGoodsWarehouseVO.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
+ tErpGoodsWarehouseVO.setNowNum(tErpSupplierWarehousingBatch.getWarehousingNumber());
+ tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
+ }
+ }else {
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpGoodsWarehouseRecordLastVO.getId()));
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 : tErpSupplierOutboundGoods) {
+ TErpGoodsWarehouseVO tErpGoodsWarehouseVO = new TErpGoodsWarehouseVO();
+ String warehousingBatchId = tErpSupplierOutboundGoods1.getWarehousingBatchId();
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(warehousingBatchId);
+ tErpGoodsWarehouseVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+ tErpGoodsWarehouseVO.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
+ tErpGoodsWarehouseVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
+ tErpGoodsWarehouseVO.setNowNum(tErpSupplierOutboundGoods1.getOutboundCount());
+ tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
+ }
+ }
+ tErpGoodsWarehouseRecordLastVO.setAllNum(tErpGoodsWarehouseVOS.stream().mapToInt(TErpGoodsWarehouseVO::getNowNum).sum());
+ tErpGoodsWarehouseRecordLastVO.setWarningInventory(goods.getWarningInventory());
+ tErpGoodsWarehouseRecordLastVO.setList(tErpGoodsWarehouseVOS);
+
+ }
+ pageInfo.setRecords( list);
+ return pageInfo;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ 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();
+ // 当前年月日时分秒
+ // 查询上一个入库单
+ TErpSupplierWarehousing last = erpSupplierWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpSupplierWarehousing>().orderByDesc(TErpSupplierWarehousing::getCreateTime).orderByDesc(TErpSupplierWarehousing::getWarehouseNo).last("LIMIT 1"));
+ if(last==null){
+ tErpSupplierWarehousing.setWarehouseNo("G"+DateUtils.dateTimeNow()+"00001");
+ }else {
+ String lastProcurementCode = last.getWarehouseNo();
+ String datePart = "G" + DateUtils.dateTimeNow();
+
+ // 直接获取后五位数字并+1,不考虑是否同一天
+ try {
+ String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
+ int number = Integer.parseInt(numberPart);
+ if (number < 99999) {
+ number++;
+ } else {
+ number = 2; // 达到99999后重置为00002
+ }
+ tErpSupplierWarehousing.setWarehouseNo(datePart + String.format("%05d", number));
+ } catch (NumberFormatException e) {
+ // 如果解析失败,默认从00001开始
+ tErpSupplierWarehousing.setWarehouseNo(datePart + "00001");
+ }
+
+ }
+
+
+ tErpSupplierWarehousing.setSupplierId(supplierClinicId);
+ tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId());
+ tErpSupplierWarehousing.setGoodsId(dto.getGoodsId());
+ TErpGoods goods = erpGoodsMapper.selectById(dto.getGoodsId());
+ tErpSupplierWarehousing.setGoodsName(goods.getGoodsName());
+ tErpSupplierWarehousing.setGoodsCount(dto.getWarehousingNum());
+ tErpSupplierWarehousing.setUnitAmount(dto.getPrice());
+ tErpSupplierWarehousing.setTotalPrice(dto.getTotalPrice());
+ List<WarehousingGoodsNextDto> warehousingGoodsNextDtos = dto.getWarehousingGoodsNextDtos();
+ int sum = warehousingGoodsNextDtos.stream().mapToInt(WarehousingGoodsNextDto::getWarehousingNum).sum();
+ tErpSupplierWarehousing.setGoodsCount(sum);
+ try {
+ erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
+ }catch (Exception e){
+ throw new RuntimeException("网络繁忙,请重试");
+ }
+
+ for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) {
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch();
+ tErpSupplierWarehousingBatch.setWarehousingId(tErpSupplierWarehousing.getId());
+ tErpSupplierWarehousingBatch.setWarehousingNumber(warehousingGoodsNextDto.getWarehousingNum());
+ tErpSupplierWarehousingBatch.setBatchNumber(warehousingGoodsNextDto.getBatchNumber());
+ tErpSupplierWarehousingBatch.setProductionDate(warehousingGoodsNextDto.getProductionDate().atStartOfDay());
+ tErpSupplierWarehousingBatch.setExpiryDate(warehousingGoodsNextDto.getExpiryDate().atStartOfDay());
+ erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch);
+
+ if(goods.getMaintenanceInterval()!=null && !goods.getMaintenanceInterval().isEmpty()){
+ TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
+ tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
+ tErpMaintenanceReminder.setMaintenanceType(1);
+ tErpMaintenanceReminder.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
+ Integer day = Integer.valueOf(goods.getMaintenanceInterval());
+ // 当前时间+day天
+ LocalDateTime time1 = LocalDateTime.now().plusDays(day);
+ tErpMaintenanceReminder.setMaintenanceTime(time1);
+ tErpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
+ }
+
+ }
+ }
+
+ }
+
+ @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,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()){
+ String[] split = query.getTime().split(" - ");
+ sTime = split[0] + " 00:00:00";
+ 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,supplierClinicId);
+ if(list.isEmpty()){
+ return pageInfo;
+ }
+
+
+
+ List<String> collect = list.stream().map(PageInventoryListVo::getId).collect(Collectors.toList());
+ List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoods = erpSupplierInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierInventoryGoods>().in(TErpSupplierInventoryGoods::getInventoryId,collect));
+ for (PageInventoryListVo pageInventoryListVo : list) {
+ // 盘盈
+ BigDecimal add = BigDecimal.ZERO;
+
+ // 盘亏
+ 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();
+ String goodsId = tErpSupplierWarehousing.getGoodsId();
+// TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+ int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().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()));
+ 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 = tErpSupplierWarehousing.getUnitAmount().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);
+
+ }
+
+ pageInfo.setRecords(list);
+ return pageInfo;
+ }
+
+ @Override
+ public List<InventoryDetailVo> detailInventory(String id, SysUser user) {
+ ArrayList<InventoryDetailVo> inventoryDetailVos = new ArrayList<>();
+
+ List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoods = erpSupplierInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierInventoryGoods>().eq(TErpSupplierInventoryGoods::getInventoryId, id));
+ if(tErpSupplierInventoryGoods!=null && !tErpSupplierInventoryGoods.isEmpty()){
+ for (TErpSupplierInventoryGoods tErpSupplierInventoryGood : tErpSupplierInventoryGoods) {
+ InventoryDetailVo inventoryDetailVo = new InventoryDetailVo();
+ if(tErpSupplierInventoryGood.getInventoryType()==1){
+ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
+ String goodsId = tErpSupplierWarehousing.getGoodsId();
+ TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+ inventoryDetailVo.setGoodsName(goods.getGoodsName());
+ TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
+ inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
+ inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
+ inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+
+ List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber()));
+ int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+ List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList());
+ if(!collect.isEmpty()){
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, collect));
+ int sum1 = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+ sum = sum-sum1;
+ }
+
+ // sum = 剩余库存
+ inventoryDetailVo.setNowCount(sum);
+ inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
+ inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
+ inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
+ }else {
+ TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+ String warehousingId = tErpSupplierOutboundGood.getWarehousingId();
+ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(warehousingId);
+ String goodsId = tErpSupplierWarehousing.getGoodsId();
+ TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+ inventoryDetailVo.setGoodsName(goods.getGoodsName());
+ TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
+ inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
+ inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
+
+ TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 = erpSupplierOutboundGoodsMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
+
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(tErpSupplierOutboundGoods2.getWarehousingBatchId());
+ inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+
+
+ List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getId, tErpSupplierOutboundGoods2.getWarehousingBatchId()));
+ int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+ List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList());
+ if(!collect.isEmpty()){
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods1 = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().in(TErpSupplierOutboundGoods::getWarehousingBatchId, collect));
+ int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+ sum = sum-sum1;
+ }
+
+ // sum = 剩余库存
+ inventoryDetailVo.setNowCount(sum);
+ inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
+ inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
+ inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
+ }
+
+ }
+ inventoryDetailVos.add(inventoryDetailVo);
+
+ }
+
+ return inventoryDetailVos;
+
+ }
+
+
+ return Collections.emptyList();
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
+ 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 = tErpSupplierWarehousing.getUnitAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum()));
+
+ TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 = new TErpSupplierOutboundGoods();
+ tErpSupplierOutboundGoods1.setWarehousingId(tErpSupplierWarehousing.getId());
+ 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);
+ TErpSupplierOutbound last = erpSupplierOutboundMapper.selectOne(new LambdaQueryWrapper<TErpSupplierOutbound>().orderByDesc(BaseModel::getCreateTime).last("LIMIT 1"));
+ if(last==null){
+ tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow()+ "00001");
+ }else{
+ String lastProcurementCode = last.getOutboundNumber();
+ String datePart = "G" + DateUtils.dateTimeNow();
+ // 直接获取后五位数字并+1,不考虑是否同一天
+ try {
+ String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
+ int number = Integer.parseInt(numberPart);
+ if (number < 99999) {
+ number++;
+ } else {
+ number = 2; // 达到99999后重置为00002
+ }
+ tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number));
+ } catch (NumberFormatException e) {
+ // 如果解析失败,默认从00001开始
+ tErpSupplierOutbound.setOutboundNumber(datePart + "00001");
+ }
+ }
+ tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing.getGoodsId());
+ try {
+ erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
+ }catch (Exception e){
+ throw new RuntimeException("网络繁忙,请重试");
+ }
+
+
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 : arrayList) {
+ tErpSupplierOutboundGoods2.setOutboundId(tErpSupplierOutbound.getId());
+ erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods2);
+ }
+
+ }
+
+
+
+ }
}
--
Gitblit v1.7.1