Jeecgboot导出编写

@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>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值