<?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.nantian.cloud.jly.mapper.EnterpriseHaltMapper">


    <select id="getEnterpriseHalt" resultType="com.nantian.cloud.jly.vo.EnterpriseHaltVo">
        SELECT
        *,o.cmp_name as name
        FROM
        enterprise_halt i
        LEFT JOIN enterprise_info o ON o.enterprise_code = i.epc
        <trim prefix="where" prefixOverrides="and">
            <if test="epc!=null and epc!='' ">
                and i.epc = #{epc}
            </if>
        </trim>
        ORDER BY i.update_time desc
    </select>

    <select id="getHaltCompany" resultType="com.nantian.cloud.jly.entity.EnterpriseHalt">
        select epc, start_time startTime, regain_time regainTime, remark from (
        select epc, start_time, IFNULL(regain_time,(select date_format(NOW(),'%Y-%m-%d'))) regain_time, state,
        IFNULL(regain_time,'待定') remark from `enterprise_halt`
        where state in ('3','4','5') and del_flag = '1'
        <if test="epcStr != null and epcStr !=  ''">
            and #{epcStr} like concat("%",epc,"%")
        </if>
        )tmp where (left(#{statDate},7) between left(start_time,7) and left(regain_time,7))
    </select>
    <select id="getHaltByState" resultType="com.nantian.cloud.jly.vo.EnterpriseHaltVo">
        SELECT i.epc, i.start_time, i.regain_time, i.remark,i.end_time,i.gov_remark,i.state,i.operator,i.operator_time,i.gov_operator,i.update_time
        ,o.cmp_name as name,o.region_code as dept_id
        FROM
        enterprise_halt i
        LEFT JOIN enterprise_info o ON o.enterprise_code = i.epc
        <trim prefix="where" prefixOverrides="and">
            <if test="state!=null and state!='' ">
                and i.state = #{state}
            </if>
        </trim>
        ORDER BY i.update_time desc
    </select>

    <select id="getHaltstateByEpc" parameterType="string" resultType="string">
        select state from enterprise_halt t where epc = #{epc} and gov_operator is not null order by start_time desc limit 1
    </select>



</mapper>
