package cn.com.ty.lift.ud.operation.mapper;


import cn.com.ty.lift.ud.operation.controller.query.UserRebateRuleQuery;
import cn.com.ty.lift.ud.operation.mapper.entity.UserRebateRuleEntity;
import cn.com.xwy.boot.web.dto.RestResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户返利规则;-Repository
 * 
 * @author Xson
 * @date 2020-06-28
 */
public interface UserRebateRuleMapper extends BaseMapper<UserRebateRuleEntity> {

    /**
     * 审批通过
     * @param id
     */
    @Update("update user_rebate_rule set examine_flag = 1 , not_examine_reason = '' where id = #{id} ")
    void examineById(Long id);

    /**
     * 审批驳回
     * @param id
     * @param notExamineReason
     */
    @Update("update user_rebate_rule set examine_flag = 2 ,not_examine_reason = #{notExamineReason} where id = #{id} ")
    void updateInfoById(@Param("id") Long id , @Param("notExamineReason")String notExamineReason);

    /**
     * 提交
     * @param id
     * @return
     */
    @Update("update user_rebate_rule set examine_flag = 0  where id = #{id} ")
    int submit(Long id);

    /**
     * 查询所有
     */
    @Select("select * from user_rebate_rule")
    List<UserRebateRuleEntity> selectAll();

    /**
     * 根据app角色查询返利信息
     * @param userLevel
     * @return
     */
    @Select("select * from user_rebate_rule where examine_flag = 1 and  role_id = #{userLevel}")
    UserRebateRuleEntity getRebateByUserLevel(Long userLevel);


    /**
     * 后台分页查询
     *
     * @param condition
     * @param page
     * @return
     */
    List<UserRebateRuleEntity> selectByQuery(@Param("ew") Wrapper condition, @Param("page") UserRebateRuleQuery page);

    /**
     * 查询总数量
     *
     * @param condition
     * @return
     */
    int countByQuery(@Param("ew") Wrapper condition);
}
