<?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.hzya.frame.sysnew.application.dictionaryDetail.dao.SysApplicationDictionaryDetailDao">

    <resultMap type="com.hzya.frame.sysnew.application.dictionaryDetail.entity.SysApplicationDictionaryDetail" id="SysApplicationDictionaryDetailMap">
        <result property="appId" column="app_id" jdbcType="VARCHAR"/>
        <result property="dictionaryId" column="dictionary_id" jdbcType="VARCHAR"/>
        <result property="fieldName" column="field_name" jdbcType="VARCHAR"/>
        <result property="fieldCode" column="field_code" jdbcType="VARCHAR"/>
        <result property="fieldType" column="field_type" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="modifyUserId" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="orgId" column="org_id" jdbcType="VARCHAR"/>
        <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SysApplicationDictionaryDetailMap">
        select
          app_id, dictionary_id, field_name, field_code, field_type, sorts, id, create_user_id, create_time, modify_time, modify_user_id, org_id, company_id, sts
        from sys_application_dictionary_detail
        where sorts = #{sorts}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SysApplicationDictionaryDetailMap">
        select
          app_id, dictionary_id, field_name, field_code, field_type, sorts, id, create_user_id, create_time, modify_time, modify_user_id, org_id, company_id, sts
        from sys_application_dictionary_detail
        <where>
            <if test="appId != null and appId != ''">
                and app_id = #{appId}
            </if>
            <if test="dictionaryId != null and dictionaryId != ''">
                and dictionary_id = #{dictionaryId}
            </if>
            <if test="fieldName != null and fieldName != ''">
                and field_name = #{fieldName}
            </if>
            <if test="fieldCode != null and fieldCode != ''">
                and field_code = #{fieldCode}
            </if>
            <if test="fieldType != null and fieldType != ''">
                and field_type = #{fieldType}
            </if>
            <if test="sorts != null">
                and sorts = #{sorts}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="createUserId != null and createUserId != ''">
                and create_user_id = #{createUserId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="modifyTime != null">
                and modify_time = #{modifyTime}
            </if>
            <if test="modifyUserId != null and modifyUserId != ''">
                and modify_user_id = #{modifyUserId}
            </if>
            <if test="orgId != null and orgId != ''">
                and org_id = #{orgId}
            </if>
            <if test="companyId != null and companyId != ''">
                and company_id = #{companyId}
            </if>
            <if test="sts != null and sts != ''">
                and sts = #{sts}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from sys_application_dictionary_detail
        <where>
            <if test="appId != null and appId != ''">
                and app_id = #{appId}
            </if>
            <if test="dictionaryId != null and dictionaryId != ''">
                and dictionary_id = #{dictionaryId}
            </if>
            <if test="fieldName != null and fieldName != ''">
                and field_name = #{fieldName}
            </if>
            <if test="fieldCode != null and fieldCode != ''">
                and field_code = #{fieldCode}
            </if>
            <if test="fieldType != null and fieldType != ''">
                and field_type = #{fieldType}
            </if>
            <if test="sorts != null">
                and sorts = #{sorts}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="createUserId != null and createUserId != ''">
                and create_user_id = #{createUserId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="modifyTime != null">
                and modify_time = #{modifyTime}
            </if>
            <if test="modifyUserId != null and modifyUserId != ''">
                and modify_user_id = #{modifyUserId}
            </if>
            <if test="orgId != null and orgId != ''">
                and org_id = #{orgId}
            </if>
            <if test="companyId != null and companyId != ''">
                and company_id = #{companyId}
            </if>
            <if test="sts != null and sts != ''">
                and sts = #{sts}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="sorts" useGeneratedKeys="true">
        insert into sys_application_dictionary_detail(app_id, dictionary_id, field_name, field_code, field_type, create_user_id, create_time, modify_time, modify_user_id, org_id, company_id, sts)
        values (#{appId}, #{dictionaryId}, #{fieldName}, #{fieldCode}, #{fieldType}, #{createUserId}, #{createTime}, #{modifyTime}, #{modifyUserId}, #{orgId}, #{companyId}, #{sts})
    </insert>

    <insert id="insertBatch" keyProperty="sorts" useGeneratedKeys="true">
        insert into sys_application_dictionary_detail(app_id, dictionary_id, field_name, field_code, field_type, create_user_id, create_time, modify_time, modify_user_id, org_id, company_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.appId}, #{entity.dictionaryId}, #{entity.fieldName}, #{entity.fieldCode}, #{entity.fieldType}, #{entity.createUserId}, #{entity.createTime}, #{entity.modifyTime}, #{entity.modifyUserId}, #{entity.orgId}, #{entity.companyId}, #{entity.sts})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="sorts" useGeneratedKeys="true">
        insert into sys_application_dictionary_detail(app_id, dictionary_id, field_name, field_code, field_type, create_user_id, create_time, modify_time, modify_user_id, org_id, company_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.appId}, #{entity.dictionaryId}, #{entity.fieldName}, #{entity.fieldCode}, #{entity.fieldType}, #{entity.createUserId}, #{entity.createTime}, #{entity.modifyTime}, #{entity.modifyUserId}, #{entity.orgId}, #{entity.companyId}, #{entity.sts})
        </foreach>
        on duplicate key update
        app_id = values(app_id),
        dictionary_id = values(dictionary_id),
        field_name = values(field_name),
        field_code = values(field_code),
        field_type = values(field_type),
        create_user_id = values(create_user_id),
        create_time = values(create_time),
        modify_time = values(modify_time),
        modify_user_id = values(modify_user_id),
        org_id = values(org_id),
        company_id = values(company_id),
        sts = values(sts)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update sys_application_dictionary_detail
        <set>
            <if test="appId != null and appId != ''">
                app_id = #{appId},
            </if>
            <if test="dictionaryId != null and dictionaryId != ''">
                dictionary_id = #{dictionaryId},
            </if>
            <if test="fieldName != null and fieldName != ''">
                field_name = #{fieldName},
            </if>
            <if test="fieldCode != null and fieldCode != ''">
                field_code = #{fieldCode},
            </if>
            <if test="fieldType != null and fieldType != ''">
                field_type = #{fieldType},
            </if>
            <if test="createUserId != null and createUserId != ''">
                create_user_id = #{createUserId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime},
            </if>
            <if test="modifyUserId != null and modifyUserId != ''">
                modify_user_id = #{modifyUserId},
            </if>
            <if test="orgId != null and orgId != ''">
                org_id = #{orgId},
            </if>
            <if test="companyId != null and companyId != ''">
                company_id = #{companyId},
            </if>
            <if test="sts != null and sts != ''">
                sts = #{sts},
            </if>
        </set>
        where sorts = #{sorts}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from sys_application_dictionary_detail where sorts = #{sorts}
    </delete>

</mapper>

