<?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.chinaweal.aiccs.aiccs.business.mapper.BizProblemReportMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.business.entity.BizProblemReport">
        <id column="problem_id" property="problemId" />
        <result column="bizseq" property="bizseq" />
        <result column="problem_title" property="problemTitle" />
        <result column="problem_desc" property="problemDesc" />
        <result column="report_org" property="reportOrg" />
        <result column="report_org_name" property="reportOrgName" />
        <result column="reporter_id" property="reporterId" />
        <result column="reporter_name" property="reporterName" />
        <result column="create_time" property="createTime" />
        <result column="report_time" property="reportTime" />
        <result column="lauptime" property="lauptime" />
        <result column="urgency" property="urgency" />
        <result column="is_deleted" property="isDeleted" />
        <result column="is_report" property="isReport" />
        <result column="state" property="state" />
        <result column="feedback_result" property="feedbackResult" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        problem_id, bizseq, problem_title, problem_desc, report_org, reporter_id, create_time, report_time, lauptime, urgency, is_deleted,is_report, state, feedback_result
    </sql>
    <sql id="P_Base_Column_List">
        p.problem_id, p.bizseq, p.problem_title, p.problem_desc, p.report_org, p.reporter_id, p.create_time, p.report_time, p.lauptime, p.urgency, p.is_deleted,is_report, p.state, p.feedback_result
    </sql>
    <select id="simplePage" resultMap="BaseResultMap">
        select <include refid="P_Base_Column_List"/>, u.realName as reporter_name, org.orgUnitName as report_org_name
        from aiccs.biz_problem_report p left join cxaicorg.t_users u on p.reporter_id = u.userid left join cxaicorg.t_orgunits org on p.report_org = org.orgUnitID
        <where>
            <if test="params != null">
                <if test="params.problemTitle != null and params.problemTitle != ''">
                    and p.problem_title like concat('%', #{params.problemTitle} ,'%')
                </if>
                <if test="params.problemDesc != null and params.problemDesc != ''">
                    and p.problem_desc like concat('%', #{params.problemDesc} ,'%')
                </if>
                <if test="params.reporterName != null and params.reporterName != ''">
                    and u.realName like concat('%', #{params.reporterName} ,'%')
                </if>
                <if test="params.createDateBegin != null and params.createDateBegin != ''">
                    and p.create_time <![CDATA[>=]]> DATE_FORMAT(#{params.createDateBegin}, '%Y-%m-%d')
                </if>
                <if test="params.createDateEnd != null and params.createDateEnd != ''">
                    and p.create_time <![CDATA[<=]]> DATE_FORMAT(#{params.createDateEnd}, '%Y-%m-%d')
                </if>
                <if test="params.reportTimeBegin != null and params.reportTimeBegin != ''">
                    and p.report_time <![CDATA[>=]]> DATE_FORMAT(#{params.reportTimeEnd}, '%Y-%m-%d')
                </if>
                <if test="params.reportTimeEnd != null and params.reportTimeEnd != ''">
                    and p.report_time <![CDATA[<=]]> DATE_FORMAT(#{params.reportTimeEnd}, '%Y-%m-%d')
                </if>
                <if test="params.urgency != null and params.urgency != ''">
                    and p.urgency = #{params.urgency}
                </if>
                <if test="params.state != null and params.state != ''">
                    and p.state = #{params.state}
                </if>
                <if test="params.isDeleted == null">
                    and p.is_deleted = '0'
                </if>
                <if test="params.isDeleted != null and params.isDeleted != ''">
                    and p.is_deleted = #{params.isDeleted}
                </if>
            </if>
        </where>
        order by create_time desc
    </select>
    <select id="selectProblemById" resultMap="BaseResultMap">
        select <include refid="P_Base_Column_List"/>, u.realName as reporter_name, org.orgUnitName as report_org_name
        from aiccs.biz_problem_report p left join cxaicorg.t_users u on p.reporter_id = u.userid left join cxaicorg.t_orgunits org on p.report_org = org.orgUnitID
        where p.problem_id = #{id}
    </select>

    <select id="selectbizProblemReportList" resultMap="BaseResultMap">
        select <include refid="P_Base_Column_List"/>, u.realName as reporter_name, org.orgUnitName as report_org_name
        from aiccs.biz_problem_report p left join cxaicorg.t_users u on p.reporter_id = u.userid left join cxaicorg.t_orgunits org on p.report_org = org.orgUnitID
    </select>
</mapper>
