admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.yeshi.fanli.controller.admin.order;
 
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.yeshi.fanli.entity.pdd.PDDOrder;
import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/v1/pddOrder")
public class PDDOrderController {
 
    @Resource
    private PDDOrderService pddOrderService;
 
 
    /**
     * 查询列表 - 新后台
     * 
     * @param callback
     * @param key
     *            查询词 名称
     * @param pageIndex
     * @param out
     */
    @RequestMapping(value = "query")
    public void query(String callback, String key, Integer pageIndex, PrintWriter out) {
        try {
            if (pageIndex == null || pageIndex < 0) {
                pageIndex = 1;
            }
 
            int pageSize = Constant.PAGE_SIZE;
            List<PDDOrder> list = pddOrderService.listQuery((pageIndex-1)*pageSize,pageSize,key);
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未找到相关信息"));
                return;
            }
 
            long count = pddOrderService.countQuery(key);
 
            int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
            PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
 
            Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
                @Override
                public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                    if (value == null) {
                        return new JsonPrimitive("");
                    } else {
                        return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }).create();
 
            JSONObject data = new JSONObject();
            data.put("pe", pe);
            data.put("result_list", gson.toJson(list));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
            e.printStackTrace();
        }
    }
 
}