【更新】完成用户导出功能
This commit is contained in:
parent
2f566b2d1a
commit
0ccaf15f40
@ -259,12 +259,27 @@ public class SysUserController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户导入
|
||||
* 下载用户导入模板
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 15)
|
||||
@ApiOperation("下载用户导入模板")
|
||||
@CommonLog("下载用户导入模板")
|
||||
@PostMapping(value = "/sys/user/downloadImportUserTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public CommonResult<String> downloadImportUserTemplate(HttpServletResponse response) throws IOException {
|
||||
sysUserService.downloadImportUserTemplate(response);
|
||||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户导入
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 16)
|
||||
@ApiOperation("用户导入")
|
||||
@CommonLog("用户导入")
|
||||
@PostMapping("/sys/user/import")
|
||||
@ -279,7 +294,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 16)
|
||||
@ApiOperationSupport(order = 17)
|
||||
@ApiOperation("用户导出")
|
||||
@CommonLog("用户导出")
|
||||
@GetMapping(value = "/sys/user/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
@ -287,6 +302,20 @@ public class SysUserController {
|
||||
sysUserService.exportUser(sysUserExportParam, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按模板导出用户个人信息
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 18)
|
||||
@ApiOperation("导出用户个人信息")
|
||||
@CommonLog("导出用户个人信息")
|
||||
@GetMapping(value = "/sys/user/exportUserInfo", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public void exportUserInfo(SysUserIdParam sysUserIdParam, HttpServletResponse response) throws IOException {
|
||||
sysUserService.exportUserInfo(sysUserIdParam, response);
|
||||
}
|
||||
|
||||
/* ====用户部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
@ -295,7 +324,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 17)
|
||||
@ApiOperationSupport(order = 19)
|
||||
@ApiOperation("获取组织树选择器")
|
||||
@GetMapping("/sys/user/orgTreeSelector")
|
||||
public CommonResult<List<Tree<String>>> orgTreeSelector() {
|
||||
@ -308,7 +337,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 18)
|
||||
@ApiOperationSupport(order = 20)
|
||||
@ApiOperation("获取组织列表选择器")
|
||||
@GetMapping("/sys/user/orgListSelector")
|
||||
public CommonResult<List<SysOrg>> orgListSelector(SysUserSelectorOrgListParam sysUserSelectorOrgListParam) {
|
||||
@ -321,7 +350,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 19)
|
||||
@ApiOperationSupport(order = 21)
|
||||
@ApiOperation("获取职位选择器")
|
||||
@GetMapping("/sys/user/positionSelector")
|
||||
public CommonResult<List<SysPosition>> positionSelector(SysUserSelectorPositionParam sysUserSelectorPositionParam) {
|
||||
@ -334,7 +363,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 20)
|
||||
@ApiOperationSupport(order = 22)
|
||||
@ApiOperation("获取角色选择器")
|
||||
@GetMapping("/sys/user/roleSelector")
|
||||
public CommonResult<List<SysRole>> roleSelector(SysUserSelectorRoleParam sysUserSelectorRoleParam) {
|
||||
@ -347,7 +376,7 @@ public class SysUserController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 21)
|
||||
@ApiOperationSupport(order = 23)
|
||||
@ApiOperation("获取用户选择器")
|
||||
@GetMapping("/sys/user/userSelector")
|
||||
public CommonResult<List<SysUser>> userSelector(SysUserSelectorUserParam sysUserSelectorUserParam) {
|
||||
|
@ -266,14 +266,17 @@ public class SysUser extends CommonEntity implements TransPojo {
|
||||
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
|
||||
private String extJson;
|
||||
|
||||
/** 组织名称 */
|
||||
@ApiModelProperty(value = "组织名称", position = 48)
|
||||
@TableField(exist = false)
|
||||
private String orgName;
|
||||
|
||||
/** 职位名称 */
|
||||
@ApiModelProperty(value = "职位名称", position = 49)
|
||||
@TableField(exist = false)
|
||||
private String positionName;
|
||||
|
||||
/** 主管名称 */
|
||||
@ApiModelProperty(value = "主管名称", position = 50)
|
||||
@TableField(exist = false)
|
||||
private String directorName;
|
||||
|
@ -340,6 +340,14 @@ public interface SysUserService extends IService<SysUser> {
|
||||
**/
|
||||
List<JSONObject> getPermissionList(List<String> userAndRoleIdList, String orgId);
|
||||
|
||||
/**
|
||||
* 下载用户导入模板
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/8/8 13:16
|
||||
**/
|
||||
void downloadImportUserTemplate(HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 用户导入
|
||||
*
|
||||
@ -356,6 +364,14 @@ public interface SysUserService extends IService<SysUser> {
|
||||
**/
|
||||
void exportUser(SysUserExportParam sysUserExportParam, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 导出用户个人信息
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/8/8 13:16
|
||||
**/
|
||||
void exportUserInfo(SysUserIdParam sysUserIdParam, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 获取登录用户的职位信息
|
||||
*
|
||||
|
@ -12,6 +12,9 @@
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.user.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.cache.manager.POICacheManager;
|
||||
import cn.afterturn.easypoi.entity.ImageEntity;
|
||||
import cn.afterturn.easypoi.word.WordExportUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
@ -19,9 +22,12 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||
@ -51,6 +57,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fhs.trans.service.impl.TransService;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -94,8 +101,10 @@ import vip.xiaonuo.sys.modular.user.service.SysUserService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -958,6 +967,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadImportUserTemplate(HttpServletResponse response) throws IOException {
|
||||
try {
|
||||
InputStream inputStream = POICacheManager.getFile("userImportTemplate.xlsx");
|
||||
byte[] bytes = IoUtil.readBytes(inputStream);
|
||||
CommonDownloadUtil.download("SNOWY2.0系统B端用户导入模板.xlsx", bytes, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CommonResponseUtil.renderError(response, "导出失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importUser(MultipartFile file) {
|
||||
// TODO
|
||||
@ -1089,6 +1110,47 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportUserInfo(SysUserIdParam sysUserIdParam, HttpServletResponse response) throws IOException {
|
||||
File destTemplateFile = null;
|
||||
File resultFile = null;
|
||||
try {
|
||||
SysUser sysUser = this.queryEntity(sysUserIdParam.getId());
|
||||
transService.transOne(sysUser);
|
||||
// 读取模板流
|
||||
InputStream inputStream = POICacheManager.getFile("userExportTemplate.docx");
|
||||
// 创建一个临时模板
|
||||
destTemplateFile = FileUtil.writeFromStream(inputStream, FileUtil.file(FileUtil.getTmpDir() +
|
||||
File.separator + "userExportTemplate.docx"));
|
||||
// 构造填充的参数
|
||||
Map<String, Object> map = BeanUtil.beanToMap(sysUser);
|
||||
map.put("avatar", new ImageEntity(ImgUtil.toBytes(ImgUtil.toImage(StrUtil.split(sysUser.getAvatar(),
|
||||
StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG), 120, 160));
|
||||
map.put("exportDateTime", DateUtil.format(DateTime.now(), DatePattern.CHINESE_DATE_PATTERN));
|
||||
// 生成doc
|
||||
XWPFDocument doc = WordExportUtil.exportWord07(destTemplateFile.getAbsolutePath(), map);
|
||||
// 生成临时导出文件
|
||||
resultFile = FileUtil.file(FileUtil.getTmpDir() + File.separator + sysUser.getName() + "个人信息.docx");
|
||||
// 写入
|
||||
BufferedOutputStream outputStream = FileUtil.getOutputStream(resultFile);
|
||||
doc.write(outputStream);
|
||||
outputStream.close();
|
||||
// 下载
|
||||
CommonDownloadUtil.download(resultFile, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CommonResponseUtil.renderError(response, "导出失败");
|
||||
} finally {
|
||||
// 删除临时文件
|
||||
if(ObjectUtil.isNotEmpty(destTemplateFile)) {
|
||||
FileUtil.del(destTemplateFile);
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(resultFile)) {
|
||||
FileUtil.del(resultFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserPositionResult> loginPositionInfo(SysUserIdParam sysUserIdParam) {
|
||||
SysUser sysUser = this.queryEntity(sysUserIdParam.getId());
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user