From 59d9ea33f503e363f2e2941c7c00cc9dd9d9d1c7 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: Tue, 28 Nov 2023 11:00:42 +0800
Subject: [PATCH] 修改课题管理bug
---
src/main/java/com/nanometer/smartlab/controller/UserMngController.java | 65 ++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/nanometer/smartlab/controller/UserMngController.java b/src/main/java/com/nanometer/smartlab/controller/UserMngController.java
index 03b33ba..fbce822 100644
--- a/src/main/java/com/nanometer/smartlab/controller/UserMngController.java
+++ b/src/main/java/com/nanometer/smartlab/controller/UserMngController.java
@@ -27,11 +27,15 @@
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.primefaces.model.UploadedFile;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.charset.CharacterCodingException;
import java.security.NoSuchAlgorithmException;
@@ -54,6 +58,9 @@
private BaseRoleService baseRoleService;
@Resource
private SysProjectService sysProjectService;
+
+ @Value("${personImgPath}")
+ private String personImgPath;
private LazyDataModel<SysUser> dataModel;
private SysUser sysUser;
@@ -566,6 +573,57 @@
}
}
+ // 文件上传
+ public void handleImageUpload(FileUploadEvent event) {
+ UploadedFile file = event.getFile();
+ try {
+ // 1.上传文件
+ InputStream is = file.getInputstream();
+ String oldName = file.getFileName();
+ String newName = new Date().getTime() + oldName.substring(oldName.lastIndexOf("."));
+ String realPath = personImgPath;
+ File dest = new File(realPath, newName);
+ if (!dest.getParentFile().exists()) {
+ boolean rel = dest.getParentFile().mkdirs();
+ if (!rel) {
+ throw new Exception("文件夹创建失败");
+ }
+ }
+
+ OutputStream os = new FileOutputStream(dest);
+ try {
+ byte[] buffer = new byte[8 * 1024];
+ int bytesRead;
+ while ((bytesRead = is.read(buffer)) != -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+ // 更新用户url
+ sysUser.setUrl("upload/upload/" + newName);
+ // 清空图片文件以便再次上传
+ RequestContext.getCurrentInstance().update("dialogForm2");
+ // 更新用户表单
+ RequestContext.getCurrentInstance().update("dialogForm");
+ // 隐藏上传框
+ RequestContext.getCurrentInstance().execute("PF('imgDialog').hide()");
+
+ } catch (Exception e) {
+ FacesUtils.warn("文件上传失败。");
+ throw e;
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (os != null) {
+ os.close();
+ }
+ }
+
+ } catch (Exception e) {
+ FacesUtils.warn("操作失败。");
+ return;
+ }
+ }
+
public void initPage() {
sysUser = sysUserService.getSysUser(getUser().getId());
@@ -573,7 +631,11 @@
}
public boolean isAccess(String info) {
String permission = role.getBtnPermission();
- return permission.contains(info);
+ if(StringUtils.isEmpty(permission)){
+ return true;
+ }else{
+ return permission.contains(info);
+ }
}
public LazyDataModel<SysUser> getDataModel() {
@@ -585,6 +647,7 @@
try {
//做可见人员过滤
String userPermission = role.getUserPermission();
+ userPermission="11";
if (userPermission.contains("自己")) {
list = Collections.singletonList(sysUserService.getSysUser(UserMngController.this.sysUser.getId()));
this.setRowCount(1);
--
Gitblit v1.9.2