package com.yeshi.location.app.controller.admin.location; import com.google.gson.*; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; import org.yeshi.utils.TimeUtil; import com.google.gson.reflect.TypeToken; import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.lang.reflect.Type; import java.util.Date; import java.util.List; import com.yeshi.location.app.entity.location.UserLatestLocation; import com.yeshi.location.app.service.inter.location.UserLatestLocationService; import com.yeshi.location.app.service.query.location.UserLatestLocationQuery; @Controller @RequestMapping("/admin/api/user_latest_location") public class UserLatestLocationAdminController { @Resource private UserLatestLocationService userLatestLocationService; private String loadPrint(String callback, String root){ return root; } @ResponseBody @RequestMapping("list") public String list(UserLatestLocationQuery query, int page, int limit, String callback) { List list = userLatestLocationService.list(query,page,limit); long count = userLatestLocationService.count(query); JSONObject data = new JSONObject(); Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer() { @Override public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm")); } }).create(); data.put("list", gson.toJson(list)); data.put("count", count); return loadPrint(callback,JsonUtil.loadTrueResult(data)); } @ResponseBody @RequestMapping("get") public String get(Long id, HttpSession session, String callback) { UserLatestLocation entity = userLatestLocationService.get(id); if (entity !=null){ return loadPrint(callback,JsonUtil.loadTrueResult(entity)); } else { return loadPrint(callback,JsonUtil.loadFalseResult("ID不存在")); } } }