xml文件下,简化SQL语句
<select id="getPresetTimeRangeActivity" parameterType="java.util.Map" resultType="com.lpk.common.response.statisticsresponse.ActivityRecord">
SELECT date, COUNT(DISTINCT uid) AS active_members
FROM eb_user_visit_record
WHERE visit_type = 1
AND date >=
<choose>
<when test="timeRangeType == 'today'">
CURDATE()
</when>
<when test="timeRangeType == 'thisWeek'">
DATE_SUB(CURDATE(), INTERVAL DAYOFWEEK(CURDATE()) - 1 DAY)
</when>
<when test="timeRangeType == 'thisMonth'">
DATE_FORMAT(CURDATE(), '%Y-%m-01')
</when>
</choose>
GROUP BY date
</select>
List<ActivityRecord> getPresetTimeRangeActivity(Map<String, Object> params);
public List<ActivityRecord> getPresetTimeRangeActivity(String timeRangeType) {
Map<String, Object> params = new HashMap<>();
params.put("timeRangeType", timeRangeType);
return statisticsMembershipDao.getPresetTimeRangeActivity(params);
}