feat: redis点赞数据同步数据库
This commit is contained in:
@@ -4,10 +4,13 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.subject.application.convert.SubjectLikedDTOConverter;
|
||||
import com.landaiqing.subject.application.dto.SubjectLikedDTO;
|
||||
import com.landaiqing.subject.common.entity.PageResult;
|
||||
import com.landaiqing.subject.common.entity.Result;
|
||||
import com.landaiqing.subject.common.util.LoginUtil;
|
||||
import com.landaiqing.subject.domain.entity.SubjectLikedBO;
|
||||
import com.landaiqing.subject.domain.service.SubjectLikedDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -38,17 +41,15 @@ public class SubjectLikedController {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectLikedController.add.dto:{}", JSON.toJSONString(subjectLikedDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getId(), "不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getSubjectId(), "不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getLikeUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getStatus(), "不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getCreatedBy(), "创建人不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getCreatedTime(), "创建时间不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getUpdateBy(), "更新人不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getIsDeleted(), "不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getSubjectId(), "题目id不能为空");
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getStatus(), "点赞状态 1点赞 0不点赞 不能为空");
|
||||
String loginId = LoginUtil.getLoginId();
|
||||
subjectLikedDTO.setLikeUserId(loginId);
|
||||
Preconditions.checkNotNull(subjectLikedDTO.getLikeUserId(), "点赞人不能为空");
|
||||
|
||||
SubjectLikedBO SubjectLikedBO = SubjectLikedDTOConverter.INSTANCE.convertDTOToBO(subjectLikedDTO);
|
||||
return Result.ok(subjectLikedDomainService.add(SubjectLikedBO));
|
||||
subjectLikedDomainService.add(SubjectLikedBO);
|
||||
return Result.ok(true);
|
||||
} catch (Exception e) {
|
||||
log.error("SubjectLikedController.register.error:{}", e.getMessage(), e);
|
||||
return Result.fail("新增题目点赞表失败");
|
||||
@@ -112,4 +113,24 @@ public class SubjectLikedController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询我的点赞列表
|
||||
*/
|
||||
@PostMapping("/getSubjectLikedPage")
|
||||
public Result<PageResult<SubjectLikedDTO>> getSubjectLikedPage(@RequestBody SubjectLikedDTO subjectLikedDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectController.getSubjectLikedPage.dto:{}", JSON.toJSONString(subjectLikedDTO));
|
||||
}
|
||||
SubjectLikedBO subjectLikedBO = SubjectLikedDTOConverter.INSTANCE.convertDTOToBO(subjectLikedDTO);
|
||||
subjectLikedBO.setPageNo(subjectLikedDTO.getPageNo());
|
||||
subjectLikedBO.setPageSize(subjectLikedDTO.getPageSize());
|
||||
PageResult<SubjectLikedBO> boPageResult = subjectLikedDomainService.getSubjectLikedPage(subjectLikedBO);
|
||||
return Result.ok(boPageResult);
|
||||
} catch (Exception e) {
|
||||
log.error("SubjectCategoryController.getSubjectLikedPage.error:{}", e.getMessage(), e);
|
||||
return Result.fail("分页查询我的点赞失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,9 +2,12 @@ package com.landaiqing.subject.application.convert;
|
||||
|
||||
import com.landaiqing.subject.application.dto.SubjectLikedDTO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectLikedBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectLiked;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题目点赞表 dto转换器
|
||||
*
|
||||
@@ -17,5 +20,6 @@ public interface SubjectLikedDTOConverter {
|
||||
SubjectLikedDTOConverter INSTANCE = Mappers.getMapper(SubjectLikedDTOConverter.class);
|
||||
|
||||
SubjectLikedBO convertDTOToBO(SubjectLikedDTO subjectLikedDTO);
|
||||
List<SubjectLikedBO> convertListInfoToBO(List<SubjectLiked> subjectLikedList);
|
||||
|
||||
}
|
||||
|
@@ -85,6 +85,23 @@ public class SubjectInfoDTO extends PageInfo implements Serializable {
|
||||
* 题目数量
|
||||
*/
|
||||
private Integer subjectCount;
|
||||
/**
|
||||
* 是否被当前用户点赞
|
||||
*/
|
||||
private Boolean liked;
|
||||
|
||||
/**
|
||||
* 当前题目点赞的数量
|
||||
*/
|
||||
private Integer likedCount;
|
||||
/**
|
||||
* 下一题
|
||||
*/
|
||||
private Long nextSubjectId;
|
||||
/**
|
||||
* 上一题
|
||||
*/
|
||||
private Long lastSubjectId;
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.landaiqing.subject.application.dto;
|
||||
|
||||
import com.landaiqing.subject.common.entity.PageInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -12,7 +13,7 @@ import java.util.Date;
|
||||
* @since 2024-03-08 13:44:59
|
||||
*/
|
||||
@Data
|
||||
public class SubjectLikedDTO implements Serializable {
|
||||
public class SubjectLikedDTO extends PageInfo implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
|
Reference in New Issue
Block a user