package com.ssj.dao.util.impl;

import com.ssj.dao.util.UtilQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

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

/**
 * 工具实现类
 *
 * @author Mount Liu
 * @date 2019/5/5
 */
@Repository
public class UtilQueryDaoImpl implements UtilQueryDao {
    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public double getDistanceBySql(double origLng, double origLat, double longitude, double latitude) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        selSQL.append("select func_calcDistance(?,?,?,?) distance from dual");
        queryParams.add(origLng);
        queryParams.add(origLat);
        queryParams.add(longitude);
        queryParams.add(latitude);
        List<Map<String, Object>> list = dao.findMap(selSQL.toString(), queryParams.toArray());
        double distance = (double) list.get(0).get("distance");
        return distance;
    }

}
