package com.java110.user.dao.impl;

import com.java110.core.base.dao.BaseServiceDao;
import com.java110.user.dao.property.ILocationTrackV1ServiceDao;
import com.java110.po.property.LocationTrackPo;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service("locationTrackV1ServiceDaoImpl")
public class LocationTrackV1ServiceDaoImpl extends BaseServiceDao implements ILocationTrackV1ServiceDao {

    @Override
    public int saveLocationTrack(LocationTrackPo po) {
        return sqlSessionTemplate.insert("LocationTrackV1ServiceDaoImpl.saveLocationTrack", po);
    }

    @Override
    public List<Map> queryLocationTracks(Map params) {
        return sqlSessionTemplate.selectList("LocationTrackV1ServiceDaoImpl.queryLocationTracks", params);
    }

    @Override
    public int queryLocationTracksCount(Map params) {
        List<Map> result = sqlSessionTemplate.selectList("LocationTrackV1ServiceDaoImpl.queryLocationTracksCount", params);
        if (result == null || result.isEmpty()) return 0;
        return Integer.parseInt(result.get(0).get("count").toString());
    }

    @Override
    public Map queryLastLocationByUserId(String userId) {
        List<Map> result = sqlSessionTemplate.selectList("LocationTrackV1ServiceDaoImpl.queryLastLocationByUserId", userId);
        return (result != null && !result.isEmpty()) ? result.get(0) : null;
    }
}
