admin
2022-06-17 2d88839407045d9f483cf2ab4aed149a59e22df4
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
package com.yeshi.makemoney.app.controller.client.api;
 
import com.google.gson.Gson;
import com.yeshi.makemoney.app.dto.config.AdSourceConfig;
import com.yeshi.makemoney.app.entity.config.SystemConfigKey;
import com.yeshi.makemoney.app.service.inter.config.SystemConfigService;
import com.yeshi.makemoney.app.vo.AcceptData;
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.StringUtil;
 
import javax.annotation.Resource;
 
/**
 * @author hxh
 * @title: ConfigController
 * @description: 配置信息接口
 * @date 2021/11/16 17:37
 */
@Controller
@RequestMapping("api/v1/config")
public class ConfigController {
 
    @Resource
    private SystemConfigService systemConfigService;
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 建议
     * @date 13:15 2021/12/2
     * @param: acceptData
     **/
    @RequestMapping("getConfig")
    @ResponseBody
    public String getConfig(AcceptData acceptData) {
        com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
 
        SystemConfigKey[] configs = new SystemConfigKey[]{
                SystemConfigKey.kefu,
                SystemConfigKey.course,
                SystemConfigKey.unRegister,
                SystemConfigKey.privacyComplain,
                SystemConfigKey.helpLink,
                SystemConfigKey.disclaimerLink
        };
 
        for (SystemConfigKey config : configs) {
            String value = systemConfigService.getValueCache(acceptData.getSystem(), config);
            data.put(config.name(), value);
        }
        //返回正在上线的版本
        try {
            String value = systemConfigService.getValueCache(acceptData.getSystem(), SystemConfigKey.onLiningVersion);
            JSONObject json = JSONObject.fromObject(value);
            String channel = acceptData.getChannel();
            if (json.optJSONObject(channel.toLowerCase()) == null) {
                channel = "qq";
            }
            json = json.optJSONObject(channel.toLowerCase());
            int onliningVersion = json.optInt("version");
            if (onliningVersion <= acceptData.getVersion()) {
                //正在上线
                data.put("onLining", true);
            } else {
                //尚未上线
                data.put("onLining", false);
            }
        } catch (Exception e) {
            data.put("onLining", false);
        }
 
        SystemConfigKey[] ads = new SystemConfigKey[]{
                SystemConfigKey.splashAd,
                SystemConfigKey.rewardAd,
                SystemConfigKey.exitAppAd
        };
 
        JSONObject adConfig = new JSONObject();
        for (SystemConfigKey ad : ads) {
            String value = systemConfigService.getValueCache(acceptData.getSystem(), ad);
            JSONObject valueJSON = JSONObject.fromObject(value);
 
            String channel = acceptData.getChannel().toLowerCase();
            if (StringUtil.isNullOrEmpty(channel) || valueJSON.optJSONObject(channel) == null) {
                channel = "qq";
            }
 
            valueJSON = valueJSON.optJSONObject(channel.toLowerCase());
            if (valueJSON != null) {
                AdSourceConfig adSourceConfig = new Gson().fromJson(valueJSON.toString(), AdSourceConfig.class);
                if (acceptData.getVersion() <= adSourceConfig.getVersion()) {
                    adConfig.put(ad.name(), new Gson().toJson(adSourceConfig.getTypes()));
                }
            }
        }
        data.put("ad", adConfig);
        return JsonUtil.loadTrueResult(data);
    }
 
 
}