|
|
@@ -0,0 +1,147 @@
|
|
|
+package shop.alien.lawyer.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import shop.alien.entity.result.R;
|
|
|
+import shop.alien.entity.store.CommentAppeal;
|
|
|
+import shop.alien.mapper.CommentAppealMapper;
|
|
|
+import shop.alien.lawyer.service.CommentAppealService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 评论申诉表 服务实现类
|
|
|
+ *
|
|
|
+ * @author system
|
|
|
+ * @since 2025-01-XX
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Transactional
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class CommentAppealServiceImpl extends ServiceImpl<CommentAppealMapper, CommentAppeal> implements CommentAppealService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<CommentAppeal> submitAppeal(CommentAppeal commentAppeal) {
|
|
|
+ log.info("CommentAppealServiceImpl.submitAppeal?commentAppeal={}", commentAppeal);
|
|
|
+
|
|
|
+ // 校验必填字段
|
|
|
+ if (commentAppeal.getCommentId() == null) {
|
|
|
+ return R.fail("评论ID不能为空");
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(commentAppeal.getAppealReason())) {
|
|
|
+ return R.fail("申诉理由不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查该评论是否已有待处理或已通过的申诉
|
|
|
+ LambdaQueryWrapper<CommentAppeal> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CommentAppeal::getCommentId, commentAppeal.getCommentId());
|
|
|
+ wrapper.eq(CommentAppeal::getDeleteFlag, 0);
|
|
|
+ wrapper.in(CommentAppeal::getStatus, 0, 1); // 待处理或已通过
|
|
|
+ CommentAppeal existingAppeal = this.getOne(wrapper);
|
|
|
+ if (existingAppeal != null) {
|
|
|
+ return R.fail("该评论已有申诉记录,无法重复申诉");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ commentAppeal.setStatus(0); // 待处理
|
|
|
+ if (commentAppeal.getDeleteFlag() == null) {
|
|
|
+ commentAppeal.setDeleteFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存申诉
|
|
|
+ boolean result = this.save(commentAppeal);
|
|
|
+ if (result) {
|
|
|
+ log.info("提交申诉成功,id={}", commentAppeal.getId());
|
|
|
+ return R.data(commentAppeal, "申诉提交成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("申诉提交失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Boolean> auditAppeal(Integer id, Integer status, Integer userId) {
|
|
|
+ log.info("CommentAppealServiceImpl.auditAppeal?id={}, status={}, userId={}", id, status, userId);
|
|
|
+
|
|
|
+ // 校验参数
|
|
|
+ if (id == null) {
|
|
|
+ return R.fail("申诉ID不能为空");
|
|
|
+ }
|
|
|
+ if (status == null || (status != 1 && status != 2)) {
|
|
|
+ return R.fail("审核状态不正确,必须是1(已通过)或2(已驳回)");
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("审核人ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询申诉记录
|
|
|
+ CommentAppeal appeal = this.getById(id);
|
|
|
+ if (appeal == null || appeal.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("申诉记录不存在或已被删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查状态
|
|
|
+ if (appeal.getStatus() != 0) {
|
|
|
+ return R.fail("该申诉已处理,无法重复审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新状态
|
|
|
+ CommentAppeal updateAppeal = new CommentAppeal();
|
|
|
+ updateAppeal.setId(id);
|
|
|
+ updateAppeal.setStatus(status);
|
|
|
+ updateAppeal.setUpdatedUserId(userId);
|
|
|
+
|
|
|
+ boolean result = this.updateById(updateAppeal);
|
|
|
+ if (result) {
|
|
|
+ String statusText = status == 1 ? "已通过" : "已驳回";
|
|
|
+ log.info("审核申诉成功,id={}, status={}", id, statusText);
|
|
|
+ return R.success("审核成功,申诉" + statusText);
|
|
|
+ } else {
|
|
|
+ return R.fail("审核失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<IPage<CommentAppeal>> getAppealPage(Integer pageNum, Integer pageSize, Integer status, Integer commentId) {
|
|
|
+ log.info("CommentAppealServiceImpl.getAppealPage?pageNum={}, pageSize={}, status={}, commentId={}",
|
|
|
+ pageNum, pageSize, status, commentId);
|
|
|
+
|
|
|
+ Page<CommentAppeal> page = new Page<>(pageNum, pageSize);
|
|
|
+ LambdaQueryWrapper<CommentAppeal> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CommentAppeal::getDeleteFlag, 0);
|
|
|
+
|
|
|
+ if (status != null) {
|
|
|
+ wrapper.eq(CommentAppeal::getStatus, status);
|
|
|
+ }
|
|
|
+ if (commentId != null) {
|
|
|
+ wrapper.eq(CommentAppeal::getCommentId, commentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.orderByDesc(CommentAppeal::getCreatedTime);
|
|
|
+
|
|
|
+ IPage<CommentAppeal> pageResult = this.page(page, wrapper);
|
|
|
+ return R.data(pageResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<CommentAppeal> getAppealDetail(Integer id) {
|
|
|
+ log.info("CommentAppealServiceImpl.getAppealDetail?id={}", id);
|
|
|
+
|
|
|
+ if (id == null) {
|
|
|
+ return R.fail("申诉ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ CommentAppeal appeal = this.getById(id);
|
|
|
+ if (appeal == null || appeal.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("申诉记录不存在或已被删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(appeal, "查询成功");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|