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