package com.njcn.device.pq.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjUtil;
import com.njcn.device.pq.pojo.vo.dataClean.CityDataExcel;
import com.njcn.device.pq.pojo.vo.dataClean.LineDataExcel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wr
 * @description
 * @date 2026/2/2 10:13
 */
public class DataLineExcelUtil {

    /**
     * 创建监测点信息表头
     * @param FlyMonitorId
     * @return
     */
    public static List<List<String>> lineHeader(Boolean FlyMonitorId) {
        List<List<String>> header = new ArrayList<>();
        header.add(Collections.singletonList("序号"));
        header.add(Collections.singletonList("监测点名称"));
        header.add(Collections.singletonList("所属部门"));
        header.add(Collections.singletonList("接入电网侧变电站名"));
        header.add(Collections.singletonList("监测点对象名称"));
        header.add(Collections.singletonList("装置编号"));
        header.add(Collections.singletonList("IP地址"));
        header.add(Collections.singletonList("终端厂家"));
        header.add(Collections.singletonList("在线率"));
        header.add(Collections.singletonList("数据完整性"));
        if(FlyMonitorId){
            header.add(Collections.singletonList("国网ID"));
        }
        return header;
    }

    /**
     * 监测点信息表头数据写入
     * @param data
     * @return
     */
    public static List<List<Object>> lineBody(List<LineDataExcel> data) {
        List<List<Object>> result = new ArrayList<>();
        if(CollUtil.isNotEmpty(data)){
            for (LineDataExcel datum : data) {
                ArrayList<Object> row = ListUtil.toList(datum.getLineNum(),
                        datum.getLineName(),
                        datum.getDeptName(),
                        datum.getPowerSubstationName(),
                        datum.getObjName(),
                        datum.getDeviceName(),
                        datum.getIp(),
                        datum.getManufacturer(),
                        datum.getOnlineRate(),
                        datum.getIntegrity());
                if(ObjUtil.isNotNull(datum.getMonitorId())){
                    row.add(datum.getMonitorId());
                }
                result.add(row);
            }
        }
        // 插入一个空行
        result.add(Collections.emptyList());
        return result;
    }

    /**
     * 创建地市信息表头
     * @return
     */
    public static List<List<String>> cityHeader() {
        List<List<String>> header = new ArrayList<>();
        header.add(Collections.singletonList("单位"));
        header.add(Collections.singletonList("监测终端数量"));
        header.add(Collections.singletonList("监测点个数"));
        header.add(Collections.singletonList("在线率（%）"));
        header.add(Collections.singletonList("完整率（%）"));
        header.add(Collections.singletonList("问题监测点"));
        return header;
    }

    public static List<List<Object>> cityBody(List<CityDataExcel> data) {
        List<List<Object>> result = new ArrayList<>();
        if(CollUtil.isNotEmpty(data)){
            for (CityDataExcel datum : data) {
                ArrayList<Object> row = ListUtil.toList(datum.getDeptName(),
                        datum.getDeviceNum(),
                        datum.getLineNum(),
                        datum.getOnlineRate(),
                        datum.getIntegrity(),
                        datum.getAbnormalNum());
            result.add(row);
            }
        }
        // 插入一个空行
        result.add(Collections.emptyList());
        return result;
    }


}
