<?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.boot.module.jcs.api.mapper.PowerTransferCompanyResourcesMapper">



    <select id="getByPowerTransferCompanyResourId" resultType="com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled">
        SELECT
         a.*
        FROM
        jc_alert_called a LEFT JOIN jc_power_transfer b on a.sequence_nbr=b.alert_called_id
        LEFT JOIN jc_power_transfer_company c on c.power_transfer_id=b.sequence_nbr
         LEFT JOIN   jc_power_transfer_company_resources d on  d.power_transfer_company_id=c.sequence_nbr where c.sequence_nbr=  #{id}
        ORDER BY d.rec_date LIMIT 1

    </select>

    <select id="getByAlertCalledIdCarId" resultType="com.yeejoin.amos.boot.module.jcs.api.entity.PowerTransferCompanyResources">
        SELECT d.sequence_nbr,
   d.power_transfer_company_id,
   d.status,
   d.type,
   d.resources_id,
   d.resources_name,
   d.resources_num,
   d.rec_user_name,
   d.rec_user_id,
   d.rec_date,
   d.car_status,
   d.remarks,
   d.is_delete,
	CASE  d.status
	WHEN 'executing' THEN '未完成'
	WHEN 'finished' THEN '已完成'
	ELSE '' END statusName,

	CASE  d.car_status
    WHEN "2" THEN  "出动"
    WHEN "3" THEN  "途中"
    WHEN "4" THEN  "到场"
    WHEN "5" THEN  "出水"
    WHEN "6" THEN  "停水"
    WHEN "7" THEN  "驻防"
    WHEN "8" THEN  "返队"
    WHEN "9" THEN  "训练"
    WHEN "10" THEN  "演练"
    WHEN "11" THEN  "加油"
    WHEN "12" THEN  "试车"
    ELSE '' END carStatusName
        FROM
        jc_alert_called a LEFT JOIN jc_power_transfer b on a.sequence_nbr=b.alert_called_id
        LEFT JOIN jc_power_transfer_company c on c.power_transfer_id=b.sequence_nbr
        LEFT JOIN   jc_power_transfer_company_resources d on  d.power_transfer_company_id=c.sequence_nbr where a.sequence_nbr=  #{alertCalledId}
        and d.resources_id=#{carId}  ORDER BY d.rec_date LIMIT 1


    </select>

    <select id="updateByAlertCalledId" resultType="com.yeejoin.amos.boot.module.jcs.api.entity.PowerTransferCompanyResources">
       	update  jc_power_transfer_company_resources set `status`='finished'   where jc_power_transfer_company_resources.power_transfer_company_id in (
			  select   c.sequence_nbr from   jc_power_transfer_company c
        LEFT JOIN  jc_power_transfer b  on  c.power_transfer_id= b.sequence_nbr  where b.alert_called_id=   #{alertCalledId}

			);

    </select>



</mapper>
