<?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.sckw.mine.mapper.KwBusinessActionTrackMapper">

    <sql id="Base_Column_List">
        id,
        task_order_num,
                mine_order_id,
                content,
                remark,
                `status`,
                create_by,
                update_by,
                create_time,
                update_time,
                del_flag
    </sql>

    <select id="findByMainOrderIdOrderByCreateTime" resultType="com.sckw.mine.entity.KwBusinessActionTrack">
        select <include refid="Base_Column_List" /> from kw_business_action_track where mine_order_id = #{orderId} and del_flag = 0 order by create_time asc
    </select>

    <select id="taskCardPageList" parameterType="com.sckw.mine.entity.req.TaskCardPageListParam" resultType="com.sckw.mine.entity.res.TaskCardPageListRes">
        select
            tk.id,
            tk.task_order_num,
            o.mine_order_no,
            o.cg_company,
            o.delivery_cutoff_time,
            tk.content statusStr,
            o.create_time orderCreateTime,
            tk.create_time,
            tk.create_by,
            wf.work_name,
            ag.name

            from kw_business_action_track tk
        left join kw_business_mine_order o on o.id = tk.mine_order_id
        left join kw_business_mineral_aggregate ag on ag.id = o.mineral_aggregate_id
        left join kw_business_mine m on m.mine_order_id = o.id
        left join kw_business_work_flow wf on wf.id = o.work_flow
        <where>
            and tk.del_flag = 0
            <if test="param.taskOrderNum != '' and param.taskOrderNum != null">
                and tk.task_order_num like concat('%', #{param.taskOrderNum}, '%')
            </if>
            <if test="param.mineOrderNo != '' and param.mineOrderNo != null">
                and o.mine_order_no like concat('%', #{param.mineOrderNo}, '%')
            </if>
            <if test="param.cgCompany != '' and param.cgCompany != null">
                and o.cg_company like concat('%', #{param.cgCompany}, '%')
            </if>
            <if test="param.startTime != '' and param.startTime != null">
                and tk.create_time >= #{param.startTime}
            </if>
            <if test="param.endTime != '' and param.endTime != null">
                and tk.create_time  &lt;= #{param.endTime}
            </if>
        </where>
        order by tk.create_time desc

    </select>
</mapper>