admin
2020-02-17 4ecb8ab87dd98bdbce6b4d591051de5d088cf907
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.yeshi.fanli.controller.wxmp.v1;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.IPUtil;
import org.yeshi.utils.JsonUtil;
 
import com.yeshi.fanli.dto.WXMPAcceptData;
import com.yeshi.fanli.entity.bus.homemodule.FloatAD;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.push.DeviceActive;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.homemodule.FloatADService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.service.inter.push.DeviceActiveService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.vo.homemodule.FloatImgDetailVO;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller("WXMPConfigController")
@RequestMapping("/wxmp/api/v1/config")
public class ConfigController {
 
    @Resource
    private SystemClientParamsService systemClientParamsService;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    @Resource
    private DeviceActiveService deviceActiveService;
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private SwiperPictureService swiperPictureService;
 
    @Resource
    private FloatADService floatADService;
 
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
 
    /**
     * 获取系统配置信息
     * 
     * @param acceptData
     * @param code
     * @param out
     */
    @RequestMapping("getSystemClientConfig")
    public void getOpenId(WXMPAcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getAppId());
        if (system == null) {
            out.print("系统不存在");
            return;
        }
        List<SystemClientParams> systemClientParamsList = systemClientParamsService
                .getSystemClientParamsBySystemId(system.getId(), Integer.parseInt(acceptData.getVersion()));
        if (systemClientParamsList == null || systemClientParamsList.size() == 0) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
        }
 
        JSONArray array = new JSONArray();
        for (SystemClientParams params : systemClientParamsList) {
            JSONObject item = new JSONObject();
            item.put("key", params.getKey());
            item.put("value", params.getValue());
            array.add(item);
        }
        out.print(JsonUtil.loadTrueResult(array));
        String ipInfo = IPUtil.getRemotIP(request) + ":" + request.getRemotePort();
        ThreadUtil.run(new Runnable() {
 
            @Override
            public void run() {
                if (!StringUtil.isNullOrEmpty(acceptData.getDevice())) {
                    // 安卓平台添加设备活跃记录
                    DeviceActive da = new DeviceActive();
                    da.setDevice(acceptData.getDevice());
                    da.setPlatform(DeviceActive.PLATFORM_WXMP);
                    da.setVersionCode(Integer.parseInt(acceptData.getVersion()));
                    da.setIpInfo(ipInfo);
                    da.setChannel("wxmp");
                    da.setMac(null);
                    deviceActiveService.addDeviceActive(da);
                }
            }
        });
    }
 
    @RequestMapping(value = "getUserConfig", method = RequestMethod.POST)
    public void getUserConfig(WXMPAcceptData acceptData, PrintWriter out) {
        try {
            // 用户协议链接
            String serviceProtocol = configService.get(ConfigKeyEnum.serviceProtocolLink.getKey());
            // 隐私条款链接
            String privacyProtocol = configService.get(ConfigKeyEnum.privacyProtocolLink.getKey());
            JSONObject data = new JSONObject();
            data.put("serviceProtocolLink", serviceProtocol);
            data.put("privacyProtocolLink", privacyProtocol);
 
            // 我的界面banner
            List<SwiperPicture> banner = swiperPictureService.getByBannerCardAndVersion("my_interface_banner",
                    acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion()));
            if (banner == null)
                banner = new ArrayList<SwiperPicture>();
            data.put("banner", JsonUtil.getApiCommonGson().toJson(banner));
 
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("获取失败"));
            e.printStackTrace();
        }
 
    }
 
    /**
     *  首页配置信息
     * 
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getHomeConfig")
    public void getHomeConfigNew(WXMPAcceptData acceptData, Long uid, String callback, PrintWriter out) {
        if (uid != null && uid == 0L)
            uid = null;
 
        String platform = acceptData.getPlatform();
        String version = acceptData.getVersion();
 
        // 活动弹框
        List<FloatAD> listAD = new ArrayList<FloatAD>();
        List<FloatImgDetailVO> listVO = new ArrayList<FloatImgDetailVO>();
        List<FloatAD> list = floatADService.getValidFloatADCache(FloatAD.POSITION_INDEX, null, platform,
                Integer.parseInt(version));
        if (list != null && !list.isEmpty())
            listAD.addAll(list);
 
        for (int i = 0; i < listAD.size(); i++) {
            FloatAD floatAD = listAD.get(i);
            JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
            if (jumpDetail != null) {
                jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
                if (jumpDetail != null) {
                    jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
                }
            }
            FloatImgDetailVO floatImgVO = new FloatImgDetailVO();
            floatImgVO.setId(floatAD.getId().toString());
            floatImgVO.setImg(floatAD.getPicture());
            floatImgVO.setParams(floatAD.getParams());
            floatImgVO.setJumpDetail(jumpDetail);
            floatImgVO.setShowTime(floatAD.getShowMode());
            floatImgVO.setAccountLogin(floatAD.isJumpNeedLogin());
            if (floatAD.getPlaySound() != null)
                floatImgVO.setPlaySound(floatAD.getPlaySound());// 默认都播放音效
            else
                floatImgVO.setPlaySound(false);
            listVO.add(floatImgVO);
        }
 
        JSONObject data = new JSONObject();
        data.put("listAD", JsonUtil.getApiCommonGson().toJson(listVO));
 
        if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadTrueResult(data));
        else
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
    }
 
}