package com.hys.app.mapper.erp;

import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.database.mybatisplus.base.BaseMapperX;
import com.hys.app.model.erp.dos.WarehouseDO;
import com.hys.app.model.erp.dto.WarehouseQueryParams;
import com.hys.app.framework.database.WebPage;

import java.util.List;

/**
 * 仓库的Mapper
 *
 * @author 张崧
 * 2023-11-30 16:35:16
 */
public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {

    default WebPage<WarehouseDO> selectPage(WarehouseQueryParams params) {
        return lambdaQuery()
                .likeIfPresent(WarehouseDO::getName, params.getKeyword())
                .likeIfPresent(WarehouseDO::getName, params.getName())
                .likeIfPresent(WarehouseDO::getSn, params.getSn())
                .eqIfPresent(WarehouseDO::getAdminId, params.getAdminId())
                .eqIfPresent(WarehouseDO::getCompanyId, AdminUserContext.getCompanyId())
                .likeIfPresent(WarehouseDO::getDescription, params.getDescription())
                .orderByDesc(WarehouseDO::getId)
                .page(params);
    }

    default List<WarehouseDO> listAll(Long deptId){
        return lambdaQuery()
                .orderByDesc(WarehouseDO::getId)
                .list();
    }
}

