<?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.plugin.dao.impl.SysApplicationPluginDaoImpl">

    <resultMap id="get-SysApplicationPluginEntity-result" type="com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity" >
       <result property="id" column="id" jdbcType="VARCHAR"/>
           <result property="appId" column="app_id" jdbcType="VARCHAR"/>
           <result property="pluginName" column="plugin_name" jdbcType="VARCHAR"/>
           <result property="pluginCode" column="plugin_code" jdbcType="VARCHAR"/>
           <result property="pluginVersion" column="plugin_version" jdbcType="VARCHAR"/>
           <result property="pluginRemark" column="plugin_remark" jdbcType="VARCHAR"/>
           <result property="releaseDate" column="release_date" jdbcType="TIMESTAMP"/>
           <result property="pluginStatus" column="plugin_status" 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="attachmentId" column="attachment_id" jdbcType="VARCHAR"/>
           <result property="pluginPackageName" column="plugin_package_name" jdbcType="VARCHAR"/>
           <result property="typeId" column="type_id" jdbcType="VARCHAR"/>
            <result property="typeName" column="type_name" jdbcType="VARCHAR"/>
        </resultMap>
    <!-- 查询的字段-->
    <sql id = "SysApplicationPluginEntity_Base_Column_List">
        id
       ,app_id 
        ,plugin_name 
        ,plugin_code 
        ,plugin_version 
        ,plugin_remark 
        ,release_date 
        ,plugin_status 
        ,sorts 
        ,create_user_id 
        ,create_time 
        ,modify_user_id 
        ,modify_time 
        ,sts 
        ,org_id
        ,attachment_id
        ,plugin_package_name
        ,type_id
     </sql>
    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-SysApplicationPluginEntity-result">
        select
        <include refid="SysApplicationPluginEntity_Base_Column_List" />
        from sys_application_plugin where sts = 'Y' and  id = #{id}
    </select>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-SysApplicationPluginEntity-result" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity">
    select
    <include refid="SysApplicationPluginEntity_Base_Column_List" />
    from sys_application_plugin
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="appId != null and appId != ''"> and app_id = #{appId} </if>
            <if test="pluginName != null and pluginName != ''"> and plugin_name = #{pluginName} </if>
            <if test="pluginCode != null and pluginCode != ''"> and plugin_code = #{pluginCode} </if>
            <if test="pluginVersion != null and pluginVersion != ''"> and plugin_version = #{pluginVersion} </if>
            <if test="pluginRemark != null and pluginRemark != ''"> and plugin_remark = #{pluginRemark} </if>
            <if test="releaseDate != null"> and release_date = #{releaseDate} </if>
            <if test="pluginStatus != null and pluginStatus != ''"> and plugin_status = #{pluginStatus} </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="attachmentId != null and attachmentId != ''"> and attachment_id = #{attachmentId} </if>
            <if test="pluginPackageName != null and pluginPackageName != ''"> and plugin_package_name = #{pluginPackageName} </if>
            <if test="typeId != null and typeId != ''"> and type_id = #{typeId} </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.sysnew.application.plugin.entity.SysApplicationPluginEntity">
        select  count(1)   from sys_application_plugin
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and id = #{id} </if>
            <if test="appId != null and appId != ''"> and app_id = #{appId} </if>
            <if test="pluginName != null and pluginName != ''"> and plugin_name = #{pluginName} </if>
            <if test="pluginCode != null and pluginCode != ''"> and plugin_code = #{pluginCode} </if>
            <if test="pluginVersion != null and pluginVersion != ''"> and plugin_version = #{pluginVersion} </if>
            <if test="pluginRemark != null and pluginRemark != ''"> and plugin_remark = #{pluginRemark} </if>
            <if test="releaseDate != null"> and release_date = #{releaseDate} </if>
            <if test="pluginStatus != null and pluginStatus != ''"> and plugin_status = #{pluginStatus} </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="attachmentId != null and attachmentId != ''"> and attachment_id = #{attachmentId} </if>
            <if test="pluginPackageName != null and pluginPackageName != ''"> and plugin_package_name = #{pluginPackageName} </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-SysApplicationPluginEntity-result" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity">
    SELECT
    p.*,
    type.NAME AS type_name
    FROM
    sys_application_plugin p
    LEFT JOIN sys_application_plugin_type type ON p.type_id = type.id
    <trim prefix="where" prefixOverrides="and"> 
        <if test="id != null and id != ''"> and p.id like concat('%',#{id},'%') </if>
            <if test="appId != null and appId != ''"> and p.app_id like concat('%',#{appId},'%') </if>
            <if test="pluginName != null and pluginName != ''"> and p.plugin_name like concat('%',#{pluginName},'%') </if>
            <if test="pluginCode != null and pluginCode != ''"> and p.plugin_code like concat('%',#{pluginCode},'%') </if>
            <if test="pluginVersion != null and pluginVersion != ''"> and p.plugin_version like concat('%',#{pluginVersion},'%') </if>
            <if test="pluginRemark != null and pluginRemark != ''"> and p.plugin_remark like concat('%',#{pluginRemark},'%') </if>
            <if test="releaseDate != null"> and p.release_date like concat('%',#{releaseDate},'%') </if>
            <if test="pluginStatus != null and pluginStatus != ''"> and p.plugin_status like concat('%',#{pluginStatus},'%') </if>
            <if test="sorts != null"> and p.sorts like concat('%',#{sorts},'%') </if>
            <if test="create_user_id != null and create_user_id != ''"> and p.create_user_id like concat('%',#{create_user_id},'%') </if>
            <if test="create_time != null"> and p.create_time like concat('%',#{create_time},'%') </if>
            <if test="modify_user_id != null and modify_user_id != ''"> and p.modify_user_id like concat('%',#{modify_user_id},'%') </if>
            <if test="modify_time != null"> and p.modify_time like concat('%',#{modify_time},'%') </if>
            <if test="sts != null and sts != ''"> and p.sts like concat('%',#{sts},'%') </if>
            <if test="org_id != null and org_id != ''"> and p.org_id like concat('%',#{org_id},'%') </if>
            <if test="attachmentId != null and attachmentId != ''"> and p.attachment_id like concat('%',#{attachmentId},'%') </if>
            <if test="pluginPackageName != null and pluginPackageName != ''"> and p.plugin_package_name like concat('%',#{pluginPackageName},'%') </if>
            <if test="typeId != null and typeId != ''"> and p.type_id like concat('%',#{typeId},'%') </if>
            and p.sts='Y'
    </trim>
    <if test=" sort == null or sort == ''.toString() "> order by p.sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!-- 查询列表 字段采用or格式 -->
<select id="SysApplicationPluginentity_list_or" resultMap="get-SysApplicationPluginEntity-result" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity">
    select
    <include refid="SysApplicationPluginEntity_Base_Column_List" />
    from sys_application_plugin
    <trim prefix="where" prefixOverrides="and"> 
         <if test="id != null and id != ''"> or id = #{id} </if>
             <if test="appId != null and appId != ''"> or app_id = #{appId} </if>
             <if test="pluginName != null and pluginName != ''"> or plugin_name = #{pluginName} </if>
             <if test="pluginCode != null and pluginCode != ''"> or plugin_code = #{pluginCode} </if>
             <if test="pluginVersion != null and pluginVersion != ''"> or plugin_version = #{pluginVersion} </if>
             <if test="pluginRemark != null and pluginRemark != ''"> or plugin_remark = #{pluginRemark} </if>
             <if test="releaseDate != null"> or release_date = #{releaseDate} </if>
             <if test="pluginStatus != null and pluginStatus != ''"> or plugin_status = #{pluginStatus} </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="attachmentId != null and attachmentId != ''"> or attachment_id = #{attachmentId} </if>
             <if test="pluginPackageName != null and pluginPackageName != ''"> or plugin_package_name = #{pluginPackageName} </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.sysnew.application.plugin.entity.SysApplicationPluginEntity" >
    insert into sys_application_plugin(
  <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> id , </if>
            <if test="appId != null and appId != ''"> app_id , </if>
            <if test="pluginName != null and pluginName != ''"> plugin_name , </if>
            <if test="pluginCode != null and pluginCode != ''"> plugin_code , </if>
            <if test="pluginVersion != null and pluginVersion != ''"> plugin_version , </if>
            <if test="pluginRemark != null and pluginRemark != ''"> plugin_remark , </if>
            <if test="releaseDate != null"> release_date , </if>
            <if test="pluginStatus != null and pluginStatus != ''"> plugin_status , </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="attachmentId != null and attachmentId != ''"> attachment_id , </if>
            <if test="pluginPackageName != null and pluginPackageName != ''"> plugin_package_name , </if>
            <if test="typeId != null and typeId != ''"> type_id , </if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="id != null and id != ''"> #{id} ,</if>
            <if test="appId != null and appId != ''"> #{appId} ,</if>
            <if test="pluginName != null and pluginName != ''"> #{pluginName} ,</if>
            <if test="pluginCode != null and pluginCode != ''"> #{pluginCode} ,</if>
            <if test="pluginVersion != null and pluginVersion != ''"> #{pluginVersion} ,</if>
            <if test="pluginRemark != null and pluginRemark != ''"> #{pluginRemark} ,</if>
            <if test="releaseDate != null"> #{releaseDate} ,</if>
            <if test="pluginStatus != null and pluginStatus != ''"> #{pluginStatus} ,</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="attachmentId != null and attachmentId != ''"> #{attachmentId} ,</if>
            <if test="pluginPackageName != null and pluginPackageName != ''"> #{pluginPackageName} ,</if>
            <if test="typeId != null and typeId != ''"> #{typeId} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" >
  insert into sys_application_plugin(app_id, plugin_name, plugin_code, plugin_version, plugin_remark, release_date, plugin_status, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.appId},#{entity.pluginName},#{entity.pluginCode},#{entity.pluginVersion},#{entity.pluginRemark},#{entity.releaseDate},#{entity.pluginStatus},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" >
    insert into sys_application_plugin(app_id, plugin_name, plugin_code, plugin_version, plugin_remark, release_date, plugin_status, sorts, create_user_id, create_time, modify_user_id, modify_time, sts, org_id)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.appId},#{entity.pluginName},#{entity.pluginCode},#{entity.pluginVersion},#{entity.pluginRemark},#{entity.releaseDate},#{entity.pluginStatus},#{entity.sorts},#{entity.create_user_id},#{entity.create_time},#{entity.modify_user_id},#{entity.modify_time},#{entity.sts},#{entity.org_id})
    </foreach>
    on duplicate key update
    app_id = values(app_id),
    plugin_name = values(plugin_name),
    plugin_code = values(plugin_code),
    plugin_version = values(plugin_version),
    plugin_remark = values(plugin_remark),
    release_date = values(release_date),
    plugin_status = values(plugin_status),
    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)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity" >
update sys_application_plugin  set
<trim suffix="" suffixOverrides=",">
  <if test="appId != null and appId != ''"> app_id = #{appId},</if>
  <if test="pluginName != null and pluginName != ''"> plugin_name = #{pluginName},</if>
  <if test="pluginCode != null and pluginCode != ''"> plugin_code = #{pluginCode},</if>
  <if test="pluginVersion != null and pluginVersion != ''"> plugin_version = #{pluginVersion},</if>
  <if test="pluginRemark != null and pluginRemark != ''"> plugin_remark = #{pluginRemark},</if>
  <if test="releaseDate != null"> release_date = #{releaseDate},</if>
  <if test="pluginStatus != null and pluginStatus != ''"> plugin_status = #{pluginStatus},</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="attachmentId != null and attachmentId != ''"> attachment_id = #{attachmentId},</if>
    <if test="pluginPackageName != null and pluginPackageName != ''"> plugin_package_name = #{pluginPackageName},</if>
    <if test="typeId != null and typeId != ''"> type_id = #{typeId},</if>
  </trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity" >
update sys_application_plugin  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.sysnew.application.plugin.entity.SysApplicationPluginEntity" >
update sys_application_plugin  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="appId != null and appId != ''"> and app_id = #{appId} </if>
            <if test="pluginName != null and pluginName != ''"> and plugin_name = #{pluginName} </if>
            <if test="pluginCode != null and pluginCode != ''"> and plugin_code = #{pluginCode} </if>
            <if test="pluginVersion != null and pluginVersion != ''"> and plugin_version = #{pluginVersion} </if>
            <if test="pluginRemark != null and pluginRemark != ''"> and plugin_remark = #{pluginRemark} </if>
            <if test="releaseDate != null"> and release_date = #{releaseDate} </if>
            <if test="pluginStatus != null and pluginStatus != ''"> and plugin_status = #{pluginStatus} </if>
            <if test="sorts != null"> and sorts = #{sorts} </if>
                                                                <if test="sts != null and sts != ''"> and sts = #{sts} </if>
                         and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
    delete from sys_application_plugin where id = #{id}
</delete>



    <!-- 分页查询列表 采用like格式 -->
    <select id="queryListlike" resultMap="get-SysApplicationPluginEntity-result" parameterType = "com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginDto">
        SELECT
        p.*,
        type.NAME AS type_name
        FROM
        sys_application_plugin p
        LEFT JOIN sys_application_plugin_type type ON p.type_id = type.id
        <trim prefix="where" prefixOverrides="and">
            <if test="appId != null and appId != ''"> and p.app_id = #{appId} </if>
            <if test="id != null and id != ''"> and p.id like concat('%',#{id},'%') </if>
            <if test="name != null and name != ''"> and ( p.plugin_name like concat('%',#{name},'%')  or p.plugin_code like concat('%',#{name},'%') or p.plugin_version like concat('%',#{name},'%') )</if>
            <if test="typeId != null and typeId != ''"> and p.type_id like concat('%',#{typeId},'%')</if>
            and p.sts='Y'
        </trim>
        order by p.sorts asc
    </select>

</mapper>

