package com.njcn.relational.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.relational.mapper.SgConPlantBNewenergyMapper;
import com.njcn.relational.pojo.po.SgConPlantBNewenergy;
import com.njcn.relational.service.SgConPlantBNewenergyService;
import org.springframework.stereotype.Service;

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

/**
 * @Author: cdf
 * @CreateTime: 2026-07-22
 * @Description:
 */
@Service
public class SgConPlantBNewenergyServiceImpl
        extends ServiceImpl<SgConPlantBNewenergyMapper, SgConPlantBNewenergy>
        implements SgConPlantBNewenergyService {


    @Override
    public boolean batchSyncFromDcloud(JSONArray dataArr) {
        if (CollUtil.isEmpty(dataArr)) {
            return true;
        }
        List<SgConPlantBNewenergy> entityList = new ArrayList<>(dataArr.size());
        for (Object obj : dataArr) {
            JSONObject json = (JSONObject) obj;
            SgConPlantBNewenergy entity = new SgConPlantBNewenergy();
            entity.setId(json.getString("ID"));
            entity.setCompensationVarCap(json.getBigDecimal("COMPENSATION_VAR_CAP"));
            entity.setConnectiveStationId(json.getString("CONNECTIVE_STATION_ID"));
            entity.setEnergyStorageCapacity(json.getBigDecimal("ENERGY_STORAGE_CAPACITY"));
            entity.setEnergyStorageDeviceCount(json.getInteger("ENERGY_STORAGE_DEVICE_COUNT"));
            entity.setInverterCount(json.getInteger("INVERTER_COUNT"));
            entity.setOwner(json.getString("OWNER"));
            entity.setStamp(json.getString("STAMP"));
            entity.setTypeNum(json.getInteger("TYPE_NUM"));
            entity.setWindturbineNum(json.getInteger("WINDTURBINE_NUM"));
            entity.setGroundType(json.getInteger("GROUND_TYPE"));
            entity.setFiltNum(json.getInteger("FILT_NUM"));
            entity.setHourNum(json.getBigDecimal("HOUR_NUM"));
            entity.setWindtowerNum(json.getInteger("WINDTOWER_NUM"));
            entity.setPhotometerNum(json.getInteger("PHOTOMETER_NUM"));
            entity.setWindrange(json.getInteger("WINDRANGE"));
            entity.setInstallLocation(json.getInteger("INSTALL_LOCATION"));
            entityList.add(entity);
        }
        // 批次500条，主键冲突自动更新
        return saveOrUpdateBatch(entityList, 500);
    }

}