wg-basic/module-dictionary/src/main/resources/mybatis/mapper/area-mapper.xml
2023-11-24 14:36:18 +08:00

382 lines
12 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="ink.wgink.module.dictionary.dao.IAreaDao">
<resultMap id="areaDTO" type="ink.wgink.module.dictionary.pojo.dtos.AreaDTO">
<id property="areaId" column="area_id"/>
<result property="areaParentId" column="area_parent_id"/>
<result property="areaName" column="area_name"/>
<result property="areaCode" column="area_code"/>
<result property="areaCityCode" column="area_city_code"/>
<result property="areaMergerName" column="area_merger_name"/>
<result property="areaShortName" column="area_short_name"/>
<result property="areaZipCode" column="area_zip_code"/>
<result property="areaLevel" column="area_level"/>
<result property="areaLng" column="area_lng"/>
<result property="areaLat" column="area_lat"/>
<result property="areaPinyin" column="area_pinyin"/>
<result property="areaFirst" column="area_first"/>
</resultMap>
<resultMap id="zTreeDTO" type="ink.wgink.pojo.dtos.ZTreeDTO">
<id property="id" column="area_id"/>
<result property="pId" column="area_parent_id"/>
<result property="name" column="area_name"/>
<result property="title" column="area_merger_name"/>
</resultMap>
<resultMap id="areaZTreeDTO" type="ink.wgink.module.dictionary.pojo.dtos.AreaZTreeDTO" extends="zTreeDTO">
<result property="areaCode" column="area_code"/>
</resultMap>
<!-- 建表 -->
<update id="createTable">
CREATE TABLE IF NOT EXISTS `data_area` (
`area_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`area_parent_id` bigint(20) DEFAULT '0',
`area_name` varchar(255) DEFAULT NULL COMMENT '地区名称',
`area_code` varchar(255) DEFAULT NULL COMMENT '地区编码',
`area_city_code` varchar(255) DEFAULT NULL COMMENT '地区城市编码',
`area_merger_name` varchar(255) DEFAULT NULL COMMENT '地区合并名称',
`area_short_name` varchar(255) DEFAULT NULL COMMENT '地区简称',
`area_zip_code` varchar(255) DEFAULT NULL COMMENT '地区邮政编码',
`area_level` int(1) DEFAULT '0' COMMENT '地区级别0: 省级 1:市级 2:县级 3:镇级 4:乡村级)',
`area_lng` varchar(255) DEFAULT NULL COMMENT '地区经度',
`area_lat` varchar(255) DEFAULT NULL COMMENT '地区纬度',
`area_pinyin` varchar(255) DEFAULT NULL COMMENT '地区拼音',
`area_first` varchar(255) DEFAULT NULL COMMENT '地区首字母',
`gmt_create` datetime DEFAULT NULL,
`creator` char(36) DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
`modifier` char(36) DEFAULT NULL,
`is_delete` int(2) DEFAULT '0',
PRIMARY KEY (`area_id`),
KEY `area_parent_id` (`area_parent_id`) USING BTREE,
KEY `is_delete` (`is_delete`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
</update>
<!-- 新增字典 -->
<insert id="save" parameterType="map" useGeneratedKeys="true" keyProperty="areaId">
INSERT INTO data_area(
area_parent_id,
area_name,
area_code,
area_city_code,
area_merger_name,
area_short_name,
area_zip_code,
area_level,
area_lng,
area_lat,
area_pinyin,
area_first,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
#{areaParentId},
#{areaName},
#{areaCode},
#{areaCityCode},
#{areaMergerName},
#{areaShortName},
#{areaZipCode},
#{areaLevel},
#{areaLng},
#{areaLat},
#{areaPinyin},
#{areaFirst},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<!-- 删除字典 -->
<update id="remove" parameterType="map">
UPDATE
data_area
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
area_id IN
<foreach collection="areaIds" index="index" open="(" separator="," close=")">
#{areaIds[${index}]}
</foreach>
</update>
<!-- 修改字典 -->
<update id="update" parameterType="map">
UPDATE
data_area
SET
<if test="areaName != null and areaName != ''">
area_name = #{areaName},
</if>
<if test="areaCode != null and areaCode != ''">
area_code = #{areaCode},
</if>
<if test="areaCityCode != null and areaCityCode != ''">
area_city_code = #{areaCityCode},
</if>
<if test="areaMergerName != null and areaMergerName != ''">
area_merger_name = #{areaMergerName},
</if>
<if test="areaShortName != null and areaShortName != ''">
area_short_name = #{areaShortName},
</if>
<if test="areaZipCode != null and areaZipCode != ''">
area_zip_code = #{areaZipCode},
</if>
<if test="areaLevel != null and areaLevel != ''">
area_level = #{areaLevel},
</if>
<if test="areaLng != null and areaLng != ''">
area_lng = #{areaLng},
</if>
<if test="areaLat != null and areaLat != ''">
area_lat = #{areaLat},
</if>
<if test="areaPinyin != null and areaPinyin != ''">
area_pinyin = #{areaPinyin},
</if>
<if test="areaFirst != null and areaFirst != ''">
area_first = #{areaFirst},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
area_id = #{areaId}
</update>
<!-- 修改合并名称和短名称 -->
<update id="updateShortAndMergerName" parameterType="map">
UPDATE
data_area
SET
area_merger_name = #{areaMergerName},
area_short_name = #{areaShortName}
WHERE
area_id = #{areaId}
</update>
<!-- ztree列表 -->
<select id="listZTree" parameterType="map" resultMap="zTreeDTO">
SELECT
*
FROM
data_area
WHERE
is_delete = 0
<if test="areaParentId != null and areaParentId != ''">
AND
area_parent_id = #{areaParentId}
</if>
</select>
<!-- ztree列表 -->
<select id="listAreaZTree" parameterType="map" resultMap="areaZTreeDTO">
SELECT
*
FROM
data_area
WHERE
is_delete = 0
<if test="areaParentId != null and areaParentId != ''">
AND
area_parent_id = #{areaParentId}
</if>
ORDER BY
area_city_code ASC
</select>
<!-- 字典列表 -->
<select id="list" parameterType="map" resultMap="areaDTO">
SELECT
area_id,
area_parent_id,
area_name,
area_code,
area_city_code,
area_merger_name,
area_short_name,
area_zip_code,
area_level,
area_lng,
area_lat,
area_pinyin,
area_first
FROM
data_area
WHERE
is_delete = 0
<if test="areaParentId != null and areaParentId != ''">
AND
area_parent_id = #{areaParentId}
</if>
<if test="keywords != null and keywords != ''">
AND
area_name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="areaCode != null and areaCode != ''">
AND
area_code LIKE CONCAT(#{areaCode}, '%')
</if>
<if test="excludeAreaCode != null and excludeAreaCode != ''">
AND
area_code != #{excludeAreaCode}
</if>
<if test="areaIds != null and areaIds.size > 0">
AND
area_id IN
<foreach collection="areaIds" index="index" open="(" separator="," close=")">
#{areaIds[${index}]}
</foreach>
</if>
<if test="areaCodes != null and areaCodes.size > 0">
AND
area_code IN
<foreach collection="areaCodes" index="index" open="(" separator="," close=")">
#{areaCodes[${index}]}
</foreach>
</if>
ORDER BY
area_city_code ASC
</select>
<!-- 字典列表 -->
<select id="listPage" parameterType="map" resultMap="areaDTO">
SELECT
area_id,
area_parent_id,
area_name,
area_code,
area_city_code,
area_merger_name,
area_short_name,
area_zip_code,
area_level,
area_lng,
area_lat,
area_pinyin,
area_first
FROM
data_area
WHERE
area_id >= (
SELECT
area_id
FROM
data_area
LIMIT
#{limitStart}, 1
)
ORDER BY
area_city_code ASC
LIMIT #{limitRow}
</select>
<!-- 字典详情 -->
<select id="get" parameterType="map" resultMap="areaDTO">
SELECT
t1.area_id,
t1.area_parent_id,
t1.area_name,
t1.area_code,
t1.area_city_code,
t1.area_merger_name,
t1.area_short_name,
t1.area_zip_code,
t1.area_level,
t1.area_lng,
t1.area_lat,
t1.area_pinyin,
t1.area_first,
t2.area_name area_parent_name
FROM
data_area t1
LEFT JOIN
data_area t2
ON
t1.area_parent_id = t2.area_id
AND
t2.is_delete = 0
WHERE
t1.is_delete = 0
<if test="areaId != null and areaId != ''">
AND
t1.area_id = #{areaId}
</if>
<if test="areaCode != null and areaCode != ''">
AND
t1.area_code = #{areaCode}
</if>
</select>
<!-- 子节点数量 -->
<select id="countByParentId" parameterType="String" resultType="Integer">
SELECT
COUNT(*)
FROM
data_area
WHERE
is_delete = 0
AND
area_parent_id = #{_parameter}
</select>
<!-- 统计总数 -->
<select id="count" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
data_area
WHERE
is_delete = 0
<if test="areaParentId != null and areaParentId != ''">
AND
area_parent_id = #{areaParentId}
</if>
</select>
<!-- 获取最后一个子字典,实际数据,包含已删除,方式编码重复 -->
<select id="getLastByParentId" parameterType="String" resultMap="areaDTO">
SELECT
area_id,
area_parent_id,
area_name,
area_code,
area_city_code,
area_merger_name,
area_short_name,
area_zip_code,
area_level,
area_lng,
area_lat,
area_pinyin,
area_first
FROM
data_area
WHERE
area_parent_id = #{_parameter}
LIMIT 0, 1
</select>
</mapper>