package com.yeshi.makemoney.app.controller.admin.goldcorn;
|
|
import com.google.gson.*;
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornTaskTypeInfo;
|
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornTaskTypeInfoService;
|
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornTaskTypeInfoQuery;
|
import com.yeshi.makemoney.app.vo.AcceptAdminData;
|
import com.yeshi.makemoney.app.vo.admin.goldcorn.GoldCornTaskTypeInfoAdminVO;
|
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 javax.annotation.Resource;
|
import java.lang.reflect.Type;
|
import java.util.Date;
|
import java.util.List;
|
|
@Controller
|
@RequestMapping("/admin/api/goldcorn/task")
|
public class GoldCornTaskTypeInfoAdminController {
|
|
@Resource
|
private GoldCornTaskTypeInfoService goldCornTaskTypeInfoService;
|
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String list(GoldCornTaskTypeInfoQuery query, int page, int limit ) {
|
List<GoldCornTaskTypeInfo> list = goldCornTaskTypeInfoService.list(query,page,limit);
|
long count = goldCornTaskTypeInfoService.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 JsonUtil.loadTrueResult(data);
|
|
}
|
|
@ResponseBody
|
@RequestMapping("delete")
|
public String delete(String ids) {
|
Type type = new TypeToken<List<String>>(){}.getType();
|
List<String> idList=new Gson().fromJson(ids,type);
|
goldCornTaskTypeInfoService.delete(idList);
|
return JsonUtil.loadTrueResult("");
|
|
}
|
|
@ResponseBody
|
@RequestMapping("add")
|
|
public String add(GoldCornTaskTypeInfoAdminVO vo, AcceptAdminData acceptAdminData) {
|
try{
|
goldCornTaskTypeInfoService.add(vo.toEntity(acceptAdminData.getSystem()));
|
return JsonUtil.loadTrueResult("");
|
|
}catch(Exception e){
|
return JsonUtil.loadFalseResult(e.getMessage());
|
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping("get")
|
public String get(String id, AcceptAdminData acceptAdminData) {
|
GoldCornTaskTypeInfo entity = goldCornTaskTypeInfoService.get(id);
|
if (entity !=null){
|
return JsonUtil.loadTrueResult(GoldCornTaskTypeInfoAdminVO.create( entity));
|
|
} else {
|
return JsonUtil.loadFalseResult("ID不存在");
|
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("update")
|
|
public String update( GoldCornTaskTypeInfoAdminVO vo ,AcceptAdminData acceptAdminData) {
|
if (vo.getId() == null) {
|
return JsonUtil.loadFalseResult("ID不能为空");
|
}
|
try{
|
goldCornTaskTypeInfoService.update(vo.toEntity(null));
|
}catch(Exception e){
|
return JsonUtil.loadFalseResult(e.getMessage());
|
|
}
|
return JsonUtil.loadTrueResult("");
|
|
}
|
|
|
@ResponseBody
|
@RequestMapping("getTypeList")
|
public String getTypeList() {
|
JSONArray array = new JSONArray();
|
for (GoldCornGetType type : GoldCornGetType.values()) {
|
JSONObject json = new JSONObject();
|
json.put("key", type.name());
|
json.put("value", type.getName());
|
array.add(json);
|
}
|
return JsonUtil.loadTrueResult(array);
|
}
|
|
}
|