package com.yfd.platform.modules.patroltask.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.modules.patroltask.domain.TaskResult;
import org.apache.ibatis.annotations.Insert;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 巡视任务结果表 Mapper 接口
 * </p>
 *
 *
 * @since 2023-04-08
 */
public interface TaskResultMapper extends BaseMapper<TaskResult> {

    /**********************************
     * 用途说明: 异常点位查询
     * 参数说明 page
     * 参数说明 taskTodoIds
     * 参数说明 taskName
     * 参数说明 deviceName
     * 参数说明 patroldeviceName
     * 参数说明 componentName
     * 参数说明 recognitionType
     * 参数说明 status
     * 参数说明 startDate
     * 参数说明 endDate
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    Page<Map<String, Object>> getAbnormalDeviceList(Page<Map<String, Object>> page, String stationCode,String areaId,
                                                    String bayId, String taskName,
                                                    String deviceName, String patroldeviceName,
                                                    String componentName, String recognitionType, String status,
                                                    String startDate, String endDate);

    Page<Map<String, Object>> getTaskDeviceList(Page<Map<String, Object>> page, String taskTodoId, String deviceName,
                                                String valid);

    /**********************************
     * 用途说明: 查询点位历史曲线
     * 参数说明 deviceId
     * 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     ***********************************/
    List<Map<String, Object>> getHistoricalCurve(String deviceId);

    /**********************************
     * 用途说明: 根据任务执行情况查询任务结果
     * 参数说明 taskTodoId 任务执行情况id
     * 返回值说明: java.util.List<com.yfd.platform.modules.patroltask.domain.TaskResult>
     ***********************************/
    List<Map<String, Object>> getTaskResultById(String taskTodoId,String areaId,String bayId,String mainDeviceId);

    /**********************************
     * 用途说明: 导出异常点位(导出全部)
     * 参数说明 page
     * 参数说明 taskTodoId
     * 参数说明 valid
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    List<Map<String, Object>> getAbnormalDevice(String stationCode, String taskName, String deviceName, String patroldeviceName, String componentName, String recognitionType, String status, String startDate, String endDate);

    /**********************************
     * 用途说明: 根据任务执行情况ID查询点位查询
     * 参数说明 taskTodoId
     * 参数说明 deviceName
     * 参数说明 valid
     * 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     ***********************************/
    List<Map<String, Object>> getTaskDeviceById(String taskTodoId, String deviceName, String valid);


    /**********************************
     * 用途说明: 巡视设备巡检统计
     * 参数说明 page
     * 参数说明 patrolDeviceCode
     * 参数说明 patrolDeviceName
     * 参数说明 type
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang.Object>>
     ***********************************/
    Page<Map<String, Object>> getDeviceInspectionStat(Page<Map<String, Object>> page, String patrolDeviceCode, String patrolDeviceName, String type);

    /**********************************
     * 用途说明: 巡视任务数据统计
     * 参数说明 page
     * 参数说明 type
     * 参数说明 startDate
     * 参数说明 endDate
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    Page<Map<String, Object>> getTaskDataStat(Page<Map<String, Object>> page, String stationCode, String type,
                                              String startDate, String endDate);

    /**********************************
     * 用途说明: 巡视任务数据统计（不分页）
     * 参数说明 page
     * 参数说明 type
     * 参数说明 startDate
     * 参数说明 endDate
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    List<Map<String, Object>> getTaskDataStat(String stationCode, String type, String startDate, String endDate);

    /**********************************
     * 用途说明: 根据任务id查询未审核告警和数量
     * 参数说明 taskTodoIds
     * 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     ***********************************/
    List<Map<String, Object>> getNotCheckAlarmInfo(String taskTodoIds);

    @Insert("<script> " +
            "insert into iis_task_result " +
            "(result_id, task_todo_id, order_num, patroldevice_code, patroldevice_name, patroldevice_channelcode, patroldevice_pos, patroldevice_baseimage, patroldevice_effectiveregion, task_code, task_name," +
            "component_id, component_name, area_id, area_name, bay_id, bay_name, " +
            "main_device_id, main_device_name, device_name, " +
            "device_id, patroldevice_date, material_id, data_type, recognition_type, " +
            "file_type, file_path, value_type, value, unit, " +
            "`desc`, `conf`, `time`, defect_file_path, rectangle, flag, valid," +
            "revise_value,revise_unit,revise_valid,is_alarm,datastatus,lastmodifier,lastmodifydate," +
            "station_code,custom1,custom2,custom3,robot_code,robot_result,phase,voice_analysis_type_list)" +
            "values " +
            "<foreach collection='taskList' index='index' item='item' separator=','> " +
            "(#{item.resultId}, #{item.taskTodoId}, #{item.orderNum}, #{item.patroldeviceCode}, #{item" +
            ".patroldeviceName}, #{item.patroldeviceChannelcode}, #{item.patroldevicePos}, #{item.patroldeviceBaseimage}, #{item.patroldeviceEffectiveregion}, " +
            "#{item.taskCode}, #{item.taskName}, #{item.componentId},#{item.componentName}," +
            "#{item.areaId}, #{item.areaName}, #{item.bayId}, #{item.bayName}, #{item.mainDeviceId}, " +
            "#{item.mainDeviceName}, #{item.deviceName}, #{item.deviceId},#{item.patroldeviceDate}, #{item.materialId}, " +
            "#{item.dataType}, #{item.recognitionType}, #{item.fileType}, #{item.filePath}, " +
            "#{item.valueType},#{item.value},#{item.unit},#{item.desc},#{item.conf}, " +
            "#{item.time}, #{item.defectFilePath},#{item.rectangle}, #{item.flag}," +
            "#{item.valid}, #{item.reviseValue}, #{item.reviseUnit}," +
            "#{item.reviseValid},#{item.isAlarm}, #{item.datastatus}, #{item.lastmodifier}," +
            "#{item.lastmodifydate},#{item.stationCode}, #{item.custom1}, #{item.custom2}, #{item.custom3}, #{item.robotCode}, #{item.robotResult},#{item.phase},#{item.voiceAnalysisTypeList}) " +
            "</foreach> " +
            "ON DUPLICATE KEY UPDATE " +
            "task_todo_id=VALUES(task_todo_id), " +
            "order_num=VALUES(order_num), " +
            "patroldevice_code=VALUES(patroldevice_code), " +
            "patroldevice_name=VALUES(patroldevice_name), " +
            "patroldevice_channelcode=VALUES(patroldevice_channelcode), " +
            "patroldevice_pos=VALUES(patroldevice_pos), " +
            "patroldevice_baseimage=VALUES(patroldevice_baseimage), " +
            "patroldevice_effectiveregion=VALUES(patroldevice_effectiveregion), " +
            "task_code=VALUES(task_code), " +
            "task_name=VALUES(task_name), " +
            "component_id=VALUES(component_id), " +
            "component_name=VALUES(component_name), " +
            "area_id=VALUES(area_id), " +
            "area_name=VALUES(area_name), " +
            "bay_id=VALUES(bay_id), " +
            "bay_name=VALUES(bay_name), " +
            "main_device_id=VALUES(main_device_id), " +
            "main_device_name=VALUES(main_device_name), " +
            "device_name=VALUES(device_name), " +
            "device_id=VALUES(device_id), " +
            "patroldevice_date=VALUES(patroldevice_date), " +
            "material_id=VALUES(material_id), " +
            "data_type=VALUES(data_type), " +
            "recognition_type=VALUES(recognition_type), " +
            "file_type=VALUES(file_type), " +
            "file_path=VALUES(file_path), " +
            "value_type=VALUES(value_type), " +
            "value=VALUES(value), " +
            "unit=VALUES(unit), " +
            "`desc`=VALUES(`desc`), " +
            "`conf`=VALUES(`conf`), " +
            "`time`=VALUES(`time`), " +
            "defect_file_path=VALUES(defect_file_path), " +
            "rectangle=VALUES(rectangle), " +
            "flag=VALUES(flag), " +
            "valid=VALUES(valid)," +
            "revise_value=VALUES(revise_value), " +
            "revise_unit=VALUES(revise_unit), " +
            "revise_valid=VALUES(revise_valid), " +
            "is_alarm=VALUES(is_alarm), " +
            "datastatus=VALUES(datastatus), " +
            "lastmodifier=VALUES(lastmodifier), " +
            "lastmodifydate=VALUES(lastmodifydate), " +
            "station_code=VALUES(station_code), " +
            "custom1=VALUES(custom1), " +
            "custom2=VALUES(custom2), " +
            "custom3=VALUES(custom3), " +
            "robot_code=VALUES(robot_code), " +
            "robot_result=VALUES(robot_result), " +
            "phase=VALUES(phase)," +
            "voice_analysis_type_list=VALUES(voice_analysis_type_list) " +
            "</script>")
    void batchAdd(List<TaskResult> taskList);
    List<Map<String, Object>> getPatrolDeviceInspectionStat();

    List<Map<String, Object>> getNonHomologousAnalysis(String stationCode, String taskName, String mainDeviceId, String componentId, String bayId, String startFormat, String endFormat);

    List<Map<String, Object>> getNonCoherentAnalysis(String taskTodoId, String stationCode, String taskName,
                                                     String mainDeviceName, String componentName,
                                                     String recognitionType, String startDate, String endDate);

    List<TaskResult> getAbnormalResult(String taskTodoId);

    List<Map<String, Object>> getValueByDeviceId(String deviceId);

    Page<Map<String, Object>> getResultByPatroldevice(Page<Map<String, Object>> page, String internationalId,String mainDeviceId, String taskName, String recognitionType, String valid,String isReport,String startDate,String endDate);

    /**********************************
    * 用途说明: 获取到不同相位的最新数据
    * 参数说明 areaId 区域Id
    * 参数说明 bayId 间隔Id
    * 参数说明 mainDeviceId 主设备Id
    * 参数说明 componentId 部件Id
    * 参数说明 recognitionTypeList 识别类型
    * 参数说明 meterType 表计类型
    * 参数说明 resultId 结果Id
    * 参数说明 taskTodoId 待执行Id
    * 参数说明 phase 相位
    * 返回值说明: java.util.List<com.yfd.platform.modules.patroltask.domain.TaskResult>
    ***********************************/
    List<TaskResult> getNonCoherentResult(String areaId,String bayId,String mainDeviceId,String componentId,String recognitionTypeList,String meterType,String resultId,String taskTodoId,String phase);

    /**********************************
     * 用途说明: 获取历史点位
     * 参数说明 startDate 开始时间
     * 参数说明 endDate 结束时间
     * 参数说明 deviceId 点位id
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    Page<Map<String, Object>> getHistoryDevice(Page<Map<String, Object>> page, String startDate, String endDate, String deviceId);

    /**********************************
    * 用途说明: 获取点位历史数据
    * 参数说明 deviceIdList
    * 返回值说明: java.util.List<com.yfd.platform.modules.patroltask.domain.TaskResult>
    ***********************************/
    List<TaskResult> getResultCurveData(List<String> deviceIdList);
}
