feat: 接受评论

master
yang 2025-01-22 17:34:20 +08:00
parent 09dfd88a12
commit 70aa6a6b27
7 changed files with 72 additions and 17 deletions

View File

@ -70,11 +70,10 @@ public class Question extends BaseEntity {
*/
private Integer isAnonymous;
// /**
// * 状态
// */
// @ApiModelProperty(value = "状态")
// private Integer status;
/**
* 0 1
*/
private Integer status;
/**
* 0 1

View File

@ -41,9 +41,9 @@ public class QuestionComment extends BaseEntity {
*/
private String content;
/**
*
* 0 1
*/
private Long isAccept;
private Integer isAccept;

View File

@ -15,15 +15,22 @@ import javax.validation.constraints.NotNull;
public interface QuestionCommentMapper extends BaseMapper<QuestionComment> {
@InterceptorIgnore(tenantLine = "true")
Page<QuestionComment> selectByTenantIdAndCommunityIdAndQuestionIdPage(Page<QuestionComment> page,
@Param("tenantId")
Long tenantId,
@Param("communityId")
Long communityId,
@Param("questionId")
Long questionId);
Page<QuestionComment> selectByTenantIdAndCommunityIdAndQuestionIdPage(Page<QuestionComment> page,
@Param("tenantId")
Long tenantId,
@Param("communityId")
Long communityId,
@Param("questionId")
Long questionId);
@InterceptorIgnore(tenantLine = "true")
QuestionComment selectByIdAndTenantIdAndCommunityIdAndQuestionIdAndCommentId(Long commentId, Long tenantId, Long communityId, Long questionId);
QuestionComment selectByIdAndTenantIdAndCommunityIdAndQuestionIdAndCommentId(@Param("tenantId")
Long tenantId,
@Param("communityId")
Long communityId,
@Param("questionId")
Long questionId,
@Param("commentId")
Long commentId);
}

View File

@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -34,6 +35,8 @@ public class QuestionCommentServiceImpl extends ServiceImpl<QuestionCommentMappe
private final QuestionMapper questionMapper;
private final ISysUserService sysUserService;
@Override
public AjaxResult comment(QuestionCommentRes questionCommentRes) {
@ -58,7 +61,6 @@ public class QuestionCommentServiceImpl extends ServiceImpl<QuestionCommentMappe
}
@Override
public TableDataInfo listByPage(QuestionCommentPageRes questionCommentPageRes) {
@ -85,6 +87,7 @@ public class QuestionCommentServiceImpl extends ServiceImpl<QuestionCommentMappe
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult adopt(QuestionCommentAdoptRes questionCommentAdoptRes) {
Long tenantId = questionCommentAdoptRes.getTenantId();
@ -92,7 +95,16 @@ public class QuestionCommentServiceImpl extends ServiceImpl<QuestionCommentMappe
Long questionId = questionCommentAdoptRes.getQuestionId();
Long commentId = questionCommentAdoptRes.getCommentId();
QuestionComment questionComment = baseMapper.selectByIdAndTenantIdAndCommunityIdAndQuestionIdAndCommentId(commentId, tenantId, communityId, questionId);
Question question = questionMapper.selectByIdAndTenantIdAndCommunityId(questionId, tenantId, communityId);
if (Objects.isNull(question)) {
return AjaxResult.error("提问不存在");
}
if (question.getStatus() == 1) {
return AjaxResult.error("该提问已解决");
}
QuestionComment questionComment = baseMapper.selectByIdAndTenantIdAndCommunityIdAndQuestionIdAndCommentId(tenantId, communityId, questionId, commentId);
if (Objects.isNull(questionComment)) {
return AjaxResult.error("评论不存在");
}
@ -101,7 +113,21 @@ public class QuestionCommentServiceImpl extends ServiceImpl<QuestionCommentMappe
return AjaxResult.error("该评论已被采纳");
}
questionComment.setIsAccept(1);
baseMapper.updateById(questionComment);
question.setStatus(1);
questionMapper.updateById(question);
SysUser sysUser = sysUserService.selectUserById(tenantId);
BigDecimal sysWallet = new BigDecimal(sysUser.getWallet().toString());
BigDecimal amount = new BigDecimal(question.getAmount().toString());
// 添加钱包
BigDecimal wallet = sysWallet.add(amount);
sysUser.setWallet(wallet.doubleValue());
sysUserService.updateUser(sysUser);
return AjaxResult.success();

View File

@ -32,6 +32,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -86,6 +87,17 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
// question.setStatus(StatusConstant.STATUS_UNREPLIED);
baseMapper.insert(question);
SysUser sysUser = sysUserService.selectUserById(userId);
BigDecimal sysWallet = new BigDecimal(sysUser.getWallet().toString());
BigDecimal amount = new BigDecimal(questionRes.getAmount().toString());
// 扣除钱包
BigDecimal subtract = sysWallet.subtract(amount);
sysUser.setWallet(subtract.doubleValue());
sysUserService.updateUser(sysUser);
// CommunityAdvice communityAdvice = new CommunityAdvice();
// communityAdvice.setTenantId(tenantId);

View File

@ -15,4 +15,14 @@
and del_flag = '0'
order by create_time desc
</select>
<select id="selectByIdAndTenantIdAndCommunityIdAndQuestionIdAndCommentId"
resultType="com.mcwl.communityCenter.domain.QuestionComment">
select id, tenant_id, community_id, question_id, user_id, content, is_accept
from cc_question_comment
where id = #{commentId}
and tenant_id = #{tenantId}
and community_id = #{communityId}
and question_id = #{questionId}
and del_flag = '0'
</select>
</mapper>

View File

@ -210,6 +210,7 @@
<if test="sex != null and sex != ''">sex = #{sex},</if>
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
<if test="password != null and password != ''">password = #{password},</if>
<if test="wallet != null">wallet = #{wallet},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if>