init
This commit is contained in:
25
src/main/resources/mapper/DistrictSchemaMapper.xml
Normal file
25
src/main/resources/mapper/DistrictSchemaMapper.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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">
|
||||
|
||||
<mapper namespace="com.whu.edu.LyStatistic.statistic.mapper.DistrictSchemaMapper">
|
||||
|
||||
<!--
|
||||
根据 district 和 village 获取对应的 schema 列表
|
||||
如果 village 为 null,则返回该 district 下所有 schema
|
||||
schema_name 字段为数据库中存储 schema 名称的字段
|
||||
-->
|
||||
<select id="findSchemasByDistrictAndVillage" resultType="string">
|
||||
SELECT schema_code
|
||||
FROM public.unit_info
|
||||
WHERE 1=1
|
||||
<if test="district != null">
|
||||
AND district = #{district}
|
||||
</if>
|
||||
<if test="village != null">
|
||||
AND village = #{village}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
14
src/main/resources/mapper/SchemaMapper.xml
Normal file
14
src/main/resources/mapper/SchemaMapper.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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">
|
||||
|
||||
<mapper namespace="com.whu.edu.LyStatistic.statistic.mapper.SchemaMapper">
|
||||
|
||||
<!-- 查询全部 schema -->
|
||||
<select id="findAllSchemas" resultType="string">
|
||||
SELECT schema_code
|
||||
FROM public.unit_info
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -4,36 +4,79 @@
|
||||
|
||||
<mapper namespace="com.whu.edu.LyStatistic.statistic.mapper.TaskStatisticMapper">
|
||||
|
||||
<select id="countByCollector" parameterType="map" resultType="com.whu.edu.LyStatistic.statistic.dto.UserTaskCount">
|
||||
SELECT collector AS user_id, COUNT(*) AS count
|
||||
FROM "${schema}"."${table}" t
|
||||
WHERE t.collector != -1
|
||||
<!-- 根表记录 -->
|
||||
<select id="findRootTasks" resultType="com.whu.edu.LyStatistic.statistic.dto.RootTask">
|
||||
SELECT "ID" AS id,
|
||||
"collector" AS collector,
|
||||
"reviewer" AS reviewer
|
||||
FROM "${schema}".roottable1
|
||||
WHERE 1=1
|
||||
<if test="timeParam != null">
|
||||
AND update_time <= #{timeParam}
|
||||
AND create_time >= #{timeParam}
|
||||
</if>
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
AND collector IN
|
||||
AND ("collector" IN
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
OR "reviewer" IN
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>)
|
||||
</if>
|
||||
</select>
|
||||
<select id="findRootTasksByTimeRange" parameterType="map" resultType="com.whu.edu.LyStatistic.statistic.dto.RootTask">
|
||||
SELECT "ID" AS id,
|
||||
"collector" AS collector,
|
||||
"reviewer" AS reviewer,
|
||||
update_time
|
||||
FROM "${schema}".roottable1
|
||||
WHERE 1=1
|
||||
<if test="startTime != null">
|
||||
AND update_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND update_time <= #{endTime}
|
||||
</if>
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
AND (collector IN
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
OR reviewer IN
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>)
|
||||
</if>
|
||||
GROUP BY collector
|
||||
</select>
|
||||
|
||||
<select id="countByReviewer" parameterType="map" resultType="com.whu.edu.LyStatistic.statistic.dto.UserTaskCount">
|
||||
SELECT reviewer AS user_id, COUNT(*) AS count
|
||||
FROM "${schema}"."${table}" t
|
||||
WHERE t.reviewer != -1
|
||||
<if test="timeParam != null">
|
||||
AND update_time <= #{timeParam}
|
||||
</if>
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
AND reviewer IN
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
GROUP BY reviewer
|
||||
<!-- 子表分组计数 -->
|
||||
<select id="countGroupByParent" resultType="map">
|
||||
SELECT "${column}" AS parentid,
|
||||
COUNT(*) AS count
|
||||
FROM "${schema}".${table}
|
||||
WHERE "${column}" IN
|
||||
<foreach collection="parentIds" item="pid" open="(" separator="," close=")">
|
||||
#{pid}
|
||||
</foreach>
|
||||
GROUP BY "${column}"
|
||||
</select>
|
||||
|
||||
<!-- 子表 ID 列表,并按 parentID 分组 -->
|
||||
<select id="findSubIdsGroupByParent" resultType="map">
|
||||
SELECT "${column}" AS parentid, "ID"
|
||||
FROM "${schema}".${table}
|
||||
WHERE "${column}" IN
|
||||
<foreach collection="parentIds" item="pid" open="(" separator="," close=")">
|
||||
#{pid}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- t1sub2 单个 parentID 计数 -->
|
||||
<select id="countByParentId" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM "${schema}".${table}
|
||||
WHERE "${column}" = #{parentId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
34
src/main/resources/mapper/UnitInfoMapper.xml
Normal file
34
src/main/resources/mapper/UnitInfoMapper.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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">
|
||||
|
||||
<mapper namespace="com.whu.edu.LyStatistic.statistic.mapper.UnitInfoMapper">
|
||||
|
||||
<select id="findDistinctDistricts" resultType="string">
|
||||
<![CDATA[
|
||||
SELECT DISTINCT district
|
||||
FROM public.unit_info
|
||||
WHERE district IS NOT NULL AND district <> ''
|
||||
ORDER BY district
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<select id="findDistinctVillages" resultType="string">
|
||||
<![CDATA[
|
||||
SELECT DISTINCT village
|
||||
FROM public.unit_info
|
||||
WHERE village IS NOT NULL AND village <> ''
|
||||
ORDER BY village
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<select id="findDistinctUnits" resultType="string">
|
||||
<![CDATA[
|
||||
SELECT DISTINCT unit_name
|
||||
FROM public.unit_info
|
||||
WHERE unit_name IS NOT NULL AND unit_name <> ''
|
||||
ORDER BY unit_name
|
||||
]]>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<!-- 根据用户名模糊查询 -->
|
||||
<select id="findByNameLike" resultType="com.whu.edu.LyStatistic.statistic.dto.UserStaff">
|
||||
SELECT id, real_name
|
||||
SELECT id, real_name AS username
|
||||
FROM public.user_staff
|
||||
WHERE real_name ILIKE CONCAT('%', #{name}, '%')
|
||||
</select>
|
||||
@@ -20,6 +20,4 @@
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user