Forráskód Böngészése

用户标签报表

guozhaoshun 6 éve
szülő
commit
cb69364155

+ 113 - 2
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/stmt/StmtUserTagController.java

@@ -6,14 +6,20 @@ import cn.rankin.cmsweb.service.stmt.StmtUserTagService;
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.util.BeanUtil;
+import cn.rankin.data.api.cms.StmtSearchDTO;
 import cn.rankin.data.api.cms.vo.UserTagStmt;
-import cn.rankin.data.api.user.dto.UserTagSearchDTO;
 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
@@ -25,7 +31,7 @@ public class StmtUserTagController
     private StmtUserTagService stmtService;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public APIResult<Page<UserTagStmt>> search(@NeedUser UserDetails user, UserTagSearchDTO searchDTO) {
+    public APIResult<Page<UserTagStmt>> search(@NeedUser UserDetails user, StmtSearchDTO searchDTO) {
         if (!user.isPlatForm()) {
             searchDTO.setMerchantId(user.getMerchantId());
         }
@@ -33,5 +39,110 @@ public class StmtUserTagController
 
     }
 
+    /**
+     * 查询已开通校区报表
+     *
+     * @param user      the user info
+     * @param searchDTO the campus search
+     * @return
+     */
+    @RequestMapping(value = {"/export"}, method = RequestMethod.GET)
+    public String exportCampus(HttpServletResponse res, @NeedUser UserDetails user, StmtSearchDTO searchDTO)
+    {
+        if (!user.isPlatForm())
+        {
+            searchDTO.setMerchantId(user.getMerchantId());
+        }
+
+        APIResult<Page<UserTagStmt>> pageAPIResult = stmtService.UserTagStmtPage(BeanUtil.convertToMap(searchDTO));
+        if(!pageAPIResult.getSuccess()){
+            return null;
+        }
+
+        Page<UserTagStmt> userTagStmtPage = pageAPIResult.getData();
+        if(null != userTagStmtPage){
+            List<UserTagStmt> 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++)
+                {
+                    UserTagStmt stmt = list.get(i);
+
+                    HSSFRow row = sheet.createRow(i + 1);
+                    row.createCell(0).setCellValue(stmt.getUCode());
+                    row.createCell(1).setCellValue(stmt.getCName());
+                    row.createCell(2).setCellValue(stmt.getCName());
+                    row.createCell(3).setCellValue(stmt.getUserTags().toString());
+                    row.createCell(4).setCellValue(stmt.getUserTagNum());
+                }
+            }
+
+            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)
+            {
+
+            }
+
+
+
+
+
+
+
+
+
+
+
+
+
+        }else{
+            return null;
+        }
+
+
+
+
+        return null;
+    }
+
 
 }

+ 27 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/cms/StmtSearchDTO.java

@@ -0,0 +1,27 @@
+package cn.rankin.data.api.cms;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+@Data
+@ToString
+public class StmtSearchDTO implements Serializable {
+
+    private String merchantId;
+
+    private String campusId;
+
+    private String name;
+
+    private String uid;
+
+    private String code;
+
+    private String sort;
+
+    private Integer pageNo = 1;
+
+    private Integer pageSize = 10;
+}

+ 3 - 2
rankin-data-api/src/main/java/cn/rankin/data/api/cms/vo/UserTagStmt.java

@@ -1,6 +1,5 @@
 package cn.rankin.data.api.cms.vo;
 
-import cn.rankin.data.api.user.entity.UserTag;
 import lombok.Data;
 import lombok.ToString;
 
@@ -21,7 +20,9 @@ public class UserTagStmt implements Serializable {
 
     private String uCode;
 
-    private List<UserTag> userTags;
+    private List<String> userTags;
+
+    private int userTagNum;
 
 
 }

+ 3 - 3
rankin-user-service/src/main/java/cn/rankin/userservice/controller/StmtUserTagController.java

@@ -2,8 +2,8 @@ package cn.rankin.userservice.controller;
 
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.cms.StmtSearchDTO;
 import cn.rankin.data.api.cms.vo.UserTagStmt;
-import cn.rankin.data.api.user.dto.UserTagSearchDTO;
 import cn.rankin.userservice.service.StmtService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +22,8 @@ public class StmtUserTagController
     private StmtService stmtService;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public APIResult<Page<UserTagStmt>> UserTagStmtPage(UserTagSearchDTO searchDTO) {
-        return stmtService.userTagStmtPage(searchDTO.getMerchantId(),searchDTO.getCampusId(),searchDTO.getPageSize(),searchDTO.getPageNo());
+    public APIResult<Page<UserTagStmt>> UserTagStmtPage(StmtSearchDTO searchDTO) {
+        return stmtService.userTagStmtPage(searchDTO.getCode(),searchDTO.getMerchantId(),searchDTO.getCampusId(),searchDTO.getPageSize(),searchDTO.getPageNo());
     }
 
 

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

@@ -16,12 +16,12 @@ public interface StmtRepository extends BasicJpaRepository<UserTag, String> {
      */
     @Query(value = "SELECT COUNT(1) FROM u_terminal_user tu " +
             " WHERE tu.id IN ( SELECT tag.uid FROM u_user_tag tag WHERE tag.status = 0 )" +
-            " AND if(?1 !='',tu.merchant_id=?1,1=1) AND if(?2 !='',tu.campus_id=?2,1=1) ",nativeQuery = true)
-    int userCount(String merchantId, String campusId);
+            " 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) ",nativeQuery = true)
+    int userCount(String code, String merchantId, String campusId);
 
     @Query(value = "SELECT  tu.id  FROM u_terminal_user tu " +
             " WHERE tu.id IN ( SELECT tag.uid FROM u_user_tag tag WHERE tag.status = 0 ) " +
-            " AND if(?1 !='',tu.merchant_id=?1,1=1) AND if(?2 !='',tu.campus_id=?2,1=1)  " +
-            " ORDER BY tu.gmt_created DESC LIMIT ?3,?4 ",nativeQuery = true)
-    List<String> uidList(String merchantId, String campusId, long start, Integer pageSize);
+            " 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 LIMIT ?4,?5 ",nativeQuery = true)
+    List<String> uidList(String code, String merchantId, String campusId, long start, Integer pageSize);
 }

+ 13 - 10
rankin-user-service/src/main/java/cn/rankin/userservice/service/StmtService.java

@@ -20,9 +20,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
+import java.util.*;
 
 import static cn.rankin.userservice.utils.DTOConverter.convert;
 
@@ -41,17 +39,16 @@ public class StmtService {
     private UserTagRepository userTagRepository;
 
 
-    public APIResult<Page<UserTagStmt>> userTagStmtPage(String merchantId, String campusId, Integer pageSize, Integer pageNo) {
+    public APIResult<Page<UserTagStmt>> userTagStmtPage(String code, String merchantId, String campusId, Integer pageSize, Integer pageNo) {
 
-
-        long count = (long)stmtRepository.userCount(merchantId, campusId);
+        long count = (long)stmtRepository.userCount(code, merchantId, campusId);
 
         Page<UserTagStmt> page = new Page(count, pageNo, pageSize);
         if (count == 0) {
             return APIResult.ok(page);
         }
 
-        List<String> uids = stmtRepository.uidList(merchantId, campusId, page.getStart() , page.getPageSize());
+        List<String> uids = stmtRepository.uidList(code, merchantId, campusId, page.getStart() , page.getPageSize());
 
         List<UserTagStmt> data = new ArrayList<>();
         uids.forEach(uid -> {
@@ -65,9 +62,15 @@ public class StmtService {
                 if(null != campus){
                     stmt.setCName(campus.getName());
                 }
-
-                stmt.setUserTags(userTagRepository.findUserTagByUidStatus(uid, BaseStatusEnum.NORMAL));
-
+                List<UserTag> userTags = userTagRepository.findUserTagByUidStatus(uid, BaseStatusEnum.NORMAL);
+                if(!CollectionUtils.isEmpty(userTags)){
+                    List<String> tags = new ArrayList<>();
+                    userTags.forEach(userTag -> {
+                        tags.add(userTag.getName());
+                    });
+                    stmt.setUserTags(tags);
+                    stmt.setUserTagNum(tags.size());
+                }
                 data.add(stmt);
             }
         });