package com.gyee.edge.gateway.config.read;


import com.gyee.edge.gateway.config.point.Point102Mapper;
import com.gyee.edge.gateway.config.point.PointMapper;
import com.gyee.edge.gateway.config.sqlite.Database;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

@Component
public class ReadPoint102SqliteData {
    @Autowired
    private Database db;

    public List<Point102Mapper> readData() {
        List<Point102Mapper> point102MapperList = new ArrayList<>();
        try {
            Connection conn = db.getConnection();
            String sql = "select * from key_table";
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Point102Mapper point102Mapper = new Point102Mapper();
                point102Mapper.setGyfp_base(rs.getFloat("gyfp_base"));
                point102Mapper.setGyfp_addr(rs.getInt("gyfp_addr"));
                point102Mapper.setGyfp_coeff(rs.getInt("gyfp_coeff"));
                point102Mapper.setIec102_addr(rs.getInt("iec102_addr"));
                point102Mapper.setIec102_base(rs.getFloat("iec102_base"));
                point102Mapper.setIec102_coeff(rs.getFloat("iec102_coeff"));
                point102Mapper.setGyfp_valid(rs.getInt("gyfp_valid"));
                point102MapperList.add(point102Mapper);
            }
            db.releaseResource();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point102MapperList;
    }
}
