|
|
@@ -1,6 +1,8 @@
|
|
|
package com.jpsoft.lotteryActivity.modules.business.controller;
|
|
|
|
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.lotteryActivity.config.OSSConfig;
|
|
|
import com.jpsoft.lotteryActivity.modules.base.entity.ActivityInfo;
|
|
|
import com.jpsoft.lotteryActivity.modules.base.entity.AwardInfo;
|
|
|
import com.jpsoft.lotteryActivity.modules.base.entity.LotteryPersonnelInfo;
|
|
|
@@ -10,14 +12,24 @@ import com.jpsoft.lotteryActivity.modules.base.service.AwardInfoService;
|
|
|
import com.jpsoft.lotteryActivity.modules.base.service.LotteryPersonnelInfoService;
|
|
|
import com.jpsoft.lotteryActivity.modules.base.service.WinningInfoService;
|
|
|
import com.jpsoft.lotteryActivity.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.lotteryActivity.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.lotteryActivity.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.lotteryActivity.utils.OSSUtil;
|
|
|
import com.jpsoft.lotteryActivity.utils.StringUtils;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -40,6 +52,9 @@ public class StartLotteryController {
|
|
|
@Autowired
|
|
|
private LotteryPersonnelInfoService lotteryPersonnelInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@ApiOperation(value = "列表")
|
|
|
@RequestMapping(value = "list", method = RequestMethod.POST)
|
|
|
public MessageResult<List<ActivityInfo>> list() {
|
|
|
@@ -246,6 +261,133 @@ public class StartLotteryController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ @ApiOperation(value = "导出")
|
|
|
+ @RequestMapping(value = "exportExcel", method = RequestMethod.POST)
|
|
|
+ public MessageResult<Object> exportExcel(String activityId, HttpServletRequest request) {
|
|
|
+ String subject = (String) request.getAttribute("subject");
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+
|
|
|
+ MessageResult<Object> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("a.create_time", "asc"));
|
|
|
+
|
|
|
+ searchParams.put("activityId", activityId);
|
|
|
+
|
|
|
+ Page<WinningInfo> page = winningInfoService.pageSearch(searchParams, 1, 20000, true, sortList);
|
|
|
+
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (WinningInfo winningInfo : page) {
|
|
|
+ Map map = new HashMap();
|
|
|
+
|
|
|
+ String activityName = "";
|
|
|
+ String phone = "";
|
|
|
+ String lotteryPersonnelNickName = "";
|
|
|
+ String lotteryPersonnelImage = "";
|
|
|
+ String awardName = "";
|
|
|
+ String awardPrizeName = "";
|
|
|
+
|
|
|
+ ActivityInfo activityInfo = activityInfoService.get(winningInfo.getActivityId());
|
|
|
+ if (activityInfo != null) {
|
|
|
+ activityName = activityInfo.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("activityName", activityName);
|
|
|
+
|
|
|
+ LotteryPersonnelInfo lotteryPersonnelInfo = lotteryPersonnelInfoService.get(winningInfo.getLotteryPersonnelId());
|
|
|
+
|
|
|
+ if (lotteryPersonnelInfo != null) {
|
|
|
+ phone = lotteryPersonnelInfo.getPhone();
|
|
|
+ lotteryPersonnelNickName = lotteryPersonnelInfo.getNickName();
|
|
|
+ lotteryPersonnelImage = lotteryPersonnelInfo.getImage();
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("lotteryPersonnelPhone", phone);
|
|
|
+ map.put("lotteryPersonnelNickName", lotteryPersonnelNickName);
|
|
|
+ map.put("lotteryPersonnelImage", lotteryPersonnelImage);
|
|
|
+
|
|
|
+ AwardInfo awardInfo = awardInfoService.get(winningInfo.getAwardId());
|
|
|
+
|
|
|
+ if (awardInfo != null) {
|
|
|
+ awardName = awardInfo.getName();
|
|
|
+ awardPrizeName = awardInfo.getPrizeName();
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("awardName", awardName);
|
|
|
+ map.put("awardPrizeName", awardPrizeName);
|
|
|
+
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String filePath = exportXls(mapList);
|
|
|
+ msgResult.setData(filePath);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //导出
|
|
|
+ private String exportXls(List<Map> mapList) {
|
|
|
+ String downloadUrl = "";
|
|
|
+
|
|
|
+ Workbook workbook = new HSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet();
|
|
|
+
|
|
|
+ //表头
|
|
|
+ Row rowTitle = sheet.createRow(0);
|
|
|
+
|
|
|
+ String[] titles = new String[]{"序号", "中奖人电话", "奖项", "所属活动"};
|
|
|
+
|
|
|
+ for (int i = 0; i < titles.length; i++) {
|
|
|
+ Cell cell = rowTitle.createCell(i);
|
|
|
+ cell.setCellValue(titles[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < mapList.size(); i++) {
|
|
|
+ Map<String, Object> map = mapList.get(i);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+
|
|
|
+ int colIndex = 0;
|
|
|
+ row.createCell(colIndex++).setCellValue(i + 1);
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("lotteryPersonnelPhone"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("awardName"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("activityName"), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ try {
|
|
|
+ workbook.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ downloadUrl = OSSUtil.upload(ossConfig, "winningInfoList", "中奖人名单.xls", input);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return downloadUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private String desensitizePhone(String phone) {
|
|
|
if (phone == null || phone.length() != 11) {
|
|
|
return phone; // 非11位手机号不处理
|