package org.nl.acs.opc;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.nl.acs.opc.domain.Opc;
import org.nl.acs.opc.service.dto.OpcDto;
import org.nl.acs.opc.service.dto.OpcServerManageDto;
import org.nl.acs.opc.service.mapper.OpcMapper;
import org.nl.acs.utils.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author 20220102CG\noblelift
 */
@Service
public class opcServerManageServiceImpl implements OpcServerManageService {

    @Autowired
    OpcMapper opcMapper;

    @Override
    public Map<String, OpcServerManageDto> queryAllServerMap() {
        List<OpcServerManageDto> opcServers = this.queryAll();
        Map<String, OpcServerManageDto> result = new HashMap();
        Iterator var3 = opcServers.iterator();

        while (var3.hasNext()) {
            OpcServerManageDto opcServer = (OpcServerManageDto) var3.next();
            result.put(opcServer.getOpc_code(), opcServer);
        }

        return result;
    }

    public List<OpcServerManageDto> queryAll() {
        //return this.opcServerRepository.queryAll(OpcServerManageDto.class);
        //OPC表【acs_opc】
//        JSONArray arr = WQLObject.getWQLObject("acs_opc").query().getResultJSONArray(0);
//
//        return arr.toJavaList(OpcServerManageDto.class);

        LambdaQueryWrapper<Opc> wrapper = new LambdaQueryWrapper<>();
        return ConvertUtil.convertList(opcMapper.selectList(wrapper), OpcServerManageDto.class);
    }
}
