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

feature: 我的赞

上级 4d524770
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
<dependency> <dependency>
<groupId>com.pica.cloud.online.exam</groupId> <groupId>com.pica.cloud.online.exam</groupId>
<artifactId>pica-cloud-analysis-common</artifactId> <artifactId>pica-cloud-analysis-common</artifactId>
<version>1.0.4</version> <version>1.0.6</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
......
...@@ -19,6 +19,7 @@ import com.pica.cloud.online.exam.analysis.server.service.DoctorService; ...@@ -19,6 +19,7 @@ import com.pica.cloud.online.exam.analysis.server.service.DoctorService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javassist.bytecode.ExceptionsAttribute; import javassist.bytecode.ExceptionsAttribute;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -625,4 +626,67 @@ public class AnalysisController { ...@@ -625,4 +626,67 @@ public class AnalysisController {
return builder.build(); return builder.build();
} }
@ApiOperation(value = "我的赞", response = PicaResponse.class)
@RequestMapping(value = "/myStar/{roundId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public PicaResponse<MyStarDto> myStar( @PathVariable(value = "roundId", required = false) Integer roundId,
@RequestHeader(required = false) String token) {
if (token == null) {
return ReturnUtil.getPicaResponse(PicaResultCode.SYSTEM_NO_TOKEN);
}
PICAUser user = CommonUtils.getUserByToken(redisClient, token);
if (user == null || user.getId().intValue() == 0) {
System.out.println("myStar: user == null, token=" + token);
return ReturnUtil.getPicaResponse(PicaResultCode.LOGIN_FAILE);
}
if (!rankingListService.isRankingInTop200(user.getId())) {
return ReturnUtil.getPicaResponse(PicaResultCode.PERMISSION_NO_ACCESS);
}
System.out.println("myStar: roundId=" + roundId.toString() + " token=" + token);
PicaResponse.Builder<MyStarDto> builder = new PicaResponse.Builder<>();
MyStarDto myStarDto = new MyStarDto();
myStarDto.setDoctor(doctorService.getDoctorDtoById(user.getId()));
myStarDto.setRoundList(new ArrayList<>());
if (roundId == null) {
List<AnalysisRoundDto> roundDtoList = analysisService.getCHCHistoryRound();
roundId = roundDtoList.get(0).getRoundId();
myStarDto.setRoundList(roundDtoList);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM:dd HH:mm:ss");
AnalysisRound analysisRound = analysisService.getRoundInfoById(roundId);
myStarDto.setStartTime(sdf.format(analysisRound.getStartTime()));
myStarDto.setEndTime(sdf.format(analysisRound.getEndTime()));
/**
* 设置结束状态
*/
if ((new Date()).getTime() > analysisRound.getEndTime().getTime()) {
myStarDto.setIsFinished(1);
} else {
myStarDto.setIsFinished(0);
}
/**
* 设置我的得赞数
*/
myStarDto.setMyStarCount(analysisService.getStarCountByRoundIdAndDoctorId(roundId, user.getId()));
/**
* 设置我是否当选
*/
Integer electedDoctorId = analysisService.getElectedDoctorIdByRoundId(roundId);
myStarDto.setIsElected(electedDoctorId.intValue() == user.getId().intValue() ? 1 : 0);
/**
* 我的解析得赞记录
*/
myStarDto.setMyExamTitleList(analysisService.getMyStarRecordByRoundIdAndDoctorId(roundId, user.getId()));
builder.setData(myStarDto);
return builder.build();
}
} }
...@@ -3,6 +3,7 @@ package com.pica.cloud.online.exam.analysis.server.mapper; ...@@ -3,6 +3,7 @@ package com.pica.cloud.online.exam.analysis.server.mapper;
import com.pica.cloud.online.exam.analysis.server.entity.Reply; import com.pica.cloud.online.exam.analysis.server.entity.Reply;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ReplyMapper { public interface ReplyMapper {
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);
...@@ -52,4 +53,18 @@ public interface ReplyMapper { ...@@ -52,4 +53,18 @@ public interface ReplyMapper {
* @return * @return
*/ */
Integer selectElectedDoctorIdByExamTitleIdList(List<Integer> examTitleIds); Integer selectElectedDoctorIdByExamTitleIdList(List<Integer> examTitleIds);
/**
* 获取某人某轮的获赞数
* @param param
* @return
*/
Integer selectStarCountByParam(Map param);
/**
* 获取某人某轮的获赞记录
* @param param
* @return
*/
List<Reply> selectStarRecordByParam(Map param);
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ import com.pica.cloud.online.exam.analysis.server.entity.AnalysisRound; ...@@ -5,6 +5,7 @@ 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 org.omg.CORBA.INTERNAL;
import java.util.List; import java.util.List;
...@@ -184,4 +185,20 @@ public interface CHCAnalysisService { ...@@ -184,4 +185,20 @@ public interface CHCAnalysisService {
* @return * @return
*/ */
Integer getElectedDoctorIdByRoundId(Integer roundId); Integer getElectedDoctorIdByRoundId(Integer roundId);
/**
* 根据医生id和轮id获取得赞数
* @param roundId
* @param doctorId
* @return
*/
Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId);
/**
* 根据医生id和轮id获取得赞记录
* @param roundId
* @param doctorId
* @return
*/
List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId);
} }
...@@ -13,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* @author wuminghao * @author wuminghao
...@@ -571,4 +569,52 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService { ...@@ -571,4 +569,52 @@ public class CHCAnalysisServiceImpl implements CHCAnalysisService {
} }
return replyMapper.selectElectedDoctorIdByExamTitleIdList(examTitleIdList); return replyMapper.selectElectedDoctorIdByExamTitleIdList(examTitleIdList);
} }
@Override
public Integer getStarCountByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) {
examTitleIdList.add(examTitle.getId());
}
param.put("examTitleList", examTitleIdList);
param.put("doctorId", doctorId);
return replyMapper.selectStarCountByParam(param);
}
@Override
public List<UserExamTitleDto> getMyStarRecordByRoundIdAndDoctorId(Integer roundId, Integer doctorId) {
Map param = new HashMap<>();
List<AnalysisRoundExamTitle> examTitleList = analysisRoundExamTitleMapper.selectExamTitleListByRoundId(roundId);
List<Integer> examTitleIdList = new ArrayList<>();
for (AnalysisRoundExamTitle examTitle : examTitleList) {
examTitleIdList.add(examTitle.getId());
}
param.put("examTitleList", examTitleIdList);
param.put("doctorId", doctorId);
List<Reply> replyList = replyMapper.selectStarRecordByParam(param);
List<UserExamTitleDto> userExamTitleDtos = new ArrayList<>();
for (int idx = 0; idx < examTitleIdList.size(); ++ idx) {
UserExamTitleDto userExamTitleDto = new UserExamTitleDto();
userExamTitleDto.setExamTitleId(examTitleIdList.get(idx));
userExamTitleDto.setSeqNo(idx + 1);
boolean isReplied = false;
Integer starCount = 0;
for (Reply reply : replyList) {
if (reply.getAnalysisRoundExamTitleId().intValue() == examTitleIdList.get(idx).intValue()) {
isReplied = true;
starCount = reply.getStarCount();
break;
}
}
userExamTitleDto.setIsReplied(isReplied ? 1 : 0);
userExamTitleDto.setStarCount(starCount);
}
return userExamTitleDtos;
}
} }
...@@ -110,6 +110,31 @@ ...@@ -110,6 +110,31 @@
limit 1 limit 1
</select> </select>
<select id="selectStarCountByParam" resultType="java.lang.Integer">
select
sum(star_count)
from p_reply
where analysis_round_exam_title_id in
<foreach item="item" index="index" collection="examTitleList" open="(" separator="," close=")">
#{item}
</foreach>
and is_deleted = 0
and user_id = #{doctorId,jdbcType=INTEGER}
</select>
<select id="selectStarRecordByParam" resultType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from p_reply
where analysis_round_exam_title_id in
<foreach item="item" index="index" collection="examTitleList" open="(" separator="," close=")">
#{item}
</foreach>
and is_deleted = 0
and user_id = #{doctorId,jdbcType=INTEGER}
order by analysis_round_exam_title_id
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_reply delete from p_reply
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册