|
@ -1,5 +1,9 @@ |
|
|
package com.epmet.dataaggre.controller.pub; |
|
|
package com.epmet.dataaggre.controller.pub; |
|
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants; |
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
|
|
import cn.afterturn.easypoi.view.EasypoiTemplateExcelView; |
|
|
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.dataaggre.dto.datastats.form.BaseDataFormDTO; |
|
|
import com.epmet.dataaggre.dto.datastats.form.BaseDataFormDTO; |
|
@ -8,16 +12,19 @@ import com.epmet.dataaggre.dto.datastats.result.SubTopicAndGroupResultDTO; |
|
|
import com.epmet.dataaggre.dto.datastats.result.SubUserTotalResultDTO; |
|
|
import com.epmet.dataaggre.dto.datastats.result.SubUserTotalResultDTO; |
|
|
import com.epmet.dataaggre.dto.datastats.result.WorkFactResultDTO; |
|
|
import com.epmet.dataaggre.dto.datastats.result.WorkFactResultDTO; |
|
|
import com.epmet.dataaggre.service.datastats.DataStatsService; |
|
|
import com.epmet.dataaggre.service.datastats.DataStatsService; |
|
|
import lombok.extern.log4j.Log4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 小程序相关配置,可以放在这,目前只放了footbar |
|
|
* 小程序相关配置,可以放在这,目前只放了footbar |
|
@ -25,7 +32,7 @@ import java.util.List; |
|
|
* @author yinzuomei@elink-cn.com |
|
|
* @author yinzuomei@elink-cn.com |
|
|
* @date 2021/7/27 18:36 |
|
|
* @date 2021/7/27 18:36 |
|
|
*/ |
|
|
*/ |
|
|
@Log4j |
|
|
@Slf4j |
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("pub") |
|
|
@RequestMapping("pub") |
|
|
public class PubController { |
|
|
public class PubController { |
|
@ -89,30 +96,52 @@ public class PubController { |
|
|
/** |
|
|
/** |
|
|
* 导出数据,使用map接收 |
|
|
* 导出数据,使用map接收 |
|
|
* |
|
|
* |
|
|
* @param map |
|
|
* @param formDTO |
|
|
* @param response |
|
|
* @param response |
|
|
* @throws IOException |
|
|
* @throws IOException |
|
|
|
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@PostMapping("/exportExcel") |
|
|
@RequestMapping("/exportExcel") |
|
|
public void exportExcel(@RequestBody BaseDataFormDTO formDTO, HttpServletResponse response) throws IOException { |
|
|
public ModelAndView exportExcel(@RequestBody BaseDataFormDTO formDTO) { |
|
|
/* try { |
|
|
//String paramStr = "{\"agencyId\":\"7b6f9a9f9f38d5f9fa7ce94a93d6eb28\",\"agencyLevel\":\"city\",\"dateId\":\"20210616\",\"type\":\"thisWeek\",\"agencyName\":\"组织名称\"}";
|
|
|
Map<String, Object> mapData = new HashMap<>(); |
|
|
//formDTO = JSON.parseObject(paramStr, BaseDataFormDTO.class);
|
|
|
BaseStatsDataResultDTO baseStatsData = dataStatsService.getBaseStatsData(formDTO); |
|
|
Map<String, Object> mapData = new HashMap<>(); |
|
|
String templatePath = "excel/trace_temp.xlsx"; |
|
|
mapData.put("collectData", dataStatsService.getBaseStatsData(formDTO)); |
|
|
log.info("exportExcel templatePath:{}",templatePath); |
|
|
mapData.put("subWorkFactList", dataStatsService.getSubWorkFact(formDTO)); |
|
|
mapData.put("dataType", baseStatsData); |
|
|
mapData.put("subUserTotalList", dataStatsService.subUserTotal(formDTO)); |
|
|
|
|
|
mapData.put("subTopicAndGroupList", dataStatsService.subTopicAndGroup(formDTO)); |
|
|
|
|
|
mapData.put("orgName",formDTO.getAgencyName()); |
|
|
|
|
|
mapData.put("type",getSearchTimeStr(formDTO.getType())); |
|
|
|
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
|
//自定义导出字段
|
|
|
|
|
|
//String templatePath = this.getClass().getClassLoader().getResource("excel/data_template.xlsx").getPath();
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
String templatePath = "excel/data_template.xlsx"; |
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new TemplateExportParams(templatePath, "数据汇总"), baseStatsData); |
|
|
log.info("exportExcel templatePath:"+templatePath); |
|
|
//header
|
|
|
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("继续追踪导出详情-".concat(DateUtils.formatDate()) + ".xlsx", "UTF-8")); |
|
|
|
|
|
//加密
|
|
|
|
|
|
log.error("excelExport build wb cost:{}",System.currentTimeMillis()-start); |
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ModelAndView mv = new ModelAndView(new EasypoiTemplateExcelView()); |
|
|
|
|
|
mv.addObject(TemplateExcelConstants.FILE_NAME, DateUtils.format(new Date(),DateUtils.DATE_TIME_NO_SPLIT)); |
|
|
|
|
|
TemplateExportParams templateExportParams = new TemplateExportParams(templatePath); |
|
|
|
|
|
Integer[] integers = {0,1,2,3}; |
|
|
|
|
|
templateExportParams.setSheetNum(integers); |
|
|
|
|
|
mv.addObject(TemplateExcelConstants.PARAMS, templateExportParams); |
|
|
|
|
|
mv.addObject(TemplateExcelConstants.MAP_DATA, mapData); |
|
|
|
|
|
log.info("excelExport cost:{}",System.currentTimeMillis()-start); |
|
|
|
|
|
return mv; |
|
|
|
|
|
} |
|
|
|
|
|
private String getSearchTimeStr(String type){ |
|
|
|
|
|
//昨日/本周/本月
|
|
|
|
|
|
switch (type){ |
|
|
|
|
|
case "yesterday": |
|
|
|
|
|
return "昨日"; |
|
|
|
|
|
case "thisWeek": |
|
|
|
|
|
return "本周"; |
|
|
|
|
|
case "thisMonth": |
|
|
|
|
|
return "本月"; |
|
|
|
|
|
default: |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|