package com.ks.app.controller.client.api; import com.google.gson.Gson; import com.ks.app.dto.config.AdSourceConfig; import com.ks.app.entity.config.SystemConfigKey; import com.ks.app.service.inter.config.SystemConfigService; import com.ks.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); } 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); } }