| | |
| | | package com.linghu.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.write.handler.SheetWriteHandler; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
| | | import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.linghu.listener.KeywordExcelListener; |
| | | import com.linghu.mapper.KeywordMapper; |
| | |
| | | import com.linghu.model.dto.ExportGetResultByPlatformIdDTO; |
| | | import com.linghu.model.dto.ExportGetResultDTO; |
| | | import com.linghu.model.dto.ExportStaticsDTO; |
| | | import com.linghu.model.entity.Keyword; |
| | | import com.linghu.model.entity.Platform; |
| | | import com.linghu.model.entity.Reference; |
| | | import com.linghu.model.entity.Type; |
| | | import com.linghu.model.excel.FeedExportExcel; |
| | | import com.linghu.model.excel.PlatformExcel; |
| | | import com.linghu.model.excel.ReferenceExcel; |
| | | import com.linghu.model.entity.*; |
| | | import com.linghu.model.excel.*; |
| | | import com.linghu.model.vo.*; |
| | | import com.linghu.model.excel.KeywordExcel; |
| | | import com.linghu.model.excel.PlatformExcel; |
| | | import com.linghu.model.vo.KeywordStaticsListVO; |
| | | import com.linghu.model.vo.KeywordStaticsVO; |
| | | import com.linghu.model.vo.PlatformProportionVO; |
| | | import com.linghu.model.vo.ResultListVO; |
| | | import com.linghu.service.KeywordService; |
| | | import com.linghu.service.PlatformService; |
| | | import com.linghu.service.ReferenceService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DataValidationHelper; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | |
| | | private ReferenceService referenceService; |
| | | @Autowired |
| | | private ReferenceMapper referenceMapper; |
| | | @Autowired |
| | | private PlatformService platformService; |
| | | |
| | | /** |
| | | * 关键词统计 EChart图 |
| | |
| | | 1 , dto.getTypeId()); |
| | | } |
| | | |
| | | |
| | | //查询所有平台名称 |
| | | List<String> typeNameList = result.stream() |
| | | .map(PlatformProportionVO::getType_name) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, PlatformProportionVO.class) |
| | | .sheet("引用数据") |
| | | .doWrite(result); |
| | | // 3. 使用自定义的SheetWriteHandler来添加数据验证 |
| | | ExcelWriter excelWriter = EasyExcel.write(out, PlatformProportionVO.class) |
| | | .registerWriteHandler(new SheetWriteHandler() { |
| | | @Override |
| | | public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, |
| | | WriteSheetHolder writeSheetHolder) { |
| | | Sheet sheet = writeSheetHolder.getSheet(); |
| | | |
| | | // 添加数据验证(下拉框) |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | CellRangeAddressList rangeList = new CellRangeAddressList( |
| | | 1, 65535, 0, 0); // D列(第4列) |
| | | |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint( |
| | | typeNameList.toArray(new String[0])); |
| | | DataValidation validation = helper.createValidation(constraint, rangeList); |
| | | sheet.addValidationData(validation); |
| | | } |
| | | }) |
| | | .build(); |
| | | |
| | | |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("平台分布占比").build(); |
| | | excelWriter.write(result, writeSheet); |
| | | excelWriter.finish(); |
| | | |
| | | // 4. 构建响应 |
| | | return ResponseEntity.ok() |
| | |
| | | result = keywordMapper.getResultByPlatformId(dto.getKeywordId(), dto.getQuestionId(), 1, |
| | | dto.getPlatformId()); |
| | | } |
| | | //查询所有平台名称 |
| | | List<String> platfromNames = result.stream() |
| | | .map(ResultListVO::getPlatform_name) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, ResultListVO.class) |
| | | .sheet("引用数据") |
| | | .doWrite(result); |
| | | |
| | | // 3. 使用自定义的SheetWriteHandler来添加数据验证 |
| | | ExcelWriter excelWriter = EasyExcel.write(out, ResultListVO.class) |
| | | .registerWriteHandler(new SheetWriteHandler() { |
| | | @Override |
| | | public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, |
| | | WriteSheetHolder writeSheetHolder) { |
| | | Sheet sheet = writeSheetHolder.getSheet(); |
| | | |
| | | // 添加数据验证(下拉框) |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | CellRangeAddressList rangeList = new CellRangeAddressList( |
| | | 1, 65535, 0, 0); // D列(第4列) |
| | | |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint( |
| | | platfromNames.toArray(new String[0])); |
| | | DataValidation validation = helper.createValidation(constraint, rangeList); |
| | | sheet.addValidationData(validation); |
| | | } |
| | | }) |
| | | .build(); |
| | | |
| | | |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("平台分布占比").build(); |
| | | excelWriter.write(result, writeSheet); |
| | | excelWriter.finish(); |
| | | |
| | | // 4. 构建响应 |
| | | return ResponseEntity.ok() |