package com.fuint.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtTaskRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * 任务记录 Mapper 接口
 *
 * Created by Codex
 */
public interface MtTaskRecordMapper extends BaseMapper<MtTaskRecord> {

    @Update("UPDATE mt_task_record SET COMPLETE_NUM = COMPLETE_NUM + 1, LAST_COMPLETE_TIME = #{now}, UPDATE_TIME = #{now} " +
            "WHERE ID = #{id} AND COMPLETE_NUM < #{dailyLimit}")
    int incrCompleteNum(@Param("id") Integer id, @Param("dailyLimit") Integer dailyLimit, @Param("now") Date now);

    @Update("UPDATE mt_task_record SET CLAIM_NUM = CLAIM_NUM + 1, LAST_CLAIM_TIME = #{now}, UPDATE_TIME = #{now} " +
            "WHERE ID = #{id} AND CLAIM_NUM = #{oldClaimNum} AND CLAIM_NUM < COMPLETE_NUM")
    int incrClaimNumIfMatch(@Param("id") Integer id, @Param("oldClaimNum") Integer oldClaimNum, @Param("now") Date now);
}
