yujian
2019-03-14 4aadf484e193995c23ee1d5bb1971a497d2f9a0d
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.yeshi.fanli.controller.admin;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import net.sf.json.JSONObject;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
 
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.service.AdminUserService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Controller
@RequestMapping("admin/new/api/v1/config")
public class ConfigAdminController {
    
    @Resource
    private ConfigService configService;
    
    
    /**
     * 查询列表 - 新后台
     * @param callback
     * @param key 查询词  名称
     * @param pageIndex
     * @param out
     */
    @RequestMapping(value = "getNewConfigList")
    public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){
        
        try {
            
            if (pageIndex == null || pageIndex < 0){
                pageIndex = 1;
            }
            
            List<Config> list =  configService.listObjects(key, pageIndex);
            
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
                return;
            }
            
            int pageSize = Constant.PAGE_SIZE;
            
            int count = configService.getCount(key, pageIndex);
            int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
            PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
            
            JSONObject data = new JSONObject();
            data.put("pe", pe);
            data.put("result_list", list);
            
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
            
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
            e.printStackTrace();
        }
    }
    
    /**
     * 参数修改 - 新后台
     * @param callback
     * @param config
     * @param out
     */
    @RequestMapping(value = "saveModify")
    public void saveModify(String callback, Config config, PrintWriter out) {
 
        Long id = config.getId();
        if (id == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
            return;
        }
        
        try {
            Config crentconfig = configService.getConfig(id);
            if (crentconfig == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作数据已不存在"));
                return;
            }
            
            if (StringUtil.isNullOrEmpty(config.getName()) || StringUtil.isNullOrEmpty(config.getValue())) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("说明、有效值不能为空"));
                return;
            }
            
            crentconfig.setName(config.getName());
            crentconfig.setValue(config.getValue());
            
            if (!StringUtil.isNullOrEmpty(config.getBeizhu())) {
                crentconfig.setBeizhu(config.getBeizhu());
            }
            
            configService.update(crentconfig);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
            
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("修改失败"));
            e.printStackTrace();
        }
        
    }
    
}