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

Merge branch 'dev_phase2' into release

# Conflicts:
#	server/src/main/java/com/pica/cloud/online/exam/analysis/server/controller/AnalysisController.java
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<groupId>com.pica.cloud.online.exam</groupId> <groupId>com.pica.cloud.online.exam</groupId>
<artifactId>pica-cloud-analysis-common</artifactId> <artifactId>pica-cloud-analysis-common</artifactId>
<name>pica-cloud-analysis-common</name> <name>pica-cloud-analysis-common</name>
<version>1.0.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
......
...@@ -14,6 +14,16 @@ public class ExamTitleReplyDetailDto { ...@@ -14,6 +14,16 @@ public class ExamTitleReplyDetailDto {
private ReplyDto reply; private ReplyDto reply;
/**
* 是否允许回复 0: 否 1: 填写 2: 编辑
*/
private Integer replyStatus;
/**
* 活动类型 1: chc 2: PSA
*/
private Integer type;
public Integer getAnalysisId() { public Integer getAnalysisId() {
return analysisId; return analysisId;
} }
...@@ -45,4 +55,20 @@ public class ExamTitleReplyDetailDto { ...@@ -45,4 +55,20 @@ public class ExamTitleReplyDetailDto {
public void setReply(ReplyDto reply) { public void setReply(ReplyDto reply) {
this.reply = reply; this.reply = reply;
} }
public Integer getReplyStatus() {
return replyStatus;
}
public void setReplyStatus(Integer replyStatus) {
this.replyStatus = replyStatus;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
} }
...@@ -17,10 +17,15 @@ public class ExamTitleReplyDto { ...@@ -17,10 +17,15 @@ public class ExamTitleReplyDto {
private List<ReplyDto> replyList; private List<ReplyDto> replyList;
/** /**
* 是否允许回复 0: 否 1: * 是否允许回复 0: 否 1: 填写 2: 编辑
*/ */
private Integer replyStatus; private Integer replyStatus;
/**
* 活动类型 1: chc 2: PSA
*/
private Integer type;
public Integer getAnalysisId() { public Integer getAnalysisId() {
return analysisId; return analysisId;
} }
...@@ -60,4 +65,12 @@ public class ExamTitleReplyDto { ...@@ -60,4 +65,12 @@ public class ExamTitleReplyDto {
public void setReplyStatus(Integer replyStatus) { public void setReplyStatus(Integer replyStatus) {
this.replyStatus = replyStatus; this.replyStatus = replyStatus;
} }
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
} }
package com.pica.cloud.online.exam.analysis.common.req;
/**
* @author wuminghao
* @date 2018/8/16 17:23
*/
public class StarReplyReq {
private Integer analysisId;
private Integer roundId;
private Integer replyId;
public Integer getAnalysisId() {
return analysisId;
}
public void setAnalysisId(Integer analysisId) {
this.analysisId = analysisId;
}
public Integer getRoundId() {
return roundId;
}
public void setRoundId(Integer roundId) {
this.roundId = roundId;
}
public Integer getReplyId() {
return replyId;
}
public void setReplyId(Integer replyId) {
this.replyId = replyId;
}
}
\ No newline at end of file
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
<dependency> <dependency>
<groupId>com.pica.cloud.online.exam</groupId> <groupId>com.pica.cloud.online.exam</groupId>
<artifactId>pica-cloud-analysis-common</artifactId> <artifactId>pica-cloud-analysis-common</artifactId>
<version>1.0.0</version> <version>1.0.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
......
...@@ -16,6 +16,24 @@ public class PropertiesConfiguration { ...@@ -16,6 +16,24 @@ public class PropertiesConfiguration {
@Value("${common.file.url}") @Value("${common.file.url}")
private String fileUrl; private String fileUrl;
@Value("${netease.antispam.text.apiurl}")
private String neteaseAntispamTextApiUrl;
@Value("${netease.antispam.text.businessid}")
private String neteaseAntispamTextBusinessId;
@Value("${netease.antispam.image.apiurl}")
private String neteaseAntispamImageApiUrl;
@Value("${netease.antispam.image.businessid}")
private String neteaseAntispamImageBusinessId;
@Value("${netease.antispam.secretid}")
private String neteaseAntispamSecretId;
@Value("${netease.antispam.secretkey}")
private String neteaseAntispamSecretKey;
public String getUserExpire() { public String getUserExpire() {
return userExpire; return userExpire;
} }
...@@ -40,6 +58,54 @@ public class PropertiesConfiguration { ...@@ -40,6 +58,54 @@ public class PropertiesConfiguration {
this.fileUrl = fileUrl; this.fileUrl = fileUrl;
} }
public String getNeteaseAntispamTextApiUrl() {
return neteaseAntispamTextApiUrl;
}
public void setNeteaseAntispamTextApiUrl(String neteaseAntispamTextApiUrl) {
this.neteaseAntispamTextApiUrl = neteaseAntispamTextApiUrl;
}
public String getNeteaseAntispamTextBusinessId() {
return neteaseAntispamTextBusinessId;
}
public void setNeteaseAntispamTextBusinessId(String neteaseAntispamTextBusinessId) {
this.neteaseAntispamTextBusinessId = neteaseAntispamTextBusinessId;
}
public String getNeteaseAntispamImageApiUrl() {
return neteaseAntispamImageApiUrl;
}
public void setNeteaseAntispamImageApiUrl(String neteaseAntispamImageApiUrl) {
this.neteaseAntispamImageApiUrl = neteaseAntispamImageApiUrl;
}
public String getNeteaseAntispamImageBusinessId() {
return neteaseAntispamImageBusinessId;
}
public void setNeteaseAntispamImageBusinessId(String neteaseAntispamImageBusinessId) {
this.neteaseAntispamImageBusinessId = neteaseAntispamImageBusinessId;
}
public String getNeteaseAntispamSecretId() {
return neteaseAntispamSecretId;
}
public void setNeteaseAntispamSecretId(String neteaseAntispamSecretId) {
this.neteaseAntispamSecretId = neteaseAntispamSecretId;
}
public String getNeteaseAntispamSecretKey() {
return neteaseAntispamSecretKey;
}
public void setNeteaseAntispamSecretKey(String neteaseAntispamSecretKey) {
this.neteaseAntispamSecretKey = neteaseAntispamSecretKey;
}
@Override @Override
public String toString() { public String toString() {
return "PropertiesConfiguration{" + return "PropertiesConfiguration{" +
......
package com.pica.cloud.online.exam.analysis.server.entity;
/**
* @author wuminghao
* @date 2018/8/28 13:52
*/
public class CHCRankingList {
private Integer id;
private Integer doctorId;
private String doctorName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getDoctorId() {
return doctorId;
}
public void setDoctorId(Integer doctorId) {
this.doctorId = doctorId;
}
public String getDoctorName() {
return doctorName;
}
public void setDoctorName(String doctorName) {
this.doctorName = doctorName;
}
}
...@@ -142,4 +142,24 @@ public class Reply { ...@@ -142,4 +142,24 @@ public class Reply {
public void setIsDeleted(Boolean isDeleted) { public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted; this.isDeleted = isDeleted;
} }
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Reply other = (Reply) obj;
if (other.getId() == null) {
return false;
}
if (id == null) {
if (other.getId() != null)
return false;
} else if (!id.equals(other.getId()))
return false;
return true;
}
} }
\ No newline at end of file
...@@ -11,6 +11,10 @@ public interface CHCAnalysisMapper { ...@@ -11,6 +11,10 @@ public interface CHCAnalysisMapper {
CHCAnalysis selectByPrimaryKey(Integer id); CHCAnalysis selectByPrimaryKey(Integer id);
CHCAnalysis selectCHCByPrimaryKey(Integer id);
CHCAnalysis selectPSAByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(CHCAnalysis record); int updateByPrimaryKeySelective(CHCAnalysis record);
int updateByPrimaryKey(CHCAnalysis record); int updateByPrimaryKey(CHCAnalysis record);
......
package com.pica.cloud.online.exam.analysis.server.mapper;
/**
* @author wuminghao
* @date 2018/8/28 15:07
*/
public interface CHCRankingListMapper {
/**
* 根据医生id判断是否在200名范围内
* @param doctorId
* @return
*/
int selectRecordExistTop200(int doctorId);
}
package com.pica.cloud.online.exam.analysis.server.mapper; package com.pica.cloud.online.exam.analysis.server.mapper;
import com.pica.cloud.online.exam.analysis.server.entity.Doctor; import com.pica.cloud.online.exam.analysis.server.entity.Doctor;
import org.omg.CORBA.INTERNAL;
/** /**
* @author wuminghao * @author wuminghao
...@@ -13,4 +14,18 @@ public interface DoctorMapper { ...@@ -13,4 +14,18 @@ public interface DoctorMapper {
* @return * @return
*/ */
Doctor selectByPrimaryKey(int id); Doctor selectByPrimaryKey(int id);
/**
* 根据医生id获取是否有权限
* @param doctorId
* @return
*/
Integer selectAuthByDoctorId(Integer doctorId);
/**
* 根据医生id获取患者个数
* @param doctorId
* @return
*/
Integer selectPatientCountByDoctorId(Integer doctorId);
} }
...@@ -19,5 +19,23 @@ public interface ReplyMapper { ...@@ -19,5 +19,23 @@ public interface ReplyMapper {
int selectReplyCountByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId); int selectReplyCountByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId);
int selectReplyCountByRecord(Reply record);
Reply selectReplyByRecord(Reply record);
List<Reply> selectReplyListByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId); List<Reply> selectReplyListByAnalysisRoundExamTitleId(Integer analysisRoundExamTitleId);
/**
* 按照时间逆序获取
* @param analysisRoundExamTitleId
* @return
*/
List<Reply> selectReplyListOrderByTime(Integer analysisRoundExamTitleId);
/**
* 获取最热的五条记录
* @param analysisRoundExamTitleId
* @return
*/
List<Reply> selectFiveHottestReplyList(Integer analysisRoundExamTitleId);
} }
\ No newline at end of file
package com.pica.cloud.online.exam.analysis.server.service;
import com.pica.cloud.foundation.entity.PicaResponse;
/**
* @author wuminghao
* @date 2018/8/27 14:38
*/
public interface AntiSpamService {
PicaResponse processString(String content);
boolean processImageContent(String content);
boolean processImage(String url);
}
...@@ -2,6 +2,7 @@ package com.pica.cloud.online.exam.analysis.server.service; ...@@ -2,6 +2,7 @@ package com.pica.cloud.online.exam.analysis.server.service;
import com.pica.cloud.online.exam.analysis.common.dto.*; import com.pica.cloud.online.exam.analysis.common.dto.*;
import com.pica.cloud.online.exam.analysis.server.entity.AnalysisRoundExamTitle; import com.pica.cloud.online.exam.analysis.server.entity.AnalysisRoundExamTitle;
import com.pica.cloud.online.exam.analysis.server.entity.CHCAnalysis;
import com.pica.cloud.online.exam.analysis.server.entity.Reply; import com.pica.cloud.online.exam.analysis.server.entity.Reply;
import java.util.List; import java.util.List;
...@@ -16,8 +17,21 @@ public interface CHCAnalysisService { ...@@ -16,8 +17,21 @@ public interface CHCAnalysisService {
* @param analysisId * @param analysisId
* @return * @return
*/ */
CHCAnalysisDto getCHCAnalysisById(Integer analysisId); CHCAnalysis getAnalysisById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId);
/** /**
* 根据活动id获取活动的轮数 * 根据活动id获取活动的轮数
...@@ -54,6 +68,14 @@ public interface CHCAnalysisService { ...@@ -54,6 +68,14 @@ public interface CHCAnalysisService {
*/ */
ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId); ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId);
/**
* 获取当前题目的下一题目
* @param roundId 当前轮的id
* @param analysisRoundExamTitleId 当前题目的id
* @return 下一题目的id
*/
ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId);
/** /**
* 根据题目id获取回复信息 * 根据题目id获取回复信息
* @param analysisRoundExamTitleId * @param analysisRoundExamTitleId
...@@ -69,6 +91,13 @@ public interface CHCAnalysisService { ...@@ -69,6 +91,13 @@ public interface CHCAnalysisService {
*/ */
Reply getReplyById(Integer replyId); Reply getReplyById(Integer replyId);
/**
* 根据id获取下一条reply
* @param replyId
* @return
*/
Reply getNextReplyById(Integer replyId);
/** /**
* 根据reply获取replydto * 根据reply获取replydto
* @param reply * @param reply
...@@ -94,4 +123,37 @@ public interface CHCAnalysisService { ...@@ -94,4 +123,37 @@ public interface CHCAnalysisService {
* @return * @return
*/ */
Integer removeStarRecord(Integer replyId, Integer userId); 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);
/**
* 获取我的评论详情
* @param examTitleId
* @param userId
* @return
*/
Reply getReplyByExamTitleId(Integer examTitleId, Integer userId);
/**
* 根据考试id获取评论列表
* @param examTitleId
* @return
*/
List<Reply> getReplyList(Integer examTitleId);
} }
package com.pica.cloud.online.exam.analysis.server.service;
/**
* @author wuminghao
* @date 2018/8/28 13:55
*/
public interface CHCRankingListService {
/**
* 判断输入的用户id是否为前200名
* @param doctorId
* @return
*/
boolean isRankingInTop200(Integer doctorId);
}
...@@ -13,4 +13,11 @@ public interface DoctorService { ...@@ -13,4 +13,11 @@ public interface DoctorService {
* @return * @return
*/ */
Doctor getDoctorById(Integer doctorId); Doctor getDoctorById(Integer doctorId);
/**
* 根据医生的id获取医生的权限
* @param doctorId
* @return
*/
boolean isAuth(Integer doctorId);
} }
package com.pica.cloud.online.exam.analysis.server.service.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.online.exam.analysis.common.util.ReturnUtil;
import com.pica.cloud.online.exam.analysis.server.configuration.PropertiesConfiguration;
import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService;
import com.pica.cloud.online.exam.analysis.server.utils.HttpClient4Utils;
import com.pica.cloud.online.exam.analysis.server.utils.SignatureUtils;
import org.apache.http.Consts;
import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.regex.Pattern;
/**
* @author wuminghao
* @date 2018/8/27 14:38
*/
@Service
public class AntiSpamServiceImpl implements AntiSpamService {
@Autowired
private PropertiesConfiguration properties;
private static HttpClient httpClient = HttpClient4Utils.createHttpClient(100, 20, 2000, 2000, 2000);
private static HttpClient httpClientImage = HttpClient4Utils.createHttpClient(100, 20, 10000, 2000, 2000);
@Override
public PicaResponse processString(String content) {
/**
* 过滤图片
*/
if (!processImageContent(content)) {
return ReturnUtil.getPicaResponse("400002", "图片包含违禁内容,请修改后重新输入");
}
Map<String, String> params = new HashMap<String, String>();
/**
* 1. 设置公共参数
*/
params.put("secretId", properties.getNeteaseAntispamSecretId());
params.put("businessId", properties.getNeteaseAntispamTextBusinessId());
params.put("version", "v3.1");
params.put("timestamp", String.valueOf(System.currentTimeMillis()));
params.put("nonce", String.valueOf(new Random().nextInt()));
/**
* 2. 设置私有参数
*/
params.put("dataId", "ebfcad1c-pica-490c-b4de-e784c2691768");
params.put("content", content);
/**
* 3. 生成签名信息
*/
try {
String signature = SignatureUtils.genSignature(properties.getNeteaseAntispamSecretKey(), params);
params.put("signature", signature);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
/**
* 4. 发送HTTP请求
*/
String response = HttpClient4Utils.sendPost(httpClient, properties.getNeteaseAntispamTextApiUrl(), params, Consts.UTF_8);
System.out.println("content:" + content + " response=" + response);
/**
* 5. 解析返回值
*/
JsonObject jObject = new JsonParser().parse(response).getAsJsonObject();
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 {
for (JsonElement labelElement : labelArray) {
JsonObject lObject = labelElement.getAsJsonObject();
int label = lObject.get("label").getAsInt();
int level = lObject.get("level").getAsInt();
JsonObject detailsObject=lObject.getAsJsonObject("details");
JsonArray hintArray=detailsObject.getAsJsonArray("hint");
if (label == 100) msg = "输入内容包含色情词汇,请修改后重新输入";
else if (label == 200) msg = "输入内容包含广告词汇,请修改后重新输入";
else if (label == 400) msg = "输入内容包含违禁词汇,请修改后重新输入";
else if (label == 500) msg = "输入内容包含涉政词汇,请修改后重新输入";
else if (label == 600) msg = "输入内容包含谩骂词汇,请修改后重新输入";
else if (label == 700) msg = "输入内容包含灌水词汇,请修改后重新输入";
return ReturnUtil.getPicaResponse("400002", msg);
}
}
} else {
return ReturnUtil.getPicaResponse(jObject.get("code").getAsString(), msg, "");
}
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS, "");
}
@Override
public boolean processImageContent(String content) {
List<String> imageUrlList = new ArrayList<>();
/**
* 如果不包含图片,直接返回
*/
if (!content.contains("<imgsrc=")) {
return true;
}
int index = -1;
int end = -1;
while (-1 != (index = content.indexOf("<imgsrc=\""))) {
end = content.substring(index, content.length()).indexOf("\">");
imageUrlList.add(content.substring(index,index + end).replace("<imgsrc=\"", ""));
content = content.replaceFirst("(<imgsrc[\\s\\S]*?>)", "");
}
for (String url : imageUrlList) {
/**
* 检测出某张图片失败 则返回
*/
if (!processImage(url)) {
return false;
}
}
return true;
}
@Override
public boolean processImage(String url) {
Map<String, String> params = new HashMap<String, String>();
/**
* 1. 设置公共参数
*/
params.put("secretId", properties.getNeteaseAntispamSecretId());
params.put("businessId", properties.getNeteaseAntispamImageBusinessId());
params.put("version", "v3.2");
params.put("timestamp", String.valueOf(System.currentTimeMillis()));
params.put("nonce", String.valueOf(new Random().nextInt()));
/**
* 2. 设置私有参数
*/
JsonArray jsonArray = new JsonArray();
JsonObject image = new JsonObject();
image.addProperty("name", url);
image.addProperty("type", 1);
image.addProperty("data", url);
jsonArray.add(image);
params.put("images", jsonArray.toString());
params.put("account", "picahealth@picahealth.com");
/**
* 3. 生成签名信息
*/
try {
String signature = SignatureUtils.genSignature(properties.getNeteaseAntispamSecretKey(), params);
params.put("signature", signature);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
/**
* 4. 发送HTTP请求
*/
String response = HttpClient4Utils.sendPost(httpClientImage, properties.getNeteaseAntispamImageApiUrl(), params, Consts.UTF_8);
/**
* 5. 解析返回值
*/
JsonObject resultObject = new JsonParser().parse(response).getAsJsonObject();
int code = resultObject.get("code").getAsInt();
String msg = resultObject.get("msg").getAsString();
if (code == 200) {
JsonArray resultArray = resultObject.getAsJsonArray("result");
for (JsonElement jsonElement : resultArray) {
JsonObject jObject = jsonElement.getAsJsonObject();
String name = jObject.get("name").getAsString();
int status = jObject.get("status").getAsInt();
String taskId = jObject.get("taskId").getAsString();
JsonArray labelArray = jObject.get("labels").getAsJsonArray();
System.out.println(String.format("taskId=%s,status=%s,name=%s,labels:", taskId, status, name));
/**
* 检测失败 0:成功 610:图片下载失败 620:图片格式错误 630:其他
*/
if (status != 0) {
continue;
}
/**
* 100:色情,110:性感,200:广告,210:二维码,300:暴恐,400:违禁,500:涉政
*/
int maxLevel = -1;
double maxRate = 0.0;
// 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
for (JsonElement labelElement : labelArray) {
JsonObject lObject = labelElement.getAsJsonObject();
int label = lObject.get("label").getAsInt();
int level = lObject.get("level").getAsInt();
double rate = lObject.get("rate").getAsDouble();
if (label == 100 || label == 110 || label == 210) {
System.out.println(String.format("label:%s, level=%s, rate=%s", label, level, rate));
maxLevel = level > maxLevel ? level : maxLevel;
maxRate = rate > maxRate ? rate : maxRate;
}
}
if (maxLevel == 2) {
return false;
}
}
} else {
System.out.println(String.format("ERROR: code=%s, msg=%s", code, msg));
}
return true;
}
}
...@@ -46,9 +46,39 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -46,9 +46,39 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
private PropertiesConfiguration properties; private PropertiesConfiguration properties;
@Override @Override
public CHCAnalysisDto getCHCAnalysisById(Integer analysisId) { public CHCAnalysis getAnalysisById(Integer analysisId) {
return analysisMapper.selectByPrimaryKey(analysisId);
}
@Override
public CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectCHCByPrimaryKey(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());
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisId); return analysisDto;
}
@Override
public CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectPSAByPrimaryKey(analysisId);
if (null == analysis) { if (null == analysis) {
return null; return null;
} }
...@@ -159,30 +189,33 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -159,30 +189,33 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
/** /**
* 设置选项 * 设置选项
*/ */
List<String> configList = new ArrayList<>(); if (analysisRoundExamTitle.getConfig() != null) {
String[] configArr = analysisRoundExamTitle.getConfig().split("\\$\\{answer\\}"); List<String> configList = new ArrayList<>();
for (int idx = 0; idx < configArr.length; ++ idx) { String[] configArr = analysisRoundExamTitle.getConfig().split("\\$\\{answer\\}");
configList.add(OPTIONS[idx] + "." + configArr[idx]); for (int idx = 0; idx < configArr.length; ++idx) {
configList.add(OPTIONS[idx] + "." + configArr[idx]);
}
examTitleDto.setConfig(configList);
} }
examTitleDto.setConfig(configList);
/** /**
* 设置答案 * 设置答案
*/ */
examTitleDto.setAnswer(analysisRoundExamTitle.getAnswer()); if (analysisRoundExamTitle.getAnswer() != null) {
String[] answerArr = analysisRoundExamTitle.getAnswer().split(","); examTitleDto.setAnswer(analysisRoundExamTitle.getAnswer());
List<Integer> idxList = new ArrayList<>(); String[] answerArr = analysisRoundExamTitle.getAnswer().split(",");
List<Integer> idxList = new ArrayList<>();
for (String sa : answerArr) {
for (int i = 0; i < 8; ++ i) { for (String sa : answerArr) {
if (sa.equals(OPTIONS[i])) { for (int i = 0; i < 8; ++i) {
idxList.add(i); if (sa.equals(OPTIONS[i])) {
idxList.add(i);
}
} }
} }
examTitleDto.setAnswerIdx(StringUtils.join(idxList, ","));
} }
examTitleDto.setAnswerIdx(StringUtils.join(idxList, ","));
examTitleDto.setErrorRate(analysisRoundExamTitle.getErrorRate()); examTitleDto.setErrorRate(analysisRoundExamTitle.getErrorRate());
examTitleDto.setStarCount(starRecordMapper.selectStarCountByRoundExamTitleId(analysisRoundExamTitle.getId())); examTitleDto.setStarCount(starRecordMapper.selectStarCountByRoundExamTitleId(analysisRoundExamTitle.getId()));
examTitleDto.setReplyCount(replyMapper.selectReplyCountByAnalysisRoundExamTitleId(analysisRoundExamTitle.getId())); examTitleDto.setReplyCount(replyMapper.selectReplyCountByAnalysisRoundExamTitleId(analysisRoundExamTitle.getId()));
...@@ -192,7 +225,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -192,7 +225,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
@Override @Override
public List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId) { public List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId) {
List<Reply> replyList = replyMapper.selectReplyListByAnalysisRoundExamTitleId(analysisRoundExamTitleId); List<Reply> replyList = getReplyList(analysisRoundExamTitleId);
List<ReplyDto> replyDtoList = new ArrayList<>(); List<ReplyDto> replyDtoList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
...@@ -216,6 +249,31 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -216,6 +249,31 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectByPrimaryKey(replyId); return replyMapper.selectByPrimaryKey(replyId);
} }
@Override
public Reply getNextReplyById(Integer replyId) {
Reply reply = replyMapper.selectByPrimaryKey(replyId);
/**
* 1. 找到该题目下的回复列表,默认是按照点赞排序的
*/
List<Reply> replyList = getReplyList(reply.getAnalysisRoundExamTitleId());
/**
* 2. 找到当前回复的所在位置,返回下一个回复
*/
int replyCount = replyList.size();
int idx = 0;
for (int i = 0; i< replyCount; ++ i) {
if (replyList.get(i).getId().intValue() == reply.getId().intValue()) {
idx = i;
break;
}
}
idx = ((idx + 1) % replyCount);
return replyList.get(idx);
}
@Override @Override
public ReplyDto getReplyDtoByReply(Reply reply, Integer userId) { public ReplyDto getReplyDtoByReply(Reply reply, Integer userId) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
...@@ -314,4 +372,121 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -314,4 +372,121 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return 0; return 0;
} }
@Override
public ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId) {
List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
Integer examTitleCount = roundExamTitleList.size();
Integer idx = 0;
for (int i = 0; i < examTitleCount; ++ i) {
if (roundExamTitleList.get(i).getId().intValue() == analysisRoundExamTitleId.intValue()) {
idx = i;
break;
}
}
idx = ((idx + 1) % examTitleCount);
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) {
/**
* 用户不存在
*/
if (userId == 0) {
return 0;
}
Reply reply = new Reply();
reply.setAnalysisRoundExamTitleId(examTitleId);
reply.setUserId(userId);
Integer myReplyCount = replyMapper.selectReplyCountByRecord(reply);
if (myReplyCount == 0) {
/**
* 未回复过
*/
return 1;
}
/**
* 已回复过
*/
return 2;
}
@Override
public Reply getReplyByExamTitleId(Integer examTitleId, Integer userId) {
Reply reply = new Reply();
reply.setAnalysisRoundExamTitleId(examTitleId);
reply.setUserId(userId);
return replyMapper.selectReplyByRecord(reply);
}
@Override
public List<Reply> getReplyList(Integer examTitleId) {
Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId);
/**
* case 1. 按照时间排序,如果个数小于5,直接返回
*/
List<Reply> replyList = replyMapper.selectReplyListOrderByTime(examTitleId);
if (replyCount < 5) {
return replyList;
}
/**
* case 2.大于等于5的时候,根据排序 5最热+ 时间排序
*/
List<Reply> replyListFive = replyMapper.selectFiveHottestReplyList(examTitleId);
List<Reply> replyListOther = new ArrayList<>();
replyListOther.addAll(replyListFive);
for (Reply reply : replyList) {
if (!replyListFive.contains(reply))
replyListOther.add(reply);
}
return replyListOther;
}
} }
package com.pica.cloud.online.exam.analysis.server.service.impl;
import com.pica.cloud.online.exam.analysis.server.mapper.CHCRankingListMapper;
import com.pica.cloud.online.exam.analysis.server.service.CHCRankingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author wuminghao
* @date 2018/8/28 13:57
*/
@Service
public class CHCRankingListServiceImpl implements CHCRankingListService {
@Autowired
CHCRankingListMapper rankingListMapper;
@Override
public boolean isRankingInTop200(Integer doctorId) {
return rankingListMapper.selectRecordExistTop200(doctorId) > 0;
}
}
...@@ -19,4 +19,10 @@ public class DoctorServiceImpl implements DoctorService { ...@@ -19,4 +19,10 @@ public class DoctorServiceImpl implements DoctorService {
public Doctor getDoctorById(Integer doctorId) { public Doctor getDoctorById(Integer doctorId) {
return doctorMapper.selectByPrimaryKey(doctorId); return doctorMapper.selectByPrimaryKey(doctorId);
} }
@Override
public boolean isAuth(Integer doctorId) {
return doctorMapper.selectAuthByDoctorId(doctorId) > 0 ||
doctorMapper.selectPatientCountByDoctorId(doctorId) >= 100;
}
} }
package com.pica.cloud.online.exam.analysis.server.utils;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* @author wuminghao
* @date 2018/8/23 15:44
*/
public class HttpClient4Utils {
/**
* 实例化HttpClient
* @param maxTotal
* @param maxPerRoute
* @param socketTimeout
* @param connectTimeout
* @param connectionRequestTimeout
* @return
*/
public static HttpClient createHttpClient(int maxTotal, int maxPerRoute, int socketTimeout, int connectTimeout,
int connectionRequestTimeout) {
RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout).setConnectionRequestTimeout(connectionRequestTimeout).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(maxTotal);
cm.setDefaultMaxPerRoute(maxPerRoute);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm)
.setDefaultRequestConfig(defaultRequestConfig).build();
return httpClient;
}
/**
* 发送post请求
* @param httpClient
* @param url 请求地址
* @param params 请求参数
* @param encoding 编码
* @return
*/
public static String sendPost(HttpClient httpClient, String url, Map<String, String> params, Charset encoding) {
String resp = "";
HttpPost httpPost = new HttpPost(url);
if (params != null && params.size() > 0) {
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
Iterator<Map.Entry<String, String>> itr = params.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, String> entry = itr.next();
formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formParams, encoding);
httpPost.setEntity(postEntity);
}
CloseableHttpResponse response = null;
try {
response = (CloseableHttpResponse) httpClient.execute(httpPost);
resp = EntityUtils.toString(response.getEntity(), encoding);
} catch (Exception e) {
// log
e.printStackTrace();
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
// log
e.printStackTrace();
}
}
}
return resp;
}
}
package com.pica.cloud.online.exam.analysis.server.utils;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Map;
/**
* @author wuminghao
* @date 2018/8/23 15:45
*/
public class SignatureUtils {
/**
* 生成签名信息
* @param secretKey 产品私钥
* @param params 接口请求参数名和参数值map,不包括signature参数名
* @return
* @throws UnsupportedEncodingException
*/
public static String genSignature(String secretKey, Map<String, String> params) throws UnsupportedEncodingException {
// 1. 参数名按照ASCII码表升序排序
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
// 2. 按照排序拼接参数名与参数值
StringBuffer paramBuffer = new StringBuffer();
for (String key : keys) {
paramBuffer.append(key).append(params.get(key) == null ? "" : params.get(key));
}
// 3. 将secretKey拼接到最后
paramBuffer.append(secretKey);
// 4. MD5是128位长度的摘要算法,用16进制表示,一个十六进制的字符能表示4个位,所以签名后的字符串长度固定为32个十六进制字符。
return DigestUtils.md5Hex(paramBuffer.toString().getBytes("UTF-8"));
}
}
...@@ -31,7 +31,27 @@ ...@@ -31,7 +31,27 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from p_chc_analysis from p_chc_analysis
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
and is_deleted = 0
</select> </select>
<select id="selectCHCByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<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 id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_chc_analysis delete from p_chc_analysis
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
......
<?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.pica.cloud.online.exam.analysis.server.mapper.CHCRankingListMapper" >
<resultMap id="BaseResultMap" type="com.pica.cloud.online.exam.analysis.server.entity.CHCRankingList" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="doctor_id" property="doctorId" jdbcType="INTEGER" />
<result column="doctor_name" property="doctorName" jdbcType="VARCHAR" />
</resultMap>
<select id="selectRecordExistTop200" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
select
count(1)
from pica.t_chc_ranking_list
where doctor_id = #{doctorId,jdbcType=INTEGER}
and delete_flag = 1
and ranking_type = 5
and seq_no &lt; 201
</select>
</mapper>
\ No newline at end of file
...@@ -18,4 +18,20 @@ ...@@ -18,4 +18,20 @@
limit 1 limit 1
</select> </select>
<select id="selectAuthByDoctorId" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
select
count(1)
from pica.p_doctor
where id = #{doctorId,jdbcType=INTEGER}
and delete_flag = 1
and (title_id in (101, 401) or administer_title_id in (101,102,103,104,105,106))
</select>
<select id="selectPatientCountByDoctorId" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
select
count(1)
from pica.p_doc_pat_mapping
where doctor_id = #{doctorId,jdbcType=INTEGER}
and delete_flag = 1
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -36,6 +36,24 @@ ...@@ -36,6 +36,24 @@
and is_deleted = 0 and is_deleted = 0
</select> </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 id="selectReplyListByAnalysisRoundExamTitleId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
...@@ -45,6 +63,25 @@ ...@@ -45,6 +63,25 @@
order by star_count desc, seq_no asc order by star_count desc, seq_no asc
</select> </select>
<select id="selectReplyListOrderByTime" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and is_deleted = 0
order by modified_time desc, seq_no asc
</select>
<select id="selectFiveHottestReplyList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id = #{analysisRoundExamTitleId,jdbcType=INTEGER}
and is_deleted = 0
order by star_count desc, modified_time desc
limit 5
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_reply delete from p_reply
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册