提交 01c2e1c6 编写于 作者: 江南一点雨

添加 FastDFS 文件上传

上级 8329c655
......@@ -28,4 +28,6 @@ public interface HrMapper {
List<Hr> getAllHrsExceptCurrentHr(Integer id);
Integer updatePasswd(@Param("hrid") Integer hrid, @Param("encodePass") String encodePass);
Integer updateUserface(@Param("url") String url, @Param("id") Integer id);
}
\ No newline at end of file
......@@ -161,6 +161,9 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateUserface">
update hr set userface = #{url} where id=#{id};
</update>
<update id="updatePasswd">
update hr set password = #{encodePass} where id=#{hrid};
</update>
......
......@@ -78,4 +78,8 @@ public class HrService implements UserDetailsService {
}
return false;
}
public Integer updateUserface(String url, Integer id) {
return hrMapper.updateUserface(url, id);
}
}
......@@ -25,7 +25,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.flywaydb:flyway-core:5.2.4" level="project" />
<orderEntry type="module" module-name="vhr-mapper" />
<orderEntry type="module" module-name="vhr-model" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE" level="project" />
......
......@@ -32,6 +32,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>net.oschina.zcx7878</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
package org.javaboy.vhr.config;
import org.csource.common.MyException;
import org.csource.fastdfs.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* @作者 江南一点雨
* @公众号 江南一点雨
* @微信号 a_java_boy
* @GitHub https://github.com/lenve
* @博客 http://wangsong.blog.csdn.net
* @网站 http://www.javaboy.org
* @时间 2020-03-01 22:49
*/
public class FastDFSUtils {
private static StorageClient1 client1;
static {
try {
ClientGlobal.initByProperties("fastdfs-client.properties");
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
client1 = new StorageClient1(trackerServer, storageServer);
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
}
public static String upload(MultipartFile file) {
String name = file.getOriginalFilename();
String s = null;
try {
s = client1.upload_file1(file.getBytes(), name.substring(name.lastIndexOf(".") + 1), null);
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
return s;
}
}
package org.javaboy.vhr.controller;
import org.javaboy.vhr.config.FastDFSUtils;
import org.javaboy.vhr.model.Hr;
import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.service.HrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
......@@ -27,6 +27,9 @@ public class HrInfoController {
@Autowired
HrService hrService;
@Value("${javaboy.nginx.host}")
String nginxHost;
@GetMapping("/hr/info")
public Hr getCurrentHr(Authentication authentication) {
return ((Hr) authentication.getPrincipal());
......@@ -51,4 +54,14 @@ public class HrInfoController {
return RespBean.error("更新失败!");
}
}
@PostMapping("/hr/userface")
public RespBean updateUserface(MultipartFile file, Integer id) {
String upload = FastDFSUtils.upload(file);
String url = nginxHost + upload;
if (hrService.updateUserface(url, id) == 1) {
return RespBean.ok("更新成功!",url);
}
return RespBean.error("更新失败!");
}
}
\ No newline at end of file
......@@ -16,4 +16,6 @@ spring.redis.host=192.168.91.128
spring.redis.database=0
spring.redis.port=6379
spring.redis.password=123
spring.cache.cache-names=menus_cache
\ No newline at end of file
spring.cache.cache-names=menus_cache
# FastDFS 文件地址
javaboy.nginx.host=http://192.168.91.128/
\ No newline at end of file
## fastdfs-client.properties
fastdfs.connect_timeout_in_seconds = 5
fastdfs.network_timeout_in_seconds = 30
fastdfs.charset = UTF-8
fastdfs.http_anti_steal_token = false
fastdfs.http_secret_key = FastDFS1234567890
fastdfs.http_tracker_http_port = 80
fastdfs.tracker_servers = 192.168.91.128:22122
## Whether to open the connection pool, if not, create a new connection every time
fastdfs.connection_pool.enabled = true
## max_count_per_entry: max connection count per host:port , 0 is not limit
fastdfs.connection_pool.max_count_per_entry = 500
## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600
fastdfs.connection_pool.max_idle_time = 3600
## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000
fastdfs.connection_pool.max_wait_time_in_ms = 1000
\ No newline at end of file
......@@ -25,7 +25,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.flywaydb:flyway-core:5.2.4" level="project" />
<orderEntry type="module" module-name="vhr-service" />
<orderEntry type="module" module-name="vhr-mapper" />
<orderEntry type="module" module-name="vhr-model" />
......@@ -91,6 +90,7 @@
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-websocket:5.1.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: net.oschina.zcx7878:fastdfs-client-java:1.27.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.1.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.8.RELEASE" level="project" />
......
......@@ -6,8 +6,15 @@
</div>
<div>
<div style="display: flex;justify-content: center">
<img title="点击修改用户图像" :src="hr.userface" style="width: 100px;height: 100px;border-radius: 50px"
alt="">
<el-upload
:data="hr"
:show-file-list="false"
:on-success="onSuccess"
action="/hr/userface">
<img title="点击修改用户图像" :src="hr.userface" style="width: 100px;height: 100px;border-radius: 50px"
alt="">
</el-upload>
</div>
<div>电话号码:
<el-tag>{{hr.telephone}}</el-tag>
......@@ -34,7 +41,8 @@
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
......@@ -58,20 +66,36 @@
<div>
<table>
<tr>
<td><el-tag>用户姓名:</el-tag></td>
<td><el-input v-model="hr2.name"></el-input></td>
<td>
<el-tag>用户姓名:</el-tag>
</td>
<td>
<el-input v-model="hr2.name"></el-input>
</td>
</tr>
<tr>
<td><el-tag>电话号码:</el-tag></td>
<td><el-input v-model="hr2.telephone"></el-input></td>
<td>
<el-tag>电话号码:</el-tag>
</td>
<td>
<el-input v-model="hr2.telephone"></el-input>
</td>
</tr>
<tr>
<td><el-tag>手机号码:</el-tag></td>
<td><el-input v-model="hr2.phone"></el-input></td>
<td>
<el-tag>手机号码:</el-tag>
</td>
<td>
<el-input v-model="hr2.phone"></el-input>
</td>
</tr>
<tr>
<td><el-tag>用户地址:</el-tag></td>
<td><el-input v-model="hr2.address"></el-input></td>
<td>
<el-tag>用户地址:</el-tag>
</td>
<td>
<el-input v-model="hr2.address"></el-input>
</td>
</tr>
</table>
</div>
......@@ -108,36 +132,42 @@
};
return {
ruleForm: {
oldpass:'',
oldpass: '',
pass: '',
checkPass: ''
},
rules: {
oldpass: [
{ validator: validatePass, trigger: 'blur' }
{validator: validatePass, trigger: 'blur'}
],
pass: [
{ validator: validatePass, trigger: 'blur' }
{validator: validatePass, trigger: 'blur'}
],
checkPass: [
{ validator: validatePass2, trigger: 'blur' }
{validator: validatePass2, trigger: 'blur'}
]
},
hr: null,
hr2: null,
passwdDialogVisible:false,
dialogVisible:false
passwdDialogVisible: false,
dialogVisible: false
}
},
mounted() {
this.initHr();
},
methods: {
onSuccess() {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
this.$store.commit('initRoutes', []);
this.$router.replace("/");
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.ruleForm.hrid = this.hr.id;
this.putRequest("/hr/pass",this.ruleForm).then(resp=>{
this.putRequest("/hr/pass", this.ruleForm).then(resp => {
if (resp) {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
......@@ -157,7 +187,7 @@
this.passwdDialogVisible = true;
},
updateHrInfo() {
this.putRequest("/hr/info",this.hr2).then(resp=>{
this.putRequest("/hr/info", this.hr2).then(resp => {
if (resp) {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册