xda 3 лет назад
Родитель
Сommit
c1997964fe

+ 4 - 0
src/main/java/com/winhc/repal/entity/RepalBill.java

@@ -12,8 +12,10 @@ import java.io.Serializable;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import org.springframework.format.annotation.DateTimeFormat;
 
@@ -26,6 +28,8 @@ import org.springframework.format.annotation.DateTimeFormat;
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
 @TableName("REPAL_BILL")
+@AllArgsConstructor
+@NoArgsConstructor
 @ApiModel(value="RepalBill实体对象", description="回款宝账款")
 public class RepalBill implements Serializable {
 

+ 4 - 3
src/main/java/com/winhc/repal/model/vo/HomeGradeVO.java

@@ -2,7 +2,9 @@ package com.winhc.repal.model.vo;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 /**
  * @Description: HomeGradeVO
@@ -11,11 +13,10 @@ import lombok.Data;
  */
 @Data
 @ApiModel("账本首页评级")
+@AllArgsConstructor
+@NoArgsConstructor
 public class HomeGradeVO {
 
-    @ApiModelProperty("级别描述")
-    private String grade;
-
     @ApiModelProperty("数量")
     private Integer count;
 

+ 19 - 2
src/main/java/com/winhc/repal/repository/RepalBillMapper.java

@@ -3,6 +3,7 @@ package com.winhc.repal.repository;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.winhc.repal.entity.RepalBill;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.winhc.repal.model.bo.BillPageBO;
 import com.winhc.repal.model.bo.ManageBillInfoBO;
 import com.winhc.repal.model.bo.RepalManageBillPageBO;
 import com.winhc.repal.model.bo.TotalMoneyBO;
@@ -26,12 +27,12 @@ public interface RepalBillMapper extends BaseMapper<RepalBill> {
     /**
      * 获取账款列表
      * @param page page
-     * @param dto dto
+     * @param billPageBO billPageBO
      * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.winhc.repal.entity.RepalBill>
      * @author xda
      * @date 2022/4/13 17:44
      */
-    Page<RepalBill> getRepalBillPage(Page<RepalBill> page, GetRepalBillPageDTO dto);
+    Page<RepalBill> getRepalBillPage(Page<RepalBill> page, BillPageBO billPageBO);
 
 
     /**
@@ -114,4 +115,20 @@ public interface RepalBillMapper extends BaseMapper<RepalBill> {
      */
     List<Long> getBillIdListByBookId(@Param("repalBookId") Long repalBookId,
                                      @Param("userId") Long userId);
+
+
+    /**
+     * 获取账本下账款的评级
+     * @param repalBookId repalBookId
+     * @param userId userId
+     * @param start start
+     * @param end end
+     * @return java.util.List<java.lang.String>
+     * @author xda
+     * @date 2022/5/7 18:22
+     */
+    List<String> getBillGradeByBookId(@Param("repalBookId") Long repalBookId,
+                                      @Param("userId") Long userId,
+                                      @Param("start") LocalDateTime start,
+                                      @Param("end") LocalDateTime end);
 }

+ 3 - 11
src/main/java/com/winhc/repal/repository/RepalRemindHistoryMapper.java

@@ -26,7 +26,9 @@ public interface RepalRemindHistoryMapper extends BaseMapper<RepalRemindHistory>
                                               @Param("overdueId")Long overdueId,
                                               @Param("financeId")Long financeId,
                                               @Param("repalBookId")Long repalBookId,
-                                              @Param("repalBillId")Long repalBillId);
+                                              @Param("repalBillId")Long repalBillId,
+                                              @Param("startTime") LocalDateTime startTime,
+                                              @Param("endTime") LocalDateTime endTime);
 
     /**
      * 查询动态的数量
@@ -41,16 +43,6 @@ public interface RepalRemindHistoryMapper extends BaseMapper<RepalRemindHistory>
                                    @Param("financeId")Long financeId);
 
     /**
-     * 查看账款列表最新的动态id
-     * @param repalBillIdList repalBillIdList
-     * @return java.util.List<com.winhc.repal.model.bo.BillRemindBO>
-     * @author xda
-     * @date 2022/4/30 13:39
-     */
-    List<BillRemindBO> repalRemindHistoryMapper(List<Long> repalBillIdList);
-
-
-    /**
      * 获取账款动态总数
      * @param repalBookId repalBookId
      * @param userId userId

+ 13 - 0
src/main/java/com/winhc/repal/service/RepalBillService.java

@@ -6,6 +6,7 @@ import com.winhc.repal.entity.RepalBill;
 import com.winhc.repal.model.dto.*;
 import com.winhc.repal.model.vo.*;
 
+import java.time.LocalDateTime;
 import java.util.List;
 
 
@@ -136,4 +137,16 @@ public interface RepalBillService extends IService<RepalBill> {
      * @date 2022/5/7 17:05
      */
     List<Long> getBillIdListByBookId(Long repalBookId, Long userId);
+
+    /**
+     * 获取账本下账款的评级
+     * @param repalBookId repalBookId
+     * @param userId userId
+     * @param start start
+     * @param end end
+     * @return java.util.List<java.lang.String>
+     * @author xda
+     * @date 2022/5/7 18:28
+     */
+    List<String> getBillGradeByBookId(Long repalBookId, Long userId, LocalDateTime start, LocalDateTime end);
 }

+ 18 - 12
src/main/java/com/winhc/repal/service/RepalRemindHistoryService.java

@@ -26,12 +26,17 @@ import java.util.Map;
  * @date 2022-04-08
  */
 public interface RepalRemindHistoryService extends IService<RepalRemindHistory> {
+
     /**
      * 查询未读数量
-     * @param repalBillIds
-     * @return
+     * @param repalBills repalBills
+     * @param userId userId
+     * @param startTime startTime
+     * @param endTime endTime
+     * @return com.winhc.repal.model.vo.RepalBillRemindUnReadVO
+     * @date 2022/5/7 19:46
      */
-    RepalBillRemindUnReadVO getRemindUnReadVO(List<RepalBill> repalBills,Long userId);
+    RepalBillRemindUnReadVO getRemindUnReadVO(List<RepalBill> repalBills,Long userId, LocalDateTime startTime, LocalDateTime endTime);
 
     /**
      * 新增评级提醒
@@ -64,15 +69,6 @@ public interface RepalRemindHistoryService extends IService<RepalRemindHistory>
      */
     VOPage<RepalRemindHistoryVO> find(RepalRemindHistoryDTO dto, Integer pageNum, Integer pageSize,UserBean userBean);
 
-    /**
-     * 查看账款列表最新的动态id
-     * @param repalBillIdList repalBillIdList
-     * @return java.util.List<com.winhc.repal.model.bo.BillRemindBO>
-     * @author xda
-     * @date 2022/4/30 13:38
-     */
-    Map<Long, List<BillRemindBO>> getRepalBillLastRemind(List<Long> repalBillIdList);
-
 
     /**
      * 获取账款动态总数
@@ -88,4 +84,14 @@ public interface RepalRemindHistoryService extends IService<RepalRemindHistory>
                                                  Long userId,
                                                  LocalDateTime startDateTime,
                                                  LocalDateTime endDateTime);
+
+
+    RepalBillRemindUnReadVO getBillRemindUnReadVO(Long riskId,
+                                              Long rankId,
+                                              Long overdueId,
+                                              Long financeId,
+                                              Long repalBookId,
+                                              Long repalBillId,
+                                              LocalDateTime startTime,
+                                              LocalDateTime endTime);
 }

+ 9 - 9
src/main/java/com/winhc/repal/service/RepalRemindReadInfoService.java

@@ -28,15 +28,15 @@ public interface RepalRemindReadInfoService extends IService<RepalRemindReadInfo
     void updateReadInfoByUserId(Long userId,String trendType,Long repalBillId,Long repalBookId);
 
 
-    /**
-     * 批量获取用户各种未读数量
-     * @param userId userId
-     * @param repalBillIdList repalBillIdList
-     * @return java.util.List<com.winhc.repal.model.bo.UserBillUnreadInfoBO>
-     * @author xda
-     * @date 2022/4/30 10:03
-     */
-    List<UserBillUnreadInfoBO> getUserBillUnreadInfo(Long userId, List<Long> repalBillIdList);
+//    /**
+//     * 批量获取用户各种未读数量
+//     * @param userId userId
+//     * @param repalBillIdList repalBillIdList
+//     * @return java.util.List<com.winhc.repal.model.bo.UserBillUnreadInfoBO>
+//     * @author xda
+//     * @date 2022/4/30 10:03
+//     */
+//    List<UserBillUnreadInfoBO> getUserBillUnreadInfo(Long userId, List<Long> repalBillIdList);
 
 
 

+ 46 - 32
src/main/java/com/winhc/repal/service/impl/RepalBillServiceImpl.java

@@ -43,6 +43,7 @@ import java.math.RoundingMode;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.function.Function;
@@ -113,13 +114,13 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
 
     @Override
     public RepalBillInfoVO getRepalBillPage(GetRepalBillPageDTO dto) {
-        Long groupId = repalGroupMemberService.getUserGroupId(UserContextUtil.getUser().getUserId());
-
+        long userId = UserContextUtil.getUser().getUserId();
+        Long groupId = repalGroupMemberService.getUserGroupId(userId);
         VOPage<RepalBillPageVO> voPage = new VOPage<>();
         voPage.setPageSize(dto.getPageSize());
         voPage.setPageNum(dto.getPageNum());
         RepalBillInfoVO infoVO = new RepalBillInfoVO();
-        boolean allFlag = repalRolePermissionService.checkUserPermission(UserContextUtil.getUser().getUserId(),
+        boolean allFlag = repalRolePermissionService.checkUserPermission(userId,
                 RepalBillTypeEnum.RECEIVABLE.getCode().equals(dto.getRepalBillType()) ? PermissionEnum.QUERY_ALL_RECEIVABLE.getCode() : PermissionEnum.QUERY_ALL_RECEIPT.getCode());
         LOGGER.info("allFlag:[{}]", allFlag);
         TotalMoneyBO totalMoneyBO;
@@ -131,9 +132,9 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
             totalBO = repalBillMapper.getTotalMoneyByGroup(groupId, dto.getRepalBillType(), null, dto.getRepalBookId());
         } else {
             // 只查询自己负责的
-            totalMoneyBO = repalBillMapper.getTotalMoneyByUser(UserContextUtil.getUser().getUserId(), groupId, dto.getRepalBillType(), RepalBillStatusEnum.PROGRESSING.getCode(), dto.getRepalBookId());
-            overdueBO = repalBillMapper.getTotalMoneyByUser(UserContextUtil.getUser().getUserId(), groupId, dto.getRepalBillType(), RepalBillStatusEnum.OVERDUE.getCode(), dto.getRepalBookId());
-            totalBO = repalBillMapper.getTotalMoneyByUser(UserContextUtil.getUser().getUserId(), groupId, dto.getRepalBillType(), null, dto.getRepalBookId());
+            totalMoneyBO = repalBillMapper.getTotalMoneyByUser(userId, groupId, dto.getRepalBillType(), RepalBillStatusEnum.PROGRESSING.getCode(), dto.getRepalBookId());
+            overdueBO = repalBillMapper.getTotalMoneyByUser(userId, groupId, dto.getRepalBillType(), RepalBillStatusEnum.OVERDUE.getCode(), dto.getRepalBookId());
+            totalBO = repalBillMapper.getTotalMoneyByUser(userId, groupId, dto.getRepalBillType(), null, dto.getRepalBookId());
         }
         infoVO.setTotalBillMoneyStr(totalMoneyBO.getTotalMoney().stripTrailingZeros().toPlainString());
         infoVO.setTotalBillCount(totalMoneyBO.getTotalCount());
@@ -145,7 +146,7 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
         Page<RepalBill> repalBillPage = new Page<>(dto.getPageNum(),dto.getPageSize());
         BillPageBO billPageBO = new BillPageBO();
         BeanUtils.copyProperties(dto, billPageBO);
-        billPageBO.setUserId(UserContextUtil.getUser().getUserId());
+        billPageBO.setUserId(userId);
         billPageBO.setAllFlag(allFlag);
         // 对应1-4到期时间
         if (Objects.nonNull(dto.getOverdueType())) {
@@ -169,7 +170,7 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
                     break;
             }
         }
-        repalBillPage = repalBillMapper.getRepalBillPage(repalBillPage, dto);
+        repalBillPage = repalBillMapper.getRepalBillPage(repalBillPage, billPageBO);
         voPage.setTotalPage(Math.toIntExact(repalBillPage.getPages()));
         voPage.setTotalNum(repalBillPage.getTotal());
         voPage.setDataList(new ArrayList<>());
@@ -179,25 +180,29 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
         }
         // 未读消息
         List<Long> billIdList = repalBillPage.getRecords().stream().map(RepalBill::getId).collect(Collectors.toList());
-        List<UserBillUnreadInfoBO> unreadInfoList = repalRemindReadInfoService.getUserBillUnreadInfo(UserContextUtil.getUser().getUserId(), billIdList);
-        Map<Long, UserBillUnreadInfoBO> unreadInfoMap = new HashMap<>();
-        if (CollUtil.isNotEmpty(unreadInfoList)) {
-            unreadInfoMap = unreadInfoList.stream().collect(Collectors.toMap(UserBillUnreadInfoBO::getRepalBillId, Function.identity()));
-        }
+        Map<Long, RepalBillRemindUnReadVO> unreadMap = new HashMap<>();
+        repalBillPage.getRecords().parallelStream().forEach(repalBill -> {
+            RepalRemindReadInfo repalRemindReadInfo = repalRemindReadInfoService.getReadInfoByUserId(userId,repalBill.getId(),repalBill.getRepalBookId());
+            RepalBillRemindUnReadVO readVO = repalRemindHistoryService.getBillRemindUnReadVO(repalRemindReadInfo.getRiskRemindId(),
+                    repalRemindReadInfo.getRankRemindId(),repalRemindReadInfo.getOverdueRemindId(),
+                    repalRemindReadInfo.getFinanceRemindId(),repalBill.getRepalBookId(),repalBill.getId(),
+                    Objects.isNull(billPageBO.getStartDate()) ? null : LocalDateTime.of(billPageBO.getStartDate(), LocalTime.MIN),
+                    Objects.isNull(billPageBO.getEndDate()) ? null : LocalDateTime.of(billPageBO.getEndDate(), LocalTime.MAX));
+            unreadMap.put(repalBill.getId(), readVO);
+        });
         Map<Long, List<String>> nameMap = repalResponsiblePersonService.getResponsiblePersonNameList(billIdList);
-        Map<Long, UserBillUnreadInfoBO> finalUnreadInfoMap = unreadInfoMap;
         voPage.setDataList(repalBillPage.getRecords().stream().map(t -> {
             RepalBillPageVO vo = new RepalBillPageVO();
             BeanUtils.copyProperties(t, vo);
             vo.setRepalBillId(t.getId());
             vo.setResponsiblePersonNames(String.join("、", nameMap.get(t.getId())));
-            UserBillUnreadInfoBO unreadInfoBO = finalUnreadInfoMap.get(vo.getRepalBillId());
-            if (Objects.nonNull(unreadInfoBO)) {
+            RepalBillRemindUnReadVO unReadVO = unreadMap.get(vo.getRepalBillId());
+            if (Objects.nonNull(unReadVO)) {
                 vo.setDynamicCountList(new ArrayList<Integer>(){{
-                    add(unreadInfoBO.getUnreadRiskCount());
-                    add(unreadInfoBO.getUnreadFinanceCount());
-                    add(unreadInfoBO.getUnreadRankCount());
-                    add(unreadInfoBO.getUnreadOverdueCount());
+                    add(unReadVO.getUnreadRiskCount());
+                    add(unReadVO.getUnreadFinanceCount());
+                    add(unReadVO.getUnreadRankCount());
+                    add(unReadVO.getUnreadOverdueCount());
                 }});
             }
             return vo;
@@ -512,25 +517,29 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
         }
         // 未读消息
         List<Long> billIdList = repalBillPage.getRecords().stream().map(RepalBill::getId).collect(Collectors.toList());
-        List<UserBillUnreadInfoBO> unreadInfoList = repalRemindReadInfoService.getUserBillUnreadInfo(UserContextUtil.getUser().getUserId(), billIdList);
-        Map<Long, UserBillUnreadInfoBO> unreadInfoMap = new HashMap<>();
-        if (CollUtil.isNotEmpty(unreadInfoList)) {
-            unreadInfoMap = unreadInfoList.stream().collect(Collectors.toMap(UserBillUnreadInfoBO::getRepalBillId, Function.identity()));
-        }
+        long userId = UserContextUtil.getUser().getUserId();
+        Map<Long, RepalBillRemindUnReadVO> unreadMap = new HashMap<>();
+        repalBillPage.getRecords().parallelStream().forEach(repalBill -> {
+            RepalRemindReadInfo repalRemindReadInfo = repalRemindReadInfoService.getReadInfoByUserId(userId,repalBill.getId(),repalBill.getRepalBookId());
+            RepalBillRemindUnReadVO readVO = repalRemindHistoryService.getBillRemindUnReadVO(repalRemindReadInfo.getRiskRemindId(),
+                    repalRemindReadInfo.getRankRemindId(),repalRemindReadInfo.getOverdueRemindId()
+                    ,repalRemindReadInfo.getFinanceRemindId(),repalBill.getRepalBookId(),repalBill.getId(),
+                    null, null);
+            unreadMap.put(repalBill.getId(), readVO);
+        });
         Map<Long, List<String>> nameMap = repalResponsiblePersonService.getResponsiblePersonNameList(billIdList);
-        Map<Long, UserBillUnreadInfoBO> finalUnreadInfoMap = unreadInfoMap;
         voPage.setDataList(repalBillPage.getRecords().stream().map(t -> {
             RepalBillPageVO vo = new RepalBillPageVO();
             BeanUtils.copyProperties(t, vo);
             vo.setRepalBillId(t.getId());
             vo.setResponsiblePersonNames(String.join("、", nameMap.get(t.getId())));
-            UserBillUnreadInfoBO unreadInfoBO = finalUnreadInfoMap.get(vo.getRepalBillId());
-            if (Objects.nonNull(unreadInfoBO)) {
+            RepalBillRemindUnReadVO unReadVO = unreadMap.get(vo.getRepalBillId());
+            if (Objects.nonNull(unReadVO)) {
                 vo.setDynamicCountList(new ArrayList<Integer>(){{
-                    add(unreadInfoBO.getUnreadRiskCount());
-                    add(unreadInfoBO.getUnreadFinanceCount());
-                    add(unreadInfoBO.getUnreadRankCount());
-                    add(unreadInfoBO.getUnreadOverdueCount());
+                    add(unReadVO.getUnreadRiskCount());
+                    add(unReadVO.getUnreadFinanceCount());
+                    add(unReadVO.getUnreadRankCount());
+                    add(unReadVO.getUnreadOverdueCount());
                 }});
             }
             return vo;
@@ -684,4 +693,9 @@ public class RepalBillServiceImpl extends ServiceImpl<RepalBillMapper, RepalBill
     public List<Long> getBillIdListByBookId(Long repalBookId, Long userId) {
         return repalBillMapper.getBillIdListByBookId(repalBookId, userId);
     }
+
+    @Override
+    public List<String> getBillGradeByBookId(Long repalBookId, Long userId, LocalDateTime start, LocalDateTime end) {
+        return repalBillMapper.getBillGradeByBookId(repalBookId, userId, start, end);
+    }
 }

+ 35 - 21
src/main/java/com/winhc/repal/service/impl/RepalBookServiceImpl.java

@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.winhc.common.enums.CodeMsg;
 import com.winhc.common.exception.CommonException;
+import com.winhc.repal.entity.RepalBill;
 import com.winhc.repal.entity.RepalBook;
-import com.winhc.repal.entity.RepalResponsiblePerson;
 import com.winhc.repal.enums.DeletedStatusEnum;
 import com.winhc.repal.enums.PermissionEnum;
 import com.winhc.repal.model.bo.BookDynamicCountBO;
@@ -14,9 +14,11 @@ import com.winhc.repal.model.bo.UserBillUnreadInfoBO;
 import com.winhc.repal.model.dto.DeleteRepalBookDTO;
 import com.winhc.repal.model.dto.HomeTypeDTO;
 import com.winhc.repal.model.vo.HomeGradeVO;
+import com.winhc.repal.model.vo.RepalBillRemindUnReadVO;
 import com.winhc.repal.model.vo.RepalBookInfoVO;
 import com.winhc.repal.repository.RepalBookMapper;
 import com.winhc.repal.service.*;
+import com.winhc.repal.util.BillGradeUtil;
 import com.winhc.repal.util.RemindTypeUtil;
 import com.winhc.repal.util.UserContextUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,7 +30,6 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -85,17 +86,15 @@ public class RepalBookServiceImpl extends ServiceImpl<RepalBookMapper, RepalBook
     @Override
     public List<RepalBookInfoVO> getRepalBookInfoList() {
         Set<String> codeSet = repalRolePermissionService.getUserPermissionCodeSet(UserContextUtil.getUser().getUserId());
-        // todo
-        //boolean receivableFlag = codeSet.contains(PermissionEnum.QUERY_ALL_RECEIVABLE.getCode());
-        boolean receivableFlag = true;
-        //boolean receiptFlag = codeSet.contains(PermissionEnum.QUERY_ALL_RECEIPT.getCode());
-        boolean receiptFlag = true;
+        boolean receivableFlag = codeSet.contains(PermissionEnum.QUERY_ALL_RECEIVABLE.getCode());
+        boolean receiptFlag = codeSet.contains(PermissionEnum.QUERY_ALL_RECEIPT.getCode());
         return repalBookMapper.getRepalBookInfoList(UserContextUtil.getUser().getUserId(), repalGroupMemberService.getUserGroupId(UserContextUtil.getUser().getUserId()), receivableFlag, receiptFlag);
     }
 
     @Override
     public List<List<Integer>> getRepalBookDynamic(HomeTypeDTO dto) {
         List<List<Integer>> resultList = new ArrayList<>();
+        long userId = UserContextUtil.getUser().getUserId();
         boolean allFlag = repalRolePermissionService.checkUserPermission(UserContextUtil.getUser().getUserId(), PermissionEnum.QUERY_ALL_RECEIVABLE.getCode());
         // 所有
         LocalDateTime start = null;
@@ -110,27 +109,42 @@ public class RepalBookServiceImpl extends ServiceImpl<RepalBookMapper, RepalBook
             start = LocalDateTime.of(now.minusDays(30), LocalTime.MIN);
             end = LocalDateTime.of(now, LocalTime.MAX);
         }
-        List<BookDynamicCountBO> countList = repalRemindHistoryService.getBookDynamicCount(dto.getRepalBookId(), allFlag ? UserContextUtil.getUser().getUserId() : null, start, end);
+        List<BookDynamicCountBO> countList = repalRemindHistoryService.getBookDynamicCount(dto.getRepalBookId(), allFlag ? userId : null, start, end);
         List<Integer> totalCountList = RemindTypeUtil.getCountList(CollUtil.isEmpty(countList) ? null : countList.stream().collect(Collectors.toMap(BookDynamicCountBO::getRemindType, BookDynamicCountBO::getTotalCount)));
         resultList.add(totalCountList);
         // 未读, 有可能是账本下所有未读
-        List<Long> billIdList = repalBillService.getBillIdListByBookId(dto.getRepalBookId(), allFlag ? null : UserContextUtil.getUser().getUserId());;
-        List<UserBillUnreadInfoBO> unreadInfoList = repalRemindReadInfoService.getUserBillUnreadInfo(UserContextUtil.getUser().getUserId(), billIdList);
-        resultList.add(new ArrayList<Integer>(){{
-            add(unreadInfoList.stream().mapToInt(UserBillUnreadInfoBO::getUnreadRiskCount).sum());
-            add(unreadInfoList.stream().mapToInt(UserBillUnreadInfoBO::getUnreadFinanceCount).sum());
-            add(unreadInfoList.stream().mapToInt(UserBillUnreadInfoBO::getUnreadRankCount).sum());
-            add(unreadInfoList.stream().mapToInt(UserBillUnreadInfoBO::getUnreadOverdueCount).sum());
-        }});
+        List<Long> billIdList = repalBillService.getBillIdListByBookId(dto.getRepalBookId(), allFlag ? null : userId);;
+        RepalBillRemindUnReadVO unReadVO = repalRemindHistoryService.getRemindUnReadVO(billIdList.stream().map(t -> new RepalBill().setId(t).setRepalBookId(dto.getRepalBookId())).collect(Collectors.toList()), userId, start, end);
+        List<Integer> unreadList = new ArrayList<Integer>(){{
+            add(unReadVO.getUnreadRiskCount());
+            add(unReadVO.getUnreadFinanceCount());
+            add(unReadVO.getUnreadRankCount());
+            add(unReadVO.getUnreadOverdueCount());
+        }};
+        resultList.add(unreadList);
         return resultList;
     }
 
     @Override
     public List<HomeGradeVO> getGradeRateList(HomeTypeDTO dto) {
-
-
-
-
-        return null;
+        boolean allFlag = repalRolePermissionService.checkUserPermission(UserContextUtil.getUser().getUserId(), PermissionEnum.QUERY_ALL_RECEIVABLE.getCode());
+        // 所有
+        LocalDateTime start = null;
+        LocalDateTime end = null;
+        if (Integer.valueOf(1).equals(dto.getQueryType())) {
+            LocalDate now = LocalDate.now();
+            start = LocalDateTime.of(now.minusDays(7), LocalTime.MIN);
+            end = LocalDateTime.of(now, LocalTime.MAX);
+        }
+        if (Integer.valueOf(2).equals(dto.getQueryType())) {
+            LocalDate now = LocalDate.now();
+            start = LocalDateTime.of(now.minusDays(30), LocalTime.MIN);
+            end = LocalDateTime.of(now, LocalTime.MAX);
+        }
+        List<String> gradeList = repalBillService.getBillGradeByBookId(dto.getRepalBookId(), allFlag ? null : UserContextUtil.getUser().getUserId(), start, end);
+        if (CollUtil.isEmpty(gradeList)) {
+            return new ArrayList<>();
+        }
+        return BillGradeUtil.getGradeList(gradeList);
     }
 }

+ 2 - 2
src/main/java/com/winhc/repal/service/impl/RepalCustomerServiceImpl.java

@@ -146,7 +146,7 @@ public class RepalCustomerServiceImpl extends ServiceImpl<RepalCustomerMapper, R
                          .eq(RepalBill::getCustomerId, customerInfo.getCustId())
                          .eq(RepalBill::getDeleted, Dict.DeletedStatusEnunm.否.getCode()));
                  if (CollUtil.isNotEmpty(repalBills)) {
-                     RepalBillRemindUnReadVO unRead = repalRemindHistoryService.getRemindUnReadVO(repalBills, userBean.getUserId());
+                     RepalBillRemindUnReadVO unRead = repalRemindHistoryService.getRemindUnReadVO(repalBills, userBean.getUserId(), null, null);
                      if (ObjectUtil.isNotNull(unRead) && unRead.getUnreadTotalCount() > 0) {
                          vo.setDynamicCountList(Stream.of(unRead.getUnreadOverdueCount(), unRead.getUnreadRiskCount(), unRead.getUnreadRankCount(), unRead.getUnreadFinanceCount()).collect(Collectors.toList()));
                      }
@@ -457,7 +457,7 @@ public class RepalCustomerServiceImpl extends ServiceImpl<RepalCustomerMapper, R
                 result.setTotalOverdueStr(repalBills.stream().filter(x-> RepalBillStatusEnum.OVERDUE.getCode().equals(x.getRepalBillStatus())).map(RepalBill::getReceivable).reduce(BigDecimal.ZERO,BigDecimal::add).stripTrailingZeros().toPlainString());
                 result.setTotalReceiptStr(repalBills.stream().map(RepalBill::getReceipt).reduce(BigDecimal.ZERO,BigDecimal::add).stripTrailingZeros().toPlainString());
                 //动态
-                RepalBillRemindUnReadVO unRead = repalRemindHistoryService.getRemindUnReadVO(repalBills, userBean.getUserId());
+                RepalBillRemindUnReadVO unRead = repalRemindHistoryService.getRemindUnReadVO(repalBills, userBean.getUserId(), null, null);
                 if (ObjectUtil.isNotNull(unRead) && unRead.getUnreadTotalCount() > 0) {
                     result.setDynamicCountList(Stream.of(unRead.getUnreadOverdueCount(), unRead.getUnreadRiskCount(), unRead.getUnreadRankCount(), unRead.getUnreadFinanceCount()).collect(Collectors.toList()));
                 }

+ 8 - 10
src/main/java/com/winhc/repal/service/impl/RepalRemindHistoryServiceImpl.java

@@ -77,12 +77,14 @@ public class RepalRemindHistoryServiceImpl extends ServiceImpl<RepalRemindHistor
     private RepalGroupMemberService repalGroupMemberService;
 
     @Override
-    public RepalBillRemindUnReadVO getRemindUnReadVO(List<RepalBill> repalBills,Long userId) {
+    public RepalBillRemindUnReadVO getRemindUnReadVO(List<RepalBill> repalBills,Long userId, LocalDateTime startTime ,LocalDateTime endTime) {
         RepalBillRemindUnReadVO result = new RepalBillRemindUnReadVO(0,0,0,0,0);
         for(RepalBill repalBill:repalBills){
             RepalRemindReadInfo repalRemindReadInfo = repalRemindReadInfoService.getReadInfoByUserId(userId,repalBill.getId(),repalBill.getRepalBookId());
             RepalBillRemindUnReadVO readVO = repalRemindHistoryMapper.getRemindUnReadVO(repalRemindReadInfo.getRiskRemindId(),
-                    repalRemindReadInfo.getRankRemindId(),repalRemindReadInfo.getOverdueRemindId(),repalRemindReadInfo.getFinanceRemindId(),repalBill.getRepalBookId(),repalBill.getId());
+                    repalRemindReadInfo.getRankRemindId(),repalRemindReadInfo.getOverdueRemindId(),
+                    repalRemindReadInfo.getFinanceRemindId(),repalBill.getRepalBookId(),repalBill.getId(),
+                    startTime, endTime);
             result.setUnreadRankCount(result.getUnreadRankCount()+readVO.getUnreadRankCount());
             result.setUnreadRiskCount(result.getUnreadRiskCount()+readVO.getUnreadRiskCount());
             result.setUnreadOverdueCount(result.getUnreadOverdueCount()+readVO.getUnreadOverdueCount());
@@ -528,16 +530,12 @@ public class RepalRemindHistoryServiceImpl extends ServiceImpl<RepalRemindHistor
     }
 
     @Override
-    public Map<Long, List<BillRemindBO>> getRepalBillLastRemind(List<Long> repalBillIdList) {
-        List<BillRemindBO> remindBOList = repalRemindHistoryMapper.repalRemindHistoryMapper(repalBillIdList);
-        if (CollUtil.isEmpty(remindBOList)) {
-            return new HashMap<>();
-        }
-        return remindBOList.stream().collect(Collectors.groupingBy(BillRemindBO::getRepalBillId, Collectors.toList()));
+    public List<BookDynamicCountBO> getBookDynamicCount(Long repalBookId, Long userId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
+        return repalRemindHistoryMapper.getBookDynamicCount(repalBookId, userId, startDateTime, endDateTime);
     }
 
     @Override
-    public List<BookDynamicCountBO> getBookDynamicCount(Long repalBookId, Long userId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
-        return repalRemindHistoryMapper.getBookDynamicCount(repalBookId, userId, startDateTime, endDateTime);
+    public RepalBillRemindUnReadVO getBillRemindUnReadVO(Long riskId, Long rankId, Long overdueId, Long financeId, Long repalBookId, Long repalBillId, LocalDateTime startTime, LocalDateTime endTime) {
+        return repalRemindHistoryMapper.getRemindUnReadVO(riskId, rankId, overdueId, financeId, repalBookId, repalBillId, startTime, endTime);
     }
 }

+ 29 - 29
src/main/java/com/winhc/repal/service/impl/RepalRemindReadInfoServiceImpl.java

@@ -143,35 +143,35 @@ public class RepalRemindReadInfoServiceImpl extends ServiceImpl<RepalRemindReadI
         return ChronoUnit.MILLIS.between(LocalDateTime.now(),midnight);
     }
 
-    @Override
-    public List<UserBillUnreadInfoBO> getUserBillUnreadInfo(Long userId, List<Long> repalBillIdList) {
-        if (CollUtil.isEmpty(repalBillIdList)) {
-            return new ArrayList<>();
-        }
-        List<RepalRemindReadInfo> readInfoList = this.list(Wrappers.lambdaQuery(RepalRemindReadInfo.class).eq(RepalRemindReadInfo::getUserId, userId)
-                        .in(RepalRemindReadInfo::getRepalBillId, repalBillIdList));
-        if (CollUtil.isEmpty(readInfoList)) {
-            return new ArrayList<>();
-        }
-        Map<Long, List<BillRemindBO>> remindMap = repalRemindHistoryService.getRepalBillLastRemind(repalBillIdList);
-        if (MapUtil.isEmpty(remindMap)) {
-            return new ArrayList<>();
-        }
-        List<UserBillUnreadInfoBO> unreadInfoList = new ArrayList<>();
-        readInfoList.forEach(readInfo -> {
-            List<BillRemindBO> remindBOList = remindMap.get(readInfo.getRepalBillId());
-            if (CollUtil.isNotEmpty(remindBOList)) {
-                UserBillUnreadInfoBO unreadInfo = new UserBillUnreadInfoBO();
-                unreadInfo.setRepalBillId(readInfo.getRepalBillId());
-                unreadInfo.setUnreadFinanceCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.财产线索.getCode()));
-                unreadInfo.setUnreadRankCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.账款评级.getCode()));
-                unreadInfo.setUnreadOverdueCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.逾期提醒.getCode()));
-                unreadInfo.setUnreadRiskCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.风险预警.getCode()));
-                unreadInfoList.add(unreadInfo);
-            }
-        });
-        return unreadInfoList;
-    }
+//    @Override
+//    public List<UserBillUnreadInfoBO> getUserBillUnreadInfo(Long userId, List<Long> repalBillIdList) {
+//        if (CollUtil.isEmpty(repalBillIdList)) {
+//            return new ArrayList<>();
+//        }
+//        List<RepalRemindReadInfo> readInfoList = this.list(Wrappers.lambdaQuery(RepalRemindReadInfo.class).eq(RepalRemindReadInfo::getUserId, userId)
+//                        .in(RepalRemindReadInfo::getRepalBillId, repalBillIdList));
+//        if (CollUtil.isEmpty(readInfoList)) {
+//            return new ArrayList<>();
+//        }
+//        Map<Long, List<BillRemindBO>> remindMap = repalRemindHistoryService.getRepalBillLastRemind(repalBillIdList);
+//        if (MapUtil.isEmpty(remindMap)) {
+//            return new ArrayList<>();
+//        }
+//        List<UserBillUnreadInfoBO> unreadInfoList = new ArrayList<>();
+//        readInfoList.forEach(readInfo -> {
+//            List<BillRemindBO> remindBOList = remindMap.get(readInfo.getRepalBillId());
+//            if (CollUtil.isNotEmpty(remindBOList)) {
+//                UserBillUnreadInfoBO unreadInfo = new UserBillUnreadInfoBO();
+//                unreadInfo.setRepalBillId(readInfo.getRepalBillId());
+//                unreadInfo.setUnreadFinanceCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.财产线索.getCode()));
+//                unreadInfo.setUnreadRankCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.账款评级.getCode()));
+//                unreadInfo.setUnreadOverdueCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.逾期提醒.getCode()));
+//                unreadInfo.setUnreadRiskCount(getRemindTypeUnread(readInfo.getId(), remindBOList, RemindEnum.风险预警.getCode()));
+//                unreadInfoList.add(unreadInfo);
+//            }
+//        });
+//        return unreadInfoList;
+//    }
 
     /**
      * 计算未读数量

+ 1 - 3
src/main/java/com/winhc/repal/service/impl/RepalRolePermissionServiceImpl.java

@@ -31,9 +31,7 @@ public class RepalRolePermissionServiceImpl extends ServiceImpl<RepalRolePermiss
 
     @Override
     public Boolean checkUserPermission(Long userId, String code) {
-        // todo
-        //return getUserPermissionCodeSet(userId).contains(code);
-        return true;
+        return getUserPermissionCodeSet(userId).contains(code);
     }
 
     @Override

+ 38 - 0
src/main/java/com/winhc/repal/util/BillGradeUtil.java

@@ -0,0 +1,38 @@
+package com.winhc.repal.util;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.winhc.repal.model.vo.HomeGradeVO;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: BillGradeUtil
+ * @Author: xda
+ * @Date: 2022/5/7 18:31
+ */
+public class BillGradeUtil {
+
+
+    public static List<HomeGradeVO> getGradeList(List<String> gradeList) {
+        if (CollUtil.isEmpty(gradeList)) {
+            return new ArrayList<>();
+        }
+        int total = gradeList.size();
+        long aCount = gradeList.stream().filter("A"::equals).count();;
+        long bCount = gradeList.stream().filter("B"::equals).count();;
+        long cCount = gradeList.stream().filter("C"::equals).count();;
+        long dCount = gradeList.stream().filter("D"::equals).count();;
+        long nCount = gradeList.stream().filter(StrUtil::isNotBlank).count();;
+        return new ArrayList<HomeGradeVO>(){{
+            add(new HomeGradeVO(Math.toIntExact(aCount), new BigDecimal(aCount).divide(new BigDecimal(total), 1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()));
+            add(new HomeGradeVO(Math.toIntExact(bCount), new BigDecimal(bCount).divide(new BigDecimal(total), 1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()));
+            add(new HomeGradeVO(Math.toIntExact(cCount), new BigDecimal(cCount).divide(new BigDecimal(total), 1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()));
+            add(new HomeGradeVO(Math.toIntExact(dCount), new BigDecimal(dCount).divide(new BigDecimal(total), 1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()));
+            add(new HomeGradeVO(Math.toIntExact(nCount), new BigDecimal(nCount).divide(new BigDecimal(total), 1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()));
+        }};
+    }
+}

+ 19 - 2
src/main/resources/mapper/RepalBillMapper.xml

@@ -178,11 +178,28 @@
     <select id="getBillIdListByBookId" resultType="java.lang.Long">
         SELECT bill.ID FROM REPAL_BILL AS bill
         <if test="userId != null">
-        LEFT JOIN REPAL_RESPONSIBLE_PERSON AS rPerson ON bill.ID = rPerson.REPAL_BILL_ID
+            LEFT JOIN REPAL_RESPONSIBLE_PERSON AS rPerson ON bill.ID = rPerson.REPAL_BILL_ID
         </if>
         WHERE bill.REPAL_BOOK_ID = #{repalBookId}
         <if test="userId != null">
-            AND bill.USER_ID = #{userId}
+            AND rPerson.USER_ID = #{userId}
+        </if>
+    </select>
+
+    <select id="getBillGradeByBookId" resultType="java.lang.String">
+        SELECT bill.DIAGNOSIS_GRADE FROM REPAL_BILL AS bill
+        <if test="userId != null">
+            LEFT JOIN REPAL_RESPONSIBLE_PERSON AS rPerson ON bill.ID = rPerson.REPAL_BILL_ID
+        </if>
+        WHERE bill.REPAL_BOOK_ID = #{repalBookId}
+        <if test="start != null">
+            AND  bill.DIAGNOSIS_DATETIME >= #{start}
+        </if>
+        <if test="end != null">
+            AND  bill.DIAGNOSIS_DATETIME <![CDATA[<=]]>#{start}
+        </if>
+        <if test="userId != null">
+            AND rPerson.USER_ID = #{userId}
         </if>
     </select>
 </mapper>

+ 36 - 18
src/main/resources/mapper/RepalRemindHistoryMapper.xml

@@ -3,10 +3,38 @@
 <mapper namespace="com.winhc.repal.repository.RepalRemindHistoryMapper">
     <select id="getRemindUnReadVO" resultType="com.winhc.repal.model.vo.RepalBillRemindUnReadVO">
         SELECT
-            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId} AND REPAL_BILL_ID = #{repalBillId} AND REMIND_TYPE = 'RISK' AND ID > #{riskId} ) AS unreadRiskCount,
-            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId} AND REMIND_TYPE = 'RANK' AND ID > #{rankId} ) AS unreadRankCount,
-            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId} AND REMIND_TYPE = 'OVERDUE' AND ID > #{overdueId} ) AS unreadOverdueCount,
-            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId} AND REMIND_TYPE = 'FINANCE' AND ID > #{financeId} ) AS unreadFinanceCount
+            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId} AND REPAL_BILL_ID = #{repalBillId}
+                                                          <if test="startTime != null">
+                                                            AND REMIND_TIME >= #{startTime}
+                                                          </if>
+                                                          <if test="endTime != null">
+                                                            AND REMIND_TIME <![CDATA[<=]]> #{endTime}
+                                                          </if>
+                                                          AND REMIND_TYPE = 'RISK' AND ID > #{riskId} ) AS unreadRiskCount,
+            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId}
+                                                            <if test="startTime != null">
+                                                                AND REMIND_TIME >= #{startTime}
+                                                            </if>
+                                                            <if test="endTime != null">
+                                                                AND REMIND_TIME <![CDATA[<=]]> #{endTime}
+                                                            </if>
+                                                          AND REMIND_TYPE = 'RANK' AND ID > #{rankId} ) AS unreadRankCount,
+            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId}
+                                                            <if test="startTime != null">
+                                                                AND REMIND_TIME >= #{startTime}
+                                                            </if>
+                                                            <if test="endTime != null">
+                                                                AND REMIND_TIME <![CDATA[<=]]> #{endTime}
+                                                            </if>
+                                                          AND REMIND_TYPE = 'OVERDUE' AND ID > #{overdueId} ) AS unreadOverdueCount,
+            ( SELECT count(*) FROM REPAL_REMIND_HISTORY WHERE REPAL_BOOK_ID = #{repalBookId}  AND REPAL_BILL_ID = #{repalBillId}
+                                                            <if test="startTime != null">
+                                                                AND REMIND_TIME >= #{startTime}
+                                                            </if>
+                                                            <if test="endTime != null">
+                                                                AND REMIND_TIME <![CDATA[<=]]> #{endTime}
+                                                            </if>
+                                                          AND REMIND_TYPE = 'FINANCE' AND ID > #{financeId} ) AS unreadFinanceCount
         FROM
             DUAL
     </select>
@@ -48,23 +76,10 @@
     </select>
 
 
-
-    <select id="repalRemindHistoryMapper" parameterType="java.lang.Long" resultType="com.winhc.repal.model.bo.BillRemindBO">
-        SELECT t1.REPAL_BILL_ID AS repalBillId, t1.ID AS repalRemindHistoryId, t1.REMIND_TYPE AS remindType FROM REPAL_REMIND_HISTORY AS t1
-        INNER JOIN
-        (SELECT MAX(tt.ID) AS id, tt.REMIND_TYPE, tt.REPAL_BILL_ID FROM REPAL_REMIND_HISTORY AS tt WHERE
-        tt.REPAL_BILL_ID IN
-        <foreach item="item" index="index" collection="repalBillIdList" open="(" close=")" separator=",">
-            #{item}
-        </foreach>
-        GROUP BY tt.REMIND_TYPE, tt.REPAL_BILL_ID) AS t2 ON t2.id = t1.ID
-    </select>
-
-
     <select id="getBookDynamicCount" resultType="com.winhc.repal.model.bo.BookDynamicCountBO">
         SELECT count(*) AS totalCount, tt.REMIND_TYPE AS remindType FROM REPAL_REMIND_HISTORY AS tt
         <if test="userId != null">
-        LEFT JOIN REPAL_RESPONSIBLE_PERSON AS rPerson ON rPerson.REPAL_BOOK_ID = #{repalBookId} and rPerson.USER_ID = #{userId}
+        LEFT JOIN REPAL_RESPONSIBLE_PERSON AS rPerson ON rPerson.REPAL_BOOK_ID = #{repalBookId}
         </if>
         WHERE
         tt.REPAL_BOOK_ID = #{repalBookId}
@@ -74,6 +89,9 @@
         <if test="endDateTime != null">
             AND tt.REMIND_TIME <![CDATA[<=]]> #{endDateTime}
         </if>
+        <if test="userId != null">
+            AND rPerson.USER_ID = #{userId}
+        </if>
         GROUP BY tt.REMIND_TYPE
     </select>
 </mapper>