| | |
| | | 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.HttpServletResponse;
|
| | | 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.entity.common.AdminUser;
|
| | | 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.annotation.RequestNoLogin;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | 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 count = configService.getCount(key, pageIndex);
|
| | | PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count);
|
| | | |
| | |
|
| | | int pageSize = Constant.PAGE_SIZE;
|
| | |
|
| | | 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
|
| | | */
|
| | | @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();
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | @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 config
|
| | | * @param listConfig
|
| | | * @param out
|
| | | */
|
| | | @RequestNoLogin()
|
| | | @RequestMapping(value = "saveModify")
|
| | | public void saveModify(String callback, Config config, Long uid, HttpServletResponse response, PrintWriter out) {
|
| | | |
| | | response.setHeader("Access-Control-Allow-Origin", "*");
|
| | | response.setHeader("Access-Control-Allow-Methods", "*");
|
| | |
|
| | | AdminUser admin = adminUserService.selectByPrimaryKey(uid);
|
| | | if (admin == null) {
|
| | | out.print(JsonUtil.loadFalseResult("当前账户验证失败"));
|
| | | return;
|
| | | }
|
| | | |
| | | Long id = config.getId();
|
| | | if (id == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | @RequestMapping(value = "changeBrandBgImg")
|
| | | public void changeBrandBgImg(String callback, HttpServletRequest request, Long id, PrintWriter out) {
|
| | | try {
|
| | | Config crentconfig = configService.getConfig(id);
|
| | | if (crentconfig == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作数据已不存在"));
|
| | | 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;
|
| | | }
|
| | | // key 不可修改
|
| | | config.setKey(crentconfig.getKey());
|
| | | configService.update(config);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
|
| | |
|
| | | Config config = configService.getConfigBykeyNoCache(ConfigKeyEnum.brandBackgroundPicture.getKey());
|
| | | if (config == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("品牌对象不存在"));
|
| | | return;
|
| | | }
|
| | | |
| | | String oldpic = config.getValue();
|
| | | |
| | | |
| | | // 文件解析 |
| | | 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();
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | }
|