|
|
@ -4,16 +4,16 @@ import cn.estsh.i3plus.core.api.iservice.busi.*;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.FileTool;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ZipTool;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.FileContentTypeTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserExportModel;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
@ -25,6 +25,7 @@ import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -32,10 +33,14 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
import java.io.File;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description : 用户信息 服务
|
|
|
|
* @Description : 用户信息 服务
|
|
|
@ -64,15 +69,6 @@ public class SysUserInfoController extends CoreBaseController{
|
|
|
|
private ISysPositionService positionService;
|
|
|
|
private ISysPositionService positionService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ISysConfigService sysConfigService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ISysFileService sysFileService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ISysMessageService sysMessageService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -81,6 +77,9 @@ public class SysUserInfoController extends CoreBaseController{
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IPersonnelService personnelService;
|
|
|
|
private IPersonnelService personnelService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource(name= CommonConstWords.IMPP_REDIS_RES)
|
|
|
|
@Resource(name= CommonConstWords.IMPP_REDIS_RES)
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -405,95 +404,61 @@ public class SysUserInfoController extends CoreBaseController{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@GetMapping("/export")
|
|
|
|
* 导出用户信息
|
|
|
|
@ApiOperation(value = "导出用户信息",notes = "导出用户信息")
|
|
|
|
* @param sysUserInfo 用户信息
|
|
|
|
public void exportSysUserInfo(SysUserInfo sysUserInfo, HttpServletResponse response) throws Exception {
|
|
|
|
* @param colName 导出列
|
|
|
|
File file = null;
|
|
|
|
* @param pageSize 页大小
|
|
|
|
|
|
|
|
* @param isZip 是否发展邮件
|
|
|
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@GetMapping(value = "/export")
|
|
|
|
|
|
|
|
@ApiOperation(value = "导出用户信息")
|
|
|
|
|
|
|
|
public ResultBean exportSysUserInfo(SysUserInfo sysUserInfo, String[] colName, int pageSize,boolean isZip) {
|
|
|
|
|
|
|
|
ListPager listPager;
|
|
|
|
|
|
|
|
List result = new ArrayList();
|
|
|
|
|
|
|
|
File zipFile = null;
|
|
|
|
|
|
|
|
File excelDir = null;
|
|
|
|
|
|
|
|
File excelFile;
|
|
|
|
|
|
|
|
ExcelTool excelTool;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
List<SysUserInfo> list = sysUserInfoService.findSysUserInfoList(sysUserInfo);
|
|
|
|
Pager pager = new Pager();
|
|
|
|
Map<Long, SysUser> sysUserMap = sysUserService.list().stream()
|
|
|
|
pager.setCurrentPage(1);
|
|
|
|
.collect(Collectors.toMap(SysUser::getId, Function.identity()));
|
|
|
|
// 判断是否超过excel最大导出数量设定值
|
|
|
|
List<UserExportModel> exportModelList = new ArrayList<>();
|
|
|
|
int maxPageSize = Integer.parseInt(sysConfigService.getSysConfigByCode(PlatformConstWords.EXCEL_EXPORT_MAX_ROW).getConfigValue());
|
|
|
|
|
|
|
|
if (pageSize == 0 || pageSize >= maxPageSize) {
|
|
|
|
|
|
|
|
pager.setPageSize(maxPageSize);
|
|
|
|
UserExportModel userExportModel;
|
|
|
|
} else {
|
|
|
|
List<SysRefUserRole> sysRefUserRoleList;
|
|
|
|
pager.setPageSize(pageSize);
|
|
|
|
StringBuffer roleName = new StringBuffer();
|
|
|
|
}
|
|
|
|
for (SysUserInfo userInfo : list) {
|
|
|
|
|
|
|
|
// 关联角色信息
|
|
|
|
|
|
|
|
sysRefUserRoleList = sysUserService.findSysRefUserRoleByUserId(userInfo.getUserId());
|
|
|
|
|
|
|
|
for (SysRefUserRole sysRefUserRole : sysRefUserRoleList) {
|
|
|
|
|
|
|
|
roleName.append(sysRefUserRole.getRoleNameRdd()).append(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
roleName.setLength(roleName.length() - 1);
|
|
|
|
|
|
|
|
|
|
|
|
// 数据校验
|
|
|
|
// 封装model
|
|
|
|
if(colName==null || colName.length == 0){
|
|
|
|
userExportModel = new UserExportModel(sysUserMap.get(userInfo.getUserId()), userInfo);
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
userExportModel.setRoleNameRdd(roleName.toString());
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
|
|
|
|
exportModelList.add(userExportModel);
|
|
|
|
.setErrorDetail("导出列不能为空")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
excelDir = new File(System.getProperty("java.io.tmpdir") + File.separator + new Date().getTime());
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
excelDir.mkdir();
|
|
|
|
String fileName = "user-info-" + System.currentTimeMillis() + ".xls";
|
|
|
|
do {
|
|
|
|
file = new File(fileName);
|
|
|
|
listPager = sysUserInfoService.querySysUserInfo(sysUserInfo, pager);
|
|
|
|
file.createNewFile();
|
|
|
|
pager = listPager.getObjectPager();
|
|
|
|
File excle = excelTool.exportData(file, exportModelList, UserExportModel.class
|
|
|
|
|
|
|
|
, (LinkedHashMap<String, String>) ExcelTool.getColName(UserExportModel.class));
|
|
|
|
// 将excel导出至临时文件夹并上传
|
|
|
|
|
|
|
|
excelFile = new File(excelDir + File.separator + SysUserInfo.class.getSimpleName() + pager.getCurrentPage() + ".xls");
|
|
|
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
|
|
|
excelFile.createNewFile();
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名
|
|
|
|
|
|
|
|
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName,true)));
|
|
|
|
excelTool.exportData(excelFile, listPager.getObjectList(), SysUserInfo.class, colName);
|
|
|
|
|
|
|
|
result.add(sysFileService.uploadFile(excelFile));
|
|
|
|
// 设置文件名
|
|
|
|
|
|
|
|
try (BufferedInputStream bis = new BufferedInputStream(new DataInputStream(new FileInputStream(excle)))) {
|
|
|
|
pager.setCurrentPage(pager.getCurrentPage() + 1);
|
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
|
} while (pager.getCurrentPage() <= pager.getTotalPages());
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
|
|
int i = bis.read(buffer);
|
|
|
|
// 将所有excel文件打包
|
|
|
|
while (i != -1) {
|
|
|
|
if(isZip){
|
|
|
|
os.write(buffer, 0, i);
|
|
|
|
zipFile = ZipTool.zipFile(null, excelDir);
|
|
|
|
i = bis.read(buffer);
|
|
|
|
result.add(sysFileService.uploadFile(zipFile));
|
|
|
|
}
|
|
|
|
sysMessageService.doSendSysMessage(ExcelTool.sendStationLetter(result,getSessionUser().getUser().getId()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(result);
|
|
|
|
e.printStackTrace();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
// 清理临时文件文件
|
|
|
|
FileUtils.deleteQuietly(file);
|
|
|
|
if(excelDir != null){
|
|
|
|
|
|
|
|
FileTool.deleteFile(excelDir.getPath());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取用户可导出字段
|
|
|
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@GetMapping("/get-col")
|
|
|
|
|
|
|
|
@ApiOperation(value = "获取用户可导出字段")
|
|
|
|
|
|
|
|
public ResultBean getSysUserInfoColName(){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultMap(ExcelTool.getColName(SysUserInfo.class));
|
|
|
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|