package com.yc.ship.module.resource.dal.mysql.category;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.resource.controller.admin.category.vo.CategoryListReqVO;
import com.yc.ship.module.resource.controller.admin.category.vo.CategoryPageReqVO;
import com.yc.ship.module.resource.controller.admin.category.vo.CategoryRespVO;
import com.yc.ship.module.resource.dal.dataobject.category.CategoryDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;


/**
 * 资源-产品分类 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CategoryMapper extends BaseMapperX<CategoryDO> {

    IPage<CategoryRespVO> selectCategoryPage(IPage<CategoryRespVO> iPage, @Param("param") CategoryPageReqVO pageReqVO);

    default PageResult<CategoryDO> selectPage(CategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .eqIfPresent(CategoryDO::getCateCode, reqVO.getCateCode())
                .likeIfPresent(CategoryDO::getCateName, reqVO.getCateName())
                .eqIfPresent(CategoryDO::getSortNum, reqVO.getSortNum())
                .eqIfPresent(CategoryDO::getType, reqVO.getType())
                .eqIfPresent(CategoryDO::getParentPath, reqVO.getParentPath())
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CategoryDO::getId));
    }

    default List<CategoryDO> selectList(CategoryListReqVO reqVO) {
        LambdaQueryWrapperX<CategoryDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.likeIfPresent(CategoryDO::getCateName, reqVO.getCateName())
                .eqIfPresent(CategoryDO::getType, reqVO.getType())
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .eqIfPresent(CategoryDO::getUseStatus, reqVO.getUseStatus())
                .orderByDesc(CategoryDO::getSortNum);

        return selectList(queryWrapperX);
    }

    List<CategoryRespVO> selectListWithSupplierNum(@Param("reqVO") CategoryPageReqVO reqVO);


    @TenantIgnore
    Map<String, Object> getPlatTenantId(Long currentTenantId);

    @TenantIgnore
    List<Map<String, Object>> getPlatAllTenantId(Long TenantId);
    @TenantIgnore
    List<CategoryDO> getCategoryByTenantIds(@Param("mapList") List<Map<String, Object>> mapList);

    /**
     *
     * @param catalogues
     * @param businessType 业务类型 1.栏目 2.分类
     * @return
     */
    List<CategoryRespVO> selectListByCatalogues(@Param("catalogues") String catalogues,@Param("businessType")Integer businessType);

    List<CategoryRespVO> getListByIds(@Param("reqVO") CategoryListReqVO reqVO);

    /**
     * 查找自身及所有父节点
     * @param id 分类id
     * @param type 类型;0资源分类 1产品分类 2小程序分类
     * @return list
     */
    List<CategoryRespVO> getAllUpCategoryById(@Param("id") Long id, @Param("type") Integer type);
    /**
     * 查找所有子节点
     * @param id 分类id
     * @param type 类型;0资源分类 1产品分类 2小程序分类
     * @return list
     */
    List<CategoryRespVO> getAllDownCategoryById(@Param("id") Long id, @Param("type") Integer type);

    void updateProductCategoryId(@Param("id") Long id,@Param("parentId") Long parentId);
}
