| @@ -165,9 +165,8 @@ public class WxQuestionOneselfController extends BaseController { | |||
| @SystemControllerLog(description = "导出") | |||
| public void exportData(@ModelAttribute WxQuestionOneselfUser record, HttpServletRequest request, HttpServletResponse response) { | |||
| logger.info("[" + getIpAddr() + "] WxQuestionOneselfController/exportData"); | |||
| logger.debug("[" + getIpAddr() + "] WxQuestionOneselfController::userList"); | |||
| if (null == record) { | |||
| record = new WxQuestionOneselfUser(); | |||
| if (null == record || record.getQuestionId() == null) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| record.updateTenantInfo(getTenantInfo()); | |||
| record.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| @@ -7,6 +7,7 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil; | |||
| import cn.afterturn.easypoi.excel.entity.ExportParams; | |||
| import cn.afterturn.easypoi.excel.entity.ImportParams; | |||
| import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; | |||
| import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelExportServer; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -31,6 +32,18 @@ public class ExcelService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| public void exportExcel(List<ExcelExportEntity> headList,List<?> dataList, String title, String sheetName, String fileName, boolean isCreateHeader, HttpServletResponse response) | |||
| { | |||
| ExportParams exportParams = new ExportParams(title, sheetName); | |||
| exportParams.setCreateHeadRows(isCreateHeader); | |||
| exportParams.setType(ExcelType.XSSF); | |||
| defaultExport(headList, dataList, fileName, response, exportParams, false); | |||
| } | |||
| public static void main(String[] args) { | |||
| } | |||
| public void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName, boolean isCreateHeader, HttpServletResponse response) | |||
| { | |||
| ExportParams exportParams = new ExportParams(title, sheetName); | |||
| @@ -73,6 +86,24 @@ public class ExcelService { | |||
| defaultExport(list, fileName, response); | |||
| } | |||
| private void defaultExport(List<ExcelExportEntity> entityList, List<?> dataList, String fileName, HttpServletResponse response, ExportParams exportParams, boolean template) { | |||
| Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityList, dataList); | |||
| if (workbook != null) { | |||
| if (template) { | |||
| Sheet sheetAt = workbook.getSheetAt(0); | |||
| CellStyle cellStyle = workbook.createCellStyle(); | |||
| Font font = workbook.createFont(); | |||
| font.setColor(IndexedColors.RED.getIndex()); | |||
| cellStyle.setFont(font); | |||
| Row row = sheetAt.createRow(sheetAt.getLastRowNum() + 2); | |||
| Cell cell = row.createCell(0); | |||
| cell.setCellValue("*为必填字段(导入数据时此行文字请删除)"); | |||
| cell.setCellStyle(cellStyle); | |||
| } | |||
| } | |||
| downLoadExcel(fileName, response, workbook); | |||
| } | |||
| private void defaultExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response, ExportParams exportParams, boolean template) { | |||
| Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list); | |||
| if (workbook != null) { | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.service.impl; | |||
| import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| @@ -164,8 +165,49 @@ public class WxQuestionOneselfUserServiceImpl implements WxQuestionOneselfUserSe | |||
| @Override | |||
| public void exportData(WxQuestionOneselfUser record, HttpServletRequest request, HttpServletResponse response) { | |||
| wxQuestionOneselfUserMapper.findList(record); | |||
| // excelService.exportExcel(); | |||
| List<ExcelExportEntity> headList = new ArrayList<>(); | |||
| ExcelExportEntity entity1 = new ExcelExportEntity("姓名","userName"); | |||
| headList.add(entity1); | |||
| ExcelExportEntity entity2 = new ExcelExportEntity("性别","userSex"); | |||
| entity2.setReplace( new String[]{"保密_0", "男_1", "女_2"} ); | |||
| headList.add(entity2); | |||
| ExcelExportEntity entity3 = new ExcelExportEntity("手机号码","userPhone"); | |||
| headList.add(entity3); | |||
| ExcelExportEntity entity4 = new ExcelExportEntity("提交时间","createDate"); | |||
| entity4.setFormat("yyyy-MM-dd HH:mm:ss"); | |||
| headList.add(entity4); | |||
| WxQuestionOneselfTopic topicQ = new WxQuestionOneselfTopic(); | |||
| topicQ.updateTenantInfo(record); | |||
| topicQ.setQuestionId(record.getId()); | |||
| List<WxQuestionOneselfTopic> topicList = wxQuestionOneselfTopicMapper.findList(topicQ); | |||
| if(topicList != null && topicList.size() > 0){ | |||
| for (WxQuestionOneselfTopic topic:topicList) { | |||
| headList.add(new ExcelExportEntity(topic.getTitle(),topic.getId().toString())); | |||
| } | |||
| } | |||
| List<Map<String,Object>> dataList = new ArrayList<>(); | |||
| List<WxQuestionOneselfUser> userList = wxQuestionOneselfUserMapper.findList(record); | |||
| if(userList != null && userList.size() > 0){ | |||
| for (WxQuestionOneselfUser user:userList) { | |||
| Map<String,Object> map = new HashMap<>(); | |||
| map.put("userName",user.getUserName()); | |||
| map.put("userSex",user.getUserSex()); | |||
| map.put("userPhone",user.getUserPhone()); | |||
| map.put("createDate",user.getCreateDate()); | |||
| WxQuestionOneselfLog logQ = new WxQuestionOneselfLog(); | |||
| logQ.updateTenantInfo(record); | |||
| logQ.setWqouId(user.getId()); | |||
| List<WxQuestionOneselfLog> logList = wxQuestionOneselfLogMapper.findList(logQ); | |||
| if(logList != null && logList.size() > 0){ | |||
| for (WxQuestionOneselfLog log:logList) { | |||
| map.put(log.getTopicId().toString(),log.getAnswerStr()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| excelService.exportExcel(headList,dataList, null, "ceshi", "ceshi.xlsx", true,response ); | |||
| } | |||
| @Override | |||