提交 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; package com.pica.cloud.online.exam.analysis.common;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.pica.cloud.foundation.redis.RedisClient;
import com.pica.cloud.foundation.utils.entity.PicaUser; import com.pica.cloud.foundation.utils.entity.PicaUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -25,14 +24,4 @@ public class CommonUtils { ...@@ -25,14 +24,4 @@ public class CommonUtils {
} }
return JSON.parseObject(JSON.toJSONString(map), PicaUser.class); 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 @@ ...@@ -12,7 +12,7 @@
<dependency> <dependency>
<groupId>com.pica.cloud.foundation</groupId> <groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId> <artifactId>pica-cloud-utils</artifactId>
<version>1.0.7-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -101,17 +101,15 @@ ...@@ -101,17 +101,15 @@
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version> <version>2.8.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.pica.cloud.foundation</groupId> <groupId>redis.clients</groupId>
<artifactId>pica-cloud-redis</artifactId> <artifactId>jedis</artifactId>
<version>1.1.2</version> <version>2.9.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.pica.cloud.foundation</groupId> <groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId> <artifactId>pica-cloud-redis</artifactId>
<version>1.0.7-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -138,10 +136,6 @@ ...@@ -138,10 +136,6 @@
<version>5.1.39</version> <version>5.1.39</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
...@@ -154,11 +148,6 @@ ...@@ -154,11 +148,6 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-utils</artifactId>
<version>1.0.7-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.dianping.cat</groupId> <groupId>com.dianping.cat</groupId>
<artifactId>cat-core</artifactId> <artifactId>cat-core</artifactId>
......
...@@ -9,10 +9,10 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients; ...@@ -9,10 +9,10 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCircuitBreaker @EnableCircuitBreaker
@SpringBootApplication @SpringBootApplication(scanBasePackages = "com.pica.cloud")
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableSwagger2 @EnableSwagger2
@EnableFeignClients @EnableFeignClients(basePackages = "com.pica.cloud")
@MapperScan("com.pica.cloud.online.exam.analysis.server.mapper") @MapperScan("com.pica.cloud.online.exam.analysis.server.mapper")
public class App { public class App {
public static void main( String[] args ) public static void main( String[] args )
......
package com.pica.cloud.online.exam.analysis.server.configuration; 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.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.pica.cloud.foundation.redis.RedisClient;
@Configuration @Configuration
@RefreshScope @RefreshScope
public class BeanConfiguration { public class BeanConfiguration {
@Autowired
private SpringContextAware springContextAware;
@Value("${spring.redis.config}") @Value("${spring.redis.config}")
private String configStr; private String configStr;
@Bean @Bean
public RedisClient redisClient() { @ConditionalOnMissingBean
System.out.println(configStr); 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; package com.pica.cloud.online.exam.analysis.server.controller;
import com.alibaba.fastjson.JSONObject; 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.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode; 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.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.dto.*;
import com.pica.cloud.online.exam.analysis.common.util.ReturnUtil; 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.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.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.service.DoctorService;
import com.pica.cloud.online.exam.analysis.server.utils.DateUtils; import com.pica.cloud.foundation.redis.ICacheClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javassist.bytecode.ExceptionsAttribute;
import org.omg.CORBA.INTERNAL;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.web.bind.annotation.*;
import java.util.Optional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/** /**
* @author wuminghao * @author wuminghao
...@@ -40,778 +26,169 @@ import java.util.List; ...@@ -40,778 +26,169 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/") @RequestMapping("/")
@Api(value = "题目分析接口", description = "查看活动及详情,用户点赞、医生回复") public class AnalysisController extends BaseController {
public class AnalysisController {
private static Logger logger = LoggerFactory.getLogger(AnalysisController.class);
@Autowired
private RedisClient redisClient;
@Qualifier("cacheMigrateClient")
@Autowired @Autowired
private LoadBalancerClient slb; private ICacheClient redisClient;
@Autowired
private IConfigServiceClient client;
@Autowired @Autowired
private CHCAnalysisService analysisService; private CHCAnalysisService analysisService;
@Autowired
private DoctorService doctorService;
@Autowired
private AntiSpamService antiSpamService;
@Autowired
private CHCRankingListService rankingListService;
@Autowired @Autowired
private PropertiesConfiguration propertiesConfiguration; private PropertiesConfiguration propertiesConfiguration;
/**
* TODO: chc错题解析活动和psa的活动id 需要前端传入
*/
static final Integer CHC_ANALYSIS_ID = 1; static final Integer CHC_ANALYSIS_ID = 1;
static final Integer PSA_ANALYSIS_ID = 2; static final Integer PSA_ANALYSIS_ID = 2;
@ApiOperation(value = "获取活动详情", response = PicaResponse.class)
@RequestMapping(value = "/config", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/config", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String config() { public String config() {
return propertiesConfiguration.toString(); return propertiesConfiguration.toString();
} }
@ApiOperation(value = "获取活动详情", response = PicaResponse.class) @RequestMapping(value = {"/activityDetail", "/activityDetail/{id}"}, method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@RequestMapping(value = "/activityDetail", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") public PicaResponse<CHCAnalysisDto> getActivityDetail(@PathVariable(required = false) Integer id) {
public PicaResponse<CHCAnalysisDto> getActivityDetail(@RequestParam(required = false) Integer id,
@RequestHeader(required = false) String token) {
Transaction t = Cat.newTransaction("Link", "/activityDetail");
PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
/**
* 如果不传活动id进来,活动id就用1
*/
id = (id == null ? CHC_ANALYSIS_ID : id);
try { try {
CHCAnalysisDto analysisDto = analysisService.getCHCAnalysisDtoById(id); user = fetchPicaUser();
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);
} catch (Exception e) { } 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(); return builder.build();
} }
@ApiOperation(value = "获取活动详情", response = PicaResponse.class)
@RequestMapping(value = "/psaActivityDetail", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/psaActivityDetail", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<CHCAnalysisDto> getPSAActivityDetail(@RequestParam(required = false) Integer id) { public PicaResponse<CHCAnalysisDto> getPSAActivityDetail(@RequestParam(required = false) Integer id) {
Transaction t = Cat.newTransaction("Link", "/psaActivityDetail");
PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<CHCAnalysisDto> builder = new PicaResponse.Builder<>();
/** builder.setData(analysisService.getPSAActivityDetail(id == null ? PSA_ANALYSIS_ID : id));
* 如果不传活动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();
return builder.build(); return builder.build();
} }
@ApiOperation(value = "获取某一轮的题目", response = PicaResponse.class)
@RequestMapping(value = "/roundDetail/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/roundDetail/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<RoundExamTitleDto> getRoundDetail(@PathVariable("roundId") Integer roundId) { 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<>(); 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 { try {
RoundExamTitleDto roundExamTitleDto = analysisService.getRoundExamTitleDtoById(roundId); user = fetchPicaUser();
List<ExamTitleDto> examTitleDtoList = analysisService.getExamTitleListByRoundId(roundId);
roundExamTitleDto.setExamTitleList(examTitleDtoList);
builder.setData(roundExamTitleDto);
t.setStatus(Transaction.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
logger.error("getRoundDetail", e);
t.setStatus(e);
Cat.logError(e);
} }
builder.setData(analysisService.getReplyListByExamTitleId(examTitleId, user));
t.complete();
return builder.build(); return builder.build();
} }
@ApiOperation(value = "获取某一道题目的回复列表", response = PicaResponse.class) @RequestMapping(value = "/replyList/v2/{examTitleId}/page/{pageNo}/size/{pageSize}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@RequestMapping(value = "/replyList/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> getReplyList(@PathVariable("examTitleId") Integer examTitleId, public PicaResponse<ExamTitleReplyDto> getReplyList(@PathVariable("examTitleId") Integer examTitleId,
@RequestHeader(required = false) String token) { @PathVariable("pageNo") Integer pageNo,
Transaction t = Cat.newTransaction("Link", "/replyList"); @PathVariable("pageSize") Integer pageSize) {
PicaUser user = null;
if (token != null) {
user = CommonUtils.getUserByToken(redisClient, token);
}
PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try { try {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(examTitleId); user = fetchPicaUser();
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);
} catch (Exception e) { } 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(); return builder.build();
} }
@ApiOperation(value = "查看回复详情", response = PicaResponse.class)
@RequestMapping(value = "/replyDetail/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/replyDetail/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetail(@PathVariable("replyId") Integer replyId, 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);
}
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try { try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto(); user = fetchPicaUser();
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);
} catch (Exception e) { } catch (Exception e) {
logger.error("getReplyDetail", e);
t.setStatus(e);
Cat.logError(e);
} }
t.complete(); builder.setData(analysisService.getReplyDetailByReplyId(replyId, user));
return builder.build(); return builder.build();
} }
@ApiOperation(value = "查看回复详情", response = PicaResponse.class)
@RequestMapping(value = "/replyDetailByExamTitleId/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/replyDetailByExamTitleId/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDetailDto> getReplyDetailByExamTitleId(@PathVariable("examTitleId") Integer examTitleId, 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);
}
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try { try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto(); user = fetchPicaUser();
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);
} catch (Exception e) { } catch (Exception e) {
logger.error("getReplyDetailByExamTitleId", e);
t.setStatus(e);
Cat.logError(e);
} }
t.complete(); builder.setData(analysisService.getReplyDetailByExamTitleId(examTitleId, user));
return builder.build(); 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") @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, public PicaResponse starReply(@PathVariable("analysisId") Integer analysisId,
@PathVariable("examTitleId") Integer examTitleId, @PathVariable("replyId") Integer replyId, @PathVariable("roundId") Integer roundId,
@RequestHeader(required = false) String token) { @PathVariable("examTitleId") Integer examTitleId,
if (token == null) { @PathVariable("replyId") Integer replyId) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN); return analysisService.starReply(fetchPicaUser(), analysisId, roundId, examTitleId, replyId);
}
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", "本期活动已结束");
}
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") @RequestMapping(value = "/cancelStar/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse cancelStar( @PathVariable("replyId") Integer replyId, public PicaResponse cancelStar( @PathVariable("replyId") Integer replyId,
@RequestHeader(required = false) String token) { @RequestHeader(required = false) String token) {
if (token == null) { if (0 != analysisService.removeStarRecord(replyId, fetchPicaUser())) {
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())) {
return ReturnUtil.getPicaResponse(PicaResultCode.RESULE_DATA_NONE); return ReturnUtil.getPicaResponse(PicaResultCode.RESULE_DATA_NONE);
} }
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS); return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS);
} }
@ApiOperation(value = "获取某一道题目的下一道题", response = PicaResponse.class)
@RequestMapping(value = "/nextExamTitle/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/nextExamTitle/{examTitleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> nextReplyList(@PathVariable("examTitleId") Integer examTitleId, 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);
}
PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<ExamTitleReplyDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try { try {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisService.getAnanlysisRoundExamTitleById(examTitleId); user = fetchPicaUser();
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);
} catch (Exception e) { } catch (Exception e) {
logger.error("nextReplyList", e);
t.setStatus(e);
Cat.logError(e);
} }
t.complete(); builder.setData(analysisService.getNextReplyListByExamTitleId(examTitleId, user));
return builder.build(); return builder.build();
} }
@ApiOperation(value = "获取某一道题目的下一道题", response = PicaResponse.class)
@RequestMapping(value = "/nextReply/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/nextReply/{replyId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<ExamTitleReplyDto> nextReplyDetail(@PathVariable("replyId") Integer replyId, public PicaResponse<ExamTitleReplyDetailDto> 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);
}
PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<ExamTitleReplyDetailDto> builder = new PicaResponse.Builder<>();
PicaUser user = null;
try { try {
ExamTitleReplyDetailDto examTitleReplyDetailDto = new ExamTitleReplyDetailDto(); user = fetchPicaUser();
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);
} catch (Exception e) { } catch (Exception e) {
logger.error("nextReplyDetail", e);
t.setStatus(e);
Cat.logError(e);
} }
t.complete(); builder.setData(analysisService.getNextReplyDetailByReplyId(replyId, user));
return builder.build(); return builder.build();
} }
@ApiOperation(value = "回复", response = PicaResponse.class) @LoginPermission
@RequestMapping(value = "/reply/{examTitleId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/reply/{examTitleId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse reply( @PathVariable("examTitleId") Integer examTitleId, public PicaResponse reply( @PathVariable("examTitleId") Integer examTitleId,
@RequestBody String content, @RequestBody String content,
@RequestHeader String sysCode, @RequestHeader String sysCode) {
@RequestHeader String token) { JSONObject jsonObject = JSONObject.parseObject(content);
Transaction t = Cat.newTransaction("Link", "/nextReply"); content = jsonObject.get("content").toString();
if (token == null) { return analysisService.reply(fetchPicaUser(), sysCode, examTitleId, content,false);
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 {
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;
} }
@ApiOperation(value = "获取某一轮的题目V2", response = PicaResponse.class) @ApiOperation(value = "获取某一轮的题目V2", response = PicaResponse.class)
@RequestMapping(value = "/roundDetail/v2/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/roundDetail/v2/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<RoundExamTitleV2Dto> getRoundDetailV2(@PathVariable(value = "roundId") Integer roundId) { 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<>(); PicaResponse.Builder<RoundExamTitleV2Dto> builder = new PicaResponse.Builder<>();
builder.setData(analysisService.getRoundDetailV2(roundId));
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();
return builder.build(); return builder.build();
} }
@LoginPermission
@ApiOperation(value = "我的赞", response = PicaResponse.class) @ApiOperation(value = "我的赞", response = PicaResponse.class)
@RequestMapping(value = {"/myStar/{roundId}","/myStar/"}, method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @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, 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);
}
PicaResponse.Builder<MyStarDto> builder = new PicaResponse.Builder<>(); PicaResponse.Builder<MyStarDto> builder = new PicaResponse.Builder<>();
try { builder.setData(analysisService.myStar(fetchPicaUser(), Optional.ofNullable(roundId)));
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();
return builder.build(); return builder.build();
} }
......
...@@ -3,17 +3,16 @@ package com.pica.cloud.online.exam.analysis.server.controller; ...@@ -3,17 +3,16 @@ package com.pica.cloud.online.exam.analysis.server.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode; 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.annotation.LoginPermission;
import com.pica.cloud.foundation.utils.controller.BaseController;
import com.pica.cloud.foundation.utils.entity.PicaUser; 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.common.util.ReturnUtil;
import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService; import com.pica.cloud.online.exam.analysis.server.service.AntiSpamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
/** /**
...@@ -22,10 +21,10 @@ import org.springframework.web.bind.annotation.*; ...@@ -22,10 +21,10 @@ import org.springframework.web.bind.annotation.*;
*/ */
@RestController @RestController
@RequestMapping("/antispam") @RequestMapping("/antispam")
@Api(value = "内容甄别解析", description = "检测文本、图片内容") public class AntiSpamController extends BaseController {
public class AntiSpamController { @Qualifier("cacheMigrateClient")
@Autowired @Autowired
private RedisClient redisClient; private ICacheClient redisClient;
@Autowired @Autowired
AntiSpamService antiSpamService; AntiSpamService antiSpamService;
...@@ -36,33 +35,17 @@ public class AntiSpamController { ...@@ -36,33 +35,17 @@ public class AntiSpamController {
public PicaResponse processText(@RequestBody String content, public PicaResponse processText(@RequestBody String content,
@RequestHeader String sysCode, @RequestHeader String sysCode,
@RequestHeader String token) { @RequestHeader String token) {
PicaUser user = CommonUtils.getUserByToken(redisClient, token); PicaUser user = fetchPicaUser();
Pair<String, Integer> params;
if (user == null || user.getId().intValue() == 0) {
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
StringBuilder sbContent = new StringBuilder();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer type = 0;
try { try {
JSONObject jsonObject = JSONObject.parseObject(content); params = parseContentAndType(content);
sbContent.append(jsonObject.get("content").toString());
type = (jsonObject.get("type") != null ? Integer.parseInt(jsonObject.get("type").toString()) : 0);
} catch (Exception e) { } catch (Exception e) {
return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID); return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID);
} }
return antiSpamService.processString(user.getId(), sysCode, params.getLeft(), params.getRight() != 0);
return antiSpamService.processString(
user.getId(),
sysCode,
sbContent.toString(),
type != 0
);
} }
@LoginPermission
@ApiOperation(value = "内容检测", response = PicaResponse.class) @ApiOperation(value = "内容检测", response = PicaResponse.class)
@RequestMapping(value = "/text/v1", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/text/v1", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processTextV1(@RequestBody String content, public PicaResponse processTextV1(@RequestBody String content,
...@@ -71,53 +54,30 @@ public class AntiSpamController { ...@@ -71,53 +54,30 @@ public class AntiSpamController {
return processText(content, sysCode, token); return processText(content, sysCode, token);
} }
@LoginPermission
@ApiOperation(value = "内容检测", response = PicaResponse.class) @ApiOperation(value = "内容检测", response = PicaResponse.class)
@RequestMapping(value = "/text/v2", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/text/v2", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processTextV2(@RequestBody String content, public PicaResponse processTextV2(@RequestBody String content,
@RequestHeader String sysCode, @RequestHeader String sysCode,
@RequestHeader String token) { @RequestHeader String token) {
PicaUser user = CommonUtils.getUserByToken(redisClient, token); PicaUser user = fetchPicaUser();
Pair<String, Integer> params;
if (user == null || user.getId().intValue() == 0) {
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
StringBuilder sbContent = new StringBuilder();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer type = 0;
try { try {
JSONObject jsonObject = JSONObject.parseObject(content); params = parseContentAndType(content);
sbContent.append(jsonObject.get("content").toString());
type = (jsonObject.get("type") != null ? Integer.parseInt(jsonObject.get("type").toString()) : 0);
} catch (Exception e) { } catch (Exception e) {
return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID); return ReturnUtil.getPicaResponse(PicaResultCode.PARAM_IS_INVALID);
} }
return antiSpamService.processStringV2( return antiSpamService.processStringV2(user.getId(), sysCode, params.getLeft(), params.getRight() != 0);
user.getId(),
sysCode,
sbContent.toString(),
type != 0
);
} }
@LoginPermission
@ApiOperation(value = "图片检测", response = PicaResponse.class) @ApiOperation(value = "图片检测", response = PicaResponse.class)
@RequestMapping(value = "/image", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/image", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public PicaResponse processImage(@RequestBody String content, public PicaResponse processImage(@RequestBody String content,
@RequestHeader String sysCode, @RequestHeader String sysCode,
@RequestHeader String token) { @RequestHeader String token) {
if (token == null) { PicaUser user = fetchPicaUser();
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);
}
StringBuilder sbContent = new StringBuilder(); StringBuilder sbContent = new StringBuilder();
try { try {
JSONObject jsonObject = JSONObject.parseObject(content); JSONObject jsonObject = JSONObject.parseObject(content);
...@@ -132,4 +92,11 @@ public class AntiSpamController { ...@@ -132,4 +92,11 @@ public class AntiSpamController {
return ReturnUtil.getPicaResponse(PicaResultCode.SUCCESS); 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; package com.pica.cloud.online.exam.analysis.server.mapper;
import com.pica.cloud.online.exam.analysis.server.entity.AntiSpamRecord; import com.pica.cloud.online.exam.analysis.server.entity.AntiSpamRecord;
import org.springframework.stereotype.Component;
@Component
public interface AntiSpamRecordMapper { public interface AntiSpamRecordMapper {
int deleteByPrimaryKey(Integer id); 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; 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.common.dto.*;
import com.pica.cloud.online.exam.analysis.server.entity.AnalysisRound; 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.AnalysisRoundExamTitle;
import com.pica.cloud.online.exam.analysis.server.entity.CHCAnalysis; 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 io.swagger.models.auth.In;
import org.omg.CORBA.INTERNAL; import org.omg.CORBA.INTERNAL;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* @author wuminghao * @author wuminghao
* @date 2018/8/17 9:40 * @date 2018/8/17 9:40
*/ */
public interface CHCAnalysisService { public interface CHCAnalysisService {
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysis getAnalysisById(Integer analysisId);
/**
* 根据活动id获取活动详情
* @param analysisId
* @return
*/
CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId);
/** /**
* 根据活动id获取活动详情 * 获取CHC活动详情
* @param analysisId * @param analysisId 活动id
* @param user
* @return * @return
*/ */
CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId); CHCAnalysisDto getCHCActivityDetail(Integer analysisId, PicaUser user);
/** /**
* 根据活动id获取活动的轮数 * 获取PSA活动详情
* @param analysisId * @param analysisId 活动id
* @return * @return
*/ */
List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId); CHCAnalysisDto getPSAActivityDetail(Integer analysisId);
/** /**
* 根据轮的id获取信息 * 获取轮详情
* @param roundId * @param roundId 轮id
* @return * @return
*/ */
RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId); RoundExamTitleDto getRoundDetail(Integer roundId);
/** /**
* 根据轮的id获取信息 * 获取轮详情V2
* @param roundId * @param roundId
* @return * @return
*/ */
AnalysisRound getRoundInfoById(Integer roundId); RoundExamTitleV2Dto getRoundDetailV2(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);
/** /**
* 根据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 examTitleId
* @param replyId * @param user
* @return * @return
*/ */
Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId); ExamTitleReplyDto getReplyListByExamTitleId(Integer examTitleId, PicaUser user);
/** /**
* 取消点赞记录 * 获取题目的回复列表 分页
* @param replyId * @param examTitleId 题目id
* @param userId * @param pageNo 页码
* @param pageSize 大小
* @param user
* @return * @return
*/ */
Integer removeStarRecord(Integer replyId, Integer userId); ExamTitleReplyDto getReplyListV2ByExamTitleId(Integer examTitleId, Integer pageNo, Integer pageSize, PicaUser user);
/** /**
* 增加解析 * 获取下一题的回复列表
* @param examTitleId * @param examTitleId
* @param content * @param user
* @param userId
* @return * @return
*/ */
Integer insertReply(Integer examTitleId, String content, Integer userId); ExamTitleReplyDto getNextReplyListByExamTitleId(Integer examTitleId, PicaUser user);
/**
* 获取我的评论状态
* @param examTitleId
* @param userId
* @return
*/
Integer getReplyStatus(Integer examTitleId, Integer userId);
/** /**
* 获取我的评论详情 * 获取回复的详情
* @param examTitleId * @param replyId 回复id
* @param userId * @param user 用户
* @return * @return
*/ */
Reply getReplyByExamTitleId(Integer examTitleId, Integer userId); ExamTitleReplyDetailDto getReplyDetailByReplyId(Integer replyId, PicaUser user);
/** /**
* 根据考试id获取评论列表 * 获取下一回复的详情
* @param examTitleId * @param replyId
* @param user
* @return * @return
*/ */
List<Reply> getReplyList(Integer examTitleId); ExamTitleReplyDetailDto getNextReplyDetailByReplyId(Integer replyId, PicaUser user);
/** /**
* 获取所有的历史轮详情 * 获取回复的详情
* @param ananlysisId * @param examTitleId 题目id
* @param user 用户
* @return * @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 * @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 * @return
*/ */
Integer getElectedDoctorIdByRoundId(Integer roundId); PicaResponse reply(PicaUser user, String sysCode, Integer examTitleId, String content, Boolean isAdFilterOpen);
/** /**
* 根据医生id和轮id获取得赞数 * 获取我的赞
* @param roundId * @param user 用户
* @param doctorId * @param roundId 某轮的id
* @return * @return
*/ */
Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId); MyStarDto myStar(PicaUser user, Optional<Integer> roundId);
/** /**
* 根据医生id和轮id获取得赞记录 * 取消点赞
* @param roundId * @param replyId 活动id
* @param doctorId * @param user 用户
* @return * @return
*/ */
List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId); Integer removeStarRecord(Integer replyId, PicaUser user);
} }
...@@ -38,7 +38,7 @@ public class AntiSpamServiceImpl implements AntiSpamService { ...@@ -38,7 +38,7 @@ public class AntiSpamServiceImpl implements AntiSpamService {
@Autowired @Autowired
private AntiSpamRecordMapper antiSpamRecordMapper; 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 static HttpClient httpClientImage = HttpClient4Utils.createHttpClient(100, 20, 10000, 2000, 2000);
private String neteaseResult(String content, boolean isAdFilterOpen) { private String neteaseResult(String content, boolean isAdFilterOpen) {
......
package com.pica.cloud.online.exam.analysis.server.service.impl; 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.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.configuration.PropertiesConfiguration;
import com.pica.cloud.online.exam.analysis.server.entity.*; 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.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.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 com.pica.cloud.online.exam.analysis.server.utils.DateUtils;
import net.bytebuddy.asm.Advice;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -42,16 +51,430 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -42,16 +51,430 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
@Autowired @Autowired
DoctorMapper doctorMapper; DoctorMapper doctorMapper;
@Autowired
CHCRankingListMapper rankingListMapper;
@Autowired @Autowired
private PropertiesConfiguration properties; 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 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 @Override
public CHCAnalysis getAnalysisById(Integer analysisId) { public MyStarDto myStar(PicaUser user, Optional<Integer> roundId) {
return analysisMapper.selectByPrimaryKey(analysisId);
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 @Override
public CHCAnalysisDto getCHCAnalysisDtoById(Integer analysisId) { 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); CHCAnalysis analysis = analysisMapper.selectCHCByPrimaryKey(analysisId);
if (null == analysis) { if (null == analysis) {
...@@ -76,8 +499,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -76,8 +499,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return analysisDto; return analysisDto;
} }
@Override private CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId) {
public CHCAnalysisDto getPSAAnalysisDtoById(Integer analysisId) {
CHCAnalysis analysis = analysisMapper.selectPSAByPrimaryKey(analysisId); CHCAnalysis analysis = analysisMapper.selectPSAByPrimaryKey(analysisId);
if (null == analysis) { if (null == analysis) {
return null; return null;
...@@ -101,17 +523,15 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -101,17 +523,15 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return analysisDto; return analysisDto;
} }
@Override private List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId) {
public List<AnalysisRoundDto> getRoundListByAnalysisId(Integer analysisId) { List<AnalysisRound> roundList = new ArrayList<AnalysisRound>();
List<AnalysisRound> roundList = new ArrayList<>();
CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisId); CHCAnalysis analysis = analysisMapper.selectByPrimaryKey(analysisId);
if (analysis.getType() == 1) if (analysis.getType() == 1) {
roundList = analysisRoundMapper.selectRoundListById(analysisId); roundList = analysisRoundMapper.selectRoundListById(analysisId);
else } else {
roundList = analysisRoundMapper.selectPSARoundListById(analysisId); roundList = analysisRoundMapper.selectPSARoundListById(analysisId);
}
if (null == roundList){ if (null == roundList){
return null; return null;
} }
...@@ -144,8 +564,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -144,8 +564,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundDtoList; return roundDtoList;
} }
@Override private RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId) {
public RoundExamTitleDto getRoundExamTitleDtoById(Integer roundId) {
AnalysisRound round = analysisRoundMapper.selectByPrimaryKey(roundId); AnalysisRound round = analysisRoundMapper.selectByPrimaryKey(roundId);
if (null == round) { if (null == round) {
...@@ -173,13 +592,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -173,13 +592,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundExamTitleDto; return roundExamTitleDto;
} }
@Override private List<ExamTitleDto> getExamTitleListByRoundId(Integer roundId) {
public AnalysisRound getRoundInfoById(Integer roundId) {
return analysisRoundMapper.selectByPrimaryKey(roundId);
}
@Override
public List<ExamTitleDto> getExamTitleListByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
if (null == roundExamTitleList) { if (null == roundExamTitleList) {
...@@ -195,13 +608,6 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -195,13 +608,6 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return ExamTitleDtoList; return ExamTitleDtoList;
} }
@Override
public AnalysisRoundExamTitle getAnanlysisRoundExamTitleById(Integer analysisRoundExamTitleId) {
return analysisRoundExamTitleMapper.selectByPrimaryKey(analysisRoundExamTitleId);
}
@Override
public ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId) { public ExamTitleDto getExamTitleDtoById(Integer analysisRoundExamTitleId) {
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(analysisRoundExamTitleId); AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(analysisRoundExamTitleId);
...@@ -249,8 +655,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -249,8 +655,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return examTitleDto; return examTitleDto;
} }
@Override private List<ReplyDto> getReplyListDtoByExamTitleId(AnalysisRound round, Integer analysisRoundExamTitleId, Integer userId) {
public List<ReplyDto> getReplyListDtoByExamTitleId(Integer analysisRoundExamTitleId, Integer userId) {
List<Reply> replyList = getReplyList(analysisRoundExamTitleId); List<Reply> replyList = getReplyList(analysisRoundExamTitleId);
List<ReplyDto> replyDtoList = new ArrayList<>(); List<ReplyDto> replyDtoList = new ArrayList<>();
...@@ -260,22 +665,16 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -260,22 +665,16 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
/** /**
* 发现有评论用户不在p_doctor的情况,数据不同步造成的 * 发现有评论用户不在p_doctor的情况,数据不同步造成的
*/ */
replyDtoList.add(getReplyDtoByReply(reply, userId)); replyDtoList.add(getReplyDtoByReply(round, reply, userId));
} catch (Exception e) { } catch (Exception e) {
logger.error("getReplyListDtoByExamTitleId", e); // logger.error("getReplyListDtoByExamTitleId", e);
} }
} }
return replyDtoList; return replyDtoList;
} }
@Override private Reply getNextReplyById(Integer replyId) {
public Reply getReplyById(Integer replyId) {
return replyMapper.selectByPrimaryKey(replyId);
}
@Override
public Reply getNextReplyById(Integer replyId) {
Reply reply = replyMapper.selectByPrimaryKey(replyId); Reply reply = replyMapper.selectByPrimaryKey(replyId);
/** /**
...@@ -299,8 +698,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -299,8 +698,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyList.get(idx); return replyList.get(idx);
} }
@Override private ReplyDto getReplyDtoByReply(AnalysisRound round, Reply reply, Integer userId) {
public ReplyDto getReplyDtoByReply(Reply reply, Integer userId) {
ReplyDto replyDto = new ReplyDto(); ReplyDto replyDto = new ReplyDto();
Doctor doctor = doctorMapper.selectByPrimaryKey(reply.getUserId()); Doctor doctor = doctorMapper.selectByPrimaryKey(reply.getUserId());
...@@ -317,10 +715,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -317,10 +715,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
replyDto.setReplayTime(DateUtils.fromNow(reply.getModifiedTime())); replyDto.setReplayTime(DateUtils.fromNow(reply.getModifiedTime()));
replyDto.setStarCount(starRecordMapper.selectStarCountByReplyId(reply.getId())); replyDto.setStarCount(starRecordMapper.selectStarCountByReplyId(reply.getId()));
AnalysisRoundExamTitle analysisRoundExamTitle = analysisRoundExamTitleMapper.selectByPrimaryKey(reply.getAnalysisRoundExamTitleId()); if ((new Date()).getTime() > round.getEndTime().getTime()) {
AnalysisRound analysisRound = analysisRoundMapper.selectByPrimaryKey(analysisRoundExamTitle.getRoundId());
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
replyDto.setStatus(2); replyDto.setStatus(2);
} else { } else {
StarRecord starRecord = new StarRecord(); StarRecord starRecord = new StarRecord();
...@@ -332,8 +727,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -332,8 +727,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyDto; return replyDto;
} }
@Override private Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId) {
public Integer insertStarRecord(Integer analysisId, Integer roundId, Integer examTitleId, Integer replyId, Integer userId) {
StarRecord starRecord = new StarRecord(); StarRecord starRecord = new StarRecord();
starRecord.setAnalysisId(analysisId); starRecord.setAnalysisId(analysisId);
...@@ -369,41 +763,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -369,41 +763,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return 0; return 0;
} }
@Override private ExamTitleDto getNextExamTitleDtoById(Integer roundId, Integer analysisRoundExamTitleId) {
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) {
List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> roundExamTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
Integer examTitleCount = roundExamTitleList.size(); Integer examTitleCount = roundExamTitleList.size();
...@@ -420,8 +780,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -420,8 +780,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return this.getExamTitleDtoById(roundExamTitleList.get(idx).getId()); return this.getExamTitleDtoById(roundExamTitleList.get(idx).getId());
} }
@Override private Integer insertReply(Integer examTitleId, String content, Integer userId) {
public Integer insertReply(Integer examTitleId, String content, Integer userId) {
/** /**
* 找到我是否已经回复过,如果回复过就编辑,没有就新建 * 找到我是否已经回复过,如果回复过就编辑,没有就新建
*/ */
...@@ -454,8 +813,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -454,8 +813,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
} }
} }
@Override private Integer getReplyStatus(Integer examTitleId, Integer userId) {
public Integer getReplyStatus(Integer examTitleId, Integer userId) {
/** /**
* 用户不存在 * 用户不存在
*/ */
...@@ -483,22 +841,21 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -483,22 +841,21 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return 2; return 2;
} }
@Override private Reply getReplyByExamTitleId(Integer examTitleId, Integer userId) {
public Reply getReplyByExamTitleId(Integer examTitleId, Integer userId) {
Reply reply = new Reply(); Reply reply = new Reply();
reply.setAnalysisRoundExamTitleId(examTitleId); reply.setAnalysisRoundExamTitleId(examTitleId);
reply.setUserId(userId); reply.setUserId(userId);
return replyMapper.selectReplyByRecord(reply); return replyMapper.selectReplyByRecord(reply);
} }
@Override private List<Reply> getReplyList(Integer examTitleId) {
public List<Reply> getReplyList(Integer examTitleId) {
Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId); Integer replyCount = replyMapper.selectReplyCountByAnalysisRoundExamTitleId(examTitleId);
/** /**
* case 1. 按照时间排序,如果个数小于5,直接返回 * case 1. 按照时间排序,如果个数小于5,直接返回
*/ */
List<Reply> replyList = replyMapper.selectReplyListOrderByTime(examTitleId); List<Reply> replyList = replyMapper.selectReplyListOrderByTime(examTitleId);
if (replyCount < 5) { if (replyCount < 5) {
return replyList; return replyList;
} }
...@@ -519,8 +876,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -519,8 +876,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyListOther; return replyListOther;
} }
@Override private List<AnalysisRoundDto> getCHCHistoryRound(Integer analysisId) {
public List<AnalysisRoundDto> getCHCHistoryRound(Integer analysisId) {
List<AnalysisRound> roundList = new ArrayList<>(); List<AnalysisRound> roundList = new ArrayList<>();
/** /**
...@@ -557,8 +913,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -557,8 +913,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return roundDtoList; return roundDtoList;
} }
@Override private Integer getElectedStarCountByRoundId(Integer roundId) {
public Integer getElectedStarCountByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>(); List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) { for (AnalysisRoundExamTitle examTitle : examTitleList) {
...@@ -567,8 +922,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -567,8 +922,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectElectedStarCountByExamTitleIdList(examTitleIdList); return replyMapper.selectElectedStarCountByExamTitleIdList(examTitleIdList);
} }
@Override private Integer getElectedDoctorIdByRoundId(Integer roundId) {
public Integer getElectedDoctorIdByRoundId(Integer roundId) {
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>(); List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) { for (AnalysisRoundExamTitle examTitle : examTitleList) {
...@@ -577,8 +931,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -577,8 +931,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectElectedDoctorIdByExamTitleIdList(examTitleIdList); return replyMapper.selectElectedDoctorIdByExamTitleIdList(examTitleIdList);
} }
@Override private Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
public Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>(); Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>(); List<Integer> examTitleIdList = new ArrayList<>();
...@@ -590,8 +943,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -590,8 +943,7 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return replyMapper.selectStarCountByParam(param); return replyMapper.selectStarCountByParam(param);
} }
@Override private List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
public List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>(); Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId); List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>(); List<Integer> examTitleIdList = new ArrayList<>();
...@@ -626,4 +978,39 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -626,4 +978,39 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
return userExamTitleDtos; 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 @@ ...@@ -38,6 +38,7 @@
seq_no from p_analysis_round seq_no from p_analysis_round
where is_published = 1 where is_published = 1
and is_deleted = 0 and is_deleted = 0
and analysis_id = #{id,jdbcType=INTEGER}
order by seq_no desc order by seq_no desc
limit 1) limit 1)
order by seq_no order by seq_no
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册