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

Merge branch 'release' into 'master'

Release



See merge request !1
流水线 #3974 已通过 于阶段
in 7 second
package com.pica.cloud.online.exam.analysis.common;
import com.alibaba.fastjson.JSON;
import com.pica.cloud.foundation.redis.RedisClient;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -25,14 +24,4 @@ public class CommonUtils {
}
return JSON.parseObject(JSON.toJSONString(map), PicaUser.class);
}
public static PicaUser getUserByToken(RedisClient client, String token) {
PicaUser picaUser = null;
try {
picaUser = CommonUtils.getUser(client.getToken(token));
} catch (Exception e) {
logger.error("根据token获取user失败:" + token);
}
return picaUser;
}
}
......@@ -12,7 +12,7 @@
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId>
<version>1.0.7-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
......
......@@ -101,17 +101,15 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-redis</artifactId>
<version>1.1.2</version>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId>
<version>1.0.7-SNAPSHOT</version>
<artifactId>pica-cloud-redis</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -138,10 +136,6 @@
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
......@@ -154,11 +148,6 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId>
<version>1.0.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.dianping.cat</groupId>
<artifactId>cat-core</artifactId>
......
......@@ -9,10 +9,10 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCircuitBreaker
@SpringBootApplication
@SpringBootApplication(scanBasePackages = "com.pica.cloud")
@EnableDiscoveryClient
@EnableSwagger2
@EnableFeignClients
@EnableFeignClients(basePackages = "com.pica.cloud")
@MapperScan("com.pica.cloud.online.exam.analysis.server.mapper")
public class App {
public static void main( String[] args )
......
package com.pica.cloud.online.exam.analysis.server.configuration;
import com.pica.cloud.foundation.redis.CacheMigrateClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.pica.cloud.foundation.redis.RedisClient;
@Configuration
@RefreshScope
public class BeanConfiguration {
@Autowired
private SpringContextAware springContextAware;
@Value("${spring.redis.config}")
private String configStr;
@Bean
public RedisClient redisClient() {
System.out.println(configStr);
@ConditionalOnMissingBean
public ICacheClient cacheClient() {
return new CacheMigrateClient(springContextAware.getActiveProfile());
return new RedisClient(configStr);
}
}
package com.pica.cloud.online.exam.analysis.server.configuration;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @author wuminghao
* @date 2018/12/27 14:11
*/
@Component
public class SpringContextAware implements ApplicationContextAware {
private ApplicationContext context = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.context = applicationContext;
}
public String getActiveProfile() {
return context.getEnvironment().getActiveProfiles()[0];
}
}
package com.pica.cloud.online.exam.analysis.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Transaction;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.RedisClient;
import com.pica.cloud.foundation.utils.annotation.LoginPermission;
import com.pica.cloud.foundation.utils.controller.BaseController;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.online.exam.analysis.common.CommonUtils;
import com.pica.cloud.online.exam.analysis.common.constants.CommonConstants;
import com.pica.cloud.online.exam.analysis.common.dto.*;
import com.pica.cloud.online.exam.analysis.common.util.ReturnUtil;
import com.pica.cloud.online.exam.analysis.server.client.IConfigServiceClient;
import com.pica.cloud.online.exam.analysis.server.configuration.PropertiesConfiguration;
import com.pica.cloud.online.exam.analysis.server.entity.*;
import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService;
import com.pica.cloud.online.exam.analysis.server.service.CHCAnalysisService;
import com.pica.cloud.online.exam.analysis.server.service.CHCRankingListService;
import com.pica.cloud.online.exam.analysis.server.service.DoctorService;
import com.pica.cloud.online.exam.analysis.server.utils.DateUtils;
import io.swagger.annotations.Api;
import com.pica.cloud.foundation.redis.ICacheClient;
import io.swagger.annotations.ApiOperation;
import javassist.bytecode.ExceptionsAttribute;
import org.omg.CORBA.INTERNAL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* @author wuminghao
......@@ -40,778 +26,169 @@ import java.util.List;
*/
@RestController
@RequestMapping("/")
@Api(value = "题目分析接口", description = "查看活动及详情,用户点赞、医生回复")
public class AnalysisController {
private static Logger logger = LoggerFactory.getLogger(AnalysisController.class);
@Autowired
private RedisClient redisClient;
@Autowired
private LoadBalancerClient slb;
public class AnalysisController extends BaseController {
@Qualifier("cacheMigrateClient")
@Autowired
private IConfigServiceClient client;
private ICacheClient redisClient;
@Autowired
private CHCAnalysisService analysisService;
@Autowired
private DoctorService doctorService;
@Autowired
private AntiSpamService antiSpamService;
@Autowired
private CHCRankingListService rankingListService;
@Autowired
private PropertiesConfiguration propertiesConfiguration;
/**
* TODO: chc错题解析活动和psa的活动id 需要前端传入
*/
static final Integer CHC_ANALYSIS_ID = 1;
static final Integer PSA_ANALYSIS_ID = 2;
@ApiOperation(value = "获取活动详情", response = PicaResponse.class)
@RequestMapping(value = "/config", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String config() {
return propertiesConfiguration.toString();
}
@ApiOperation(value = "获取活动详情", response = PicaResponse.class)
@RequestMapping(value = "/activityDetail", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<CHCAnalysisDto> getActivityDetail(@RequestParam(required = false) Integer id,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/activityDetail");
@RequestMapping(value = {"/activityDetail", "/activityDetail/{id}"}, method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<CHCAnalysisDto> getActivityDetail(@PathVariable(required = false) Integer id) {
PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>();
/**
* 如果不传活动id进来,活动id就用1
*/
id = (id == null ? CHC_ANALYSIS_ID : id);
try {
CHCAnalysisDto analysisDto = analysisService.getCHCAnalysisDtoById(id);
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
if (rankingListService.isRankingInTop200(user != null ? user.getId() : 0)) {
analysisDto.setIsJoinIn(1);
} else {
analysisDto.setIsJoinIn(0);
}
List<AnalysisRoundDto> roundList = analysisService.getRoundListByAnalysisId(id);
/**
* chc活动固定返回两轮, 将第一轮设置为所有
*/
if (roundList.size() > 0) {
roundList.get(0).setRoundId(-1);
}
/**
* 如果是最后一起, 补上最后一期 和前端约定为-2
*/
if (roundList.size() == 1) {
AnalysisRoundDto analysisRoundDto = new AnalysisRoundDto();
analysisRoundDto.setRoundId(-2);
roundList.add(analysisRoundDto);
}
analysisDto.setRoundList(roundList);
builder.setData(analysisDto);
t.setStatus(Transaction.SUCCESS);
try {
user = fetchPicaUser();
} catch (Exception e) {
logger.error("getActivityDetail", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getCHCActivityDetail(id == null ? CHC_ANALYSIS_ID : id, user));
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) {
Transaction t = Cat.newTransaction("Link", "/psaActivityDetail");
PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>();
/**
* 如果不传活动id进来,活动id就用1
*/
id = (id == null ? PSA_ANALYSIS_ID : id);
try {
CHCAnalysisDto analysisDto = analysisService.getPSAAnalysisDtoById(id);
List<AnalysisRoundDto> roundList = analysisService.getRoundListByAnalysisId(id);
analysisDto.setRoundList(roundList);
builder.setData(analysisDto);
t.setStatus(Transaction.SUCCESS);
} catch (Exception e) {
logger.error("getPSAActivityDetail", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getPSAActivityDetail(id == null ? PSA_ANALYSIS_ID : id));
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) {
Transaction t = Cat.newTransaction("Link", "/roundDetail");
logger.info("roundDetail: roundId" + roundId);
PicaResponse.Builder<RoundExamTitleDto> builder = new PicaResponse.Builder<>();
builder.setData(analysisService.getRoundDetail(roundId));
return builder.build();
}
@RequestMapping(value = "/replyList/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> getReplyList(@PathVariable("examTitleId") Integer examTitleId) {
PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
RoundExamTitleDto roundExamTitleDto = analysisService.getRoundExamTitleDtoById(roundId);
List<ExamTitleDto> examTitleDtoList = analysisService.getExamTitleListByRoundId(roundId);
roundExamTitleDto.setExamTitleList(examTitleDtoList);
builder.setData(roundExamTitleDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("getRoundDetail", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getReplyListByExamTitleId(examTitleId, user));
return builder.build();
}
@ApiOperation(value = "获取某一道题目的回复列表", response = PicaResponse.class)
@RequestMapping(value = "/replyList/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@RequestMapping(value = "/replyList/v2/{examTitleId}/page/{pageNo}/size/{pageSize}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> getReplyList(@PathVariable("examTitleId") Integer examTitleId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/replyList");
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
@PathVariable("pageNo") Integer pageNo,
@PathVariable("pageSize") Integer pageSize) {
PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(examTitleId);
ExamTitleReplyDto examTitleReplyDto = new ExamTitleReplyDto();
ExamTitleDto examTitleDto = analysisService.getExamTitleDtoById(examTitleId);
List<ReplyDto> replyDtoList = analysisService.getReplyListDtoByExamTitleId(examTitleId, user != null ? user.getId() : 0);
/**
* TODO: 如果是PSA 删除时间显示
*/
if (analysisRoundExamTitle.getAnalysisId().intValue() == PSA_ANALYSIS_ID ) {
for (ReplyDto replyDto : replyDtoList) {
replyDto.setReplayTime("");
}
}
examTitleReplyDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setExamTitle(examTitleDto);
examTitleReplyDto.setReplyList(replyDtoList);
AnalysisRound analysisRound = analysisService.getRoundInfoById(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
/**
* 设置回复状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
examTitleReplyDto.setReplyStatus(0);
} else {
examTitleReplyDto.setReplyStatus(0);
if (user != null && user.getId() != 0) {
examTitleReplyDto.setReplyStatus(getReplyStatus(analysisRoundExamTitle.getAnalysisId(),
examTitleId, user.getId()));
}
}
/**
* 设置类型
*/
CHCAnalysis analysis = analysisService.getAnalysisById(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setType(analysis.getType().intValue());
builder.setData(examTitleReplyDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("getReplyList", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getReplyListV2ByExamTitleId(examTitleId, pageNo, pageSize, user));
return builder.build();
}
@ApiOperation(value = "查看回复详情", response = PicaResponse.class)
@RequestMapping(value = "/replyDetail/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetail(@PathVariable("replyId") Integer replyId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/replyDetail");
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetail(@PathVariable("replyId") Integer replyId) {
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto();
Reply reply = analysisService.getReplyById(replyId);
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(reply.getAnalysisRoundExamTitleId());
ExamTitleDto examTitleDto = analysisService.getExamTitleDtoById(reply.getAnalysisRoundExamTitleId());
ReplyDto replyDto = analysisService.getReplyDtoByReply(reply, user != null ? user.getId() : 0);
examTitleReplyDetailDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setExamTitle(examTitleDto);
examTitleReplyDetailDto.setReply(replyDto);
AnalysisRound analysisRound = analysisService.getRoundInfoById(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
/**
* 设置回复状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
examTitleReplyDetailDto.setReplyStatus(0);
} else {
examTitleReplyDetailDto.setReplyStatus(0);
if (user != null && user.getId() != 0) {
examTitleReplyDetailDto.setReplyStatus(getReplyStatus(analysisRoundExamTitle.getAnalysisId(),
reply.getAnalysisRoundExamTitleId(), user.getId()));
}
}
/**
* 设置类型
*/
CHCAnalysis analysis = analysisService.getAnalysisById(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setType(analysis.getType().intValue());
builder.setData(examTitleReplyDetailDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("getReplyDetail", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getReplyDetailByReplyId(replyId, user));
return builder.build();
}
@ApiOperation(value = "查看回复详情", response = PicaResponse.class)
@RequestMapping(value = "/replyDetailByExamTitleId/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetailByExamTitleId(@PathVariable("examTitleId") Integer examTitleId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/replyDetailByExamTitleId");
logger.info("replyDetailByExamTitleId: examTitleId == " + examTitleId.toString() + ", token=" + token);
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetailByExamTitleId(@PathVariable("examTitleId") Integer examTitleId) {
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto();
Reply reply = analysisService.getReplyByExamTitleId(examTitleId, user != null ? user.getId() : 0);
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(examTitleId);
ExamTitleDto examTitleDto = analysisService.getExamTitleDtoById(examTitleId);
ReplyDto replyDto = new ReplyDto();
if (null != reply) {
replyDto = analysisService.getReplyDtoByReply(reply, user != null ? user.getId() : 0);
} else {
replyDto.setContent("");
}
examTitleReplyDetailDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setExamTitle(examTitleDto);
examTitleReplyDetailDto.setReply(replyDto);
AnalysisRound analysisRound = analysisService.getRoundInfoById(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
/**
* 设置回复状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
examTitleReplyDetailDto.setReplyStatus(0);
} else {
examTitleReplyDetailDto.setReplyStatus(0);
if (user != null && user.getId() != 0 && reply != null) {
examTitleReplyDetailDto.setReplyStatus(getReplyStatus(analysisRoundExamTitle.getAnalysisId(),
reply.getAnalysisRoundExamTitleId(), user.getId()));
}
}
/**
* 设置类型
*/
CHCAnalysis analysis = analysisService.getAnalysisById(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setType(analysis.getType().intValue());
builder.setData(examTitleReplyDetailDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("getReplyDetailByExamTitleId", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getReplyDetailByExamTitleId(examTitleId, user));
return builder.build();
}
@ApiOperation(value = "点赞", response = PicaResponse.class)
@LoginPermission
@RequestMapping(value = "/starReply/{replyId}/analysis/{analysisId}/round/{roundId}/examTitle/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse starReply(@PathVariable("analysisId") Integer analysisId, @PathVariable("roundId") Integer roundId,
@PathVariable("examTitleId") Integer examTitleId, @PathVariable("replyId") Integer replyId,
@RequestHeader(required = false) String token) {
if (token == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
}
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
logger.info("starrecord: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
Doctor doctor = doctorService.getDoctorById(user.getId());
if (doctor == null) {
logger.info("starrecord: doctor == null, userid=" + user.getId().toString());
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_INVALID_TOKEN);
}
/**
* 未认证用户直接返回
*/
if (!(doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_3) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_6) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_7) )) {
return ReturnUtil.getPicaResponse(PicaResultCode.INTERFACE_FORBID_VISIT);
}
logger.info("starrecord: replyid=" + replyId.toString() + " token=" + token + " roundId=" + roundId + " examTitleId=" + examTitleId);
AnalysisRound analysisRound = analysisService.getRoundInfoById(roundId);
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
return ReturnUtil.getPicaResponse("500002", "本期活动已结束");
public PicaResponse starReply(@PathVariable("analysisId") Integer analysisId,
@PathVariable("roundId") Integer roundId,
@PathVariable("examTitleId") Integer examTitleId,
@PathVariable("replyId") Integer replyId) {
return analysisService.starReply(fetchPicaUser(), analysisId, roundId, examTitleId, replyId);
}
if (0 != analysisService.insertStarRecord(analysisId, roundId, examTitleId, replyId, user.getId())) {
/**
* 已经点过赞
*/
return ReturnUtil.getPicaResponse(PicaResultCode.DATA_ALREADY_EXISTED);
}
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
@ApiOperation(value = "取消点赞", response = PicaResponse.class)
@LoginPermission
@RequestMapping(value = "/cancelStar/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse cancelStar( @PathVariable("replyId") Integer replyId,
@RequestHeader(required = false) String token) {
if (token == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
}
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
logger.info("cancelStar: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
logger.info("cancelStar: replyid=" + replyId.toString() + " token=" + token);
if (0 != analysisService.removeStarRecord(replyId, user.getId())) {
if (0 != analysisService.removeStarRecord(replyId, fetchPicaUser())) {
return ReturnUtil.getPicaResponse(PicaResultCode.RESULE_DATA_NONE);
}
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
@ApiOperation(value = "获取某一道题目的下一道题", response = PicaResponse.class)
@RequestMapping(value = "/nextExamTitle/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> nextReplyList(@PathVariable("examTitleId") Integer examTitleId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/nextExamTitle");
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
public PicaResponse<ExamTitleReplyDto> nextReplyList(@PathVariable("examTitleId") Integer examTitleId) {
PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(examTitleId);
ExamTitleReplyDto examTitleReplyDto = new ExamTitleReplyDto();
ExamTitleDto examTitleDto = analysisService.getNextExamTitleDtoById(analysisRoundExamTitle.getRoundId(), examTitleId);
List<ReplyDto> replyDtoList = analysisService.getReplyListDtoByExamTitleId(examTitleDto.getExamTitleId(), user != null ? user.getId() : 0);
examTitleReplyDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setExamTitle(examTitleDto);
examTitleReplyDto.setReplyList(replyDtoList);
AnalysisRound analysisRound = analysisService.getRoundInfoById(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
/**
* 设置回复状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
examTitleReplyDto.setReplyStatus(0);
} else {
examTitleReplyDto.setReplyStatus(0);
if (user != null && user.getId() != 0) {
examTitleReplyDto.setReplyStatus(getReplyStatus(analysisRoundExamTitle.getAnalysisId(),
examTitleId, user.getId()));
}
}
/**
* 设置类型
*/
CHCAnalysis analysis = analysisService.getAnalysisById(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setType(analysis.getType().intValue());
builder.setData(examTitleReplyDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("nextReplyList", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getNextReplyListByExamTitleId(examTitleId, user));
return builder.build();
}
@ApiOperation(value = "获取某一道题目的下一道题", response = PicaResponse.class)
@RequestMapping(value = "/nextReply/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> nextReplyDetail(@PathVariable("replyId") Integer replyId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/nextReply");
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
public PicaResponse<ExamTitleReplyDetailDto> nextReplyDetail(@PathVariable("replyId") Integer replyId) {
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto();
Reply reply = analysisService.getNextReplyById(replyId);
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(reply.getAnalysisRoundExamTitleId());
ExamTitleDto examTitleDto = analysisService.getExamTitleDtoById(reply.getAnalysisRoundExamTitleId());
ReplyDto replyDto = analysisService.getReplyDtoByReply(reply, user != null ? user.getId() : 0);
examTitleReplyDetailDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setExamTitle(examTitleDto);
examTitleReplyDetailDto.setReply(replyDto);
AnalysisRound analysisRound = analysisService.getRoundInfoById(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
/**
* 设置回复状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
examTitleReplyDetailDto.setReplyStatus(0);
} else {
examTitleReplyDetailDto.setReplyStatus(0);
if (user != null && user.getId() != 0) {
examTitleReplyDetailDto.setReplyStatus(getReplyStatus(analysisRoundExamTitle.getAnalysisId(),
reply.getAnalysisRoundExamTitleId(), user.getId()));
}
}
/**
* 设置类型
*/
CHCAnalysis analysis = analysisService.getAnalysisById(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setType(analysis.getType().intValue());
builder.setData(examTitleReplyDetailDto);
t.setStatus(Transaction.SUCCESS);
user = fetchPicaUser();
} catch (Exception e) {
logger.error("nextReplyDetail", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getNextReplyDetailByReplyId(replyId, user));
return builder.build();
}
@ApiOperation(value = "回复", response = PicaResponse.class)
@LoginPermission
@RequestMapping(value = "/reply/{examTitleId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse reply( @PathVariable("examTitleId") Integer examTitleId,
@RequestBody String content,
@RequestHeader String sysCode,
@RequestHeader String token) {
Transaction t = Cat.newTransaction("Link", "/nextReply");
if (token == null) {
PicaResponse picaResponse = ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
picaResponse.setData("");
return picaResponse;
}
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
logger.info("reply: user == null, token=" + token);
PicaResponse picaResponse = ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
picaResponse.setData("");
return picaResponse;
}
try {
@RequestHeader String sysCode) {
JSONObject jsonObject = JSONObject.parseObject(content);
content = jsonObject.get("content").toString();
} catch (Exception e) {
logger.info("parse error: " + content);
}
/**
* 如果判断检测的数据中有垃圾 直接返回
*/
PicaResponse response = antiSpamService.processString(user.getId(), sysCode, content, false);
if (!response.getCode().equals(PicaResultCode.SUCCESS.code())) {
response.setData("");
return response;
}
/**
* 插入数据库
*/
try {
analysisService.insertReply(examTitleId, content, user.getId());
t.setStatus(Transaction.SUCCESS);
t.complete();
} catch (Exception e) {
t.setStatus(e);
Cat.logError(e);
t.complete();
PicaResponse picaResponse = ReturnUtil.getPicaResponse(PicaResultCode.INTERFACE_INVOKE_EXCEPTION);
picaResponse.setData("");
return picaResponse;
}
PicaResponse picaResponse = ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
picaResponse.setMessage("发布成功");
return picaResponse;
}
Integer getReplyStatus(Integer analysisId, Integer examTitleId, Integer userId) {
Doctor doctor = doctorService.getDoctorById(userId);
if (doctor != null) {
CHCAnalysis analysis = analysisService.getAnalysisById(analysisId);
if (analysis.getType() == 1) {
/**
* CHC 获取考试前两百名
*/
if (rankingListService.isRankingInTop200(doctor.getId())) {
return analysisService.getReplyStatus(examTitleId, userId);
}
} else if (analysis.getType() == 2) {
/**
* 如果为认证 不可见
*/
if (!(doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_3) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_6) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_7) )) {
return 0;
}
/**
* PSA 职务职称主任/副主任 院长/副院长 科长/副科长 管理人数100以上
*/
if (doctorService.isAuth(doctor.getId())) {
return analysisService.getReplyStatus(examTitleId, userId);
}
}
}
return 0;
return analysisService.reply(fetchPicaUser(), sysCode, examTitleId, content,false);
}
@ApiOperation(value = "获取某一轮的题目V2", response = PicaResponse.class)
@RequestMapping(value = "/roundDetail/v2/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<RoundExamTitleV2Dto> getRoundDetailV2(@PathVariable(value = "roundId") Integer roundId) {
Transaction t = Cat.newTransaction("Link", "/roundDetail/v2/");
logger.info("roundDetail: roundId" + roundId);
PicaResponse.Builder<RoundExamTitleV2Dto> builder = new PicaResponse.Builder<>();
try {
RoundExamTitleV2Dto roundExamTitleV2Dto = new RoundExamTitleV2Dto();
if (roundId > 0) {
/**
* 有rounfid传入时设置roundList为空
*/
roundExamTitleV2Dto.setRoundList(new ArrayList<>());
} else {
List<AnalysisRoundDto> roundDtoList = analysisService.getCHCHistoryRound(CHC_ANALYSIS_ID);
/**
* 获取list中最后一个的roundId
*/
if (roundDtoList.size() > 0) {
roundId = roundDtoList.get(roundDtoList.size() - 1).getRoundId();
}
roundExamTitleV2Dto.setRoundList(roundDtoList);
}
RoundExamTitleDto roundExamTitleDto = analysisService.getRoundExamTitleDtoById(roundId);
/**
* 转换格式
*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-M-d");
roundExamTitleV2Dto.setAnalysisId(roundExamTitleDto.getAnalysisId());
roundExamTitleV2Dto.setRoundId(roundExamTitleDto.getRoundId());
roundExamTitleV2Dto.setStartTime(outFormat.format(sdf.parse(roundExamTitleDto.getStartTime())));
roundExamTitleV2Dto.setEndTime(outFormat.format(sdf.parse(roundExamTitleDto.getEndTime())));
roundExamTitleV2Dto.setTotalCount(roundExamTitleDto.getTotalCount());
roundExamTitleV2Dto.setPublished(roundExamTitleDto.getPublished());
if ((new Date()).getTime() > sdf.parse(roundExamTitleDto.getEndTime()).getTime()) {
roundExamTitleV2Dto.setRemainingTime("");
roundExamTitleV2Dto.setIsFinished(1);
roundExamTitleV2Dto.setElectedStarCount(analysisService.getElectedStarCountByRoundId(roundId));
Integer doctorId = analysisService.getElectedDoctorIdByRoundId(roundId);
roundExamTitleV2Dto.setElectedDoctor(doctorId != null ? doctorService.getDoctorDtoById(doctorId) : new DoctorDto() );
} else {
roundExamTitleV2Dto.setRemainingTime(DateUtils.remainingTime(sdf.parse(roundExamTitleDto.getEndTime())));
roundExamTitleV2Dto.setIsFinished(0);
roundExamTitleV2Dto.setElectedDoctor(new DoctorDto());
}
List<ExamTitleDto> examTitleDtoList = analysisService.getExamTitleListByRoundId(roundId);
roundExamTitleV2Dto.setExamTitleList(examTitleDtoList);
builder.setData(roundExamTitleV2Dto);
t.setStatus(Transaction.SUCCESS);
} catch (Exception e) {
logger.error("getRoundDetailV2", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.getRoundDetailV2(roundId));
return builder.build();
}
@LoginPermission
@ApiOperation(value = "我的赞", response = PicaResponse.class)
@RequestMapping(value = {"/myStar/{roundId}","/myStar/"}, method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<MyStarDto> myStar( @PathVariable(value = "roundId", required = false) Integer roundId,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/roundDetail/v2/");
if (token == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
}
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
logger.info("myStar: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
if (roundId != null) {
logger.info("myStar: roundId=" + roundId.toString() + " token=" + token);
}
public PicaResponse<MyStarDto> myStar( @PathVariable(value = "roundId", required = false) Integer roundId) {
PicaResponse.Builder<MyStarDto> builder = new PicaResponse.Builder<>();
try {
MyStarDto myStarDto = new MyStarDto();
myStarDto.setDoctor(doctorService.getDoctorDtoById(user.getId()));
myStarDto.setRoundList(new ArrayList<>());
if (roundId == null) {
List<AnalysisRoundDto> roundDtoList = analysisService.getCHCHistoryRound(CHC_ANALYSIS_ID);
roundId = roundDtoList.get(0).getRoundId();
myStarDto.setRoundList(roundDtoList);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d");
AnalysisRound analysisRound = analysisService.getRoundInfoById(roundId);
myStarDto.setStartTime(sdf.format(analysisRound.getStartTime()));
myStarDto.setEndTime(sdf.format(analysisRound.getEndTime()));
myStarDto.setRemainingTime(DateUtils.remainingTime(analysisRound.getEndTime()));
/**
* 设置结束状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
myStarDto.setIsFinished(1);
/**
* 设置我是否当选
*/
Integer electedDoctorId = analysisService.getElectedDoctorIdByRoundId(roundId);
myStarDto.setIsElected(electedDoctorId.intValue() == user.getId().intValue() ? 1 : 0);
} else {
myStarDto.setIsFinished(0);
myStarDto.setIsElected(0);
}
/**
* 设置我的得赞数
*/
myStarDto.setMyStarCount(analysisService.getStarCountByRoundIdAndDoctorId(roundId, user.getId()));
/**
* 我的解析得赞记录
*/
myStarDto.setMyExamTitleList(analysisService.getMyStarRecordByRoundIdAndDoctorId(roundId, user.getId()));
builder.setData(myStarDto);
t.setStatus(Transaction.SUCCESS);
} catch (Exception e) {
logger.error("myStar", e);
t.setStatus(e);
Cat.logError(e);
}
t.complete();
builder.setData(analysisService.myStar(fetchPicaUser(), Optional.ofNullable(roundId)));
return builder.build();
}
......
......@@ -3,17 +3,16 @@ package com.pica.cloud.online.exam.analysis.server.controller;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.RedisClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.annotation.LoginPermission;
import com.pica.cloud.foundation.utils.controller.BaseController;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.online.exam.analysis.common.CommonUtils;
import com.pica.cloud.online.exam.analysis.common.util.ReturnUtil;
import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
/**
......@@ -22,10 +21,10 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequestMapping("/antispam")
@Api(value = "内容甄别解析", description = "检测文本、图片内容")
public class AntiSpamController {
public class AntiSpamController extends BaseController {
@Qualifier("cacheMigrateClient")
@Autowired
private RedisClient redisClient;
private ICacheClient redisClient;
@Autowired
AntiSpamService antiSpamService;
......@@ -36,33 +35,17 @@ public class AntiSpamController {
public PicaResponse processText(@RequestBody String content,
@RequestHeader String sysCode,
@RequestHeader String token) {
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
StringBuilder sbContent = new StringBuilder();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer type = 0;
PicaUser user = fetchPicaUser();
Pair<String, Integer> params;
try {
JSONObject jsonObject = JSONObject.parseObject(content);
sbContent.append(jsonObject.get("content").toString());
type = (jsonObject.get("type") != null ? Integer.parseInt(jsonObject.get("type").toString()) : 0);
params = parseContentAndType(content);
} catch (Exception e) {
return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID);
}
return antiSpamService.processString(
user.getId(),
sysCode,
sbContent.toString(),
type != 0
);
return antiSpamService.processString(user.getId(), sysCode, params.getLeft(), params.getRight() != 0);
}
@LoginPermission
@ApiOperation(value = "内容检测", response = PicaResponse.class)
@RequestMapping(value = "/text/v1", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processTextV1(@RequestBody String content,
......@@ -71,53 +54,30 @@ public class AntiSpamController {
return processText(content, sysCode, token);
}
@LoginPermission
@ApiOperation(value = "内容检测", response = PicaResponse.class)
@RequestMapping(value = "/text/v2", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processTextV2(@RequestBody String content,
@RequestHeader String sysCode,
@RequestHeader String token) {
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
StringBuilder sbContent = new StringBuilder();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer type = 0;
PicaUser user = fetchPicaUser();
Pair<String, Integer> params;
try {
JSONObject jsonObject = JSONObject.parseObject(content);
sbContent.append(jsonObject.get("content").toString());
type = (jsonObject.get("type") != null ? Integer.parseInt(jsonObject.get("type").toString()) : 0);
params = parseContentAndType(content);
} catch (Exception e) {
return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID);
}
return antiSpamService.processStringV2(
user.getId(),
sysCode,
sbContent.toString(),
type != 0
);
return antiSpamService.processStringV2(user.getId(), sysCode, params.getLeft(), params.getRight() != 0);
}
@LoginPermission
@ApiOperation(value = "图片检测", response = PicaResponse.class)
@RequestMapping(value = "/image", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processImage(@RequestBody String content,
@RequestHeader String sysCode,
@RequestHeader String token) {
if (token == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
}
PicaUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
PicaUser user = fetchPicaUser();
StringBuilder sbContent = new StringBuilder();
try {
JSONObject jsonObject = JSONObject.parseObject(content);
......@@ -132,4 +92,11 @@ public class AntiSpamController {
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
public Pair<String, Integer> parseContentAndType(String content) {
JSONObject jsonObject = JSONObject.parseObject(content);
return Pair.of(jsonObject.get("content").toString(),
jsonObject.get("type") != null ? Integer.parseInt(jsonObject.get("type").toString()) : 0
);
}
}
package com.pica.cloud.online.exam.analysis.server.mapper;
import com.pica.cloud.online.exam.analysis.server.entity.AntiSpamRecord;
import org.springframework.stereotype.Component;
@Component
public interface AntiSpamRecordMapper {
int deleteByPrimaryKey(Integer id);
......
package com.pica.cloud.online.exam.analysis.server.monitor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.dianping.cat.servlet.CatFilter;
@Configuration
public class CatFilterConfigure {
@Bean
public FilterRegistrationBean catFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
CatFilter filter = new CatFilter();
registration.setFilter(filter);
registration.addUrlPatterns("/*");
registration.setName("cat-filter");
registration.setOrder(1);
return registration;
}
}
\ No newline at end of file
package com.pica.cloud.online.exam.analysis.server.service;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.online.exam.analysis.common.dto.*;
import com.pica.cloud.online.exam.analysis.server.entity.AnalysisRound;
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 io.swagger.models.auth.In;
import org.omg.CORBA.INTERNAL;
import java.util.List;
import java.util.Optional;
/**
* @author wuminghao
* @date 2018/8/17 9:40
*/
public interface CHCAnalysisService {
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysis getAnalysisById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* 获取CHC活动详情
* @param analysisId 活动id
* @param user
* @return
*/
CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId);
CHCAnalysisDto getCHCActivityDetail(Integer analysisId, PicaUser user);
/**
* 根据活动id获取活动的轮数
* @param analysisId
* 获取PSA活动详情
* @param analysisId 活动id
* @return
*/
List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId);
CHCAnalysisDto getPSAActivityDetail(Integer analysisId);
/**
* 根据轮的id获取信息
* @param roundId
* 获取轮详情
* @param roundId 轮id
* @return
*/
RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId);
RoundExamTitleDto getRoundDetail(Integer roundId);
/**
* 根据轮的id获取信息
* 获取轮详情V2
* @param roundId
* @return
*/
AnalysisRound getRoundInfoById(Integer roundId);
/**
* 根据轮的id获取题目信息
* @param roundId
* @return
*/
List<ExamTitleDto> getExamTitleListByRoundId(Integer roundId);
/**
* 获取当前的活动-轮-题目关联表
* @param analysisRoundExamTitleId
* @return
*/
AnalysisRoundExamTitle getAnanlysisRoundExamTitleById(Integer analysisRoundExamTitleId);
/**
* 获取考题信息
* @param analysisRoundExamTitleId
* @return
*/
ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId);
/**
* 获取当前题目的下一题目
* @param roundId 当前轮的id
* @param analysisRoundExamTitleId 当前题目的id
* @return 下一题目的id
*/
ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId);
/**
* 根据题目id获取回复信息
* @param analysisRoundExamTitleId
* @param userId
* @return
*/
List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId);
/**
* 根据id获取reply
* @param replyId
* @return
*/
Reply getReplyById(Integer replyId);
RoundExamTitleV2Dto getRoundDetailV2(Integer roundId);
/**
* 根据id获取下一条reply
* @param replyId
* @return
*/
Reply getNextReplyById(Integer replyId);
/**
* 根据reply获取replydto
* @param reply
* @param userId
* @return
*/
ReplyDto getReplyDtoByReply(Reply reply, Integer userId);
/**
* 插入点赞记录
* @param analysisId
* @param roundId
* 获取题目的回复列表
* @param examTitleId
* @param replyId
* @param user
* @return
*/
Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId);
ExamTitleReplyDto getReplyListByExamTitleId(Integer examTitleId, PicaUser user);
/**
* 取消点赞记录
* @param replyId
* @param userId
* 获取题目的回复列表 分页
* @param examTitleId 题目id
* @param pageNo 页码
* @param pageSize 大小
* @param user
* @return
*/
Integer removeStarRecord(Integer replyId, Integer userId);
ExamTitleReplyDto getReplyListV2ByExamTitleId(Integer examTitleId, Integer pageNo, Integer pageSize, PicaUser user);
/**
* 增加解析
* 获取下一题的回复列表
* @param examTitleId
* @param content
* @param userId
* @param user
* @return
*/
Integer insertReply(Integer examTitleId, String content, Integer userId);
/**
* 获取我的评论状态
* @param examTitleId
* @param userId
* @return
*/
Integer getReplyStatus(Integer examTitleId, Integer userId);
ExamTitleReplyDto getNextReplyListByExamTitleId(Integer examTitleId, PicaUser user);
/**
* 获取我的评论详情
* @param examTitleId
* @param userId
* 获取回复的详情
* @param replyId 回复id
* @param user 用户
* @return
*/
Reply getReplyByExamTitleId(Integer examTitleId, Integer userId);
ExamTitleReplyDetailDto getReplyDetailByReplyId(Integer replyId, PicaUser user);
/**
* 根据考试id获取评论列表
* @param examTitleId
* 获取下一回复的详情
* @param replyId
* @param user
* @return
*/
List<Reply> getReplyList(Integer examTitleId);
ExamTitleReplyDetailDto getNextReplyDetailByReplyId(Integer replyId, PicaUser user);
/**
* 获取所有的历史轮详情
* @param ananlysisId
* 获取回复的详情
* @param examTitleId 题目id
* @param user 用户
* @return
*/
List<AnalysisRoundDto> getCHCHistoryRound(Integer analysisId);
ExamTitleReplyDetailDto getReplyDetailByExamTitleId(Integer examTitleId, PicaUser user);
/**
* 获取某一轮的最多得票数
* @param roundId
* 点赞
* @param user 用户
* @param analysisId 活动id
* @param roundId 轮id
* @param examTitleId 题目id
* @param replyId 回复id
* @return
*/
Integer getElectedStarCountByRoundId(Integer roundId);
PicaResponse starReply(PicaUser user, Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId);
/**
* 获取被选中的医生id
* @param roundId
* 解析/回复某一个题目
* @param user 用户
* @param sysCode
* @param examTitleId 题目
* @param content 内容
* @param isAdFilterOpen 广告检测
* @return
*/
Integer getElectedDoctorIdByRoundId(Integer roundId);
PicaResponse reply(PicaUser user, String sysCode, Integer examTitleId, String content, Boolean isAdFilterOpen);
/**
* 根据医生id和轮id获取得赞数
* @param roundId
* @param doctorId
* 获取我的赞
* @param user 用户
* @param roundId 某轮的id
* @return
*/
Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId);
MyStarDto myStar(PicaUser user, Optional<Integer> roundId);
/**
* 根据医生id和轮id获取得赞记录
* @param roundId
* @param doctorId
* 取消点赞
* @param replyId 活动id
* @param user 用户
* @return
*/
List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId);
Integer removeStarRecord(Integer replyId, PicaUser user);
}
......@@ -38,7 +38,7 @@ public class AntiSpamServiceImpl implements AntiSpamService {
@Autowired
private AntiSpamRecordMapper antiSpamRecordMapper;
private static HttpClient httpClient = HttpClient4Utils.createHttpClient(100, 20, 2000, 2000, 2000);
private static HttpClient httpClient = HttpClient4Utils.createHttpClient(200, 200, 2000, 2000, 2000);
private static HttpClient httpClientImage = HttpClient4Utils.createHttpClient(100, 20, 10000, 2000, 2000);
private String neteaseResult(String content, boolean isAdFilterOpen) {
......
package com.pica.cloud.online.exam.analysis.server.service.impl;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.online.exam.analysis.common.constants.CommonConstants;
import com.pica.cloud.online.exam.analysis.common.dto.*;
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.entity.*;
import com.pica.cloud.online.exam.analysis.server.mapper.*;
import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService;
import com.pica.cloud.online.exam.analysis.server.service.CHCAnalysisService;
import com.pica.cloud.online.exam.analysis.server.service.CHCRankingListService;
import com.pica.cloud.online.exam.analysis.server.service.DoctorService;
import com.pica.cloud.online.exam.analysis.server.utils.DateUtils;
import net.bytebuddy.asm.Advice;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -42,16 +51,430 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
@Autowired
DoctorMapper doctorMapper;
@Autowired
CHCRankingListMapper rankingListMapper;
@Autowired
private PropertiesConfiguration properties;
@Autowired
private CHCRankingListService chcRankingListService;
@Autowired
private DoctorService doctorService;
@Autowired
private AntiSpamService antiSpamService;
static final byte ANALYSIS_TYPE_CHC = 1;
static final byte ANALYSIS_TYPE_PSA = 2;
static final int CHC_ANALYSIS_ID = 1;
static final int PSA_ANALYSIS_ID = 2;
/**
* chc 活动详情
* @param analysisId
* @param user
* @return
*/
@Override
public CHCAnalysisDto getCHCActivityDetail(Integer analysisId, PicaUser user) {
CHCAnalysisDto analysisDto = this.getCHCAnalysisDtoById(analysisId);
if (chcRankingListService.isRankingInTop200(user != null ? user.getId() : 0)) {
analysisDto.setIsJoinIn(1);
} else {
analysisDto.setIsJoinIn(0);
}
List<AnalysisRoundDto> roundList = this.getRoundListByAnalysisId(analysisId);
if (analysisId == CHC_ANALYSIS_ID) {
/**
* chc活动固定返回两轮, 将第一轮设置为所有
*/
if (roundList.size() > 0) {
roundList.get(0).setRoundId(-1);
}
/**
* 如果是最后一起, 补上最后一期 和前端约定为-2
*/
if (roundList.size() == 1) {
AnalysisRoundDto analysisRoundDto = new AnalysisRoundDto();
analysisRoundDto.setRoundId(-2);
roundList.add(analysisRoundDto);
}
}
analysisDto.setRoundList(roundList);
return analysisDto;
}
@Override
public CHCAnalysisDto getPSAActivityDetail(Integer analysisId) {
CHCAnalysisDto analysisDto = getPSAAnalysisDtoById(analysisId);
List<AnalysisRoundDto> roundList = getRoundListByAnalysisId(analysisId);
analysisDto.setRoundList(roundList);
return analysisDto;
}
@Override
public RoundExamTitleDto getRoundDetail(Integer roundId) {
RoundExamTitleDto roundExamTitleDto = getRoundExamTitleDtoById(roundId);
List<ExamTitleDto> examTitleDtoList = getExamTitleListByRoundId(roundId);
roundExamTitleDto.setExamTitleList(examTitleDtoList);
return roundExamTitleDto;
}
@Override
public RoundExamTitleV2Dto getRoundDetailV2(Integer roundId) {
RoundExamTitleV2Dto roundExamTitleV2Dto = new RoundExamTitleV2Dto();
/**
* 有rounfid传入时设置roundList为空
*/
if (roundId > 0) {
roundExamTitleV2Dto.setRoundList(new ArrayList<>());
} else {
List<AnalysisRoundDto> roundDtoList = getCHCHistoryRound(CHC_ANALYSIS_ID);
/**
* 获取list中最后一个的roundId
*/
if (roundDtoList.size() > 0) {
roundId = roundDtoList.get(roundDtoList.size() - 1).getRoundId();
}
roundExamTitleV2Dto.setRoundList(roundDtoList);
}
RoundExamTitleDto roundExamTitleDto = getRoundExamTitleDtoById(roundId);
try {
/**
* 转换格式
*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-M-d");
roundExamTitleV2Dto.setAnalysisId(roundExamTitleDto.getAnalysisId());
roundExamTitleV2Dto.setRoundId(roundExamTitleDto.getRoundId());
roundExamTitleV2Dto.setStartTime(outFormat.format(sdf.parse(roundExamTitleDto.getStartTime())));
roundExamTitleV2Dto.setEndTime(outFormat.format(sdf.parse(roundExamTitleDto.getEndTime())));
roundExamTitleV2Dto.setTotalCount(roundExamTitleDto.getTotalCount());
roundExamTitleV2Dto.setPublished(roundExamTitleDto.getPublished());
if ((new Date()).getTime() > sdf.parse(roundExamTitleDto.getEndTime()).getTime()) {
roundExamTitleV2Dto.setRemainingTime("");
roundExamTitleV2Dto.setIsFinished(1);
roundExamTitleV2Dto.setElectedStarCount(getElectedStarCountByRoundId(roundId));
Integer doctorId = getElectedDoctorIdByRoundId(roundId);
roundExamTitleV2Dto.setElectedDoctor(doctorId != null ? doctorService.getDoctorDtoById(doctorId) : new DoctorDto());
} else {
roundExamTitleV2Dto.setRemainingTime(DateUtils.remainingTime(sdf.parse(roundExamTitleDto.getEndTime())));
roundExamTitleV2Dto.setIsFinished(0);
roundExamTitleV2Dto.setElectedDoctor(new DoctorDto());
}
} catch (Exception e) {
logger.error("getRoundDetailV2: ", e);
}
List<ExamTitleDto> examTitleDtoList = getExamTitleListByRoundId(roundId);
roundExamTitleV2Dto.setExamTitleList(examTitleDtoList);
return roundExamTitleV2Dto;
}
@Override
public ExamTitleReplyDto getReplyListByExamTitleId(Integer examTitleId, PicaUser user) {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(examTitleId);
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisRoundExamTitle.getAnalysisId());
ExamTitleReplyDto examTitleReplyDto = new ExamTitleReplyDto();
ExamTitleDto examTitleDto = getExamTitleDtoById(examTitleId);
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
List<ReplyDto> replyDtoList = getReplyListDtoByExamTitleId(analysisRound, examTitleId, user != null ? user.getId() : 0);
/**
* 如果是PSA 删除回复的时间显示
*/
if (analysis.getType() == ANALYSIS_TYPE_PSA ) {
replyDtoList.forEach(replyDto -> replyDto.setReplayTime(""));
}
examTitleReplyDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setExamTitle(examTitleDto);
examTitleReplyDto.setReplyList(replyDtoList);
examTitleReplyDto.setType(analysis.getType().intValue());
/**
* 设置回复状态
*/
examTitleReplyDto.setReplyStatus(0);
if ((new Date()).getTime() < analysisRound.getEndTime().getTime()) {
if (user != null && user.getId() != 0) {
examTitleReplyDto.setReplyStatus(getReplyStatus(analysis, examTitleId, user.getId()));
}
}
return examTitleReplyDto;
}
@Override
public ExamTitleReplyDto getReplyListV2ByExamTitleId(Integer examTitleId, Integer pageNo, Integer pageSize, PicaUser user) {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(examTitleId);
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisRoundExamTitle.getAnalysisId());
ExamTitleReplyDto examTitleReplyDto = new ExamTitleReplyDto();
ExamTitleDto examTitleDto = getExamTitleDtoById(examTitleId);
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
List<ReplyDto> replyDtoList = getReplyListDtoByExamTitleId(analysisRound, examTitleId, user != null ? user.getId() : 0);
/**
* 分页 pageNo: 1,2,...
*/
Integer totalRecordCount = replyDtoList.size();
if ((pageNo - 1) * pageSize >= totalRecordCount) {
replyDtoList.clear();
} else {
Integer beginIdx = (pageNo - 1) * pageSize;
Integer endIdx = Integer.min(pageNo * pageSize, totalRecordCount - 1);
replyDtoList = replyDtoList.subList(beginIdx, endIdx);
}
/**
* 如果是PSA 删除回复的时间显示
*/
if (analysis.getType() == ANALYSIS_TYPE_PSA ) {
replyDtoList.forEach(replyDto -> replyDto.setReplayTime(""));
}
examTitleReplyDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDto.setExamTitle(examTitleDto);
examTitleReplyDto.setReplyList(replyDtoList);
examTitleReplyDto.setType(analysis.getType().intValue());
/**
* 设置回复状态
*/
examTitleReplyDto.setReplyStatus(0);
if ((new Date()).getTime() < analysisRound.getEndTime().getTime()) {
if (user != null && user.getId() != 0) {
examTitleReplyDto.setReplyStatus(getReplyStatus(analysis, examTitleId, user.getId()));
}
}
return examTitleReplyDto;
}
@Override
public ExamTitleReplyDto getNextReplyListByExamTitleId(Integer examTitleId, PicaUser user) {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(examTitleId);
ExamTitleDto examTitleDto = getNextExamTitleDtoById(analysisRoundExamTitle.getRoundId(), examTitleId);
return getReplyListByExamTitleId(examTitleDto.getExamTitleId(), user);
}
@Override
public ExamTitleReplyDetailDto getReplyDetailByReplyId(Integer replyId, PicaUser user) {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto();
Reply reply = replyMapper.selectByPrimaryKey(replyId);
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(reply.getAnalysisRoundExamTitleId());
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
ExamTitleDto examTitleDto = getExamTitleDtoById(reply.getAnalysisRoundExamTitleId());
ReplyDto replyDto = getReplyDtoByReply(analysisRound, reply, user != null ? user.getId() : 0);
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setExamTitle(examTitleDto);
examTitleReplyDetailDto.setReply(replyDto);
examTitleReplyDetailDto.setType(analysis.getType().intValue());
/**
* 设置回复状态
*/
examTitleReplyDetailDto.setReplyStatus(0);
if ((new Date()).getTime() < analysisRound.getEndTime().getTime()) {
if (user != null && user.getId() != 0) {
examTitleReplyDetailDto.setReplyStatus(getReplyStatus(analysis, reply.getAnalysisRoundExamTitleId(), user.getId()));
}
}
return examTitleReplyDetailDto;
}
@Override
public ExamTitleReplyDetailDto getNextReplyDetailByReplyId(Integer replyId, PicaUser user) {
Reply reply = getNextReplyById(replyId);
return getReplyDetailByReplyId(reply.getId(), user);
}
@Override
public ExamTitleReplyDetailDto getReplyDetailByExamTitleId(Integer examTitleId, PicaUser user) {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto();
Reply reply = getReplyByExamTitleId(examTitleId, user != null ? user.getId() : 0);
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(examTitleId);
ExamTitleDto examTitleDto = getExamTitleDtoById(examTitleId);
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setPublished(analysisRound.getIsPublished() ? 1 : 0);
ReplyDto replyDto = new ReplyDto();
if (null != reply) {
replyDto = getReplyDtoByReply(analysisRound, reply, user != null ? user.getId() : 0);
} else {
replyDto.setContent("");
}
examTitleReplyDetailDto.setAnalysisId(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setRoundId(analysisRoundExamTitle.getRoundId());
examTitleReplyDetailDto.setExamTitle(examTitleDto);
examTitleReplyDetailDto.setReply(replyDto);
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisRoundExamTitle.getAnalysisId());
examTitleReplyDetailDto.setType(analysis.getType().intValue());
/**
* 设置回复状态
*/
examTitleReplyDetailDto.setReplyStatus(0);
if ((new Date()).getTime() < analysisRound.getEndTime().getTime()) {
if (user != null && user.getId() != 0) {
examTitleReplyDetailDto.setReplyStatus(getReplyStatus(analysis, examTitleId, user.getId()));
}
}
return examTitleReplyDetailDto;
}
@Override
public PicaResponse starReply(PicaUser user, Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId) {
Doctor doctor = doctorService.getDoctorById(user.getId());
/**
* 未认证用户直接返回
*/
if (!(doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_3) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_6) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_7) )) {
return ReturnUtil.getPicaResponse(PicaResultCode.INTERFACE_FORBID_VISIT);
}
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(roundId);
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
return ReturnUtil.getPicaResponse("500002", "本期活动已结束");
}
/**
* 已经点过赞
*/
if (0 != insertStarRecord(analysisId, roundId, examTitleId, replyId, user.getId())) {
return ReturnUtil.getPicaResponse(PicaResultCode.DATA_ALREADY_EXISTED);
}
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
}
@Override
public CHCAnalysis getAnalysisById(Integer analysisId) {
return analysisMapper.selectByPrimaryKey(analysisId);
public PicaResponse reply(PicaUser user, String sysCode, Integer examTitleId, String content, Boolean isAdFilterOpen) {
/**
* 如果判断检测的数据中有垃圾 直接返回
*/
PicaResponse response = antiSpamService.processString(user.getId(), sysCode, content, false);
if (!response.getCode().equals(PicaResultCode.SUCCESS.code())) {
response.setData("");
return response;
}
insertReply(examTitleId, content, user.getId());
PicaResponse picaResponse = ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
picaResponse.setMessage("发布成功");
return picaResponse;
}
@Override
public CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId) {
public MyStarDto myStar(PicaUser user, Optional<Integer> roundId) {
MyStarDto myStarDto = new MyStarDto();
myStarDto.setDoctor(doctorService.getDoctorDtoById(user.getId()));
myStarDto.setRoundList(new ArrayList<>());
if (!roundId.isPresent()) {
List<AnalysisRoundDto> roundDtoList = getCHCHistoryRound(CHC_ANALYSIS_ID);
roundId = Optional.of(roundDtoList.get(0).getRoundId());
myStarDto.setRoundList(roundDtoList);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d");
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(roundId.get());
myStarDto.setStartTime(sdf.format(analysisRound.getStartTime()));
myStarDto.setEndTime(sdf.format(analysisRound.getEndTime()));
myStarDto.setRemainingTime(DateUtils.remainingTime(analysisRound.getEndTime()));
/**
* 设置结束状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
myStarDto.setIsFinished(1);
/**
* 设置我是否当选
*/
Integer electedDoctorId = getElectedDoctorIdByRoundId(roundId.get());
myStarDto.setIsElected(electedDoctorId.intValue() == user.getId().intValue() ? 1 : 0);
} else {
myStarDto.setIsFinished(0);
myStarDto.setIsElected(0);
}
/**
* 设置我的得赞数
*/
myStarDto.setMyStarCount(getStarCountByRoundIdAndDoctorId(roundId.get(), user.getId()));
/**
* 我的解析得赞记录
*/
myStarDto.setMyExamTitleList(getMyStarRecordByRoundIdAndDoctorId(roundId.get(), user.getId()));
return myStarDto;
}
@Override
public Integer removeStarRecord(Integer replyId, PicaUser user) {
/**
* 1. 判断是否存在点赞记录
*/
StarRecord starRecord = new StarRecord();
starRecord.setReplyId(replyId);
starRecord.setCreatedId(user.getId());
if (starRecordMapper.selectStarCountByRecord(starRecord) == 0) {
return -1;
}
/**
* 2. 删除点赞记录
*/
StarRecord record = starRecordMapper.selectBySelective(starRecord);
record.setModifiedId(user.getId());
record.setModifiedTime(new Date());
record.setIsDeleted(true);
starRecordMapper.updateByPrimaryKeySelective(record);
/**
* 3. 修改点赞数
*/
Reply reply = replyMapper.selectByPrimaryKey(replyId);
reply.setStarCount(reply.getStarCount() - 1);
replyMapper.updateByPrimaryKey(reply);
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
private CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectCHCByPrimaryKey(analysisId);
if (null == analysis) {
......@@ -76,8 +499,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return analysisDto;
}
@Override
public CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId) {
private CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectPSAByPrimaryKey(analysisId);
if (null == analysis) {
return null;
......@@ -101,17 +523,15 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return analysisDto;
}
@Override
public List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId) {
List<AnalysisRound> roundList = new ArrayList<>();
private List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId) {
List<AnalysisRound> roundList = new ArrayList<AnalysisRound>();
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisId);
if (analysis.getType() == 1)
if (analysis.getType() == 1) {
roundList = analysisRoundMapper.selectRoundListById(analysisId);
else
} else {
roundList = analysisRoundMapper.selectPSARoundListById(analysisId);
}
if (null == roundList){
return null;
}
......@@ -144,8 +564,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundDtoList;
}
@Override
public RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId) {
private RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId) {
AnalysisRound round = analysisRoundMapper.selectByPrimaryKey(roundId);
if (null == round) {
......@@ -173,13 +592,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundExamTitleDto;
}
@Override
public AnalysisRound getRoundInfoById(Integer roundId) {
return analysisRoundMapper.selectByPrimaryKey(roundId);
}
@Override
public List<ExamTitleDto> getExamTitleListByRoundId(Integer roundId) {
private List<ExamTitleDto> getExamTitleListByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
if (null == roundExamTitleList) {
......@@ -195,13 +608,6 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return ExamTitleDtoList;
}
@Override
public AnalysisRoundExamTitle getAnanlysisRoundExamTitleById(Integer analysisRoundExamTitleId) {
return analysisRoundExamTitleMapper.selectByPrimaryKey(analysisRoundExamTitleId);
}
@Override
public ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId) {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(analysisRoundExamTitleId);
......@@ -249,8 +655,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return examTitleDto;
}
@Override
public List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId) {
private List<ReplyDto> getReplyListDtoByExamTitleId(AnalysisRound round, Integer analysisRoundExamTitleId, Integer userId) {
List<Reply> replyList = getReplyList(analysisRoundExamTitleId);
List<ReplyDto> replyDtoList = new ArrayList<>();
......@@ -260,22 +665,16 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
/**
* 发现有评论用户不在p_doctor的情况,数据不同步造成的
*/
replyDtoList.add(getReplyDtoByReply(reply, userId));
replyDtoList.add(getReplyDtoByReply(round, reply, userId));
} catch (Exception e) {
logger.error("getReplyListDtoByExamTitleId", e);
// logger.error("getReplyListDtoByExamTitleId", e);
}
}
return replyDtoList;
}
@Override
public Reply getReplyById(Integer replyId) {
return replyMapper.selectByPrimaryKey(replyId);
}
@Override
public Reply getNextReplyById(Integer replyId) {
private Reply getNextReplyById(Integer replyId) {
Reply reply = replyMapper.selectByPrimaryKey(replyId);
/**
......@@ -299,8 +698,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyList.get(idx);
}
@Override
public ReplyDto getReplyDtoByReply(Reply reply, Integer userId) {
private ReplyDto getReplyDtoByReply(AnalysisRound round, Reply reply, Integer userId) {
ReplyDto replyDto = new ReplyDto();
Doctor doctor = doctorMapper.selectByPrimaryKey(reply.getUserId());
......@@ -317,10 +715,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
replyDto.setReplayTime(DateUtils.fromNow(reply.getModifiedTime()));
replyDto.setStarCount(starRecordMapper.selectStarCountByReplyId(reply.getId()));
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(reply.getAnalysisRoundExamTitleId());
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
if ((new Date()).getTime() > round.getEndTime().getTime()) {
replyDto.setStatus(2);
} else {
StarRecord starRecord = new StarRecord();
......@@ -332,8 +727,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyDto;
}
@Override
public Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId) {
private Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId) {
StarRecord starRecord = new StarRecord();
starRecord.setAnalysisId(analysisId);
......@@ -369,41 +763,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return 0;
}
@Override
public Integer removeStarRecord(Integer replyId, Integer userId) {
/**
* 1. 判断是否存在点赞记录
*/
StarRecord starRecord = new StarRecord();
starRecord.setReplyId(replyId);
starRecord.setCreatedId(userId);
if (starRecordMapper.selectStarCountByRecord(starRecord) == 0) {
return -1;
}
/**
* 2. 删除点赞记录
*/
StarRecord record = starRecordMapper.selectBySelective(starRecord);
record.setModifiedId(userId);
record.setModifiedTime(new Date());
record.setIsDeleted(true);
starRecordMapper.updateByPrimaryKeySelective(record);
/**
* 3. 修改点赞数
*/
Reply reply = replyMapper.selectByPrimaryKey(replyId);
reply.setStarCount(reply.getStarCount() - 1);
replyMapper.updateByPrimaryKey(reply);
return 0;
}
@Override
public ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId) {
private ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId) {
List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
Integer examTitleCount = roundExamTitleList.size();
......@@ -420,8 +780,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return this.getExamTitleDtoById(roundExamTitleList.get(idx).getId());
}
@Override
public Integer insertReply(Integer examTitleId, String content, Integer userId) {
private Integer insertReply(Integer examTitleId, String content, Integer userId) {
/**
* 找到我是否已经回复过,如果回复过就编辑,没有就新建
*/
......@@ -454,8 +813,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
}
}
@Override
public Integer getReplyStatus(Integer examTitleId, Integer userId) {
private Integer getReplyStatus(Integer examTitleId, Integer userId) {
/**
* 用户不存在
*/
......@@ -483,22 +841,21 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return 2;
}
@Override
public Reply getReplyByExamTitleId(Integer examTitleId, Integer userId) {
private 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) {
private List<Reply> getReplyList(Integer examTitleId) {
Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId);
/**
* case 1. 按照时间排序,如果个数小于5,直接返回
*/
List<Reply> replyList = replyMapper.selectReplyListOrderByTime(examTitleId);
if (replyCount < 5) {
return replyList;
}
......@@ -519,8 +876,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyListOther;
}
@Override
public List<AnalysisRoundDto> getCHCHistoryRound(Integer analysisId) {
private List<AnalysisRoundDto> getCHCHistoryRound(Integer analysisId) {
List<AnalysisRound> roundList = new ArrayList<>();
/**
......@@ -557,8 +913,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundDtoList;
}
@Override
public Integer getElectedStarCountByRoundId(Integer roundId) {
private Integer getElectedStarCountByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) {
......@@ -567,8 +922,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectElectedStarCountByExamTitleIdList(examTitleIdList);
}
@Override
public Integer getElectedDoctorIdByRoundId(Integer roundId) {
private Integer getElectedDoctorIdByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) {
......@@ -577,8 +931,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectElectedDoctorIdByExamTitleIdList(examTitleIdList);
}
@Override
public Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
private Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
......@@ -590,8 +943,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectStarCountByParam(param);
}
@Override
public List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
private List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
......@@ -626,4 +978,39 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return userExamTitleDtos;
}
Integer getReplyStatus(CHCAnalysis analysis, Integer examTitleId, Integer userId) {
Doctor doctor = doctorService.getDoctorById(userId);
if (doctor != null) {
if (analysis.getId() == CHC_ANALYSIS_ID) {
/**
* CHC 获取考试前两百名
*/
if (chcRankingListService.isRankingInTop200(doctor.getId())) {
return getReplyStatus(examTitleId, userId);
}
} else if (analysis.getId() == PSA_ANALYSIS_ID) {
/**
* 如果未认证 不可见
*/
if (!(doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_3) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_6) ||
doctor.getStatus().equals(CommonConstants.DOCTOR_STATUS_7) )) {
return 0;
}
/**
* PSA 职务职称主任/副主任 院长/副院长 科长/副科长 管理人数100以上
*/
if (doctorService.isAuth(doctor.getId())) {
return getReplyStatus(examTitleId, userId);
}
} else {
return getReplyStatus(examTitleId, userId);
}
}
return 0;
}
}
......@@ -38,6 +38,7 @@
seq_no from p_analysis_round
where is_published = 1
and is_deleted = 0
and analysis_id = #{id,jdbcType=INTEGER}
order by seq_no desc
limit 1)
order by seq_no
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册