package com.tuoheng.admin.service.warehouse.query;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.admin.entity.domain.Warehouse;
import com.tuoheng.admin.entity.domain.Warning;
import com.tuoheng.admin.entity.request.warehouse.QueryWarehousePageListRequest;
import com.tuoheng.admin.entity.request.warning.QueryWarningListRequest;
import com.tuoheng.admin.mapper.WarehouseMapper;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.system.entity.User;
import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 查询仓库分页列表业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-11-22
 */
@Slf4j
@Service
public class QueryWarehousePageListService {

    @Autowired
    private WarehouseMapper warehouseMapper;

    public JsonResult getPageList(QueryWarehousePageListRequest request) {
//        log.info("进入查询仓库分页列表业务");
        User user = ShiroUtils.getUserInfo();
        Integer tenantId = user.getTenantId();
        request.setTenantId(tenantId);

        JsonResult result = this.check(tenantId, request);
        if (0 != result.getCode()) {
            log.info("进入查询仓库分页列表业务：校验失败：{}", result.getMsg());
            return result;
        }
        // 设置分页参数
        IPage<Warehouse> page = new Page<>(request.getPage(), request.getLimit());
        // 查询结果
        IPage<Warehouse> pageData = warehouseMapper.selectPageList(page, request);
        if (CollectionUtil.isEmpty(pageData.getRecords())) {
            log.info("仓库分页列表数据为空");
        }
        return JsonResult.success(pageData);
    }

    /**
     * 检查参数
     *
     * @param tenantId
     * @param request
     * @return
     */
    private JsonResult check(Integer tenantId, QueryWarehousePageListRequest request) {

        return JsonResult.success();
    }

}
