cm-cloud/cloud-common-plugin-map/src/main/resources/mybatis/mapper/grid-mapper.xml

250 lines
7.3 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.cm.plugin.map.dao.IGridDao">
<cache/>
<resultMap id="gridRelationDTO" type="com.cm.plugin.map.pojo.dto.GridRelationDTO">
<id column="relation_id" property="relationId"/>
<result column="grid_id" property="gridId"/>
</resultMap>
<resultMap id="gridDTO" type="com.cm.plugin.map.pojo.dto.GridDTO" extends="gridRelationDTO">
<id column="grid_id" property="gridId"/>
<result column="fill_color" property="fillColor"/>
<result column="grid_name" property="gridName"/>
<result column="relation_id" property="relationId"/>
</resultMap>
<resultMap id="gridPointDTO" type="com.cm.plugin.map.pojo.dto.GridPointDTO">
<id column="grid_id" property="gridId"/>
<result column="lng" property="lng"/>
<result column="lat" property="lat"/>
</resultMap>
<!-- 保存网格 -->
<insert id="saveGrid" parameterType="map" flushCache="true">
INSERT INTO map_grid(
grid_id,
grid_name,
fill_color,
gmt_create,
creator,
gmt_modified,
modifier,
is_delete
) VALUES(
#{gridId},
#{gridName},
#{fillColor},
#{gmtCreate},
#{creator},
#{gmtModified},
#{modifier},
#{isDelete}
)
</insert>
<!-- 保存网格关联关系 -->
<insert id="saveGridRelation" parameterType="map" flushCache="true">
INSERT INTO map_grid_relation(
grid_id,
relation_id
) VALUES(
#{gridId},
#{relationId}
)
</insert>
<!-- 删除网格 -->
<delete id="deleteGrid" parameterType="map" flushCache="true">
DELETE FROM
map_grid
WHERE
<if test="gridId != null and gridId != ''">
grid_id = #{gridId}
</if>
<if test="gridIds != null and gridIds.size > 0">
grid_id IN
<foreach collection="gridIds" index="index" open="(" separator="," close=")">
#{gridIds[${index}]}
</foreach>
</if>
</delete>
<!-- 删除网格点 -->
<delete id="deleteGridPoint" parameterType="map" flushCache="true">
DELETE FROM
map_grid_point
WHERE
<if test="gridId != null and gridId != ''">
grid_id = #{gridId}
</if>
<if test="gridIds != null and gridIds.size > 0">
grid_id IN
<foreach collection="gridIds" index="index" open="(" separator="," close=")">
#{gridIds[${index}]}
</foreach>
</if>
</delete>
<!-- 删除网格关联关系 -->
<delete id="deleteGridRelation" parameterType="map" flushCache="true">
DELETE FROM
map_grid_relation
<where>
<if test="gridId != null and gridId != ''">
grid_id = #{gridId}
</if>
<if test="gridIds != null and gridIds.size > 0">
AND
grid_id IN
<foreach collection="gridIds" index="index" open="(" separator="," close=")">
#{gridIds[${index}]}
</foreach>
</if>
<if test="relationId != null and relationId != ''">
AND
relation_id = #{relationId}
</if>
</where>
</delete>
<!-- 保存网格点 -->
<insert id="saveGridPoint" parameterType="map" flushCache="true">
INSERT INTO map_grid_point(
grid_id,
lng,
lat
) VALUES(
#{gridId},
#{lng},
#{lat}
)
</insert>
<!-- 获取关联关系列表 -->
<select id="listGridRelation" parameterType="map" resultMap="gridRelationDTO" useCache="true">
SELECT
relation_id,
grid_id
FROM
map_grid_relation
WHERE
1 = 1
<if test="relationId != null">
AND
relation_id = #{relationId}
</if>
<if test="relationIds != null and relationIds.size > 0">
AND
relation_id IN
<foreach collection="relationIds" index="index" open="(" separator="," close=")">
#{relationIds[${index}]}
</foreach>
</if>
<if test="gridId != null and gridId != ''">
AND
grid_id = #{gridId}
</if>
<if test="gridIds != null and gridIds.size > 0">
AND
grid_id IN
<foreach collection="gridIds" index="index" open="(" separator="," close=")">
#{gridIds[${index}]}
</foreach>
</if>
</select>
<!-- 获取网格列表通过关联ID -->
<select id="listGridByRelationId" parameterType="java.lang.String" resultMap="gridDTO" useCache="true">
SELECT
t1.grid_id,
t1.fill_color,
t1.grid_name,
t2.relation_id
FROM
map_grid t1
LEFT JOIN
map_grid_relation t2
ON
t1.grid_id = t2.grid_id
WHERE
t1.is_delete = 0
AND
t2.relation_id = #{_parameter}
</select>
<select id="listGridByRelationIds" parameterType="java.util.List" resultMap="gridDTO" useCache="true">
SELECT
t1.grid_id,
t1.fill_color,
t1.grid_name,
t2.relation_id
FROM
map_grid t1
LEFT JOIN
map_grid_relation t2
ON
t1.grid_id = t2.grid_id
WHERE
t1.is_delete = 0
AND
t2.relation_id IN
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{list[${index}]}
</foreach>
</select>
<select id="listGridGroupByRelationIds" parameterType="java.util.List" resultMap="gridDTO" useCache="true">
SELECT
t1.grid_id,
t1.fill_color,
t1.grid_name
FROM
map_grid t1
LEFT JOIN
map_grid_relation t2
ON
t1.grid_id = t2.grid_id
WHERE
t1.is_delete = 0
AND
t2.relation_id IN
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{list[${index}]}
</foreach>
GROUP BY
t1.grid_id,
t1.fill_color,
t1.grid_name
</select>
<!-- 获取网格点列表通过网格ID -->
<select id="listPointByGridId" parameterType="java.lang.String" resultMap="gridPointDTO" useCache="true">
SELECT
grid_id,
lng,
lat
FROM
map_grid_point
WHERE
grid_id = #{_parameter}
</select>
<!-- 获取网格点列表通过网格ID列表 -->
<select id="listPointByGridIds" parameterType="java.util.List" resultMap="gridPointDTO" useCache="true">
SELECT
grid_id,
lng,
lat
FROM
map_grid_point
WHERE
grid_id IN
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{list[${index}]}
</foreach>
</select>
</mapper>