<?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.lutao.cloud.oil.mapper.ContractorManageMapper">

  <resultMap id="contractorManageMap" type="com.lutao.entity.ContractorManage">
                  <id property="id" column="id"/>
                        <result property="originId" column="origin_id"/>
                        <result property="facilityName" column="facility_name"/>
                        <result property="contractorUnitName" column="contractor_unit_name"/>
                        <result property="contractorPersonInt" column="contractor_person_int"/>
                        <result property="teamLeaderName" column="team_leader_name"/>
                        <result property="highRiskOperationDesc" column="high_risk_operation_desc"/>
                        <result property="pfId" column="pf_id"/>
                        <result property="appId" column="app_id"/>
                        <result property="platformCode" column="platform_code"/>
                        <result property="platformName" column="platform_name"/>
                        <result property="platformId" column="platform_id"/>
                        <result property="createDate" column="create_date"/>
                        <result property="createBy" column="create_by"/>
                        <result property="updateDate" column="update_date"/>
                        <result property="updateBy" column="update_by"/>
            </resultMap>
    <select id="getContractorStatistic" resultType="com.lutao.cloud.oil.pojo.vo.ContractorStatisticVO">
        SELECT
        cm.contractor_unit_name AS contractorName,
        IFNULL( SUM( cm.contractor_person_int ), 0 ) AS contractorPersonNumber,
        MAX(pi.platform_name) AS areaName,
        MAX(pi.oil_gas_name) AS oilGasName,
        MAX(pi.operating_company) AS operationCompany,
        MAX(ai.app_name) AS appName
        FROM
        contractor_manage cm
        LEFT JOIN platform_info pi ON cm.platform_code = pi.platform_code
        LEFT JOIN app_info ai ON cm.app_id = ai.id
            <where>
                pi.delete_flag = '0'
                <if test="true">
                     and contractor_unit_name != ''
                </if>
                <if test="param.appId != null and param.appId != ''">
                    and cm.app_id = #{param.appId}
                </if>
            </where>
        GROUP BY contractor_unit_name
    </select>
</mapper>
