浏览代码

举报代码修改

zhangchen 3 周之前
父节点
当前提交
4c457c7e28
共有 1 个文件被更改,包括 166 次插入30 次删除
  1. 166 30
      alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerUserViolationServiceImpl.java

+ 166 - 30
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerUserViolationServiceImpl.java

@@ -87,6 +87,21 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
      */
     private static final String REPORT_CONTEXT_TYPE_ORDER = "6";
 
+    /**
+     * 删除标志:未删除
+     */
+    private static final Integer DELETE_FLAG_NOT_DELETED = 0;
+
+    /**
+     * 图片分隔符
+     */
+    private static final String IMAGE_SEPARATOR = ",";
+
+    /**
+     * 最大分页大小
+     */
+    private static final int MAX_PAGE_SIZE = 100;
+
     private final LawyerUserViolationMapper lawyerUserViolationMapper;
 
     private final LawyerUserMapper lawyerUserMapper;
@@ -735,57 +750,178 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
         }
     }
 
+    /**
+     * 分页查询违规举报信息
+     * <p>
+     * 根据查询条件分页查询律师用户违规举报信息,支持按订单号、处理状态、
+     * 被举报人名称、违规原因等条件进行筛选查询
+     * </p>
+     *
+     * @param page            当前页码,从1开始,必须大于0
+     * @param size            每页大小,必须大于0且不超过最大值
+     * @param orderId         订单号,支持模糊查询,可为空
+     * @param processingStatus 处理状态,精确匹配,可为空
+     * @param reportedUserName 被举报人名称,支持模糊查询,可为空
+     * @param violationReason 违规原因,精确匹配,可为空
+     * @return 分页查询结果,包含违规举报DTO列表
+     * @throws RuntimeException 当分页参数无效时抛出
+     * @author system
+     * @since 2025-01-XX
+     */
     @Override
-    public IPage<LawyerUserViolationDto> getViolationPage(int page, int size, String orderId, String processingStatus, String reportedUserName, String violationReason) {
-        IPage<LawyerUserViolationVo> pageRequest = new Page<>(page, size);
+    public IPage<LawyerUserViolationDto> getViolationPage(int page, int size, String orderId,
+                                                           String processingStatus, String reportedUserName,
+                                                           String violationReason) {
+        // 参数校验
+        validatePageParams(page, size);
+
+        try {
+            // 构建分页对象
+            IPage<LawyerUserViolationVo> pageRequest = new Page<>(page, size);
+
+            // 构建查询条件
+            QueryWrapper<LawyerUserViolationVo> queryWrapper = buildQueryWrapper(orderId,
+                    processingStatus, reportedUserName, violationReason);
+
+            // 执行分页查询
+            IPage<LawyerUserViolationVo> resultPage = lawyerUserViolationMapper.getViolationPage(pageRequest,
+                    queryWrapper);
+
+            // 转换为DTO并处理数据
+            return convertToDtoPage(resultPage);
+
+        } catch (Exception e) {
+            log.error("分页查询违规举报信息异常,页码:{},每页大小:{},异常信息:{}", page, size, e.getMessage(), e);
+            throw new RuntimeException("分页查询违规举报信息失败:" + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 校验分页参数
+     *
+     * @param page 当前页码
+     * @param size 每页大小
+     * @throws RuntimeException 当参数无效时抛出
+     */
+    private void validatePageParams(int page, int size) {
+        if (page < 1) {
+            log.warn("分页查询参数无效,页码:{}", page);
+            throw new RuntimeException("页码必须大于0");
+        }
+        if (size < 1) {
+            log.warn("分页查询参数无效,每页大小:{}", size);
+            throw new RuntimeException("每页大小必须大于0");
+        }
+        if (size > MAX_PAGE_SIZE) {
+            log.warn("分页查询参数无效,每页大小超过最大值:{}", size);
+            throw new RuntimeException("每页大小不能超过" + MAX_PAGE_SIZE);
+        }
+    }
+
+    /**
+     * 构建查询条件
+     *
+     * @param orderId          订单号
+     * @param processingStatus 处理状态
+     * @param reportedUserName 被举报人名称
+     * @param violationReason  违规原因
+     * @return 查询条件包装器
+     */
+    private QueryWrapper<LawyerUserViolationVo> buildQueryWrapper(String orderId, String processingStatus,
+                                                                   String reportedUserName, String violationReason) {
         QueryWrapper<LawyerUserViolationVo> queryWrapper = new QueryWrapper<>();
 
-        // 基础查询条件
-        queryWrapper.eq("luv.delete_flag", 0)
-                .eq("luv.report_context_type", 6);
+        // 基础查询条件:未删除且为订单举报
+        queryWrapper.eq("luv.delete_flag", DELETE_FLAG_NOT_DELETED)
+                .eq("luv.report_context_type", REPORT_CONTEXT_TYPE_ORDER);
 
-        // 动态查询条件
-        queryWrapper.like(StringUtils.isNotEmpty(orderId), "luv.order_id", orderId);
+        // 动态查询条件:订单号模糊查询
+        if (StringUtils.isNotEmpty(orderId)) {
+            queryWrapper.like("luv.order_id", orderId);
+        }
+
+        // 动态查询条件:处理状态精确匹配
         if (StringUtils.isNotEmpty(processingStatus)) {
             queryWrapper.eq("luv.processing_status", processingStatus);
         }
-        // 被举报人名称模糊查询
+
+        // 动态查询条件:被举报人名称模糊查询
         if (StringUtils.isNotEmpty(reportedUserName)) {
             queryWrapper.like("ui_reported.nick_name", reportedUserName);
         }
 
-        // 被举报人名称模糊查询
+        // 动态查询条件:违规原因精确匹配
         if (StringUtils.isNotEmpty(violationReason)) {
             queryWrapper.eq("luv.violation_reason", violationReason);
         }
 
+        // 排序:按更新时间倒序
         queryWrapper.orderByDesc("luv.updated_time");
 
-        IPage<LawyerUserViolationVo> resultPage = lawyerUserViolationMapper.getViolationPage(pageRequest, queryWrapper);
+        return queryWrapper;
+    }
 
-        return resultPage.convert(e -> {
-            LawyerUserViolationDto dto = new LawyerUserViolationDto();
-            BeanUtils.copyProperties(e, dto);
+    /**
+     * 将VO分页结果转换为DTO分页结果
+     *
+     * @param voPage VO分页结果
+     * @return DTO分页结果
+     */
+    private IPage<LawyerUserViolationDto> convertToDtoPage(IPage<LawyerUserViolationVo> voPage) {
+        return voPage.convert(this::convertToDto);
+    }
 
-            // 处理举报凭证图片
-            if (Objects.nonNull(e.getReportEvidenceImg())) {
-                List<String> imageList = Arrays.stream(e.getReportEvidenceImg().split(","))
-                        .map(String::trim)
-                        .filter(StringUtils::isNotEmpty)
-                        .collect(Collectors.toList());
+    /**
+     * 将VO对象转换为DTO对象
+     *
+     * @param vo VO对象
+     * @return DTO对象
+     */
+    private LawyerUserViolationDto convertToDto(LawyerUserViolationVo vo) {
+        LawyerUserViolationDto dto = new LawyerUserViolationDto();
+        BeanUtils.copyProperties(vo, dto);
 
-                if (!imageList.isEmpty()) {
-                    dto.setImage(imageList.get(0));
-                    dto.setImageList(imageList);
-                }
-            }
+        // 处理举报凭证图片
+        processReportEvidenceImages(vo, dto);
 
-            // 设置举报人和被举报人名称
-            dto.setNickname(e.getNickName());
-            dto.setReportUserName(e.getReportUserName());
-            dto.setReportedUserName(e.getReportedUserName());
-            return dto;
-        });
+        // 设置用户名称信息
+        setUserNames(vo, dto);
+
+        return dto;
+    }
+
+    /**
+     * 处理举报凭证图片
+     *
+     * @param vo  VO对象
+     * @param dto DTO对象
+     */
+    private void processReportEvidenceImages(LawyerUserViolationVo vo, LawyerUserViolationDto dto) {
+        if (Objects.isNull(vo.getReportEvidenceImg())) {
+            return;
+        }
+
+        List<String> imageList = Arrays.stream(vo.getReportEvidenceImg().split(IMAGE_SEPARATOR))
+                .map(String::trim)
+                .filter(StringUtils::isNotEmpty)
+                .collect(Collectors.toList());
+
+        if (!imageList.isEmpty()) {
+            dto.setImage(imageList.get(0));
+            dto.setImageList(imageList);
+        }
+    }
+
+    /**
+     * 设置用户名称信息
+     *
+     * @param vo  VO对象
+     * @param dto DTO对象
+     */
+    private void setUserNames(LawyerUserViolationVo vo, LawyerUserViolationDto dto) {
+        dto.setNickname(vo.getNickName());
+        dto.setReportUserName(vo.getReportUserName());
+        dto.setReportedUserName(vo.getReportedUserName());
     }
 
     /**