| | |
| | | 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 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.accept.AcceptData;
|
| | | 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.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;
|
| | |
| | | @Resource
|
| | | private EhCacheCacheManager ehCacheCacheManager;
|
| | |
|
| | | @Resource
|
| | | private ConfigCategoryService configCategoryService;
|
| | | |
| | | |
| | | /**
|
| | | * 查询列表 - 新后台
|
| | | *
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | @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));
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 版本号信息
|
| | | *
|
| | |
| | | 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();
|
| | | |
| | | |
| | | // 文件解析 |
| | | 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();
|
| | | }
|
| | | }
|
| | | |
| | | }
|