【无标题】

// 迁改导出
    @ApiOperation("迁改导出")
    @GetMapping("exportProcess/{ids}")
    public AjaxResult exportProcess(@PathVariable Long[] ids, HttpServletResponse response) throws Exception {

        try {
            // 设置响应输出的头类型
            response.setHeader("content-Type", "application/vnd.ms-excel");
            // 下载文件的默认名称
            response.setHeader("Content-Disposition", "attachment;filename=user.xlsx");

            // =========easypoi部分
            List<ProcessExeclVo> exportList = new LinkedList<ProcessExeclVo>();


            for (Long aLong : ids) {
                // 获取主表
                Process process = processService.getById(aLong);
                String processCode = process.getProcessCode();


                // 获取明细表
                LambdaQueryWrapper<ProcessDetail> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(ProcessDetail::getProcessCode,processCode);
                List<ProcessDetail> list = processDetailService.list(queryWrapper);

                // 主表数据
                ProcessExeclVo processByVo = BeanUtil.toBean(process, ProcessExeclVo.class);

                // 返回 赔补类型
                String processTemplateString = getProcessTemplateString(processByVo.getProcessTemplateId());
                processByVo.setProcessTemplateId(processTemplateString);

                // 返回 审批类型
                String processType = getProcessTypeString(processByVo.getProcessTypeId());
                processByVo.setProcessTypeId(processType);

                // 返回 设计网络类型
                ProcessDetail processDetail1 = list.get(0);
                String networkNameString = getNetworkNameString(processDetail1.getNetworkName());
                processByVo.setNetworName(networkNameString);

                // 返回 故障
                String speciality =  getSpeciality(processDetail1.getSpeciality());
                processByVo.setSpeciality(speciality);

                // 明细表
                LinkedList<ProcessDetailExeclVo> negotionVos = new LinkedList<>();
                // 谈判信息
                LinkedList<NegotionVo> negotions = new LinkedList<>();


                for (ProcessDetail processDetail : list) {
                    ProcessDetailExeclVo processDetailVo = BeanUtil.toBean(processDetail, ProcessDetailExeclVo.class);


                    if (ObjectUtil.isNotEmpty(processDetail.getNegotionId())){
                        LambdaQueryWrapper<Negotion> negotionLambdaQueryWrapper = new LambdaQueryWrapper<>();
                        negotionLambdaQueryWrapper.eq(Negotion::getProcessCode,processCode);
                        List<Negotion> negotionList = negotionMapper.selectList(negotionLambdaQueryWrapper);
                        for (Negotion negotion : negotionList) {
                            NegotionVo negotionVo = BeanUtil.toBean(negotion, NegotionVo.class);
                            negotionVo.setIds(negotion.getId());
                            negotions.add(negotionVo);
                        }
                    }

                    // 将明细表信息放入主表保存
                    negotionVos.add(processDetailVo);
                }
                // 将明细添加到主表里面
                processByVo.setProcessDetailExeclVos(negotionVos);
                // 将谈判信息添加到主表里面
                processByVo.setNegotionVoList(negotions);

                // 部门集合
                exportList.add(processByVo);
            }

            ExportParams deptExportParams = new ExportParams();
            // 设置sheet得名称
            deptExportParams.setSheetName("员工报表1");

            Map<String, Object> deptExportMap = new HashMap<>();
            // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
            deptExportMap.put("title", deptExportParams);
            // 模版导出对应得实体类型
            deptExportMap.put("entity", ProcessExeclVo.class);
            // sheet中要填充得数据
            deptExportMap.put("data", exportList);

            List<Map<String, Object>> sheetsList = new ArrayList<>();
            sheetsList.add(deptExportMap);
            Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
            ServletOutputStream outputStream = response.getOutputStream();
            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return AjaxResult.success("导出成功");
    }

你可能感兴趣的:(windows)