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

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.module.resource.controller.admin.cartype.vo.CarTypePageReqVO;
import com.yc.ship.module.resource.controller.admin.cartype.vo.CarTypeReqVO;
import com.yc.ship.module.resource.dal.dataobject.cartype.CarTypeDO;
import com.yc.ship.module.resource.enums.CommonStatusEnum;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * 车辆类型管理 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CarTypeMapper extends BaseMapperX<CarTypeDO> {

    default PageResult<CarTypeDO> selectPage(CarTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CarTypeDO>()
                .likeIfPresent(CarTypeDO::getName, reqVO.getName())
                .eqIfPresent(CarTypeDO::getCarCode, reqVO.getCarCode())
                .eqIfPresent(CarTypeDO::getCarMaxLoad, reqVO.getCarMaxLoad())
                .eqIfPresent(CarTypeDO::getCarFixedCost, reqVO.getCarFixedCost())
                .eqIfPresent(CarTypeDO::getRemark, reqVO.getRemark())
                .eqIfPresent(CarTypeDO::getUseStatus, reqVO.getUseStatus())
                .betweenIfPresent(CarTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CarTypeDO::getId));
    }

    default List<CarTypeDO> selectList(CarTypeReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CarTypeDO>()
                .likeIfPresent(CarTypeDO::getName, reqVO.getName())
                .eqIfPresent(CarTypeDO::getUseStatus, reqVO.getUseStatus())
                .eq(CarTypeDO::getDeleted, CommonStatusEnum.ENABLE.getStatus())
                .orderBy(true,false,CarTypeDO::getCarLevel)
                .orderBy(true,true,CarTypeDO::getName));
    }

    @MapKey("id")
    Map<String, CarTypeDO> selectNameMap(@Param("ids") Set<String> ids);
}