@ApiOperation(value="专家维护导出", notes="专家维护导出")
@GetMapping(value = "/exportXls")
@RequiresRoles(value = {"admin"}, logical = Logical.OR)
public ModelAndView exportXls(ExperParam experParam) {
String title = "专家维护";
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// Step 2: 根据请求参数筛选查询数据
List<Expert> list = service.lists(experParam);
// Step 3: 处理字典字段和一对多关联数据
List<ExpertExcelForm> exportList = list.stream()
.map(item -> {
ExpertExcelForm vo = new ExpertExcelForm();
vo = expertService.checkDicti(item);
BeanUtil.copyProperties(item,vo);
log.info("用户名称:"+sysUser.getRealname()+",导出时间:"+new Date());
//获取一对多用,分割的二级领域
LambdaQueryWrapper<ExpertIndustry> expertIndustryQuery = new LambdaQueryWrapper<>();
expertIndustryQuery.eq(ExpertIndustry::getExpertId, item.getId());
List<ExpertIndustry> talentExpertIndustries = expertIndustryService.list(expertIndustryQuery);
List<IndustryVO> emergingIndustries = talentExpertIndustries.stream()
.map(expertIndustry -> industryService.listIndustryVO(expertIndustry.getIndustryId()))
.flatMap(List::stream)
.collect(Collectors.toList());
String industriesString = emergingIndustries.stream()
.map(IndustryVO::getIndustryName)
.collect(Collectors.joining(", "));
vo.setMajorFieldSecond(industriesString);
//获取荣誉头衔
LambdaQueryWrapper<ExperDict> experDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
experDictLambdaQueryWrapper.eq(ExperDict::getExpertId, item.getId());
List<ExperDict> experDicts = iExperDictService.list(experDictLambdaQueryWrapper);
List<String> academicHonorsList = experDicts.stream()
.map(experDict -> iExperDictService.listAcademicHonorsVO(experDict.getDictId()))
.flatMap(List::stream)
.map(DictListVO::getItemText)
.collect(Collectors.toList());
String academicHonorsString = String.join(", ", academicHonorsList);
vo.setAcademicHonors(academicHonorsString);
return vo;
})
.collect(Collectors.toList());
// Step 4: 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
mv.addObject(NormalExcelConstants.FILE_NAME, title);
mv.addObject(NormalExcelConstants.CLASS, ExpertExcelForm.class);
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
exportParams.setImageBasePath(super.jeecgBaseConfig.getPath().getUpload());
exportParams.setType(ExcelType.XSSF);
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv;
}
public ExpertExcelForm checkDicti(Expert experExcel) {
ExpertExcelForm expertForm=new ExpertExcelForm();
if(experExcel==null){
throw new ExcelAnalysisException("excel文件数据为空");
}
//表映射
if (!StringUtil.isNullOrEmpty(experExcel.getCountry())){
String country = expertMapper.getCountryById(experExcel.getCountry());
experExcel.setCountry(country);
}
if (!StringUtil.isNullOrEmpty(experExcel.getEthnicity())){
String ethnicity = expertMapper.getEthnicityById(experExcel.getEthnicity());
experExcel.setEthnicity(ethnicity);
}
//字典映射
if (StringUtil.isNullOrEmpty(experExcel.getGender())){
experExcel.setGender(null);
}else {
String gender = null;
switch (experExcel.getGender()) {
case "1":
gender = "男";
break;
case "2":
gender = "女";
break;
}
experExcel.setGender(gender != null ? gender : null);
}
return expertForm;
}
实体类
mapper编写
Expert selectExpertInfoById(@Param("expertId") String id);
xml编写
<select id="lists" resultType="org.dataocean.modules.expert.entity.Expert" parameterType="org.dataocean.modules.expert.model.ExperParam">
SELECT
DISTINCT tpe.id, tpe.phone, tpe.name
FROM lhs_talent_pool.talent_pool_expertss AS tpe
LEFT JOIN talent_expert_industry tei ON tei.expert_id = tpe.id
LEFT JOIN sys_category sc ON tei.industry_id = sc.id
<where>
tpe.delete_time IS NULL
<if test="experParam.majorFieldFirst != null and experParam.majorFieldFirst !=''">
and tpe.major_field_first LIKE CONCAT('%', #{experParam.majorFieldFirst}, '%')
</if>
<if test="experParam.majorFieldSecond != null and experParam.majorFieldSecond !=''">
and sc.name = #{experParam.majorFieldSecond}
</if>
</where>
</select>