package com.ks.app.controller.client.api; 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.vipLink }; for (SystemConfigKey config : configs) { String value = systemConfigService.getValueCache(acceptData.getSystem(), config); data.put(config.name(), value); } //TODO 广告K接口配置 SystemConfigKey[] ads = new SystemConfigKey[]{ }; for (SystemConfigKey ad : ads) { String value = systemConfigService.getValueCache(acceptData.getSystem(), ad); JSONObject valueJSON = JSONObject.fromObject(value); String channel = acceptData.getChannel(); if (StringUtil.isNullOrEmpty(channel) || valueJSON.optJSONObject(channel) == null) { channel = "qq"; } valueJSON = valueJSON.optJSONObject(channel.toLowerCase()); if (valueJSON != null) { if (acceptData.getVersion() <= valueJSON.optInt("version")) { String pid = valueJSON.optString("pid"); String type = valueJSON.optString("type"); valueJSON = new JSONObject(); valueJSON.put("pid", pid); valueJSON.put("type", type); } else { valueJSON = null; } } if (valueJSON != null) { data.put(ad.name().replace("ad_", ""), valueJSON.toString()); } } return JsonUtil.loadTrueResult(data); } }