package com.yeshi.location.app.controller.admin.user;
|
|
import com.google.gson.*;
|
import com.yeshi.location.app.vo.AcceptAdminData;
|
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.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import com.yeshi.location.app.entity.user.UserInfo;
|
import com.yeshi.location.app.service.inter.user.UserInfoService;
|
import com.yeshi.location.app.service.query.user.UserInfoQuery;
|
import org.yeshi.utils.statistic.BaseStatisticTimeQuery;
|
import org.yeshi.utils.statistic.StatisticNumberResult;
|
import org.yeshi.utils.statistic.StatisticResulterFilterUtil;
|
import org.yeshi.utils.statistic.StatisticTimeSpan;
|
|
@Controller
|
@RequestMapping("admin/api/user")
|
public class UserInfoAdminController {
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
|
private String loadPrint(String callback, String root) {
|
return root;
|
}
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String list(UserInfoQuery query, int page, int limit, String callback) {
|
List<UserInfo> list = userInfoService.list(query, page, limit);
|
//获取详情
|
if (list != null) {
|
List<Long> idList = new ArrayList<>();
|
for (UserInfo user : list) {
|
idList.add(user.getId());
|
}
|
list = userInfoService.getDetailList(idList);
|
}
|
|
long count = userInfoService.count(query);
|
JSONObject data = new JSONObject();
|
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
|
@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("delete")
|
public String delete(String ids, String callback) {
|
Type type = new TypeToken<List<Long>>() {
|
}.getType();
|
List<Long> idList = new Gson().fromJson(ids, type);
|
userInfoService.delete(idList);
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
}
|
|
@ResponseBody
|
@RequestMapping("add")
|
public String add(UserInfo bean, HttpSession session, String callback) {
|
try {
|
userInfoService.add(bean);
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
} catch (Exception e) {
|
return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping("get")
|
public String get(Long id, HttpSession session, String callback) {
|
UserInfo entity = userInfoService.get(id);
|
if (entity != null) {
|
return loadPrint(callback, JsonUtil.loadTrueResult(entity));
|
} else {
|
return loadPrint(callback, JsonUtil.loadFalseResult("ID不存在"));
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("update")
|
public String update(UserInfo bean, HttpSession session, String callback) {
|
if (bean.getId() == null) {
|
return loadPrint(callback, JsonUtil.loadFalseResult("ID不能为空"));
|
}
|
try {
|
userInfoService.update(bean);
|
} catch (Exception e) {
|
return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
}
|
|
|
@ResponseBody
|
@RequestMapping("statisticRegisterUser")
|
public String statisticRegisterUser(AcceptAdminData acceptAdminData, long startTime, long endTime, String span, String callback) {
|
if (endTime < startTime) {
|
return JsonUtil.loadFalseResult("开始时间不能大于结束时间");
|
}
|
|
if (StatisticTimeSpan.valueOf(span) == null) {
|
return JsonUtil.loadFalseResult("时间间隔不存在");
|
}
|
|
BaseStatisticTimeQuery timeQuery = new BaseStatisticTimeQuery();
|
timeQuery.setStartTime(new Date(startTime));
|
timeQuery.setEndTime(new Date(endTime));
|
timeQuery.setTimeSpan(StatisticTimeSpan.valueOf(span));
|
|
List<StatisticNumberResult> list = userInfoService.statisticRegisterUser(acceptAdminData.getSystem(), timeQuery);
|
list = StatisticResulterFilterUtil.filterNumberResult(list, timeQuery);
|
JSONObject data = new JSONObject();
|
data.put("list", new Gson().toJson(list));
|
data.put("count", list.size());
|
return loadPrint(callback, JsonUtil.loadTrueResult(data));
|
}
|
|
|
}
|