<?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.bonus.sgzb.base.mapper.RepairMapper">


    <select id="getRepairTaskList" resultType="com.bonus.sgzb.base.domain.RepairTask">
        SELECT
            ts.CODE AS repairCode,
            bui.unit_name AS backUnit,
            bpi.pro_name AS backProName,
            ts.create_by AS createBy,
            ts.create_time AS createTime,
            bai.CODE AS backCode,
            CASE
                WHEN rad.radCount = rad2.radCount1 THEN '1' ELSE '0'
                END AS repairStatus
        FROM
            tm_task ts
                LEFT JOIN ( SELECT task_id, COUNT(*) AS radCount,back_id FROM repair_apply_details GROUP BY task_id,back_id ) rad ON ts.task_id = rad.task_id
                LEFT JOIN ( SELECT task_id, COUNT(*) AS radCount1,back_id FROM repair_apply_details WHERE STATUS = '1' GROUP BY task_id,back_id ) rad2 ON ts.task_id = rad2.task_id
                LEFT JOIN back_apply_info bai ON rad.back_id = bai.id
                LEFT JOIN tm_task_agreement tta ON bai.task_id = tta.task_id
                LEFT JOIN bm_agreement_info bai2 ON tta.agreement_id = bai2.agreement_id
                LEFT JOIN bm_unit_info bui ON bai2.unit_id = bui.unit_id
                LEFT JOIN bm_project_info bpi ON bai2.project_id = bpi.pro_id
        where ts.task_type = '1'

    </select>
    <select id="getRepairMaTypeList" resultType="com.bonus.sgzb.base.domain.RepairTaskDetails">

    </select>
</mapper>
