liujie
2 天以前 f15d99d9d4fdaff8b13776e861ce958ec9f26749
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
@@ -8,10 +8,12 @@
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.dto.ClinicOutboundGoodsDto;
import com.ruoyi.system.dto.OutboundGoodsNextDto;
import com.ruoyi.system.dto.WarehouseGoodsDto;
import com.ruoyi.system.dto.clinicWarehouseGoodsDto;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.*;
import com.ruoyi.system.service.TCrmSupplierService;
import com.ruoyi.system.service.TErpClinicWarehousingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.vo.*;
@@ -67,6 +69,11 @@
    @Resource
    private TErpGoodsTypeMapper erpGoodsTypeMapper;
    @Resource
    private TErpMaintenanceReminderMapper erpMaintenanceReminderMapper;
    @Resource
    private TCrmSupplierMapper crmSupplierMapper;
    @Override
@@ -161,6 +168,16 @@
                    TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                    String goodsId = tErpSupplierInventoryGood.getGoodsId();
                    TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                    if(goods.getGoodsSource()==1){
                        TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
                        if(supplier!=null){
                            inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                        }
                    }else {
                        inventoryDetailVo.setSupplierName(goods.getSupplierName());
                    }
                    inventoryDetailVo.setGoodsName(goods.getGoodsName());
                    TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
                    inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
@@ -182,6 +199,49 @@
                    inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
                    inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
                    inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
                }else {
                    TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                    List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
                    for (TErpClinicOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
                        String warehousingId = tErpSupplierOutboundGood.getWarehousingId();
                        TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(warehousingId);
                        String goodsId = tErpSupplierInventoryGood.getGoodsId();
                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                        if(goods.getGoodsSource()==1){
                            TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
                            if(supplier!=null){
                                inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                            }
                        }else {
                            inventoryDetailVo.setSupplierName(goods.getSupplierName());
                        }
                        inventoryDetailVo.setGoodsName(goods.getGoodsName());
                        TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
                        inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
                        inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
                        TErpClinicOutboundGoods outboundGoods = erpClinicOutboundGoodsMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
                        TErpClinicWarehousingBatch tErpSupplierWarehousingBatch = erpClinicWarehousingBatchMapper.selectById(outboundGoods.getWarehousingBatchId());
                        inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                        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()){
                            List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods1 = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
                            int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
                            sum = sum-sum1;
                        }
                        // sum = 剩余库存
                        inventoryDetailVo.setNowCount(sum);
                        inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
                        inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
                        inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
                    }
                }
                inventoryDetailVos.add(inventoryDetailVo);
@@ -238,6 +298,24 @@
        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()){
            return list;
        }
        List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
        if(!typeIds.isEmpty()){
            List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds);
            for (TErpGoodsVO tErpGoodsVO : list) {
                typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName()));
                tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName());
            }
        }
        return list;
    }
    @Override
    public PageInfo<TErpClinicWarehousePageListVO> warehousePageList(TClinicWarehouseQuery query, SysUser user, String supplierClinicId) {
@@ -282,31 +360,29 @@
    }
    @Override
    public void warehouseGoods(List<clinicWarehouseGoodsDto> dtos, SysUser user, String supplierClinicId) {
    public void warehouseGoods(WarehouseGoodsDto dtos, SysUser user, String supplierClinicId) {
        // dtos根据供应商分组
        Map<String, List<clinicWarehouseGoodsDto>> collect = dtos.stream().collect(Collectors.groupingBy(clinicWarehouseGoodsDto::getSupplierId));
//        Map<String, List<clinicWarehouseGoodsDto>> collect = dtos.stream().collect(Collectors.groupingBy(clinicWarehouseGoodsDto::getSupplierId));
        for (Map.Entry<String, List<clinicWarehouseGoodsDto>> stringListEntry : collect.entrySet()) {
            String key = stringListEntry.getKey();
            List<clinicWarehouseGoodsDto> value = stringListEntry.getValue();
//        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.setSupplierId(key);
            tErpClinicWarehousing.setType(3);
            tErpClinicWarehousing.setStatus(dtos.getStatus());
            this.save(tErpClinicWarehousing);
            BigDecimal totalPrice = new BigDecimal(0);
            for (clinicWarehouseGoodsDto dto : value) {
            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());
                tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate());
                tErpClinicWarehousingBatch.setProductionDate(dto.getProductionDate().atStartOfDay());
                tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate().atStartOfDay());
                tErpClinicWarehousingBatch.setGoodsId(dto.getId());
                TErpGoods goods = erpGoodsMapper.selectById(dto.getId());
                tErpClinicWarehousingBatch.setGoodsName(goods.getGoodsName());
@@ -319,12 +395,26 @@
                tErpClinicWarehousingBatch.setPurchaseCount(dto.getPurchaseCount());
                erpClinicWarehousingBatchMapper.insert(tErpClinicWarehousingBatch);
                if(goods.getMaintenanceInterval()!=null){
                    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.setTotalPrice(totalPrice);
            this.updateById(tErpClinicWarehousing);
        }
//        }
    }