<?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.u8c.ax.dao.impl.AxDaoImpl">
    <resultMap id="get-ArchivesEntity-result" type="com.hzya.frame.u8c.ax.entity.ArchivesEntity" >
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="leftAppId" column="left_app_id" jdbcType="VARCHAR"/>
        <result property="leftAppCode" column="left_app_code" jdbcType="VARCHAR"/>
        <result property="leftAppName" column="left_app_name" jdbcType="VARCHAR"/>
        <result property="leftApiId" column="left_api_id" jdbcType="VARCHAR"/>
        <result property="leftId" column="left_id" jdbcType="VARCHAR"/>
        <result property="leftCode" column="left_code" jdbcType="VARCHAR"/>
        <result property="leftName" column="left_name" jdbcType="VARCHAR"/>
        <result property="rightAppId" column="right_app_id" jdbcType="VARCHAR"/>
        <result property="rightAppCode" column="right_app_code" jdbcType="VARCHAR"/>
        <result property="rightAppName" column="right_app_name" jdbcType="VARCHAR"/>
        <result property="rightApiId" column="right_api_id" jdbcType="VARCHAR"/>
        <result property="rightId" column="right_id" jdbcType="VARCHAR"/>
        <result property="rightCode" column="right_code" jdbcType="VARCHAR"/>
        <result property="rightName" column="right_name" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="create_user_id" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modify_user_id" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="modify_time" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
        <result property="org_id" column="org_id" jdbcType="VARCHAR"/>
        <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="queryArchivesData" resultMap="get-ArchivesEntity-result"
            parameterType="com.hzya.frame.u8c.ax.entity.ArchivesEntity">
        select
        right_code
        from
        <choose>
            <when test="archivesType == '1'.toString()"> sys_personnel_control </when>
            <when test="archivesType == '2'.toString()"> sys_org_control </when>
            <when test="archivesType == '6'.toString()"> sys_stock_control </when>
            <when test="archivesType == '73'.toString()"> sys_merchant_control </when>
            <when test="archivesType == 'D01'.toString()"> sys_taxrate_control </when>
            <when test="archivesType == 'jobass'.toString()"> sys_project_control </when>
            <when test="archivesType == '93'.toString()"> sys_bank_control </when>
            <when test="archivesType == '96'.toString()"> sys_bankaccount_control </when>
            <when test="archivesType == '22'.toString()"> sys_assets_control </when>
        </choose>
        <trim prefix="where" prefixOverrides="and">
            <if test="leftCode != null and leftCode != ''">and left_code = #{leftCode}</if>
            <if test="leftOrg != null and leftOrg != ''">and left_org = #{leftOrg}</if>
            and sts='Y'
        </trim>
    </select>


    <!--新增所有列-->
    <insert id="saveArchivesByType" parameterType = "com.hzya.frame.u8c.ax.entity.ArchivesEntity">
        insert into
        <choose>
            <when test="archivesType == '1'.toString()"> sys_personnel_control </when>
            <when test="archivesType == '2'.toString()"> sys_org_control </when>
            <when test="archivesType == '6'.toString()"> sys_stock_control </when>
            <when test="archivesType == '73'.toString()"> sys_merchant_control </when>
            <when test="archivesType == 'D01'.toString()"> sys_taxrate_control </when>
            <when test="archivesType == 'jobass'.toString()"> sys_project_control </when>
            <when test="archivesType == '93'.toString()"> sys_bank_control </when>
            <when test="archivesType == '96'.toString()"> sys_bankaccount_control </when>
            <when test="archivesType == '22'.toString()"> sys_assets_control </when>
        </choose>
        (
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''"> id , </if>
            <if test="leftAppId != null and leftAppId != ''"> left_app_id , </if>
            <if test="leftAppCode != null and leftAppCode != ''"> left_app_code , </if>
            <if test="leftAppName != null and leftAppName != ''"> left_app_name , </if>
            <if test="leftApiId != null and leftApiId != ''"> left_api_id , </if>
            <if test="leftId != null and leftId != ''"> left_id , </if>
            <if test="leftCode != null and leftCode != ''"> left_code , </if>
            <if test="leftName != null and leftName != ''"> left_name , </if>
            <if test="rightAppId != null and rightAppId != ''"> right_app_id , </if>
            <if test="rightAppCode != null and rightAppCode != ''"> right_app_code , </if>
            <if test="rightAppName != null and rightAppName != ''"> right_app_name , </if>
            <if test="rightApiId != null and rightApiId != ''"> right_api_id , </if>
            <if test="rightId != null and rightId != ''"> right_id , </if>
            <if test="rightCode != null and rightCode != ''"> right_code , </if>
            <if test="rightName != null and rightName != ''"> right_name , </if>
            <if test="sorts != null"> sorts , </if>
            <if test="create_user_id != null and create_user_id != ''"> create_user_id , </if>
            <if test="create_time != null"> create_time , </if>
            <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id , </if>
            <if test="modify_time != null"> modify_time , </if>
            <if test="sts != null and sts != ''"> sts , </if>
            <if test="org_id != null and org_id != ''"> org_id , </if>
            <if test="companyId != null and companyId != ''"> company_id , </if>
            <if test="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''"> #{id} ,</if>
            <if test="leftAppId != null and leftAppId != ''"> #{leftAppId} ,</if>
            <if test="leftAppCode != null and leftAppCode != ''"> #{leftAppCode} ,</if>
            <if test="leftAppName != null and leftAppName != ''"> #{leftAppName} ,</if>
            <if test="leftApiId != null and leftApiId != ''"> #{leftApiId} ,</if>
            <if test="leftId != null and leftId != ''"> #{leftId} ,</if>
            <if test="leftCode != null and leftCode != ''"> #{leftCode} ,</if>
            <if test="leftName != null and leftName != ''"> #{leftName} ,</if>
            <if test="rightAppId != null and rightAppId != ''"> #{rightAppId} ,</if>
            <if test="rightAppCode != null and rightAppCode != ''"> #{rightAppCode} ,</if>
            <if test="rightAppName != null and rightAppName != ''"> #{rightAppName} ,</if>
            <if test="rightApiId != null and rightApiId != ''"> #{rightApiId} ,</if>
            <if test="rightId != null and rightId != ''"> #{rightId} ,</if>
            <if test="rightCode != null and rightCode != ''"> #{rightCode} ,</if>
            <if test="rightName != null and rightName != ''"> #{rightName} ,</if>
            <if test="sorts != null"> #{sorts} ,</if>
            <if test="create_user_id != null and create_user_id != ''"> #{create_user_id} ,</if>
            <if test="create_time != null"> #{create_time} ,</if>
            <if test="modify_user_id != null and modify_user_id != ''"> #{modify_user_id} ,</if>
            <if test="modify_time != null"> #{modify_time} ,</if>
            <if test="sts != null and sts != ''"> #{sts} ,</if>
            <if test="org_id != null and org_id != ''"> #{org_id} ,</if>
            <if test="companyId != null and companyId != ''"> #{companyId} ,</if>
            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>

    <!--通过主键修改方法-->
    <update id="updateArchivesByType" parameterType = "com.hzya.frame.u8c.ax.entity.ArchivesEntity" >
        update
        <choose>
            <when test="archivesType == '1'.toString()"> sys_personnel_control </when>
            <when test="archivesType == '2'.toString()"> sys_org_control </when>
            <when test="archivesType == '6'.toString()"> sys_stock_control </when>
            <when test="archivesType == '73'.toString()"> sys_merchant_control </when>
            <when test="archivesType == 'D01'.toString()"> sys_taxrate_control </when>
            <when test="archivesType == 'jobass'.toString()"> sys_project_control </when>
            <when test="archivesType == '93'.toString()"> sys_bank_control </when>
            <when test="archivesType == '96'.toString()"> sys_bankaccount_control </when>
            <when test="archivesType == '22'.toString()"> sys_assets_control </when>
        </choose>
      set
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''"> id = #{id},</if>
            <if test="leftAppId != null and leftAppId != ''"> left_app_id = #{leftAppId},</if>
            <if test="leftAppCode != null and leftAppCode != ''"> left_app_code = #{leftAppCode},</if>
            <if test="leftAppName != null and leftAppName != ''"> left_app_name = #{leftAppName},</if>
            <if test="leftApiId != null and leftApiId != ''"> left_api_id = #{leftApiId},</if>
            <if test="leftId != null and leftId != ''"> left_id = #{leftId},</if>
            <if test="leftCode != null and leftCode != ''"> left_code = #{leftCode},</if>
            <if test="leftName != null and leftName != ''"> left_name = #{leftName},</if>
            <if test="rightAppId != null and rightAppId != ''"> right_app_id = #{rightAppId},</if>
            <if test="rightAppCode != null and rightAppCode != ''"> right_app_code = #{rightAppCode},</if>
            <if test="rightAppName != null and rightAppName != ''"> right_app_name = #{rightAppName},</if>
            <if test="rightApiId != null and rightApiId != ''"> right_api_id = #{rightApiId},</if>
            <if test="rightId != null and rightId != ''"> right_id = #{rightId},</if>
            <if test="rightCode != null and rightCode != ''"> right_code = #{rightCode},</if>
            <if test="rightName != null and rightName != ''"> right_name = #{rightName},</if>
            <if test="sorts != null"> sorts = #{sorts},</if>
            <if test="create_user_id != null and create_user_id != ''"> create_user_id = #{create_user_id},</if>
            <if test="create_time != null"> create_time = #{create_time},</if>
            <if test="modify_user_id != null and modify_user_id != ''"> modify_user_id = #{modify_user_id},</if>
            <if test="modify_time != null"> modify_time = #{modify_time},</if>
            <if test="sts != null and sts != ''"> sts = #{sts},</if>
            <if test="org_id != null and org_id != ''"> org_id = #{org_id},</if>
            <if test="companyId != null and companyId != ''"> company_id = #{companyId},</if>
        </trim>
        where  right_id = #{rightId}
    </update>

    <!-- 多条件逻辑删除 -->
    <update id="deleteArchivesByType" parameterType = "com.hzya.frame.u8c.ax.entity.ArchivesEntity" >
        update
        <choose>
            <when test="archivesType == '1'.toString()"> sys_personnel_control </when>
            <when test="archivesType == '2'.toString()"> sys_org_control </when>
            <when test="archivesType == '6'.toString()"> sys_stock_control </when>
            <when test="archivesType == '73'.toString()"> sys_merchant_control </when>
            <when test="archivesType == 'D01'.toString()"> sys_taxrate_control </when>
            <when test="archivesType == 'jobass'.toString()"> sys_project_control </when>
            <when test="archivesType == '93'.toString()"> sys_bank_control </when>
            <when test="archivesType == '96'.toString()"> sys_bankaccount_control </when>
            <when test="archivesType == '22'.toString()"> sys_assets_control </when>
        </choose>
        set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="leftAppId != null and leftAppId != ''"> and left_app_id = #{leftAppId} </if>
            <if test="leftAppCode != null and leftAppCode != ''"> and left_app_code = #{leftAppCode} </if>
            <if test="leftAppName != null and leftAppName != ''"> and left_app_name = #{leftAppName} </if>
            <if test="leftApiId != null and leftApiId != ''"> and left_api_id = #{leftApiId} </if>
            <if test="leftId != null and leftId != ''"> and left_id = #{leftId} </if>
            <if test="leftCode != null and leftCode != ''"> and left_code = #{leftCode} </if>
            <if test="leftName != null and leftName != ''"> and left_name = #{leftName} </if>
            <if test="rightAppId != null and rightAppId != ''"> and right_app_id = #{rightAppId} </if>
            <if test="rightAppCode != null and rightAppCode != ''"> and right_app_code = #{rightAppCode} </if>
            <if test="rightAppName != null and rightAppName != ''"> and right_app_name = #{rightAppName} </if>
            <if test="rightApiId != null and rightApiId != ''"> and right_api_id = #{rightApiId} </if>
            <if test="rightId != null and rightId != ''"> and right_id = #{rightId} </if>
            <if test="rightCode != null and rightCode != ''"> and right_code = #{rightCode} </if>
            <if test="rightName != null and rightName != ''"> and right_name = #{rightName} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </if>
            and sts='Y'
        </trim>
    </update>

</mapper>

