From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java | 517 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 400 insertions(+), 117 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java index f48680f..125017b 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java @@ -1,117 +1,400 @@ -package com.yeshi.fanli.controller.admin; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import net.sf.json.JSONObject; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.yeshi.utils.JsonUtil; - -import com.yeshi.fanli.entity.common.Config; -import com.yeshi.fanli.service.AdminUserService; -import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.tag.PageEntity; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.StringUtil; - -@Controller -@RequestMapping("admin/new/api/v1/config") -public class ConfigAdminController { - - @Resource - private ConfigService configService; - - - /** - * 鏌ヨ鍒楄〃 - 鏂板悗鍙� - * @param callback - * @param key 鏌ヨ璇� 鍚嶇О - * @param pageIndex - * @param out - */ - @RequestMapping(value = "getNewConfigList") - public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){ - - try { - - if (pageIndex == null || pageIndex < 0){ - pageIndex = 1; - } - - List<Config> list = configService.listObjects(key, pageIndex); - - if (list == null || list.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏇村鏁版嵁")); - return; - } - - int pageSize = Constant.PAGE_SIZE; - - int count = configService.getCount(key, pageIndex); - int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); - PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); - - JSONObject data = new JSONObject(); - data.put("pe", pe); - data.put("result_list", list); - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触")); - e.printStackTrace(); - } - } - - /** - * 鍙傛暟淇敼 - 鏂板悗鍙� - * @param callback - * @param config - * @param out - */ - @RequestMapping(value = "saveModify") - public void saveModify(String callback, Config config, PrintWriter out) { - - Long id = config.getId(); - if (id == null) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID涓嶈兘涓虹┖")); - return; - } - - try { - Config crentconfig = configService.getConfig(id); - if (crentconfig == null) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔鏁版嵁宸蹭笉瀛樺湪")); - return; - } - - if (StringUtil.isNullOrEmpty(config.getName()) || StringUtil.isNullOrEmpty(config.getValue())) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇存槑銆佹湁鏁堝�间笉鑳戒负绌�")); - return; - } - - crentconfig.setName(config.getName()); - crentconfig.setValue(config.getValue()); - - if (!StringUtil.isNullOrEmpty(config.getBeizhu())) { - crentconfig.setBeizhu(config.getBeizhu()); - } - - configService.update(crentconfig); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇敼鎴愬姛")); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇敼澶辫触")); - e.printStackTrace(); - } - - } - -} +package com.yeshi.fanli.controller.admin; + +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.accept.AdminAcceptData; +import com.yeshi.fanli.util.annotation.RequestNoLogin; +import com.yeshi.fanli.util.taobao.TaoBaoUtil; +import net.sf.json.JSONArray; +import org.springframework.cache.ehcache.EhCacheCacheManager; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.tencentcloud.COSManager; + +import com.yeshi.fanli.dto.system.ListConfig; +import com.yeshi.fanli.entity.AppVersionInfo; +import com.yeshi.fanli.entity.common.Config; +import com.yeshi.fanli.entity.system.ConfigCategory; +import com.yeshi.fanli.entity.system.ConfigCategory.ConfigCategoryEnum; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.fanli.service.inter.config.AppVersionService; +import com.yeshi.fanli.service.inter.config.ConfigCategoryService; +import com.yeshi.fanli.service.inter.config.ConfigService; +import com.yeshi.common.entity.PageEntity; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.FilePathEnum; +import com.yeshi.fanli.util.StringUtil; + +import net.sf.json.JSONObject; + +@Controller +@RequestMapping("admin/new/api/v1/config") +public class ConfigAdminController { + + @Resource + private ConfigService configService; + + @Resource + private AppVersionService appVersionService; + + @Resource + private EhCacheCacheManager ehCacheCacheManager; + + @Resource + private ConfigCategoryService configCategoryService; + + + /** + * 鏌ヨ鍒楄〃 - 鏂板悗鍙� + * + * @param callback + * @param key 鏌ヨ璇� 鍚嶇О + * @param pageIndex + * @param out + */ + @RequestMapping(value = "getNewConfigList") + public void getNewConfigList(AdminAcceptData acceptData, String callback, String key, Integer pageIndex, PrintWriter out) { + + try { + + if (pageIndex == null || pageIndex < 0) { + pageIndex = 1; + } + + List<AppVersionInfo> versionList = appVersionService.getAppVersionInfoListByPlatform("android", acceptData.getSystem()); + Map<Integer, String> androidMapName = new HashMap<>(); + for (AppVersionInfo version : versionList) + androidMapName.put(version.getVersionCode(), version.getVersion()); + + versionList = appVersionService.getAppVersionInfoListByPlatform("ios", acceptData.getSystem()); + Map<Integer, String> iosMapName = new HashMap<>(); + for (AppVersionInfo version : versionList) + iosMapName.put(version.getVersionCode(), version.getVersion()); + + List<Config> list = configService.listObjects(key, pageIndex, acceptData.getSystem()); + + for (Config config : list) { + config.setMinAndroidVersion(androidMapName.get(config.getMinAndroidVersionCode())); + config.setMinIosVersion(iosMapName.get(config.getMinIosVersionCode())); + } + + if (list == null || list.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏇村鏁版嵁")); + return; + } + + int pageSize = Constant.PAGE_SIZE; + + int count = configService.getCount(key, acceptData.getSystem()); + int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); + PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); + + JSONObject data = new JSONObject(); + data.put("pe", pe); + data.put("result_list", list); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触")); + e.printStackTrace(); + } + } + + /** + * 鍙傛暟淇敼 - 鏂板悗鍙� + * + * @param callback + * @param config + * @param out + */ + @RequestMapping(value = "saveModify") + public void saveModify(AdminAcceptData acceptData, String callback, Config config, PrintWriter out) { + + Long id = config.getId(); + if (id == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID涓嶈兘涓虹┖")); + return; + } + + try { + Config crentconfig = configService.getConfig(id); + if (crentconfig == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔鏁版嵁宸蹭笉瀛樺湪")); + return; + } + + if (StringUtil.isNullOrEmpty(config.getName()) || StringUtil.isNullOrEmpty(config.getValue())) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇存槑銆佹湁鏁堝�间笉鑳戒负绌�")); + return; + } + + crentconfig.setName(config.getName()); + crentconfig.setValue(config.getValue()); + + if (!StringUtil.isNullOrEmpty(config.getBeizhu())) { + crentconfig.setBeizhu(config.getBeizhu()); + } + + configService.update(crentconfig); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇敼鎴愬姛")); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇敼澶辫触")); + e.printStackTrace(); + } + } + + + @RequestMapping(value = "getArticleHot") + public void getArticleHot(AdminAcceptData acceptData, PrintWriter out) { + JSONObject data = new JSONObject(); + data.put("list", configService.getValue(ConfigKeyEnum.articleHotWords.getKey(), acceptData.getSystem())); + out.print(JsonUtil.loadTrueResult(data)); + } + + + /** + * 鐗堟湰鍙蜂俊鎭� + * + * @param callback + * @param out + */ + @RequestMapping(value = "getVersionList") + public void getVersionList(AdminAcceptData acceptData, String callback, PrintWriter out) { + + try { + AppVersionInfo appVersionInfo = new AppVersionInfo(); + appVersionInfo.setVersion("鍏ㄦ帹"); + + // IOS鐗堟湰 + List<AppVersionInfo> list1 = appVersionService.getAppVersionInfoListByPlatform(AppVersionInfo.PLATFORM_IOS, acceptData.getSystem()); + if (list1 == null) { + list1 = new ArrayList<AppVersionInfo>(); + } + List<AppVersionInfo> listIOS = new ArrayList<AppVersionInfo>(); + listIOS.add(appVersionInfo); + listIOS.addAll(list1); + + // 瀹夊崜鐗堟湰 + List<AppVersionInfo> list2 = appVersionService + .getAppVersionInfoListByPlatform(AppVersionInfo.PLATFORM_ANDROID, acceptData.getSystem()); + if (list2 == null) { + list2 = new ArrayList<AppVersionInfo>(); + } + List<AppVersionInfo> listAndroid = new ArrayList<AppVersionInfo>(); + listAndroid.add(appVersionInfo); + listAndroid.addAll(list2); + //灏忕▼搴忕増鏈� + List<AppVersionInfo> list3 = appVersionService + .getAppVersionInfoListByPlatform(AppVersionInfo.PLATFORM_XCX, acceptData.getSystem()); + if (list3 == null) { + list3 = new ArrayList<AppVersionInfo>(); + } + List<AppVersionInfo> listWxmp = new ArrayList<AppVersionInfo>(); + listWxmp.add(appVersionInfo); + listWxmp.addAll(list3); + + JSONObject data = new JSONObject(); + data.put("android", listAndroid); + data.put("ios", listIOS); + data.put("wxmp", listWxmp); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐗堟湰鏌ヨ澶辫触")); + e.printStackTrace(); + } + } + + @RequestMapping(value = "clearCaches") + public void clearCaches(String callback, PrintWriter out) { + ehCacheCacheManager.getCacheManager().clearAll(); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("")); + } + + + /** + * 鏍规嵁鍒嗙被鏌ヨ + * + * @param callback + * @param type + * @param out + */ + @RequestMapping(value = "getByCategory") + public void getByCategory(AdminAcceptData acceptData, String callback, String type, PrintWriter out) { + try { + ConfigCategoryEnum categoryEnum = configCategoryService.getCategoryEnum(type); + if (categoryEnum == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐗堟湰鏌ヨ澶辫触")); + return; + } + + List<ConfigCategory> list = new ArrayList<>(); + + List<ConfigCategory> listCategory = configCategoryService.listByType(categoryEnum); + if (listCategory != null) { + for (ConfigCategory category : listCategory) { + Config config = configService.getConfigBykeyNoCache(category.getKeyEnum().getKey(), acceptData.getSystem()); + if (config != null) { + category.setConfig(config); + list.add(category); + } + } + } + + JSONObject data = new JSONObject(); + data.put("list", list); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触")); + e.printStackTrace(); + } + } + + + /** + * 淇濆瓨淇℃伅 + * + * @param callback + * @param listConfig + * @param out + */ + @RequestMapping(value = "saveConfig") + public void saveConfig(String callback, ListConfig listConfig, PrintWriter out) { + try { + if (listConfig == null || listConfig.getConfig() == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈帴鏀跺埌淇濆瓨鐨勪俊鎭�")); + return; + } + + configService.update(listConfig.getConfig()); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇敼鎴愬姛")); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇敼澶辫触")); + e.printStackTrace(); + } + } + + + /** + * 鏌ヨ鍝佺墝鑳屾櫙鍥剧墖 + * + * @param callback + * @param type + * @param out + */ + @RequestMapping(value = "getBrandBgImg") + public void getBrandBgImg(AdminAcceptData acceptData, String callback, String type, PrintWriter out) { + try { + Config config = configService.getConfigBykeyNoCache(ConfigKeyEnum.brandBackgroundPicture.getKey(), acceptData.getSystem()); + + JSONObject data = new JSONObject(); + if (config == null || StringUtil.isNullOrEmpty(config.getValue())) { + data.put("pic", ""); + } else { + data.put("pic", config.getValue()); + } + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触")); + e.printStackTrace(); + } + } + + /** + * 淇敼鍝佺墝鑳屾櫙鍥剧墖 + * + * @param callback + * @param out + */ + @RequestMapping(value = "changeBrandBgImg") + public void changeBrandBgImg(AdminAcceptData acceptData, String callback, HttpServletRequest request, Long id, PrintWriter out) { + try { + MultipartFile file = null; + if (request instanceof MultipartHttpServletRequest) { + MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request; + file = fileRequest.getFile("file"); + } + + if (file == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇蜂笂浼犲浘鐗囨枃浠�")); + return; + } + + Config config = configService.getConfigBykeyNoCache(ConfigKeyEnum.brandBackgroundPicture.getKey(), acceptData.getSystem()); + if (config == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鍝佺墝瀵硅薄涓嶅瓨鍦�")); + return; + } + + String oldpic = config.getValue(); + + + // 鏂囦欢瑙f瀽 + InputStream inputStream = file.getInputStream(); + String contentType = file.getContentType(); + String type = contentType.substring(contentType.indexOf("/") + 1); + // 鏂囦欢璺緞 + String filePath = FilePathEnum.brand.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; + // 鎵ц涓婁紶 + String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + if (StringUtil.isNullOrEmpty(fileLink)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏂囦欢涓婁紶澶辫触")); + return; + } + + config.setValue(fileLink); + configService.update(config); + + if (!Constant.IS_TEST) { + if (oldpic != null && oldpic.trim().length() > 0) { + COSManager.getInstance().deleteFile(oldpic); + } + } + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇敼鎴愬姛")); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇敼澶辫触")); + e.printStackTrace(); + } + } + + + @RequestNoLogin + @RequestMapping(value = "getSystem") + public void getSystem(AdminAcceptData acceptData, String callback, PrintWriter out) { + JSONArray array = new JSONArray(); + for (SystemEnum system : SystemEnum.values()) { + JSONObject item = new JSONObject(); + item.put("name", system.getName()); + item.put("key", system.name()); + array.add(item); + } + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(array.toString())); + } + + + @RequestNoLogin + @RequestMapping(value = "getTaoBaoAuthLink") + public void getTaoBaoAuthLink(AdminAcceptData acceptData, Long uid, String callback, PrintWriter out) { + JSONObject data = new JSONObject(); + data.put("url", TaoBaoUtil.getTaoBaoAuthLink(uid, "bind")); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + } + +} -- Gitblit v1.8.0