[CMLR-070] 动态查询 selectPkInfoByCondition 等价迁移
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package vvpkassistant.pk.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import vvpkassistant.pk.model.PkInfoModel;
|
||||
|
||||
@@ -12,36 +13,56 @@ import java.util.Map;
|
||||
public interface PkInfoDao extends BaseMapper<PkInfoModel> {
|
||||
|
||||
//根据条件筛选pk列表数据
|
||||
@Select("<script>" +
|
||||
"SELECT * FROM pk_info " +
|
||||
"WHERE 1=1 " +
|
||||
" <if test='condition.sex != null'> AND sex = #{condition.sex} </if>" + // 性别筛选
|
||||
" <if test='condition.coin != null'> " + // 金币筛选
|
||||
" AND coin BETWEEN #{condition.coin.start} AND #{condition.coin.end} " +
|
||||
" </if>" +
|
||||
" <if test='condition.country != null'> AND country = #{condition.country} </if>" +
|
||||
" <if test='condition.pkTime != null'> " + // pk时间筛选
|
||||
" AND pk_time BETWEEN #{condition.pkTime.start} AND #{condition.pkTime.end} " +
|
||||
" </if>" +
|
||||
" <if test='condition.type == 1'> " + // 当天时间
|
||||
" AND pk_time BETWEEN #{todayStart} AND #{todayEnd}" +
|
||||
" </if>" +
|
||||
" <if test='condition.type == 2'> " + // 大于当天
|
||||
" AND pk_time > #{todayEnd}" +
|
||||
" </if>" +
|
||||
" AND invite_status = 0 " +
|
||||
"ORDER BY pin_expire_time > UNIX_TIMESTAMP() DESC, " +
|
||||
"CASE WHEN pin_expire_time > UNIX_TIMESTAMP() THEN pin_create_time ELSE NULL END ASC, " +
|
||||
"id DESC " +
|
||||
"LIMIT #{page} , #{size}" +
|
||||
"</script>")
|
||||
List<PkInfoModel> selectPkInfoByCondition(
|
||||
@Param("page") int page,
|
||||
@Param("size") int size,
|
||||
@Param("condition") Map<String, Object> condition,
|
||||
@Param("todayStart") long todayStart, // 当天开始时间戳(00:00:00)
|
||||
@Param("todayEnd") long todayEnd // 当天结束时间戳(23:59:59)
|
||||
);
|
||||
default List<PkInfoModel> selectPkInfoByCondition(
|
||||
int page,
|
||||
int size,
|
||||
Map<String, Object> condition,
|
||||
long todayStart,
|
||||
long todayEnd
|
||||
) {
|
||||
LambdaQueryWrapper<PkInfoModel> wrapper = Wrappers.<PkInfoModel>lambdaQuery();
|
||||
if (condition != null) {
|
||||
Object sex = condition.get("sex");
|
||||
if (sex != null) {
|
||||
wrapper.eq(PkInfoModel::getSex, sex);
|
||||
}
|
||||
|
||||
Map<String, Object> coin = asMap(condition.get("coin"));
|
||||
Long coinStart = asLong(coin == null ? null : coin.get("start"));
|
||||
Long coinEnd = asLong(coin == null ? null : coin.get("end"));
|
||||
if (coinStart != null && coinEnd != null) {
|
||||
wrapper.between(PkInfoModel::getCoin, coinStart, coinEnd);
|
||||
}
|
||||
|
||||
Object country = condition.get("country");
|
||||
if (country != null) {
|
||||
wrapper.eq(PkInfoModel::getCountry, country);
|
||||
}
|
||||
|
||||
Map<String, Object> pkTime = asMap(condition.get("pkTime"));
|
||||
Long pkTimeStart = asLong(pkTime == null ? null : pkTime.get("start"));
|
||||
Long pkTimeEnd = asLong(pkTime == null ? null : pkTime.get("end"));
|
||||
if (pkTimeStart != null && pkTimeEnd != null) {
|
||||
wrapper.between(PkInfoModel::getPkTime, pkTimeStart, pkTimeEnd);
|
||||
}
|
||||
|
||||
Integer type = asInteger(condition.get("type"));
|
||||
if (type != null) {
|
||||
if (type == 1) {
|
||||
wrapper.between(PkInfoModel::getPkTime, todayStart, todayEnd);
|
||||
} else if (type == 2) {
|
||||
wrapper.gt(PkInfoModel::getPkTime, todayEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
wrapper.eq(PkInfoModel::getInviteStatus, 0);
|
||||
wrapper.last(String.format(
|
||||
"ORDER BY pin_expire_time > UNIX_TIMESTAMP() DESC, " +
|
||||
"CASE WHEN pin_expire_time > UNIX_TIMESTAMP() THEN pin_create_time ELSE NULL END ASC, " +
|
||||
"id DESC LIMIT %d, %d",
|
||||
page, size));
|
||||
return selectList(wrapper);
|
||||
}
|
||||
|
||||
// 查询用户发布的大于当前时间的pk数据
|
||||
default List<PkInfoModel> queryCanUseData(Integer userId, Long time) {
|
||||
@@ -88,4 +109,39 @@ public interface PkInfoDao extends BaseMapper<PkInfoModel> {
|
||||
.gt(PkInfoModel::getPkTime, currentTime));
|
||||
}
|
||||
|
||||
static Map<String, Object> asMap(Object value) {
|
||||
if (value instanceof Map) {
|
||||
return (Map<String, Object>) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Long asLong(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).longValue();
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(value.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Integer asInteger(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user