From 80260a9fa08639ff11a8e10681454713239ca980 Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Thu, 21 Apr 2022 10:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=8C=87=E5=8D=97=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CategoryServiceImpl.java | 3 +- .../controller/ResourceController.java | 46 +++++++++++++++++++ .../service/impl/ResourceServiceImpl.java | 6 ++- .../src/main/resources/application.yml | 1 + .../src/main/resources/temp/devModelFile.md | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/category/service/impl/CategoryServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/category/service/impl/CategoryServiceImpl.java index 2d92acad..713aa041 100644 --- a/renren-admin/src/main/java/io/renren/modules/category/service/impl/CategoryServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/category/service/impl/CategoryServiceImpl.java @@ -74,7 +74,8 @@ public class CategoryServiceImpl extends CrudServiceImpl categories = categoryDao.selectList(wrapper); + return categories; } @Override diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 51634a5e..7c088faa 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -3,6 +3,7 @@ package io.renren.modules.resource.controller; import com.alibaba.fastjson.JSONObject; import io.renren.common.annotation.LogOperation; import io.renren.common.constant.Constant; +import io.renren.common.controller.FileUploadController; import io.renren.common.page.PageData; import io.renren.common.utils.Result; import io.renren.common.validator.ValidatorUtils; @@ -14,13 +15,21 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.util.Date; import java.util.Map; +import java.util.UUID; /** * 资源表 @@ -32,9 +41,14 @@ import java.util.Map; @RequestMapping("/resource") @Api(tags="资源表") public class ResourceController { + + @Value("${resource.devModelFilePath}") + private String delModelFilePath; @Autowired private ResourceService resourceService; + private static Logger logger = LoggerFactory.getLogger(ResourceController.class); + @GetMapping("/page") @ApiOperation("分页查询资源信息") @ApiImplicitParams({ @@ -135,6 +149,38 @@ public class ResourceController { } } + @PostMapping("/upload") + @ApiOperation("开发指南文件上传") + @ApiImplicitParams({ + @ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true) + }) + public Result upload(@RequestParam("file") MultipartFile uploadFile, + HttpServletRequest request) { + logger.info("上传文件:" + uploadFile.getOriginalFilename()); + File folder = new File(delModelFilePath); + if (!folder.isDirectory()) { + folder.mkdirs(); + } + if (folder.exists()) { + if (folder.isFile()) { + if (!folder.delete()) { + return new Result<>().error("保存开发指南失败!!!"); + } + } + } + // 对上传的文件重命名,避免文件重名 + //String oldName = uploadFile.getOriginalFilename(); + String fileName = "devModelFile.md"; + try { + // 文件保存 + uploadFile.transferTo(new File(folder, fileName)); + + return new Result<>(); + } catch (IOException e) { + return new Result().error(e.getMessage()); + } + } + /*@GetMapping("export") @ApiOperation("导出") @LogOperation("导出") diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 36670d39..3b1267bb 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -20,6 +20,7 @@ import io.renren.modules.security.user.UserDetail; import org.apache.commons.io.IOUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,6 +44,9 @@ import java.util.Map; @Service public class ResourceServiceImpl extends CrudServiceImpl implements ResourceService { + @Value("${resource.devModelFilePath}") + private String delModelFilePath; + @Autowired private ResourceDao resourceDao; @@ -183,7 +187,7 @@ public class ResourceServiceImpl extends CrudServiceImpl