3
0

2 Commits b9d116a40d ... 0738b8486c

Autor SHA1 Nachricht Datum
  guozhaoshun 0738b8486c 报表 vor 6 Jahren
  guozhaoshun 1340b87ab7 用户标签报表 vor 6 Jahren

+ 96 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/stmt/StmtStatsController.java

@@ -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

+ 5 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/stmt/StmtUserTagController.java

@@ -54,6 +54,10 @@ public class StmtUserTagController
             searchDTO.setMerchantId(user.getMerchantId());
         }
 
+        //下载所有
+        searchDTO.setPageNo(1);
+        searchDTO.setPageNo(10000);
+
         APIResult<Page<UserTagStmt>> pageAPIResult = stmtService.UserTagStmtPage(BeanUtil.convertToMap(searchDTO));
         if(!pageAPIResult.getSuccess()){
             return null;
@@ -66,7 +70,7 @@ public class StmtUserTagController
             //创建HSSFWorkbook对象(excel的文档对象)
             HSSFWorkbook wb = new HSSFWorkbook();
             //建立新的sheet对象(excel的表单)
-            HSSFSheet sheet = wb.createSheet("已配置用户标签终端信息报表已配置用户标签");
+            HSSFSheet sheet = wb.createSheet("已配置标签终端信息报表");
             //设置单元格宽度
             sheet.setColumnWidth(0, 20 * 256);
             sheet.setColumnWidth(1, 10 * 256);

+ 1 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/repository/StmtRepository.java

@@ -26,6 +26,6 @@ public interface StmtRepository extends BasicJpaRepository<UserTag, String> {
             " AND if(?1 !='',tu.code LIKE CONCAT('%',?1,'%'),1=1) " +
             " AND if(?2 !='',tu.merchant_id=?2,1=1) " +
             " AND if(?3 !='',tu.campus_id=?3,1=1)  " +
-            " ORDER BY tu.gmt_created DESC if(?5 != null ,LIMIT ?4,?5 ) ",nativeQuery = true)
+            " ORDER BY tu.gmt_created DESC LIMIT ?4,?5  ",nativeQuery = true)
     List<String> uidList(String code, String merchantId, String campusId, long start, Integer pageSize);
 }