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)));
|
}
|
|
}
|