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

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.Warehouse;
import com.tuoheng.admin.entity.request.warehouse.QueryWarehouseListRequest;
import com.tuoheng.admin.enums.MarkTypeEnum;
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 QueryWarehouseListService {

    @Autowired
    private WarehouseMapper warehouseMapper;

    public JsonResult getList(QueryWarehouseListRequest 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;
        }

        List<Warehouse> warehouseList = warehouseMapper.selectList(new LambdaQueryWrapper<Warehouse>()
                        .eq(Warehouse::getMark, MarkTypeEnum.VALID.getCode())
                        .eq(Warehouse::getTenantId, request.getTenantId()));
        if (CollectionUtil.isEmpty(warehouseList)) {
            log.info("仓库列表数据为空");
        }
        return JsonResult.success(warehouseList);
    }

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

        return JsonResult.success();
    }

}
