package cn.hmsoft.weixin.processor.event;

import java.time.LocalDateTime;

import cn.hmsoft.application.SpringHelper;
import cn.hmsoft.weixin.data.model.WxUserLocation;
import cn.hmsoft.weixin.entity.reply.WeiXinReply;

public class EventLocationProcessor extends EvenBasicProcessor {

	private final static String UPDATE_USER_SQL = "update wx_user set active_time=?,location_latitude=?,location_longitude=?,location_precision=? where open_id=?";

	@Override
	public WeiXinReply handleEvent() throws Exception {
		WxUserLocation loc = new WxUserLocation();
		loc.setLoc_latitude(this.jsonEntity.getLatitude());
		loc.setLoc_longitude(this.jsonEntity.getLongitude());
		loc.setLoc_precision(this.jsonEntity.getPsrecision());
		loc.setLog_time(LocalDateTime.now());
		loc.setOpen_id(this.msg.getFromUserName());
		try {
			SpringHelper.AppGobalDao.insert(loc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			SpringHelper.AppGobalDao.updateBySql(UPDATE_USER_SQL, loc.getLog_time(), loc.getLoc_latitude(), loc.getLoc_longitude(), loc.getLoc_precision(), this.msg.getFromUserName());
		} catch (Exception e) {

		}
		return null;

	}

}
