liujie
3 天以前 ce531d3bb32f5221b35f9e24d027ef83450ebbc6
修改bug
8个文件已修改
491 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpProcurementController.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java 247 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysGoodsServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpProcurementController.java
@@ -24,6 +24,7 @@
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@@ -267,6 +268,7 @@
    @ApiOperation(value = "采购详情入库")
    @PostMapping(value = "/updateStatusProcurement")
    @Transactional(rollbackFor = Exception.class)
    public R<DetailProcurementVO> updateStatusProcurement(@RequestBody @Valid UpdateStatusProcurementLastDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
@@ -308,9 +310,35 @@
//        tErpClinicWarehousing.setUnitAmount(tErpProcurementGoods.getSalesAmount());
        tErpClinicWarehousing.setWarehousingType(1);
        tErpClinicWarehousing.setType(1);
        tErpClinicWarehousing.setWarehouseNo("G"+ DateUtils.dateTimeNow());
        TErpClinicWarehousing last = erpClinicWarehousingService.getOne(new LambdaQueryWrapper<TErpClinicWarehousing>().orderByDesc(BaseModel::getCreateTime).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
                }
                tErpClinicWarehousing.setWarehouseNo(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpClinicWarehousing.setWarehouseNo(datePart + "00001");
            }
        }
        tErpClinicWarehousing.setProcurementId(erpProcurement.getId());
        erpClinicWarehousingService.save(tErpClinicWarehousing);
        try {
            erpClinicWarehousingService.save(tErpClinicWarehousing);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        // goodsId分组
        for (UpdateStatusProcurementDto updateStatusProcurementDto : dto.getList()) {
            TErpProcurementGoods tErpProcurementGoods = list.stream().filter(t -> t.getId().equals(updateStatusProcurementDto.getId())).findFirst().get();
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java
@@ -97,7 +97,9 @@
                List<TSysGoodsExchange> list = sysGoodsExchangeService.list(new LambdaQueryWrapper<TSysGoodsExchange>().in(TSysGoodsExchange::getGoodsId, records.stream().map(TSysGoods::getId).collect(Collectors.toList())));
                records.forEach(item -> {
                    item.setExchangeQuantity(list.stream().filter(item1 -> item1.getGoodsId().equals(item.getId())).mapToInt(TSysGoodsExchange::getGoodsCount).sum());
                    item.setSurplusQuantity(item.getGoodsTotal() - item.getExchangeQuantity());
                    if(item.getGoodsTotal()!=null){
                        item.setSurplusQuantity(item.getGoodsTotal() - item.getExchangeQuantity());
                    }
                });
            }
            pageInfo.setRecords(records);
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -30,7 +30,7 @@
    public static String YYYY_MM_DD = "yyyy-MM-dd";
    public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static String YYYYMMDDHHMMSS = "yyyyMMdd";
    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
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;
@@ -360,6 +363,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void warehouseGoods(WarehouseGoodsDto dtos, SysUser user, String supplierClinicId) {
        // dtos根据供应商分组
@@ -375,12 +379,40 @@
        TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing();
        tErpClinicWarehousing.setClinicId(supplierClinicId);
        tErpClinicWarehousing.setCreateId(user.getUserId().toString());
        tErpClinicWarehousing.setWarehouseNo("G" + DateUtils.dateTimeNow());
        TErpClinicWarehousing last = this.getOne(new LambdaQueryWrapper<TErpClinicWarehousing>().orderByDesc(BaseModel::getCreateTime).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
                }
                tErpClinicWarehousing.setWarehouseNo(datePart + String.format("%05d", number));
            } catch (NumberFormatException e) {
                // 如果解析失败,默认从00001开始
                tErpClinicWarehousing.setWarehouseNo(datePart + "00001");
            }
        }
        tErpClinicWarehousing.setCreateTime(LocalDateTime.now());
        tErpClinicWarehousing.setType(3);
        tErpClinicWarehousing.setStatus(dtos.getStatus());
        tErpClinicWarehousing.setWarehousingType(2);
        this.save(tErpClinicWarehousing);
        try {
            this.save(tErpClinicWarehousing);
        }catch (Exception e){
            throw new RuntimeException("网络繁忙,请重试");
        }
        BigDecimal totalPrice = new BigDecimal(0);
        ArrayList<String> names = new ArrayList<>();
@@ -431,17 +463,45 @@
    }
    @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).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()) {
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
@@ -7,6 +7,7 @@
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;
@@ -535,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).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) {
@@ -561,10 +589,34 @@
                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).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();
@@ -598,12 +650,37 @@
                    tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
                    tErpSupplierOutbound.setSupplierId(supplierClinicId);
                    tErpSupplierOutbound.setOutboundType(1);
                    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++;
                            } 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());
                    erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                    try {
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                    }catch (Exception e){
                        throw new RuntimeException("网络繁忙,请重试");
                    }
                    TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                    tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
@@ -619,11 +696,37 @@
                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++;
                        } 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(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing2.getGoodsId());
                erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                try {
                    erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
@@ -651,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;
@@ -669,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).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) {
@@ -682,8 +812,6 @@
            String warehousingId = tErpSupplierWarehousingBatch.getWarehousingId();
            TErpClinicWarehousing tErpSupplierWarehousing1 = erpClinicWarehousingMapper.selectById(warehousingId);
            TErpGoods erpGoods = this.getById(tErpSupplierWarehousingBatch.getGoodsId());
            // 盘点是盘亏盘盈   赢
            if (inventoryGoodsDto.getNum() < inventoryGoodsDto.getInventoryCount()) {
@@ -695,8 +823,28 @@
//                tErpSupplierWarehousing.setUnitAmount(erpGoods.getSalesAmount());
                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).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());
                if(erpGoods.getGoodsSource()==1){
@@ -705,7 +853,11 @@
                }else {
                    tErpSupplierWarehousing.setSupplierName(erpGoods.getSupplierName());
                }
                erpClinicWarehousingMapper.insert(tErpSupplierWarehousing);
                try {
                    erpClinicWarehousingMapper.insert(tErpSupplierWarehousing);
                }catch (Exception e){
                    throw new RuntimeException("网络繁忙,请重试");
                }
                // 添加批次信息
                TErpClinicWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpClinicWarehousingBatch();
@@ -735,17 +887,41 @@
            } else {
                if(inventoryGoodsDto.getDamagedCount()!=null && inventoryGoodsDto.getDamagedCount()>0){
                    TErpClinicOutbound tErpSupplierOutbound = new TErpClinicOutbound();
//                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
//                tErpSupplierOutbound.setSupplierId(supplierClinicId);
                    tErpSupplierOutbound.setOutboundType(1);
                    tErpSupplierOutbound.setOutboundNumber("G" + s);
                    TErpClinicOutbound last2 = erpClinicOutboundMapper.selectOne(new LambdaQueryWrapper<TErpClinicOutbound>().orderByDesc(BaseModel::getCreateTime).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());
                    erpClinicOutboundMapper.insert(tErpSupplierOutbound);
                    try {
                        erpClinicOutboundMapper.insert(tErpSupplierOutbound);
                    }catch (Exception e){
                        throw new RuntimeException("网络繁忙,请重试");
                    }
                    TErpClinicOutboundGoods tErpSupplierOutboundGoods = new TErpClinicOutboundGoods();
@@ -760,11 +936,36 @@
//                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
//                tErpSupplierOutbound.setSupplierId(supplierClinicId);
                tErpSupplierOutbound.setOutboundType(6);
                tErpSupplierOutbound.setOutboundNumber("G" + s);
                TErpClinicOutbound last4 = erpClinicOutboundMapper.selectOne(new LambdaQueryWrapper<TErpClinicOutbound>().orderByDesc(BaseModel::getCreateTime).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++;
                        } 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(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();
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -467,8 +467,8 @@
                String datePart = "C" + DateUtils.dateTimeNow();
                // 直接获取后五位数字并+1,不考虑是否同一天
                String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
                try {
                    String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
                    int number = Integer.parseInt(numberPart);
                    if (number < 99999) {
                        number++;
@@ -606,8 +606,34 @@
                        tErpSupplierOutbound.setOutboundType(7);
                        //TODO 确定这个是采购价还是销售价格
                        tErpSupplierOutbound.setTotalMoney(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow());
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        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");
                            }
                        }
                        try {
                            erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        }catch (Exception e){
                            throw new RuntimeException("网络繁忙,请重试");
                        }
                        TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                        tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
@@ -629,8 +655,35 @@
                        tErpSupplierOutbound.setOutboundType(7);
                        //TODO 确定这个是采购价还是销售价格
                        tErpSupplierOutbound.setTotalMoney(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
                        tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow());
                        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        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");
                            }
                        }
                        try {
                            erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                        }catch (Exception e){
                            throw new RuntimeException("网络繁忙,请重试");
                        }
                        TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                        tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
@@ -3,6 +3,7 @@
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;
@@ -24,6 +25,8 @@
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;
@@ -253,6 +256,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void warehousingGoods(List<WarehousingGoodsDto> dtos, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
@@ -273,8 +277,32 @@
        for (WarehousingGoodsDto dto : dtos) {
            TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing();
            // 当前年月日时分秒
            String time = DateUtils.dateTimeNow();
            tErpSupplierWarehousing.setWarehouseNo("G"+time);
            // 查询上一个入库单
            TErpSupplierWarehousing last = erpSupplierWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpSupplierWarehousing>().orderByDesc(TErpSupplierWarehousing::getCreateTime).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());
@@ -285,8 +313,12 @@
            tErpSupplierWarehousing.setTotalPrice(dto.getTotalPrice());
            List<WarehousingGoodsNextDto> warehousingGoodsNextDtos = dto.getWarehousingGoodsNextDtos();
            int sum = warehousingGoodsNextDtos.stream().mapToInt(WarehousingGoodsNextDto::getWarehousingNum).sum();
            tErpSupplierWarehousing.setGoodsCount( sum);
            erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
            tErpSupplierWarehousing.setGoodsCount(sum);
            try {
                erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
            }catch (Exception e){
                throw new RuntimeException("网络繁忙,请重试");
            }
            for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) {
                TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch();
@@ -513,6 +545,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void outbountGoods(OutboundGoodsDto dto, SysUser user) {
        Integer roleType = user.getRoleType();
        String supplierClinicId = null;
@@ -561,10 +594,34 @@
            tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
            tErpSupplierOutbound.setSupplierId(supplierClinicId);
            tErpSupplierOutbound.setTotalMoney(add);
            String s = DateUtils.dateTimeNow();
            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++;
                    } else {
                        number = 2; // 达到99999后重置为00002
                    }
                    tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number));
                } catch (NumberFormatException e) {
                    // 如果解析失败,默认从00001开始
                    tErpSupplierOutbound.setOutboundNumber(datePart + "00001");
                }
            }
            tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing.getGoodsId());
            erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
            try {
                erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
            }catch (Exception e){
                throw new RuntimeException("网络繁忙,请重试");
            }
            for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 : arrayList) {
                tErpSupplierOutboundGoods2.setOutboundId(tErpSupplierOutbound.getId());
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysGoodsServiceImpl.java
@@ -48,10 +48,10 @@
        // 判断已经购买的了多少
        List<TSysGoodsExchange> list = sysGoodsExchangeMapper.selectList(new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, dto.getGoodsId()));
        int sum = list.stream().mapToInt(TSysGoodsExchange::getGoodsCount).sum();
        if(sum+dto.getCount()>tSysGoods.getGoodsTotal()){
        if(tSysGoods.getGoodsTotal()!=null && sum+dto.getCount()>tSysGoods.getGoodsTotal()){
            throw new RuntimeException("商品库存不足");
        }
        if(sum+dto.getCount()>tSysGoods.getConvertibleQuantity()){
        if(tSysGoods.getConvertibleQuantity()!=null && sum+dto.getCount()>tSysGoods.getConvertibleQuantity()){
            throw new RuntimeException("可兑换数量不足");
        }
        List<TCrmClinicPoints> points = crmClinicPointsMapper.selectList(new LambdaQueryWrapper<TCrmClinicPoints>().eq(TCrmClinicPoints::getClinicId, crmClinic.getId()).ge(TCrmClinicPoints::getExpireTime, new Date()).last(" and points > use_points ORDER BY create_time ASC"));