Commit cc0c508e authored by trumansdo's avatar trumansdo
Browse files

用户管理待完成:

1、统一包装上传组件,为了后续前端代码不重复写上传逻辑。
2、下载导出
parent b64a9584
...@@ -4,15 +4,13 @@ import com.ibeetl.admin.console.service.UserConsoleService; ...@@ -4,15 +4,13 @@ import com.ibeetl.admin.console.service.UserConsoleService;
import com.ibeetl.admin.console.util.VOUtil; import com.ibeetl.admin.console.util.VOUtil;
import com.ibeetl.admin.console.web.query.CoreUserElQuery; import com.ibeetl.admin.console.web.query.CoreUserElQuery;
import com.ibeetl.admin.core.annotation.Function; import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.annotation.RequestBodyPlus;
import com.ibeetl.admin.core.entity.CoreUser; import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.service.CorePlatformService; import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.service.CoreUserService;
import com.ibeetl.admin.core.service.param.CoreUserParam; import com.ibeetl.admin.core.service.param.CoreUserParam;
import com.ibeetl.admin.core.util.ConvertUtil;
import com.ibeetl.admin.core.util.ValidateConfig; import com.ibeetl.admin.core.util.ValidateConfig;
import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.admin.core.web.JsonResult;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.beetl.sql.core.engine.PageQuery; import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -71,7 +69,7 @@ public class UserConsoleElController { ...@@ -71,7 +69,7 @@ public class UserConsoleElController {
@Function("user.delete") @Function("user.delete")
@DeleteMapping @DeleteMapping
public JsonResult delete(Long[] ids) { public JsonResult delete(@RequestBodyPlus("ids") Long[] ids) {
userConsoleService.batchDelSysUser(Arrays.asList(ids)); userConsoleService.batchDelSysUser(Arrays.asList(ids));
return JsonResult.success(); return JsonResult.success();
} }
......
...@@ -5,6 +5,8 @@ user.id=1 ...@@ -5,6 +5,8 @@ user.id=1
user.orgId=1 user.orgId=1
#\u6253\u5F00\u5BA1\u8BA1\u529F\u80FD\uFF0C\u5F00\u53D1\u6A21\u5F0F\u5E94\u8BE5\u5173\u95ED #\u6253\u5F00\u5BA1\u8BA1\u529F\u80FD\uFF0C\u5F00\u53D1\u6A21\u5F0F\u5E94\u8BE5\u5173\u95ED
audit.enable=false audit.enable=false
# \u6587\u4EF6\u64CD\u4F5C\u7684\u6839\u76EE\u5F55\u914D\u7F6E \u8BF7\u6839\u636E\u5404\u81EA\u8BA1\u7B97\u673A\u914D\u7F6E
localFile.root = E:\\code_workspace\\temp_space\\
# --------\u670D\u52A1\u5668undertow\u914D\u7F6E # --------\u670D\u52A1\u5668undertow\u914D\u7F6E
server.port=8080 server.port=8080
......
layui.define([ 'form', 'laydate', 'table','userApi' ], function(exports) { layui.define(['form', 'laydate', 'table', 'userApi'], function (exports) {
var form = layui.form; var form = layui.form;
var laydate = layui.laydate; var laydate = layui.laydate;
var table = layui.table; var table = layui.table;
var userApi=layui.userApi; var userApi = layui.userApi;
var userTable = null; var userTable = null;
var view ={ var view = {
init:function(){ init: function () {
this.initTable(); this.initTable();
this.initSearchForm(); this.initSearchForm();
this.initToolBar(); this.initToolBar();
window.dataReload = function(){ window.dataReload = function () {
Lib.doSearchForm($("#searchForm"),userTable) Lib.doSearchForm($("#searchForm"), userTable)
} }
}, },
initTable:function(){ initTable: function () {
userTable = table.render({ userTable = table.render({
elem : '#userTable', elem: '#userTable',
height : Lib.getTableHeight(2), height: Lib.getTableHeight(2),
method : 'post', method: 'post',
url : Common.ctxPath + '/admin/user/list.json' //数据接口 url: Common.ctxPath + '/admin/user/list.json' //数据接口
,page : Lib.tablePage //开启分页 , page: Lib.tablePage //开启分页
,limit : 10, , limit: 10,
cols : [ [ //表头 cols: [[ //表头
{ {
type : 'checkbox', type: 'checkbox',
fixed:'left', fixed: 'left',
}, { }, {
field : 'id', field: 'id',
title : 'id', title: 'id',
width : 80, width: 80,
fixed:'left', fixed: 'left',
sort : true sort: true
}, { }, {
field : 'code', field: 'code',
title : '用户名', title: '用户名',
width : 150 width: 150
}, { }, {
field : 'name', field: 'name',
title : '姓名', title: '姓名',
width : 120, width: 120,
sort : true sort: true
}, { }, {
field : 'orgName', field: 'orgName',
title : '机构', title: '机构',
width : 120, width: 120,
sort : true sort: true
}, { }, {
field : 'stateText', field: 'stateText',
title : '状态', title: '状态',
width : 120, width: 120,
sort : true sort: true
}, },
{ {
field : 'jobType0Text', field: 'jobType0Text',
title : '职位', title: '职位',
width : 120, width: 120,
sort : true sort: true
}, },
{ {
field : 'jobType1Text', field: 'jobType1Text',
title : '职位明细', title: '职位明细',
width : 80, width: 80,
sort : true sort: true
}, },
{ {
field : 'createTime', field: 'createTime',
title : '创建时间', title: '创建时间',
width : 120, width: 120,
templet:function(d){ templet: function (d) {
return Common.getDate(d.createTime); return Common.getDate(d.createTime);
}, },
sort : true sort: true
} }
] ] ]]
}); });
}, },
initSearchForm:function(){ initSearchForm: function () {
Lib.initSearchForm( $("#searchForm"),userTable,form); Lib.initSearchForm($("#searchForm"), userTable, form);
}, },
initToolBar:function(){ initToolBar: function () {
toolbar = { toolbar = {
add : function() { //获取选中数据 add: function () { //获取选中数据
var url = "/admin/user/add.do"; var url = "/admin/user/add.do";
Common.openDlg(url,"用户管理>新增"); Common.openDlg(url, "用户管理>新增");
}, },
edit : function() { //获取选中数目 edit: function () { //获取选中数目
var data = Common.getOneFromTable(table,"userTable"); var data = Common.getOneFromTable(table, "userTable");
if(data==null){ if (data == null) {
return ; return;
} }
var url = "/admin/user/edit.do?id="+data.id; var url = "/admin/user/edit.do?id=" + data.id;
Common.openDlg(url,"用户管理>编辑"); Common.openDlg(url, "用户管理>编辑");
}, },
del : function() { del: function () {
layui.use(['del'], function(){ layui.use(['del'], function () {
var delView = layui.del var delView = layui.del
delView.delBatch(); delView.delBatch();
}); });
}, },
userRole : function() { //获取选中数目 userRole: function () { //获取选中数目
var data = Common.getOneFromTable(table,"userTable"); var data = Common.getOneFromTable(table, "userTable");
if(data==null){ if (data == null) {
return ; return;
} }
var url = "/admin/user/role/list.do?id="+data.id; var url = "/admin/user/role/list.do?id=" + data.id;
Common.openDlg(url,"用户管理>"+data.name+">角色管理"); Common.openDlg(url, "用户管理>" + data.name + ">角色管理");
}, },
changePassword:function(){ changePassword: function () {
var data = Common.getOneFromTable(table,"userTable"); var data = Common.getOneFromTable(table, "userTable");
if(data==null){ if (data == null) {
return ; return;
} }
var url = "/admin/user/changePassword.do?id="+data.id; var url = "/admin/user/changePassword.do?id=" + data.id;
Common.openDlg(url,"用户管理>更改密码"); Common.openDlg(url, "用户管理>更改密码");
}, },
exportUsers:function(){ exportUsers: function () {
Common.openConfirm("确认要导出这些用户?",function(){ Common.openConfirm("确认要导出这些用户?", function () {
userApi.exportUsers($("#searchForm"),function(fileId){ userApi.exportUsers($("#searchForm"), function (fileId) {
Lib.download(fileId); Lib.download(fileId);
}) })
}) })
} }
}; };
$('.ext-toolbar').on('click', function() { $('.ext-toolbar').on('click', function () {
var type = $(this).data('type'); var type = $(this).data('type');
toolbar[type] ? toolbar[type].call(this) : ''; toolbar[type] ? toolbar[type].call(this) : '';
}); });
} }
} }
exports('index',view); exports('index', view);
}); });
\ No newline at end of file
...@@ -6,11 +6,19 @@ import com.fasterxml.jackson.databind.SerializerProvider; ...@@ -6,11 +6,19 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
/**
* Class DateToTimestampSerializer : <br>
* 描述:在date序列化时间戳时,默认的jackson会将纳秒一起序列化,但是没必要。
*
* @author 一日看尽长安花 Created on 2020/3/13
*/
public class DateToTimestampSerializer extends JsonSerializer<Date> { public class DateToTimestampSerializer extends JsonSerializer<Date> {
private static final long NANO_MULTIPLE = 1000L;
@Override @Override
public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers)
throws IOException { throws IOException {
gen.writeNumber(value.getTime()/1000L); gen.writeNumber(value.getTime() / NANO_MULTIPLE);
} }
} }
...@@ -33,6 +33,7 @@ public class CoreFile extends BaseEntity { ...@@ -33,6 +33,7 @@ public class CoreFile extends BaseEntity {
private Long orgId; private Long orgId;
private String bizType; private String bizType;
/*文件批次id,用于其它业务表记录*/
private String fileBatchId; private String fileBatchId;
public CoreFile() {} public CoreFile() {}
......
package com.ibeetl.admin.core.file; package com.ibeetl.admin.core.file;
import java.io.OutputStream; import java.io.OutputStream;
import lombok.Data;
@Data
public abstract class FileItem { public abstract class FileItem {
protected Long id; protected Long id;
protected String name; protected String name;
...@@ -13,36 +15,4 @@ public abstract class FileItem { ...@@ -13,36 +15,4 @@ public abstract class FileItem {
public abstract void copy(OutputStream os); public abstract void copy(OutputStream os);
public abstract boolean delete(); public abstract boolean delete();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public boolean isTemp() {
return isTemp;
}
public void setTemp(boolean isTemp) {
this.isTemp = isTemp;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
} }
package com.ibeetl.admin.core.file; package com.ibeetl.admin.core.file;
import com.ibeetl.admin.core.util.PlatformException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import com.ibeetl.admin.core.util.PlatformException;
/** /**
* 本地文件系统 * 本地文件系统
* *
* @author xiandafu * @author xiandafu
*/ */
class LocalFileItem extends PersistFileItem { public class LocalFileItem extends PersistFileItem {
String root = null; String root;
public LocalFileItem(String root) { public LocalFileItem(String root) {
this.root = root; this.root = root;
...@@ -28,7 +27,7 @@ class LocalFileItem extends PersistFileItem { ...@@ -28,7 +27,7 @@ class LocalFileItem extends PersistFileItem {
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
return fos; return fos;
} catch (IOException e) { } catch (IOException e) {
throw new PlatformException("Open stream error " + path); throw new PlatformException("Open file [" + path + "] output stream error ");
} }
} }
...@@ -45,7 +44,7 @@ class LocalFileItem extends PersistFileItem { ...@@ -45,7 +44,7 @@ class LocalFileItem extends PersistFileItem {
} }
} catch (Exception ex) { } catch (Exception ex) {
throw new PlatformException("下载文件失败" + ex); throw new PlatformException("下载/复制文件失败" + ex);
} finally { } finally {
try { try {
input.close(); input.close();
...@@ -56,7 +55,7 @@ class LocalFileItem extends PersistFileItem { ...@@ -56,7 +55,7 @@ class LocalFileItem extends PersistFileItem {
} }
} }
if (path.startsWith("temp")) { if (isTemp) {
this.delete(); this.delete();
} }
} }
......
package com.ibeetl.admin.core.file; package com.ibeetl.admin.core.file;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import com.ibeetl.admin.core.dao.CoreFileDao; import com.ibeetl.admin.core.dao.CoreFileDao;
import com.ibeetl.admin.core.entity.CoreFile; import com.ibeetl.admin.core.entity.CoreFile;
import com.ibeetl.admin.core.util.DateUtil; import com.ibeetl.admin.core.util.DateUtil;
import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.UUIDUtil; import com.ibeetl.admin.core.util.UUIDUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
/** /**
* 一个本地文件系统,管理临时文件和用户文件 * 一个本地文件系统,管理临时文件和用户文件
* *
* @author xiandafu * @author xiandafu
*/ */
@Slf4j
public class LocalFileService implements FileService { public class LocalFileService implements FileService {
Log log = LogFactory.getLog(this.getClass());
DBIndexHelper dbHelper = null; DBIndexHelper dbHelper = null;
String root = null; String root;
public LocalFileService(ApplicationContext ctx, String root) { public LocalFileService(ApplicationContext ctx, String root) {
this.root = root; this.root = root;
...@@ -104,7 +101,6 @@ public class LocalFileService implements FileService { ...@@ -104,7 +101,6 @@ public class LocalFileService implements FileService {
item.setBizType(file.getBizType()); item.setBizType(file.getBizType());
item.setId(file.getId()); item.setId(file.getId());
item.setOrgId(file.getOrgId()); item.setOrgId(file.getOrgId());
item.setId(file.getId());
return item; return item;
} }
...@@ -146,7 +142,7 @@ public class LocalFileService implements FileService { ...@@ -146,7 +142,7 @@ public class LocalFileService implements FileService {
FileItem item = this.getFileItem(file); FileItem item = this.getFileItem(file);
boolean success = item.delete(); boolean success = item.delete();
if (!success) { if (!success) {
log.warn("删除文件失败 " + file.getName() + ",id=" + file.getId() + " path=" + file.getPath()); log.warn("删除文件[" + file.getName() + "]失败,id=" + file.getId() + " path=" + file.getPath());
throw new PlatformException("删除文件失败 " + file.getName()); throw new PlatformException("删除文件失败 " + file.getName());
} }
dbHelper.fileDao.deleteById(id); dbHelper.fileDao.deleteById(id);
......
...@@ -5,7 +5,6 @@ import java.util.UUID; ...@@ -5,7 +5,6 @@ import java.util.UUID;
public class UUIDUtil { public class UUIDUtil {
public static String uuid() { public static String uuid() {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString(); return uuid.toString();
return randomUUIDString;
} }
} }
package com.ibeetl.admin.core.web; package com.ibeetl.admin.core.web;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.ibeetl.admin.core.entity.CoreOrg;
import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.file.FileItem;
import com.ibeetl.admin.core.file.FileService;
import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.util.FileUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -19,43 +24,42 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -19,43 +24,42 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.ibeetl.admin.core.entity.CoreOrg;
import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.file.FileItem;
import com.ibeetl.admin.core.file.FileService;
import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.util.FileUtil;
/** /**
* Class FileSystemContorller : <br/> * 描述:文件上传下载操作
* 描述:业务中有关文件的上传,下载。<br/> *
* TODO 待改动计划: * @author 一日看尽长安花 Created on 2020/3/16
* 改成加上MD5验证,减少重复文件的io
* 补上文件表中有关文件属性(大小,类型,)的信息
* 补上文件上传的临时状态,避免上传文件却中断业务逻辑,产生无用数据以及文件
* @author 一日看尽长安花
* Updated on 2020/3/8
*/ */
@Slf4j @Slf4j
@Controller @Controller
@RequestMapping("/core/file") @RequestMapping("/core/file")
public class FileSystemContorller { public class FileSystemElContorller {
@Autowired CorePlatformService platformService; @Autowired CorePlatformService platformService;
@Autowired FileService fileService; @Autowired FileService fileService;
/*附件类操作*/ /**
@PostMapping("/uploadAttachment.json") * 上传文件
*
* @author 一日看尽长安花
* @param fileBatchId 文件批次id,第一次上传应该自动生成一个返回给前端
* @param bizId 有关的业务id
* @param bizType 有关的业务类型type
* @return JsonResult<String> 返回文件操作批次id
* @throws IOException when
*/
@PostMapping("/uploadAttachment")
@ResponseBody @ResponseBody
public JsonResult uploadFile( public JsonResult<String> uploadFile(
@RequestParam("file") MultipartFile file, String batchFileUUID, String bizType, String bizId) @RequestParam("file") MultipartFile file, String fileBatchId, String bizType, String bizId)
throws IOException { throws IOException {
if (file.isEmpty()) { if (file.isEmpty()) {
return JsonResult.fail(); return JsonResult.fail();
} }
if (StrUtil.isBlank(fileBatchId)) {
fileBatchId = IdUtil.fastUUID();
}
CoreUser user = platformService.getCurrentUser(); CoreUser user = platformService.getCurrentUser();
CoreOrg org = platformService.getCurrentOrg(); CoreOrg org = platformService.getCurrentOrg();
FileItem fileItem = FileItem fileItem =
...@@ -65,22 +69,30 @@ public class FileSystemContorller { ...@@ -65,22 +69,30 @@ public class FileSystemContorller {
bizId, bizId,
user.getId(), user.getId(),
org.getId(), org.getId(),
batchFileUUID, fileBatchId,
null); null);
OutputStream os = fileItem.openOutpuStream(); OutputStream os = fileItem.openOutpuStream();
FileUtil.copy(file.getInputStream(), os); FileUtil.copy(file.getInputStream(), os);
return JsonResult.success(fileItem); return JsonResult.success(fileBatchId);
} }
@PostMapping("/deleteAttachment.json") @PostMapping("/deleteAttachment")
@ResponseBody @ResponseBody
public JsonResult deleteFile(Long fileId, String batchFileUUID) throws IOException { public JsonResult deleteFile(Long fileId, String batchFileUUID) throws IOException {
fileService.removeFile(fileId, batchFileUUID); fileService.removeFile(fileId, batchFileUUID);
return JsonResult.success(); return JsonResult.success();
} }
@GetMapping("/download/{fileId}/{batchFileUUID}/{name}") /**
public ModelAndView download( * 下载多文件中的某一个文件,
*
* @author 一日看尽长安花
* @param batchFileUUID 多文件的文件操作批次id
* @param fileId 多文件中某个文件的id
* @throws IOException when
*/
@GetMapping("/download/{fileId}/{batchFileUUID}")
public void downloadMutipleFile(
HttpServletResponse response, @PathVariable Long fileId, @PathVariable String batchFileUUID) HttpServletResponse response, @PathVariable Long fileId, @PathVariable String batchFileUUID)
throws IOException { throws IOException {
FileItem item = fileService.getFileItemById(fileId, batchFileUUID); FileItem item = fileService.getFileItemById(fileId, batchFileUUID);
...@@ -88,14 +100,19 @@ public class FileSystemContorller { ...@@ -88,14 +100,19 @@ public class FileSystemContorller {
"Content-Disposition", "Content-Disposition",
"attachment; filename=" + URLEncoder.encode(item.getName(), "UTF-8")); "attachment; filename=" + URLEncoder.encode(item.getName(), "UTF-8"));
item.copy(response.getOutputStream()); item.copy(response.getOutputStream());
return null;
} }
/*execl 导入导出*/ /*execl 导入导出*/
@GetMapping("/get.do") /**
public ModelAndView index(HttpServletResponse response, String id) throws IOException { * 通过路径下载文件
String path = id; *
* @author 一日看尽长安花
* @param path 文件path路径
* @throws IOException when
*/
@GetMapping("/download")
public void downloadFileByPath(HttpServletResponse response, String path) throws IOException {
response.setContentType("text/html; charset = UTF-8"); response.setContentType("text/html; charset = UTF-8");
FileItem fileItem = fileService.loadFileItemByPath(path); FileItem fileItem = fileService.loadFileItemByPath(path);
response.setHeader( response.setHeader(
...@@ -105,12 +122,10 @@ public class FileSystemContorller { ...@@ -105,12 +122,10 @@ public class FileSystemContorller {
if (fileItem.isTemp()) { if (fileItem.isTemp()) {
fileItem.delete(); fileItem.delete();
} }
return null;
} }
@GetMapping("/downloadTemplate.do") @GetMapping("/downloadTemplate")
public ModelAndView dowloadTemplate(HttpServletResponse response, String path) public void dowloadTemplate(HttpServletResponse response, String path) throws IOException {
throws IOException {
response.setContentType("text/html; charset = UTF-8"); response.setContentType("text/html; charset = UTF-8");
int start1 = path.lastIndexOf("\\"); int start1 = path.lastIndexOf("\\");
int start2 = path.lastIndexOf("/"); int start2 = path.lastIndexOf("/");
...@@ -125,17 +140,21 @@ public class FileSystemContorller { ...@@ -125,17 +140,21 @@ public class FileSystemContorller {
.getContextClassLoader() .getContextClassLoader()
.getResourceAsStream("excelTemplates/" + path); .getResourceAsStream("excelTemplates/" + path);
FileUtil.copy(input, response.getOutputStream()); FileUtil.copy(input, response.getOutputStream());
return null;
} }
@GetMapping("/simpleUpload.do") /**
public ModelAndView simpleUploadPage(String uploadUrl, String templatePath, String fileType) * 通过文件批次操作id,返回文件列表信息
throws IOException { *
ModelAndView view = new ModelAndView("/common/simpleUpload.html"); * @author 一日看尽长安花
view.addObject("uploadUrl", uploadUrl); * @return JsonResult<List < LocalFileItem>>
view.addObject("templatePath", templatePath); */
view.addObject("fileType", fileType); @GetMapping("/items")
@ResponseBody
return view; public JsonResult<List<FileItem>> fileItemList(String fileBatchId) {
if (StrUtil.isBlank(fileBatchId)) {
return JsonResult.success();
}
List<FileItem> fileItems = fileService.queryByBatchId(fileBatchId);
return JsonResult.success(fileItems);
} }
} }
/*
* @Author: 一日看尽长安花
* @since: 2020-03-16 11:16:52
* @LastEditTime: 2020-03-16 13:13:31
* @LastEditors: 一日看尽长安花
* @Description:
*/
import request from '@/utils/request';
/**
* 一些常量
*/
export const IMG_MIME = 'image/*';
export const DOC_MIME =
'.doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document';
/**
* 手动上传附件
*/
export function uploadAttachment(data) {
return request({
url: '/core/file/uploadAttachment',
method: 'post',
data
});
}
/**
* 下载多附件中的一个附件
* @param {object} params 包含的参数:fileId,batchFileUUID
*/
export function downloadMutipleFile(params) {
const { fileId, batchFileUUID } = { ...params };
return request({
url: `/core/file/download/${fileId}/${batchFileUUID}`,
method: 'get'
});
}
/**
* 通过path下载单个文件
*
* @param {object} params 包含的参数:path
*/
export function download(params) {
return request({
url: '/core/file/download',
method: 'get',
params
});
}
/**
* 获取附件信息
* @param {object} params 包含fileBatchId
*/
export function getFileList(params) {
return request({
url: '/core/file/items',
method: 'get',
params
});
}
/* /*
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-09-04 20:55:14 * @since: 2019-09-04 20:55:14
* @LastEditTime : 2020-02-04 13:20:29 * @LastEditTime: 2020-03-15 10:59:27
* @LastEditors : 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: * @Description:
*/ */
import request from '@/utils/request'; import request from '@/utils/request';
...@@ -60,3 +60,11 @@ export function updateUserData(data) { ...@@ -60,3 +60,11 @@ export function updateUserData(data) {
data data
}); });
} }
export function deleteUserData(data) {
return request({
url: '/users',
method: 'delete',
data
});
}
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-10-12 16:14:37 * @since: 2019-10-12 16:14:37
* @LastEditTime : 2020-02-22 17:32:45 * @LastEditTime: 2020-03-16 16:01:20
* @LastEditors : 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: * @Description:
--> -->
<template> <template>
...@@ -145,7 +145,7 @@ export default { ...@@ -145,7 +145,7 @@ export default {
if (valType === 'date') { if (valType === 'date') {
val = parseTime(val / 1000, '{y}-{m}-{d} {h}:{i}:{s}'); val = parseTime(val / 1000, '{y}-{m}-{d} {h}:{i}:{s}');
} else if (valType === 'dict') { } else if (valType === 'dict') {
val = val.name; val = this.$lodash.get(val, 'name');
} }
return val; return val;
}, },
......
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-09-09 12:16:28 * @since: 2019-09-09 12:16:28
* @LastEditTime: 2019-10-27 00:01:53 * @LastEditTime: 2020-03-13 16:38:34
* @LastEditors: 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: 这个分页是直接从组件复制的,为了保证以后修改逻辑不影响其它的页面使用公共的分页。 * @Description: 这个分页是直接从组件复制的,为了保证以后修改逻辑不影响其它的页面使用公共的分页。
--> -->
<template> <template>
<div :class="{ hidden: hidden }" class="pagination-container"> <div :class="{ hidden: hidden }" class="pagination-container">
<el-pagination <el-pagination
ref="paginationGP"
:background="background" :background="background"
:current-page.sync="currentPage" :current-page.sync="currentPage"
:page-size.sync="pageSize" :page-size.sync="pageSize"
......
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-10-12 16:14:37 * @since: 2019-10-12 16:14:37
* @LastEditTime : 2020-02-05 17:00:21 * @LastEditTime: 2020-03-17 15:46:23
* @LastEditors : 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: * @Description:
--> -->
<template> <template>
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
<el-dialog <el-dialog
:fullscreen="true" :fullscreen="true"
:center="true" :center="true"
:destroy-on-close="true" :destroy-on-close="false"
:show-close="false"
:title="dialogTitle" :title="dialogTitle"
:visible="dialogVisible" :visible="dialogVisible"
:close-on-click-modal="false" :close-on-click-modal="false"
...@@ -134,17 +135,7 @@ export default { ...@@ -134,17 +135,7 @@ export default {
this.$refs['editForm'].validate(valid => { this.$refs['editForm'].validate(valid => {
if (valid) { if (valid) {
this.$emit('create-data', this.dialogData); this.$emit('create-data', this.dialogData);
/* 将回调延迟到下次 DOM 更新循环之后执行。
而数据更新就代表dom更新,所以如果创建成功,数据就会更新 */
this.$nextTick(() => {
this.$emit('update:dialogVisible', false); this.$emit('update:dialogVisible', false);
this.$notify({
title: '成功',
message: '添加成功',
type: 'success',
duration: 2000
});
});
} else { } else {
this.$notify({ this.$notify({
title: '失败', title: '失败',
...@@ -159,15 +150,7 @@ export default { ...@@ -159,15 +150,7 @@ export default {
this.$refs['editForm'].validate(valid => { this.$refs['editForm'].validate(valid => {
if (valid) { if (valid) {
this.$emit('update-data', this.dialogData); this.$emit('update-data', this.dialogData);
this.$nextTick(() => {
this.$emit('update:dialogVisible', false); this.$emit('update:dialogVisible', false);
this.$notify({
title: '成功',
message: '修改成功',
type: 'success',
duration: 2000
});
});
} else { } else {
this.$notify({ this.$notify({
title: '失败', title: '失败',
......
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-10-12 15:43:18 * @since: 2019-10-12 15:43:18
* @LastEditTime: 2020-03-06 16:02:51 * @LastEditTime: 2020-03-15 16:36:57
* @LastEditors: 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: 后台管理页面的自动生成, * @Description: 后台管理页面的自动生成,
* 主要暴露了分页方法、数据表格搜索方法、条件查询方法、增删改方法 * 主要暴露了分页方法、数据表格搜索方法、条件查询方法、增删改方法
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<template> <template>
<div> <div>
<search-pane <search-pane
ref="searchPaneGP"
:metadata="metadata" :metadata="metadata"
@filter-search="filterSearch" @filter-search="filterSearch"
@handle-create="handleCreate" @handle-create="handleCreate"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
</template> </template>
</search-pane> </search-pane>
<data-table <data-table
ref="dataTableGP"
:loading="loading" :loading="loading"
:metadata="metadata" :metadata="metadata"
:tabledata="tabledata" :tabledata="tabledata"
...@@ -29,9 +31,10 @@ ...@@ -29,9 +31,10 @@
@update:tabledata="$emit('update:tabledata', $event)" @update:tabledata="$emit('update:tabledata', $event)"
@pagination="pagination" @pagination="pagination"
@handle-edit="handleEdit" @handle-edit="handleEdit"
@delete-data="$emit('delete-data', $event)" @delete-data="deleteData"
></data-table> ></data-table>
<detail-page <detail-page
ref="detailPageGP"
:metadata="metadata" :metadata="metadata"
:dialog-visible.sync="dialogVisible" :dialog-visible.sync="dialogVisible"
:dialog-title="dialogTitle" :dialog-title="dialogTitle"
...@@ -119,6 +122,9 @@ export default { ...@@ -119,6 +122,9 @@ export default {
this.dialogTitle = '修改'; this.dialogTitle = '修改';
this.dialogVisible = true; this.dialogVisible = true;
this.dialogData = Object.assign({}, row); this.dialogData = Object.assign({}, row);
},
deleteData(index, row) {
this.$emit('delete-data', index, row);
} }
} }
}; };
......
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2020-03-08 11:03:14 * @since: 2020-03-08 11:03:14
* @LastEditTime: 2020-03-08 15:32:26 * @LastEditTime: 2020-03-17 20:54:30
* @LastEditors: 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: * @Description:
--> -->
<template> <template>
<el-upload <el-upload
:ref="refs" ref="upload"
:headers="headers" :headers="headers"
:multiple="multiple" :multiple="multiple"
:data="data" :data="data"
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
:before-remove="beforeRemove" :before-remove="beforeRemove"
:list-type="listType" :list-type="listType"
:auto-upload="autoUpload" :auto-upload="autoUpload"
:file-list="fileList" :file-list="fileList_d"
:http-request="httpRequest" :http-request="updateFiles"
:disabled="disabled" :disabled="disabled"
:limit="limit" :limit="limit"
:on-exceed="onExceed" :on-exceed="onExceed"
action="https://jsonplaceholder.typicode.com/posts/" action="/core/file/uploadAttachment"
> >
<template v-slot:default> <template v-slot:default>
<slot name="default"> </slot> <slot name="default"> </slot>
...@@ -45,13 +45,23 @@ ...@@ -45,13 +45,23 @@
</el-upload> </el-upload>
</template> </template>
<script> <script>
import { getFileList } from '@/api/file';
export default { export default {
name: 'FileUpload', name: 'FileUpload',
components: {}, components: {},
props: { props: {
refs: { fileBatchId: {
type: String, type: String,
default: 'fileUpload' default: null
},
bizType: {
type: String,
default: null
},
bizId: {
type: String,
default: null
}, },
headers: { headers: {
type: Object, type: Object,
...@@ -66,7 +76,11 @@ export default { ...@@ -66,7 +76,11 @@ export default {
data: { data: {
type: Object, type: Object,
default() { default() {
return undefined; return {
fileBatchId: this.fileBatchId,
bizType: this.bizType,
bizId: this.bizId
};
} }
}, },
name: { name: {
...@@ -143,17 +157,41 @@ export default { ...@@ -143,17 +157,41 @@ export default {
type: Function, type: Function,
default: undefined default: undefined
}, },
httpRequest: {
type: Function,
default: undefined
},
onExceed: { onExceed: {
type: Function, type: Function,
default: undefined default: undefined
} }
}, },
data() { data() {
return {}; return {
fileList_d: this.fileList
};
},
watch: {
fileBatchId: {
immediate: true,
deep: true,
handler: function(newVal, oldVal) {
/** 只有当文件操作批次id与上一次不一样时进入 */
this.loadFilelItems();
}
}
},
methods: {
loadFilelItems() {
if (!this.fileBatchId || this.fileBatchId.trim().length <= 0) {
this.fileList_d = [];
return;
}
getFileList({ fileBatchId: this.fileBatchId }).then(res => {
const { code, data } = { ...res };
this.fileList_d = data || [];
});
},
updateFiles(params) {
debugger;
console.log(params);
}
} }
}; };
</script> </script>
<!-- <!--
* @Author: 一日看尽长安花 * @Author: 一日看尽长安花
* @since: 2019-10-12 15:43:18 * @since: 2019-10-12 15:43:18
* @LastEditTime: 2020-03-11 15:30:15 * @LastEditTime: 2020-03-17 18:11:53
* @LastEditors: 一日看尽长安花 * @LastEditors: 一日看尽长安花
* @Description: * @Description:
--> -->
...@@ -104,11 +104,20 @@ ...@@ -104,11 +104,20 @@
</el-form-item> </el-form-item>
<el-form-item key="fileKey" label="上传文档" prop="file"> <el-form-item key="fileKey" label="上传文档" prop="file">
<file-upload> <file-upload
ref="fileUpload"
:file-batch-id="dialogData.attachment_id"
:on-success="onUploadSuccess"
>
<el-button slot="trigger" size="small" type="primary"> <el-button slot="trigger" size="small" type="primary">
选取文件 选取文件
</el-button> </el-button>
<el-button style="margin-left: 10px;" size="small" type="success"> <el-button
style="margin-left: 10px;"
size="small"
type="success"
@click="submitUpload"
>
上传到服务器 上传到服务器
</el-button> </el-button>
<div slot="tip" class="el-upload__tip"> <div slot="tip" class="el-upload__tip">
...@@ -125,7 +134,13 @@ ...@@ -125,7 +134,13 @@
import GeneralPage from '@/components/GeneralPage'; import GeneralPage from '@/components/GeneralPage';
import FileUpload from '@/components/Upload/FileUpload'; import FileUpload from '@/components/Upload/FileUpload';
import { users, usersMetadata, saveUserData, updateUserData } from '@/api/user'; import {
users,
usersMetadata,
saveUserData,
updateUserData,
deleteUserData
} from '@/api/user';
import { immaditeLoadDicts } from '@/api/dict'; import { immaditeLoadDicts } from '@/api/dict';
import { immaditeLoadOrgs } from '@/api/org'; import { immaditeLoadOrgs } from '@/api/org';
import { layzyLoadDictTree, handleCascaderValue } from '@/services/dict'; import { layzyLoadDictTree, handleCascaderValue } from '@/services/dict';
...@@ -205,6 +220,7 @@ export default { ...@@ -205,6 +220,7 @@ export default {
'job_type1' 'job_type1'
]); ]);
queryParams = handleCascaderValue(queryParams, 'state', ['state']); queryParams = handleCascaderValue(queryParams, 'state', ['state']);
const _lodash = this.$lodash;
users(queryParams) users(queryParams)
.then(result => { .then(result => {
const { code, data } = { ...result }; const { code, data } = { ...result };
...@@ -213,15 +229,14 @@ export default { ...@@ -213,15 +229,14 @@ export default {
* 所以将其处理为一级节点 * 所以将其处理为一级节点
*/ */
for (let i in result.data) { for (let i in result.data) {
result.data[i]['org_id_value'] = result.data[i]['org']['id']; let item = result.data[i];
result.data[i]['state_value'] = result.data[i]['state']['value']; item['org_id_value'] = _lodash.get(item, 'org.id');
if (result.data[i]['job_type0']) { item['state_value'] = _lodash.get(item, 'state.value');
result.data[i]['job_type_value'] = if (item['job_type0']) {
result.data[i]['job_type0']['value']; item['job_type_value'] = _lodash.get(item, 'job_type0.value');
} }
if (result.data[i]['job_type1']) { if (item['job_type1']) {
result.data[i]['job_type_value'] = item['job_type_value'] = _lodash.get(item, 'job_type1.value');
result.data[i]['job_type1']['value'];
} }
} }
this.tabledata = Object.assign({}, result); this.tabledata = Object.assign({}, result);
...@@ -243,18 +258,20 @@ export default { ...@@ -243,18 +258,20 @@ export default {
this.obtainData(Object.assign({ page: 1, limit: 10 }, queryParams)); this.obtainData(Object.assign({ page: 1, limit: 10 }, queryParams));
}, },
createData(dialogData) { createData(dialogData) {
this.handleEditorDataObject(dialogData, 'org_id_value', { dialogData = this.handleEditorDataObject(dialogData, 'org_id_value', {
org_id: 'org.id' org_id: 'org.id'
}); });
this.handleEditorDataObject(dialogData, 'state_value', { dialogData = this.handleEditorDataObject(dialogData, 'state_value', {
state: 'state.value' state: 'state.value'
}); });
this.handleEditorDataObject(dialogData, 'job_type_value', { dialogData = this.handleEditorDataObject(dialogData, 'job_type_value', {
job_type0: 'job_type0.value', job_type0: 'job_type0.value',
job_type1: 'job_type1.value' job_type1: 'job_type1.value'
}); });
const Vue = this;
saveUserData(dialogData) saveUserData(dialogData)
.then(result => { .then(result => {
Vue.$children[0].$refs.searchPaneGP.$refs.searchButton.$emit('click');
this.$nextTick(() => { this.$nextTick(() => {
this.$notify({ this.$notify({
title: '成功', title: '成功',
...@@ -276,23 +293,29 @@ export default { ...@@ -276,23 +293,29 @@ export default {
}); });
}, },
updateData(dialogData) { updateData(dialogData) {
this.handleEditorDataObject(dialogData, 'org_id_value', { dialogData = this.handleEditorDataObject(dialogData, 'org_id_value', {
org_id: 'org.id' org_id: 'org.id'
}); });
this.handleEditorDataObject(dialogData, 'state_value', { dialogData = this.handleEditorDataObject(dialogData, 'state_value', {
state: 'state.value' state: 'state.value'
}); });
this.handleEditorDataObject(dialogData, 'job_type_value', { dialogData = this.handleEditorDataObject(dialogData, 'job_type_value', {
job_type0: 'job_type0.value', job_type0: 'job_type0.value',
job_type1: 'job_type1.value' job_type1: 'job_type1.value'
}); });
const Vue = this;
updateUserData(dialogData) updateUserData(dialogData)
.then(result => { .then(result => {
this.$refs['searchButton'].click(); /** 刷新数据表格数据,懒得重新写个方法挂载在组件上了 */
Vue.$children[0].$refs.searchPaneGP.$refs.searchButton.$emit('click');
/**
* 将回调延迟到下次 DOM 更新循环之后执行。
* 而数据更新就代表dom更新,所以如果创建成功,数据就会更新
*/
this.$nextTick(() => { this.$nextTick(() => {
this.$notify({ this.$notify({
title: '成功', title: '成功',
message: '修改成功', message: '修改成功1',
type: 'success', type: 'success',
duration: 2000 duration: 2000
}); });
...@@ -302,7 +325,7 @@ export default { ...@@ -302,7 +325,7 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.$notify({ this.$notify({
title: '失败', title: '失败',
message: '修改失败', message: '修改用户失败',
type: 'error', type: 'error',
duration: 2000 duration: 2000
}); });
...@@ -322,16 +345,43 @@ export default { ...@@ -322,16 +345,43 @@ export default {
dialogData[key] = this.$lodash.get(dialogData, keyPathMap[key]); dialogData[key] = this.$lodash.get(dialogData, keyPathMap[key]);
} }
} }
return dialogData;
}, },
deleteData(index, row) { deleteData(index, row) {
deleteUserData({ ids: [row.id] })
.then(result => {
/** 刷新数据表格数据,懒得重新写个方法挂载在组件上了 */
Vue.$children[0].$refs.searchPaneGP.$refs.searchButton.$emit('click');
/**
* 将回调延迟到下次 DOM 更新循环之后执行。
* 而数据更新就代表dom更新,所以如果创建成功,数据就会更新
*/
this.$nextTick(() => { this.$nextTick(() => {
this.$notify({ this.$notify({
title: '成功', title: '成功',
message: '删除成功', message: '删除用户成功',
type: 'success', type: 'success',
duration: 2000 duration: 2000
}); });
}); });
})
.catch(err => {
this.$nextTick(() => {
this.$notify({
title: '失败',
message: '删除用户失败',
type: 'error',
duration: 2000
});
});
});
},
submitUpload() {
debugger;
this.$refs.fileUpload.$refs.upload.submit();
},
onUploadSuccess(response, file, fileList) {
debugger;
} }
} }
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment