|
|
package com.example.demo.mapper;
import com.example.demo.domain.entity.Rate; import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper public interface RateMapper {
@Insert({ "insert into rate", "(start_time,end_time,currency,exchange_rate,create_time,update_time,admin_id,flag)", "values", "(#{startTime},#{endTime},#{currency},#{exchangeRate},now(),#{updateTime},#{adminId},1)" }) // 获取自增主键
@Options(useGeneratedKeys = true,keyColumn = "rate_id",keyProperty = "rateId") int insert(Rate rate);
//软删除
@Update({ "update rate set flag = 0 where rate_id=#{rateId}" }) int deleteById(Integer rateId);
@Update({ "<script>", "update rate", "<set>", "<if test='startTime!=null'>start_time=#{startTime},</if>", "<if test='endTime!=null'>end_time=#{endTime},</if>", "<if test='currency!=null and currency.length>0'>currency=#{currency},</if>", "<if test='exchangeRate!=null'>exchange_rate=#{exchangeRate},</if>", "<if test='updateTime!=null'>update_time=#{updateTime},</if>", "<if test='adminId!=null'>admin_id=#{adminId},</if>", "</set>", "where rate_id = #{rateId}", "</script>" }) int update(Rate rate);
@Select({ "select * from rate where rate_id=#{rateId}" }) Rate selectById(Integer rateId);
@Select({ "<script>", "SELECT r.*, a.name AS adminName", "FROM rate r", "LEFT JOIN admin a ON r.admin_id = a.admin_id", "LEFT JOIN admin u ON r.admin_id = u.admin_id", "WHERE r.flag =1 ", "<if test='rateId != null'>AND r.rate_id = #{rateId}</if>", "<if test='startTime != null'>AND r.start_time >= #{startTime}</if>", "<if test='endTime != null'>AND r.end_time <= #{endTime}</if>", "<if test='currency != null and currency.length > 0'>AND r.currency LIKE CONCAT('%', #{currency}, '%')</if>", "<if test='exchangeRate != null'>AND r.exchange_rate LIKE CONCAT('%', #{exchangeRate}, '%')</if>", "<if test='updateTime != null'>AND r.update_time LIKE CONCAT('%', #{updateTime}, '%')</if>", "<if test='adminId != null'>AND r.admin_id = #{adminId}</if>", "<if test='updateId != null'>AND r.update_id = #{updateId}</if>", "</script>"
}) List<Rate> select(Rate rate); }
|