package cn.cecep.talroad.mapper;

import cn.cecep.talroad.domain.EarlyWarning;
import cn.cecep.talroad.domain.PcLabelFactory;
import cn.cecep.talroad.domain.PcLabelValue;
import cn.cecep.talroad.domain.SEnvGasMonReal;
import cn.cecep.talroad.vo.FactoryLicenseVo;
import cn.cecep.talroad.vo.PcLabelFactoryVo;
import cn.cecep.talroad.vo.WarningEnvGasMonRealVo;
import cn.cecep.talroad.vo.query.PcLabelFactoryQuery;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Date;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Select;

/**
 * 特征标签-与企业关系中间Mapper接口
 *
 * @author szhpt
 * @date 2023-02-02*/
@Mapper
public interface PcLabelFactoryMapper extends BaseMapper<PcLabelFactory>
{
    /**
     * 查询特征标签-与企业关系中间列表
     *
     * @param pcLabelFactory 特征标签-与企业关系中间
     * @return 特征标签-与企业关系中间集合
     */
    List<PcLabelFactory> selectPcLabelFactoryList(PcLabelFactory pcLabelFactory);

    List<PcLabelFactory> selectLabelFactory(@Param("factoryName") String factoryName, @Param("labelIds") Set<String> labelIds);

    void batchUpdateValue(@Param("updateList") List<PcLabelFactory> updateList);

    void batchSave(@Param("addList") List<PcLabelFactory> addList);

    List<WarningEnvGasMonRealVo> selectWarningReal(@Param("startTime") String startTime, @Param("endTime") String endTime);

    List<FactoryLicenseVo> selectPollutantLicenseLabel();

    List<FactoryLicenseVo> selectLicenseTypeLabel();

    List<FactoryLicenseVo> selectPollutantTypeLabel();

    @Select("SELECT  " +
        "f.\"id\" as factory_id, " +
        "CASE WHEN af.factory_id IS NOT NULL THEN '1001' ELSE '1002' END as label_value " +
        "FROM pc_factory f " +
        "LEFT JOIN pc_adsl_factory af ON af.factory_id=f.\"id\" AND af.adsl_code='A002' " +
        "GROUP BY f.\"id\",af.factory_id " +
        "ORDER BY f.\"id\"")
    List<PcLabelFactory> isInstallFbjdLabel();

    @Select("SELECT  " +
        "f.\"id\" as factory_id, " +
        "CASE WHEN o.factory_id IS NOT NULL THEN '1001' ELSE '1002' END as label_value " +
        "FROM pc_factory f " +
        "LEFT JOIN pc_outlet o ON o.factory_id=f.\"id\" AND o.pollutant_type='3' " +
        "GROUP BY f.\"id\",o.factory_id " +
        "ORDER BY f.\"id\"")
    List<PcLabelFactory> isInstallWzzjkdwLabel();

    @Select("SELECT  " +
        "f.\"id\" as factory_id, " +
        "CASE WHEN o.factory_id IS NULL THEN '1001' ELSE '1002' END as label_value " +
        "FROM pc_factory f " +
        "LEFT JOIN ( " +
        "SELECT m.factory_id FROM m_am_problem_fi m " +
        "WHERE m.problem_type LIKE '004%' " +
        "AND m.create_time >= #{startTime} " +
        "GROUP BY m.factory_id " +
        ") o ON o.factory_id=f.\"id\" " +
        "GROUP BY f.\"id\",o.factory_id " +
        "ORDER BY f.\"id\"")
    List<PcLabelFactory> isZlssExceptionInMonthLabel(@Param("startTime") Date startTime);

    @Select("SELECT  " +
        "f.\"id\" as factory_id, " +
        "CASE WHEN o.factory_id IS NULL THEN '1058' ELSE '1059' END as label_value " +
        "FROM pc_factory f " +
        "LEFT JOIN ( " +
        "SELECT m.factory_id FROM m_am_problem_fi m " +
        "LEFT JOIN pc_outlet p ON p.factory_id=m.factory_id AND p.\"id\"=m.station_id " +
        "WHERE m.problem_type = '003004' " +
        "AND p.pollutant_type='3' " +
        "AND m.create_time >= #{startTime} " +
        "GROUP BY m.factory_id " +
        ") o ON o.factory_id=f.\"id\" " +
        "GROUP BY f.\"id\",o.factory_id " +
        "ORDER BY f.\"id\"")
    List<PcLabelFactory> isWzzcbpfExceptionInMonthLabel(@Param("startTime")Date startTime);

    Long selectCountByLableValue(PcLabelValue lableVale);

    List<PcLabelFactoryVo> selectFactoryLabelList(@Param("voPage") Page<PcLabelFactoryVo> voPage, @Param("query") PcLabelFactoryQuery query);
}
