<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.archives.mapper.TGzAreaMapper">

  <resultMap id="tGzAreaMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TGzArea">
    <id property="id" column="ID"/>
    <result property="province" column="PROVINCE"/>
    <result property="city" column="CITY"/>
    <result property="town" column="TOWN"/>
    <result property="areaCode" column="AREA_CODE"/>
    <result property="areaName" column="AREA_NAME"/>
    <result property="gzCode" column="GZ_CODE"/>
    <result property="gzName" column="GZ_NAME"/>
    <result property="createTime" column="create_time"/>
    <result property="createBy" column="create_by"/>
    <result property="createName" column="create_name"/>
    <result property="updateBy" column="update_by"/>
    <result property="updateTime" column="update_time"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.PROVINCE,
                a.CITY,
                a.TOWN,
                a.AREA_CODE,
                a.AREA_NAME,
                a.GZ_CODE,
                a.GZ_NAME,
                a.create_time,
                a.create_by,
                a.create_name,
                a.update_by,
                a.update_time
    </sql>
    <sql id="tGzArea_where">
        <if test="tGzArea != null">
                    <if test="tGzArea.id != null and tGzArea.id.trim() != ''">
                        AND a.ID = #{tGzArea.id}
                    </if>
                    <if test="tGzArea.province != null">
                        AND a.PROVINCE = #{tGzArea.province}
                    </if>
                    <if test="tGzArea.city != null">
                        AND a.CITY = #{tGzArea.city}
                    </if>
                    <if test="tGzArea.town != null">
                        AND a.TOWN = #{tGzArea.town}
                    </if>
                    <if test="tGzArea.areaCode != null and tGzArea.areaCode.trim() != ''">
                        AND a.AREA_CODE = #{tGzArea.areaCode}
                    </if>
                    <if test="tGzArea.areaName != null and tGzArea.areaName.trim() != ''">
                        AND a.AREA_NAME like concat('%', #{tGzArea.areaName}, '%')
                    </if>
                    <if test="tGzArea.gzCode != null and tGzArea.gzCode.trim() != ''">
                        AND a.GZ_CODE = #{tGzArea.gzCode}
                    </if>
                    <if test="tGzArea.gzName != null and tGzArea.gzName.trim() != ''">
                        AND a.GZ_NAME like concat('%', #{tGzArea.gzName}, '%')
                    </if>
                    <if test="tGzArea.createTime != null">
                        AND a.create_time = #{tGzArea.createTime}
                    </if>
                    <if test="tGzArea.createBy != null and tGzArea.createBy.trim() != ''">
                        AND a.create_by = #{tGzArea.createBy}
                    </if>
                    <if test="tGzArea.createName != null and tGzArea.createName.trim() != ''">
                        AND a.create_name = #{tGzArea.createName}
                    </if>
                    <if test="tGzArea.updateBy != null and tGzArea.updateBy.trim() != ''">
                        AND a.update_by = #{tGzArea.updateBy}
                    </if>
                    <if test="tGzArea.updateTime != null">
                        AND a.update_time = #{tGzArea.updateTime}
                    </if>
        </if>
    </sql>

    <!--tGzArea简单分页查询-->
    <select id="getTGzAreaPage" resultMap="tGzAreaMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_gz_area a
        <where>
            1=1
            <include refid="tGzArea_where"/>
        </where>
		ORDER BY a.create_time DESC
    </select>

	<!-- 查询list -->
    <select id="getTGzAreaList" resultMap="tGzAreaMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_gz_area a
        <where>
            1=1
            <include refid="tGzArea_where"/>
        </where>
		ORDER BY a.create_time DESC
    </select>

	<!-- 导出条数 -->
    <select id="getTGzAreaExportCount" resultType="java.lang.Long">
        SELECT
        count(1)
        FROM t_gz_area a
        <where>
            1=1
            <include refid="tGzArea_where"/>
        </where>
    </select>

	<!-- 导出 -->
    <select id="getTGzAreaExport" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TGzAreaExportVo">
        SELECT
			a.AREA_CODE,
			a.AREA_NAME,
			a.GZ_CODE,
			a.GZ_NAME
        FROM t_gz_area a
        <where>
            1=1
            <include refid="tGzArea_where"/>
        </where>
		ORDER BY a.create_time DESC
		<if test="tGzArea != null">
			<if test="tGzArea.limitStart != null">
				limit #{tGzArea.limitStart},#{tGzArea.limitEnd}
			</if>
		</if>
    </select>

	<!-- 验重复 -->
	<select id="getTGzAreaCountByCode" resultType="java.lang.Long">
		SELECT
		count(1)
		FROM t_gz_area a
		where a.AREA_CODE = #{areaCode}
		<if test="id != null and id.trim() != ''">
			AND a.ID != #{id}
		</if>
	</select>
</mapper>
