<?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.hotent.baseInfo.dao.AuditedUnitDao">

    <resultMap id="BaseResultMap" type="com.hotent.baseInfo.model.AuditedUnit">
        <id column="unit_id" property="unitId" />
        <result column="unit_name" property="unitName" />
        <result column="social_credit_code" property="socialCreditCode" />
        <result column="area_level" property="areaLevel" />
        <result column="area_code" property="areaCode" />
        <result column="address" property="address" />
        <result column="entity_type" property="entityType" />
        <result column="related_units" property="relatedUnits" />
        <result column="related_items" property="relatedItems" />
        <result column="contact_name" property="contactName" />
        <result column="contact_mobile" property="contactMobile" />
        <result column="email" property="email" />
        <result column="postal_code" property="postalCode" />
        <result column="account" property="account" />
        <result column="password" property="password" />
        <result column="status" property="status" />
        <result column="is_deleted" property="isDeleted" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="tenant_id_" property="tenantId" />
    </resultMap>

    <sql id="Base_Column_List">
        unit_id, unit_name, social_credit_code, area_level, area_code, address, entity_type, related_units, related_items,
        contact_name, contact_mobile, email, postal_code, account, password, status, is_deleted, create_time, create_by, update_time, update_by, tenant_id_
    </sql>

    <select id="selectByRegionAndName" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM audited_unit
        WHERE is_deleted = 0
        <if test="regionCode != null and regionCode != '' and regionCode != '全部'">
            AND region_code = #{regionCode}
        </if>
        <if test="unitName != null and unitName != ''">
            AND unit_name LIKE CONCAT('%', #{unitName}, '%')
        </if>
        ORDER BY unit_name ASC
    </select>

</mapper>


