liujie
2 天以前 f73e9c5419c82b9ff685b8e67d839fd942100073
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.DateUtils;
import com.ruoyi.system.dto.ClinicOutboundGoodsDto;
@@ -18,6 +19,8 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
@@ -80,30 +83,29 @@
    public PageInfo<PageInventoryListVo> pageInventoryList(TErpInventoryQuery query, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
        if(roleType == 5){
        if (roleType == 5) {
            // 诊所
            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId =crmClinic.getId();
            supplierClinicId = crmClinic.getId();
        }
        String sTime=null;
        String eTime =null;
        if(query.getTime()!=null && !query.getTime().isEmpty()){
        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()){
        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<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().in(TErpClinicInventoryGoods::getInventoryId,collect));
        List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().in(TErpClinicInventoryGoods::getInventoryId, collect));
        for (PageInventoryListVo pageInventoryListVo : list) {
            // 盘盈
            BigDecimal add = BigDecimal.ZERO;
@@ -114,9 +116,9 @@
            for (TErpClinicInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
                if(tErpSupplierInventoryGoods1!=null){
                if (tErpSupplierInventoryGoods1 != null) {
                    // 盘盈 查入库
                    if(tErpSupplierInventoryGoods1.getInventoryType()==1){
                    if (tErpSupplierInventoryGoods1.getInventoryType() == 1) {
                        TErpClinicWarehousingBatch tErpSupplierWarehousing = erpClinicWarehousingBatchMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingBatchId());
//                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
//                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
@@ -125,7 +127,7 @@
                        int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
                        BigDecimal multiply = tErpSupplierWarehousing.getSalesAmount().multiply(new BigDecimal(count));
                        add = add.add(multiply);
                    }else {
                    } else {
                        // 盘亏 查出库
                        TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
@@ -161,20 +163,20 @@
        ArrayList<InventoryDetailVo> inventoryDetailVos = new ArrayList<>();
        List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().eq(TErpClinicInventoryGoods::getInventoryId, id));
        if(tErpSupplierInventoryGoods!=null && !tErpSupplierInventoryGoods.isEmpty()){
        if (tErpSupplierInventoryGoods != null && !tErpSupplierInventoryGoods.isEmpty()) {
            for (TErpClinicInventoryGoods tErpSupplierInventoryGood : tErpSupplierInventoryGoods) {
                InventoryDetailVo inventoryDetailVo = new InventoryDetailVo();
                if(tErpSupplierInventoryGood.getInventoryType()==1){
                if (tErpSupplierInventoryGood.getInventoryType() == 1) {
                    TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                    String goodsId = tErpSupplierInventoryGood.getGoodsId();
                    TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                    if(goods.getGoodsSource()==1){
                    if (goods.getGoodsSource() == 1) {
                        TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
                        if(supplier!=null){
                        if (supplier != null) {
                            inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                        }
                    }else {
                    } else {
                        inventoryDetailVo.setSupplierName(goods.getSupplierName());
                    }
@@ -188,10 +190,10 @@
                    List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber()));
                    int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpClinicWarehousingBatch::getWarehousingNumber).sum();
                    List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpClinicWarehousingBatch::getId).collect(Collectors.toList());
                    if(!collect.isEmpty()){
                    if (!collect.isEmpty()) {
                        List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
                        int sum1 = tErpSupplierOutboundGoods.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
                        sum = sum-sum1;
                        sum = sum - sum1;
                    }
                    // sum = 剩余库存
@@ -199,7 +201,7 @@
                    inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
                    inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
                    inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
                }else {
                } else {
                    TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                    List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
                    for (TErpClinicOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
@@ -207,18 +209,20 @@
                        TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(warehousingId);
                        String goodsId = tErpSupplierInventoryGood.getGoodsId();
                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                        if(goods.getGoodsSource()==1){
                        if (goods.getGoodsSource() == 1) {
                            TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
                            if(supplier!=null){
                            if (supplier != null) {
                                inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                            }
                        }else {
                        } else {
                            inventoryDetailVo.setSupplierName(goods.getSupplierName());
                        }
                        inventoryDetailVo.setGoodsName(goods.getGoodsName());
                        TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
                        inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
                        if(tErpGoodsUnit!=null){
                            inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
                        }
                        inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
                        TErpClinicOutboundGoods outboundGoods = erpClinicOutboundGoodsMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
@@ -229,10 +233,10 @@
                        List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getId, outboundGoods.getWarehousingBatchId()));
                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpClinicWarehousingBatch::getWarehousingNumber).sum();
                        List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpClinicWarehousingBatch::getId).collect(Collectors.toList());
                        if(!collect.isEmpty()){
                        if (!collect.isEmpty()) {
                            List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods1 = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().in(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
                            int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
                            sum = sum-sum1;
                            sum = sum - sum1;
                        }
                        // sum = 剩余库存
@@ -256,39 +260,37 @@
    }
    @Override
    public PageInfo<ValidityPeriodWarningVo> validityPeriodWarning(ValidityPeriodWarningQuery query, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
        if(roleType == 5){
        if (roleType == 5) {
            // 诊所
            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId =crmClinic.getId();
            supplierClinicId = crmClinic.getId();
        }
        // 获取当前时间后9个月的时间
        LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(9);
        // 获取当前时间后1个月的时间
        LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(1);
        PageInfo<ValidityPeriodWarningVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        return this.baseMapper.validityPeriodWarning(pageInfo,query,user,nineMonthLater,supplierClinicId);
        return this.baseMapper.validityPeriodWarning(pageInfo, query, user, nineMonthLater, supplierClinicId);
    }
    @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()){
        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()){
        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()));
@@ -298,16 +300,17 @@
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public List<TErpGoodsVO> pageList1(TErpGoodsQuery query, SysUser user) {
        List<TErpGoodsVO> list = this.baseMapper.pageList1(query,user);
        if(list.isEmpty()){
        List<TErpGoodsVO> list = this.baseMapper.pageList1(query, user);
        if (list.isEmpty()) {
            return list;
        }
        List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
        if(!typeIds.isEmpty()){
        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()));
@@ -320,16 +323,16 @@
    @Override
    public PageInfo<TErpClinicWarehousePageListVO> warehousePageList(TClinicWarehouseQuery query, SysUser user, String supplierClinicId) {
        String time = query.getTime();
        String sTime =null;
        String sTime = null;
        String eTime = null;
        if(time!=null && !time.isEmpty()){
        if (time != null && !time.isEmpty()) {
            String[] split = time.split(" - ");
            sTime = split[0] + " 00:00:00";
            eTime = split[1] + " 23:59:59";
        }
        PageInfo<TErpClinicWarehousePageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TErpClinicWarehousePageListVO> list = this.baseMapper.warehousePageList(query,pageInfo,user,supplierClinicId,sTime,eTime);
        if(list.isEmpty()){
        List<TErpClinicWarehousePageListVO> list = this.baseMapper.warehousePageList(query, pageInfo, user, supplierClinicId, sTime, eTime);
        if (list.isEmpty()) {
            return pageInfo;
        }
        List<String> collect = list.stream().map(TErpClinicWarehousePageListVO::getId).collect(Collectors.toList());
@@ -346,90 +349,159 @@
    @Override
    public PageInfo<TErpClinicOutboundPageListVO> outboundPageList(TClinicOutboundQuery query, SysUser user, String supplierClinicId) {
        String time = query.getTime();
        String sTime =null;
        String sTime = null;
        String eTime = null;
        if(time!=null && !time.isEmpty()){
        if (time != null && !time.isEmpty()) {
            String[] split = time.split(" - ");
            sTime = split[0] + " 00:00:00";
            eTime = split[1] + " 23:59:59";
        }
        PageInfo<TErpClinicOutboundPageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TErpClinicOutboundPageListVO> list = this.baseMapper.outboundPageList(query,pageInfo,user,supplierClinicId,sTime,eTime);
        List<TErpClinicOutboundPageListVO> list = this.baseMapper.outboundPageList(query, pageInfo, user, supplierClinicId, sTime, eTime);
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void warehouseGoods(WarehouseGoodsDto dtos, SysUser user, String supplierClinicId) {
        // dtos根据供应商分组
//        Map<String, List<clinicWarehouseGoodsDto>> collect = dtos.stream().collect(Collectors.groupingBy(clinicWarehouseGoodsDto::getSupplierId));
//        for (Map.Entry<String, List<clinicWarehouseGoodsDto>> stringListEntry : collect.entrySet()) {
            TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing();
            tErpClinicWarehousing.setClinicId(supplierClinicId);
            tErpClinicWarehousing.setCreateId(user.getUserId().toString());
            tErpClinicWarehousing.setWarehouseNo("G"+ DateUtils.dateTimeNow());
            tErpClinicWarehousing.setCreateTime(LocalDateTime.now());
            tErpClinicWarehousing.setType(3);
            tErpClinicWarehousing.setStatus(dtos.getStatus());
            this.save(tErpClinicWarehousing);
        if(dtos.getStatus()==null || dtos.getStatus()!=1 ){
            // 草稿-》正式 移除所有草稿
            this.baseMapper.delete(new LambdaQueryWrapper<TErpClinicWarehousing>().eq(TErpClinicWarehousing::getClinicId,supplierClinicId).eq(TErpClinicWarehousing::getStatus,1));
        }
            BigDecimal totalPrice = new BigDecimal(0);
            for (clinicWarehouseGoodsDto dto : dtos.getDtos()) {
                TErpClinicWarehousingBatch tErpClinicWarehousingBatch = new TErpClinicWarehousingBatch();
                tErpClinicWarehousingBatch.setWarehousingId(tErpClinicWarehousing.getId());
                tErpClinicWarehousingBatch.setWarehousingNumber(dto.getPurchaseCount());
                tErpClinicWarehousingBatch.setBatchNumber(dto.getBatchNumber());
                tErpClinicWarehousingBatch.setProductionDate(dto.getProductionDate().atStartOfDay());
                tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate().atStartOfDay());
                tErpClinicWarehousingBatch.setGoodsId(dto.getId());
                TErpGoods goods = erpGoodsMapper.selectById(dto.getId());
                tErpClinicWarehousingBatch.setGoodsName(goods.getGoodsName());
                tErpClinicWarehousingBatch.setQuasiNumber(goods.getQuasiNumber());
                tErpClinicWarehousingBatch.setUnitAmount(dto.getUnitAmount());
                tErpClinicWarehousingBatch.setSalesAmount(dto.getSalesAmount());
                if(dto.getSalesAmount()==null){
                    tErpClinicWarehousingBatch.setSalesAmount(goods.getClinicPurchasePrice());
        TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing();
        tErpClinicWarehousing.setClinicId(supplierClinicId);
        tErpClinicWarehousing.setCreateId(user.getUserId().toString());
        TErpClinicWarehousing last = this.getOne(new LambdaQueryWrapper<TErpClinicWarehousing>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicWarehousing::getWarehouseNo).last("LIMIT 1"));
        if(last==null){
            tErpClinicWarehousing.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
                }
                tErpClinicWarehousingBatch.setPurchaseCount(dto.getPurchaseCount());
                erpClinicWarehousingBatchMapper.insert(tErpClinicWarehousingBatch);
                if(goods.getMaintenanceInterval()!=null && !goods.getMaintenanceInterval().isEmpty()){
                    TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
                    tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
                    tErpMaintenanceReminder.setMaintenanceType(2);
                    tErpMaintenanceReminder.setWarehousingBatchId(tErpClinicWarehousingBatch.getId());
                    Integer day = Integer.valueOf(goods.getMaintenanceInterval());
                    // 当前时间+day天
                    LocalDateTime time1 = LocalDateTime.now().plusDays(day);
                    tErpMaintenanceReminder.setMaintenanceTime(time1);
                    erpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
                }
                totalPrice = totalPrice.add(dto.getSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
                tErpClinicWarehousing.setWarehouseNo(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpClinicWarehousing.setWarehouseNo(datePart + "00001");
            }
            tErpClinicWarehousing.setTotalPrice(totalPrice);
            this.updateById(tErpClinicWarehousing);
        }
        tErpClinicWarehousing.setCreateTime(LocalDateTime.now());
        tErpClinicWarehousing.setType(3);
        tErpClinicWarehousing.setStatus(dtos.getStatus());
        tErpClinicWarehousing.setWarehousingType(2);
        try {
            this.save(tErpClinicWarehousing);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        BigDecimal totalPrice = new BigDecimal(0);
        ArrayList<String> names = new ArrayList<>();
        for (clinicWarehouseGoodsDto dto : dtos.getDtos()) {
            TErpClinicWarehousingBatch tErpClinicWarehousingBatch = new TErpClinicWarehousingBatch();
            tErpClinicWarehousingBatch.setWarehousingId(tErpClinicWarehousing.getId());
            tErpClinicWarehousingBatch.setWarehousingNumber(dto.getPurchaseCount());
            tErpClinicWarehousingBatch.setBatchNumber(dto.getBatchNumber());
            tErpClinicWarehousingBatch.setProductionDate(dto.getProductionDate().atStartOfDay());
            tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate().atStartOfDay());
            tErpClinicWarehousingBatch.setGoodsId(dto.getId());
            TErpGoods goods = erpGoodsMapper.selectById(dto.getId());
            String supplierName = goods.getSupplierName();
            names.add(supplierName);
            tErpClinicWarehousingBatch.setGoodsName(goods.getGoodsName());
            tErpClinicWarehousingBatch.setQuasiNumber(goods.getQuasiNumber());
            tErpClinicWarehousingBatch.setUnitAmount(dto.getUnitAmount());
            tErpClinicWarehousingBatch.setSalesAmount(dto.getSalesAmount());
            if (dto.getSalesAmount() == null) {
                tErpClinicWarehousingBatch.setSalesAmount(goods.getClinicPurchasePrice());
            }
            tErpClinicWarehousingBatch.setPurchaseCount(dto.getPurchaseCount());
            erpClinicWarehousingBatchMapper.insert(tErpClinicWarehousingBatch);
            if (goods.getMaintenanceInterval() != null && !goods.getMaintenanceInterval().isEmpty()) {
                TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
                tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
                tErpMaintenanceReminder.setMaintenanceType(2);
                tErpMaintenanceReminder.setWarehousingBatchId(tErpClinicWarehousingBatch.getId());
                Integer day = Integer.valueOf(goods.getMaintenanceInterval());
                // 当前时间+day天
                LocalDateTime time1 = LocalDateTime.now().plusDays(day);
                tErpMaintenanceReminder.setMaintenanceTime(time1);
                erpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
            }
            totalPrice = totalPrice.add(dto.getUnitAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
        }
        tErpClinicWarehousing.setTotalPrice(totalPrice);
        String name = names.stream().collect(Collectors.joining(","));
        tErpClinicWarehousing.setSupplierName(name);
        this.updateById(tErpClinicWarehousing);
//        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void outboundGoods(ClinicOutboundGoodsDto dto, SysUser user, String supplierClinicId) {
        TErpClinicOutbound tErpClinicOutbound = new TErpClinicOutbound();
        tErpClinicOutbound.setClinicId(supplierClinicId);
        tErpClinicOutbound.setCreateId(user.getUserId().toString());
        tErpClinicOutbound.setOutboundNumber("G"+ DateUtils.dateTimeNow());
        TErpClinicOutbound last = erpClinicOutboundMapper.selectOne(new LambdaQueryWrapper<TErpClinicOutbound>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicOutbound::getOutboundNumber).last("limit 1"));
        if(last==null){
            tErpClinicOutbound.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
                }
                tErpClinicOutbound.setOutboundNumber(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpClinicOutbound.setOutboundNumber(datePart + "00001");
            }
        }
        tErpClinicOutbound.setCreateTime(LocalDateTime.now());
        tErpClinicOutbound.setOutboundType(dto.getOutboundType());
        tErpClinicOutbound.setTotalMoney(dto.getTotalPrice());
        tErpClinicOutbound.setOutboundReason(dto.getOutboundReason());
        tErpClinicOutbound.setTypeNum(dto.getTypeNum());
        erpClinicOutboundMapper.insert(tErpClinicOutbound);
        try {
            erpClinicOutboundMapper.insert(tErpClinicOutbound);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        List<TErpClinicOutboundGoods> tErpClinicOutboundGoods = new ArrayList<>();
        for (OutboundGoodsNextDto outboundGoodsNextDto : dto.getOutboundGoodsNextDtos()) {
@@ -440,7 +512,11 @@
            tErpClinicOutboundGoods1.setWarehousingId(tErpClinicWarehousingBatch.getWarehousingId());
            tErpClinicOutboundGoods1.setWarehousingBatchId(batchId);
            tErpClinicOutboundGoods1.setOutboundCount(outboundGoodsNextDto.getNum());
            tErpClinicOutboundGoods1.setTotalPrice(tErpClinicWarehousingBatch.getUnitAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum())));
            if(tErpClinicWarehousingBatch.getUnitAmount()==null){
                tErpClinicOutboundGoods1.setTotalPrice(tErpClinicWarehousingBatch.getSalesAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum())));
            }else {
                tErpClinicOutboundGoods1.setTotalPrice(tErpClinicWarehousingBatch.getUnitAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum())));
            }
            tErpClinicOutboundGoods1.setGoodsId(tErpClinicWarehousingBatch.getGoodsId());
            tErpClinicOutboundGoods.add(tErpClinicOutboundGoods1);
            erpClinicOutboundGoodsMapper.insert(tErpClinicOutboundGoods1);