parent
54c05ecea4
commit
3b7e996e2f
@ -1,70 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<!-- 定义命名空间,对应 DAO 接口 -->
|
||||
<mapper namespace="com.dao.CommonDao">
|
||||
<!-- 查询指定列的不重复值,排除空值和空字符串 -->
|
||||
<!-- 可根据 level 和 parent 条件进行筛选 -->
|
||||
<select id="getOption" resultType="String" >
|
||||
<!-- 查询指定表中指定列的不重复值 -->
|
||||
SELECT distinct ${column} FROM ${table}
|
||||
where ${column} is not null and ${column} !=''
|
||||
<if test = "level != null">
|
||||
<!-- 排除列值为 null 和空字符串的情况 -->
|
||||
where ${column} is not null and ${column} !=''
|
||||
<!-- 如果 level 参数不为空,添加 level 条件 -->
|
||||
<if test = "level != null">
|
||||
and level=#{level}
|
||||
</if>
|
||||
<if test = "parent != null">
|
||||
</if>
|
||||
<!-- 如果 parent 参数不为空,添加 parent 条件 -->
|
||||
<if test = "parent != null">
|
||||
and parent=#{parent}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据指定列的值查询表中的所有列 -->
|
||||
<select id="getFollowByOption" resultType="map" >
|
||||
<!-- 查询指定表中指定列等于指定值的所有记录 -->
|
||||
SELECT * FROM ${table} where ${column}=#{columnValue}
|
||||
</select>
|
||||
|
||||
<!-- 根据 id 更新表中的 sfsh 字段 -->
|
||||
<update id="sh">
|
||||
<!-- 更新指定表中 id 等于指定值的记录的 sfsh 字段 -->
|
||||
UPDATE ${table} set sfsh=#{sfsh} where id=#{id}
|
||||
</update>
|
||||
|
||||
<!-- 根据不同条件统计记录数量 -->
|
||||
<select id="remindCount" resultType="int" >
|
||||
<!-- 统计指定表中的记录数量 -->
|
||||
SELECT count(1) FROM ${table}
|
||||
where 1=1
|
||||
<if test = "type == 1 ">
|
||||
<if test = " remindstart != null ">
|
||||
and ${column} >= #{remindstart}
|
||||
</if>
|
||||
<if test = " remindend != null ">
|
||||
and ${column} <= #{remindend}
|
||||
</if>
|
||||
<!-- 基础条件,始终为真 -->
|
||||
where 1=1
|
||||
<!-- 如果 type 为 1 -->
|
||||
<if test = "type == 1 ">
|
||||
<!-- 如果 remindstart 参数不为空,添加大于等于条件 -->
|
||||
<if test = " remindstart != null ">
|
||||
and ${column} >= #{remindstart}
|
||||
</if>
|
||||
<!-- 如果 remindend 参数不为空,添加小于等于条件 -->
|
||||
<if test = " remindend != null ">
|
||||
and ${column} <= #{remindend}
|
||||
</if>
|
||||
<if test = "type == 2 ">
|
||||
<if test = " remindstart != null ">
|
||||
and ${column} >= str_to_date(#{remindstart},'%Y-%m-%d')
|
||||
</if>
|
||||
<if test = " remindend != null ">
|
||||
and ${column} <= str_to_date(#{remindend},'%Y-%m-%d')
|
||||
</if>
|
||||
</if>
|
||||
<!-- 如果 type 为 2 -->
|
||||
<if test = "type == 2 ">
|
||||
<!-- 如果 remindstart 参数不为空,添加大于等于日期转换后的条件 -->
|
||||
<if test = " remindstart != null ">
|
||||
and ${column} >= str_to_date(#{remindstart},'%Y-%m-%d')
|
||||
</if>
|
||||
<!-- 如果 remindend 参数不为空,添加小于等于日期转换后的条件 -->
|
||||
<if test = " remindend != null ">
|
||||
and ${column} <= str_to_date(#{remindend},'%Y-%m-%d')
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 对指定列进行聚合计算,包括求和、最大值、最小值和平均值 -->
|
||||
<select id="selectCal" resultType="map" >
|
||||
<!-- 对指定表中的指定列进行求和、求最大值、求最小值和求平均值 -->
|
||||
SELECT sum(${column}) sum,max(${column}) max,min(${column}) min,avg(${column}) avg FROM ${table}
|
||||
</select>
|
||||
|
||||
<!-- 对指定列进行分组统计,统计每组的记录数量 -->
|
||||
<select id="selectGroup" resultType="map" >
|
||||
<!-- 对指定表中的指定列进行分组,并统计每组的记录数量 -->
|
||||
SELECT ${column} , count(1) total FROM ${table} group by ${column}
|
||||
</select>
|
||||
|
||||
<!-- 对指定的 x 列和 y 列进行分组统计,统计每组 y 列的总和 -->
|
||||
<select id="selectValue" resultType="map" >
|
||||
<!-- 对指定表中的 x 列进行分组,并统计每组 y 列的总和 -->
|
||||
SELECT ${xColumn}, sum(${yColumn}) total FROM ${table} group by ${xColumn}
|
||||
</select>
|
||||
|
||||
<select id="selectTimeStatValue" resultType="map" >
|
||||
<if test = 'timeStatType == "日"'>
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y-%m-%d') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y-%m-%d')
|
||||
</if>
|
||||
<if test = 'timeStatType == "月"'>
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y-%m') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y-%m')
|
||||
</if>
|
||||
<if test = 'timeStatType == "年"'>
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y')
|
||||
</if>
|
||||
</select>
|
||||
<select id="getFollowByOption2" resultType="java.lang.String"></select>
|
||||
<!-- 根据不同的时间统计类型对指定的 x 列和 y 列进行分组统计,统计每组 y 列的总和 -->
|
||||
<select id="selectTimeStatValue" resultType="map" >
|
||||
<!-- 如果时间统计类型为日 -->
|
||||
<if test = 'timeStatType == "日"'>
|
||||
<!-- 按日对指定表中的 x 列进行分组,并统计每组 y 列的总和 -->
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y-%m-%d') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y-%m-%d')
|
||||
</if>
|
||||
<!-- 如果时间统计类型为月 -->
|
||||
<if test = 'timeStatType == "月"'>
|
||||
<!-- 按月对指定表中的 x 列进行分组,并统计每组 y 列的总和 -->
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y-%m') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y-%m')
|
||||
</if>
|
||||
<!-- 如果时间统计类型为年 -->
|
||||
<if test = 'timeStatType == "年"'>
|
||||
<!-- 按年对指定表中的 x 列进行分组,并统计每组 y 列的总和 -->
|
||||
SELECT DATE_FORMAT(${xColumn},'%Y') ${xColumn}, sum(${yColumn}) total FROM ${table} group by DATE_FORMAT(${xColumn},'%Y')
|
||||
</if>
|
||||
</select>
|
||||
<!-- 此查询方法未实现具体的 SQL 逻辑 -->
|
||||
<select id="getFollowByOption2" resultType="java.lang.String"></select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
Loading…
Reference in new issue