admin
2021-12-04 c79b1ebed5a42a4cbb2f824232da2a51ff22a9a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.yeshi.location.app.controller.admin.feedback;
 
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.feedback.Advice;
import com.yeshi.location.app.service.inter.feedback.AdviceService;
import com.yeshi.location.app.service.query.feedback.AdviceQuery;
 
@Controller
@RequestMapping("/admin/api/feedback/advice")
public class AdviceAdminController {
 
    @Resource
    private AdviceService adviceService;
 
 
    private String loadPrint(String callback, String root){
          return root;
    }
 
    @ResponseBody
    @RequestMapping("list")
    public String list(AdviceQuery query, int page, int limit, String callback) {
        List<Advice> list = adviceService.list(query,page,limit);
        long count = adviceService.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("get")
    public String get(String id, HttpSession session, String callback) {
        Advice entity = adviceService.get(id);
        if (entity !=null){
            return loadPrint(callback,JsonUtil.loadTrueResult(entity));
        } else {
            return loadPrint(callback,JsonUtil.loadFalseResult("ID不存在"));
        }
    }
 
 
 
 
}