package com.yc.ship.module.product.dal.mysql.pricetemplate;

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.product.controller.admin.pricetemplate.vo.PriceTemplatePageReqVO;
import com.yc.ship.module.product.controller.admin.pricetemplate.vo.PriceTemplateReqVO;
import com.yc.ship.module.product.dal.dataobject.pricetemplate.PriceTemplateDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 价格模板 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface PriceTemplateMapper extends BaseMapperX<PriceTemplateDO> {

    default PageResult<PriceTemplateDO> selectPage(PriceTemplatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PriceTemplateDO>()
                .likeIfPresent(PriceTemplateDO::getName, reqVO.getName())
                .eqIfPresent(PriceTemplateDO::getShipId, reqVO.getShipId())
                .eqIfPresent(PriceTemplateDO::getRouteId, reqVO.getRouteId())
                .eqIfPresent(PriceTemplateDO::getPriceMode, reqVO.getPriceMode())
                .betweenIfPresent(PriceTemplateDO::getValidateTime, reqVO.getValidateTime())
                .eqIfPresent(PriceTemplateDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(PriceTemplateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PriceTemplateDO::getId));
    }

    default List<PriceTemplateDO> selectList(PriceTemplateReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PriceTemplateDO>()
                .eqIfPresent(PriceTemplateDO::getShipId, reqVO.getShipId())
                .eqIfPresent(PriceTemplateDO::getRouteId, reqVO.getRouteId())
                .orderByAsc(PriceTemplateDO::getCreateTime));
    }
}