<?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="org.jeecg.modules.stm.audit.mapper.AuditTaskMapper">
    <select id="getAllTask" resultType="java.util.Map">
        SELECT DISTINCT B.content,B.des as checkDes,C.checkid,C.citemid,D.item,D.file_id as fileId,
            E.file_tp AS fileTp,E.file_path AS filePath,E.file_name AS fileName,
            D.content as complineContent,G.realname,F.userid,D.cgrp,D.cgrp_path as cgrpPath
        FROM  audit_check_method B
        INNER JOIN audit_item_rel_check C ON B.id = C.checkid
        INNER JOIN audit_compliane_item D ON C.citemid = D.id
        LEFT JOIN doc_files E ON D.file_id  = E.id
        LEFT JOIN audit_task F on B.id=F.checkid
        LEFT JOIN sys_user G on F.userid=G.id
        LEFT JOIN audit_act_rel_others H on H.tid=B.id and tp=5
        <where>
            <if test="userid != null">
                F.userid = #{userid}
            </if>
            <if test="actId != null">
                and H.act_id = #{actId}
            </if>
        </where>
        order by E.id,D.id,B.id
    </select>

    <select id="copyCheckItem2ProjectItem">
        INSERT INTO audit_project_item (tp,checkid,name,des,pid,come_from)
        SELECT tp,checkid,name,des, #{projectid}  AS pid,2 FROM audit_check_method_item
        <where>
            <if test="checkids != null and checkids.size()>0">
                checkid in
                <foreach item="id" collection="checkids" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>

    <select id="copyInnerCheckItem2ProjectItem">
        INSERT INTO audit_project_item (tp,checkid,name,des,pid,come_from)
        SELECT tp,checkid,name,des, #{projectid}  AS pid,3 FROM audit_inner_order_checkmethod_item
        <where>
            <if test="checkids != null and checkids.size()>0">
                checkid in
                <foreach item="id" collection="checkids" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>

</mapper>