Commit 721486a8 by 梅存智

Merge branch 'dev' into 'master'

投票单选、投票排行榜

See merge request !3
parents ee01c1b0 e83988f2
......@@ -2,6 +2,7 @@ package com.yizhi.research.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import com.yizhi.research.application.vo.domain.VoteRankingVo;
import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
......@@ -86,4 +87,19 @@ public interface ResearchQuestionClient {
@GetMapping("/researchQuestion/getFinishedAccountIds")
List<Long> getFinishedAccountIds(@RequestParam("researchId") Long researchId,@RequestParam("companyId") Long companyId,@RequestParam("siteId")Long siteId);
/**
* 获取投票结果
* @param researchId
* @return
*/
@GetMapping("/researchQuestion/getVoteResult")
VoteRankingVo getVoteResult(@RequestParam("researchId") Long researchId);
/**
* 获取投票排行榜
* @param researchId
* @return
*/
@GetMapping("/researchQuestion/getVoteTop")
VoteRankingVo getVoteTop(@RequestParam("researchId") Long researchId);
}
......@@ -235,4 +235,13 @@ public class ResearchVo {
@ApiModelProperty(value = "调研logo")
private String logoImg;
@ApiModelProperty(value = "业务类型:1调研;2投票")
private Integer bizType;
@ApiModelProperty(value = "呈现样式:1逐题呈现;2整页呈现;3整页投票单选")
private Integer pageMode;
@ApiModelProperty(value = "投票选择次数:0无限制")
private Integer voteNum;
}
......@@ -179,7 +179,10 @@ public class TrResearchQuestionVo extends Model<TrResearchQuestionVo> {
@ApiModelProperty(value = "调研说明")
private String researchContent;
private String researchContent;
@ApiModelProperty(value = "关键字")
private String keywords;
@Override
protected Serializable pkVal() {
......
package com.yizhi.research.application.vo.domain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@Api(tags = "VoteRankingListVo", description = "调研排行榜")
public class VoteRankingListVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "问题主键ID,主键")
private Long id;
@ApiModelProperty(value = "存放附件路径,附件格式:音频、视频、图片")
private String contentAppendixUrl;
@ApiModelProperty(value = "问题内容")
private String content;
@ApiModelProperty(value = "关键字")
private String keywords;
@ApiModelProperty(value = "序号")
private Integer no;
@ApiModelProperty(value = "剩余投票次数")
private Integer voteNum = 0;
@ApiModelProperty(value = "投票量")
private Integer voteCount = 0;
@ApiModelProperty(value = "true=已投票;false未投票")
private Boolean answerState;
}
package com.yizhi.research.application.vo.domain;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@Api(tags = "VoteRankingVo", description = "调研排行榜")
public class VoteRankingVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "调研主键ID,主键")
private Long id;
@ApiModelProperty(value = "调研名称")
private String name;
@ApiModelProperty(value = "剩余投票次数")
private Integer voteNum = 0;
@ApiModelProperty(value = "调研问题")
private List<VoteRankingListVo> rankingList;
}
......@@ -11,6 +11,8 @@ import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOptionVo;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import com.yizhi.research.application.vo.domain.VoteRankingVo;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -167,5 +169,24 @@ public class TrResearchQuestionController {
return researchQuestionService.getFinishedAccountIds(researchId, companyId, siteId);
}
/**
* 获取投票结果
* @param researchId
* @return
*/
@GetMapping("/getVoteResult")
VoteRankingVo getVoteResult(@RequestParam("researchId") Long researchId) {
return researchQuestionService.getVoteResult(researchId);
}
/**
* 获取投票排行榜
* @param researchId
* @return
*/
@GetMapping("/getVoteTop")
VoteRankingVo getVoteTop(@RequestParam("researchId") Long researchId) {
return researchQuestionService.getVoteTop(researchId);
}
}
......@@ -118,6 +118,8 @@
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
,tb.biz_type
,tb.page_mode
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
......@@ -152,6 +154,8 @@
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
,tb.biz_type
,tb.page_mode
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
......@@ -197,6 +201,8 @@
,tb.org_id AS orgId
,tb.site_id AS siteId
,tb.image
,tb.biz_type
,tb.page_mode
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId} and answer.finish=1
left join tr_research_answer answerf on answer.research_id = tb.id and answerf.account_id = #{accountId} and answerf.finish in(0,1)
......@@ -210,7 +216,9 @@
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
and tb.biz_type=#{bizType}
<if test="bizType != null">
and tb.biz_type=#{bizType}
</if>
group by tb.id
)t
order by t.endTime desc,id
......@@ -420,7 +428,9 @@
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
and tb.biz_type=#{bizType}
<if test="bizType != null">
and tb.biz_type=#{bizType}
</if>
group by tb.id
</if>
)ttt
......@@ -586,6 +596,8 @@
,tb.content AS content
,tb.remark
,tb.image
,tb.page_mode
,tb.vote_num
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId} and answer.finish=1
left join tr_research_answer answerf on answer.research_id = tb.id and answerf.account_id = #{accountId} and answerf.finish in(0,1)
......
......@@ -2,6 +2,8 @@ package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.VoteRankingVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
......@@ -89,5 +91,16 @@ public interface TrResearchQuestionMapper extends BaseMapper<TrResearchQuestion>
void updateJumpNum(@Param("ids") List<Long> ids);
/**
* 获取投票结果
* @param companyId
* @param siteId
* @param researchId
* @param accountId
* @param isTop
* @return
*/
VoteRankingVo getVoteResult(@Param("companyId") Long companyId, @Param("siteId") Long siteId, @Param("researchId") Long researchId, @Param("accountId") Long accountId, @Param("isTop") boolean isTop);
}
......@@ -27,6 +27,21 @@
<result column="tb_org_id" property="orgId" />
<result column="tb_site_id" property="siteId" />
</resultMap>
<resultMap id="getVoteResultMap" type="com.yizhi.research.application.vo.domain.VoteRankingVo">
<result property="id" column="id"/>
<result property="name" column="name"/>
<collection property="rankingList" ofType="com.yizhi.research.application.vo.domain.VoteRankingListVo">
<result property="id" column="questionId"/>
<result property="no" column="no"/>
<result property="contentAppendixUrl" column="content_appendix_url"/>
<result property="content" column="content"/>
<result property="keywords" column="keywords"/>
<result property="top" column="top"/>
<result property="voteCount" column="voteCount"/>
<result property="answerState" column="answerState"/>
</collection>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
......@@ -159,4 +174,35 @@
#{id}
</foreach>
</update>
<select id="getVoteResult" resultMap="getVoteResultMap">
SELECT r.id,r.name,a.id AS questionId,a.no,a.content_appendix_url,b.content, a.keywords,COUNT(c.id) AS voteCount
<if test="isTop == null or isTop == false" >
,IFNULL(myanswer.answerState,0) AS answerState
</if>
FROM tr_research_question a
INNER JOIN tr_research_question_option b ON a.id=b.question_id AND b.deleted=0
LEFT JOIN tr_research_answer_question_result c ON c.option_id=b.id
LEFT JOIN research r ON a.research_id=r.id AND r.deleted=0
<if test="isTop == null or isTop == false" >
LEFT JOIN(
SELECT myb.question_id,COUNT(myb.question_id) AS answerState
FROM tr_research_answer mya
INNER JOIN tr_research_answer_question myb ON myb.answer_id=mya.id AND myb.deleted=0
INNER JOIN tr_research_answer_question_result myc ON myc.answer_question_id=myb.id AND myc.option_id IS NOT NULL
WHERE mya.research_id=#{researchId} AND mya.account_id=#{accountId} AND mya.finish=1
GROUP BY myb.question_id
) myanswer ON b.question_id=myanswer.question_id
</if>
WHERE a.research_id=#{researchId} AND a.company_id=#{companyId} AND a.site_id=#{siteId} AND a.deleted=0
GROUP BY b.question_id
<if test="isTop != null and isTop == true" >
ORDER BY COUNT(c.id) DESC,MIN(c.create_time)
</if>
<if test="isTop != null and isTop == false" >
ORDER BY a.no
</if>
</select>
</mapper>
......@@ -6,6 +6,8 @@ import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.VoteRankingVo;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
......@@ -72,4 +74,19 @@ public interface ITrResearchQuestionService extends IService<TrResearchQuestion>
Integer updateQuestionJump(QuestionJumpVo vo);
List<Long> getFinishedAccountIds(Long researchId, Long companyId, Long siteId);
/**
* 获取投票结果
* @param researchId
* @return
*/
VoteRankingVo getVoteResult(Long researchId);
/**
* 获取投票排行榜
* 按投票票数升序、票数相同时按谁先被投票的
* @param researchId
* @return
*/
VoteRankingVo getVoteTop(Long researchId);
}
......@@ -869,6 +869,10 @@ public class ResearchServiceImpl extends ServiceImpl<ResearchMapper, Research> i
}
ResearchVo research = researchMapper.selectResearchDetails(id, requestContext.getAccountId(), requestContext.getSiteId());
//投票完成或过期选择次数0
if(research.getFinishState() == 1 || research.getFinishState() == 2){
research.setVoteNum(0);
}
return research;
}
......
......@@ -3,6 +3,7 @@ package com.yizhi.research.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
......@@ -1012,4 +1013,28 @@ public class TrResearchQuestionServiceImpl extends ServiceImpl<TrResearchQuestio
}
return noToOptions;
}
@Override
public VoteRankingVo getVoteResult(Long researchId) {
RequestContext context = ContextHolder.get();
Long companyId = context.getCompanyId();
Long siteId = context.getSiteId();
return researchQuestionMapper.getVoteResult(companyId, siteId, researchId, context.getAccountId(), false);
}
@Override
public VoteRankingVo getVoteTop(Long researchId) {
RequestContext context = ContextHolder.get();
Long companyId = context.getCompanyId();
Long siteId = context.getSiteId();
VoteRankingVo result = researchQuestionMapper.getVoteResult(companyId, siteId, researchId, context.getAccountId(), true);
if(result != null && !CollectionUtils.isEmpty(result.getRankingList())){
int no = 1;
for(VoteRankingListVo item : result.getRankingList()){
item.setNo(no++);
}
}
return result;
}
}
......@@ -235,6 +235,15 @@ public class Research extends Model<Research> {
private String image;
@ApiModelProperty(value = " 业务类型:1调研;2投票")
private Integer bizType;
@ApiModelProperty(value = "呈现样式:1逐题呈现;2整页呈现;3整页投票单选")
private Integer pageMode;
@ApiModelProperty(value = "投票选择次数:0无限制")
private Integer voteNum;
@Override
protected Serializable pkVal() {
return this.id;
......
......@@ -180,7 +180,11 @@ public class TrResearchQuestion extends Model<TrResearchQuestion> {
@ApiModelProperty(value = "调研说明")
@TableField(exist = false)
private String researchContent;
@ApiModelProperty(value = "关键字")
@TableField("keywords")
private String keywords;
@Override
protected Serializable pkVal() {
return this.id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment