<?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.yeejoin.amos.supervision.business.dao.mapper.PlanTaskDetailMapper">
	<update id="finishTaskDetail">
		call updatePlanTask(#{planTaskId}, #{pointId}, #{planTaskDetailId} ,#{executorId},#{executorName},#{size},#{planTaskStatus})
	</update>
	
	<select id="findPlanTaskByTaskIdAndPointId" resultType="Map">
		SELECT
			p.name planName, pt.begin_time beginTime, pt.end_time endTime, pp.name pointName, pp.point_no pointNo, ptd.id planTaskDetailId, pt.route_id routeId, pr.name routeName
		FROM
			p_plan_task pt
		LEFT JOIN p_plan p ON pt.plan_id = p.id
		LEFT JOIN p_plan_task_detail ptd on ptd.task_no = pt.id
		left join p_point pp on pp.id = ptd.point_id
		left join p_route pr on pr.id = pt.route_id
		where pp.id = #{pointId}
		and pt.id = #{planTaskId}
	</select>
	<select id="findPlanTaskDetailByTaskId" resultType="com.yeejoin.amos.supervision.dao.entity.PlanTaskDetail">
		select * from p_plan_task_detail where task_no = #{planTaskId}
	</select>

	<update id="updateDanger">
		UPDATE p_plan_task_detail pptd,
		(SELECT SUM(pci.safety_danger_num) saf, SUM(pci.major_danger_num) maj, ptd.id  FROM p_check_input pci
            LEFT JOIN p_check pc ON pc.id = pci.check_id
            LEFT JOIN p_plan_task_detail ptd ON ptd.id = pc.plan_task_detail_id
            WHERE ptd.id = #{planTaskDetailId}) a
		set
            pptd.safety_danger_num = a.saf,
            pptd.major_danger_num = a.maj
		WHERE
		    pptd.id = a.id
	</update>
</mapper>