<?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.usky.fire.mapper.DemFireReformMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.DemFireReform">
        <id column="id" property="id" />
        <result column="company_id" property="companyId" />
        <result column="company_code" property="companyCode" />
        <result column="reform_part" property="reformPart" />
        <result column="send_time" property="sendTime" />
        <result column="reform_status" property="reformStatus" />
    </resultMap>

    <select id="fireReformList" resultType="com.usky.fire.service.vo.DemFireReformVO">
        SELECT
        a.reform_code AS reFormId,
        b.company_name AS companyName,
        b.company_type AS companyType,
        c.fire_duty_name AS fireDutyName,
        c.fire_manage_name AS fireManageName,
        b.company_nature AS companyNature,
        DATE_FORMAT(a.send_time,'%Y-%m-%d %H:%i:%s') AS createTime,
        a.reform_status AS reformStatus,
        DATE_FORMAT((CASE a.reform_status WHEN '1' THEN a.send_time WHEN '2' THEN '' WHEN '3' THEN d.reform_time ELSE d.review_time END),'%Y-%m-%d %H:%i:%s') AS statusTime
        FROM
        dem_fire_reform AS a
        LEFT JOIN base_company AS b ON a.company_id = b.company_id
        LEFT JOIN base_company_person AS c ON a.company_id = c.company_id
        LEFT JOIN dem_reform_review AS d ON a.id = d.reform_id
        <where>
            a.reform_status != 0
            <if test="companyName != null and companyName != ''">
                and b.company_name LIKE CONCAT(CONCAT('%',#{companyName}),'%')
            </if>
            <if test="reformId != null and reformId != ''">
                and a.reform_code LIKE CONCAT(CONCAT('%', #{reformId}),'%')
            </if>
            <if test="companyType != null and companyType != ''">
                and b.company_type LIKE CONCAT(CONCAT('%', #{companyType}),'%')
            </if>
        </where>
        <if test="current != null and size != null and size != 0">
            limit #{current},#{size}
        </if>
    </select>

    <select id="mobileScheduleList" resultType="com.usky.fire.service.vo.MobileScheduleVO">
        SELECT
        a.reform_code AS reformId ,
        DATE_FORMAT(a.send_time, '%Y-%m-%d %H:%i:%s') AS sendTime,
        DATE_FORMAT(a.limit_time, '%Y-%m-%d %H:%i:%s') AS limitTime,
        a.reform_status AS reformStatus,
        a.reform_part AS reformPart,
        DATE_FORMAT(d.reform_time, '%Y-%m-%d %H:%i:%s') AS reformTime,
        d.reform_path1 AS reformPath1,
        d.reform_path2 AS reformPath2,
        d.reform_path3 AS reformPath3,
        d.reform_path4 AS reformPath4,
        d.reform_path5 AS reformPath5,
        DATE_FORMAT(d.review_time, '%Y-%m-%d %H:%i:%s') AS reviewTime,
        d.review_remark AS reviewRemark
        FROM
        dem_fire_reform AS a
        LEFT JOIN dem_reform_review AS d ON a.id = d.reform_id
        <where>
            a.reform_status != 0
            <if test="companyId != null and companyId != ''">
                and a.company_id  = #{companyId}
            </if>
            <if test="reformId != null and reformId != ''">
                and a.reform_code = #{reformId}
            </if>
            <if test="reformStatus > 0">
                and a.reform_status = #{reformStatus}
            </if>
        </where>
        <if test="current != null and size != null and size != 0">
            limit #{current},#{size}
        </if>
    </select>

    <select id="reformReview" resultType="com.usky.fire.service.vo.DemReformReviewVO">
        SELECT
            a.reform_code AS reFormId,
            a.reform_part AS reformPart,
            DATE_FORMAT(a.send_time,'%Y-%m-%d %H:%i:%s') AS sendTime,
            DATE_FORMAT(b.reform_time,'%Y-%m-%d %H:%i:%s') AS reformTime,
            b.reform_path1 AS reformPath1,
            b.reform_path2 AS reformPath2,
            b.reform_path3 AS reformPath3,
            b.reform_path4 AS reformPath4,
            b.reform_path5 AS reformPath5,
            DATE_FORMAT(b.review_time,'%Y-%m-%d %H:%i:%s') AS reviewTime
        FROM
        dem_fire_reform AS a
        LEFT JOIN dem_reform_review AS b ON a.id = b.reform_id
        <where>
            <if test="reformId != null and reformId != 0">
                and a.reform_code = #{reformId}
            </if>
        </where>
    </select>

</mapper>
