package vip.xiaonuo.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.warehouse.entity.WarehouseStockDetail;
import vip.xiaonuo.warehouse.mapper.WarehouseStockDetailMapper;
import vip.xiaonuo.warehouse.param.WarehouseStockDetailParam;
import vip.xiaonuo.warehouse.service.IWarehouseStockDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 仓库库存明细表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-04
 */
@Service
public class WarehouseStockDetailServiceImpl extends ServiceImpl<WarehouseStockDetailMapper, WarehouseStockDetail> implements IWarehouseStockDetailService {

    @Autowired
    private WarehouseStockDetailMapper detailMapper;


    @Override
    public Page<WarehouseStockDetail> listDetail(WarehouseStockDetailParam detailParam) {
        String orgId = detailParam.getOrgId();
        String time = detailParam.getTime();
        QueryWrapper<WarehouseStockDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("create_time", time + "-31 23:59:59");
        queryWrapper.eq(StringUtils.isNotBlank(orgId),"org_id", orgId);
        if (null == detailParam.getMaterialType()) {
        } else {
            queryWrapper.eq("material_code", detailParam.getMaterialType());
        }
        Page<WarehouseStockDetail> page = new Page(detailParam.getPageNum(), detailParam.getPageSize());
        return detailMapper.selectPage(page,queryWrapper);
    }
}
