提交 25043b4d 编写于 作者: minghao.wu's avatar minghao.wu

feature: 加入replyStatus参数,插入回复记录完成

上级 da0b51b8
......@@ -14,6 +14,11 @@ public class ExamTitleReplyDetailDto {
private ReplyDto reply;
/**
* 是否允许回复 0: 否 1: 填写 2: 编辑
*/
private Integer replyStatus;
public Integer getAnalysisId() {
return analysisId;
}
......@@ -45,4 +50,12 @@ public class ExamTitleReplyDetailDto {
public void setReply(ReplyDto reply) {
this.reply = reply;
}
public Integer getReplyStatus() {
return replyStatus;
}
public void setReplyStatus(Integer replyStatus) {
this.replyStatus = replyStatus;
}
}
......@@ -17,7 +17,7 @@ public class ExamTitleReplyDto {
private List<ReplyDto> replyList;
/**
* 是否允许回复 0: 否 1:
* 是否允许回复 0: 否 1: 填写 2: 编辑
*/
private Integer replyStatus;
......
......@@ -16,6 +16,7 @@ import com.pica.cloud.online.exam.analysis.server.service.CHCAnalysisService;
import com.pica.cloud.online.exam.analysis.server.service.DoctorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javassist.bytecode.ExceptionsAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*;
......@@ -72,6 +73,30 @@ public class AnalysisController {
return builder.build();
}
@ApiOperation(value = "获取活动详情", response = PicaResponse.class)
@RequestMapping(value = "/psaActivityDetail", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<CHCAnalysisDto> getPSAActivityDetail(@RequestParam(required = false) Integer id) {
PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>();
/**
* 如果不传活动id进来,活动id就用1
*/
id = (id == null ? 2 : id);
try {
CHCAnalysisDto analysisDto = analysisService.getPSAAnalysisById(id);
List<AnalysisRoundDto> roundList = analysisService.getRoundListByAnalysisId(id);
analysisDto.setRoundList(roundList);
builder.setData(analysisDto);
} catch (Exception e) {
e.printStackTrace();
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_INNER_ERROR);
}
return builder.build();
}
@ApiOperation(value = "获取某一轮的题目", response = PicaResponse.class)
@RequestMapping(value = "/roundDetail/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<RoundExamTitleDto> getRoundDetail(@PathVariable("roundId") Integer roundId) {
......@@ -94,7 +119,7 @@ public class AnalysisController {
@ApiOperation(value = "获取某一道题目的回复列表", response = PicaResponse.class)
@RequestMapping(value = "/replyList/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> getReplyList(@PathVariable("examTitleId") Integer examTitleId,
@RequestParam(required = false) String token) {
@RequestHeader(required = false) String token) {
PICAUser user = null;
......@@ -116,6 +141,15 @@ public class AnalysisController {
examTitleReplyDto.setExamTitle(examTitleDto);
examTitleReplyDto.setReplyList(replyDtoList);
if (user == null || user.getId() == 0) {
examTitleReplyDto.setReplyStatus(0);
} else {
/**
* 判断权限
*/
examTitleReplyDto.setReplyStatus(analysisService.getReplyStatus(examTitleId, user.getId()));
}
builder.setData(examTitleReplyDto);
} catch (Exception e) {
e.printStackTrace();
......@@ -212,8 +246,9 @@ public class AnalysisController {
PICAUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_INVALID_TOKEN);
if (user == null || user.getId().intValue() == 0) {
System.out.println("cancelStar: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
System.out.println("cancelStar: replyid=" + replyId.toString() + " token=" + token);
......@@ -306,11 +341,26 @@ public class AnalysisController {
PICAUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_INVALID_TOKEN);
if (user == null || user.getId().intValue() == 0) {
System.out.println("reply: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
antiSpamService.processString(content);
/**
* 如果判断检测的数据中有垃圾 直接返回
*/
PicaResponse response = antiSpamService.processString(content);
if (!response.getCode().equals(PicaResultCode.SUCCESS.code()))
return response;
/**
* 插入数据库
*/
try {
analysisService.insertReply(examTitleId, content, user.getId());
} catch (Exception e) {
return ReturnUtil.getPicaResponse(PicaResultCode.INTERFACE_INVOKE_EXCEPTION);
}
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
......
......@@ -11,6 +11,8 @@ public interface CHCAnalysisMapper {
CHCAnalysis selectByPrimaryKey(Integer id);
CHCAnalysis selectPSAByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(CHCAnalysis record);
int updateByPrimaryKey(CHCAnalysis record);
......
......@@ -19,5 +19,9 @@ public interface ReplyMapper {
int selectReplyCountByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId);
int selectReplyCountByRecord(Reply record);
Reply selectReplyByRecord(Reply record);
List<Reply> selectReplyListByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId);
}
\ No newline at end of file
......@@ -18,6 +18,12 @@ public interface CHCAnalysisService {
*/
CHCAnalysisDto getCHCAnalysisById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysisDto getPSAAnalysisById(Integer analysisId);
/**
* 根据活动id获取活动的轮数
......@@ -110,4 +116,20 @@ public interface CHCAnalysisService {
*/
Integer removeStarRecord(Integer replyId, Integer userId);
/**
* 增加解析
* @param examTitleId
* @param content
* @param userId
* @return
*/
Integer insertReply(Integer examTitleId, String content, Integer userId);
/**
* 获取我的评论状态
* @param examTitleId
* @param userId
* @return
*/
Integer getReplyStatus(Integer examTitleId, Integer userId);
}
package com.pica.cloud.online.exam.analysis.server.service.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.pica.cloud.foundation.entity.PicaResponse;
......@@ -46,6 +47,7 @@ public class AntiSpamServiceImpl implements AntiSpamService {
/**
* 2. 设置私有参数
*/
params.put("dataId", "ebfcad1c-pica-490c-b4de-e784c2691768");
params.put("content", content);
/**
......@@ -63,6 +65,8 @@ public class AntiSpamServiceImpl implements AntiSpamService {
*/
String response = HttpClient4Utils.sendPost(httpClient, properties.getNeteaseAntispamTextApiUrl(), params, Consts.UTF_8);
System.out.println("content:" + content + " response=" + response);
/**
* 5. 解析返回值
*/
......@@ -70,11 +74,37 @@ public class AntiSpamServiceImpl implements AntiSpamService {
int code = jObject.get("code").getAsInt();
String msg = jObject.get("msg").getAsString();
if (code == 200) {
JsonObject resultObject = jObject.getAsJsonObject("result");
int action = resultObject.get("action").getAsInt();
/**
* label: 100 色情
* label: 200 广告
* label: 400 违禁
* label: 500 涉政
* label: 600 谩骂
* label: 700 灌水
*/
JsonArray labelArray = resultObject.getAsJsonArray("labels");
/**
* action: 0 通过
* action: 1 嫌疑
* action: 2 不通过
*/
if (action == 0) {
} else {
/**
* TODO: 可以进一步处理 显示信息被过滤原因
*/
return ReturnUtil.getPicaResponse(PicaResultCode.DATA_IS_WRONG);
}
} else {
return ReturnUtil.getPicaResponse(PicaResultCode.DATA_IS_WRONG);
return ReturnUtil.getPicaResponse(jObject.get("code").getAsString(), msg);
}
return ReturnUtil.getPicaResponse(PicaResultCode.DATA_IS_WRONG);
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
}
......@@ -71,6 +71,31 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return analysisDto;
}
@Override
public CHCAnalysisDto getPSAAnalysisById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectPSAByPrimaryKey(analysisId);
if (null == analysis) {
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
CHCAnalysisDto analysisDto = new CHCAnalysisDto();
analysisDto.setId(analysis.getId());
analysisDto.setName(analysis.getAnalysisName());
analysisDto.setMainTitle(analysis.getMainTitle());
analysisDto.setSubTitle(analysis.getSubTitle());
analysisDto.setIntro(analysis.getIntro());
analysisDto.setStartTime(sdf.format(analysis.getStartTime()));
analysisDto.setEndTime(sdf.format(analysis.getEndTime()));
analysisDto.setLogoUrl(analysis.getLogoUrl());
analysisDto.setPrizeUrl(analysis.getPrizeUrl());
analysisDto.setAuthUser(analysis.getAuthUser());
analysisDto.setRule(analysis.getRule());
return analysisDto;
}
@Override
public List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId) {
List<AnalysisRound> roundList = analysisRoundMapper.selectRoundListById(analysisId);
......@@ -357,4 +382,60 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return this.getExamTitleDtoById(roundExamTitleList.get(idx).getId());
}
@Override
public Integer insertReply(Integer examTitleId, String content, Integer userId) {
/**
* 找到我是否已经回复过,如果回复过就编辑,没有就新建
*/
Reply reply = new Reply();
reply.setAnalysisRoundExamTitleId(examTitleId);
reply.setUserId(userId);
Integer myReplyCount = replyMapper.selectReplyCountByRecord(reply);
if (myReplyCount == 0) {
Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId);
reply.setContent(content);
reply.setReplyLevel((byte) 1);
reply.setSeqNo(replyCount + 1);
reply.setStarCount(0);
reply.setCreatedId(userId);
reply.setCreatedTime(new Date());
reply.setModifiedId(userId);
reply.setModifiedTime(new Date());
reply.setIsDeleted(false);
return replyMapper.insert(reply);
} else {
Reply record = replyMapper.selectReplyByRecord(reply);
record.setContent(content);
record.setModifiedTime(new Date());
return replyMapper.updateByPrimaryKey(record);
}
}
@Override
public Integer getReplyStatus(Integer examTitleId, Integer userId) {
Reply reply = new Reply();
reply.setAnalysisRoundExamTitleId(examTitleId);
reply.setUserId(userId);
Integer myReplyCount = replyMapper.selectReplyCountByRecord(reply);
if (myReplyCount == 0) {
/**
* 未回复过
*/
return 1;
}
/**
* 已回复过
*/
return 2;
}
}
......@@ -31,7 +31,19 @@
<include refid="Base_Column_List" />
from p_chc_analysis
where id = #{id,jdbcType=INTEGER}
and type = 1
and is_deleted = 0
</select>
<select id="selectPSAByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_chc_analysis
where id = #{id,jdbcType=INTEGER}
and type = 2
and is_deleted = 0
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_chc_analysis
where id = #{id,jdbcType=INTEGER}
......
......@@ -36,6 +36,24 @@
and is_deleted = 0
</select>
<select id="selectReplyCountByRecord" resultType="java.lang.Integer" parameterType="com.pica.cloud.online.exam.analysis.server.entity.Reply" >
select
count(1)
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
and is_deleted = 0
</select>
<select id="selectReplyByRecord" resultMap="BaseResultMap" parameterType="com.pica.cloud.online.exam.analysis.server.entity.Reply" >
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
and is_deleted = 0
</select>
<select id="selectReplyListByAnalysisRoundExamTitleId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册