Administrator
2018-11-05 507352ecd05c0f9fd7e0a461df5013606f9ebab0
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
package com.yeshi.fanli.controller.client;
 
import java.io.PrintWriter;
import java.util.ArrayList;
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.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.system.CustomerContent;
import com.yeshi.fanli.entity.system.System;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.push.IOSPushService;
import com.yeshi.fanli.util.ThreadUtil;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/v1/systemclient")
public class SystemClientController {
 
    @Resource
    private SystemService systemService;
 
    @Resource
    private SystemClientParamsService systemClientParamsService;
 
    @Resource
    private IOSPushService iosPushService;
 
    @Resource
    private ConfigService configService;
 
    @RequestMapping("getsystemclientparams")
    public void getSystemClientParams(AcceptData acceptData, PrintWriter out) {
        System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
        if (system == null) {
            out.print("系统不存在");
            return;
        }
        List<SystemClientParams> systemClientParamsList = systemClientParamsService
                .getSystemClientParamsBySystemId(system.getId());
        if (systemClientParamsList == null || systemClientParamsList.size() == 0) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
        }
 
        // TODO 需要改成数据库控制,暂时写成这样
 
        List<SystemClientParams> list = new ArrayList<>();
        list.addAll(systemClientParamsList);
        for (SystemClientParams sp : list) {
            if (sp.getKey().equalsIgnoreCase("iosonling") && "ios".equalsIgnoreCase(acceptData.getPlatform())
                    && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
                sp.setValue("1");
                break;
            }
        }
 
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        JSONObject data = new JSONObject();
        data.put("count", list.size());
        data.put("systemClientParamsList", gson.toJson(list));
        out.print(JsonUtil.loadTrueResult(data));
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    if ("ios".equalsIgnoreCase(acceptData.getPlatform()))
                        iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), null,
                                acceptData.getDevice());
                } catch (Exception e) {
                }
            }
        });
 
        return;
    }
 
    /**
     * 
     * 方法说明: 联系客服接口
     * 
     * @author mawurui createTime 2018年4月10日 上午9:02:41
     */
    @RequestMapping("contactCustomerService")
    public void contactCustomerService(AcceptData acceptData, PrintWriter out) {
        String title = "联系客服";
        List<CustomerContent> contentList = systemClientParamsService.contactCustomerService(title);
        JSONObject data = new JSONObject();
        data.put("contentList", JsonUtil.getSimpleGsonWithDate().toJson(contentList));
        out.print(JsonUtil.loadTrueResult(data));
    }
 
}