Browse Source

feat: [导出] 导出支持中英文表头

master
memorylkf 2 months ago
parent
commit
66cd8c6ea4
7 changed files with 45 additions and 19 deletions
  1. +15
    -4
      hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java
  2. +5
    -0
      hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/annotation/Excel.java
  3. +7
    -3
      hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/poi/ExcelUtil.java
  4. +5
    -5
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/RoleChange.java
  5. +4
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java
  6. +3
    -1
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java
  7. +6
    -6
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/dto/UserExportDto.java

+ 15
- 4
hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysRole.java View File

@ -25,12 +25,12 @@ public class SysRole extends BaseEntity
private Long roleId;
/** 角色名称 */
@Excel(name = "角色名称",sort = 1)
@Excel(name = "角色名称",nameEn = "Role Name",sort = 1)
@Compare(name = "角色名称",nameEn = "Role Name")
private String roleName;
/** 角色权限 */
@Excel(name = "角色编码",sort = 2)
@Excel(name = "角色编码",nameEn = "Role ID",sort = 2)
@Compare(name = "角色编码",nameEn = "Role ID")
private String roleKey;
@ -47,9 +47,12 @@ public class SysRole extends BaseEntity
private boolean deptCheckStrictly;
/** 角色状态(0正常 1停用) */
@Excel(name = "状态", readConverterExp = "0=启用,1=禁用",sort = 4)
private String status;
/** 角色显示名称 */
@Excel(name = "状态",nameEn = "Status",sort = 4)
private String statusText;
/** 删除标志(0代表存在 2代表删除) */
private String delFlag;
@ -66,7 +69,7 @@ public class SysRole extends BaseEntity
private Set<String> permissions;
/** 备注 */
@Excel(name = "备注",sort = 3)
@Excel(name = "备注",nameEn = "Role Description",sort = 3)
@Compare(name = "备注",nameEn = "Role Description")
private String remark;
@ -175,6 +178,14 @@ public class SysRole extends BaseEntity
this.status = status;
}
public String getStatusText() {
return statusText;
}
public void setStatusText(String statusText) {
this.statusText = statusText;
}
public String getDelFlag()
{
return delFlag;

+ 5
- 0
hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/annotation/Excel.java View File

@ -29,6 +29,11 @@ public @interface Excel
public String name() default "";
/**
* 导出到Excel中的名字.
*/
public String nameEn() default "";
/**
* 日期格式, : yyyy-MM-dd
*/
public String dateFormat() default "";

+ 7
- 3
hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/poi/ExcelUtil.java View File

@ -19,11 +19,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hxhq.common.core.annotation.Excel;
import com.hxhq.common.core.exception.UtilException;
import com.hxhq.common.core.utils.DateUtils;
import com.hxhq.common.core.utils.ServletUtils;
import com.hxhq.common.core.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
@ -62,6 +64,8 @@ import com.hxhq.common.core.text.Convert;
import com.hxhq.common.core.utils.file.FileTypeUtils;
import com.hxhq.common.core.utils.file.ImageUtils;
import com.hxhq.common.core.utils.reflect.ReflectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* Excel相关处理
@ -255,7 +259,7 @@ public class ExcelUtil
if (Collection.class.isAssignableFrom(field.getType()))
{
Cell cell = subRow.createCell(column);
cell.setCellValue(attr.name());
cell.setCellValue(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?attr.name():attr.nameEn());
cell.setCellStyle(cellStyle);
int subFieldSize = subFieldsMap != null ? subFieldsMap.get(field.getName()).size() : 0;
if (subFieldSize > 1)
@ -268,7 +272,7 @@ public class ExcelUtil
else
{
Cell cell = subRow.createCell(column++);
cell.setCellValue(attr.name());
cell.setCellValue(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?attr.name():attr.nameEn());
cell.setCellStyle(cellStyle);
}
}
@ -840,7 +844,7 @@ public class ExcelUtil
// 创建列
Cell cell = row.createCell(column);
// 写入列信息
cell.setCellValue(attr.name());
cell.setCellValue(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?attr.name():attr.nameEn());
setDataValidation(attr, row, column);
cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
if (isSubList())

+ 5
- 5
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/RoleChange.java View File

@ -26,7 +26,7 @@ public class RoleChange extends MpBaseEntity
private Long userId;
/** 操作类型 */
@Excel(name = "操作类型",sort = 2)
@Excel(name = "操作类型",nameEn = "Meaning of Signature",sort = 2)
private String jcmc;
/** 操作类型-英文 */
@ -36,23 +36,23 @@ public class RoleChange extends MpBaseEntity
private Long qmrId;
/** 操作人名称 */
@Excel(name = "签名人",sort = 1)
@Excel(name = "签名人",nameEn = "Signed By",sort = 1)
private String qmrMc;
/** 操作人名称-英文 */
private String qmrMcEn;
/** 变更前角色 */
@Excel(name = "变更前角色",sort = 4)
@Excel(name = "变更前角色",nameEn = "Role Before Change",sort = 4)
private String bgq;
/** 变更后角色 */
@Excel(name = "变更后角色",sort = 5)
@Excel(name = "变更后角色",nameEn = "Role After Change",sort = 5)
private String bgh;
/** 创建时间 */
@TableField(exist = false)
@Excel(name = "签名时间",sort = 3)
@Excel(name = "签名时间", nameEn = "Date",sort = 3)
private String createTimeText;

+ 4
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java View File

@ -11,6 +11,7 @@ import com.hxhq.business.form.common.SignForm;
import com.hxhq.business.service.IRoleChangeService;
import com.hxhq.business.service.ISystemLogService;
import com.hxhq.common.core.exception.ServiceException;
import com.hxhq.common.core.utils.ServletUtils;
import com.hxhq.common.core.utils.StringUtils;
import com.hxhq.system.domain.SysUserRole;
import com.hxhq.system.form.RoleUserSaveForm;
@ -79,6 +80,9 @@ public class SysRoleController extends BaseController
public void export(HttpServletResponse response, SysRole role)
{
List<SysRole> list = roleService.selectRoleList(role);
for(SysRole l : list){
l.setStatusText("0".endsWith(l.getStatus())?(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?"启用":"Enabled"):(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?"禁用":"Disabled"));
}
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
util.exportExcel(response, list, "角色数据");
}

+ 3
- 1
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java View File

@ -13,6 +13,7 @@ import com.hxhq.business.dto.select.DeptUserTreeDto;
import com.hxhq.business.enums.dept.DeptTypeEnum;
import com.hxhq.business.enums.study.StudyTypeEnum;
import com.hxhq.business.service.IStudyService;
import com.hxhq.common.core.utils.ServletUtils;
import com.hxhq.system.dto.UserExportDto;
import com.hxhq.system.form.UserSaveForm;
import com.hxhq.system.service.ISysConfigService;
@ -119,7 +120,8 @@ public class SysUserController extends BaseController
exportDto.setEmail(u.getEmail());
exportDto.setDeptName(u.getDept()==null?"":u.getDept().getDeptName());
exportDto.setRoleName(getRoleName(u.getRoles()));
exportDto.setStatus(u.getStatus());
exportDto.setStatus("0".endsWith(u.getStatus())?(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?"启用":"Enabled"):(ServletUtils.getRequest().getHeader("lang").equals("zh_CN")?"禁用":"Disabled"));
userList.add(exportDto);
}
ExcelUtil<UserExportDto> util = new ExcelUtil<UserExportDto>(UserExportDto.class);

+ 6
- 6
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/dto/UserExportDto.java View File

@ -9,32 +9,32 @@ public class UserExportDto {
/**
* 账号
*/
@Excel(name = "账号")
@Excel(name = "账号",nameEn = "User")
private String userName;
/**
* 姓名
*/
@Excel(name = "姓名")
@Excel(name = "姓名",nameEn = "Name")
private String nickName;
/**
* 手机
*/
@Excel(name = "邮箱")
@Excel(name = "邮箱",nameEn = "Email")
private String email;
/**
* 所属部门/学科
*/
@Excel(name = "所属部门/学科")
@Excel(name = "所属部门/学科",nameEn = "Department")
private String deptName;
/**
* 所属角色
*/
@Excel(name = "所属角色")
@Excel(name = "所属角色",nameEn = "Owned RoleOwned Role")
private String roleName;
/**
* 状态
*/
@Excel(name = "状态", readConverterExp = "0=启用,1=禁用")
@Excel(name = "状态",nameEn = "Status")
private String status;
public String getUserName() {

Loading…
Cancel
Save