<?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.baosong.mapper.BaosongTaskRecordMapper">

    <select id="queryTaskRecords" resultType="java.util.Map">
        SELECT
        A.title,
        B.content,
        B.rind,
        B.itemid,
        B.tplcode
        FROM baosong_tpl_item A
        INNER JOIN baosong_task_record B ON A.id = B.itemid
        <where>
            <if test="query.taskid != null">
                AND B.taskid = #{query.taskid}
            </if>
            <if test="query.tplid != null">
                AND B.tplid = #{query.tplid}
            </if>
            <if test="query.itempid != null">
                AND B.itempid = #{query.itempid}
            </if>
        </where>
        ORDER BY B.tplid, B.taskid
    </select>

    <select id="findTaskRecords" resultType="org.jeecg.modules.stm.baosong.entity.BaosongQuery">
        SELECT A.name AS taskName,C.tpl_name AS tplName,C.title as tplItemName,
            C.treepath_name AS treepathName,B.content,
            B.create_by AS createBy,B.create_time AS createTime,B.rind,B.tplcode,
            B.taskid,B.tplid,B.itemid,B.itempid
        FROM baosong_task A
        INNER JOIN baosong_task_record B ON A.id=B.taskid
        INNER JOIN baosong_tpl_item C ON B.itemid=C.id
        <where>
            <if test="query.taskid != null">
                AND B.taskid = #{query.taskid}
            </if>
            <if test="query.tplid != null">
                AND B.tplid = #{query.tplid}
            </if>
            <if test="query.itemid != null">
                AND B.itemid = #{query.itemid}
            </if>
            <if test="query.itempid != null">
                AND B.itempid = #{query.itempid}
            </if>
            <if test="query.itempid != null">
                AND B.itempid = #{query.itempid}
            </if>
            <if test="query.tp != null">
                AND A.tp = #{query.tp}
            </if>
        </where>
    </select>

</mapper>