<?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.sys.contrastTask.dao.impl.SysContrastTaskDaoImpl">

    <resultMap id="get-SysContrastTaskEntity-result"
               type="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="serviceName" column="service_name" jdbcType="VARCHAR"/>
        <result property="leftAppId" column="left_app_id" jdbcType="VARCHAR"/>
        <result property="leftApiId" column="left_api_id" jdbcType="VARCHAR"/>
        <result property="rightAppId" column="right_app_id" jdbcType="VARCHAR"/>
        <result property="rightApiId" column="right_api_id" jdbcType="VARCHAR"/>
        <result property="taskStatus" column="task_status" jdbcType="VARCHAR"/>
        <result property="taskMsg" column="task_msg" jdbcType="VARCHAR"/>
        <result property="sorts" column="sorts" jdbcType="INTEGER"/>
        <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="modifyUserId" column="modify_user_id" jdbcType="VARCHAR"/>
        <result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP"/>
        <result property="sts" column="sts" jdbcType="VARCHAR"/>
        <result property="orgId" column="org_id" jdbcType="VARCHAR"/>
        <result property="matchMode" column="match_mode" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="SysContrastTaskEntity_Base_Column_List">
        id
       ,service_name 
        ,left_app_id 
        ,left_api_id 
        ,right_app_id 
        ,right_api_id 
        ,task_status 
        ,task_msg 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,match_mode
     </sql>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-SysContrastTaskEntity-result"
            parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        select
        <include refid="SysContrastTaskEntity_Base_Column_List"/>
        from sys_contrast_task
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="serviceName != null and serviceName != ''">and service_name = #{serviceName}</if>
            <if test="leftAppId != null and leftAppId != ''">and left_app_id = #{leftAppId}</if>
            <if test="leftApiId != null and leftApiId != ''">and left_api_id = #{leftApiId}</if>
            <if test="rightAppId != null and rightAppId != ''">and right_app_id = #{rightAppId}</if>
            <if test="rightApiId != null and rightApiId != ''">and right_api_id = #{rightApiId}</if>
            <if test="taskStatus != null and taskStatus != ''">and task_status = #{taskStatus}</if>
            <if test="taskMsg != null and taskMsg != ''">and task_msg = #{taskMsg}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id = #{createUserId}</if>
            <if test="createTime != null">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">and org_id = #{orgId}</if>
            <if test="matchMode != null and matchMode != ''">and match_mode = #{matchMode}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询符合条件的数量 -->
    <select id="entity_count" resultType="Integer"
            parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        select count(1) from sys_contrast_task
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="serviceName != null and serviceName != ''">and service_name = #{serviceName}</if>
            <if test="leftAppId != null and leftAppId != ''">and left_app_id = #{leftAppId}</if>
            <if test="leftApiId != null and leftApiId != ''">and left_api_id = #{leftApiId}</if>
            <if test="rightAppId != null and rightAppId != ''">and right_app_id = #{rightAppId}</if>
            <if test="rightApiId != null and rightApiId != ''">and right_api_id = #{rightApiId}</if>
            <if test="taskStatus != null and taskStatus != ''">and task_status = #{taskStatus}</if>
            <if test="taskMsg != null and taskMsg != ''">and task_msg = #{taskMsg}</if>
            <if test="sorts != null">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id = #{createUserId}</if>
            <if test="createTime != null">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">and sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">and org_id = #{orgId}</if>
            <if test="matchMode != null and matchMode != ''">and match_mode = #{matchMode}</if>
            and sts='Y'
        </trim>
        <if test=" sort ==''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-SysContrastTaskEntity-result"
            parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        select
        <include refid="SysContrastTaskEntity_Base_Column_List"/>
        from sys_contrast_task
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="serviceName != null and serviceName != ''">and service_name like concat('%',#{serviceName},'%')
            </if>
            <if test="leftAppId != null and leftAppId != ''">and left_app_id like concat('%',#{leftAppId},'%')</if>
            <if test="leftApiId != null and leftApiId != ''">and left_api_id like concat('%',#{leftApiId},'%')</if>
            <if test="rightAppId != null and rightAppId != ''">and right_app_id like concat('%',#{rightAppId},'%')</if>
            <if test="rightApiId != null and rightApiId != ''">and right_api_id like concat('%',#{rightApiId},'%')</if>
            <if test="taskStatus != null and taskStatus != ''">and task_status like concat('%',#{taskStatus},'%')</if>
            <if test="taskMsg != null and taskMsg != ''">and task_msg like concat('%',#{taskMsg},'%')</if>
            <if test="sorts != null">and sorts like concat('%',#{sorts},'%')</if>
            <if test="createUserId != null and createUserId != ''">and create_user_id like
                concat('%',#{createUserId},'%')
            </if>
            <if test="createTime != null">and create_time like concat('%',#{createTime},'%')</if>
            <if test="modifyUserId != null and modifyUserId != ''">and modify_user_id like
                concat('%',#{modifyUserId},'%')
            </if>
            <if test="modifyTime != null">and modify_time like concat('%',#{modifyTime},'%')</if>
            <if test="sts != null and sts != ''">and sts like concat('%',#{sts},'%')</if>
            <if test="orgId != null and orgId != ''">and org_id like concat('%',#{orgId},'%')</if>
            <if test="matchMode != null and matchMode != ''">and match_mode like concat('%',#{matchMode},'%')</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询列表 字段采用or格式 -->
    <select id="SysContrastTaskentity_list_or" resultMap="get-SysContrastTaskEntity-result"
            parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        select
        <include refid="SysContrastTaskEntity_Base_Column_List"/>
        from sys_contrast_task
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="serviceName != null and serviceName != ''">or service_name = #{serviceName}</if>
            <if test="leftAppId != null and leftAppId != ''">or left_app_id = #{leftAppId}</if>
            <if test="leftApiId != null and leftApiId != ''">or left_api_id = #{leftApiId}</if>
            <if test="rightAppId != null and rightAppId != ''">or right_app_id = #{rightAppId}</if>
            <if test="rightApiId != null and rightApiId != ''">or right_api_id = #{rightApiId}</if>
            <if test="taskStatus != null and taskStatus != ''">or task_status = #{taskStatus}</if>
            <if test="taskMsg != null and taskMsg != ''">or task_msg = #{taskMsg}</if>
            <if test="sorts != null">or sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">or create_user_id = #{createUserId}</if>
            <if test="createTime != null">or create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">or modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">or modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">or sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">or org_id = #{orgId}</if>
            <if test="matchMode != null and matchMode != ''">or match_mode = #{matchMode}</if>
            and sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!--新增所有列-->
    <insert id="entity_insert" parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity"
            keyProperty="" useGeneratedKeys="true">
        insert into sys_contrast_task(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="serviceName != null and serviceName != ''">service_name ,</if>
            <if test="leftAppId != null and leftAppId != ''">left_app_id ,</if>
            <if test="leftApiId != null and leftApiId != ''">left_api_id ,</if>
            <if test="rightAppId != null and rightAppId != ''">right_app_id ,</if>
            <if test="rightApiId != null and rightApiId != ''">right_api_id ,</if>
            <if test="taskStatus != null and taskStatus != ''">task_status ,</if>
            <if test="taskMsg != null and taskMsg != ''">task_msg ,</if>
            <if test="sorts != null">sorts ,</if>
            <if test="createUserId != null and createUserId != ''">create_user_id ,</if>
            <if test="createTime != null">create_time ,</if>
            <if test="modifyUserId != null and modifyUserId != ''">modify_user_id ,</if>
            <if test="modifyTime != null">modify_time ,</if>
            <if test="sts != null and sts != ''">sts ,</if>
            <if test="orgId != null and orgId != ''">org_id ,</if>
            <if test="matchMode != null and matchMode != ''">match_mode ,</if>
            <if test="sorts == null ">sorts,</if>
            <if test="sts == null ">sts,</if>
        </trim>
        )values(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">#{id} ,</if>
            <if test="serviceName != null and serviceName != ''">#{serviceName} ,</if>
            <if test="leftAppId != null and leftAppId != ''">#{leftAppId} ,</if>
            <if test="leftApiId != null and leftApiId != ''">#{leftApiId} ,</if>
            <if test="rightAppId != null and rightAppId != ''">#{rightAppId} ,</if>
            <if test="rightApiId != null and rightApiId != ''">#{rightApiId} ,</if>
            <if test="taskStatus != null and taskStatus != ''">#{taskStatus} ,</if>
            <if test="taskMsg != null and taskMsg != ''">#{taskMsg} ,</if>
            <if test="sorts != null">#{sorts} ,</if>
            <if test="createUserId != null and createUserId != ''">#{createUserId} ,</if>
            <if test="createTime != null">#{createTime} ,</if>
            <if test="modifyUserId != null and modifyUserId != ''">#{modifyUserId} ,</if>
            <if test="modifyTime != null">#{modifyTime} ,</if>
            <if test="sts != null and sts != ''">#{sts} ,</if>
            <if test="orgId != null and orgId != ''">#{orgId} ,</if>
            <if test="matchMode != null and matchMode != ''">#{matchMode} ,</if>
            <if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from sys_contrast_task a WHERE
                a.sts = 'Y' ),
            </if>
            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="entityInsertBatch" keyProperty="" useGeneratedKeys="true">
        insert into sys_contrast_task(id, service_name, left_app_id, left_api_id, right_app_id, right_api_id,
        task_status, task_msg, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, match_mode,
        sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id},#{entity.serviceName},#{entity.leftAppId},#{entity.leftApiId},#{entity.rightAppId},#{entity.rightApiId},#{entity.taskStatus},#{entity.taskMsg},#{entity.sorts},#{entity.createUserId},#{entity.createTime},#{entity.modifyUserId},#{entity.modifyTime},#{entity.sts},#{entity.orgId},#{entity.matchMode},
            'Y')
        </foreach>
    </insert>
    <!-- 批量新增或者修改-->
    <insert id="entityInsertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
        insert into sys_contrast_task(id, service_name, left_app_id, left_api_id, right_app_id, right_api_id,
        task_status, task_msg, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, match_mode)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.serviceName}, #{entity.leftAppId}, #{entity.leftApiId}, #{entity.rightAppId},
            #{entity.rightApiId}, #{entity.taskStatus}, #{entity.taskMsg}, #{entity.sorts}, #{entity.createUserId},
            #{entity.createTime}, #{entity.modifyUserId}, #{entity.modifyTime}, #{entity.sts}, #{entity.orgId},
            #{entity.matchMode})
        </foreach>
        on duplicate key update
        id = values(id),
        service_name = values(service_name),
        left_app_id = values(left_app_id),
        left_api_id = values(left_api_id),
        right_app_id = values(right_app_id),
        right_api_id = values(right_api_id),
        task_status = values(task_status),
        task_msg = values(task_msg),
        sorts = values(sorts),
        create_user_id = values(create_user_id),
        create_time = values(create_time),
        modify_user_id = values(modify_user_id),
        modify_time = values(modify_time),
        sts = values(sts),
        org_id = values(org_id),
        match_mode = values(match_mode)
    </insert>
    <!--通过主键修改方法-->
    <update id="entity_update" parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        update sys_contrast_task set
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id = #{id},</if>
            <if test="serviceName != null and serviceName != ''">service_name = #{serviceName},</if>
            <if test="leftAppId != null and leftAppId != ''">left_app_id = #{leftAppId},</if>
            <if test="leftApiId != null and leftApiId != ''">left_api_id = #{leftApiId},</if>
            <if test="rightAppId != null and rightAppId != ''">right_app_id = #{rightAppId},</if>
            <if test="rightApiId != null and rightApiId != ''">right_api_id = #{rightApiId},</if>
            <if test="taskStatus != null and taskStatus != ''">task_status = #{taskStatus},</if>
            <if test="taskMsg != null and taskMsg != ''">task_msg = #{taskMsg},</if>
            <if test="sorts != null">sorts = #{sorts},</if>
            <if test="createUserId != null and createUserId != ''">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modifyUserId != null and modifyUserId != ''">modify_user_id = #{modifyUserId},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
            <if test="sts != null and sts != ''">sts = #{sts},</if>
            <if test="orgId != null and orgId != ''">org_id = #{orgId},</if>
            <if test="matchMode != null and matchMode != ''">match_mode = #{matchMode},</if>
        </trim>
        where id = #{id}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
update sys_contrast_task  set sts= 'N'
where  id = #{id}
</update>
    <!-- 多条件逻辑删除 -->
    <update id="entity_logicDelete_Multi_Condition"
            parameterType="com.hzya.frame.sys.contrastTask.entity.SysContrastTaskEntity">
        update sys_contrast_task set sts= 'N'
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="serviceName != null and serviceName != ''">or service_name = #{serviceName}</if>
            <if test="leftAppId != null and leftAppId != ''">or left_app_id = #{leftAppId}</if>
            <if test="leftApiId != null and leftApiId != ''">or left_api_id = #{leftApiId}</if>
            <if test="rightAppId != null and rightAppId != ''">or right_app_id = #{rightAppId}</if>
            <if test="rightApiId != null and rightApiId != ''">or right_api_id = #{rightApiId}</if>
            <if test="taskStatus != null and taskStatus != ''">or task_status = #{taskStatus}</if>
            <if test="taskMsg != null and taskMsg != ''">or task_msg = #{taskMsg}</if>
            <if test="sorts != null">or sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId != ''">or create_user_id = #{createUserId}</if>
            <if test="createTime != null">or create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId != ''">or modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null">or modify_time = #{modifyTime}</if>
            <if test="sts != null and sts != ''">or sts = #{sts}</if>
            <if test="orgId != null and orgId != ''">or org_id = #{orgId}</if>
            <if test="matchMode != null and matchMode != ''">or match_mode = #{matchMode}</if>
            and sts='Y'
        </trim>
    </update>
    <!--通过主键删除-->
    <delete id="deleteById">
    delete from sys_contrast_task where id = #{id}
</delete>
    <!--通过ID获取数据 -->
    <select id="truncateTable" resultType="java.lang.Integer">
			truncate table  ${tableName}
	</select>


    <!-- 批量新增 -->
    <insert id="saveBatchContrast" parameterType="com.hzya.frame.sys.contrastTask.entity.SaveBatchConTrastEntity">
        insert into ${tableName} (
        id,
        left_app_id,
        left_app_code,
        left_app_name,
        left_api_id,
        left_id,
        left_code,
        left_name,
        <if test="tableName == 'sys_customer_control'.toString()">left_tin,</if>
        <if test="tableName == 'sys_supplier_control'.toString()">left_tin,</if>
        <if test="tableName == 'sys_personnel_control'.toString()">left_tel,</if>
        <if test="tableName == 'sys_personnel_control'.toString()">left_ic,</if>

        right_app_id,
        right_app_code,
        right_app_name,
        right_api_id,
        right_id,
        right_code,
        right_name,
        <if test="tableName == 'sys_customer_control'.toString()">right_tin,</if>
        <if test="tableName == 'sys_supplier_control'.toString()">right_tin,</if>
        <if test="tableName == 'sys_personnel_control'.toString()">right_tel,</if>
        <if test="tableName == 'sys_personnel_control'.toString()">right_ic,</if>

        sorts,
        create_user_id,
        create_time,
        modify_user_id,
        modify_time,
        sts
        )
        values
        <foreach collection="detailData" item="entity" separator=",">
            (
            #{entity.id},
            #{left_app_id},
            #{left_app_code},
            #{left_app_name},
            #{left_api_id},
            #{entity.left_id},
            #{entity.left_code},
            #{entity.left_name},
            <if test="tableName == 'sys_customer_control'.toString()">#{entity.left_tin},</if>
            <if test="tableName == 'sys_supplier_control'.toString()">#{entity.left_tin},</if>
            <if test="tableName == 'sys_personnel_control'.toString()">#{entity.left_tel},</if>
            <if test="tableName == 'sys_personnel_control'.toString()">#{entity.left_ic},</if>
            #{right_app_id},
            #{right_app_code},
            #{right_app_name},
            #{right_api_id},
            #{entity.right_id},
            #{entity.right_code},
            #{entity.right_name},
            <if test="tableName == 'sys_customer_control'.toString()">#{entity.right_tin},</if>
            <if test="tableName == 'sys_supplier_control'.toString()">#{entity.right_tin},</if>
            <if test="tableName == 'sys_personnel_control'.toString()">#{entity.right_tel},</if>
            <if test="tableName == 'sys_personnel_control'.toString()">#{entity.right_tel},</if>
            #{entity.sorts},
            #{userId},
            now(),
            #{userId},
            now(),
            'Y'
            )
        </foreach>
    </insert>

    <!--    根据sql语句查询-->
    <select id="dosql" resultType="com.alibaba.fastjson.JSONObject" parameterType="string">
        <if test="null != sql and sql != ''">
            ${sql}
        </if>
    </select>
</mapper>

