feat 管理员增加导出Excel功能
This commit is contained in:
parent
78786abb01
commit
b09199ae53
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mdd.admin.controller.system;
|
package com.mdd.admin.controller.system;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.mdd.admin.LikeAdminThreadLocal;
|
import com.mdd.admin.LikeAdminThreadLocal;
|
||||||
import com.mdd.admin.aop.Log;
|
import com.mdd.admin.aop.Log;
|
||||||
import com.mdd.common.aop.NotPower;
|
import com.mdd.common.aop.NotPower;
|
||||||
|
|
@ -15,6 +16,7 @@ import com.mdd.admin.vo.system.SystemAuthAdminListedVo;
|
||||||
import com.mdd.admin.vo.system.SystemAuthAdminSelvesVo;
|
import com.mdd.admin.vo.system.SystemAuthAdminSelvesVo;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
|
import com.mdd.common.util.StringUtils;
|
||||||
import com.mdd.common.validator.annotation.IDMust;
|
import com.mdd.common.validator.annotation.IDMust;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
@ -33,10 +35,20 @@ public class SystemAuthAdminController {
|
||||||
|
|
||||||
@GetMapping("/lists")
|
@GetMapping("/lists")
|
||||||
@ApiOperation(value="管理员列表")
|
@ApiOperation(value="管理员列表")
|
||||||
public AjaxResult<PageResult<SystemAuthAdminListedVo>> list(@Validated PageValidate pageValidate,
|
public AjaxResult<Object> list(@Validated PageValidate pageValidate,
|
||||||
@Validated SystemAdminSearchValidate searchValidate) {
|
@Validated SystemAdminSearchValidate searchValidate) {
|
||||||
PageResult<SystemAuthAdminListedVo> list = iSystemAuthAdminService.list(pageValidate, searchValidate);
|
if (StringUtils.isNotNull(searchValidate.getExport()) && searchValidate.getExport().equals(1)) {
|
||||||
return AjaxResult.success(list);
|
JSONObject ret = iSystemAuthAdminService.getExportData(pageValidate, searchValidate);
|
||||||
|
return AjaxResult.success(ret);
|
||||||
|
} else if (StringUtils.isNotNull(searchValidate.getExport()) && searchValidate.getExport().equals(2)) {
|
||||||
|
String path = iSystemAuthAdminService.export(searchValidate);
|
||||||
|
return AjaxResult.success(new JSONObject() {{
|
||||||
|
put("url", path);
|
||||||
|
}});
|
||||||
|
} else {
|
||||||
|
PageResult<SystemAuthAdminListedVo> list = iSystemAuthAdminService.list(pageValidate, searchValidate);
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotPower
|
@NotPower
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mdd.admin.service.admin;
|
package com.mdd.admin.service.admin;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.mdd.admin.validate.commons.PageValidate;
|
import com.mdd.admin.validate.commons.PageValidate;
|
||||||
import com.mdd.admin.validate.system.SystemAdminCreateValidate;
|
import com.mdd.admin.validate.system.SystemAdminCreateValidate;
|
||||||
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
||||||
|
|
@ -94,4 +95,15 @@ public interface IAdminService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AdminMySelfVo mySelf(Integer id, List<Integer> roleIds);
|
AdminMySelfVo mySelf(Integer id, List<Integer> roleIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回导出格式
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
JSONObject getExportData(PageValidate pageValidate, SystemAdminSearchValidate searchValidate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出
|
||||||
|
*/
|
||||||
|
String export(SystemAdminSearchValidate searchValidate);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
package com.mdd.admin.service.impl.admin;
|
package com.mdd.admin.service.impl.admin;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
|
|
@ -14,9 +17,12 @@ import com.mdd.admin.validate.system.SystemAdminCreateValidate;
|
||||||
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
||||||
import com.mdd.admin.validate.system.SystemAdminUpInfoValidate;
|
import com.mdd.admin.validate.system.SystemAdminUpInfoValidate;
|
||||||
import com.mdd.admin.validate.system.SystemAdminUpdateValidate;
|
import com.mdd.admin.validate.system.SystemAdminUpdateValidate;
|
||||||
|
import com.mdd.admin.validate.user.UserSearchValidate;
|
||||||
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
||||||
import com.mdd.admin.vo.auth.AuthMySelfVo;
|
import com.mdd.admin.vo.auth.AuthMySelfVo;
|
||||||
import com.mdd.admin.vo.system.*;
|
import com.mdd.admin.vo.system.*;
|
||||||
|
import com.mdd.admin.vo.user.UserListExportVo;
|
||||||
|
import com.mdd.admin.vo.user.UserVo;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
import com.mdd.common.entity.admin.Admin;
|
import com.mdd.common.entity.admin.Admin;
|
||||||
import com.mdd.common.entity.admin.Dept;
|
import com.mdd.common.entity.admin.Dept;
|
||||||
|
|
@ -34,6 +40,7 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -505,4 +512,136 @@ public class AdminServiceImpl implements IAdminService {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject getExportData(PageValidate pageValidate, SystemAdminSearchValidate searchValidate) {
|
||||||
|
Integer page = pageValidate.getPage_no();
|
||||||
|
Integer limit = pageValidate.getPage_size();
|
||||||
|
PageResult<SystemAuthAdminListedVo> userVoPageResult = this.list(pageValidate, searchValidate);
|
||||||
|
JSONObject ret = ToolUtils.getExportData(userVoPageResult.getCount(), limit, searchValidate.getPage_start(), searchValidate.getPage_end(),"管理员记录列表");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String export(SystemAdminSearchValidate searchValidate) {
|
||||||
|
PageValidate pageValidate = new PageValidate();
|
||||||
|
if (StringUtils.isNotNull(searchValidate.getPage_start())) {
|
||||||
|
pageValidate.setPage_no(searchValidate.getPage_start());
|
||||||
|
} else {
|
||||||
|
pageValidate.setPage_no(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotNull(searchValidate.getPage_end()) && StringUtils.isNotNull(searchValidate.getPage_size())) {
|
||||||
|
pageValidate.setPage_size(searchValidate.getPage_end() * searchValidate.getPage_size());
|
||||||
|
} else {
|
||||||
|
pageValidate.setPage_size(20);
|
||||||
|
}
|
||||||
|
Boolean isAll = StringUtils.isNull(searchValidate.getPage_type()) || searchValidate.getPage_type().equals(0) ? true : false;
|
||||||
|
List<SystemAuthAdminListedExportVo> excellist = this.getExcellist(isAll, pageValidate, searchValidate);
|
||||||
|
String fileName = StringUtils.isNull(searchValidate.getFile_name()) ? ToolUtils.makeUUID() : searchValidate.getFile_name();
|
||||||
|
String folderPath = "/excel/export/"+ TimeUtils.timestampToDay(System.currentTimeMillis() / 1000) +"/" ;
|
||||||
|
String path = folderPath + fileName +".xlsx";
|
||||||
|
String filePath = YmlUtils.get("like.upload-directory") + path;
|
||||||
|
File folder = new File(YmlUtils.get("like.upload-directory") + folderPath);
|
||||||
|
if (!folder.exists()) {
|
||||||
|
if (!folder.mkdirs()) {
|
||||||
|
throw new OperateException("创建文件夹失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EasyExcel.write(filePath)
|
||||||
|
.head(SystemAuthAdminListedExportVo.class)
|
||||||
|
.excelType(ExcelTypeEnum.XLSX)
|
||||||
|
.sheet("管理员记录")
|
||||||
|
.doWrite(excellist);
|
||||||
|
return UrlUtils.toAbsoluteUrl(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SystemAuthAdminListedExportVo> getExcellist(boolean isAll, PageValidate pageValidate, SystemAdminSearchValidate searchValidate) {
|
||||||
|
Integer page = pageValidate.getPage_no();
|
||||||
|
Integer limit = pageValidate.getPage_size();
|
||||||
|
|
||||||
|
MPJQueryWrapper<Admin> mpjQueryWrapper = new MPJQueryWrapper<>();
|
||||||
|
mpjQueryWrapper.select("distinct t.id,t.account,t.name,t.avatar," +
|
||||||
|
"t.multipoint_login," +
|
||||||
|
"t.disable,t.login_ip,t.login_time,t.create_time,t.update_time")
|
||||||
|
.leftJoin("la_admin_role lar ON lar.admin_id = t.id")
|
||||||
|
.isNull("t.delete_time")
|
||||||
|
.orderByDesc(Arrays.asList("t.id"));
|
||||||
|
|
||||||
|
|
||||||
|
systemAuthAdminMapper.setSearch(mpjQueryWrapper, searchValidate, new String[]{
|
||||||
|
"like:account:str",
|
||||||
|
"like:name:str"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (StringUtils.isNotNull(searchValidate.getRole_id())) {
|
||||||
|
mpjQueryWrapper.in("lar.role_id", searchValidate.getRole_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SystemAuthAdminListedExportVo> retList = new ArrayList<>();
|
||||||
|
if (isAll) {
|
||||||
|
retList = systemAuthAdminMapper.selectJoinList(SystemAuthAdminListedExportVo.class, mpjQueryWrapper);
|
||||||
|
} else {
|
||||||
|
IPage<SystemAuthAdminListedExportVo> iPage = systemAuthAdminMapper.selectJoinPage(
|
||||||
|
new Page<>(page, limit),
|
||||||
|
SystemAuthAdminListedExportVo.class,
|
||||||
|
mpjQueryWrapper);
|
||||||
|
retList = iPage.getRecords();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SystemAuthAdminListedExportVo vo : retList) {
|
||||||
|
if (vo.getId().equals(1)) {
|
||||||
|
vo.setRoleName("系统管理员");
|
||||||
|
vo.setDeptName("-");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
List<SystemRole> roles = systemAuthRoleMapper.getByAdminId(vo.getId());
|
||||||
|
List<Integer> roleIds = new ArrayList<>();
|
||||||
|
List<String> roleNames = new ArrayList<>();
|
||||||
|
if (!roles.isEmpty()) {
|
||||||
|
roles.forEach(item-> {
|
||||||
|
roleIds.add(item.getId());
|
||||||
|
roleNames.add(item.getName());
|
||||||
|
|
||||||
|
});
|
||||||
|
vo.setRoleId(roleIds);
|
||||||
|
vo.setRoleName(StringUtils.join(roleNames, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<Jobs> jobs = jobsMapper.getByAdminId(vo.getId());
|
||||||
|
List<Integer> jobsId = new ArrayList<>();
|
||||||
|
List<String> jobsNames = new ArrayList<>();
|
||||||
|
if (!jobs.isEmpty()) {
|
||||||
|
jobs.forEach(item-> {
|
||||||
|
jobsId.add(item.getId());
|
||||||
|
jobsNames.add(item.getName());
|
||||||
|
});
|
||||||
|
vo.setJobsId(jobsId);
|
||||||
|
vo.setJobsName(StringUtils.join(jobsNames, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<Dept> depts = deptMapper.getByAdminId(vo.getId());
|
||||||
|
List<Integer> deptIds = new ArrayList<>();
|
||||||
|
List<String> deptNames = new ArrayList<>();
|
||||||
|
if (!depts.isEmpty()) {
|
||||||
|
depts.forEach(item-> {
|
||||||
|
deptIds.add(item.getId());
|
||||||
|
deptNames.add(item.getName());
|
||||||
|
});
|
||||||
|
vo.setDeptId(deptIds);
|
||||||
|
vo.setDeptName(StringUtils.join(deptNames, ","));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vo.setDisableDesc(vo.getDisable() != null && vo.getDisable().equals(0) ? "启用" : "禁用");
|
||||||
|
vo.setAvatar(UrlUtils.toAbsoluteUrl(vo.getAvatar()));
|
||||||
|
vo.setCreateTime(TimeUtils.timestampToDate(vo.getCreateTime()));
|
||||||
|
vo.setUpdateTime(TimeUtils.timestampToDate(vo.getUpdateTime()));
|
||||||
|
vo.setLoginTime(TimeUtils.timestampToDate(vo.getLoginTime()));
|
||||||
|
}
|
||||||
|
return retList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,21 @@ public class SystemAdminSearchValidate implements Serializable {
|
||||||
@ApiModelProperty(value = "角色ID")
|
@ApiModelProperty(value = "角色ID")
|
||||||
private Integer role_id;
|
private Integer role_id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "导出信息")
|
||||||
|
private Integer export;
|
||||||
|
@ApiModelProperty(value = "file_name")
|
||||||
|
private String file_name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "page_start")
|
||||||
|
private Integer page_start;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "page_end")
|
||||||
|
private Integer page_end;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "page_size")
|
||||||
|
private Integer page_size;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "page_type")
|
||||||
|
private Integer page_type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import lombok.Data;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ApiModel("系统岗位Vo")
|
@ApiModel("系统岗位导出Vo")
|
||||||
public class JobsExportVo implements Serializable {
|
public class JobsExportVo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.mdd.admin.vo.system;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("管理员导出列表Vo")
|
||||||
|
public class SystemAuthAdminListedExportVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键")
|
||||||
|
@ExcelProperty("主键")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "账号")
|
||||||
|
@ExcelProperty("账号")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "昵称")
|
||||||
|
@ExcelProperty("昵称")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "头像")
|
||||||
|
@ExcelProperty("头像")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "部门")
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "部门")
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "部门")
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String jobsName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID")
|
||||||
|
@ExcelProperty("角色ID")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private List<Integer> roleId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "部门ID")
|
||||||
|
@ExcelProperty("部门ID")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private List<Integer> deptId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "岗位ID")
|
||||||
|
@ExcelProperty("ID")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private List<Integer> jobsId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "多端登录: [0=否, 1=是]")
|
||||||
|
@ExcelProperty("多端登录: [0=否, 1=是]")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private Integer multipointLogin;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否禁用: [0=否, 1=是]")
|
||||||
|
@ExcelProperty("是否禁用: [0=否, 1=是]")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private Integer disable;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否禁用")
|
||||||
|
@ExcelProperty("是否禁用")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String disableDesc;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "root")
|
||||||
|
@ExcelProperty("root")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private Integer root;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后登录IP")
|
||||||
|
@ExcelProperty("最后登录IP")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后登录时间")
|
||||||
|
@ExcelProperty("最后登录时间")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String loginTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "更新时间")
|
||||||
|
@ExcelProperty("更新时间")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue