mybits 根据指定日期查询 当天 周 月 数据条件过滤
2019-06-28 本文已影响0人
记忆心态
mybits 根据指定日期查询 当天 周 月 数据条件过滤
<choose>
--指定日期当天
<when test="classType == 1 and dateStr!=null and dateStr!=''">
and date(create_date) = date(#{dateStr})
</when>
--指定日期当周
<when test="classType == 2 and dateStr!=null and dateStr!=''">
AND DATE_FORMAT(create_date,'%Y-%m-%d') >=subdate(#{dateStr},if(date_format(#{dateStr},'%w')=0,7,date_format(#{dateStr},'%w'))-1) and subdate(#{dateStr},if(date_format(#{dateStr},'%w')=0,7,date_format(#{dateStr},'%w'))-7) >= DATE_FORMAT(create_date,'%Y-%m-%d')
</when>
--指定日期当月
<when test="classType == 3 and dateStr!=null and dateStr!=''">
AND DATE_FORMAT(create_date, '%Y%m') = DATE_FORMAT(#{dateStr}, '%Y%m')
</when>
</choose>