package cn.com.liandisys.ycjt.ggcx.taxiGps.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import cn.com.liandisys.ycjt.ggcx.taxiGps.vo.TaxiVo;

public class TaxiGpsDaoImpl implements TaxiGpsDaoCustom {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @SuppressWarnings("deprecation")
    public Page<TaxiVo> getTaxiGpsList(Pageable pageable) {

        RowMapper<TaxiVo> mapper = new RowMapper<TaxiVo>() {

            public TaxiVo mapRow(ResultSet rs, int rowNum) throws SQLException {

                TaxiVo vo = new TaxiVo();
                vo.setXm(rs.getString("XM"));
                vo.setDh(rs.getString("DH"));
                vo.setJd(rs.getString("JD"));
                vo.setWd(rs.getString("WD"));
                vo.setSfkx(rs.getString("SFKX"));
                return vo;
            }
        };
        StringBuffer querySql = new StringBuffer();
        querySql.append(" select XM as xm,DH as dh,JD as jd,WD as wd,SFKX as sfkx FROM ");
        querySql.append(
                " (select XM,DH,JD,WD,SFKX,rownum rownum_ from ISN_CXYC_CZCJBXX inner join ISN_CXYC_CZCSSXX on ISN_CXYC_CZCJBXX.SBID=ISN_CXYC_CZCSSXX.SBID  where rownum <="
                        + (pageable.getPageNumber() + 1) * pageable.getPageSize());
        querySql.append(") where rownum_>" + pageable.getPageNumber() * pageable.getPageSize());
        int total = jdbcTemplate.queryForInt(
                "select count(1) from ISN_CXYC_CZCJBXX inner join ISN_CXYC_CZCSSXX on ISN_CXYC_CZCJBXX.SBID=ISN_CXYC_CZCSSXX.SBID");
        List<TaxiVo> list = jdbcTemplate.query(querySql.toString(), mapper);
        Page<TaxiVo> pageList = new PageImpl<TaxiVo>(list, pageable, total);
        return pageList;
    }

    @SuppressWarnings("deprecation")
    public List<TaxiVo> getTaxiGpsListForLayer() {

        RowMapper<TaxiVo> mapper = new RowMapper<TaxiVo>() {

            public TaxiVo mapRow(ResultSet rs, int rowNum) throws SQLException {

                TaxiVo vo = new TaxiVo();
                vo.setXm(rs.getString("XM"));
                vo.setDh(rs.getString("DH"));
                vo.setJd(rs.getString("JD"));
                vo.setWd(rs.getString("WD"));
                vo.setSfkx(rs.getString("SFKX"));
                return vo;
            }
        };
        StringBuffer querySql = new StringBuffer();
        querySql.append(" select XM,DH,JD,WD,SFKX from ISN_CXYC_CZCJBXX inner join ISN_CXYC_CZCSSXX on ISN_CXYC_CZCJBXX.SBID=ISN_CXYC_CZCSSXX.SBID ");
        
        List<TaxiVo> list = jdbcTemplate.query(querySql.toString(), mapper);
        return list;
    }
    
}
