<?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.report.reportManage.dao.impl.ReportManageDaoImpl">

    <resultMap id="get-ReportManageEntity-result" type="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="reportId" column="report_id" jdbcType="VARCHAR"/>
        <result property="reportName" column="report_name" jdbcType="VARCHAR"/>
        <result property="classifyId" column="classify_id" jdbcType="VARCHAR"/>
        <result property="classifyName" column="classify_name" jdbcType="VARCHAR"/>
        <result property="previewAddress" column="preview_address" jdbcType="VARCHAR"/>
        <result property="state" column="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"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id="ReportManageEntity_Base_Column_List">
        id
       ,report_id 
        ,report_name 
        ,classify_id 
        ,preview_address 
        ,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-ReportManageEntity-result">
        select
        <include refid="ReportManageEntity_Base_Column_List"/>
        from report_manage where sts = 'Y' and id = #{id}
    </select>
    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-ReportManageEntity-result"
            parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        select
        <include refid="ReportManageEntity_Base_Column_List"/>
        from report_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="reportId != null and reportId != ''">and report_id = #{reportId}</if>
            <if test="reportName != null and reportName != ''">and report_name = #{reportName}</if>
            <if test="classifyId != null and classifyId != ''">and classify_id = #{classifyId}</if>
            <if test="previewAddress != null and previewAddress != ''">and preview_address = #{previewAddress}</if>
            <if test="state != null and state != ''">and state = #{state}</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.report.reportManage.entity.ReportManageEntity">
        select count(1) from report_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="reportId != null and reportId != ''">and report_id = #{reportId}</if>
            <if test="reportName != null and reportName != ''">and report_name = #{reportName}</if>
            <if test="classifyId != null and classifyId != ''">and classify_id = #{classifyId}</if>
            <if test="previewAddress != null and previewAddress != ''">and preview_address = #{previewAddress}</if>
            <if test="state != null and state != ''">and state = #{state}</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>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-ReportManageEntity-result"
            parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        select
        <include refid="ReportManageEntity_Base_Column_List"/>
        from report_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and id like concat('%',#{id},'%')</if>
            <if test="reportId != null and reportId != ''">and report_id like concat('%',#{reportId},'%')</if>
            <if test="reportName != null and reportName != ''">and report_name like concat('%',#{reportName},'%')</if>
            <if test="classifyId != null and classifyId != ''">and classify_id like concat('%',#{classifyId},'%')</if>
            <if test="previewAddress != null and previewAddress != ''">and preview_address like
                concat('%',#{previewAddress},'%')
            </if>
            <if test="state != null and state != ''">and state like concat('%',#{state},'%')</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="ReportManageentity_list_or" resultMap="get-ReportManageEntity-result"
            parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        select
        <include refid="ReportManageEntity_Base_Column_List"/>
        from report_manage
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">or id = #{id}</if>
            <if test="reportId != null and reportId != ''">or report_id = #{reportId}</if>
            <if test="reportName != null and reportName != ''">or report_name = #{reportName}</if>
            <if test="classifyId != null and classifyId != ''">or classify_id = #{classifyId}</if>
            <if test="previewAddress != null and previewAddress != ''">or preview_address = #{previewAddress}</if>
            <if test="state != null and state != ''">or state = #{state}</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>

    <!--新增所有列-->
    <insert id="entity_insert" parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        insert into report_manage(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id ,</if>
            <if test="reportId != null and reportId != ''">report_id ,</if>
            <if test="reportName != null and reportName != ''">report_name ,</if>
            <if test="classifyId != null and classifyId != ''">classify_id ,</if>
            <if test="previewAddress != null and previewAddress != ''">preview_address ,</if>
            <if test="state != null and state != ''">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="reportId != null and reportId != ''">#{reportId} ,</if>
            <if test="reportName != null and reportName != ''">#{reportName} ,</if>
            <if test="classifyId != null and classifyId != ''">#{classifyId} ,</if>
            <if test="previewAddress != null and previewAddress != ''">#{previewAddress} ,</if>
            <if test="state != null and state != ''">#{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 != ''">#{companyId} ,</if>
            <if test="sts == null ">'Y',</if>
        </trim>
        )
    </insert>
    <!-- 批量新增 -->
    <insert id="entityInsertBatch">
        insert into report_manage(id, report_id, report_name, classify_id, preview_address, state, sorts,
        create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id, sts)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id},#{entity.reportId},#{entity.reportName},#{entity.classifyId},#{entity.previewAddress},#{entity.state},#{entity.sorts},#{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 report_manage(id, report_id, report_name, classify_id, preview_address, state, sorts,
        create_user_id, create_time, modify_user_id, modify_time, sts, org_id, company_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id},#{entity.reportId},#{entity.reportName},#{entity.classifyId},#{entity.previewAddress},#{entity.state},#{entity.sorts},#{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
        id = values(id),
        report_id = values(report_id),
        report_name = values(report_name),
        classify_id = values(classify_id),
        preview_address = values(preview_address),
        state = values(state),
        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),
        company_id = values(company_id)
    </insert>
    <!--通过主键修改方法-->
    <update id="entity_update" parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        update report_manage set
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id != ''">id = #{id},</if>
            <if test="reportId != null and reportId != ''">report_id = #{reportId},</if>
            <if test="reportName != null and reportName != ''">report_name = #{reportName},</if>
            <if test="classifyId != null and classifyId != ''">classify_id = #{classifyId},</if>
            <if test="previewAddress != null and previewAddress != ''">preview_address = #{previewAddress},</if>
            <if test="state != null and state != ''">state = #{state},</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 = #{id}
    </update>
    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
update report_manage  set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
where  = #{id}
</update>
    <!-- 多条件逻辑删除 -->
    <update id="entity_logicDelete_Multi_Condition"
            parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        update report_manage 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="reportId != null and reportId != ''">and report_id = #{reportId}</if>
            <if test="reportName != null and reportName != ''">and report_name = #{reportName}</if>
            <if test="classifyId != null and classifyId != ''">and classify_id = #{classifyId}</if>
            <if test="previewAddress != null and previewAddress != ''">and preview_address = #{previewAddress}</if>
            <if test="state != null and state != ''">and state = #{state}</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 report_manage where  = #{id}
</delete>
    <!-- 分页查询列表 采用like格式 -->
    <select id="queryByLikeClassify" resultMap="get-ReportManageEntity-result"
            parameterType="com.hzya.frame.report.reportManage.entity.ReportManageEntity">
        select
        a.id
        ,a.report_id
        ,a.report_name
        ,a.classify_id
        ,p.name as classify_name
        ,a.preview_address
        ,a.state
        ,a.sorts
        ,a.create_user_id
        ,a.create_time
        ,a.modify_user_id
        ,a.modify_time
        ,a.sts
        ,a.org_id
        ,a.company_id
        from report_manage a
        LEFT JOIN report_classify p on p.id = a.classify_id and p.sts = 'Y'
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">and a.id like concat('%',#{id},'%')</if>
            <if test="reportId != null and reportId != ''">and a.report_id like concat('%',#{reportId},'%')</if>
            <if test="reportName != null and reportName != ''">and a.report_name like concat('%',#{reportName},'%')</if>
            <if test="classifyId != null and classifyId != ''">and a.classify_id like concat('%',#{classifyId},'%')</if>
            <if test="previewAddress != null and previewAddress != ''">and a.preview_address like
                concat('%',#{previewAddress},'%')
            </if>
            <if test="state != null and state != ''">and a.state like concat('%',#{state},'%')</if>
            <if test="sorts != null">and a.sorts like concat('%',#{sorts},'%')</if>
            <if test="create_user_id != null and create_user_id != ''">and a.create_user_id like
                concat('%',#{create_user_id},'%')
            </if>
            <if test="create_time != null">and a.create_time like concat('%',#{create_time},'%')</if>
            <if test="modify_user_id != null and modify_user_id != ''">and a.modify_user_id like
                concat('%',#{modify_user_id},'%')
            </if>
            <if test="modify_time != null">and a.modify_time like concat('%',#{modify_time},'%')</if>
            <if test="sts != null and sts != ''">and a.sts like concat('%',#{sts},'%')</if>
            <if test="org_id != null and org_id != ''">and a.org_id like concat('%',#{org_id},'%')</if>
            <if test="companyId != null and companyId != ''">and a.company_id like concat('%',#{companyId},'%')</if>
            and a.sts='Y'
        </trim>
        <if test=" sort == null or sort == ''.toString() ">order by a.sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>


    <!-- 分页查询列表 采用like格式 -->
    <select id="queryReportNotUse" resultType="com.hzya.frame.report.reportManage.entity.JimuReportEntity"
            parameterType="com.hzya.frame.report.reportManage.entity.JimuReportEntity">
        SELECT
	a.id as id
	,a.code as code
	,a.name as name
	,a.del_flag as delFlag
FROM
	jimu_report a
	LEFT JOIN report_manage b on b.report_id = a.id and b.sts = 'Y'
	WHERE a.del_flag = '0' and b.id is null  ORDER BY a.create_time desc
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="queryReportEntity" resultType="com.hzya.frame.report.reportManage.entity.JimuReportEntity"
            parameterType="com.hzya.frame.report.reportManage.entity.JimuReportEntity">
        SELECT
	id as id
	,code as code
	,name as name
	,del_flag as delFlag
        FROM
	jimu_report
	WHERE del_flag = '0' and id = #{id}
    </select>
</mapper>

