feat: 提问

master
yang 2025-01-19 17:12:48 +08:00
parent 84f3caf7af
commit d5acfb00ae
11 changed files with 122 additions and 33 deletions

View File

@ -3,6 +3,7 @@ package com.mcwl.web.controller.communityCenter;
import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.page.TableDataInfo; import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.communityCenter.domain.dto.QuestionDetailRes;
import com.mcwl.communityCenter.domain.dto.QuestionPageRes; import com.mcwl.communityCenter.domain.dto.QuestionPageRes;
import com.mcwl.communityCenter.domain.dto.QuestionReplyRes; import com.mcwl.communityCenter.domain.dto.QuestionReplyRes;
import com.mcwl.communityCenter.domain.dto.QuestionRes; import com.mcwl.communityCenter.domain.dto.QuestionRes;
@ -43,22 +44,22 @@ public class QuestionController {
/** /**
* *
*/ */
@PostMapping("listUnReplied") @PostMapping("list")
@ApiOperation(value = "获取未回复问题列表") @ApiOperation(value = "获取问题列表")
public TableDataInfo listUnReplied(@RequestBody @Valid QuestionPageRes questionPageRes) { public TableDataInfo list(@RequestBody @Valid QuestionPageRes questionPageRes) {
return questionService.listUnReplied(questionPageRes); return questionService.list(questionPageRes);
} }
/** /**
* *
*/ */
@GetMapping("detail") @PostMapping("detail")
@ApiOperation(value = "获取问题详情") @ApiOperation(value = "获取问题详情")
public AjaxResult getQuestionDetail(@NotNull(message = "id不能为空") @Valid Long id) { public AjaxResult getQuestionDetail(@RequestBody @Valid QuestionDetailRes questionDetailRes) {
QuestionVo questionVo = questionService.getDetail(id); QuestionVo questionVo = questionService.getDetail(questionDetailRes);
if (Objects.isNull(questionVo)) { if (Objects.isNull(questionVo)) {
return AjaxResult.error("获取详情失败"); return AjaxResult.error("获取详情失败");
} }
@ -72,9 +73,7 @@ public class QuestionController {
@ApiOperation(value = "回复") @ApiOperation(value = "回复")
public AjaxResult reply(@RequestBody @Valid QuestionReplyRes questionReplyRes) { public AjaxResult reply(@RequestBody @Valid QuestionReplyRes questionReplyRes) {
questionService.reply(questionReplyRes); return questionService.reply(questionReplyRes);
return AjaxResult.success();
} }

View File

@ -0,0 +1,27 @@
package com.mcwl.communityCenter.domain.dto;
import com.mcwl.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
@Data
@ApiModel(value = "查看详情请求参数")
public class QuestionDetailRes {
@NotNull(message = "问题id不能为空")
@ApiModelProperty(value = "问题id", required = true)
private Long questionId;
@NotNull(message = "租户不能为空")
@ApiModelProperty(value = "租户id", required = true)
private Long tenantId;
@NotNull(message = "社区不能为空")
@ApiModelProperty(value = "社区id", required = true)
private Long communityId;
}

View File

@ -3,6 +3,7 @@ package com.mcwl.communityCenter.domain.dto;
import com.mcwl.common.core.page.PageDomain; import com.mcwl.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.util.AllowableValues;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -13,8 +14,15 @@ import javax.validation.constraints.NotNull;
@ApiModel(value = "提问分页请求参数") @ApiModel(value = "提问分页请求参数")
public class QuestionPageRes extends PageDomain { public class QuestionPageRes extends PageDomain {
@NotNull(message = "租户不能为空")
@ApiModelProperty(value = "租户id", required = true)
private Long tenantId;
@NotNull(message = "社区不能为空") @NotNull(message = "社区不能为空")
@ApiModelProperty(value = "社区id", required = true) @ApiModelProperty(value = "社区id", required = true)
private Long communityId; private Long communityId;
@ApiModelProperty(value = "状态")
private Integer status;
} }

View File

@ -11,6 +11,10 @@ import javax.validation.constraints.NotNull;
@ApiModel(value = "回复问题") @ApiModel(value = "回复问题")
public class QuestionReplyRes { public class QuestionReplyRes {
@NotNull(message = "社区不能为空")
@ApiModelProperty(value = "社区id", required = true)
private Long communityId;
/** /**
* id * id
*/ */
@ -23,6 +27,6 @@ public class QuestionReplyRes {
*/ */
@NotBlank(message = "回复内容不能为空") @NotBlank(message = "回复内容不能为空")
@ApiModelProperty(value = "回复内容", required = true) @ApiModelProperty(value = "回复内容", required = true)
private String content; private String reply;
} }

View File

@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull;
@Mapper @Mapper
public interface CommunityMapper extends BaseMapper<Community> { public interface CommunityMapper extends BaseMapper<Community> {
@InterceptorIgnore(tenantLine = "true") @InterceptorIgnore(tenantLine = "true")
Community getByUserIdAndCommunityId(@NotNull(message = "租户id不能为空") Community getByTenantIdAndCommunityId(@NotNull(message = "租户id不能为空")
@Param("tenantId") @Param("tenantId")
Long tenantId, Long tenantId,
@NotNull(message = "社区id不能为空") @NotNull(message = "社区id不能为空")

View File

@ -1,10 +1,33 @@
package com.mcwl.communityCenter.mapper; package com.mcwl.communityCenter.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.communityCenter.domain.Community; import com.mcwl.communityCenter.domain.Community;
import com.mcwl.communityCenter.domain.Question; import com.mcwl.communityCenter.domain.Question;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import javax.validation.constraints.NotNull;
@Mapper @Mapper
public interface QuestionMapper extends BaseMapper<Question> { public interface QuestionMapper extends BaseMapper<Question> {
@InterceptorIgnore(tenantLine = "true")
Page<Question> list(Page<Question> page,
@NotNull(message = "租户不能为空")
@Param("tenantId")
Long tenantId,
@NotNull(message = "社区不能为空")
@Param("communityId")
Long communityId,
@Param("status")
Integer status);
@InterceptorIgnore(tenantLine = "true")
Question selectByIdAndTenantIdAndCommunityId(@Param("id")
Long id,
@Param("tenantId")
Long tenantId,
@Param("communityId")
Long communityId);
} }

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.page.TableDataInfo; import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.communityCenter.domain.Question; import com.mcwl.communityCenter.domain.Question;
import com.mcwl.communityCenter.domain.dto.QuestionDetailRes;
import com.mcwl.communityCenter.domain.dto.QuestionPageRes; import com.mcwl.communityCenter.domain.dto.QuestionPageRes;
import com.mcwl.communityCenter.domain.dto.QuestionReplyRes; import com.mcwl.communityCenter.domain.dto.QuestionReplyRes;
import com.mcwl.communityCenter.domain.dto.QuestionRes; import com.mcwl.communityCenter.domain.dto.QuestionRes;
@ -20,13 +21,13 @@ public interface QuestionService extends IService<Question> {
AjaxResult addQuestion(QuestionRes questionRes); AjaxResult addQuestion(QuestionRes questionRes);
TableDataInfo listUnReplied(QuestionPageRes questionPageRes); TableDataInfo list(QuestionPageRes questionPageRes);
QuestionVo getDetail(@NotNull(message = "id不能为空") Long id); QuestionVo getDetail(QuestionDetailRes questionDetailRes);
/** /**
* *
* @param questionReplyRes * @param questionReplyRes
*/ */
void reply(QuestionReplyRes questionReplyRes); AjaxResult reply(QuestionReplyRes questionReplyRes);
} }

View File

@ -69,7 +69,7 @@ public class PublishServiceImpl extends ServiceImpl<PublishMapper, Publish> impl
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
Community community = communityMapper.getByUserIdAndCommunityId(publishRes.getTenantId(), publishRes.getCommunityId()); Community community = communityMapper.getByTenantIdAndCommunityId(publishRes.getTenantId(), publishRes.getCommunityId());
if (Objects.isNull(community)) { if (Objects.isNull(community)) {
return AjaxResult.error(HttpStatus.ERROR, "用户社区未创建"); return AjaxResult.error(HttpStatus.ERROR, "用户社区未创建");

View File

@ -15,6 +15,7 @@ import com.mcwl.communityCenter.constant.StatusConstant;
import com.mcwl.communityCenter.domain.Community; import com.mcwl.communityCenter.domain.Community;
import com.mcwl.communityCenter.domain.CommunityAdvice; import com.mcwl.communityCenter.domain.CommunityAdvice;
import com.mcwl.communityCenter.domain.Question; import com.mcwl.communityCenter.domain.Question;
import com.mcwl.communityCenter.domain.dto.QuestionDetailRes;
import com.mcwl.communityCenter.domain.dto.QuestionPageRes; import com.mcwl.communityCenter.domain.dto.QuestionPageRes;
import com.mcwl.communityCenter.domain.dto.QuestionReplyRes; import com.mcwl.communityCenter.domain.dto.QuestionReplyRes;
import com.mcwl.communityCenter.domain.dto.QuestionRes; import com.mcwl.communityCenter.domain.dto.QuestionRes;
@ -41,7 +42,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
private final CommunityAdviceMapper communityAdviceMapper; private final CommunityAdviceMapper communityAdviceMapper;
private final CommunityService communityService; private final CommunityMapper communityMapper;
private final ISysUserService sysUserService; private final ISysUserService sysUserService;
@ -59,9 +60,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
// 获取租户id // 获取租户id
Long tenantId = questionRes.getTenantId(); Long tenantId = questionRes.getTenantId();
Community community = communityService.lambdaQuery() Community community = communityMapper.getByTenantIdAndCommunityId(tenantId, communityId);
.eq(Community::getId, communityId)
.eq(Community::getTenantId, tenantId).one();
if (Objects.isNull(community)) { if (Objects.isNull(community)) {
return AjaxResult.error("租户或社区不存在"); return AjaxResult.error("租户或社区不存在");
@ -94,7 +93,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
} }
@Override @Override
public TableDataInfo listUnReplied(QuestionPageRes questionPageRes) { public TableDataInfo list(QuestionPageRes questionPageRes) {
Page<Question> page = new Page<>(questionPageRes.getPageNum(), questionPageRes.getPageSize()); Page<Question> page = new Page<>(questionPageRes.getPageNum(), questionPageRes.getPageSize());
OrderItem orderItem = new OrderItem(); OrderItem orderItem = new OrderItem();
@ -105,11 +104,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
orderItem.setAsc(Objects.equals(questionPageRes.getIsAsc(), "asc")); orderItem.setAsc(Objects.equals(questionPageRes.getIsAsc(), "asc"));
page.addOrder(orderItem); page.addOrder(orderItem);
baseMapper.list(page, questionPageRes.getTenantId(), questionPageRes.getCommunityId(), questionPageRes.getStatus());
LambdaQueryWrapper<Question> lqw = new LambdaQueryWrapper<>();
lqw.eq(Question::getCommunityId, questionPageRes.getCommunityId())
.eq(Question::getStatus, StatusConstant.STATUS_UNREPLIED);
baseMapper.selectPage(page, lqw);
// 获取分页数据 // 获取分页数据
List<Question> questionList = page.getRecords(); List<Question> questionList = page.getRecords();
@ -137,9 +132,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
} }
@Override @Override
public QuestionVo getDetail(Long id) { public QuestionVo getDetail(QuestionDetailRes questionDetailRes) {
Long questionId = questionDetailRes.getQuestionId();
Long tenantId = questionDetailRes.getTenantId();
Long communityId = questionDetailRes.getCommunityId();
Question question = baseMapper.selectById(id); Question question = baseMapper.selectByIdAndTenantIdAndCommunityId(questionId, tenantId, communityId);
if (Objects.isNull(question)) { if (Objects.isNull(question)) {
return null; return null;
} }
@ -160,25 +158,28 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
* @param questionReplyRes * @param questionReplyRes
*/ */
@Override @Override
public void reply(QuestionReplyRes questionReplyRes) { public AjaxResult reply(QuestionReplyRes questionReplyRes) {
Long communityId = questionReplyRes.getCommunityId();
Long questionId = questionReplyRes.getQuestionId(); Long questionId = questionReplyRes.getQuestionId();
LambdaQueryWrapper<Question> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Question> lqw = new LambdaQueryWrapper<>();
lqw.eq(Question::getId, questionId) lqw.eq(Question::getId, questionId)
.eq(Question::getCommunityId, communityId)
.eq(Question::getStatus, StatusConstant.STATUS_UNREPLIED); .eq(Question::getStatus, StatusConstant.STATUS_UNREPLIED);
// 查询问题信息 // 查询问题信息
Question question = baseMapper.selectOne(lqw); Question question = baseMapper.selectOne(lqw);
if (Objects.isNull(question)) { if (Objects.isNull(question)) {
return; return AjaxResult.error("问题不存在或已被回复");
} }
question.setContent(questionReplyRes.getContent()); question.setReply(questionReplyRes.getReply());
question.setStatus(StatusConstant.STATUS_REPLIED); question.setStatus(StatusConstant.STATUS_REPLIED);
question.setReplyTime(new Date()); question.setReplyTime(new Date());
baseMapper.updateById(question); baseMapper.updateById(question);
return AjaxResult.success();
} }

View File

@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.communityCenter.mapper.CommunityMapper"> <mapper namespace="com.mcwl.communityCenter.mapper.CommunityMapper">
<select id="getByUserIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Community"> <select id="getByTenantIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Community">
select id, select id,
tenant_id, tenant_id,
community_name, community_name,

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.communityCenter.mapper.QuestionMapper">
<select id="list" resultType="com.mcwl.communityCenter.domain.Question">
select id, tenant_id, community_id, question_user_id, content,question_url, reply,reply_time,is_anonymous,status
from cc_question
where del_flag = '0'
and tenant_id = #{tenantId}
and community_id = #{communityId}
<if test="status != null">
and status= #{status}
</if>
</select>
<select id="selectByIdAndTenantIdAndCommunityId" resultType="com.mcwl.communityCenter.domain.Question">
select id, tenant_id, community_id, question_user_id, content,question_url, reply,reply_time,is_anonymous,status
from cc_question
where id = #{id}
and tenant_id = #{tenantId}
and community_id = #{communityId}
and del_flag = '0'
</select>
</mapper>