feat(smartfactory): 优化员工导出功能

- 为 CameraDeviceMapper 添加按 sort 字段升序排序
- 在 StaffController 中增加工种字典值和工厂信息的获取,并完善员工信息导出内容
- 更新 StaffRespVO,增加 factoryName 和 workTypeName 字段,修改 sex 字段为 sexStr
This commit is contained in:
furongxin 2025-06-04 16:54:55 +08:00
parent 77d7620898
commit b7cb164837
3 changed files with 35 additions and 10 deletions

View File

@ -18,7 +18,6 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -141,9 +140,27 @@ public class StaffController {
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<StaffDO> list = staffService.getStaffPage(pageReqVO).getList(); List<StaffDO> list = staffService.getStaffPage(pageReqVO).getList();
// 获取工种字典值
List<DictDataRespDTO> dictDataRespDTOS = dictDataApi.getDictDataList("user_work_type").getCheckedData();
Map<String, String> workTypeMap = dictDataRespDTOS.stream().collect(Collectors.toMap(DictDataRespDTO::getValue, DictDataRespDTO::getLabel));
// 获取工厂信息Map
Map<Long, FactoryInfoDO> factoryInfoDOMap = convertMap(factoryInfoService.getFactoryList(), FactoryInfoDO::getId);
List<StaffRespVO> respVOS = BeanUtils.toBean(list, StaffRespVO.class);
respVOS.forEach(item -> {
if (item.getWorkTypeId() != null) {
item.setWorkTypeName(workTypeMap.getOrDefault(item.getWorkTypeId().toString(), ""));
}
// 设置性别
item.setSexStr(item.getSex() == null ? null : item.getSex() == 1 ? "" : "");
// 设置工厂名称
item.setFactoryName(factoryInfoDOMap.get(item.getFactoryId()) != null ? factoryInfoDOMap.get(item.getFactoryId()).getShortName() : null);
});
// 导出 Excel // 导出 Excel
ExcelUtils.write(response, "员工.xls", "数据", StaffRespVO.class, ExcelUtils.write(response, "员工.xls", "数据", StaffRespVO.class, respVOS);
BeanUtils.toBean(list, StaffRespVO.class));
} }
@GetMapping("/get-import-template") @GetMapping("/get-import-template")

View File

@ -20,27 +20,34 @@ public class StaffRespVO {
@ExcelProperty("姓名") @ExcelProperty("姓名")
private String nickName; private String nickName;
@Schema(description = "工厂名称", example = "6971")
@ExcelProperty("工厂名称")
private String factoryName;
@Schema(description = "年龄") @Schema(description = "年龄")
@ExcelProperty("年龄") @ExcelProperty("年龄")
private Integer age; private Integer age;
@Schema(description = "用户性别0男 1女 2未知") @Schema(description = "用户性别1男 2女")
@ExcelProperty("性别")
private Integer sex; private Integer sex;
@Schema(description = "用户性别1男 2女")
@ExcelProperty("性别")
private String sexStr;
@Schema(description = "工种id", example = "6971") @Schema(description = "工种id", example = "6971")
private Integer workTypeId; private Integer workTypeId;
@Schema(description = "工种名称", example = "6971")
@ExcelProperty("工种")
private String workTypeName;
@Schema(description = "所属业务类型") @Schema(description = "所属业务类型")
private Integer businessType; private Integer businessType;
@Schema(description = "工厂id", example = "6971") @Schema(description = "工厂id", example = "6971")
private Long factoryId; private Long factoryId;
@Schema(description = "工厂名称", example = "6971")
@ExcelProperty("工厂名称")
private String factoryName;
@Schema(description = "手机号") @Schema(description = "手机号")
@ExcelProperty("手机号") @ExcelProperty("手机号")
private String mobile; private String mobile;

View File

@ -39,6 +39,7 @@ public interface CameraDeviceMapper extends BaseMapperX<CameraDeviceDO> {
return selectList(new LambdaQueryWrapperX<CameraDeviceDO>() return selectList(new LambdaQueryWrapperX<CameraDeviceDO>()
.eq(factoryId != null, CameraDeviceDO::getFactoryId, factoryId) .eq(factoryId != null, CameraDeviceDO::getFactoryId, factoryId)
.eq(CameraDeviceDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) .eq(CameraDeviceDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
.eq(CameraDeviceDO::getIsShow, 1)); .eq(CameraDeviceDO::getIsShow, 1)
.orderByAsc(CameraDeviceDO::getSort));
} }
} }