package com.dcs.equipment.service.impl;

import com.dcs.dcs.service.IDcsEquipmentService;
import com.dcs.equipment.domain.vo.DataTwinEquipmentVo;
import com.dcs.equipment.service.DataTwinService;
import com.dcs.equipment.service.ModbusTcpService;
import com.dcs.hnyz.domain.vo.EquipmentParamFormVo;
import com.dcs.hnyz.domain.vo.EquipmentParamFormVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author: wangpx
 * @date: 2025-05-06 09:09
 */
@Service
public class DataTwinServiceImpl implements DataTwinService {
    @Autowired
    private ModbusTcpService modbusTcpService;
    @Autowired
    private IDcsEquipmentService dcsEquipmentService;

    @Override
    public List<DataTwinEquipmentVo> selectDataTwinList() {
        List<EquipmentParamFormVo> equipmentFormVoList = modbusTcpService.getDataTwinEquipmentValues();
        List<DataTwinEquipmentVo> dataTwinEquipmentVoList = new ArrayList<>();
        // S1
        EquipmentParamFormVo S1Temperature = equipmentFormVoList.get(68);
        S1Temperature.setEquipmentName("S1温度");
        extracted(dataTwinEquipmentVoList, S1Temperature);
        EquipmentParamFormVo S1Pressure = equipmentFormVoList.get(81);
        S1Pressure.setEquipmentName("S1压力");
        extracted(dataTwinEquipmentVoList, S1Pressure);
        // S2
        EquipmentParamFormVo S2Temperature = equipmentFormVoList.get(43);
        S2Temperature.setEquipmentName("S2温度");
        extracted(dataTwinEquipmentVoList, S2Temperature);
        EquipmentParamFormVo S2Pressure = equipmentFormVoList.get(45);
        S2Pressure.setEquipmentName("S2压力");
        extracted(dataTwinEquipmentVoList, S2Pressure);
        // M1
        EquipmentParamFormVo M1Pressure = equipmentFormVoList.get(48);
        M1Pressure.setEquipmentName("M1压力");
        extracted(dataTwinEquipmentVoList, M1Pressure);
        // M2
        EquipmentParamFormVo M2Pressure = equipmentFormVoList.get(84);
        M2Pressure.setEquipmentName("M2压力");
        extracted(dataTwinEquipmentVoList, M2Pressure);
        return dataTwinEquipmentVoList;

    }

    private static void extracted(List<DataTwinEquipmentVo> dataTwinEquipmentVoList, EquipmentParamFormVo equipmentFormVo) {
        DataTwinEquipmentVo target = new DataTwinEquipmentVo();
        BeanUtils.copyProperties(equipmentFormVo, target);
        dataTwinEquipmentVoList.add(target);
    }
}

