|
@@ -13,11 +13,18 @@ import cn.rankin.data.api.user.vo.CampusVo;
|
|
|
import cn.rankin.data.api.user.vo.TerminalUserAuthVo;
|
|
|
import cn.rankin.data.api.user.vo.TerminalUserVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -51,6 +58,95 @@ public class StmtStatsController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 下载终端明细
|
|
|
+ *
|
|
|
+ * @param user the user details
|
|
|
+ * @param searchDTO the search Dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = {"/export", "/"}, method = RequestMethod.GET)
|
|
|
+ public APIResult<Page<TerminalUserVo>> campusListExport(HttpServletResponse res, @NeedUser UserDetails user, TerminalUserSearchDTO searchDTO) {
|
|
|
+ if (!user.isPlatForm()) {
|
|
|
+ String merchantId = user.getMerchantId();
|
|
|
+ searchDTO.setMerchantId(merchantId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ searchDTO.setPageNo(1);
|
|
|
+ searchDTO.setPageNo(10000);
|
|
|
+
|
|
|
+ APIResult<Page<TerminalUserVo>> pageAPIResult = terminalUserService.search(BeanUtil.convertToMap(searchDTO));
|
|
|
+
|
|
|
+ if (!pageAPIResult.getSuccess()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<TerminalUserVo> userTagStmtPage = pageAPIResult.getData();
|
|
|
+
|
|
|
+ if (null != userTagStmtPage) {
|
|
|
+ List<TerminalUserVo> list = userTagStmtPage.getList();
|
|
|
+
|
|
|
+ //创建HSSFWorkbook对象(excel的文档对象)
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+ //建立新的sheet对象(excel的表单)
|
|
|
+ HSSFSheet sheet = wb.createSheet("总统计表");
|
|
|
+ //设置单元格宽度
|
|
|
+ sheet.setColumnWidth(0, 20 * 256);
|
|
|
+ sheet.setColumnWidth(1, 10 * 256);
|
|
|
+ sheet.setColumnWidth(2, 30 * 256);
|
|
|
+ sheet.setColumnWidth(3, 30 * 256);
|
|
|
+ sheet.setColumnWidth(4, 10 * 256);
|
|
|
+ sheet.setColumnWidth(5, 30 * 256);
|
|
|
+ sheet.setColumnWidth(6, 15 * 256);
|
|
|
+ sheet.setColumnWidth(7, 15 * 256);
|
|
|
+ //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
|
|
|
+ HSSFRow row1 = sheet.createRow(0);
|
|
|
+ //创建单元格并设置单元格内容
|
|
|
+ row1.createCell(0).setCellValue("校区类型");
|
|
|
+ row1.createCell(1).setCellValue("校区名称");
|
|
|
+ row1.createCell(2).setCellValue("终端编号");
|
|
|
+ row1.createCell(3).setCellValue("终端名称");
|
|
|
+ row1.createCell(4).setCellValue("终端状态");
|
|
|
+
|
|
|
+ //单元格日期格式
|
|
|
+ HSSFCellStyle cellStyle = wb.createCellStyle();
|
|
|
+ HSSFDataFormat format = wb.createDataFormat();
|
|
|
+ cellStyle.setDataFormat(format.getFormat("yyyy/mm/dd"));
|
|
|
+
|
|
|
+ //插入数据
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ TerminalUserVo vo = list.get(i);
|
|
|
+
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);
|
|
|
+ row.createCell(0).setCellValue(vo.getMerchantName());
|
|
|
+ row.createCell(1).setCellValue(vo.getCampusName());
|
|
|
+ row.createCell(2).setCellValue(vo.getCode());
|
|
|
+ row.createCell(3).setCellValue(vo.getName());
|
|
|
+ row.createCell(4).setCellValue(vo.getStatus().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ long currentTime = new Date().getTime();
|
|
|
+ //输出Excel文件
|
|
|
+ OutputStream output = res.getOutputStream();
|
|
|
+ res.reset();
|
|
|
+ res.setHeader("Content-disposition", "attachment; filename=lingjiao_terminal_user_" + currentTime + ".xls");
|
|
|
+ res.setContentType("application/msexcel");
|
|
|
+ wb.write(output);
|
|
|
+ output.close();
|
|
|
+ } catch (Exception ex) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取校区总数
|
|
|
*
|
|
|
* @param user the user details
|