Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
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;
 
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.entity.bus.user.HongBaoManage;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.JsonUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
 
@Controller
@RequestMapping("admin/new/api/v1/haobao")
public class HongBaoManageAdminController {
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private HongBaoService hongBaoService;
 
    @RequestMapping(value = "updateHongBaoManage", method = RequestMethod.POST)
    public void updateHongBaoManage(String map, PrintWriter out) {
        List<HongBaoManage> hongBaoManageList = hongBaoManageService.getHongBaoManage();
        Map<String, String> data = JsonUtil.parseData(map);
        for (HongBaoManage hbm : hongBaoManageList) {
            String key = hbm.getKey();
            boolean b = data.containsKey(key);
            if (b) {
                String value = data.get(key);
                hbm.setValue(value);
            }
        }
        hongBaoManageService.update(hongBaoManageList);
        out.print(JsonUtil.loadTrueResult("修改成功"));
    }
 
    @RequestMapping(value = "getHongBaoManage", method = RequestMethod.POST)
    public void getHongBaoManage(PrintWriter out) {
        List<HongBaoManage> hongBaoManageList = hongBaoManageService.getHongBaoManage();
        JSONObject data = new JSONObject();
        data.put("hongBaoManageList", hongBaoManageList);
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    @RequestMapping(value = "getHongBaoList", method = RequestMethod.POST)
    public void getHongBaoList(int pageIndex, String state, PrintWriter out) {
 
        List<HongBao> list = hongBaoService.getHongBaoList(pageIndex - 1, state);
 
        
        JsonConfig jsonConfig = new JsonConfig(); // 建立配置文件
        jsonConfig.setIgnoreDefaultExcludes(false); // 设置默认忽略
        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        JSONArray hongBaoList = JSONArray.fromObject(list, jsonConfig);
 
        int count = hongBaoService.getCount(state);
        int totalPage = count % Constant.PAGE_SIZE == 0 ? count / Constant.PAGE_SIZE : count / Constant.PAGE_SIZE + 1;
        PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count, totalPage);
        Map<String, String> map = new HashMap<String, String>();
        map.put("state", state);
        pe.setParams(map);
        JSONObject data = new JSONObject();
        data.put("pe", pe);
        data.put("hongBaoList", hongBaoList);
        out.print(JsonUtil.loadTrueResult(data));
        return;
    }
 
}