package com.ks.app.controller.admin.vip;
|
|
import com.google.gson.*;
|
import com.ks.app.entity.vip.VIPPriceType;
|
import com.ks.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.ks.app.entity.vip.VIPPrice;
|
import com.ks.app.service.inter.vip.VIPPriceService;
|
import com.ks.app.service.query.vip.VIPPriceQuery;
|
|
@Controller
|
@RequestMapping("admin/api/vip/vipprice")
|
public class VIPPriceAdminController {
|
|
@Resource
|
private VIPPriceService vIPPriceService;
|
|
|
private String loadPrint(String callback, String root) {
|
return root;
|
}
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String list(VIPPriceQuery query, int page, int limit, String callback) {
|
List<VIPPrice> list = vIPPriceService.list(query, page, limit);
|
long count = vIPPriceService.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"));
|
}
|
}).registerTypeAdapter(VIPPriceType.class, new JsonSerializer<VIPPriceType>() {
|
|
@Override
|
public JsonElement serialize(VIPPriceType date, Type type, JsonSerializationContext jsonSerializationContext) {
|
return date == null ? new JsonPrimitive("") : new JsonPrimitive(date.getName());
|
}
|
}).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<String>>() {
|
}.getType();
|
List<String> idList = new Gson().fromJson(ids, type);
|
vIPPriceService.delete(idList);
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
}
|
|
@ResponseBody
|
@RequestMapping("add")
|
public String add(AcceptAdminData acceptData, VIPPrice bean, HttpSession session, String callback) {
|
try {
|
bean.setSystem(acceptData.getSystem());
|
vIPPriceService.add(bean);
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
} catch (Exception e) {
|
return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping("get")
|
public String get(String id, HttpSession session, String callback) {
|
VIPPrice entity = vIPPriceService.get(id);
|
if (entity != null) {
|
return loadPrint(callback, JsonUtil.loadTrueResult(entity));
|
} else {
|
return loadPrint(callback, JsonUtil.loadFalseResult("ID不存在"));
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("update")
|
public String update(VIPPrice bean, HttpSession session, String callback) {
|
if (bean.getId() == null) {
|
return loadPrint(callback, JsonUtil.loadFalseResult("ID不能为空"));
|
}
|
try {
|
vIPPriceService.update(bean);
|
} catch (Exception e) {
|
return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
return loadPrint(callback, JsonUtil.loadTrueResult(""));
|
}
|
|
|
}
|