<?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.ard.data.region.mapper.ArdDeptRegionMapper">
|
|
<resultMap type="ArdDeptRegion" id="ArdDeptRegionResult">
|
<id property="id" column="id" />
|
<result property="deptId" column="dept_id" />
|
<result property="regionName" column="region_name" />
|
<result property="regionColor" column="region_color" />
|
<result property="centerLat" column="center_lat" />
|
<result property="centerLng" column="center_lng" />
|
<result property="areaSize" column="area_size" />
|
<result property="status" column="status" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="remark" column="remark" />
|
</resultMap>
|
|
<sql id="selectArdDeptRegionVo">
|
SELECT r.id, r.dept_id, r.region_name, r.region_color,
|
ST_AsText(r.region_boundary) as boundary_wkt,
|
r.center_lat, r.center_lng, r.area_size,
|
r.status, r.create_by, r.create_time, r.update_by, r.update_time, r.remark,
|
d.dept_name
|
FROM ard_dept_region r
|
LEFT JOIN sys_dept d ON r.dept_id = d.dept_id
|
</sql>
|
|
<!-- 查询部门区域列表(查询所有,不过滤状态) -->
|
<select id="selectArdDeptRegionList" parameterType="ArdDeptRegion" resultMap="ArdDeptRegionResult">
|
<include refid="selectArdDeptRegionVo"/>
|
<where>
|
<if test="deptId != null"> AND r.dept_id = #{deptId}</if>
|
<if test="regionName != null and regionName != ''"> AND r.region_name like concat('%', #{regionName}, '%')</if>
|
<if test="status != null and status != ''"> AND r.status = #{status}</if>
|
</where>
|
ORDER BY r.create_time DESC
|
</select>
|
|
<!-- 查询部门区域(根据ID,查询所有) -->
|
<select id="selectArdDeptRegionById" parameterType="Long" resultMap="ArdDeptRegionResult">
|
<include refid="selectArdDeptRegionVo"/>
|
WHERE r.id = #{id}
|
</select>
|
|
<!-- 获取边界WKT -->
|
<select id="selectBoundaryWkt" parameterType="Long" resultType="String">
|
SELECT ST_AsText(region_boundary)
|
FROM ard_dept_region
|
WHERE id = #{id}
|
</select>
|
|
<!-- 根据区域名称查询区域(用于唯一性校验,查询所有) -->
|
<select id="checkRegionNameUnique" parameterType="String" resultMap="ArdDeptRegionResult">
|
SELECT id, dept_id, region_name, region_color,
|
center_lat, center_lng, area_size,
|
status, create_by, create_time, update_by, update_time, remark
|
FROM ard_dept_region
|
WHERE region_name = #{regionName}
|
LIMIT 1
|
</select>
|
|
<!-- 检查点冲突(只查启用的区域) -->
|
<select id="checkPointConflict" resultType="ConflictRegion">
|
SELECT
|
id,
|
region_name as regionName,
|
region_color as regionColor,
|
CASE
|
WHEN ST_Contains(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '包含该点'
|
WHEN ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '相交'
|
ELSE '无冲突'
|
END as relationship
|
FROM ard_dept_region
|
WHERE status = '0'
|
<if test="deptId != null">
|
AND dept_id = #{deptId}
|
</if>
|
<if test="excludeId != null">
|
AND id != #{excludeId}
|
</if>
|
AND ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326))
|
</select>
|
|
<!-- 检查线冲突(只查启用的区域) -->
|
<select id="checkLineConflict" resultType="ConflictRegion">
|
SELECT
|
id,
|
region_name as regionName,
|
region_color as regionColor,
|
CASE
|
WHEN ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '相交'
|
WHEN ST_Contains(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '包含该线'
|
ELSE '无冲突'
|
END as relationship
|
FROM ard_dept_region
|
WHERE status = '0'
|
<if test="deptId != null">
|
AND dept_id = #{deptId}
|
</if>
|
<if test="excludeId != null">
|
AND id != #{excludeId}
|
</if>
|
AND ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326))
|
</select>
|
|
<!-- 检查面冲突(只查启用的区域) -->
|
<select id="checkPolygonConflict" resultType="ConflictRegion">
|
SELECT
|
id,
|
region_name as regionName,
|
region_color as regionColor,
|
CASE
|
WHEN ST_Contains(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '包含该面'
|
WHEN ST_Within(ST_GeomFromText(#{wkt}, 4326), region_boundary) THEN '在该面内部'
|
WHEN ST_Overlaps(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '重叠'
|
WHEN ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326)) THEN '相交'
|
ELSE '无冲突'
|
END as relationship
|
FROM ard_dept_region
|
WHERE status = '0'
|
<if test="deptId != null">
|
AND dept_id = #{deptId}
|
</if>
|
<if test="excludeId != null">
|
AND id != #{excludeId}
|
</if>
|
AND ST_Intersects(region_boundary, ST_GeomFromText(#{wkt}, 4326))
|
</select>
|
|
<!-- 根据坐标查询所属区域(查询所有区域,包括禁用的) -->
|
<select id="selectRegionByPoint" resultMap="ArdDeptRegionResult">
|
<include refid="selectArdDeptRegionVo"/>
|
WHERE ST_Contains(r.region_boundary, ST_GeomFromText(#{pointWkt}, 4326))
|
LIMIT 1
|
</select>
|
|
<!-- 新增部门区域(默认状态为启用0) -->
|
<insert id="insertArdDeptRegion" parameterType="ArdDeptRegion" useGeneratedKeys="true" keyProperty="id">
|
INSERT INTO ard_dept_region
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="deptId != null">dept_id,</if>
|
<if test="regionName != null">region_name,</if>
|
<if test="regionColor != null">region_color,</if>
|
<if test="boundaryWkt != null">region_boundary,</if>
|
<if test="centerLat != null">center_lat,</if>
|
<if test="centerLng != null">center_lng,</if>
|
<if test="areaSize != null">area_size,</if>
|
<if test="createBy != null">create_by,</if>
|
<if test="remark != null">remark,</if>
|
status, create_time
|
</trim>
|
VALUES
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="deptId != null">#{deptId},</if>
|
<if test="regionName != null">#{regionName},</if>
|
<if test="regionColor != null">#{regionColor},</if>
|
<if test="boundaryWkt != null">ST_GeomFromText(#{boundaryWkt}, 4326),</if>
|
<if test="centerLat != null">#{centerLat},</if>
|
<if test="centerLng != null">#{centerLng},</if>
|
<if test="areaSize != null">#{areaSize},</if>
|
<if test="createBy != null">#{createBy},</if>
|
<if test="remark != null">#{remark},</if>
|
'0', NOW()
|
</trim>
|
</insert>
|
|
<!-- 修改部门区域 -->
|
<update id="updateArdDeptRegion" parameterType="ArdDeptRegion">
|
UPDATE ard_dept_region
|
<set>
|
<if test="deptId != null">dept_id = #{deptId},</if>
|
<if test="regionName != null">region_name = #{regionName},</if>
|
<if test="regionColor != null">region_color = #{regionColor},</if>
|
<if test="boundaryWkt != null">region_boundary = ST_GeomFromText(#{boundaryWkt}, 4326),</if>
|
<if test="centerLat != null">center_lat = #{centerLat},</if>
|
<if test="centerLng != null">center_lng = #{centerLng},</if>
|
<if test="areaSize != null">area_size = #{areaSize},</if>
|
<if test="status != null">status = #{status},</if>
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
<if test="remark != null">remark = #{remark},</if>
|
update_time = NOW()
|
</set>
|
WHERE id = #{id}
|
</update>
|
|
<!-- 启用/禁用区域 -->
|
<update id="updateStatus">
|
UPDATE ard_dept_region
|
SET status = #{status}, update_time = NOW()
|
WHERE id = #{id}
|
</update>
|
|
<!-- 物理删除区域 -->
|
<delete id="deleteArdDeptRegionById" parameterType="Long">
|
DELETE FROM ard_dept_region WHERE id = #{id}
|
</delete>
|
|
<!-- 批量物理删除区域 -->
|
<delete id="deleteArdDeptRegionByIds" parameterType="String">
|
DELETE FROM ard_dept_region WHERE id IN
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</delete>
|
|
</mapper>
|