瀏覽代碼

Merge branch 'develop' of http://39.101.216.213/gogs/liuhuijin/lineage into develop

Alex 4 年之前
父節點
當前提交
f5f0bd2345

+ 23 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -16,6 +16,7 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.framework.config.ServerConfig;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
 
 /**
  * 通用请求处理
@@ -23,8 +24,7 @@ import com.ruoyi.framework.config.ServerConfig;
  * @author ruoyi
  */
 @RestController
-public class CommonController
-{
+public class CommonController {
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);
 
     @Autowired
@@ -68,8 +68,7 @@ public class CommonController
      * 通用上传请求
      */
     @PostMapping("/common/upload")
-    public AjaxResult uploadFile(MultipartFile file) throws Exception
-    {
+    public AjaxResult uploadFile(MultipartFile file) throws Exception {
         try
         {
             // 上传文件路径
@@ -81,9 +80,26 @@ public class CommonController
             ajax.put("fileName", fileName);
             ajax.put("url", url);
             return ajax;
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
         }
-        catch (Exception e)
-        {
+    }
+    /**
+     * 图片上传请求
+     */
+    @PostMapping("/common/uploadImg")
+    public AjaxResult uploadFile(MultipartHttpServletRequest multiReq) throws Exception {
+        try {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, multiReq.getFile("img"));
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("fileName", fileName);
+            ajax.put("url", url);
+            return ajax;
+        } catch (Exception e) {
             return AjaxResult.error(e.getMessage());
         }
     }
@@ -92,8 +108,7 @@ public class CommonController
      * 本地资源通用下载
      */
     @GetMapping("/common/download/resource")
-    public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception
-    {
+    public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
         // 本地资源路径
         String localPath = RuoYiConfig.getProfile();
         // 数据库资源地址

+ 31 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TPersonalImgController.java

@@ -6,7 +6,10 @@ import java.util.List;
 import java.util.Arrays;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.framework.config.ServerConfig;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -27,6 +30,7 @@ import com.ruoyi.system.domain.TPersonalImg;
 import com.ruoyi.system.service.ITPersonalImgService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 个人页 图片Controller
@@ -41,6 +45,9 @@ public class TPersonalImgController extends BaseController {
 
     private final ITPersonalImgService iTPersonalImgService;
 
+    @Autowired
+    private ServerConfig serverConfig;
+
     /**
      * 查询个人页 图片列表
      */
@@ -126,4 +133,28 @@ public class TPersonalImgController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(iTPersonalImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @PostMapping("/upload")
+    public AjaxResult uploadFile(MultipartFile file, String personalId) throws Exception {
+        try {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getProfile() + "/personal";
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("fileName", fileName);
+            ajax.put("url", url);
+
+            TPersonalImg item = new TPersonalImg();
+            item.setPersonalId(Long.parseLong(personalId));
+            item.setEnable("0");
+            item.setUrl(fileName);
+            iTPersonalImgService.save(item);
+
+            return ajax;
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
 }

+ 19 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TPersonalPageController.java

@@ -2,24 +2,20 @@ package com.ruoyi.web.controller.system;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Arrays;
 
+import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUploadUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -28,6 +24,7 @@ import com.ruoyi.system.domain.TPersonalPage;
 import com.ruoyi.system.service.ITPersonalPageService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 个人页Controller
@@ -151,4 +148,18 @@ public class TPersonalPageController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(iTPersonalPageService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @PreAuthorize("@ss.hasPermi('system:personalPage:edit')")
+    @PostMapping("/avatar")
+    public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file, Long id) throws IOException {
+        if (!file.isEmpty()) {
+            String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
+            if (iTPersonalPageService.updateAvatar(id, avatar)) {
+                AjaxResult ajax = AjaxResult.success();
+                ajax.put("imgUrl", avatar);
+                return ajax;
+            }
+        }
+        return AjaxResult.error("上传图片异常,请联系管理员");
+    }
 }

+ 0 - 57
ruoyi-admin/src/main/resources/application-druid.yml

@@ -1,57 +0,0 @@
-# 数据源配置
-spring:
-    datasource:
-        type: com.alibaba.druid.pool.DruidDataSource
-        driverClassName: com.mysql.cj.jdbc.Driver
-        druid:
-            # 主库数据源
-            master:
-                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-                username: root
-                password: 123456
-            # 从库数据源
-            slave:
-                # 从数据源开关/默认关闭
-                enabled: false
-                url: 
-                username: 
-                password: 
-            # 初始连接数
-            initialSize: 5
-            # 最小连接池数量
-            minIdle: 10
-            # 最大连接池数量
-            maxActive: 20
-            # 配置获取连接等待超时的时间
-            maxWait: 60000
-            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
-            timeBetweenEvictionRunsMillis: 60000
-            # 配置一个连接在池中最小生存的时间,单位是毫秒
-            minEvictableIdleTimeMillis: 300000
-            # 配置一个连接在池中最大生存的时间,单位是毫秒
-            maxEvictableIdleTimeMillis: 900000
-            # 配置检测连接是否有效
-            validationQuery: SELECT 1 FROM DUAL
-            testWhileIdle: true
-            testOnBorrow: false
-            testOnReturn: false
-            webStatFilter: 
-                enabled: true
-            statViewServlet:
-                enabled: true
-                # 设置白名单,不填则允许所有访问
-                allow:
-                url-pattern: /druid/*
-                # 控制台管理用户名和密码
-                login-username: 
-                login-password: 
-            filter:
-                stat:
-                    enabled: true
-                    # 慢SQL记录
-                    log-slow-sql: true
-                    slow-sql-millis: 1000
-                    merge-sql: true
-                wall:
-                    config:
-                        multi-statement-allow: true

+ 8 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TPersonalPageMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
 
 import com.ruoyi.system.domain.TPersonalPage;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 个人页Mapper接口
@@ -10,5 +11,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @date 2020-09-16
  */
 public interface TPersonalPageMapper extends BaseMapper<TPersonalPage> {
+    /**
+     * 修改头像
+     *
+     * @param id 个人id
+     * @param avatar 头像地址
+     */
+    int updateAvatar(@Param("id") Long id, @Param("avatar") String avatar);
 
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ITPersonalPageService.java

@@ -11,4 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ITPersonalPageService extends IService<TPersonalPage> {
 
+    boolean updateAvatar(Long id, String avatar);
+
 }

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPersonalPageServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service.impl;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.system.mapper.TPersonalPageMapper;
@@ -14,5 +15,13 @@ import com.ruoyi.system.service.ITPersonalPageService;
  */
 @Service
 public class TPersonalPageServiceImpl extends ServiceImpl<TPersonalPageMapper, TPersonalPage> implements ITPersonalPageService {
+    @Autowired
+    private TPersonalPageMapper tPersonalPageMapper;
+
+    @Override
+    public boolean updateAvatar(Long id, String avatar){
+        return tPersonalPageMapper.updateAvatar(id,avatar) > 0;
+    }
+
 
 }

+ 3 - 0
ruoyi-system/src/main/resources/mapper/system/TPersonalPageMapper.xml

@@ -21,5 +21,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="remark"    column="remark"    />
     </resultMap>
 
+    <update id="updateAvatar" parameterType="TPersonalPage">
+         update t_personal_page set avatar = #{avatar} where id = #{id}
+    </update>
 
 </mapper>