From 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 09 五月 2020 21:41:27 +0800 Subject: [PATCH] 2.1需求 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java | 335 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 280 insertions(+), 55 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 1743487..0cd2828 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,106 +1,119 @@ 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 net.sf.json.JSONObject; - +import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +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.accept.AcceptData; import com.yeshi.fanli.entity.common.Config; -import com.yeshi.fanli.service.AdminUserService; +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.fanli.tag.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 AdminUserService adminUserService; + private AppVersionService appVersionService; + + @Resource + private EhCacheCacheManager ehCacheCacheManager; + + @Resource + private ConfigCategoryService configCategoryService; - - @RequestMapping(value = "getConfigList", method = RequestMethod.POST) - public void getConfigList(PrintWriter out){ - List<Config> configList = configService.getAllList(); - out.print(JsonUtil.loadTrueResult(configList)); - } - - @RequestMapping(value = "updateConfig", method = RequestMethod.POST) - public void updateConfig(String map, PrintWriter out) { - List<Config> list = configService.getAllList(); - List<Config> newList = new ArrayList<Config>(); - Map<String, String> data = JsonUtil.parseData(map); - for (Config config : list) { - String key = config.getKey(); - if(data.containsKey(key)){ - String value =data.get(key); - if(!config.getValue().equals(value)){ - config.setValue(value); - newList.add(config); - } - } - } - configService.update(newList); - out.print(JsonUtil.loadTrueResult("淇敼鎴愬姛")); - return; - } /** * 鏌ヨ鍒楄〃 - 鏂板悗鍙� + * * @param callback - * @param key 鏌ヨ璇� 鍚嶇О + * @param key + * 鏌ヨ璇� 鍚嶇О * @param pageIndex * @param out */ @RequestMapping(value = "getNewConfigList") - public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){ - + public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out) { + try { - - if (pageIndex == null || pageIndex < 0){ + + if (pageIndex == null || pageIndex < 0) { pageIndex = 1; } - - List<Config> list = configService.listObjects(key, pageIndex); - + + List<AppVersionInfo> versionList = appVersionService.getAppVersionInfoListByPlatform("android"); + Map<Integer, String> androidMapName = new HashMap<>(); + for (AppVersionInfo version : versionList) + androidMapName.put(version.getVersionCode(), version.getVersion()); + + versionList = appVersionService.getAppVersionInfoListByPlatform("ios"); + Map<Integer, String> iosMapName = new HashMap<>(); + for (AppVersionInfo version : versionList) + iosMapName.put(version.getVersionCode(), version.getVersion()); + + List<Config> list = configService.listObjects(key, pageIndex); + + 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, pageIndex); + + int count = configService.getCount(key); 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 @@ -113,34 +126,246 @@ 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(AcceptData acceptData, PrintWriter out) { + JSONObject data = new JSONObject(); + data.put("list", configService.get(ConfigKeyEnum.articleHotWords.getKey())); + out.print(JsonUtil.loadTrueResult(data)); + } + + + /** + * 鐗堟湰鍙蜂俊鎭� + * + * @param callback + * @param out + */ + @RequestMapping(value = "getVersionList") + public void getVersionList(String callback, PrintWriter out) { + + try { + AppVersionInfo appVersionInfo = new AppVersionInfo(); + appVersionInfo.setVersion("鍏ㄦ帹"); + + // IOS鐗堟湰 + List<AppVersionInfo> list1 = appVersionService.getAppVersionInfoListByPlatform(AppVersionInfo.PLATFORM_IOS); + 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); + 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); + 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(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()); + 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(String callback, String type, PrintWriter out) { + try { + Config config = configService.getConfigBykeyNoCache(ConfigKeyEnum.brandBackgroundPicture.getKey()); + + 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 listConfig + * @param out + */ + @RequestMapping(value = "changeBrandBgImg") + public void changeBrandBgImg(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()); + 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(); + } } } -- Gitblit v1.8.0