Ver código fonte

用户标签报表

guozhaoshun 6 anos atrás
pai
commit
fa5d2f2cce

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

@@ -0,0 +1,32 @@
+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.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;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+
+@Slf4j
+@RestController
+@RequestMapping(value = "/stmt/userTagStmt")
+public class StmtUserTagController
+{
+    @Autowired
+    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());
+    }
+
+
+
+
+}

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

@@ -0,0 +1,27 @@
+package cn.rankin.userservice.repository;
+
+import cn.rankin.common.utils.jpa.BasicJpaRepository;
+import cn.rankin.data.api.user.entity.UserTag;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface StmtRepository extends BasicJpaRepository<UserTag, String> {
+
+    /**
+     * 配置用户标签的终端数量
+     * @param merchantId
+     * @param campusId
+     * @return
+     */
+    @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);
+
+    @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);
+}

+ 3 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/repository/UserTagRepository.java

@@ -30,4 +30,7 @@ public interface UserTagRepository extends BasicJpaRepository<UserTag, String> {
 
     @Query(value = "select t from UserTag t where t.uid = ?1  order by t.sort")
     List<UserTag> findUserTagByUid(String uid);
+
+    @Query(value = "select t from UserTag t where t.uid = ?1 and t.status = ?2 order by t.sort")
+    List<UserTag> findUserTagByUidStatus(String uid,BaseStatusEnum status);
 }

+ 78 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/StmtService.java

@@ -0,0 +1,78 @@
+package cn.rankin.userservice.service;
+
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.common.utils.enums.BaseOrderEnum;
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.common.utils.util.JpaSortUtil;
+import cn.rankin.data.api.cms.vo.UserTagStmt;
+import cn.rankin.data.api.user.dto.UserTagDTO;
+import cn.rankin.data.api.user.entity.Campus;
+import cn.rankin.data.api.user.entity.TerminalUser;
+import cn.rankin.data.api.user.entity.UserTag;
+import cn.rankin.userservice.repository.CampusRepository;
+import cn.rankin.userservice.repository.StmtRepository;
+import cn.rankin.userservice.repository.TerminalUserRepository;
+import cn.rankin.userservice.repository.UserTagRepository;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+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 static cn.rankin.userservice.utils.DTOConverter.convert;
+
+@Slf4j
+@Service
+public class StmtService {
+
+    @Autowired
+    private StmtRepository stmtRepository;
+
+    @Autowired
+    private TerminalUserRepository terminalUserRepository;
+    @Autowired
+    private CampusRepository campusRepository;
+    @Autowired
+    private UserTagRepository userTagRepository;
+
+
+    public APIResult<Page<UserTagStmt>> userTagStmtPage(String merchantId, String campusId, Integer pageSize, Integer pageNo) {
+
+
+        long count = (long)stmtRepository.userCount(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<UserTagStmt> data = new ArrayList<>();
+        uids.forEach(uid -> {
+            TerminalUser terminalUser = terminalUserRepository.find(uid);
+            if(null != terminalUser){
+                UserTagStmt stmt = new UserTagStmt();
+                stmt.setUCode(terminalUser.getCode());
+                stmt.setUid(uid);
+                stmt.setUName(terminalUser.getName());
+                Campus campus = campusRepository.find(terminalUser.getCampusId());
+                if(null != campus){
+                    stmt.setCName(campus.getName());
+                }
+
+                stmt.setUserTags(userTagRepository.findUserTagByUidStatus(uid, BaseStatusEnum.NORMAL));
+
+                data.add(stmt);
+            }
+        });
+
+        page.setList(data);
+        return APIResult.ok(page);
+    }
+}