新增了用户投票
This commit is contained in:
parent
be5a9a2085
commit
5e50b35ef4
@ -665,18 +665,18 @@ public class CaseExchangeController {
|
||||
public Response<T> AddCaseExchangeVote(
|
||||
@Validated()
|
||||
@PathVariable("exchange_id") String exchangeId,
|
||||
@ModelAttribute addCaseExchangeVote r
|
||||
@RequestBody addCaseExchangeVote r
|
||||
) {
|
||||
|
||||
String userId = (String) httpServletRequest.getAttribute("userId");
|
||||
|
||||
if (userId == null) {
|
||||
return Response.error("操作失败");
|
||||
return Response.error("操作失败1");
|
||||
}
|
||||
|
||||
boolean res = caseExchangeService.AddCaseExchangeVote(exchangeId,userId,r.getOptionId());
|
||||
if (!res){
|
||||
return Response.error("操作失败");
|
||||
return Response.error("操作失败2");
|
||||
}
|
||||
|
||||
return Response.success();
|
||||
|
||||
@ -4,7 +4,31 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.caseData.model.CaseExchangeVoteModel;
|
||||
import com.example.caseData.model.CaseExchangeVoteOptionModel;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
@Mapper
|
||||
public interface CaseExchangeVoteOptionDao extends BaseMapper<CaseExchangeVoteOptionModel> {
|
||||
/**
|
||||
* Inc 自增
|
||||
* @param optionId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 增加的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE case_exchange_vote_option SET ${field} = ${field} + #{numeral} WHERE option_id = #{optionId}")
|
||||
int inc(@Param("optionId") Long optionId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
|
||||
/**
|
||||
* Dec 自减
|
||||
*
|
||||
* @param optionId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 减少的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE case_exchange_vote_option " +
|
||||
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
||||
"WHERE option_id = #{optionId}")
|
||||
int dec(@Param("optionId") Long optionId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
}
|
||||
|
||||
@ -26,18 +26,18 @@ public interface StatsCaseClinicalDoctorDao extends BaseMapper<StatsCaseClinical
|
||||
|
||||
/**
|
||||
* Inc 自增
|
||||
* @param articleId 文章 ID
|
||||
* @param doctorId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 增加的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE stats_case_clinical_doctor SET ${field} = ${field} + #{numeral} WHERE doctor_id = #{doctorId}")
|
||||
int inc(@Param("doctorId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
int inc(@Param("doctorId") Long doctorId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
|
||||
/**
|
||||
* Dec 自减
|
||||
*
|
||||
* @param articleId 文章 ID
|
||||
* @param doctorId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 减少的数值
|
||||
* @return 更新的行数
|
||||
@ -45,5 +45,5 @@ public interface StatsCaseClinicalDoctorDao extends BaseMapper<StatsCaseClinical
|
||||
@Update("UPDATE stats_case_clinical_doctor " +
|
||||
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
||||
"WHERE doctor_id = #{doctorId}")
|
||||
int dec(@Param("doctorId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
int dec(@Param("doctorId") Long doctorId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
}
|
||||
@ -36,6 +36,12 @@ public class UserVoteExchangeModel {
|
||||
@TableField("vote_id")
|
||||
private Long voteId;
|
||||
|
||||
/**
|
||||
* 选项id
|
||||
*/
|
||||
@TableField("option_id")
|
||||
private Long optionId;
|
||||
|
||||
/**
|
||||
* 投票时间
|
||||
*/
|
||||
|
||||
@ -6,7 +6,6 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class addCaseExchangeVote {
|
||||
// 父级 次级评论此字段必须存在
|
||||
@JsonProperty("option_id")
|
||||
private String optionId;
|
||||
}
|
||||
|
||||
@ -532,29 +532,28 @@ public class CaseExchangeService {
|
||||
|
||||
// 获取对应投票选项
|
||||
LambdaQueryWrapper<CaseExchangeVoteOptionModel> caseExchangeVoteOptionQueryWrapper = new LambdaQueryWrapper<>();
|
||||
caseExchangeVoteOptionQueryWrapper.eq(CaseExchangeVoteOptionModel::getOptionId, optionId);
|
||||
caseExchangeVoteOptionQueryWrapper.eq(CaseExchangeVoteOptionModel::getVoteId, caseExchangeVote.getVoteId());
|
||||
List<CaseExchangeVoteOptionModel> caseExchangeVoteOptions = caseExchangeVoteOptionDao.selectList(caseExchangeVoteOptionQueryWrapper);
|
||||
if (caseExchangeVoteOptions == null || caseExchangeVoteOptions.isEmpty()) {
|
||||
return true;
|
||||
CaseExchangeVoteOptionModel caseExchangeVoteOption = caseExchangeVoteOptionDao.selectOne(caseExchangeVoteOptionQueryWrapper);
|
||||
if (caseExchangeVoteOption == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// // 新增投票
|
||||
// UserVoteExchangeModel userVoteExchangedata = new UserVoteExchangeModel();
|
||||
// userVoteExchangedata.setUserId(Long.valueOf(userId));
|
||||
// userVoteExchangedata.setExchangeId(Long.valueOf(exchangeId));
|
||||
// int res = userCollectExchangeDao.insert(userCollectExchangeData);
|
||||
// if (res <= 0){
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // 增加病例交流收藏数
|
||||
// caseExchangeDao.inc(Long.valueOf(exchangeId),"collect_num",1);
|
||||
//
|
||||
// // 增加病例交流总收藏数
|
||||
// statsCaseExchangeDao.inc(1L,"exchange_collect_num",1);
|
||||
//
|
||||
// // 增加用户交流收藏数
|
||||
// statsCaseExchangeUserDao.inc(Long.valueOf(userId),"exchange_collect_num",1);
|
||||
// 新增投票
|
||||
UserVoteExchangeModel userVoteExchangedata = new UserVoteExchangeModel();
|
||||
userVoteExchangedata.setUserId(Long.valueOf(userId));
|
||||
userVoteExchangedata.setExchangeId(Long.valueOf(exchangeId));
|
||||
userVoteExchangedata.setVoteId(caseExchangeVote.getVoteId());
|
||||
userVoteExchangedata.setOptionId(Long.valueOf(optionId));
|
||||
userVoteExchangedata.setVoteTime(LocalDateTime.now());
|
||||
int res = userVoteExchangeDao.insert(userVoteExchangedata);
|
||||
if (res <= 0){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 处理投票数
|
||||
caseExchangeVoteOptionDao.inc(Long.valueOf(optionId),"vote_num",1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user