xuhy
4 天以前 79c1cc71dfcf2ac2a96433439507e582b7bf23e2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
@@ -4,19 +4,23 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.TErpGoodsMapper;
import com.ruoyi.system.mapper.TErpGoodsTypeMapper;
import com.ruoyi.system.mapper.TErpSupplierInventoryMapper;
import com.ruoyi.system.mapper.TErpSupplierWarehousingMapper;
import com.ruoyi.system.model.TErpGoods;
import com.ruoyi.system.model.TErpGoodsType;
import com.ruoyi.system.model.TSysBanner;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.dto.InventoryDto;
import com.ruoyi.system.dto.InventoryGoodsDto;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TErpGoodsInventoryQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.service.TErpGoodsService;
import com.ruoyi.system.service.TErpSupplierInventoryGoodsService;
import com.ruoyi.system.vo.TErpGoodsInventoryVO;
import com.ruoyi.system.vo.TErpGoodsVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -34,20 +38,108 @@
    @Resource
    private TErpGoodsTypeMapper erpGoodsTypeMapper;
    @Resource
    private TErpGoodsUnitMapper erpGoodsUnitMapper;
    @Resource
    private TErpSupplierInventoryMapper erpSupplierInventoryMapper;
    @Resource
    private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper;
    @Resource
    private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper;
    @Resource
    private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper;
    @Resource
    private TErpSupplierOutboundMapper erpSupplierOutboundMapper;
    @Resource
    private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
    @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()));
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public List<TErpGoodsVO> listExport(TErpGoodsQuery query, SysUser user) {
        List<TErpGoodsVO> list = this.baseMapper.listExport(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());
            }
        }
        List<String> lowUnitIds = list.stream().map(TErpGoods::getLowUnitId).collect(Collectors.toList());
        if (!lowUnitIds.isEmpty()) {
            List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(lowUnitIds);
            for (TErpGoodsVO tErpGoodsVO : list) {
                tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getLowUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setLowUnitName(t.getUnitName()));
            }
        }
        List<String> packingUnitId = list.stream().map(TErpGoods::getPackingUnitId).collect(Collectors.toList());
        if (!packingUnitId.isEmpty()) {
            List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId);
            for (TErpGoodsVO tErpGoodsVO : list) {
                tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName()));
            }
        }
        return list;
    }
    @Override
    public boolean isExit(String goodsIdCode, String quasiNumber) {
        Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).eq(TErpGoods::getGoodsIdCode, goodsIdCode).or().eq(TErpGoods::getQuasiNumber, quasiNumber));
        if (size > 0) {
            return true;
        }
        return false;
    }
    @Override
    public PageInfo<TErpGoodsInventoryVO> pageInventoryGoodsPageList(TErpGoodsInventoryQuery query, SysUser user) {
        PageInfo<TErpGoodsInventoryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user);
        if (list.isEmpty()) {
            return pageInfo;
        }
        List<String> typeIds = list.stream().map(TErpGoodsInventoryVO::getTypeId).collect(Collectors.toList());
        if (!typeIds.isEmpty()) {
            List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds);
            for (TErpGoodsInventoryVO tErpGoodsVO : list) {
                typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName()));
                tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName());
            }
        }
        List<String> packingUnitId = list.stream().map(TErpGoodsInventoryVO::getPackingUnitId).collect(Collectors.toList());
        if (!packingUnitId.isEmpty()) {
            List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId);
            for (TErpGoodsInventoryVO tErpGoodsVO : list) {
                tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName()));
            }
        }
        pageInfo.setRecords(list);
@@ -55,12 +147,97 @@
    }
    @Override
    public boolean isExit(String goodsIdCode,String quasiNumber) {
        Long size = this.baseMapper.selectCount(new LambdaQueryWrapper<>(TErpGoods.class).eq(TErpGoods::getGoodsIdCode, goodsIdCode).or().eq(TErpGoods::getQuasiNumber, quasiNumber));
        if(size>0){
            return true;
    public void inventoryGoods(InventoryDto dto, SysUser user) {
        TErpSupplierInventory tErpSupplierInventory = new TErpSupplierInventory();
        String s = DateUtils.dateTimeNow();
        tErpSupplierInventory.setInventoryNumber("P" + s);
        tErpSupplierInventory.setWarehouseId(dto.getWarehouseId());
        tErpSupplierInventory.setSupplierId(String.valueOf(user.getUserId()));
        erpSupplierInventoryMapper.insert(tErpSupplierInventory);
        List<InventoryGoodsDto> dtos = dto.getDtos();
        for (InventoryGoodsDto inventoryGoodsDto : dtos) {
            // 根据入库批次id查询入库信息
            TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing();
            TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(inventoryGoodsDto.getId());
            String warehousingId = tErpSupplierWarehousingBatch.getWarehousingId();
            TErpSupplierWarehousing tErpSupplierWarehousing1 = erpSupplierWarehousingMapper.selectById(warehousingId);
            TErpGoods erpGoods = this.getById(tErpSupplierWarehousing1.getGoodsId());
            // 盘点是盘亏盘盈   赢
            if (inventoryGoodsDto.getNum() < inventoryGoodsDto.getInventoryCount()) {
                // 添加入库信息
                tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId());
                tErpSupplierWarehousing.setSupplierId(String.valueOf(user.getUserId()));
                tErpSupplierWarehousing.setGoodsId(tErpSupplierWarehousing1.getGoodsId());
                tErpSupplierWarehousing.setGoodsName(erpGoods.getGoodsName());
                tErpSupplierWarehousing.setGoodsCount(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum());
                tErpSupplierWarehousing.setUnitAmount(erpGoods.getSalesAmount());
                tErpSupplierWarehousing.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(tErpSupplierWarehousing.getGoodsCount())));
                // 当前年月日时分秒
                String time = DateUtils.dateTimeNow();
                tErpSupplierWarehousing.setWarehouseNo("G" + time);
                tErpSupplierWarehousing.setType(2);
                erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
                // 添加批次信息
                TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpSupplierWarehousingBatch();
                tErpSupplierWarehousingBatch1.setWarehousingId(tErpSupplierWarehousing.getId());
                tErpSupplierWarehousingBatch1.setWarehousingNumber(tErpSupplierWarehousing.getGoodsCount());
                tErpSupplierWarehousingBatch1.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
                tErpSupplierWarehousingBatch1.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
                tErpSupplierWarehousingBatch1.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate());
                erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch1);
                // 添加盘点信息
                TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods();
                tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId());
                tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierWarehousing.getId());
                tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch1.getId());
                tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount());
                tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount());
                tErpSupplierInventoryGoods.setInventoryType(1);
                tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId());
                erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods);
            } else {
                TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound();
                tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
                tErpSupplierOutbound.setSupplierId(String.valueOf(user.getUserId()));
                tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing1.getGoodsId());
                tErpSupplierOutbound.setOutboundType(6);
                tErpSupplierOutbound.setOutboundNumber("G" + s);
                int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount();
                tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                tErpSupplierOutbound.setGoodsId(erpGoods.getId());
                erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
                TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods();
                tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
                tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing.getId());
                tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                tErpSupplierOutboundGoods.setOutboundCount(count);
                tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count)));
                erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                // 添加盘点信息
                TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods();
                tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId());
                tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierOutbound.getId());
                tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierOutboundGoods.getId());
                tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount());
                tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount());
                tErpSupplierInventoryGoods.setInventoryType(2);
                tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId());
                erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods);
            }
        }
        return false;
    }
}