<?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.mdm.mdmModuleSource.dao.impl.MdmModuleSourceDaoImpl">

    <resultMap id="get-MdmModuleSourceEntity-result" type="com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity" >
       <result property="id" column="id" jdbcType="VARCHAR"/>
           <result property="mdmId" column="mdm_id" jdbcType="VARCHAR"/>
           <result property="sourceType" column="source_type" jdbcType="VARCHAR"/>
           <result property="sourceName" column="source_name" jdbcType="VARCHAR"/>
           <result property="triggerType" column="trigger_type" jdbcType="VARCHAR"/>
           <result property="sourceCode" column="source_code" jdbcType="VARCHAR"/>
           <result property="addApi" column="add_api" jdbcType="VARCHAR"/>
           <result property="updateApi" column="update_api" jdbcType="VARCHAR"/>
           <result property="deleteApi" column="delete_api" jdbcType="VARCHAR"/>
           <result property="enabledState" column="enabled_state" 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"/>
           <result property="appType" column="app_type" jdbcType="VARCHAR"/>
           <result property="dbCode" column="db_code" jdbcType="VARCHAR"/>
           <result property="appName" column="app_name" jdbcType="VARCHAR"/>
           <result property="mdmCode" column="mdm_code" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "MdmModuleSourceEntity_Base_Column_List">
        id
       ,mdm_id 
        ,source_type 
        ,source_name 
        ,trigger_type
        ,source_code
        ,add_api
        ,update_api
        ,delete_api
        ,enabled_state
        ,sorts
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id 
        ,company_id 
     </sql>
 <!-- 查询 采用==查询 -->
    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-MdmModuleSourceEntity-result">
        select
        <include refid="MdmModuleSourceEntity_Base_Column_List" />
        from mdm_module_source where id = #{ id } and sts='Y'
    </select>
 <select id="entity_list_base" resultMap="get-MdmModuleSourceEntity-result" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity">
    select
    <include refid="MdmModuleSourceEntity_Base_Column_List" />
    from mdm_module_source
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="mdmId != null and mdmId != ''"> and mdm_id = #{mdmId} </if>
            <if test="sourceType != null and sourceType != ''"> and source_type = #{sourceType} </if>
            <if test="sourceName != null and sourceName != ''"> and source_name = #{sourceName} </if>
            <if test="triggerType != null and triggerType != ''"> and trigger_type = #{triggerType} </if>
            <if test="sourceCode != null and sourceCode != ''"> and source_code = #{sourceCode} </if>
            <if test="addApi != null and addApi != ''"> and add_api = #{addApi} </if>
            <if test="updateApi != null and updateApi != ''"> and update_api = #{updateApi} </if>
            <if test="deleteApi != null and deleteApi != ''"> and delete_api = #{deleteApi} </if>
            <if test="enabledState != null and enabledState != ''"> and enabled_state = #{enabledState} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </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.mdm.mdmModuleSource.entity.MdmModuleSourceEntity">
        select  count(1)   from mdm_module_source
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="mdmId != null and mdmId != ''"> and mdm_id = #{mdmId} </if>
            <if test="sourceType != null and sourceType != ''"> and source_type = #{sourceType} </if>
            <if test="sourceName != null and sourceName != ''"> and source_name = #{sourceName} </if>
            <if test="triggerType != null and triggerType != ''"> and trigger_type = #{triggerType} </if>
            <if test="sourceCode != null and sourceCode != ''"> and source_code = #{sourceCode} </if>
            <if test="addApi != null and addApi != ''"> and add_api = #{addApi} </if>
            <if test="updateApi != null and updateApi != ''"> and update_api = #{updateApi} </if>
            <if test="deleteApi != null and deleteApi != ''"> and delete_api = #{deleteApi} </if>
            <if test="enabledState != null and enabledState != ''"> and enabled_state = #{enabledState} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id = #{create_user_id} </if>
            <if test="create_time != null"> and create_time = #{create_time} </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id = #{modify_user_id} </if>
            <if test="modify_time != null"> and modify_time = #{modify_time} </if>
            <if test="sts != null and sts != ''"> and sts = #{sts} </if>
            <if test="org_id != null and org_id != ''"> and org_id = #{org_id} </if>
            <if test="companyId != null and companyId != ''"> and company_id = #{companyId} </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>

    <!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-MdmModuleSourceEntity-result" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity">
    select
    <include refid="MdmModuleSourceEntity_Base_Column_List" />
    from mdm_module_source
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id like concat('%',#{id},'%') </if>
            <if test="mdmId != null and mdmId != ''"> and mdm_id like concat('%',#{mdmId},'%') </if>
            <if test="sourceType != null and sourceType != ''"> and source_type like concat('%',#{sourceType},'%') </if>
            <if test="sourceName != null and sourceName != ''"> and source_name like concat('%',#{sourceName},'%') </if>
            <if test="triggerType != null and triggerType != ''"> and trigger_type like concat('%',#{triggerType},'%') </if>
            <if test="sourceCode != null and sourceCode != ''"> and source_code like concat('%',#{sourceCode},'%') </if>
            <if test="addApi != null and addApi != ''"> and add_api like concat('%',#{addApi},'%') </if>
            <if test="updateApi != null and updateApi != ''"> and update_api like concat('%',#{updateApi},'%') </if>
            <if test="deleteApi != null and deleteApi != ''"> and delete_api like concat('%',#{deleteApi},'%') </if>
            <if test="enabledState != null and enabledState != ''"> and enabled_state like concat('%',#{enabledState},'%') </if>
            <if test="sorts != null"> and sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and org_id like concat('%',#{org_id},'%') </if>
            <if test="companyId != null and companyId != ''"> and company_id like concat('%',#{companyId},'%') </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="MdmModuleSourceentity_list_or" resultMap="get-MdmModuleSourceEntity-result" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity">
    select
    <include refid="MdmModuleSourceEntity_Base_Column_List" />
    from mdm_module_source
    <trim prefix="where" prefixOverrides="and"> 
         <if test="id != null and id != ''"> or id = #{id} </if>
             <if test="mdmId != null and mdmId != ''"> or mdm_id = #{mdmId} </if>
             <if test="sourceType != null and sourceType != ''"> or source_type = #{sourceType} </if>
             <if test="sourceName != null and sourceName != ''"> or source_name = #{sourceName} </if>
             <if test="triggerType != null and triggerType != ''"> or trigger_type = #{triggerType} </if>
             <if test="sourceCode != null and sourceCode != ''"> or source_code = #{sourceCode} </if>
             <if test="addApi != null and addApi != ''"> or add_api = #{addApi} </if>
             <if test="updateApi != null and updateApi != ''"> or update_api = #{updateApi} </if>
             <if test="deleteApi != null and deleteApi != ''"> or delete_api = #{deleteApi} </if>
             <if test="enabledState != null and enabledState != ''"> or enabled_state = #{enabledState} </if>
             <if test="sorts != null"> or sorts = #{sorts} </if>
             <if test="create_user_id != null and create_user_id != ''"> or create_user_id = #{create_user_id} </if>
              <if test="create_time != null"> or create_time = #{create_time} </if>
              <if test="modify_user_id != null and modify_user_id != ''"> or modify_user_id = #{modify_user_id} </if>
              <if test="modify_time != null"> or modify_time = #{modify_time} </if>
              <if test="sts != null and sts != ''"> or sts = #{sts} </if>
             <if test="org_id != null and org_id != ''"> or org_id = #{org_id} </if>
              <if test="companyId != null and companyId != ''"> or company_id = #{companyId} </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="queryMdmModuleSourceentityGroupByType" resultMap="get-MdmModuleSourceEntity-result" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity">
         SELECT
            plug.plugin_code,
            plug.plugin_name,
            application.name as app_name,
            source.source_name,
            source.source_code ,
            application.app_type,
            model.mdm_code,
            applicationdatabase.source_code as db_code
        FROM
            mdm_module_source source
            LEFT JOIN sys_application_plugin plug ON plug.id = source.source_code
            LEFT JOIN sys_application application ON source.source_name = application.id
            left join sys_application_database applicationdatabase on applicationdatabase.app_id = source.source_name
        LEFT JOIN	mdm_module	model on source.mdm_id = model.id
        WHERE
            source.source_type = '1'
            AND source.sts = 'Y'
            AND plug.sts = 'Y'
            and application.sts = 'Y'
            AND applicationdatabase.sts = 'Y'
            AND applicationdatabase.db_status = '1'

    </select>

<!--新增所有列-->
<insert id="entity_insert" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity" >
    insert into mdm_module_source(
  <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> id , </if>
            <if test="mdmId != null and mdmId != ''"> mdm_id , </if>
            <if test="sourceType != null and sourceType != ''"> source_type , </if>
            <if test="sourceName != null and sourceName != ''"> source_name , </if>
            <if test="triggerType != null and triggerType != ''"> trigger_type , </if>
            <if test="sourceCode != null and sourceCode != ''"> source_code , </if>
            <if test="addApi != null and addApi != ''"> add_api , </if>
            <if test="updateApi != null and updateApi != ''"> update_api , </if>
            <if test="deleteApi != null and deleteApi != ''"> delete_api , </if>
            <if test="enabledState != null and enabledState != ''"> enabled_state , </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="mdmId != null and mdmId != ''"> #{mdmId} ,</if>
            <if test="sourceType != null and sourceType != ''"> #{sourceType} ,</if>
            <if test="sourceName != null and sourceName != ''"> #{sourceName} ,</if>
            <if test="triggerType != null and triggerType != ''"> #{triggerType} ,</if>
            <if test="sourceCode != null and sourceCode != ''"> #{sourceCode} ,</if>
            <if test="addApi != null and addApi != ''"> #{addApi} ,</if>
            <if test="updateApi != null and updateApi != ''"> #{updateApi} ,</if>
            <if test="deleteApi != null and deleteApi != ''"> #{deleteApi} ,</if>
            <if test="enabledState != null and enabledState != ''"> #{enabledState} ,</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>
<!-- 批量新增 -->
<insert id="entityInsertBatch" >
  insert into mdm_module_source(mdm_id, source_type, source_name, trigger_type, source_code, add_api, update_api, delete_api, enabled_state, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id,  sts)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.mdmId},#{entity.sourceType},#{entity.sourceName},#{entity.triggerType},#{entity.sourceCode},#{entity.addApi},#{entity.updateApi},#{entity.deleteApi},#{entity.enabledState},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" >
    insert into mdm_module_source(mdm_id, source_type, source_name, trigger_type, source_code, add_api, update_api, delete_api, enabled_state, create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.mdmId},#{entity.sourceType},#{entity.sourceName},#{entity.triggerType},#{entity.sourceCode},#{entity.addApi},#{entity.updateApi},#{entity.deleteApi},#{entity.enabledState},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id},#{entity.companyId})
    </foreach>
    on duplicate key update
    mdm_id = values(mdm_id),
    source_type = values(source_type),
    source_name = values(source_name),
    trigger_type = values(trigger_type),
    source_code = values(source_code),
    add_api = values(add_api),
    update_api = values(update_api),
    delete_api = values(delete_api),
    enabled_state = values(enabled_state),
    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),
    company_id = values(company_id)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity" >
update mdm_module_source  set
<trim suffix="" suffixOverrides=",">
  <if test="mdmId != null and mdmId != ''"> mdm_id = #{mdmId},</if>
  <if test="sourceType != null and sourceType != ''"> source_type = #{sourceType},</if>
  <if test="sourceName != null and sourceName != ''"> source_name = #{sourceName},</if>
  <if test="triggerType != null and triggerType != ''"> trigger_type = #{triggerType},</if>
  <if test="sourceCode != null and sourceCode != ''"> source_code = #{sourceCode},</if>
  <if test="addApi != null and addApi != ''"> add_api = #{addApi},</if>
  <if test="updateApi != null and updateApi != ''"> update_api = #{updateApi},</if>
  <if test="deleteApi != null and deleteApi != ''"> delete_api = #{deleteApi},</if>
  <if test="enabledState != null and enabledState != ''"> enabled_state = #{enabledState},</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 id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity" >
update mdm_module_source  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where id = #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity" >
update mdm_module_source  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="mdmId != null and mdmId != ''"> and mdm_id = #{mdmId} </if>
            <if test="sourceType != null and sourceType != ''"> and source_type = #{sourceType} </if>
            <if test="sourceName != null and sourceName != ''"> and source_name = #{sourceName} </if>
            <if test="triggerType != null and triggerType != ''"> and trigger_type = #{triggerType} </if>
            <if test="sourceCode != null and sourceCode != ''"> and source_code = #{sourceCode} </if>
            <if test="addApi != null and addApi != ''"> and add_api = #{addApi} </if>
            <if test="updateApi != null and updateApi != ''"> and update_api = #{updateApi} </if>
            <if test="deleteApi != null and deleteApi != ''"> and delete_api = #{deleteApi} </if>
            <if test="enabledState != null and enabledState != ''"> and enabled_state = #{enabledState} </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>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from mdm_module_source where id = #{id}
</delete>


</mapper>

