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


import cn.com.ty.lift.ud.operation.mapper.entity.OtherSettingEntity;
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-05-16
 */
public interface OtherSettingMapper extends BaseMapper<OtherSettingEntity> {

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

    /**
     * 查询所有待审核的
     * @return
     */
    @Select("select * from other_setting where examine_flag = 0")
    List<OtherSettingEntity> getAllStay();

    /**
     * 查询所有待提交的
     * @return
     */
    @Select("select * from other_setting where examine_flag = 3")
    List<OtherSettingEntity> getAllCommit();

    /**
     * 查询历史版版本（最新版本的上一个版本）
     * @return
     */
    @Select("select * from other_setting where version_id<(select max(version_id) from other_setting) " +
            " order by version_id Desc limit 0,1")
    OtherSettingEntity getHistoryVersion();

    /**
     * 查询最新的版本
     * @return
     */
    @Select("select * from other_setting where version_id =(select max(version_id) from other_setting where examine_flag = 1) ")
    OtherSettingEntity getLatestVersion();

    /**
     * 设置版本号
     * @param versionId
     * @param id
     * @return
     */
    @Update("update other_setting set version_id = #{version_id} , examine_flag = 1," +
            " not_examine_reason = '' where id = #{id} ")
    int updateVersionId(@Param("version_id") Integer versionId, @Param("id")Long id);

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