xuhy
2 天以前 72aaf45389cd09c206ee1b90f0c7f5bf59782930
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
@@ -7,19 +7,20 @@
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.utils.CodeGenerateUtils;
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.TClinicGoodsWarehouseQuery;
import com.ruoyi.system.query.TErpGoodsInventoryQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.*;
import com.ruoyi.system.service.TErpGoodsService;
import com.ruoyi.system.service.TErpSupplierInventoryGoodsService;
import com.ruoyi.system.vo.*;
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;
@@ -52,31 +53,37 @@
    @Resource
    private TErpSupplierInventoryMapper erpSupplierInventoryMapper;
    @Resource
    private TErpClinicInventoryMapper erpClinicInventoryMapper;
    @Resource
    private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper;
    @Resource
    private TErpClinicInventoryGoodsMapper erpClinicInventoryGoodsMapper;
    @Resource
    private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper;
    @Resource
    private TErpClinicWarehousingMapper erpClinicWarehousingMapper;
    @Resource
    private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper;
    @Resource
    private TErpClinicWarehousingBatchMapper erpClinicWarehousingBatchMapper;
    @Resource
    private TErpSupplierOutboundMapper erpSupplierOutboundMapper;
    @Resource
    private TErpClinicOutboundMapper erpClinicOutboundMapper;
    @Resource
    private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
    @Resource
    private TErpClinicOutboundGoodsMapper erpClinicOutboundGoodsMapper;
@@ -85,6 +92,10 @@
    @Resource
    private  TCrmSupplierMapper crmSupplierMapper;
    @Resource
    private TErpProcurementMapper erpProcurementMapper;
    @Override
@@ -101,9 +112,57 @@
                typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName()));
            }
        }
        List<String> collect = list.stream().filter(e -> e.getGoodsSource() == 1).map(TErpGoods::getSupplierClinicId).collect(Collectors.toList());
        if (!collect.isEmpty()) {
            List<TCrmSupplier> crmClinics = crmSupplierMapper.selectBatchIds(collect);
            for (TErpGoodsVO tErpGoodsVO : list) {
                crmClinics.stream().filter(t -> t.getId().equals(tErpGoodsVO.getSupplierClinicId())).findFirst().ifPresent(t -> tErpGoodsVO.setSupplierName(t.getSupplierName()));
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public PageInfo<TErpGoodsVO> pageList1(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 PageInfo<TErpGoodsVO> pageAdminList(TErpGoodsAdminQuery query) {
        PageInfo<TErpGoodsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TErpGoodsVO> list = this.baseMapper.pageAdminList(query, pageInfo);
        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<TErpGoods> pageAddList(Page<TErpGoods> tErpGoodsPage, String clinicSupplierId, PageAddListQuery query) {
        return this.baseMapper.pageAddList(tErpGoodsPage, clinicSupplierId, query);
    }
    @Override
@@ -139,7 +198,15 @@
    @Override
    public boolean isExit(String goodsIdCode, String quasiNumber,String id) {
        Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).ne(id!=null,TErpGoods::getId, id).eq(TErpGoods::getGoodsIdCode, goodsIdCode).or().eq(TErpGoods::getQuasiNumber, quasiNumber));
        Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).eq(TErpGoods::getGoodsSource,1).ne(id!=null,TErpGoods::getId, id).and(q -> q.eq(TErpGoods::getGoodsIdCode, goodsIdCode).or().eq(TErpGoods::getQuasiNumber, quasiNumber)));
        if (size > 0) {
            return true;
        }
        return false;
    }
    @Override
    public boolean isExitOne(String goodsIdCode, String quasiNumber,String id) {
        Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).eq(TErpGoods::getGoodsSource,1).ne(id!=null,TErpGoods::getId, id).and(q -> q.eq(TErpGoods::getQuasiNumber, quasiNumber)));
        if (size > 0) {
            return true;
        }
@@ -342,6 +409,26 @@
        }
        wrapper.orderByDesc(BaseModel::getCreateTime);
        Page<TErpGoods> page = this.page(new Page<>(query.getPageNum(), query.getPageSize()), wrapper);
        List<TErpGoods> records = page.getRecords();
        if(records.isEmpty()){
            return page;
        }
        List<String> packingUnitId = records.stream().map(TErpGoods::getPackingUnitId).collect(Collectors.toList());
        if(!packingUnitId.isEmpty()){
            List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId);
            for (TErpGoods tErpGoods : records) {
                tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoods.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoods.setPackingUnitName(t.getUnitName()));
            }
        }
        List<String> typeIds = records.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
        if(!typeIds.isEmpty()){
            List<TErpGoodsType> tErpGoodsTypes = erpGoodsTypeMapper.selectBatchIds(typeIds);
            for (TErpGoods tErpGoods : records) {
                tErpGoodsTypes.stream().filter(t -> t.getId().equals(tErpGoods.getTypeId())).findFirst().ifPresent(t -> tErpGoods.setTypeName(t.getTypeName()));
            }
        }
        page.setRecords( records);
        return page;
    }
@@ -352,6 +439,10 @@
        warehouseGoodsDetailVo.setCreateTime(tErpClinicWarehousing.getCreateTime());
        warehouseGoodsDetailVo.setCreateBy(tErpClinicWarehousing.getCreateBy());
        if(tErpClinicWarehousing.getType()==1){
            TErpProcurement tErpProcurement = erpProcurementMapper.selectById(tErpClinicWarehousing.getProcurementId());
            warehouseGoodsDetailVo.setInventoryNumber(tErpProcurement.getProcurementCode());
        }
        if(tErpClinicWarehousing.getType()==2){
            TErpClinicInventory tErpClinicInventory = erpClinicInventoryMapper.selectById(tErpClinicWarehousing.getInventoryId());
            warehouseGoodsDetailVo.setInventoryNumber(tErpClinicInventory.getInventoryNumber());
        }
@@ -360,9 +451,12 @@
        for (TErpClinicWarehousingBatch tErpClinicWarehousingBatch : tErpClinicWarehousingBatches) {
            String goodsId = tErpClinicWarehousingBatch.getGoodsId();
            TErpGoods tErpGoods = erpGoodsMapper.selectById(goodsId);
            tErpClinicWarehousingBatch.setGoodsName(tErpGoods.getGoodsName());
            String packingUnitId = tErpGoods.getPackingUnitId();
            TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(packingUnitId);
            tErpClinicWarehousingBatch.setUnitName(tErpGoodsUnit.getUnitName());
            if(tErpGoodsUnit!=null){
                tErpClinicWarehousingBatch.setUnitName(tErpGoodsUnit.getUnitName());
            }
        }
@@ -378,6 +472,7 @@
        outboundGoodsDetailVo.setCreateBy(tErpClinicOutbound.getCreateBy());
        outboundGoodsDetailVo.setOutboundType(tErpClinicOutbound.getOutboundType());
        outboundGoodsDetailVo.setOrderNumber(tErpClinicOutbound.getOrderNumber());
        outboundGoodsDetailVo.setOutboundReason(tErpClinicOutbound.getOutboundReason());
        if(tErpClinicOutbound.getOutboundType()==6){
            TErpClinicInventory tErpClinicInventory = erpClinicInventoryMapper.selectById(tErpClinicOutbound.getInventoryId());
            outboundGoodsDetailVo.setInventoryNumber(tErpClinicInventory.getInventoryNumber());
@@ -392,7 +487,7 @@
            outboundGoodsDetailNextVo.setWarehouseNo(tErpClinicWarehousing.getWarehouseNo());
            outboundGoodsDetailNextVo.setGoodsId(outboundGoods.getGoodsId());
            TErpGoods goods = erpGoodsMapper.selectById(outboundGoods.getGoodsId());
            TErpGoods goods = erpGoodsMapper.getGoodsById(outboundGoods.getGoodsId());
            outboundGoodsDetailNextVo.setGoodsName(goods.getGoodsName());
            outboundGoodsDetailNextVo.setTypeId(goods.getTypeId());
@@ -422,6 +517,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void inventoryGoods(InventoryDto dto, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
@@ -440,11 +536,38 @@
            supplierClinicId =crmClinic.getId();
        }
        TErpSupplierInventory tErpSupplierInventory = new TErpSupplierInventory();
        String s = DateUtils.dateTimeNow();
        tErpSupplierInventory.setInventoryNumber("P" + s);
        TErpSupplierInventory last1 = erpSupplierInventoryMapper.selectOne(new LambdaQueryWrapper<TErpSupplierInventory>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpSupplierInventory::getInventoryNumber).last("limit 1"));
        if(last1==null){
            tErpSupplierInventory.setInventoryNumber("P" + DateUtils.dateTimeNow()+"00001");
        }else {
            String lastProcurementCode = last1.getInventoryNumber();
            String datePart = "P" + 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
                }
                tErpSupplierInventory.setInventoryNumber(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpSupplierInventory.setInventoryNumber(datePart + "00001");
            }
        }
        tErpSupplierInventory.setWarehouseId(dto.getWarehouseId());
        tErpSupplierInventory.setSupplierId(supplierClinicId);
        erpSupplierInventoryMapper.insert(tErpSupplierInventory);
        try {
            erpSupplierInventoryMapper.insert(tErpSupplierInventory);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        List<InventoryGoodsDto> dtos = dto.getDtos();
        for (InventoryGoodsDto inventoryGoodsDto : dtos) {
@@ -463,13 +586,37 @@
                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())));
                tErpSupplierWarehousing.setUnitAmount(tErpSupplierWarehousing1.getUnitAmount());
                tErpSupplierWarehousing.setTotalPrice(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(tErpSupplierWarehousing.getGoodsCount())));
                // 当前年月日时分秒
                String time = DateUtils.dateTimeNow();
                tErpSupplierWarehousing.setWarehouseNo("G" + time);
                TErpSupplierWarehousing last = erpSupplierWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpSupplierWarehousing>().orderByDesc(BaseModel::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.setType(2);
                erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
                try {
                    erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                // 添加批次信息
                TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpSupplierWarehousingBatch();
@@ -493,16 +640,93 @@
                erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods);
            } else {
                int i =1;
                TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = erpSupplierWarehousingBatchMapper.selectById(inventoryGoodsDto.getId());
                String warehousingId1 = tErpSupplierWarehousingBatch1.getWarehousingId();
                TErpSupplierWarehousing tErpSupplierWarehousing2 = erpSupplierWarehousingMapper.selectById(warehousingId1);
                if(inventoryGoodsDto.getDamagedCount()!=null && inventoryGoodsDto.getDamagedCount()>0){
                    TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound();
                    tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
                    tErpSupplierOutbound.setSupplierId(supplierClinicId);
                    tErpSupplierOutbound.setOutboundType(1);
                    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");
                        }
                    }
                    int count = inventoryGoodsDto.getDamagedCount();
                    tErpSupplierOutbound.setTotalMoney(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count)));
                    tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing2.getGoodsId());
                    try {
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                    }catch (Exception e){
                        throw new RuntimeException("网络繁忙,请重试");
                    }
                    TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                    tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
                    tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId());
                    tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                    tErpSupplierOutboundGoods.setOutboundCount(count);
                    tErpSupplierOutboundGoods.setTotalPrice(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count)));
                    erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                    i=2;
                }
                TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound();
                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
                tErpSupplierOutbound.setSupplierId(supplierClinicId);
                tErpSupplierOutbound.setOutboundType(6);
                tErpSupplierOutbound.setOutboundNumber("G" + s);
                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+=i;
                        } else {
                            number = 2; // 达到99999后重置为00002
                        }
                        tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number));
                    } catch (NumberFormatException e) {
                        // 如果解析失败,默认从00001开始
                        tErpSupplierOutbound.setOutboundNumber(datePart + "00001");
                    }
                }
                int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount();
                tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                tErpSupplierOutbound.setTotalMoney(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing2.getGoodsId());
                try {
                    erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
@@ -510,7 +734,7 @@
                tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId());
                tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                tErpSupplierOutboundGoods.setOutboundCount(count);
                tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutboundGoods.setTotalPrice(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count)));
                erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
@@ -530,6 +754,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void inventoryGoods1(InventoryDto dto, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
@@ -548,10 +773,36 @@
            supplierClinicId =crmClinic.getId();
        }
        TErpClinicInventory tErpSupplierInventory = new TErpClinicInventory();
        String s = DateUtils.dateTimeNow();
        tErpSupplierInventory.setInventoryNumber("P" + s);
        TErpClinicInventory last = erpClinicInventoryMapper.selectOne(new LambdaQueryWrapper<TErpClinicInventory>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicInventory::getInventoryNumber).last("limit 1"));
        if(last==null){
            tErpSupplierInventory.setInventoryNumber("P" + DateUtils.dateTimeNow()+"00001");
        }else {
            String lastProcurementCode = last.getInventoryNumber();
            String datePart = "P" + 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
                }
                tErpSupplierInventory.setInventoryNumber(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpSupplierInventory.setInventoryNumber(datePart + "00001");
            }
        }
        tErpSupplierInventory.setClinicId(supplierClinicId);
        erpClinicInventoryMapper.insert(tErpSupplierInventory);
        try {
            erpClinicInventoryMapper.insert(tErpSupplierInventory);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        List<InventoryGoodsDto> dtos = dto.getDtos();
        for (InventoryGoodsDto inventoryGoodsDto : dtos) {
@@ -570,13 +821,43 @@
//                tErpSupplierWarehousing.setGoodsName(erpGoods.getGoodsName());
//                tErpSupplierWarehousing.setPurchaseCount(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum());
//                tErpSupplierWarehousing.setUnitAmount(erpGoods.getSalesAmount());
                tErpSupplierWarehousing.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum())));
                tErpSupplierWarehousing.setTotalPrice(tErpSupplierWarehousingBatch.getUnitAmount().multiply(new BigDecimal(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum())));
                // 当前年月日时分秒
                String time = DateUtils.dateTimeNow();
                tErpSupplierWarehousing.setWarehouseNo("G" + time);
                TErpClinicWarehousing last1 = erpClinicWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpClinicWarehousing>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicWarehousing::getWarehouseNo).last("limit 1"));
                if(last1==null){
                    tErpSupplierWarehousing.setWarehouseNo("G" + DateUtils.dateTimeNow()+"00001");
                }else {
                    String lastProcurementCode = last1.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.setType(2);
                tErpSupplierWarehousing.setInventoryId(tErpSupplierInventory.getId());
                erpClinicWarehousingMapper.insert(tErpSupplierWarehousing);
                if(erpGoods.getGoodsSource()==1){
                    TCrmSupplier supplier = crmSupplierMapper.selectById(erpGoods.getSupplierClinicId());
                    tErpSupplierWarehousing.setSupplierName(supplier.getSupplierName());
                }else {
                    tErpSupplierWarehousing.setSupplierName(erpGoods.getSupplierName());
                }
                try {
                    erpClinicWarehousingMapper.insert(tErpSupplierWarehousing);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                // 添加批次信息
                TErpClinicWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpClinicWarehousingBatch();
@@ -605,17 +886,87 @@
                erpClinicInventoryGoodsMapper.insert(tErpSupplierInventoryGoods);
            } else {
                int i=1;
                if(inventoryGoodsDto.getDamagedCount()!=null && inventoryGoodsDto.getDamagedCount()>0){
                    TErpClinicOutbound tErpSupplierOutbound = new TErpClinicOutbound();
//                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
//                tErpSupplierOutbound.setSupplierId(supplierClinicId);
                    tErpSupplierOutbound.setOutboundType(1);
                    TErpClinicOutbound last2 = erpClinicOutboundMapper.selectOne(new LambdaQueryWrapper<TErpClinicOutbound>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicOutbound::getOutboundNumber).last("limit 1"));
                    if(last2==null){
                        tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow()+"00001");
                    }else {
                        String lastProcurementCode = last2.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");
                        }
                    }
                    int count = inventoryGoodsDto.getDamagedCount();
                    tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                    tErpSupplierOutbound.setInventoryId(tErpSupplierInventory.getId());
                    try {
                        erpClinicOutboundMapper.insert(tErpSupplierOutbound);
                    }catch (Exception e){
                        throw new RuntimeException("网络繁忙,请重试");
                    }
                    TErpClinicOutboundGoods tErpSupplierOutboundGoods = new TErpClinicOutboundGoods();
                    tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
                    tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId());
                    tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                    tErpSupplierOutboundGoods.setOutboundCount(count);
                    tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                    erpClinicOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                    i=2;
                }
                TErpClinicOutbound tErpSupplierOutbound = new TErpClinicOutbound();
//                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
//                tErpSupplierOutbound.setSupplierId(supplierClinicId);
                tErpSupplierOutbound.setOutboundType(6);
                tErpSupplierOutbound.setOutboundNumber("G" + s);
                TErpClinicOutbound last4 = erpClinicOutboundMapper.selectOne(new LambdaQueryWrapper<TErpClinicOutbound>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicOutbound::getOutboundNumber).last("limit 1"));
                if(last4==null){
                    tErpSupplierOutbound.setOutboundNumber("G" +  DateUtils.dateTimeNow()+"00001");
                }else {
                    String lastProcurementCode = last4.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+=i;
                        } else {
                            number = 2; // 达到99999后重置为00002
                        }
                        tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number));
                    } catch (NumberFormatException e) {
                        // 如果解析失败,默认从00001开始
                        tErpSupplierOutbound.setOutboundNumber(datePart + "00001");
                    }
                }
                int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount();
                tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutbound.setTotalMoney(tErpSupplierWarehousingBatch.getSalesAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutbound.setInventoryId(tErpSupplierInventory.getId());
                erpClinicOutboundMapper.insert(tErpSupplierOutbound);
                try {
                    erpClinicOutboundMapper.insert(tErpSupplierOutbound);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                TErpClinicOutboundGoods tErpSupplierOutboundGoods = new TErpClinicOutboundGoods();
@@ -623,7 +974,7 @@
                tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId());
                tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                tErpSupplierOutboundGoods.setOutboundCount(count);
                tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutboundGoods.setTotalPrice(tErpSupplierWarehousingBatch.getSalesAmount().multiply(new BigDecimal(count)));
                erpClinicOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);