<?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.force.mapper.XrLiccanRecTaskMapper">
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.force.entity.XrLiccanRecTask">
        <result column="taskid" property="taskId"/>
        <result column="recid" property="recId"/>
        <result column="pripid" property="pripId"/>
        <result column="entname" property="entName"/>
        <result column="unisc_id" property="uniscId"/>
        <result column="regno" property="regno"/>
        <result column="reg_org" property="regOrg"/>
        <result column="reg_org_cn" property="regOrgCn"/>
        <result column="status" property="status"/>
        <result column="biz_seq_no" property="bizSeqNo"/>
        <result column="reg_type" property="regType"/>
        <result column="lican_reason" property="liccanReason"/>
        <result column="isoricop" property="isoricop"/>
        <result column="lican_sta" property="liccanSta"/>
        <result column="lican_date" property="liccanDate"/>
        <result column="liccopy_no" property="liccopyNo"/>
        <result column="forceresid" property="forceResId"/>
        <result column="apply_time" property="applyTime"/>
    </resultMap>

    <select id="selectXrLiccanRecTaskTodo" resultType="com.chinaweal.aiccs.aiccs.force.entity.XrLiccanRecTask">
        select distinct
        task.biz_seq_no as bizSeqNo,
        biz.taskid as taskId,
        biz.recid as recId,
        biz.pripid as pripId,
        biz.entname as entName,
        biz.unisc_id as uniscId,
        biz.regno as regno,
        biz.reg_org as regOrg,
        biz.lican_reason as liccanReason,
        biz.status as status,
        biz.apply_time as applyTime,
        task.accept_no as acceptNo,
        task.bus_name as busName,
        task.bus_status as busStatus,
        activity.link_type as linkType,
        activity.link_name as linkName
        from xr_task_list task
        inner join xr_liccan_rec_task biz on task.biz_seq_no = biz.biz_seq_no
        inner join xr_activity activity on task.task_like_id = activity.task_id
        <where>
            activity.link_status = '1'
            and biz.status != '5'
            <if test="param.authList.size > 0">
                and activity.ident in
                <foreach collection="param.authList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.busStatus != null and param.busStatus != ''">
                and task.bus_status = #{param.busStatus}
            </if>
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (biz.unisc_id = #{param.searchUscc} or biz.regno = #{param.searchUscc})
            </if>
            <if test="param.entName != null and param.entName != ''">
                and biz.entname like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.liccanReason != null and param.liccanReason != ''">
                and biz.lican_reason = #{param.liccanReason}
            </if>
            <if test="param.status != null and param.status != ''">
                and biz.status = #{param.status}
            </if>
        </where>
        order by biz.apply_time desc
    </select>

    <select id="selectXrLiccanRecTaskHistory" resultType="com.chinaweal.aiccs.aiccs.force.entity.XrLiccanRecTask">
        select
        biz.taskid as taskId,
        biz.recid as recId,
        biz.biz_seq_no as bizSeqNo,
        biz.pripid as pripId,
        biz.entname as entName,
        biz.unisc_id as uniscId,
        biz.regno as regno,
        biz.reg_org as regOrg,
        biz.reg_org_cn as regorgCn,
        biz.lican_reason as liccanReason,
        biz.lican_date as liccanDate,
        biz.status as status,
        biz.apply_time as applyTime
        from xr_liccan_rec_task biz
        <where>
            1=1
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (biz.unisc_id = #{param.searchUscc} or biz.regno = #{param.searchUscc})
            </if>
            <if test="param.entName != null and param.entName != ''">
                and biz.entname like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.liccanReason != null and param.liccanReason != ''">
                and biz.lican_reason = #{param.liccanReason}
            </if>
            <if test="param.regOrg != null and param.regOrg != ''">
                and biz.reg_org like #{param.regOrg}
            </if>
            <if test="param.status != null and param.status != ''">
                and biz.status = #{param.status}
            </if>
            <if test="param.status == null or param.status == ''">
                and biz.status != '5'
            </if>
        </where>
        order by biz.apply_time desc
    </select>

</mapper>
