40 lines
1.5 KiB
Java
40 lines
1.5 KiB
Java
package com.example.caseData.dao;
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.example.caseData.dto.caseExchange.CaseExchangeDto;
|
|
import com.example.caseData.model.CaseExchangeModel;
|
|
import com.example.caseData.model.StatsCaseExchangeUserModel;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
import java.util.Map;
|
|
|
|
@Mapper
|
|
public interface StatsCaseExchangeUserDao extends BaseMapper<StatsCaseExchangeUserModel> {
|
|
/**
|
|
* Inc 自增
|
|
* @param userId 文章 ID
|
|
* @param field 字段名称
|
|
* @param numeral 增加的数值
|
|
* @return 更新的行数
|
|
*/
|
|
@Update("UPDATE stats_case_exchange_user SET ${field} = ${field} + #{numeral} WHERE user_id = #{userId}")
|
|
int inc(@Param("userId") Long userId, @Param("field") String field, @Param("numeral") int numeral);
|
|
|
|
/**
|
|
* Dec 自减
|
|
*
|
|
* @param userId 文章 ID
|
|
* @param field 字段名称
|
|
* @param numeral 减少的数值
|
|
* @return 更新的行数
|
|
*/
|
|
@Update("UPDATE stats_case_exchange_user " +
|
|
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
|
"WHERE user_id = #{userId}")
|
|
int dec(@Param("userId") Long userId, @Param("field") String field, @Param("numeral") int numeral);
|
|
}
|