新增了阅读记录
This commit is contained in:
parent
12ddc57bca
commit
916a9868c5
@ -214,10 +214,10 @@ public class UserCaseReadController extends BaseController {
|
||||
}
|
||||
|
||||
try {
|
||||
// boolean res = userCaseReadService.AddUserCaseRead(request,userId);
|
||||
// if (!res){
|
||||
// return Response.error("操作失败");
|
||||
// }
|
||||
boolean res = userCaseReadService.AddUserCaseRead(request,userId);
|
||||
if (!res){
|
||||
return Response.error("操作失败");
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
return Response.error(e.getMessage());
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.example.caseData.dto.userCaseRead.UserCaseReadDto;
|
||||
import com.example.caseData.dto.userCollectClinicalArticle.UserCollectClinicalArticleDto;
|
||||
import com.example.caseData.model.UserCaseReadModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
public interface UserCaseReadDao extends BaseMapper<UserCaseReadModel> {
|
||||
/**
|
||||
@ -41,4 +42,25 @@ public interface UserCaseReadDao extends BaseMapper<UserCaseReadModel> {
|
||||
@Param("keyword") String keyword,
|
||||
@Param("userId") String userId
|
||||
);
|
||||
|
||||
/**
|
||||
* Inc 自增
|
||||
* @param field 字段名称
|
||||
* @param numeral 增加的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE user_case_read SET ${field} = ${field} + #{numeral} WHERE read_id = #{readId}")
|
||||
int inc(@Param("readId") Long readId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
|
||||
/**
|
||||
* Dec 自减
|
||||
*
|
||||
* @param field 字段名称
|
||||
* @param numeral 减少的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE user_case_read " +
|
||||
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
||||
"WHERE read_id = #{statsId}")
|
||||
int dec(@Param("readId") Long readId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
}
|
||||
|
||||
@ -13,10 +13,4 @@ public class LoginRequest {
|
||||
|
||||
@NotEmpty(message = "错误请求2", groups = {Login.class})
|
||||
private String wx_code;
|
||||
|
||||
/**
|
||||
* 来源(1:小程序 2:h5)
|
||||
*/
|
||||
@NotNull(message = "错误请求", groups = {Login.class})
|
||||
private Integer source;
|
||||
}
|
||||
@ -1,48 +1,77 @@
|
||||
package com.example.caseData.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.example.caseData.dao.*;
|
||||
import com.example.caseData.exception.BusinessException;
|
||||
import com.example.caseData.model.CaseClinicalArticleAuthorModel;
|
||||
import com.example.caseData.model.CaseClinicalArticleModel;
|
||||
import com.example.caseData.model.UserCaseReadModel;
|
||||
import com.example.caseData.model.UserCommentClinicalArticleModel;
|
||||
import com.example.caseData.request.CaseClinicalArticleRequest.addClinicalArticleComment;
|
||||
import com.example.caseData.request.userCaseReadRequest.addUserCaseRead;
|
||||
import com.example.caseData.utils.Replace;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserCaseReadService {
|
||||
// /**
|
||||
// * 浏览记录-新增
|
||||
// * @return bool
|
||||
// */
|
||||
// @Transactional
|
||||
// public boolean AddUserCaseRead(addUserCaseRead request, String userId){
|
||||
// // 检测是否已存在
|
||||
//
|
||||
//
|
||||
// // 新增评论
|
||||
// UserCommentClinicalArticleModel userCommentClinicalArticleData = new UserCommentClinicalArticleModel();
|
||||
// userCommentClinicalArticleData.setUserId(Long.valueOf(userId));
|
||||
// userCommentClinicalArticleData.setArticleId(Long.valueOf(articleId));
|
||||
// userCommentClinicalArticleData.setStatus(1);
|
||||
// userCommentClinicalArticleData.setIsSensitive(0);
|
||||
// userCommentClinicalArticleData.setContent(request.getContent());
|
||||
// userCommentClinicalArticleData.setCommentImage(Replace.removeOssDomain(request.getCommentImage()));
|
||||
//
|
||||
// // 评论根id
|
||||
// if (request.getRootId() != null) {
|
||||
// userCommentClinicalArticleData.setRootId(Long.valueOf(request.getRootId()));
|
||||
// }
|
||||
//
|
||||
// // 评论父级id
|
||||
// if (request.getParentId() != null) {
|
||||
// userCommentClinicalArticleData.setParentId(Long.valueOf(request.getParentId()));
|
||||
// }
|
||||
//
|
||||
// int res = userCommentClinicalArticleDao.insert(userCommentClinicalArticleData);
|
||||
// return res > 0;
|
||||
// }
|
||||
@Resource
|
||||
private UserCaseReadDao userCaseReadDao;
|
||||
|
||||
@Resource
|
||||
private CaseClinicalArticleDao caseClinicalArticleDao;
|
||||
|
||||
@Resource
|
||||
private CaseClinicalVideoDao caseClinicalVideoDao;
|
||||
|
||||
@Resource
|
||||
private CaseExchangeDao caseExchangeDao;
|
||||
|
||||
/**
|
||||
* 浏览记录-新增
|
||||
* @return bool
|
||||
*/
|
||||
@Transactional
|
||||
public boolean AddUserCaseRead(addUserCaseRead request, String userId){
|
||||
// 检测是否已存在
|
||||
LambdaQueryWrapper<UserCaseReadModel> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserCaseReadModel::getUserId, userId);
|
||||
queryWrapper.eq(UserCaseReadModel::getId, request.getId());
|
||||
queryWrapper.eq(UserCaseReadModel::getType, request.getType());
|
||||
UserCaseReadModel userCaseRead = userCaseReadDao.selectOne(queryWrapper);
|
||||
if (userCaseRead == null){
|
||||
UserCaseReadModel data = new UserCaseReadModel();
|
||||
data.setUserId(Long.valueOf(userId));
|
||||
data.setId(Long.valueOf( request.getId()));
|
||||
data.setType(request.getType());
|
||||
data.setReadNum(1);
|
||||
int res = userCaseReadDao.insert(data);
|
||||
return res > 0;
|
||||
}else{
|
||||
userCaseReadDao.inc(userCaseRead.getReadId(),"read_num",1);
|
||||
}
|
||||
|
||||
// 文章
|
||||
if (request.getType() == 1){
|
||||
caseClinicalArticleDao.inc(Long.valueOf(request.getId()),"read_num",1);
|
||||
}
|
||||
|
||||
// 视频
|
||||
if (request.getType() == 2){
|
||||
caseClinicalVideoDao.inc(Long.valueOf(request.getId()),"read_num",1);
|
||||
}
|
||||
|
||||
// 病例交流
|
||||
if (request.getType() == 3){
|
||||
caseExchangeDao.inc(Long.valueOf(request.getId()),"read_num",1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user