liujie
6 天以前 cb86c79d9cf74418a51d022103fc42c7634a0331
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
@@ -3,21 +3,26 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.dto.WarehousingGoodsDto;
import com.ruoyi.system.dto.WarehousingGoodsNextDto;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.TErpGoodsWarehouseQuery;
import com.ruoyi.system.query.TErpInventoryQuery;
import com.ruoyi.system.query.ValidityPeriodWarningQuery;
import com.ruoyi.system.service.TErpSupplierWarehousingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.vo.TErpGoodsVO;
import com.ruoyi.system.vo.TErpGoodsWarehouseLastVO;
import com.ruoyi.system.vo.TErpGoodsWarehouseRecordLastVO;
import com.ruoyi.system.vo.TErpGoodsWarehouseVO;
import com.ruoyi.system.vo.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -52,6 +57,18 @@
    @Resource
    private TCrmWarehouseMapper crmWarehouseMapper;
    @Resource
    private TErpMaintenanceReminderMapper tErpMaintenanceReminderMapper;
    @Resource
    private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper;
    @Resource
    private TErpSupplierOutboundMapper erpSupplierOutboundMapper;
    @Resource
    private TErpGoodsUnitMapper erpGoodsUnitMapper;
    @Override
@@ -123,7 +140,7 @@
                    tErpGoodsWarehouseVO.setNowNum(tErpSupplierWarehousingBatch.getWarehousingNumber());
                }
                tErpGoodsWarehouseVO.setUnitAmount(new BigDecimal(tErpSupplierWarehousing.getUnitAmount()*tErpGoodsWarehouseVO.getNowNum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
                tErpGoodsWarehouseVO.setUnitAmount(tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(tErpGoodsWarehouseVO.getNowNum())).setScale(2, RoundingMode.HALF_UP).doubleValue());
                tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
            }
            tErpGoodsWarehouseLastVO.setAllNum(tErpGoodsWarehouseVOS.stream().mapToInt(TErpGoodsWarehouseVO::getNowNum).sum());
@@ -138,10 +155,208 @@
    @Override
    public PageInfo<TErpGoodsWarehouseRecordLastVO> pageWarehouseList(TErpGoodsWarehouseQuery query, SysUser user) {
        TErpGoods goods = erpGoodsMapper.selectById(query.getGoodsId());
        PageInfo<TErpGoodsWarehouseRecordLastVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TErpGoodsWarehouseRecordLastVO> list = this.baseMapper.pageWarehouseList(query,pageInfo,user);
        String sTime=null;
        String eTime =null;
        if(query.getTime()!=null && !query.getTime().isEmpty()){
            String[] split = query.getTime().split(" - ");
            sTime = split[0] + " 00:00:00";
            eTime = split[1] + " 23:59:59";
        }
        List<TErpGoodsWarehouseRecordLastVO> list = this.baseMapper.pageWarehouseList(query,pageInfo,user,sTime,eTime);
        for (TErpGoodsWarehouseRecordLastVO tErpGoodsWarehouseRecordLastVO : list) {
            ArrayList<TErpGoodsWarehouseVO> tErpGoodsWarehouseVOS = new ArrayList<>();
            if(tErpGoodsWarehouseRecordLastVO.getCategory()==1){
                List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpGoodsWarehouseRecordLastVO.getId()));
                for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : tErpSupplierWarehousingBatches) {
                    TErpGoodsWarehouseVO tErpGoodsWarehouseVO = new TErpGoodsWarehouseVO();
                    tErpGoodsWarehouseVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                    tErpGoodsWarehouseVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
                    tErpGoodsWarehouseVO.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
                    tErpGoodsWarehouseVO.setNowNum(tErpSupplierWarehousingBatch.getWarehousingNumber());
                    tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
                }
            }else {
                List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpGoodsWarehouseRecordLastVO.getId()));
                for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 : tErpSupplierOutboundGoods) {
                    TErpGoodsWarehouseVO tErpGoodsWarehouseVO = new TErpGoodsWarehouseVO();
                    String warehousingBatchId = tErpSupplierOutboundGoods1.getWarehousingBatchId();
                    TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(warehousingBatchId);
                    tErpGoodsWarehouseVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                    tErpGoodsWarehouseVO.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
                    tErpGoodsWarehouseVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
                    tErpGoodsWarehouseVO.setNowNum(tErpSupplierOutboundGoods1.getOutboundCount());
                    tErpGoodsWarehouseVOS.add(tErpGoodsWarehouseVO);
                }
            }
            tErpGoodsWarehouseRecordLastVO.setAllNum(tErpGoodsWarehouseVOS.stream().mapToInt(TErpGoodsWarehouseVO::getNowNum).sum());
            tErpGoodsWarehouseRecordLastVO.setWarningInventory(goods.getWarningInventory());
            tErpGoodsWarehouseRecordLastVO.setList(tErpGoodsWarehouseVOS);
        return null;
        }
        pageInfo.setRecords( list);
        return pageInfo;
    }
    @Override
    public void warehousingGoods(List<WarehousingGoodsDto> dtos, SysUser user) {
        for (WarehousingGoodsDto dto : dtos) {
            TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing();
            // 当前年月日时分秒
            String time = DateUtils.dateTimeNow();
            tErpSupplierWarehousing.setWarehouseNo("G"+time);
            tErpSupplierWarehousing.setSupplierId(user.getUserId().toString());
            tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId());
            tErpSupplierWarehousing.setGoodsId(dto.getGoodsId());
            TErpGoods goods = erpGoodsMapper.selectById(dto.getGoodsId());
            tErpSupplierWarehousing.setGoodsName(goods.getGoodsName());
            tErpSupplierWarehousing.setGoodsCount(tErpSupplierWarehousing.getGoodsCount());
            tErpSupplierWarehousing.setUnitAmount(tErpSupplierWarehousing.getUnitAmount());
            tErpSupplierWarehousing.setTotalPrice(tErpSupplierWarehousing.getTotalPrice());
            erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
            List<WarehousingGoodsNextDto> warehousingGoodsNextDtos = dto.getWarehousingGoodsNextDtos();
            for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) {
                TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch();
                tErpSupplierWarehousingBatch.setWarehousingId(tErpSupplierWarehousing.getId());
                tErpSupplierWarehousingBatch.setWarehousingNumber(warehousingGoodsNextDto.getWarehousingNum());
                tErpSupplierWarehousingBatch.setBatchNumber(warehousingGoodsNextDto.getBatchNumber());
                tErpSupplierWarehousingBatch.setProductionDate(warehousingGoodsNextDto.getProductionDate().atStartOfDay());
                tErpSupplierWarehousingBatch.setExpiryDate(warehousingGoodsNextDto.getExpiryDate().atStartOfDay());
                erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch);
                if(goods.getMaintenanceInterval()!=null){
                    TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
                    tErpMaintenanceReminder.setClinicSupplierId(user.getUserId().toString());
                    tErpMaintenanceReminder.setMaintenanceType(1);
                    tErpMaintenanceReminder.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                    Integer day = Integer.valueOf(goods.getMaintenanceInterval());
                    // 当前时间+day天
                    LocalDateTime time1 = LocalDateTime.now().plusDays(day);
                    tErpMaintenanceReminder.setMaintenanceTime(time1);
                    tErpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
                }
            }
        }
    }
    @Override
    public PageInfo<ValidityPeriodWarningVo> validityPeriodWarning(ValidityPeriodWarningQuery query, SysUser user) {
        // 获取当前时间后9个月的时间
        LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(9);
        PageInfo<ValidityPeriodWarningVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        return this.baseMapper.validityPeriodWarning(pageInfo,query,user,nineMonthLater);
    }
    @Override
    public PageInfo<PageInventoryListVo> pageInventoryList(TErpInventoryQuery query, SysUser user) {
        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);
        if(list.isEmpty()){
            return pageInfo;
        }
        List<String> collect = list.stream().map(PageInventoryListVo::getId).collect(Collectors.toList());
        List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoods = erpSupplierInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierInventoryGoods>().in(TErpSupplierInventoryGoods::getInventoryId,collect));
        for (PageInventoryListVo pageInventoryListVo : list) {
                // 盘盈
                BigDecimal add = BigDecimal.ZERO;
                // 盘亏
                BigDecimal subtract = BigDecimal.ZERO;
            List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoodsList = tErpSupplierInventoryGoods.stream().filter(t -> t.getInventoryId().equals(pageInventoryListVo.getId())).collect(Collectors.toList());
            for (TErpSupplierInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
                if(tErpSupplierInventoryGoods1!=null){
                    // 盘盈 查入库
                    if(tErpSupplierInventoryGoods1.getInventoryType()==1){
                        TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
                        String goodsId = tErpSupplierWarehousing.getGoodsId();
                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
                        add = add.add(multiply);
                    }else {
                        // 盘亏 查出库
                        TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
                        List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
                        int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
                        String goodsId = tErpSupplierOutbound.getGoodsId();
                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
                        subtract = subtract.add(multiply);
                    }
                }
            }
            int size = tErpSupplierInventoryGoodsList.stream().map(TErpSupplierInventoryGoods::getGoodsId).collect(Collectors.toSet()).size();
            pageInventoryListVo.setNum(size);
            pageInventoryListVo.setTotalPrice(add.subtract(subtract));
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public List<InventoryDetailVo> detailInventory(String id, SysUser user) {
        ArrayList<InventoryDetailVo> inventoryDetailVos = new ArrayList<>();
        List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoods = erpSupplierInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierInventoryGoods>().eq(TErpSupplierInventoryGoods::getInventoryId, id));
        if(tErpSupplierInventoryGoods!=null && !tErpSupplierInventoryGoods.isEmpty()){
            for (TErpSupplierInventoryGoods tErpSupplierInventoryGood : tErpSupplierInventoryGoods) {
                InventoryDetailVo inventoryDetailVo = new InventoryDetailVo();
                if(tErpSupplierInventoryGood.getInventoryType()==1){
                    TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                    String goodsId = tErpSupplierWarehousing.getGoodsId();
                    TErpGoods goods = erpGoodsMapper.selectById(goodsId);
                    inventoryDetailVo.setGoodsName(goods.getGoodsName());
                    TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
                    inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
                    inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
                    TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
                    inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                    List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber()));
                    int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
                    List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList());
                    if(!collect.isEmpty()){
                        List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, collect));
                        int sum1 = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
                        sum = sum-sum1;
                    }
                    // sum = 剩余库存
                    inventoryDetailVo.setNowCount(sum);
                    inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
                    inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
                    inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
                }
                inventoryDetailVos.add(inventoryDetailVo);
            }
            return inventoryDetailVos;
        }
        return Collections.emptyList();
    }
}