<?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.jxiop.biz.mapper2.SjglZsjZsbtzMapper">
    <select id="getStationCapactityByStationWerks" resultType="Double">
        select SUM(CAPACITYL) from sjgl_zsj_zsbtz where WERKS = #{WERKS}
    </select>

    <select id="getStationInfoMapByStationWerks" resultType="map">

            SELECT LEFT
            ( SBMC, 4 ) AS NAME,
            GROUP_CONCAT(REPLACE (REPLACE( substring( SBMC, 5 ),'风机系统', '' ) ,"#","" )) as equipNum
        FROM
            `sjgl_zsj_zsbtz`
        WHERE
            MACHGENRE = #{DATAID} and WERKS = #{WERKS}
        GROUP BY
            FSB

</select>

    <select id="getStationInfoMapByStationGFWerks" resultType="map">

        SELECT LEFT
            ( b.SBMC, 4 ) AS NAME,
            GROUP_CONCAT( REPLACE ( SUBSTRING_INDEX( b.SBMC, "#",- 1 ), '光伏阵区系统', '' ) ) AS equipNum
        FROM
            (
            SELECT
            *
            FROM
            sjgl_zsj_zsbtz
            WHERE
            FSB IN ( SELECT DBID FROM `sjgl_zsj_zsbtz` WHERE MACHGENRE = ( SELECT DATAID FROM `tpri_dmp_databook` WHERE DATANAME = #{DATAID} ) AND WERKS = #{WERKS} )
            ) B
        GROUP BY
            B.FSB
    </select>

    <select id="getEquipQrcodeInfo" resultType="com.yeejoin.amos.boot.module.jxiop.api.entity.StationQrCodeStatistics">
        SELECT
            WERKS AS `code`,
            count( QRCODE_COLOR = 'red' OR NULL ) AS redNum,
            count( QRCODE_COLOR = 'yellow' OR NULL ) AS yellowNum,
            count( QRCODE_COLOR = 'green' OR NULL ) AS greenNum,
            'equip' AS type,
            CURRENT_DATE AS recordDate
        FROM
            sjgl_zsj_zsbtz
        GROUP BY
            WERKS
    </select>

    <select id="getTaskQrcodeInfo" resultType="com.yeejoin.amos.boot.module.jxiop.api.entity.StationQrCodeStatistics">
        SELECT
            WERKS AS `code`,
            count( QRCODE_COLOR = 'red' OR NULL ) AS redNum,
            count( QRCODE_COLOR = 'yellow' OR NULL ) AS yellowNum,
            count( QRCODE_COLOR = 'green' OR NULL ) AS greenNum,
            'job' AS type,
            CURRENT_DATE AS recordDate
        FROM
            fdgl_job_main
        GROUP BY
            WERKS
    </select>

    <select id="getEquipYardStatistics" resultType="java.util.Map">
        SELECT
        a.QRCODE_COLOR as qrCodeColor,
        count( 1 ) as value
        FROM
        sjgl_zsj_zsbtz a
        LEFT JOIN privilege_company b on a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                b.COMPANY_CODE  like concat(#{parentCode},'%')
            </if>
        </where>
        GROUP BY
        QRCODE_COLOR
    </select>

    <select id="getJobYardStatistics" resultType="java.util.Map">
        SELECT
        a.QRCODE_COLOR as qrCodeColor,
        count( 1 ) as value
        FROM
        fdgl_job_main a
        LEFT JOIN privilege_company b on a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                b.COMPANY_CODE  like concat(#{parentCode},'%')
            </if>
        </where>
        GROUP BY
        QRCODE_COLOR
    </select>

    <select id="getEquipYardByPage" resultType="java.util.Map">
        SELECT
        ifnull(a.SBMC, '') as objectName ,
        ifnull(a.QRCODE_COLOR, '') AS qrCodeColor,
        ifnull(b.COMPANY_NAME, '') AS stationName
        FROM
        sjgl_zsj_zsbtz a
        LEFT JOIN privilege_company b ON a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                AND b.COMPANY_CODE like concat(#{parentCode},'%')
            </if>
        </where>
        ORDER BY  a.CREATE_TIME DESC
        limit #{current},#{size}
    </select>

    <select id="getEquipYardByPageCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        sjgl_zsj_zsbtz a
        LEFT JOIN privilege_company b ON a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                AND b.COMPANY_CODE like concat(#{parentCode},'%')
            </if>
        </where>
    </select>

    <select id="getJobYardByPage" resultType="java.util.Map">
        SELECT
        ifnull(a.JOB_DESCRIPTION, '') as objectName ,
        ifnull(a.qrcode_color, '') AS qrCodeColor,
        ifnull(b.COMPANY_NAME, '') AS stationName
        FROM
        fdgl_job_main a
        LEFT JOIN privilege_company b ON a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                AND b.COMPANY_CODE like concat(#{parentCode},'%')
            </if>
        </where>
        ORDER BY  a.CREATE_TIME DESC
        limit #{current},#{size}
    </select>

    <select id="getJobYardByPageCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        fdgl_job_main a
        LEFT JOIN privilege_company b ON a.WERKS = b.COMPANY_CODE and b.IS_DELETED = false
        <where>
            <if test="parentCode != null and parentCode != ''">
                AND b.COMPANY_CODE like concat(#{parentCode},'%')
            </if>
        </where>
    </select>
</mapper>
