<?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.revoke.mapper.TsrevtasklistMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.revoke.entity.Tsrevtasklist">
        <id column="TASKLISTID" property="tasklistid" />
        <result column="CASEID" property="caseid" />
        <result column="WORKFLOWID" property="workflowid" />
        <result column="BIZSEQID" property="bizseqid" />
        <result column="SIGNUSERID" property="signuserid" />
        <result column="SENDERORGID" property="senderorgid" />
        <result column="SENDERUSERID" property="senderuserid" />
        <result column="SENDTOORGID" property="sendtoorgid" />
        <result column="ACCEPTNO" property="acceptno" />
        <result column="BUSNAME" property="busname" />
        <result column="SIGNTIME" property="signtime" />
        <result column="BUSTYPE" property="bustype" />
        <result column="BUSSTATUS" property="busstatus" />
        <result column="LINKNAME" property="linkname" />
        <result column="AUDITDEPTTYPE" property="auditdepttype" />
        <result column="ISSIGNON" property="issignon" />
        <result column="SIGNLOGINNAME" property="signloginname" />
        <result column="SENDERTIME" property="sendertime" />
        <result column="SENDERNAME" property="sendername" />
        <result column="ACCEPTGROUPID" property="acceptgroupid" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="CREATEUSERID" property="createUserid" />
        <result column="CREATEUSERNAME" property="createUsername" />
        <result column="CREATETIME" property="createTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        TASKLISTID, CASEID, WORKFLOWID, BIZSEQID, SIGNUSERID, SENDERORGID, SENDERUSERID, SENDTOORGID, ACCEPTNO, BUSNAME, SIGNTIME, BUSTYPE, BUSSTATUS, LINKNAME, AUDITDEPTTYPE, ISSIGNON, SIGNLOGINNAME, SENDERTIME, SENDERNAME, ACCEPTGROUPID, AREA_CODE, LAUPTIME, CREATEUSERID, CREATEUSERNAME, CREATETIME
    </sql>

    <select id="selectByWorkflowID" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tsrevtasklist
        where WORKFLOWID = #{workflowid}
    </select>

    <select id="todoListWithBizstatu" resultMap="BaseResultMap">
        select DISTINCT t.TASKLISTID, t.CASEID, t.WORKFLOWID, t.BIZSEQID, t.SIGNUSERID, t.SENDERORGID, t.SENDERUSERID, t.SENDTOORGID, t.ACCEPTNO, t.BUSNAME, t.SIGNTIME, t.BUSTYPE, t.BUSSTATUS, t.LINKNAME, t.AUDITDEPTTYPE, t.ISSIGNON, t.SIGNLOGINNAME, t.SENDERTIME, t.SENDERNAME, t.ACCEPTGROUPID, t.AREA_CODE, t.LAUPTIME , b.STATUS as bizStatus
        from tsrevtasklist t, tsbizrevlist b
        where t.bizseqid = b.bizseq and (t.busstatus = 0 or t.busstatus = 2)
        <if test="customParamMap != null">
            <if test="customParamMap.bustype != null and customParamMap.bustype != '' ">
                and t.BUSTYPE = #{customParamMap.bustype}
            </if>
            <if test="customParamMap.searchName != null and customParamMap.searchName != '' ">
                and t.BUSNAME like concat('%',#{customParamMap.searchName},'%')
            </if>
            <if test="customParamMap.acceptno != null and customParamMap.acceptno != '' ">
                and t.ACCEPTNO = #{customParamMap.acceptno}
            </if>
            <if test="customParamMap.bizStatus != null and customParamMap.bizStatus != '' ">
                and b.STATUS = #{customParamMap.bizStatus}
            </if>
        </if>
        and t.SIGNUSERID = #{tasklistModel.signuserid}
        and b.ISREMOVE = '0'
        order by t.SENDERTIME desc
    </select>

    <select id="selectBatchRevokeTaskPage" resultType="com.chinaweal.aiccs.aiccs.business.entity.dto.TaskListUnionDto">
        select distinct t.TASKLISTID, t.WORKFLOWID, t.BIZSEQID, t.SIGNUSERID, t.SENDERORGID, t.SENDERUSERID, t.SENDTOORGID, t.ACCEPTNO, t.BUSNAME, t.SIGNTIME, t.BUSTYPE, t.BUSSTATUS, t.LINKNAME, t.AUDITDEPTTYPE, t.ISSIGNON, t.SIGNLOGINNAME, t.SENDERTIME, t.SENDERNAME, t.ACCEPTGROUPID, t.AREA_CODE, t.LAUPTIME , b.STATUS as currentNodeOrBizStatus, null as lastNode, t.CREATETIME, null as ISDEADLINE, null as ISBACK, null as deadlineDate
        from tsrevtasklist t, tsbizrevlist b
        where t.bizseqid = b.bizseq and t.busstatus = 0 and b.ISREMOVE = '0'
        and (t.SIGNUSERID = #{userId} or exists (select 1 from tsrefgroupanduser tg where tg.GROUPID = t.ACCEPTGROUPID and tg.USERID = #{userId}))
    </select>

</mapper>
