package com.yeshi.makemoney.app.controller.admin.goldcorn;
|
|
import com.google.gson.*;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
|
import com.yeshi.makemoney.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.Date;
|
import java.util.List;
|
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord;
|
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService;
|
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery;
|
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/goldcorn/get/record")
|
public class GoldCornGetRecordAdminController {
|
|
@Resource
|
private GoldCornGetRecordService goldCornGetRecordService;
|
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String list(GoldCornGetRecordQuery query, int page, int limit) {
|
List<GoldCornGetRecord> list = goldCornGetRecordService.list(query, page, limit);
|
long count = goldCornGetRecordService.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:ss"));
|
}
|
}).registerTypeAdapter(GoldCornGetType.class, new JsonSerializer<GoldCornGetType>() {
|
|
@Override
|
public JsonElement serialize(GoldCornGetType value, Type type, JsonSerializationContext jsonSerializationContext) {
|
return value == null ? new JsonPrimitive("") : new JsonPrimitive(value.getName());
|
}
|
}).create();
|
|
data.put("list", gson.toJson(list));
|
data.put("count", count);
|
return JsonUtil.loadTrueResult(data);
|
|
}
|
|
|
@ResponseBody
|
@RequestMapping("get")
|
public String get(String id, HttpSession session) {
|
GoldCornGetRecord entity = goldCornGetRecordService.get(id);
|
if (entity != null) {
|
return JsonUtil.loadTrueResult(entity);
|
|
} else {
|
return JsonUtil.loadFalseResult("ID不存在");
|
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("statistic")
|
public String statistic(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 = goldCornGetRecordService.statistic(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 JsonUtil.loadTrueResult(data);
|
}
|
|
|
}
|