jug
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package io.v.nutz.fitnessWalk.model;
|
||||
|
||||
import io.v.nutz.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table
|
||||
@Data
|
||||
@Comment("打卡模式抽奖记录")
|
||||
public class FitnessWalkPunchLottery extends BaseModel {
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@Comment("活动")
|
||||
private String activityId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@Comment("中奖用户")
|
||||
private String userName;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
@Comment("奖品名称")
|
||||
private String prizeName;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
@Comment("奖品")
|
||||
private String prizeId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否中奖")
|
||||
private Boolean isWin;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
@Comment("是否中奖")
|
||||
private Date winDate;
|
||||
|
||||
}
|
||||
@@ -5,14 +5,14 @@ import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.base.utils.WxHttpUtil;
|
||||
import io.v.nutz.jsz.services.JszTypeService;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.question.model.Question_reply;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.web.commons.base.Globals;
|
||||
import io.v.nutz.zhgh.question.model.Question_issue;
|
||||
import io.v.nutz.zhgh.question.model.Question_reply;
|
||||
import io.v.nutz.zhgh.question.service.QuestionIssueService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionReplyService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionWorService;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
|
||||
@@ -1,375 +0,0 @@
|
||||
package io.v.nutz.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.activity.models.ActivityUserScope;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.*;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 问卷H5
|
||||
*
|
||||
* @author jug
|
||||
* @date 2023/04/24
|
||||
*/
|
||||
@IocBean
|
||||
@At("/mobile/question/h5")
|
||||
@Ok("json:full")
|
||||
public class QuestionH5Controller {
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At("/list")
|
||||
@Ok("beetl:/mobile/question/list.html")
|
||||
public void list() {
|
||||
|
||||
}
|
||||
|
||||
@At("/poll/index")
|
||||
@Ok("beetl:/mobile/question/poll.html")
|
||||
public void pollIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/shop/index")
|
||||
@Ok("beetl:/mobile/question/shop.html")
|
||||
public void shopIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/cake/index")
|
||||
@Ok("beetl:/mobile/question/cake.html")
|
||||
public void cakeIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/answer/index")
|
||||
@Ok("beetl:/mobile/question/answer.html")
|
||||
public void answerIndex() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 页面数据
|
||||
*
|
||||
* @param pageForm 页面形式
|
||||
* @param status 状态 进行中1 已结束2
|
||||
* @param type 类型 问卷类型
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/pageData")
|
||||
public Object pageData(PageForm pageForm, int status, int type) {
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
q.*,
|
||||
(select count(1) from question_issue where iqid = q.qid and displayDate = @today) as topicTotal
|
||||
from
|
||||
question q
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("today", DateUtil.today());
|
||||
Cnd cnd = Cnd.NEW();
|
||||
long now = System.currentTimeMillis();
|
||||
if (status == 1) {
|
||||
cnd.and("q.startTime", "<", now);
|
||||
cnd.and("q.endTime", ">", now);
|
||||
} else {
|
||||
cnd.and("q.endTime", "<", now);
|
||||
}
|
||||
cnd.and("q.qlx", "=", type);
|
||||
cnd.and("q.qflag", "=", 2);
|
||||
cnd.desc("q.startTime");
|
||||
sql.setCondition(cnd);
|
||||
|
||||
Pagination pagination = questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参加权限
|
||||
*
|
||||
* @param activityUserScopeId 活动用户范围id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/checkPermission/?")
|
||||
public Object checkPermission(String activityUserScopeId) {
|
||||
boolean exists = questionService.dao().count(ActivityUserScope.class, Cnd.where("groupId", "=", activityUserScopeId).and("userId", "=", ShiroUtil.getPrincipalProperty("id"))) > 0;
|
||||
return Result.success(exists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 问卷信息
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/questionInfo/{id}")
|
||||
public Object questionInfo(@PathVariable String id) {
|
||||
Question question = questionService.fetch(id);
|
||||
|
||||
Cnd issueCnd = Cnd.NEW();
|
||||
|
||||
//出题模式
|
||||
// mode==1 定时定题 直接查询
|
||||
// mode==2 先查询今天的随机题目有没有设置好 设置好了直接查询今天的题目 没有的话查询displayDate为null的题目然后取题目再设置时间进行查询
|
||||
Integer ctMode = question.getCtMode();
|
||||
if (ctMode == 2) {
|
||||
//单次出题的数量
|
||||
Integer ctNum = question.getCtNum();
|
||||
int todayIssueCount = dao.count(Question_issue.class, Cnd.where("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"))
|
||||
.and("iqid", "=", id));
|
||||
if (todayIssueCount == 0) {
|
||||
Sql randIssueSql = Sqls.create("SELECT iid FROM question_issue WHERE iqid = @qid AND displayDate IS NULL ORDER BY RAND() LIMIT @ctNum");
|
||||
randIssueSql.setParam("qid", id);
|
||||
randIssueSql.setParam("ctNum", ctNum);
|
||||
String[] randIssueIds = (String[]) Daos.query(dao, randIssueSql.toString(), Sqls.callback.strs());
|
||||
dao.update(Question_issue.class, Chain.make("displayDate", new Date()), Cnd.where("iid", "in", randIssueIds));
|
||||
}
|
||||
// issueCnd.and("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
issueCnd.asc("ipxbh");
|
||||
questionService.fetchLinks(question, "issues", issueCnd);
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
questionService.fetchLinks(issue, "wors", Cnd.NEW().asc("wpxbh"));
|
||||
}
|
||||
return Result.success(question);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存答案
|
||||
*
|
||||
* @param repliesArray 回复
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/saveAnswer")
|
||||
public Object saveAnswer(@Param("repliesArray") Question_reply[] repliesArray) {
|
||||
if (Lang.isNotEmpty(repliesArray)) {
|
||||
List<Question_reply> replies = Arrays.asList(repliesArray);
|
||||
if (Lang.isNotEmpty(replies)) {
|
||||
String qid = replies.get(0).getQid();
|
||||
questionService.dao().clear(Question_reply.class, Cnd.where("qid", "=", qid).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
replies.forEach(v -> {
|
||||
v.setUserId(String.valueOf(ShiroUtil.getPrincipalProperty("id")));
|
||||
v.setRtime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
questionService.insert(replies);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存答案 只针对答题模式
|
||||
*
|
||||
* @param replies 问题回复
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/saveAnswer2")
|
||||
public Object saveAnswer2(Question_reply[] replies) {
|
||||
if (Lang.isNotEmpty(replies)) {
|
||||
Arrays.asList(replies).forEach(v -> {
|
||||
v.setUserId(String.valueOf(ShiroUtil.getPrincipalProperty("id")));
|
||||
v.setRtime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
questionService.insert(replies);
|
||||
insertQuestionAnswerScore(Arrays.asList(replies));
|
||||
insertQuestionAnswerScore2(Arrays.asList(replies));
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public void insertQuestionAnswerScore(List<Question_reply> replyList) {
|
||||
//用户id
|
||||
String userId = (String) ShiroUtil.getPrincipalProperty("id");
|
||||
//问卷id
|
||||
String questionId = replyList.get(0).getQid();
|
||||
//题目id
|
||||
String issueId = replyList.get(0).getIssueId();
|
||||
|
||||
Question_issue issue = dao.fetch(Question_issue.class, Cnd.where("iid", "=", issueId));
|
||||
Integer fraction = issue.getFraction();
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT wid FROM question_wor qw WHERE qw.correct = 1 AND qw.wiid = @wiid
|
||||
""").setParam("wiid", issueId);
|
||||
//正确的选项
|
||||
Set<String> correctOptionIdList = new HashSet<>((List<String>) Daos.query(dao, sql.toString(), Sqls.callback.strList()));
|
||||
//用户选的选项
|
||||
Set<String> userSelectedOptionIdList = replyList.stream().map(v -> v.getRwid()).collect(Collectors.toSet());
|
||||
|
||||
int count = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId).and("subjectId", "=", issueId).and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")).and("userId", "=", userId));
|
||||
|
||||
QuestionAnswerUserScore answerUserScore = new QuestionAnswerUserScore();
|
||||
answerUserScore.setQuestionId(questionId);
|
||||
answerUserScore.setSubjectId(issueId);
|
||||
answerUserScore.setUserId(userId);
|
||||
answerUserScore.setAnswerDate(new Date());
|
||||
answerUserScore.setAnswerNum(count + 1);
|
||||
|
||||
if (correctOptionIdList.equals(userSelectedOptionIdList)) {
|
||||
answerUserScore.setSubjectScore(fraction);
|
||||
} else {
|
||||
answerUserScore.setSubjectScore(0);
|
||||
}
|
||||
dao.insert(answerUserScore);
|
||||
}
|
||||
|
||||
public void insertQuestionAnswerScore2(List<Question_reply> replyList) {
|
||||
//问卷id
|
||||
String questionId = replyList.get(0).getQid();
|
||||
//查询今天的题目
|
||||
List<Question_issue> todayIssues = dao.query(Question_issue.class, Cnd.where("displayDate", "=", DateUtil.today())
|
||||
.and("iqid", "=", questionId));
|
||||
if (todayIssues != null && todayIssues.size() > 0) {
|
||||
Set<String> todayIssueIds = todayIssues.stream().map(v -> v.getIid()).collect(Collectors.toSet());
|
||||
//判断今天的题目是否已答完
|
||||
List<Question_reply> replyIssues = dao.query(Question_reply.class, Cnd.where("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("qid", "=", questionId));
|
||||
Set<String> replyIssueIds = replyIssues.stream().map(v -> v.getIssueId()).collect(Collectors.toSet());
|
||||
if (todayIssueIds.equals(replyIssueIds)) {
|
||||
//答完了 去看看今天有没有答过
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("answerDate", "=", DateUtil.today()));
|
||||
|
||||
AtomicInteger sum = new AtomicInteger();
|
||||
|
||||
//每题的回答记录
|
||||
Map<String, List<Question_reply>> issueReplies = replyIssues.stream().collect(Collectors.groupingBy(v -> v.getIssueId()));
|
||||
|
||||
//查出选项信息
|
||||
dao.fetchLinks(todayIssues, "wors");
|
||||
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(x -> x.getRwid()).collect(Collectors.toSet());
|
||||
|
||||
Optional<Question_issue> issueOptional = todayIssues.stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
|
||||
//正确答案
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId((String) ShiroUtil.getPrincipalProperty("id"));
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
dao.insert(questionUserScore);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 答题信息
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerInfo/?")
|
||||
public Object answerInfo(String id) {
|
||||
List<Question_reply> replies = questionService.dao().query(Question_reply.class, Cnd.where("qid", "=", id).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
return Result.success(replies);
|
||||
}
|
||||
|
||||
/**
|
||||
* 再答一次
|
||||
*
|
||||
* @param questionId 问题id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerAgain")
|
||||
public Object answerAgain(String questionId) {
|
||||
Sql issueIdsSql = Sqls.create("select iid from question_issue where iqid = @qid").setParam("qid", questionId);
|
||||
String[] issueIds = (String[]) Daos.query(dao, issueIdsSql.toString(), Sqls.callback.strs());
|
||||
//清空本日的答题记录
|
||||
dao.clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getPlatformUid()).and("issueId", "in", issueIds));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At("/winInfo")
|
||||
public Object winInfo(String questionId) {
|
||||
// List<QuestionWinner> winners = dao.query(QuestionWinner.class, Cnd.where("questionId", "=", questionId));
|
||||
// return Result.success(winners);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.username,
|
||||
qw.winDate,
|
||||
u.id
|
||||
FROM
|
||||
`question_winner` qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
WHERE
|
||||
qw.questionId = @questionId
|
||||
""");
|
||||
sql.setParam("questionId", questionId);
|
||||
List<NutMap> list = questionService.listMap(sql);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@At("/canAnswer")
|
||||
public Object canAnswer(String questionId) {
|
||||
|
||||
//每天的题目数量
|
||||
int issueCount = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId).and("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
|
||||
//当前最大答题次数
|
||||
int maxCount = dao.func(QuestionAnswerUserScore.class, "max", "answerNum", Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
|
||||
//最大答题次数已经答了多少题
|
||||
int answerIssue = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("answerNum", "=", maxCount));
|
||||
|
||||
return Result.success(answerIssue < issueCount);
|
||||
|
||||
}
|
||||
|
||||
@At("/todayMaxScore")
|
||||
public Object todayMaxScore(String questionId) {
|
||||
List<QuestionUserScore> userScores = dao.query(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
.and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
|
||||
Map<Integer, Integer> numScoreMap = userScores.stream().collect(Collectors.toMap(v -> v.getAnswerNum(), v -> v.getScore()));
|
||||
|
||||
// List<QuestionAnswerUserScore> list = dao.query(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
// .and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
// .and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
//
|
||||
// Map<Integer, Integer> numScoreMap = list.stream().collect(Collectors.groupingBy(v -> v.getAnswerNum(), Collectors.summingInt(v -> v.getSubjectScore())));
|
||||
return Result.success(numScoreMap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.v.nutz.question.service;
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* Created by 李耀威 on 2020-02-19
|
||||
* info by 问卷调查 service
|
||||
*/
|
||||
public interface QuestionService extends ViService<Question> {
|
||||
Question getQuestion(String qid);
|
||||
|
||||
NutMap getVoteData(String qid);
|
||||
|
||||
NutMap getRankData(String qid);
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "Zgfw_question")
|
||||
public class QuestionServiceImpl extends ViServiceImpl<Question> implements QuestionService {
|
||||
@Inject
|
||||
private QuestionIssueService questionIssueService;
|
||||
@Inject
|
||||
private QuestionWorService questionWorService;
|
||||
@Inject
|
||||
private QuestionReplyService questionReplyService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
public QuestionServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Question getQuestion(String qid) {
|
||||
Question question = fetch(qid);
|
||||
question.setIssues(questionIssueService.query(Cnd.where("iqid", "=", qid).asc("ipxbh")));
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
issue.setWors(questionWorService.query(Cnd.where("wiid", "=", issue.getIid()).asc("wpxbh")));
|
||||
}
|
||||
return question;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap getVoteData(String qid) {
|
||||
Question_issue issue = questionIssueService.fetch(Cnd.where("iqid", "=", qid));
|
||||
NutMap res = new NutMap();
|
||||
//选项数
|
||||
res.setv("optionum", questionWorService.count(Cnd.where("wiid", "=", issue.getIid())));
|
||||
//投票总数
|
||||
int votecount = questionReplyService.count(Sqls.create("SELECT COUNT(1) FROM question_reply r WHERE r.`rwid` IN (SELECT w.`wid` FROM zgfw_question_wor w WHERE w.`wiid` = @iid)").setParam("iid", issue.getIid()));
|
||||
res.setv("votecount", votecount);
|
||||
|
||||
Sql sql = Sqls.create("SELECT w.`wid`,(SELECT COUNT(1) FROM question_reply r WHERE r.rwid=w.`wid`) COUNT FROM zgfw_question_wor w WHERE w.`wiid` = @iid").setParam("iid", issue.getIid());
|
||||
for (Record record : questionWorService.list(sql)) {
|
||||
res.setv(record.getString("wid"), record.getInt("count"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap getRankData(String qid) {
|
||||
NutMap res = new NutMap();
|
||||
Question question = getQuestion(qid);
|
||||
res.setv("qid", qid);
|
||||
res.setv("qtitle", question.getQtitle());
|
||||
|
||||
Question_issue issue = questionIssueService.fetch(Cnd.where("iqid", "=", qid));
|
||||
res.setv("iname", issue.getIname());
|
||||
//选项数
|
||||
res.setv("optionum", questionWorService.count(Cnd.where("wiid", "=", issue.getIid())));
|
||||
//投票总数
|
||||
int votecount = questionReplyService.count(Sqls.create("SELECT COUNT(1) FROM question_reply r WHERE r.`rwid` IN (SELECT w.`wid` FROM zgfw_question_wor w WHERE w.`wiid` = @iid)").setParam("iid", issue.getIid()));
|
||||
res.setv("votecount", votecount);
|
||||
|
||||
Sql sql = Sqls.create("SELECT w.`wid`,w.`wimg`,w.`wtxt`,(SELECT COUNT(1) FROM question_reply r WHERE r.rwid=w.`wid`) COUNT FROM zgfw_question_wor w WHERE w.`wiid` = @iid ORDER BY COUNT DESC").setParam("iid", issue.getIid());
|
||||
res.setv("wors", questionWorService.list(sql));
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -397,4 +397,8 @@ public class ShiroUtil {
|
||||
|
||||
return Lang.isNotEmpty(ids) ? ids : null;
|
||||
}
|
||||
|
||||
public static String getUserId() {
|
||||
return (String) getPrincipalProperty("id");
|
||||
}
|
||||
}
|
||||
+21
-88
@@ -1,15 +1,16 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.sys.services.SysUnionService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.question.service.QuestionAnswerRankingService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -40,6 +41,9 @@ public class QuestionAnswerRankingController {
|
||||
@Inject
|
||||
private SysUnionService sysUnionService;
|
||||
|
||||
@Inject
|
||||
private QuestionAnswerRankingService questionAnswerRankingService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/question/ranking.html")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
@@ -49,96 +53,25 @@ public class QuestionAnswerRankingController {
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "answerDate",required = false) String answerDate) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
MAX( score ) AS max_score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId", "qus.answerDate");
|
||||
cnd.desc("qus.userId").desc("max_score");
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
return questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "answerDate", required = false) String answerDate) {
|
||||
Pagination pagination = questionAnswerRankingService.pageData(pageForm, questionId, unionId, unitId, answerDate);
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public void doExport(@Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "answerDate",required = false) String answerDate, HttpServletResponse response) {
|
||||
public void doExport(@Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "answerDate", required = false) String answerDate, HttpServletResponse response) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
MAX( score ) AS max_score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId", "qus.answerDate");
|
||||
cnd.desc("qus.userId").desc("max_score");
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> dataList = questionService.listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "max_score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String(("得分名单.xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, dataList);
|
||||
workbook.write(response.getOutputStream());
|
||||
|
||||
questionAnswerRankingService.exportXlsx(questionId, response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -147,7 +80,7 @@ public class QuestionAnswerRankingController {
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public void doExportAll(@Param(value = "questionId",required = false) String questionId, HttpServletResponse response) {
|
||||
public void doExportAll(@Param(value = "questionId", required = false) String questionId, HttpServletResponse response) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
@@ -210,7 +143,7 @@ public class QuestionAnswerRankingController {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("YEAR(qctime)", "=", year);
|
||||
if (!ShiroUtil.hasRole("sysadmin")) {
|
||||
cnd.and("qcreator", "=", ShiroUtil.getUserId());
|
||||
cnd.and("qcreator", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
}
|
||||
cnd.and("qflag", "=", 2);
|
||||
cnd.desc("qctime");
|
||||
+9
-9
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
@@ -9,9 +9,9 @@ import cn.wizzer.framework.base.Result;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.QuestionWinner;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.QuestionWinner;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -63,8 +63,8 @@ public class QuestionAnswerWinnerController {
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
(select max(score) from question_user_score where questionId = qw.questionId and userId = qw.userId and answerDate = DATE_SUB( qw.winDate, INTERVAL 0 DAY )) maxScore,
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate,
|
||||
qw.score
|
||||
FROM
|
||||
question_winner qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
@@ -108,8 +108,8 @@ public class QuestionAnswerWinnerController {
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
(select max(score) from question_user_score where questionId = qw.questionId and userId = qw.userId and answerDate = DATE_SUB( qw.winDate, INTERVAL 0 DAY )) maxScore,
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate,
|
||||
qw.score
|
||||
FROM
|
||||
question_winner qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
@@ -132,7 +132,7 @@ public class QuestionAnswerWinnerController {
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("中奖日期", "winDate", 20));
|
||||
exportEntities.add(new ExcelExportEntity("抽奖分数(最高分)", "maxScore", 20));
|
||||
exportEntities.add(new ExcelExportEntity("抽奖分数", "score", 20));
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String(("中奖名单.xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.util.ViTool;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
@@ -0,0 +1,548 @@
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.activity.models.ActivityUserScope;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.question.model.*;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 问卷H5
|
||||
*
|
||||
* @author jug
|
||||
* @date 2023/04/24
|
||||
*/
|
||||
@IocBean
|
||||
@At("/mobile/question/h5")
|
||||
@Ok("json:full")
|
||||
public class QuestionH5Controller {
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At("/list")
|
||||
@Ok("beetl:/mobile/question/list.html")
|
||||
@RequiresAuthentication
|
||||
public void list() {
|
||||
|
||||
}
|
||||
|
||||
@At("/poll/index")
|
||||
@Ok("beetl:/mobile/question/poll.html")
|
||||
public void pollIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/shop/index")
|
||||
@Ok("beetl:/mobile/question/shop.html")
|
||||
public void shopIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/cake/index")
|
||||
@Ok("beetl:/mobile/question/cake.html")
|
||||
public void cakeIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/answer/index")
|
||||
@Ok("beetl:/mobile/question/answer.html")
|
||||
@RequiresAuthentication
|
||||
public void answerIndex() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 页面数据
|
||||
*
|
||||
* @param pageForm 页面形式
|
||||
* @param status 状态 进行中1 已结束2
|
||||
* @param type 类型 问卷类型
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/pageData")
|
||||
public Object pageData(PageForm pageForm, int status, int type) {
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
q.*
|
||||
from
|
||||
question q
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("today", DateUtil.today());
|
||||
Cnd cnd = Cnd.NEW();
|
||||
long now = System.currentTimeMillis();
|
||||
if (status == 1) {
|
||||
cnd.and("q.startTime", "<", now);
|
||||
cnd.and("q.endTime", ">", now);
|
||||
} else {
|
||||
cnd.and("q.endTime", "<", now);
|
||||
}
|
||||
cnd.and("q.qlx", "=", type);
|
||||
cnd.and("q.qflag", "=", 2);
|
||||
cnd.desc("q.startTime");
|
||||
sql.setCondition(cnd);
|
||||
|
||||
Pagination pagination = questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参加权限
|
||||
*
|
||||
* @param activityUserScopeId 活动用户范围id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/checkPermission/?")
|
||||
public Object checkPermission(String activityUserScopeId) {
|
||||
boolean exists = questionService.dao().count(ActivityUserScope.class, Cnd.where("groupId", "=", activityUserScopeId).and("userId", "=", ShiroUtil.getPrincipalProperty("id"))) > 0;
|
||||
return Result.success(exists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 问卷信息
|
||||
*
|
||||
* @param id id
|
||||
* @param currentDate 日期
|
||||
* @param randomCount 轮数
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/questionInfo/{id}")
|
||||
public Object questionInfo(@PathVariable String id,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = questionService.fetch(id);
|
||||
Cnd issueCnd = Cnd.NEW();
|
||||
|
||||
Integer ctMode = question.getCtMode();
|
||||
|
||||
if (ctMode == 1) {
|
||||
//定时定题
|
||||
|
||||
//判断传入的日期是否已经加入到表里
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate));
|
||||
if (Lang.isEmpty(randomIssue)) {
|
||||
Sql issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid AND displayDate = @displayDate");
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setParam("displayDate", currentDate);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(currentDate));
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", randomIssue.getIssueIds());
|
||||
}
|
||||
} else if (ctMode == 2) {
|
||||
//随机模式
|
||||
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
//每次随机的题目数量
|
||||
Integer ranDomSingleIssueNum = question.getRanDomSingleIssueNum();
|
||||
//总共随机几次
|
||||
Integer ranDomSum = question.getRanDomSum();
|
||||
|
||||
if (betweenDay == 0) {
|
||||
//同一天 一天随机多次
|
||||
|
||||
if (randomCount != null) {
|
||||
QuestionRandomIssue randomIssues = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()).and("num", "=", randomCount));
|
||||
issueCnd.andEX("iid", "in", randomIssues.getIssueIds());
|
||||
} else {
|
||||
//用户的随机题目
|
||||
List<QuestionRandomIssue> randomIssues = dao.query(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
//查询已经随机但是并没有答题完成的题目
|
||||
List<String> notFinishIssueIds = randomIssues.stream().filter(v -> v.getIsFinish() != null && !v.getIsFinish()).findFirst().map(QuestionRandomIssue::getIssueIds).orElseGet(Collections::emptyList);
|
||||
|
||||
if (Lang.isNotEmpty(notFinishIssueIds)) {
|
||||
//就查询没答完的题目
|
||||
issueCnd.and("iid", "in", notFinishIssueIds);
|
||||
} else {
|
||||
//进行下一次随机 然后加入到随机题目表里
|
||||
//已经答了的题目
|
||||
List<String> hasAnswerIssueIds = randomIssues.stream().flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
//已经随机几次了
|
||||
int maxAnswerNum = randomIssues.stream().mapToInt(QuestionRandomIssue::getNum).max().orElse(0);
|
||||
|
||||
Sql issueSql = null;
|
||||
if (maxAnswerNum == ranDomSum) {
|
||||
//随机完了 没有题目了 默认去最后一轮
|
||||
// issueCnd.andEX("iid", "in", hasAnswerIssueIds);
|
||||
List<String> lastRanDomIssueIds = randomIssues.stream().filter(v -> v.getNum() == maxAnswerNum).flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
issueCnd.andEX("iid", "in", lastRanDomIssueIds);
|
||||
} else {
|
||||
if (maxAnswerNum == 0) {
|
||||
//从没有随即过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid ORDER BY RAND() LIMIT @num");
|
||||
} else {
|
||||
//之前随机过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid and iid not in (@issueIds) ORDER BY RAND() LIMIT @num");
|
||||
issueSql.setParam("issueIds", hasAnswerIssueIds);
|
||||
}
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setParam("num", ranDomSingleIssueNum);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
|
||||
if (Lang.isNotEmpty(randomIssueIds)) {
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(maxAnswerNum + 1);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao.insert(questionRandomIssue);
|
||||
}
|
||||
//获取本次的随机题目
|
||||
issueCnd.andEX("iid", "in", randomIssueIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不是一天 那就一天随机一次
|
||||
|
||||
//用户的随机题目记录
|
||||
List<QuestionRandomIssue> randomIssues = dao.query(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
//已经随机的题目
|
||||
List<String> hasRanDomIssueIds = randomIssues.stream().flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
|
||||
//判断传入的日期是否已经加入到表里
|
||||
QuestionRandomIssue currentDateRandomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate));
|
||||
if (Lang.isEmpty(currentDateRandomIssue)) {
|
||||
Sql issueSql = null;
|
||||
if (Lang.isEmpty(hasRanDomIssueIds)) {
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid ORDER BY RAND() LIMIT @num");
|
||||
} else {
|
||||
//之前随机过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid and iid not in (@issueIds) ORDER BY RAND() LIMIT @num");
|
||||
issueSql.setParam("issueIds", hasRanDomIssueIds);
|
||||
}
|
||||
issueSql.setParam("num", ranDomSingleIssueNum);
|
||||
issueSql.setParam("qid", id);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(currentDate));
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", currentDateRandomIssue.getIssueIds());
|
||||
}
|
||||
}
|
||||
} else if (ctMode == 3) {
|
||||
//常规模式
|
||||
//判断是否将题目加进去了
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
if (Lang.isEmpty(randomIssue)) {
|
||||
Sql issueSql = Sqls.create(" SELECT iid FROM `question_issue` where iqid = @qid");
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setCallback(Sqls.callback.strList());
|
||||
dao.execute(issueSql);
|
||||
List<String> randomIssueIds = (List<String>) issueSql.getResult();
|
||||
Collections.shuffle(randomIssueIds);
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(randomIssueIds);
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", randomIssue.getIssueIds());
|
||||
}
|
||||
}
|
||||
|
||||
// issueCnd.asc("ipxbh");
|
||||
questionService.fetchLinks(question, "issues", issueCnd);
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
questionService.fetchLinks(issue, "wors", Cnd.NEW().asc("wpxbh"));
|
||||
}
|
||||
|
||||
if (question.getDisruptingOrder()) {
|
||||
Collections.shuffle(question.getIssues());
|
||||
}
|
||||
|
||||
return Result.success(question);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存答案
|
||||
*
|
||||
* @param repliesArray 答复记录
|
||||
* @param questionId 问卷ID
|
||||
* @param isSave 是否保存
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/saveAnswer")
|
||||
public Object saveAnswer(@Param("replies") Question_reply[] repliesArray, String questionId, Boolean isSave) {
|
||||
questionService.saveAnswer(repliesArray, questionId, isSave);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 答题信息
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerInfo/?")
|
||||
public Object answerInfo(String id,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Cnd cnd = Cnd.where("qid", "=", id).and("userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
|
||||
Question question = dao.fetch(Question.class, id);
|
||||
if (question.getCtMode() == 1) {
|
||||
cnd.and("DATE(rtime)", "=", currentDate);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
|
||||
} else {
|
||||
cnd.and("DATE(rtime)", "=", currentDate);
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
|
||||
}
|
||||
|
||||
List<Question_reply> replies = questionService.dao().query(Question_reply.class, cnd);
|
||||
return Result.success(replies);
|
||||
}
|
||||
|
||||
/**
|
||||
* 再答一次
|
||||
*
|
||||
* @param questionId 问题id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerAgain")
|
||||
public Object answerAgain(String questionId) {
|
||||
Sql issueIdsSql = Sqls.create("select iid from question_issue where iqid = @qid").setParam("qid", questionId);
|
||||
String[] issueIds = (String[]) Daos.query(dao, issueIdsSql.toString(), Sqls.callback.strs());
|
||||
//清空本日的答题记录
|
||||
dao.clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getPlatformUid()).and("issueId", "in", issueIds));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At("/winInfo")
|
||||
public Object winInfo(String questionId) {
|
||||
// List<QuestionWinner> winners = dao.query(QuestionWinner.class, Cnd.where("questionId", "=", questionId));
|
||||
// return Result.success(winners);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.username,
|
||||
qw.winDate,
|
||||
u.id
|
||||
FROM
|
||||
`question_winner` qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
WHERE
|
||||
qw.questionId = @questionId
|
||||
""");
|
||||
sql.setParam("questionId", questionId);
|
||||
List<NutMap> list = questionService.listMap(sql);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否答完
|
||||
*
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object checkUserFinishAnswer(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
if (question.getCtMode() == 3) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
if (betweenDay == 0) {
|
||||
//同一天
|
||||
if (randomCount != null) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("num", "=", randomCount));
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
return Result.success(false);
|
||||
} else {
|
||||
//不是同一天 判断今天是否答完就行了
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
//时间过了
|
||||
if (DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(true);
|
||||
}
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
} else if (question.getCtMode() == 1) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", currentDate));
|
||||
//时间过了
|
||||
if (DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(true);
|
||||
}
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
return Result.success(false);
|
||||
}
|
||||
|
||||
@At
|
||||
public Object checkCanAnswerAgain(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
if (question.getCanRepeatedAnswer()) {
|
||||
//0次则不限制
|
||||
if (question.getCanRepeatedAnswerNum() == 0) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
if (question.getCtMode() == 3) {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay == 0) {
|
||||
return Result.success(false);
|
||||
} else {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("answerDate", "=", DateUtil.today()));
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
}
|
||||
} else if (question.getCtMode() == 1) {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("answerDate", "=", currentDate));
|
||||
//时间过了
|
||||
if (Lang.isNotEmpty(currentDate) && DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(false);
|
||||
}
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
}
|
||||
}
|
||||
return Result.success(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取得分
|
||||
*
|
||||
* @param questionId
|
||||
* @param currentDate
|
||||
* @param randomCount
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object getScore(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate)
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
if (betweenDay == 0) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
// .and("displayDate", "=", currentDate)
|
||||
.and("answerNum", "=", randomCount)
|
||||
.desc("answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
} else {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate)
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户已回答的轮数 针对单天随机
|
||||
*
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object getUserHasAnswerRandomNum(String questionId) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (question.getCtMode() == 2 && betweenDay == 0) {
|
||||
int count = dao.count(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success().addData(count);
|
||||
}
|
||||
return Result.success().addData(0);
|
||||
}
|
||||
}
|
||||
+81
-53
@@ -1,24 +1,25 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.question.model.Question_reply;
|
||||
import io.v.nutz.question.model.Question_wor;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.sys.models.Sys_task;
|
||||
import io.v.nutz.sys.services.SysTaskService;
|
||||
import io.v.nutz.task.services.TaskPlatformService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.Question_issue;
|
||||
import io.v.nutz.zhgh.question.model.Question_reply;
|
||||
import io.v.nutz.zhgh.question.model.Question_wor;
|
||||
import io.v.nutz.zhgh.question.service.QuestionIssueService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionReplyService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionWorService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
@@ -30,18 +31,18 @@ import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -86,7 +87,7 @@ public class QuestionMangeController {
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.mange")
|
||||
public Object pageData(PageForm pageForm, @Param(value = "qtitle", required = false) String qtitle,
|
||||
@Param(value = "year",required = false) Integer year) {
|
||||
@Param(value = "year", required = false) Integer year) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(qtitle)) {
|
||||
@@ -98,6 +99,7 @@ public class QuestionMangeController {
|
||||
sql.setCondition(cnd);
|
||||
return Result.success().addData(questionService.listPage(pageForm.getPageNumber(), pageForm.getPageSize(), sql));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
@@ -114,8 +116,6 @@ public class QuestionMangeController {
|
||||
@RequiresPermissions("question.mange")
|
||||
public Object upStatus(String qid, Integer flag) {
|
||||
try {
|
||||
Assert.notBlank(qid);
|
||||
Assert.notNull(flag);
|
||||
dao.update(Question.class, Chain.make("qflag", flag), Cnd.where("qid", "=", qid));
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
@@ -131,13 +131,23 @@ public class QuestionMangeController {
|
||||
public Object doAdd(@Param("question") Question question) {
|
||||
try {
|
||||
question.setQflag(1);
|
||||
question.setQctime(DateUtil.getDate());
|
||||
question.setQctime(DateUtil.now());
|
||||
question.setQcreator(ShiroUtil.getPrincipalProperty("id").toString());
|
||||
|
||||
//这里要额外判断下随机模式下的答题天数
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
|
||||
Question insert = questionService.insert(question);
|
||||
|
||||
int i = 1;
|
||||
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
issue.setIid(Strings.isNotBlank(issue.getIid()) ? issue.getIid() : R.UU32());
|
||||
issue.setIqid(insert.getQid());
|
||||
@@ -145,7 +155,6 @@ public class QuestionMangeController {
|
||||
if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i);
|
||||
}
|
||||
|
||||
Question_issue issueInsert = questionIssueService.insert(issue);
|
||||
int j = 1;
|
||||
for (Question_wor wor : issue.getWors()) {
|
||||
@@ -157,9 +166,7 @@ public class QuestionMangeController {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
raffleTask(question.getQid());
|
||||
|
||||
// raffleTask(question.getQid());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -173,6 +180,17 @@ public class QuestionMangeController {
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.mange")
|
||||
public Object doEdit(@Param("question") Question question) {
|
||||
//这里要额外判断下随机模式下的答题天数
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
questionService.update(question);
|
||||
|
||||
List<Question_issue> oldIssues = dao.query(Question_issue.class, Cnd.where("iqid", "=", question.getQid()));
|
||||
@@ -239,7 +257,7 @@ public class QuestionMangeController {
|
||||
|
||||
|
||||
/**
|
||||
* 删除文具按
|
||||
* 删除问卷
|
||||
*
|
||||
* @param qid qid
|
||||
* @return {@link Object}
|
||||
@@ -309,13 +327,23 @@ public class QuestionMangeController {
|
||||
@At("/modifyBasicInfo")
|
||||
@RequiresPermissions("question.mange")
|
||||
@ViReturn
|
||||
public Object modifyBasicInfo(Question question) {
|
||||
public Object modifyBasicInfo(@Param("question") Question question) {
|
||||
try {
|
||||
Assert.notNull(question);
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(question.getQid())) {
|
||||
dao.updateIgnoreNull(question);
|
||||
} else {
|
||||
question.setQctime(cn.hutool.core.date.DateUtil.today());
|
||||
question.setQctime(DateUtil.today());
|
||||
question.setQcreator(ShiroUtil.getUserId());
|
||||
question.setQflag(1);
|
||||
dao.insert(question);
|
||||
@@ -370,9 +398,9 @@ public class QuestionMangeController {
|
||||
for (int i = 0; i < issueList.size(); i++) {
|
||||
Question_issue issue = issueList.get(i);
|
||||
issue.setIqid(questionId);
|
||||
if (question.getCtMode() == 2) {
|
||||
// if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i + 1);
|
||||
}
|
||||
// }
|
||||
dao.insertOrUpdate(issue);
|
||||
List<Question_wor> wors = issue.getWors();
|
||||
for (int i1 = 0; i1 < wors.size(); i1++) {
|
||||
@@ -416,41 +444,41 @@ public class QuestionMangeController {
|
||||
* @param questionId 问题id
|
||||
*/
|
||||
private void raffleTask(String questionId) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
//每天凌晨一点执行
|
||||
String cron = "0 0 1 * * ?";
|
||||
cron = "30 * * * * ? ";
|
||||
String cronData = Json.toJson(Map.of("questionId", questionId));
|
||||
//删除之前的任务再添加
|
||||
List<Sys_task> oldTasks = dao.query(Sys_task.class, Cnd.where("data", "like", "%" + questionId + "%"));
|
||||
for (Sys_task task : oldTasks) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
sysTaskService.delete(task.getId());
|
||||
}
|
||||
|
||||
String jobClass = "io.v.nutz.task.job.question.QuestionRaffleJob";
|
||||
Sys_task task = sysTaskService.fetch(Cnd.where("jobClass", "=", jobClass).and("data", "=", cronData));
|
||||
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
//需要抽奖
|
||||
if (question.getIsRaffle() != null && question.getIsRaffle()) {
|
||||
if (task != null) {
|
||||
task.setName(HtmlUtil.cleanHtmlTag(question.getQtitle()) + "问卷调查抽奖任务");
|
||||
task.setCron(cron);
|
||||
sysTaskService.updateIgnoreNull(task);
|
||||
if (taskPlatformService.isExist(task.getId(), task.getId())) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
}
|
||||
} else {
|
||||
task = new Sys_task();
|
||||
|
||||
String dateFormat = "ss mm HH dd MM ? yyyy";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
|
||||
List<Question.RaffleRule> raffleRules = question.getRaffleRule();
|
||||
for (Question.RaffleRule raffleRule : raffleRules) {
|
||||
Date raffleTime = raffleRule.getRaffleTime();
|
||||
String formatTimeStr = sdf.format(raffleTime);
|
||||
|
||||
NutMap raffleRuleMap = Lang.obj2nutmap(raffleRule);
|
||||
raffleRuleMap.put("questionId", questionId);
|
||||
|
||||
String cronData = Json.toJson(raffleRuleMap);
|
||||
|
||||
Sys_task task = new Sys_task();
|
||||
task.setName(HtmlUtil.cleanHtmlTag(question.getQtitle()) + "问卷调查抽奖任务");
|
||||
task.setJobClass(jobClass);
|
||||
task.setNote("问卷调查抽奖任务");
|
||||
task.setCron(cron);
|
||||
task.setCron(formatTimeStr);
|
||||
task.setData(cronData);
|
||||
task.setDisabled(false);
|
||||
sysTaskService.insert(task);
|
||||
}
|
||||
taskPlatformService.add(task.getId(), task.getId(), task.getJobClass(), task.getCron(),
|
||||
task.getNote(), task.getData());
|
||||
} else {
|
||||
if (task != null) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
sysTaskService.delete(task.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
@@ -6,12 +6,12 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.base.utils.Html2Text;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.Question_issue;
|
||||
import io.v.nutz.zhgh.question.service.QuestionIssueService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionReplyService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionWorService;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.controller;
|
||||
package io.v.nutz.zhgh.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
@@ -10,11 +10,11 @@ import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.activity.models.ActivityUserScope;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.sys.models.Sys_union;
|
||||
import io.v.nutz.util.ViTool;
|
||||
import io.v.nutz.web.commons.utils.FileUtil;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
@@ -109,7 +109,7 @@ public class QuestionUnionIntentionalChoiceController {
|
||||
""").setParam("questionId", questionId);
|
||||
|
||||
CndPlus cndPlus = CndPlus.create();
|
||||
cndPlus.andExcludeEmpty("un.id", "=", unionId);
|
||||
cndPlus.andEX("un.id", "=", unionId);
|
||||
sql.setCondition(cndPlus);
|
||||
List<NutMap> unionList = questionService.listMap(sql);
|
||||
|
||||
@@ -270,7 +270,7 @@ public class QuestionUnionIntentionalChoiceController {
|
||||
$condition
|
||||
""").setParam("questionId", questionId);
|
||||
|
||||
cnd.andExcludeEmpty("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.groupBy("u.id");
|
||||
cnd.desc("u.unioncode");
|
||||
sql.setCondition(cnd);
|
||||
+62
-7
@@ -1,9 +1,10 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -51,7 +52,7 @@ public class Question implements Serializable {
|
||||
|
||||
@Column
|
||||
@Comment("说明")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 2000)
|
||||
@ColDefine(customType = "text")
|
||||
private String qsm;
|
||||
|
||||
@Column
|
||||
@@ -95,16 +96,16 @@ public class Question implements Serializable {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ctMode;
|
||||
|
||||
@Column
|
||||
@Comment("单次出题数量")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ctNum;
|
||||
|
||||
@Column
|
||||
@Comment("是否抽奖")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isRaffle;
|
||||
|
||||
@Column
|
||||
@Comment("抽奖时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date raffleTime;
|
||||
|
||||
@Column
|
||||
@Comment("多少分可以抽奖")
|
||||
@ColDefine(type = ColType.INT)
|
||||
@@ -115,5 +116,59 @@ public class Question implements Serializable {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer raffleWinnerUserNum;
|
||||
|
||||
@Column
|
||||
@Comment("题目顺序打乱")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean disruptingOrder;
|
||||
|
||||
@Column
|
||||
@Comment("随机单次出题数量")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ranDomSingleIssueNum;
|
||||
|
||||
@Column
|
||||
@Comment("总共随机次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ranDomSum;
|
||||
|
||||
@Column
|
||||
@Comment("是否多次答")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean canRepeatedAnswer;
|
||||
|
||||
@Column
|
||||
@Comment("多次答数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer canRepeatedAnswerNum;
|
||||
|
||||
@Column
|
||||
@Comment("得分统计(重复答题允许下 1.保存最高分 2.保存最新得分)")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer calcScoreMode;
|
||||
|
||||
@Column
|
||||
@Comment("抽奖规则")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<RaffleRule> raffleRule;
|
||||
|
||||
/**
|
||||
* 抽奖规则
|
||||
*/
|
||||
@Data
|
||||
public static class RaffleRule {
|
||||
//开始答题时间
|
||||
private Date startAnswerDate;
|
||||
|
||||
//结束答题时间
|
||||
private Date endAnswerDate;
|
||||
|
||||
//抽奖时间
|
||||
private Date raffleTime;
|
||||
|
||||
//抽奖分数
|
||||
private Integer raffleScore;
|
||||
|
||||
//抽奖人数
|
||||
private Integer raffleWinnerUserNum;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
@@ -0,0 +1,52 @@
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import io.v.nutz.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Comment("问卷随机题目")
|
||||
@Table
|
||||
public class QuestionRandomIssue extends BaseModel {
|
||||
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("问卷的id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String questionId;
|
||||
|
||||
@Column
|
||||
@Comment("用户id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@Comment("题目")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<String> issueIds;
|
||||
|
||||
@Column
|
||||
@Comment("回答次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer num;
|
||||
|
||||
@Column
|
||||
@Comment("是否回答完成")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isFinish;
|
||||
|
||||
@Column
|
||||
@Comment("显示日期")
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date displayDate;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
+14
-2
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import io.v.nutz.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
@@ -12,9 +14,10 @@ import java.util.Date;
|
||||
* @author jug
|
||||
* @date 2023/06/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Table
|
||||
public class QuestionUserScore {
|
||||
public class QuestionUserScore extends BaseModel {
|
||||
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@@ -46,4 +49,13 @@ public class QuestionUserScore {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer answerNum;
|
||||
|
||||
@Column
|
||||
@Comment("随机次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer randomNum;
|
||||
|
||||
@Column
|
||||
@Comment("显示日期(只针对定时定题)")
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date displayDate;
|
||||
}
|
||||
+6
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
@@ -37,4 +37,9 @@ public class QuestionWinner {
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date winDate;
|
||||
|
||||
@Column
|
||||
@Comment("分数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer score;
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
+4
-1
@@ -1,10 +1,11 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.integration.json4excel.annotation.J4EIgnore;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,4 +86,6 @@ public class Question_reply implements Serializable {
|
||||
|
||||
@One(field = "rwid", key = "wid")
|
||||
private Question_wor wor;
|
||||
|
||||
private List<String> userSelect;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.v.nutz.question.model;
|
||||
package io.v.nutz.zhgh.question.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.v.nutz.zhgh.question.service;
|
||||
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.zhgh.question.model.QuestionUserScore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 得分
|
||||
*/
|
||||
public interface QuestionAnswerRankingService extends BaseService<QuestionUserScore> {
|
||||
|
||||
Pagination pageData(PageForm pageForm,
|
||||
String questionId,
|
||||
String unionId,
|
||||
String unitId,
|
||||
String answerDate);
|
||||
|
||||
void exportXlsx(String questionId, OutputStream os) throws IOException;
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package io.v.nutz.question.service;
|
||||
package io.v.nutz.zhgh.question.service;
|
||||
|
||||
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.zhgh.question.model.Question_issue;
|
||||
|
||||
public interface QuestionIssueService extends BaseService<Question_issue> {
|
||||
}
|
||||
+3
-4
@@ -1,10 +1,9 @@
|
||||
package io.v.nutz.question.service;
|
||||
package io.v.nutz.zhgh.question.service;
|
||||
|
||||
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_reply;
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.Question_reply;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.v.nutz.zhgh.question.service;
|
||||
|
||||
import io.v.nutz.service.ViService;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.Question_reply;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* Created by 李耀威 on 2020-02-19
|
||||
* info by 问卷调查 service
|
||||
*/
|
||||
public interface QuestionService extends ViService<Question> {
|
||||
Question getQuestion(String qid);
|
||||
|
||||
NutMap getVoteData(String qid);
|
||||
|
||||
NutMap getRankData(String qid);
|
||||
|
||||
|
||||
/**
|
||||
* 答题
|
||||
*
|
||||
* @param repliesArray 记录
|
||||
* @param questionId 问卷ID
|
||||
* @param isSave 是否保存
|
||||
*/
|
||||
void saveAnswer(Question_reply[] repliesArray, String questionId, Boolean isSave);
|
||||
|
||||
|
||||
/**
|
||||
* 是否同天 仅限随机
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
boolean isSameDay(String questionId);
|
||||
|
||||
/**
|
||||
* 是否同天 仅限随机
|
||||
* @param startTimeTs 开始时间
|
||||
* @param endTimeTs 结束时间
|
||||
* @return
|
||||
*/
|
||||
boolean isSameDay(long startTimeTs,long endTimeTs);
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package io.v.nutz.question.service;
|
||||
package io.v.nutz.zhgh.question.service;
|
||||
|
||||
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.question.model.Question_wor;
|
||||
import io.v.nutz.zhgh.question.model.Question_wor;
|
||||
|
||||
public interface QuestionWorService extends BaseService<Question_wor> {
|
||||
}
|
||||
+422
@@ -0,0 +1,422 @@
|
||||
package io.v.nutz.zhgh.question.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.base.service.impl.BaseServiceImpl;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.zhgh.question.model.Question;
|
||||
import io.v.nutz.zhgh.question.model.QuestionUserScore;
|
||||
import io.v.nutz.zhgh.question.service.QuestionAnswerRankingService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class QuestionAnswerRankingServiceImpl extends BaseServiceImpl<QuestionUserScore> implements QuestionAnswerRankingService {
|
||||
public QuestionAnswerRankingServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, String questionId, String unionId, String unitId, String answerDate) {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
GROUP_CONCAT( qus.answerNum, '(', qus.score, ')' ORDER BY qus.answerNum SEPARATOR ', ' ) AS everyRandomScore,
|
||||
sum( score ) AS score,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
} else {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND answerNum = max( qus.answerNum )\s
|
||||
AND questionId = qus.questionId
|
||||
) as lastAnswerNumScore,
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND score = max( qus.score )\s
|
||||
AND questionId = qus.questionId
|
||||
) as maxAnswerScore,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
qus.answerNum,
|
||||
max( qus.answerNum ),
|
||||
min( qus.answerNum ),
|
||||
qus.score,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
List<NutMap> list = pagination.getList();
|
||||
for (NutMap map : list) {
|
||||
map.put("score", map.getInt(question.getCalcScoreMode() == 1 ? "maxAnswerScore" : "lastAnswerNumScore"));
|
||||
}
|
||||
return pagination;
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
return new Pagination();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportXlsx(String questionId, OutputStream os) throws IOException {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
GROUP_CONCAT( qus.answerNum, '(', qus.score, ')' ORDER BY qus.answerNum SEPARATOR ', ' ) AS everyRandomScore,
|
||||
sum( score ) AS score,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("每轮分数", "everyRandomScore", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
|
||||
} else {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND answerNum = max( qus.answerNum )\s
|
||||
AND questionId = qus.questionId
|
||||
) as lastAnswerNumScore,
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND score = max( qus.score )\s
|
||||
AND questionId = qus.questionId
|
||||
) as maxAnswerScore,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
qus.answerNum,
|
||||
max( qus.answerNum ),
|
||||
min( qus.answerNum ),
|
||||
qus.score,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
for (NutMap map : list) {
|
||||
map.put("score", map.getInt(question.getCalcScoreMode() == 1 ? "maxAnswerScore" : "lastAnswerNumScore"));
|
||||
}
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
package io.v.nutz.zhgh.question.service.impl;
|
||||
|
||||
|
||||
import io.v.nutz.base.service.impl.BaseServiceImpl;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.zhgh.question.model.Question_issue;
|
||||
import io.v.nutz.zhgh.question.service.QuestionIssueService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
+4
-3
@@ -1,9 +1,9 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
package io.v.nutz.zhgh.question.service.impl;
|
||||
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.question.model.*;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.zhgh.question.model.*;
|
||||
import io.v.nutz.zhgh.question.service.QuestionReplyService;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -13,6 +13,7 @@ import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.random.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -0,0 +1,266 @@
|
||||
package io.v.nutz.zhgh.question.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.question.model.*;
|
||||
import io.v.nutz.zhgh.question.service.QuestionIssueService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionReplyService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionService;
|
||||
import io.v.nutz.zhgh.question.service.QuestionWorService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "Zgfw_question")
|
||||
public class QuestionServiceImpl extends ViServiceImpl<Question> implements QuestionService {
|
||||
@Inject
|
||||
private QuestionIssueService questionIssueService;
|
||||
@Inject
|
||||
private QuestionWorService questionWorService;
|
||||
@Inject
|
||||
private QuestionReplyService questionReplyService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
public QuestionServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Question getQuestion(String qid) {
|
||||
Question question = fetch(qid);
|
||||
question.setIssues(questionIssueService.query(Cnd.where("iqid", "=", qid).asc("ipxbh")));
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
issue.setWors(questionWorService.query(Cnd.where("wiid", "=", issue.getIid()).asc("wpxbh")));
|
||||
}
|
||||
return question;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap getVoteData(String qid) {
|
||||
Question_issue issue = questionIssueService.fetch(Cnd.where("iqid", "=", qid));
|
||||
NutMap res = new NutMap();
|
||||
//选项数
|
||||
res.setv("optionum", questionWorService.count(Cnd.where("wiid", "=", issue.getIid())));
|
||||
//投票总数
|
||||
int votecount = questionReplyService.count(Sqls.create("SELECT COUNT(1) FROM question_reply r WHERE r.`rwid` IN (SELECT w.`wid` FROM zgfw_question_wor w WHERE w.`wiid` = @iid)").setParam("iid", issue.getIid()));
|
||||
res.setv("votecount", votecount);
|
||||
|
||||
Sql sql = Sqls.create("SELECT w.`wid`,(SELECT COUNT(1) FROM question_reply r WHERE r.rwid=w.`wid`) COUNT FROM zgfw_question_wor w WHERE w.`wiid` = @iid").setParam("iid", issue.getIid());
|
||||
for (Record record : questionWorService.list(sql)) {
|
||||
res.setv(record.getString("wid"), record.getInt("count"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap getRankData(String qid) {
|
||||
NutMap res = new NutMap();
|
||||
Question question = getQuestion(qid);
|
||||
res.setv("qid", qid);
|
||||
res.setv("qtitle", question.getQtitle());
|
||||
|
||||
Question_issue issue = questionIssueService.fetch(Cnd.where("iqid", "=", qid));
|
||||
res.setv("iname", issue.getIname());
|
||||
//选项数
|
||||
res.setv("optionum", questionWorService.count(Cnd.where("wiid", "=", issue.getIid())));
|
||||
//投票总数
|
||||
int votecount = questionReplyService.count(Sqls.create("SELECT COUNT(1) FROM question_reply r WHERE r.`rwid` IN (SELECT w.`wid` FROM zgfw_question_wor w WHERE w.`wiid` = @iid)").setParam("iid", issue.getIid()));
|
||||
res.setv("votecount", votecount);
|
||||
|
||||
Sql sql = Sqls.create("SELECT w.`wid`,w.`wimg`,w.`wtxt`,(SELECT COUNT(1) FROM question_reply r WHERE r.rwid=w.`wid`) COUNT FROM zgfw_question_wor w WHERE w.`wiid` = @iid ORDER BY COUNT DESC").setParam("iid", issue.getIid());
|
||||
res.setv("wors", questionWorService.list(sql));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveAnswer(Question_reply[] repliesArray, String questionId, Boolean isSave) {
|
||||
//删除上一次的答题记录
|
||||
//此处需判断 如果是有分多天 随机多次就要按条件删除
|
||||
|
||||
//问卷信息包含题目选项
|
||||
Question question = getQuestion(questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
//删除今天的之前的答题记录
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay > 0) {
|
||||
//多天随机
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()));
|
||||
} else {
|
||||
//一天多次随机 删除保存的
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()).and("save", "=", 1));
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
}
|
||||
|
||||
List<Question_reply> replyList = new ArrayList<>();
|
||||
for (Question_reply reply : repliesArray) {
|
||||
if (Lang.isNotEmpty(reply.getUserSelect())) {
|
||||
for (String userSelect : reply.getUserSelect()) {
|
||||
Question_reply questionReply = new Question_reply();
|
||||
questionReply.setRwid(userSelect);
|
||||
questionReply.setIssueId(reply.getIssueId());
|
||||
questionReply.setUserId(ShiroUtil.getUserId());
|
||||
questionReply.setRtime(DateUtil.now());
|
||||
questionReply.setRwid(userSelect);
|
||||
questionReply.setQid(questionId);
|
||||
questionReply.setSave(isSave);
|
||||
replyList.add(questionReply);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insert(replyList);
|
||||
|
||||
//判断是否提交 提交则计算此次分数
|
||||
|
||||
if (!isSave) {
|
||||
|
||||
//得分
|
||||
AtomicInteger sum = new AtomicInteger();
|
||||
|
||||
//常规模式计算全部题目的分数
|
||||
if (question.getCtMode() == 3) {
|
||||
//每题的回答记录
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
dao().insert(questionUserScore);
|
||||
} else if (question.getCtMode() == 1) {
|
||||
//每题的回答记录
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
List<String> issueIds = randomIssue.getIssueIds();
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("issueId", "in", issueIds).and("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
questionUserScore.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao().insert(questionUserScore);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
|
||||
//每题的回答记录
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()).desc("num"));
|
||||
List<String> issueIds = randomIssue.getIssueIds();
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("issueId", "in", issueIds).and("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//同一天
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
questionUserScore.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao().insert(questionUserScore);
|
||||
}
|
||||
|
||||
//随机题库设为已完成
|
||||
if (question.getCtMode() == 3) {
|
||||
//常规模式下不需要判断次数
|
||||
dao().update(QuestionRandomIssue.class, Chain.make("isFinish", 1), Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
} else if (question.getCtMode() == 1) {
|
||||
//定时定题需要加上日期的条件
|
||||
dao().update(QuestionRandomIssue.class, Chain.make("isFinish", 1), Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//随机模式 要判断是否为同一天
|
||||
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()).desc("num"));
|
||||
randomIssue.setIsFinish(true);
|
||||
dao().update(randomIssue, "isFinish");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameDay(String questionId) {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
return isSameDay(question.getStartTime(), question.getEndTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameDay(long startTimeTs, long endTimeTs) {
|
||||
DateTime startTime = DateUtil.date(startTimeTs);
|
||||
DateTime endTime = DateUtil.date(endTimeTs);
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
return betweenDay == 0;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
package io.v.nutz.zhgh.question.service.impl;
|
||||
|
||||
import io.v.nutz.base.service.impl.BaseServiceImpl;
|
||||
import io.v.nutz.question.model.Question_wor;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.zhgh.question.model.Question_wor;
|
||||
import io.v.nutz.zhgh.question.service.QuestionWorService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
@@ -3,534 +3,590 @@ layout("/mobile/platform.html"){
|
||||
#-->
|
||||
|
||||
<style>
|
||||
.container {
|
||||
/*height: calc(56vh);*/
|
||||
width: 100%;
|
||||
background: #f9f9f9;
|
||||
@font-face {
|
||||
font-family: 'Indie Flower';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(/assets/platform/fonts/m8JVjfNVeKWVnh3QMuKkFcZVaUuH.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
.header-info {
|
||||
background: #FFFFFF;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.page-survey {
|
||||
background-color: rgba(242, 242, 242, 1);
|
||||
}
|
||||
|
||||
.header-info .no {
|
||||
font-weight: bolder;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #FFFFFF;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.card .header {
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
border-bottom: .1px solid #e2e2e2;
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.card .body {
|
||||
padding: 0 10px 10px 10px;
|
||||
}
|
||||
|
||||
.issue-card .issue {
|
||||
height: calc(0%);
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20px 10px;
|
||||
font-size: 14px;
|
||||
color: #000;
|
||||
font-family: 'Helvetica Neue', Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.issue-card .issue div {
|
||||
overflow-y: auto;
|
||||
.page-survey .survey-container {
|
||||
height: 100%;
|
||||
overflow: visible;
|
||||
padding-top: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.issue-card .options {
|
||||
height: calc(0%);
|
||||
padding: 0 10px;
|
||||
overflow-y: auto;
|
||||
.survey-container .question-list {
|
||||
flex: auto;
|
||||
padding-bottom: 84px;
|
||||
}
|
||||
|
||||
.issue-card .options .option {
|
||||
padding: 10px 20px;
|
||||
background: #eeeeee8f;
|
||||
border: 1px solid rgba(234, 233, 233, 0.5);
|
||||
margin-bottom: 10px;
|
||||
border-radius: 8px;
|
||||
.question {
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
background: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
.issue-card .options .option-selected {
|
||||
border: 1px solid #c59f48;
|
||||
background: #fffbf3;
|
||||
color: #c59f48;
|
||||
.question-head {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
padding: 20px;
|
||||
background: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
.issue-card .options .option-correct {
|
||||
border: 1px solid #ace59d;
|
||||
background: #cdf3a8;
|
||||
color: #ace59d;
|
||||
.question-tags {
|
||||
position: absolute;
|
||||
top: -2px;
|
||||
}
|
||||
|
||||
.answer-card .body .result {
|
||||
padding: 10px;
|
||||
font-weight: bolder;
|
||||
.question-title {
|
||||
position: relative;
|
||||
font-size: 1.125em;
|
||||
font-weight: normal;
|
||||
word-wrap: break-word;
|
||||
word-break: break-word;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.answer-card .body .result .success {
|
||||
color: #71d5a1;
|
||||
.question-seq {
|
||||
display: block;
|
||||
margin-right: 8px;
|
||||
font-size: 18px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.answer-card .body .result .error {
|
||||
color: red;
|
||||
.question-title .text {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.answer-card .body .desc {
|
||||
padding: 10px;
|
||||
.question-body {
|
||||
background-color: rgba(255, 255, 255, 1);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.footer-info {
|
||||
background: #ffffff;
|
||||
height: 50px;
|
||||
.question-footer {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.van-checkbox {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.van-cell__title {
|
||||
font-size: 16px;
|
||||
color: rgba(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
.page-control {
|
||||
padding: 20px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
grid-gap: 20px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.survey-head-top {
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer-info div {
|
||||
flex: 1;
|
||||
.survey-head-top .randomCount {
|
||||
font-family: 'Arial', sans-serif;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
/*line-height: 50px;*/
|
||||
line-height: 1.5;
|
||||
color: #000000;
|
||||
background-color: #f0f0f0;
|
||||
border: 1px solid #000000;
|
||||
border-radius: 5px;
|
||||
padding: 5px 20px;
|
||||
}
|
||||
|
||||
.win-info-button {
|
||||
position: fixed;
|
||||
bottom: 60px;
|
||||
right: 10px;
|
||||
transform: translateY(-50%);
|
||||
padding: 5px;
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
.survey-head-top .score {
|
||||
/*font-family: 'Comic Sans MS', cursive;*/
|
||||
/*font-family: 'Indie Flower', cursive;*/
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.winPopup {
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
|
||||
.survey-head {
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.iconDiv {
|
||||
color: white;
|
||||
font-size: 66px;
|
||||
.survey-head .title {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.survey-head .desc {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="app" v-cloak>
|
||||
<div class="container">
|
||||
<div class="header-info" v-if="false">
|
||||
<div class="no">
|
||||
序号:{{ currentIssueIndex + 1 + '/' + todayIssueList.length }}
|
||||
<div class="root">
|
||||
<m-page-loading v-if="mLoading"></m-page-loading>
|
||||
<van-nav-bar title="知识竞答" left-arrow placeholder fixed
|
||||
@click-left="history.go(-1)"></van-nav-bar>
|
||||
<template v-if="!mLoading">
|
||||
<div class="page-survey" style="touch-action: manipulation;min-height: 100vh;">
|
||||
<div class="survey-container">
|
||||
<!-- v-if="questionData.qlx==2 && (questionData.ctMode==1 || questionData.ctMode==2)"-->
|
||||
<div class="survey-head-top">
|
||||
<template>
|
||||
<div v-if="questionData.qlx==2 && questionData.ctMode==2 && isSameDay && randomCount > 0"
|
||||
class="randomCount"
|
||||
@click="openRandomCount">
|
||||
第<span>{{randomCount}}</span>轮
|
||||
</div>
|
||||
<div class="no" v-if="questionData.qdtkssj && questionData.qdtjssj">
|
||||
<van-icon name="clock-o" size="16"/>
|
||||
答题时间:{{ questionData.qdtkssj + ' 至 ' + questionData.qdtjssj }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="question-card" v-for="(issue,issueIdx) in todayIssueList" :key="issue.issue">
|
||||
<template v-if="issueIdx===currentIssueIndex">
|
||||
<div class="card issue-card">
|
||||
<div class="header">
|
||||
<!-- <div class="issue-type">-->
|
||||
<!-- <span v-if="issue.itx===1 && issue.iisdx">单选题</span>-->
|
||||
<!-- <span v-if="issue.itx===1 && !issue.iisdx">多选题</span>-->
|
||||
<!-- </div>-->
|
||||
<div class="issue-type">
|
||||
序号:{{ currentIssueIndex + 1 + '/' + todayIssueList.length }}
|
||||
</div>
|
||||
<div class="score">
|
||||
分数:{{ issue.fraction }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="body">
|
||||
<div class="issue">
|
||||
<div style="font-size: 16px" v-html="issue.iname"></div>
|
||||
</div>
|
||||
<div class="options">
|
||||
<template v-for="wor in issue.wors">
|
||||
<div class="option"
|
||||
@click="optionSelect(issue,wor)"
|
||||
:key="wor.wid"
|
||||
:class="[currentSelectedWors.map(v=>v.wid).includes(wor.wid) ? 'option-selected':'']">
|
||||
{{ wor.wtxt }}
|
||||
<div v-if="questionData.qlx==2 && (questionData.ctMode==1 || (questionData.ctMode==2 && !isSameDay))"
|
||||
class="randomCount"
|
||||
@click="openRandomCount">
|
||||
<!--定时定题 可切换时间查看以前的题目-->
|
||||
<span>{{currentDate}}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="score" v-if="finishAnswer && ( currentScore || currentScore===0 )">
|
||||
{{questionData.calcScoreMode==1?'今日最高成绩':'得分'}}{{currentScore}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="survey-head">
|
||||
<div class="title">
|
||||
{{questionData.qtitle}}
|
||||
</div>
|
||||
|
||||
<div class="card answer-card" v-if="hasAnswerIssueIds.includes(issue.iid)">
|
||||
<!-- <div class="header">-->
|
||||
<!-- 答案-->
|
||||
<!-- <div class="desc">-->
|
||||
<!-- {{titleMsg}}-->
|
||||
<!-- </div>-->
|
||||
<div class="body">
|
||||
<div class="result">
|
||||
<span v-if="currentIssueAnswerResult" class="success">回答正确</span>
|
||||
<span v-else class="error">回答错误</span>
|
||||
</div>
|
||||
<div class="desc">我的答案:{{ currentIssueMyAnswer }}</div>
|
||||
<div class="desc" v-if="!currentIssueAnswerResult">正确答案:{{ correctWorsText }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="question-list">
|
||||
<section v-for="(issue,issueIdx) in issueList" :key="issue.iid" class="question"
|
||||
:id="'issue'+issue.iid">
|
||||
<div class="question-head">
|
||||
<div class="question-tags">
|
||||
<template v-if="issue.itx===1">
|
||||
<van-tag :type="issue.iisdx?'primary':'warning'" size="large">
|
||||
{{issue.iisdx?'单选':'多选'}}
|
||||
</van-tag>
|
||||
</template>
|
||||
<!-- <van-tag v-if="issue.fraction" type="primary" size="large">{{issue.fraction}}分-->
|
||||
<!-- </van-tag>-->
|
||||
</div>
|
||||
<h2 class="question-title">
|
||||
<span class="question-seq">
|
||||
<b>
|
||||
{{issueIdx+1}}.
|
||||
</b>
|
||||
</span>
|
||||
<div class="text" v-html="issue.iname"></div>
|
||||
</h2>
|
||||
|
||||
<div class="footer-info"
|
||||
style="background: #FFFFFF;height: 50px;position: fixed;bottom: 0;left: 0;right: 0;display: flex;">
|
||||
<div class="prev">
|
||||
<van-button @click="changeIssue(false)" type="info" :disabled="currentIssueIndex<=0">
|
||||
上一题
|
||||
</van-button>
|
||||
</div>
|
||||
<div class="question-body">
|
||||
<van-checkbox-group v-model="issue.userSelect" :ref="'checkboxGroup'+issue.iid">
|
||||
<van-cell-group>
|
||||
<van-cell
|
||||
v-for="(item,index) in issue.wors"
|
||||
clickable
|
||||
:key="item"
|
||||
:title="item.wtxt"
|
||||
@click="cellToggle(issue,item.wid)"
|
||||
>
|
||||
<template #label v-if="finishAnswer || finishAllAnswer">
|
||||
<div>
|
||||
得分:{{ getScore() }}
|
||||
{{item.correct?'正确答案':''}}
|
||||
</div>
|
||||
<div class="next">
|
||||
<!-- <template v-if="hasAnswerIssueIds.length === issueList.length">-->
|
||||
<!-- <van-button>-->
|
||||
<!-- 回答完毕-->
|
||||
<!-- </van-button>-->
|
||||
<!-- </template>-->
|
||||
<!-- <template v-else>-->
|
||||
<van-button v-if="!hasAnswerIssueIds.includes(currentIssueId)"
|
||||
type="info"
|
||||
:disabled="currentSelectedWors.length===0" @click="confirmAnswer">
|
||||
确认答案
|
||||
</template>
|
||||
<template #icon>
|
||||
<van-checkbox :name="item.wid" :ref="'checkboxes'+item.wid"
|
||||
:disabled="finishAnswer || finishAllAnswer"
|
||||
:shape="issue.iisdx?'round':'square'"></van-checkbox>
|
||||
</template>
|
||||
</van-cell>
|
||||
</van-cell-group>
|
||||
</van-checkbox-group>
|
||||
|
||||
</div>
|
||||
<div class="question-footer" v-if="finishAnswer || finishAllAnswer">
|
||||
<div>
|
||||
<div style="display: flex;align-items: center;"
|
||||
:style="{color:(issue.isEqual?'#15db81':'red')}">
|
||||
{{issue.isEqual?'回答正确':'回答错误'}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="page-control" v-if="!finishAnswer">
|
||||
<van-button type="info" block @click="save()">保存</van-button>
|
||||
<van-button type="info" block @click="submit()">提交</van-button>
|
||||
</div>
|
||||
<div class="page-control" style="grid-template-columns: auto" v-if="canAnswerAgain && finishAnswer && moment().format('YYYY-MM-DD') === vue.currentDate">
|
||||
<van-button type="info" block @click="answerAgain">
|
||||
再答一次
|
||||
</van-button>
|
||||
|
||||
<van-button v-else
|
||||
type="info"
|
||||
:disabled="currentIssueIndex === todayIssueList.length-1"
|
||||
@click="changeIssue(true)">
|
||||
下一题
|
||||
</van-button>
|
||||
<!-- </template>-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<div class="win-info-button" @click="showWinInfo">
|
||||
获奖信息
|
||||
</div>-->
|
||||
|
||||
<van-popup v-model="winPopupShow" class="winPopup" :style="{ height: '100%' }">
|
||||
<div>每人仅有一次机会</div>
|
||||
<img v-if="isWin" width="100%" height="60%" style="margin-top: 100px"
|
||||
src="/assets/mobile/img/question/win.png"/>
|
||||
<img v-if="!isWin" width="100%" height="80%" src="/assets/mobile/img/question/noWin.png"/>
|
||||
<div class="iconDiv">
|
||||
<van-icon @click="winPopupShow = false" name="close"></van-icon>
|
||||
</div>
|
||||
</van-popup>
|
||||
</template>
|
||||
|
||||
<van-action-sheet
|
||||
v-model="randomCountSheetShow"
|
||||
:actions="randomActions"
|
||||
@select="randomCountSelect"
|
||||
cancel-text="取消"
|
||||
close-on-click-action
|
||||
></van-action-sheet>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const BASE_URL = '/mobile/question/h5'
|
||||
const vue = new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
questionData: {},
|
||||
questionData: {
|
||||
issues: []
|
||||
},
|
||||
currentIssueIndex: 0,
|
||||
currentIssue: null,
|
||||
currentSelectedWors: [],
|
||||
replyInfo: [],
|
||||
todayStr: moment(new Date()).format('YYYY-MM-DD') + ' 00:00:00',
|
||||
winPopupShow: false,
|
||||
winList: [],
|
||||
isWin: false,
|
||||
finishAnswer: false,
|
||||
finishAllAnswer: false,
|
||||
mLoading: true,
|
||||
|
||||
//用户已答题总轮数
|
||||
randomCount: null,
|
||||
currentRandomCountScore: 0,
|
||||
sumScore: 0,
|
||||
randomCountSheetShow: false,
|
||||
randomActions: [],
|
||||
currentRandomCount: null,
|
||||
|
||||
//能否再次答题
|
||||
canAnswerAgain: false,
|
||||
|
||||
//当前的时间(针对定时定题)
|
||||
currentDate: moment().format('YYYY-MM-DD'),
|
||||
|
||||
//当前分数
|
||||
currentScore: null,
|
||||
|
||||
//获取用户已回答的轮数 针对单天随机
|
||||
userHasAnswerRandomNum: 0
|
||||
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
currentIssueId() {
|
||||
return this.currentIssue ? this.currentIssue.iid : null
|
||||
},
|
||||
issueList() {
|
||||
if (this.questionData && this.questionData.issues && this.questionData.issues.length) {
|
||||
return this.questionData.issues
|
||||
} else {
|
||||
return []
|
||||
},
|
||||
titleMsg() {
|
||||
const radios = this.issueList.filter(v => v.itx === 1 && v.iisdx)
|
||||
const checkBoxes = this.issueList.filter(v => v.itx === 1 && !v.iisdx)
|
||||
|
||||
const radioScore = radios && radios.length > 0 ? radios[0].fraction : 0
|
||||
const checkBoxesScore = checkBoxes && checkBoxes.length > 0 ? checkBoxes[0].fraction : 0
|
||||
|
||||
const radioScoreSum = radios.map(v => v.fraction ? v.fraction : 0).reduce((a, b) => a + b, 0)
|
||||
const checkBoxesScoreSum = checkBoxes.map(v => v.fraction ? v.fraction : 0).reduce((a, b) => a + b, 0)
|
||||
|
||||
const sumScore = radioScoreSum + checkBoxesScoreSum
|
||||
|
||||
let radiosText = ''
|
||||
let checkBoxesText = ''
|
||||
|
||||
if (radios && radios.length > 0) {
|
||||
radiosText = "单选题" + radios.length + "题,每题" + radioScore + "分,合计" + radioScoreSum + "分;"
|
||||
}
|
||||
},
|
||||
todayIssueList() {
|
||||
if (this.issueList && this.issueList.length > 0) {
|
||||
return this.issueList.filter(v => v.displayDate === this.todayStr)
|
||||
} else {
|
||||
return []
|
||||
if (checkBoxes && checkBoxes.length > 0) {
|
||||
checkBoxesText = "多选题" + checkBoxes.length + "题,每题" + checkBoxesScore + "分,合计" + checkBoxesScoreSum + "分;总分" + sumScore + "分。"
|
||||
}
|
||||
return "说明:" + radiosText + checkBoxesText
|
||||
},
|
||||
correctWorsText() {
|
||||
return this.currentIssue && this.currentIssue.wors.filter(v => v.correct).map(v => v.wtxt).join('、')
|
||||
|
||||
fullScore() {
|
||||
return this.issueList.map(v => v.fraction ? v.fraction : 0).reduce((a, b) => a + b)
|
||||
},
|
||||
currentIssueMyAnswer() {
|
||||
return this.currentSelectedWors.map(v => v.wtxt).join('、')
|
||||
radioNum() {
|
||||
return this.issueList.filter(v => v.idx === 1 && v.iisdx).map(v => v.fraction ? v.fraction : 0).reduce((a, b) => a + b)
|
||||
},
|
||||
//该题是否回答正确
|
||||
currentIssueAnswerResult() {
|
||||
const userSelectWorIds = this.currentSelectedWors.map(v => v.wid).slice().sort()
|
||||
if (this.currentIssue) {
|
||||
const correctWorIds = this.currentIssue.wors.filter(v => v.correct).map(v => v.wid).slice().sort()
|
||||
return userSelectWorIds.length === correctWorIds.length && correctWorIds.every(v => userSelectWorIds.includes(v))
|
||||
checkBoxNum() {
|
||||
|
||||
},
|
||||
|
||||
//判断是否为同一天
|
||||
isSameDay() {
|
||||
if (this.questionData.startTime && this.questionData.endTime) {
|
||||
return moment(this.questionData.startTime).isSame(moment(this.questionData.endTime), 'day')
|
||||
}
|
||||
return false
|
||||
},
|
||||
//已经回答的题目
|
||||
hasAnswerIssueIds() {
|
||||
if (this.replyInfo && this.replyInfo.length) {
|
||||
return this.replyInfo.map(v => v.issueId)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
todayScore() {
|
||||
return this.todayIssueList.filter(v => {
|
||||
const correctWids = v.wors.filter(v => v.correct).map(v => v.wid)
|
||||
const rwids = this.replyInfo.filter(v => v.issueId === v.iid).map(v => v.rwid)
|
||||
if (rwids && rwids.length > 0 && rwids.every(r => correctWids.includes(r))) {
|
||||
return v
|
||||
}
|
||||
}).map(v => v.fraction).reduce((a, b) => {
|
||||
return a + b
|
||||
}, 0)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
openRandomCount() {
|
||||
this.randomCountSheetShow = true
|
||||
this.randomActions = []
|
||||
|
||||
if (this.questionData.qlx == 2 && this.questionData.ctMode == 2 && this.isSameDay) {
|
||||
for (let i = 0; i < this.userHasAnswerRandomNum; i++) {
|
||||
this.randomActions.push({
|
||||
name: '第' + (i + 1) + '轮',
|
||||
val: i + 1
|
||||
})
|
||||
}
|
||||
} else if (this.questionData.qlx == 2 && (this.questionData.ctMode == 1 || (this.questionData.ctMode == 2 && !this.isSameDay))) {
|
||||
const {startTime, endTime} = this.questionData
|
||||
const startMoment = moment(startTime)
|
||||
const endMoment = moment(endTime)
|
||||
const now = moment()
|
||||
// 计算两个日期之间相差的天数
|
||||
const daysDifference = endMoment.diff(startMoment, 'days')
|
||||
for (let i = 0; i <= daysDifference; i++) {
|
||||
this.randomActions.push({
|
||||
name: startMoment.clone().add(i, 'days').format('YYYY-MM-DD'),
|
||||
val: startMoment.clone().add(i, 'days').format('YYYY-MM-DD'),
|
||||
disabled: moment(startMoment.clone().add(i, 'days').format('YYYY-MM-DD')).isAfter(now)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
async randomCountSelect(val) {
|
||||
if (this.questionData.qlx == 2 && this.questionData.ctMode == 2 && this.isSameDay) {
|
||||
this.randomCount = val.val
|
||||
} else if (this.questionData.qlx == 2 && this.questionData.ctMode == 2 && !this.isSameDay) {
|
||||
this.currentDate = val.val
|
||||
} else if (this.questionData.qlx == 2 && this.questionData.ctMode == 1) {
|
||||
this.currentDate = val.val
|
||||
}
|
||||
await this.getQuestionData()
|
||||
await this.checkUserFinishAnswer()
|
||||
await this.checkCanAnswerAgain()
|
||||
await this.getScore()
|
||||
},
|
||||
|
||||
async getQuestionData() {
|
||||
const resp = await $.get('/mobile/question/h5/questionInfo/' + this.id)
|
||||
const resp = await $.get(BASE_URL + '/questionInfo/' + this.id, {
|
||||
currentDate: this.currentDate,
|
||||
randomCount: this.randomCount
|
||||
})
|
||||
this.questionData = resp.data
|
||||
},
|
||||
|
||||
//获取回答信息
|
||||
async getReply() {
|
||||
const resp = await $.get('/mobile/question/h5/answerInfo/' + this.id)
|
||||
this.replyInfo = resp.data
|
||||
},
|
||||
|
||||
//点击选项
|
||||
optionSelect(issue, wor) {
|
||||
if (this.hasAnswerIssueIds.includes(issue.iid)) {
|
||||
cellToggle(issue, worId) {
|
||||
if (this.finishAnswer || this.finishAllAnswer) {
|
||||
return
|
||||
}
|
||||
this.currentIssue = issue
|
||||
if (this.currentIssue.itx === 1) {
|
||||
if (this.currentIssue.iisdx) {
|
||||
this.toggle(issue, worId)
|
||||
},
|
||||
|
||||
toggle(issue, worId) {
|
||||
//单选
|
||||
this.currentSelectedWors = [wor]
|
||||
if (issue.iisdx) {
|
||||
vue.$refs['checkboxGroup' + issue.iid][0].toggleAll(false)
|
||||
} else {
|
||||
//多选
|
||||
const idx = this.currentSelectedWors.findIndex(v => v.wid === wor.wid)
|
||||
if (idx > -1) {
|
||||
this.currentSelectedWors.splice(idx, 1)
|
||||
} else {
|
||||
this.currentSelectedWors.push(wor)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
console.log(issue.userSelect)
|
||||
this.$refs['checkboxes' + worId][0].toggle()
|
||||
setTimeout(() => {
|
||||
console.log(issue.userSelect)
|
||||
})
|
||||
},
|
||||
|
||||
//确认答案
|
||||
async confirmAnswer() {
|
||||
if (this.questionData.qdtkssj && this.questionData.qdtjssj) {
|
||||
const startTimes = this.questionData.qdtkssj.split(':')
|
||||
const endTimes = this.questionData.qdtjssj.split(':')
|
||||
const nows = moment(new Date()).format('HH:mm:ss').split(':')
|
||||
|
||||
let startTime = new Date()
|
||||
startTime.setHours(startTimes[0])
|
||||
startTime.setMinutes(startTimes[1])
|
||||
startTime.setSeconds(startTimes[2])
|
||||
|
||||
let endTime = new Date()
|
||||
endTime.setHours(endTimes[0])
|
||||
endTime.setMinutes(endTimes[1])
|
||||
endTime.setSeconds(endTimes[2])
|
||||
|
||||
let nowTime = new Date()
|
||||
nowTime.setHours(nows[0])
|
||||
nowTime.setMinutes(nows[1])
|
||||
nowTime.setSeconds(nows[2])
|
||||
|
||||
|
||||
if (nowTime < startTime || nowTime > endTime) {
|
||||
this.$modal.msg('不在答题时间范围内')
|
||||
return
|
||||
save() {
|
||||
this.$modal.confirm('保存后下次可继续做答,您确定要保存吗?').then(async () => {
|
||||
const replies = this.questionData.issues.map(v => {
|
||||
return {
|
||||
qid: v.iid,
|
||||
issueId: v.iid,
|
||||
userSelect: v.userSelect,
|
||||
}
|
||||
}
|
||||
if (this.questionData.qrkdcs && this.questionData.qrkdcs > 0) {
|
||||
const {data: canAnswer} = await $.get('/mobile/question/h5/canAnswer', {questionId: this.questionData.qid})
|
||||
if (!canAnswer) {
|
||||
this.$modal.msg('今日答题次数已超上限')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.$modal.loading('提交中')
|
||||
|
||||
//用户选择的答案
|
||||
const userSelectWorIds = this.currentSelectedWors.map(v => v.wid).slice().sort()
|
||||
|
||||
const formData = []
|
||||
userSelectWorIds.forEach(v => {
|
||||
formData.push({
|
||||
qid: this.questionData.qid,
|
||||
issueId: this.currentIssue.iid,
|
||||
rwid: v,
|
||||
save: false
|
||||
})
|
||||
})
|
||||
|
||||
$.post('/mobile/question/h5/saveAnswer2', {replies: JSON.stringify(formData)}).then(res => {
|
||||
if (res.code === 0) {
|
||||
const getReplyPromise = () => {
|
||||
return new Promise(async resolve => {
|
||||
await this.getReply()
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
getReplyPromise().then(() => {
|
||||
this.checkTodayReplyFinish()
|
||||
const {code} = await $.post(BASE_URL + '/saveAnswer', {
|
||||
replies: JSON.stringify(replies),
|
||||
questionId: this.questionData.qid,
|
||||
isSave: true,
|
||||
randomCount: this.randomCount
|
||||
})
|
||||
this.$modal.closeLoading()
|
||||
if (code === 0) {
|
||||
this.$modal.msg('保存成功')
|
||||
} else {
|
||||
this.$modal.msg('保存失败')
|
||||
}
|
||||
})
|
||||
},
|
||||
async checkTodayReplyFinish() {
|
||||
if (this.issueList.map(x => x.iid).every(x => this.replyInfo.map(v => v.issueId).includes(x))) {
|
||||
this.$modal.msg('全部答题完成')
|
||||
} else if (this.todayIssueList.map(x => x.iid).every(x => this.replyInfo.map(v => v.issueId).includes(x))) {
|
||||
const score = this.getScore()
|
||||
const {data: scoreMap} = await $.get('/mobile/question/h5/todayMaxScore', {questionId: this.questionData.qid})
|
||||
const scoreValues = Object.values(scoreMap)
|
||||
let msg = null
|
||||
if (scoreValues.length > 1) {
|
||||
const maxScore = Math.max(...scoreValues)
|
||||
msg = '今日答题已完成,您当前分数为' + score + ',历史最高分为' + maxScore + ',是否重新答题?'
|
||||
} else {
|
||||
msg = '今日答题已完成,您当前分数为' + score + ',是否重新答题?'
|
||||
|
||||
submit() {
|
||||
const iids = this.questionData.issues.filter(v => !v.userSelect).map(v => v.iid)
|
||||
|
||||
if (iids.length > 0) {
|
||||
this.$toast('您还有' + iids.length + '题未作答,请答完后再提交!')
|
||||
document.getElementById('issue' + iids[0]).scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
'inline': 'start'
|
||||
});
|
||||
return
|
||||
}
|
||||
|
||||
const msg = '一旦提交不可修改,您确定要提交吗?'
|
||||
|
||||
this.$modal.confirm(msg).then(async () => {
|
||||
const {code} = await $.post('/mobile/question/h5/answerAgain', {questionId: this.questionData.qid})
|
||||
const replies = this.questionData.issues.map(v => {
|
||||
return {
|
||||
qid: this.id,
|
||||
issueId: v.iid,
|
||||
userSelect: v.userSelect,
|
||||
}
|
||||
})
|
||||
|
||||
const {code} = await $.post(BASE_URL + '/saveAnswer', {
|
||||
replies: JSON.stringify(replies),
|
||||
questionId: this.questionData.qid,
|
||||
isSave: false,
|
||||
randomCount: this.randomCount
|
||||
})
|
||||
this.$modal.closeLoading()
|
||||
if (code === 0) {
|
||||
this.$modal.msg('提交成功')
|
||||
await this.getUserHasAnswerRandomNum()
|
||||
await this.checkUserFinishAnswer()
|
||||
await this.getReply()
|
||||
const {ctMode} = this.questionData
|
||||
this.initCurrentIssueInfo(this.questionData.issues.find(v => v.displayDate && v.displayDate.includes(moment(new Date()).format('YYYY-MM-DD'))).iid)
|
||||
|
||||
/*if (ctMode === 2) {
|
||||
this.initCurrentIssueInfo(this.questionData.issues.find(v => v.displayDate && v.displayDate.includes(moment(new Date()).format('YYYY-MM-DD'))).iid)
|
||||
} else {
|
||||
this.initCurrentIssueInfo(this.questionData.issues[0].iid)
|
||||
}*/
|
||||
})
|
||||
} else if (this.replyInfo.map(v => v.issueId).length === 0) {
|
||||
|
||||
}
|
||||
},
|
||||
initCurrentIssueInfo(issueId) {
|
||||
if (issueId) {
|
||||
this.currentIssue = this.questionData.issues.find(v => v.iid === issueId)
|
||||
this.currentIssueIndex = this.todayIssueList.findIndex(v => v.iid === issueId)
|
||||
this.currentSelectedWors = this.currentIssue.wors.filter(v => this.replyInfo.filter(v => v.issueId === issueId).map(v => v.rwid).includes(v.wid))
|
||||
}
|
||||
},
|
||||
changeIssue(isNext) {
|
||||
const index = isNext ? this.currentIssueIndex + 1 : this.currentIssueIndex - 1
|
||||
const issueId = this.todayIssueList[index].iid
|
||||
this.currentSelectedWors = []
|
||||
this.initCurrentIssueInfo(issueId)
|
||||
},
|
||||
getScore() {
|
||||
let sum = 0
|
||||
if (this.replyInfo && this.replyInfo.length > 0) {
|
||||
this.todayIssueList.forEach(v => {
|
||||
const correctWids = v.wors.filter(x => x.correct).map(x => x.wid)
|
||||
const rwids = this.replyInfo.filter(x => x.issueId === v.iid).map(x => x.rwid)
|
||||
const eq = correctWids.length === rwids.length && correctWids.sort().toString() === rwids.sort().toString();
|
||||
if (eq) {
|
||||
sum += v.fraction
|
||||
await this.assignmentAnswer()
|
||||
await this.checkUserFinishAnswer()
|
||||
await this.checkCanAnswerAgain()
|
||||
await this.getScore()
|
||||
}
|
||||
})
|
||||
}
|
||||
return sum
|
||||
},
|
||||
async showWinInfo() {
|
||||
const {data} = await $.post('/mobile/question/h5/winInfo', {questionId: this.questionData.qid})
|
||||
const userId = "${@shiro.getPrincipalProperty('id')}"
|
||||
const user = data.find(o => o.id === userId)
|
||||
this.isWin = user !== undefined
|
||||
this.winList = data
|
||||
console.log(this.isWin)
|
||||
vant.Dialog.alert({
|
||||
message: '每人仅有一次中奖机会喔,点击查询获奖信息。'
|
||||
}).then(() => {
|
||||
this.winPopupShow = true
|
||||
});
|
||||
//获取回答信息
|
||||
async getReply() {
|
||||
const resp = await $.get(BASE_URL + '/answerInfo/' + this.id, {
|
||||
randomCount: this.randomCount,
|
||||
currentDate: this.currentDate
|
||||
})
|
||||
this.replyInfo = resp.data
|
||||
},
|
||||
//用户是否全部答完提交
|
||||
async checkUserFinishAnswer() {
|
||||
this.mLoading = true
|
||||
const resp = await $.get(BASE_URL + '/checkUserFinishAnswer', {
|
||||
questionId: this.id,
|
||||
randomCount: this.randomCount,
|
||||
currentDate: this.currentDate
|
||||
})
|
||||
this.mLoading = false
|
||||
this.finishAnswer = resp.data
|
||||
await this.getReply()
|
||||
await this.assignmentAnswer()
|
||||
},
|
||||
|
||||
//答案赋值
|
||||
assignmentAnswer() {
|
||||
this.questionData.issues.forEach(issue => {
|
||||
const rwids = this.replyInfo.filter(v => v.issueId === issue.iid).map(v => v.rwid)
|
||||
rwids.forEach(rwid => {
|
||||
this.toggle(issue, rwid)
|
||||
})
|
||||
const wids = issue.wors.filter(v => v.correct).map(v => v.wid)
|
||||
const userSelects = this.replyInfo.filter(v => v.issueId === issue.iid).map(v => v.rwid)
|
||||
const isEqual = wids.length === userSelects.length && wids.every(value => userSelects.includes(value))
|
||||
issue.isEqual = isEqual
|
||||
})
|
||||
},
|
||||
|
||||
answerAgain() {
|
||||
this.finishAnswer = false
|
||||
setTimeout(() => {
|
||||
this.questionData.issues.forEach(issue => {
|
||||
issue.wors.forEach(wor => {
|
||||
this.$refs['checkboxes' + wor.wid][0].toggle(false)
|
||||
})
|
||||
})
|
||||
}, 0)
|
||||
},
|
||||
|
||||
async getUserHasAnswerRandomNum() {
|
||||
const resp = await $.get(BASE_URL + '/getUserHasAnswerRandomNum', {
|
||||
questionId: this.id
|
||||
})
|
||||
this.userHasAnswerRandomNum = resp.data
|
||||
this.randomCount = this.userHasAnswerRandomNum
|
||||
},
|
||||
|
||||
async checkCanAnswerAgain() {
|
||||
const resp = await $.get(BASE_URL + '/checkCanAnswerAgain', {
|
||||
questionId: this.id,
|
||||
randomCount: this.randomCount,
|
||||
currentDate: this.currentDate
|
||||
})
|
||||
this.canAnswerAgain = resp.data
|
||||
},
|
||||
|
||||
async getScore() {
|
||||
const resp = await $.get(BASE_URL + '/getScore/', {
|
||||
questionId: this.id,
|
||||
randomCount: this.randomCount,
|
||||
currentDate: this.currentDate
|
||||
})
|
||||
this.currentScore = resp.data
|
||||
}
|
||||
|
||||
},
|
||||
async created() {
|
||||
this.id = GetQueryString("id")
|
||||
await this.getQuestionData()
|
||||
await this.getReply()
|
||||
const {ctMode} = this.questionData
|
||||
|
||||
this.initCurrentIssueInfo(this.questionData.issues.find(v => v.displayDate && v.displayDate.includes(moment(new Date()).format('YYYY-MM-DD')))?.iid)
|
||||
/* if (ctMode === 2) {
|
||||
this.initCurrentIssueInfo(this.questionData.issues.find(v => v.displayDate && v.displayDate.includes(moment(new Date()).format('YYYY-MM-DD'))).iid)
|
||||
} else {
|
||||
this.initCurrentIssueInfo(this.questionData.issues[0].iid)
|
||||
}*/
|
||||
const {data: scoreMap} = await $.get('/mobile/question/h5/todayMaxScore', {questionId: this.questionData.qid})
|
||||
const scoreValues = Object.values(scoreMap)
|
||||
let msg = null
|
||||
console.log(scoreValues)
|
||||
if (scoreValues.length >= 1 && this.todayIssueList.map(x => x.iid).some(x => !this.replyInfo.map(v => v.issueId).includes(x))) {
|
||||
console.log(111)
|
||||
const maxScore = Math.max(...scoreValues)
|
||||
msg = '您历史的最高分数为' + maxScore + '分!'
|
||||
this.$modal.confirm(msg).then(async () => {
|
||||
|
||||
})
|
||||
} else {
|
||||
this.checkTodayReplyFinish()
|
||||
}
|
||||
await this.checkCanAnswerAgain()
|
||||
await this.getUserHasAnswerRandomNum()
|
||||
await this.checkUserFinishAnswer()
|
||||
await this.getScore()
|
||||
this.mLoading = false
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener('pageshow', async e => {
|
||||
if (e.persisted || (window.performance && window.performance.navigation.type === 2)) {
|
||||
vue.id = GetQueryString("id")
|
||||
await vue.getQuestionData()
|
||||
// await vue.getRanDomModeNum()
|
||||
// await vue.getSumScore()
|
||||
// await vue.checkUserFinishAnswer()
|
||||
// await vue.getCurrentRandomCountScore()
|
||||
this.mLoading = false
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
|
||||
@@ -86,13 +86,14 @@ layout("/mobile/platform.html"){
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
}
|
||||
.winPopup img{
|
||||
|
||||
.winPopup img {
|
||||
transform: translateY(-50%);
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
.winPopup .van-popup__close-icon{
|
||||
.winPopup .van-popup__close-icon {
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ layout("/mobile/platform.html"){
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.win_tag{
|
||||
.win_tag {
|
||||
position: relative;
|
||||
top: 16px;
|
||||
left: 5px;
|
||||
@@ -138,19 +139,25 @@ layout("/mobile/platform.html"){
|
||||
<div class="quizzes-item-info-v">
|
||||
<div class="quizzes-item-info-title">{{ item.qtitle }}</div>
|
||||
<div class="quizzes-item-info-right">
|
||||
<span class="quizzes-item-info-tip">创建时间:</span>
|
||||
<span class="quizzes-item-info-tip">活动开始时间:</span>
|
||||
<span class="quizzes-item-info-text">
|
||||
{{ moment(item.createTime).format('YYYY年MM月DD日') }}
|
||||
{{ moment(item.startTime).format('YYYY年MM月DD日') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="quizzes-item-info-right" v-if="item.qlx!==4">
|
||||
<span class="quizzes-item-info-tip">题目数量:</span>
|
||||
<div class="quizzes-item-info-right">
|
||||
<span class="quizzes-item-info-tip">活动结束时间:</span>
|
||||
<span class="quizzes-item-info-text">
|
||||
{{item.ctMode === 1 ? item.topicTotal : item.ctNum }}
|
||||
{{ moment(item.endTime).format('YYYY年MM月DD日') }}
|
||||
</span>
|
||||
<span class="quizzes-item-info-text" style="position: absolute;right: 0" >
|
||||
<van-tag @click.stop="showWinInfo(item)" type="primary" class="win_tag" v-if="item.qlx===2 && item.isRaffle && moment(item.startTime).diff(moment(new Date().getTime()),'days') < 0">获奖信息</van-tag>
|
||||
<!-- v-if="moment(item.startTime).diff(moment(new Date().getTime()),'days') < 0"-->
|
||||
</div>
|
||||
<div class="quizzes-item-info-right" v-if="item.isRaffle">
|
||||
<!-- <span class="quizzes-item-info-tip">题目数量:</span>-->
|
||||
<!-- <span class="quizzes-item-info-text">-->
|
||||
<!-- {{item.ctMode === 1 ? item.topicTotal : item.ctNum }}-->
|
||||
<!-- </span>-->
|
||||
<span class="quizzes-item-info-text" style="position: absolute;right: 0;bottom: 0">
|
||||
<van-tag @click.stop="showWinInfo(item)" type="primary" class="win_tag"
|
||||
v-if="item.qlx===2 && item.isRaffle && moment().isAfter(moment('2024-06-18 00:05:00'))">获奖信息</van-tag>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -169,13 +176,19 @@ layout("/mobile/platform.html"){
|
||||
>
|
||||
<div style="display: flex;align-items: center">
|
||||
<img v-if="isWin" width="100%" height="60%" src="/assets/mobile/img/question/win.png"/>
|
||||
<img v-if="!isWin" width="100%" height="50%" src="/assets/mobile/img/question/noWin1.png"/>
|
||||
<img v-if="!isWin" width="100%" height="50%"
|
||||
src="/assets/mobile/img/question/noWin1-removebg-preview.png"/>
|
||||
</div>
|
||||
<div class="iconDiv">
|
||||
<div v-if="isWin" style="font-size: 14px;!important;">恭喜您中奖了,本次活动中奖机会只有一次喔!</div>
|
||||
<van-icon @click="winPopupShow = false" name="close"></van-icon>
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
<van-dialog v-model="tipShow" title="提示">
|
||||
<div>活动期间,每天答题次数不限,每天答题的最终成绩取最高分。每天答题得90分(含)以上者,可参加线上抽奖活动。</div>
|
||||
<div>6月17日至6月23日每天线上抽取“幸运奖”100名'。</div>
|
||||
</van-dialog>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -192,8 +205,10 @@ layout("/mobile/platform.html"){
|
||||
queryForm: {
|
||||
status: '1'
|
||||
},
|
||||
winPopupShow:false,
|
||||
isWin:false
|
||||
winPopupShow: false,
|
||||
isWin: false,
|
||||
|
||||
tipShow:false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -269,6 +284,7 @@ layout("/mobile/platform.html"){
|
||||
|
||||
async openAnswer(item) {
|
||||
const {qid, qlx, qflag, activityUserScopeId} = item
|
||||
|
||||
if (qflag !== 2) {
|
||||
this.$modal.msg('该问卷未发布')
|
||||
return
|
||||
@@ -280,13 +296,39 @@ layout("/mobile/platform.html"){
|
||||
return
|
||||
}
|
||||
|
||||
/*if (activityUserScopeId) {
|
||||
if (activityUserScopeId) {
|
||||
const resp = await $.get('/mobile/question/h5/checkPermission/' + activityUserScopeId)
|
||||
if (!resp.data) {
|
||||
this.$modal.msg('您无权限参加')
|
||||
return
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (qid === '827cc4ef9cde47ed97bc21f6be75f91a') {
|
||||
this.$dialog.alert({
|
||||
title:'提示',
|
||||
messageAlign:'left',
|
||||
message: '<div style="text-indent: 2em;">活动期间,每天答题次数不限,每天答题的最终成绩取最高分。每天答题得90分(含)以上者,可参加线上抽奖活动。<div>' +
|
||||
'<div style="text-indent: 2em;">6月17日至6月23日每天线上抽取“幸运奖”100名。</div>'+
|
||||
'<div style="text-indent: 2em;">答题并提交成功后,可于次日查看获奖信息。</div>'
|
||||
,
|
||||
}).then(()=>{
|
||||
if (qlx === 1) {
|
||||
//调查
|
||||
location.href = '/mobile/question/h5/poll/index?id=' + qid
|
||||
} else if (qlx === 2) {
|
||||
//答题
|
||||
location.href = '/mobile/question/h5/answer/index?id=' + qid
|
||||
} else if (qlx === 3) {
|
||||
//购物
|
||||
location.href = '/mobile/question/h5/shop/index?id=' + qid
|
||||
} else if (qlx === 4) {
|
||||
//蛋糕卡
|
||||
location.href = '/mobile/question/h5/cake/index?id=' + qid
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (qlx === 1) {
|
||||
//调查
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
<!--#
|
||||
layout("/mobile/platform.html"){
|
||||
#-->
|
||||
|
||||
<style>
|
||||
.middle-subject {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
background-color: #f6f7f9;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.middle-subject-info-padding {
|
||||
padding: 10px;
|
||||
background-color: #f6f7f9;
|
||||
}
|
||||
|
||||
.middle-subject-info-scroll {
|
||||
/*height: 100%;*/
|
||||
height: calc(100vh - 110px);
|
||||
max-height: calc(100vh - 110px);
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.middle-subject-info-head {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.middle-subject-topic-icon {
|
||||
width: 30px;
|
||||
padding: 2px;
|
||||
font-size: 10px;
|
||||
background-color: #1678ff;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
border-radius: 0 0 5px 5px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 10px;
|
||||
}
|
||||
|
||||
.middle-subject-title {
|
||||
margin-bottom: 1rem;
|
||||
font-weight: bolder;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.middle-subject-other {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.middle-subject-topic {
|
||||
background-color: #FFFFFF;
|
||||
margin-bottom: 1rem;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 2px 2px 12px 4px rgba(0, 0, 0, 0.1);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.middle-subject-topic-title {
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
.middle-subject-topic-submit {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.middle-subject-topic-desc {
|
||||
color: rgb(160, 160, 160);
|
||||
text-align: left;
|
||||
margin-left: 20px;
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.itx_field {
|
||||
background-color: #fff;
|
||||
background-image: none;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dcdfe6;
|
||||
box-sizing: border-box;
|
||||
color: #606266;
|
||||
display: inline-block;
|
||||
font-size: inherit;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
outline: none;
|
||||
padding: 0 15px;
|
||||
transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
.middle-subject-topic-submit .u-btn {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.middle-subject-info-search {
|
||||
position: absolute;
|
||||
bottom: 45%;
|
||||
right: 0;
|
||||
height: 40px;
|
||||
z-index: 999;
|
||||
background-color: #FFF;
|
||||
box-shadow: 0 0 20px rgb(230, 230, 230);
|
||||
border-radius: 20px 0 0 20px;
|
||||
}
|
||||
|
||||
.middle-subject-info-search-icon {
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
box-shadow: 0 0 10px #1678ff;
|
||||
border-radius: 20px 0 0 20px;
|
||||
background-color: #FFF;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.middle-subject-info-search-info {
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
height: inherit;
|
||||
z-index: 999;
|
||||
align-items: center;
|
||||
box-shadow: 0 0 10px #1678ff;
|
||||
border-radius: 20px 0 0 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
.middle-subject-info-footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-height: 64px;
|
||||
background-color: #FFF;
|
||||
box-shadow: 0 0 20px rgb(230, 230, 230);
|
||||
z-index: 999;
|
||||
padding: 10px 20px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.middle-subject-info-footer-save {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.middle-subject-info-footer-save .van-button {
|
||||
/*width: 40%;*/
|
||||
width: calc((100% - 100px) / 2);
|
||||
}
|
||||
|
||||
.middle-subject-info-footer-pagination {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
.van-radio__label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.totalMoney {
|
||||
width: 80px;
|
||||
max-width: 80px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
overflow-x: scroll;
|
||||
color: red;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="app" v-cloak>
|
||||
<div class="middle-subject">
|
||||
<van-nav-bar title="在线调查" left-arrow
|
||||
@click-left="history.back()"></van-nav-bar>
|
||||
|
||||
<div class="middle-subject-info">
|
||||
<div class="middle-subject-info-scroll">
|
||||
<div class="middle-subject-info-padding">
|
||||
<div class="middle-subject-info-head">
|
||||
<div class="middle-subject-title">{{ questionData.qtitle }}</div>
|
||||
<div class="middle-subject-other">
|
||||
<template v-if="questionData.qlx!==3">
|
||||
<!-- <span>创建人:{{ questionData.username }}</span>-->
|
||||
<!-- <span>总题数:{{ issueList.length }}</span>-->
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="middle-subject-info-body">
|
||||
<div class="middle-subject-topic" v-for="(issue,issueIndex) in issueList" :key="issue.qid">
|
||||
<div v-if="!issue.iisdx" class="middle-subject-topic-icon">
|
||||
<span>多选</span>
|
||||
</div>
|
||||
<div style="margin-bottom: 10px">
|
||||
<span v-if="issue.iisbd" style="color: red;">*</span>
|
||||
<span class="middle-subject-topic-title">
|
||||
{{ issueIndex + 1 }}.
|
||||
{{ removeHTMLTag(issue.iname) }}
|
||||
<span v-if="issue.iminselect">(最少选择:{{issue.iminselect}})</span>
|
||||
<span v-if="issue.imaxselect">(最多选择:{{issue.imaxselect}})</span>
|
||||
<div v-if="issue.its" class="middle-subject-topic-desc"
|
||||
style="margin-left: 17px;font-size: 12px;font-weight: 500;">
|
||||
{{ issue.its }}
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 选择题 -->
|
||||
<template v-if="issue.itx===1">
|
||||
<!-- 单选题 -->
|
||||
<van-radio-group v-if="issue.iisdx" v-model="issue.rwid" :disabled="replyFinish">
|
||||
<div v-for="(wor,worIndex) in issue.wors" :key="wor.wid">
|
||||
<van-radio :ref="wor.wid" :name="wor.wid">
|
||||
{{ letterList[worIndex] }}. {{ wor.wtxt }}
|
||||
</van-radio>
|
||||
<div class="middle-subject-topic-desc">
|
||||
<van-row gutter="16">
|
||||
<van-col span="8" v-if="wor.wimg">
|
||||
<image style="height: 80px;width: 80px" :src="wor.wimg"
|
||||
mode="aspectFit">
|
||||
</image>
|
||||
</van-col>
|
||||
<van-col span="16" v-if="wor.wsm">
|
||||
{{ wor.wsm }}
|
||||
</van-col>
|
||||
</van-row>
|
||||
<van-row style="margin-top: 10px;">
|
||||
<van-col :span="8"
|
||||
style="height: 28px;line-height: 28px;font-size: 14px;color: #d16565">
|
||||
单价:¥{{ wor.price }}
|
||||
</van-col>
|
||||
<van-col :span="16" style="display: flex;justify-content: right"
|
||||
v-if="issue.rwid === wor.wid">
|
||||
<view style="height: 28px;line-height: 28px;font-size: 14px;color: #d16565;">
|
||||
数量:
|
||||
</view>
|
||||
<van-stepper v-model="wor.number" :disabled="replyFinish" integer
|
||||
disable-input :default-value="0"
|
||||
:min="0"></van-stepper>
|
||||
</van-col>
|
||||
</van-row>
|
||||
</div>
|
||||
</div>
|
||||
</van-radio-group>
|
||||
|
||||
<!-- 多选题 -->
|
||||
<van-checkbox-group v-else-if="!issue.iisdx" v-model="issue.rwid"
|
||||
:disabled="replyFinish"
|
||||
:max="issue.imaxselect ? issue.imaxselect:0">
|
||||
<div v-for="(wor,worIndex) in issue.wors" :key="wor.wid">
|
||||
<van-checkbox :ref="wor.wid" :name="wor.wid" shape="square">
|
||||
{{ letterList[worIndex] }}. {{ wor.wtxt }}
|
||||
</van-checkbox>
|
||||
<div class="middle-subject-topic-desc">
|
||||
<van-row gutter="16">
|
||||
<van-col span="8" v-if="wor.wimg">
|
||||
<image style="height: 80px;width: 80px" :src="wor.wimg"
|
||||
mode="aspectFit">
|
||||
</image>
|
||||
</van-col>
|
||||
<van-col span="16" v-if="wor.wsm">
|
||||
{{ wor.wsm }}
|
||||
</van-col>
|
||||
</van-row>
|
||||
<van-row style="margin-top: 10px;">
|
||||
<van-col :span="8"
|
||||
style="height: 28px;line-height: 28px;font-size: 14px;color: #d16565">
|
||||
单价:¥{{ wor.price }}
|
||||
</van-col>
|
||||
<van-col :span="16" style="display: flex;justify-content: right"
|
||||
v-if="issue.rwid && issue.rwid.includes(wor.wid)">
|
||||
<view style="height: 28px;line-height: 28px;font-size: 14px;color: #d16565;">
|
||||
数量:
|
||||
</view>
|
||||
<van-stepper v-model="wor.number" :disabled="replyFinish" integer
|
||||
disable-input :default-value="0"
|
||||
:min="0"></van-stepper>
|
||||
</van-col>
|
||||
</van-row>
|
||||
</div>
|
||||
</div>
|
||||
</van-checkbox-group>
|
||||
</template>
|
||||
|
||||
<!-- 填空题 -->
|
||||
<template v-if="issue.itx===2">
|
||||
<van-field v-model="issue.rval" type="text" border
|
||||
class="itx_field"
|
||||
cursor-spacing="100"
|
||||
:show-confirmbar="false"
|
||||
:disabled="replyFinish" :auto-height="true" maxlength="2000"></van-field>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="middle-subject-info-footer">
|
||||
<div class="middle-subject-info-footer-save">
|
||||
<div class="totalMoney">
|
||||
¥{{ totalMoney }}
|
||||
</div>
|
||||
<van-button size="medium" type="primary" @click="saveAnswer" :disabled="replyFinish">
|
||||
保存
|
||||
</van-button>
|
||||
<van-button size="medium" type="info" :disabled="replyFinish" @click="submitAnswer">
|
||||
提交
|
||||
</van-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const vue = new Vue({
|
||||
el: '#app',
|
||||
mixins: [mobileMixins],
|
||||
data() {
|
||||
return {
|
||||
id: null,
|
||||
questionData: {},
|
||||
issueList: [],
|
||||
replyInfo: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
letterList() {
|
||||
const alphabet = Array.from(new Array(26), (ele, index) => {
|
||||
return String.fromCharCode(65 + index);
|
||||
})
|
||||
return alphabet
|
||||
},
|
||||
replyFinish() {
|
||||
return this.replyInfo.some(v => !v.save)
|
||||
},
|
||||
totalMoney() {
|
||||
let sum = 0
|
||||
this.issueList.forEach(v => {
|
||||
if (v.itx === 1 && v.iisdx && v.rwid) {
|
||||
//单选
|
||||
const sel = v.wors.find(w => w.wid === v.rwid)
|
||||
sum += sel.number * sel.price
|
||||
} else if (v.itx === 1 && !v.iisdx && v.rwid) {
|
||||
//多选
|
||||
sum += v.wors.filter(w => v.rwid.includes(w.wid)).map(w => isNaN(w.price * w.number) ? 0 : w.price * w.number).reduce((a, b) => a + b, 0)
|
||||
}
|
||||
})
|
||||
return sum
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getQuestionData() {
|
||||
const resp = await $.get('/mobile/question/h5/questionInfo/' + this.id)
|
||||
this.questionData = resp.data
|
||||
this.issueList = this.questionData && this.questionData.issues
|
||||
},
|
||||
saveAnswer() {
|
||||
const formData = this.formatFormData(true)
|
||||
if (formData.length === 0) {
|
||||
this.$modal.msg('请先选择后再保存')
|
||||
return
|
||||
}
|
||||
if (formData.some(v => v.number === 0)) {
|
||||
this.$modal.msg('最少选择一项')
|
||||
return
|
||||
}
|
||||
|
||||
this.$modal.loading('保存中')
|
||||
$.post('/mobile/question/h5/saveAnswer', {repliesArray: JSON.stringify(formData)}).then(res => {
|
||||
this.$modal.closeLoading()
|
||||
if (res.code === 0) {
|
||||
this.$modal.msg('保存成功')
|
||||
this.getReply()
|
||||
} else {
|
||||
this.$modal.msg('保存失败')
|
||||
}
|
||||
})
|
||||
},
|
||||
submitAnswer() {
|
||||
const formData = this.formatFormData(false)
|
||||
if (formData.length === 0) {
|
||||
this.$modal.msg('请先选择后再提交')
|
||||
return
|
||||
}
|
||||
if (formData.some(v => v.number === 0)) {
|
||||
this.$modal.msg('最少选择一项')
|
||||
return
|
||||
}
|
||||
this.$modal.confirm('您确定要提交吗?提交后不能修改!').then(() => {
|
||||
this.$modal.loading('提交中')
|
||||
$.post('/mobile/question/h5/saveAnswer', {repliesArray: JSON.stringify(formData)}).then(res => {
|
||||
this.$modal.closeLoading()
|
||||
if (res.code === 0) {
|
||||
this.$modal.msg('提交成功')
|
||||
this.getReply()
|
||||
} else {
|
||||
this.$modal.msg('提交失败')
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
//格式化提交数据
|
||||
formatFormData(save) {
|
||||
const formData = []
|
||||
this.issueList.forEach(v => {
|
||||
if (v.itx === 1 && v.iisdx) {
|
||||
//单选
|
||||
if (v.rwid) {
|
||||
formData.push({
|
||||
"rwid": v.rwid,
|
||||
"qid": this.questionData.qid,
|
||||
"issueId": v.iid,
|
||||
"number": v.wors.find(w => w.wid === v.rwid).number,
|
||||
"save": save
|
||||
})
|
||||
}
|
||||
} else if (v.itx === 1 && !v.iisdx) {
|
||||
//多选
|
||||
if (v.rwid) {
|
||||
v.rwid.forEach(r => {
|
||||
formData.push({
|
||||
"rwid": r,
|
||||
"qid": this.questionData.qid,
|
||||
"issueId": v.iid,
|
||||
"number": v.wors.find(w => w.wid === r).number,
|
||||
"save": save
|
||||
})
|
||||
})
|
||||
}
|
||||
} else if (v.itx === 2) {
|
||||
if (v.rval) {
|
||||
formData.push({
|
||||
"rval": v.rval,
|
||||
"qid": this.questionData.qid,
|
||||
"issueId": v.iid,
|
||||
"save": save
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return formData
|
||||
},
|
||||
//获取回答信息并赋值
|
||||
async getReply() {
|
||||
const resp = await $.get('/mobile/question/h5/answerInfo/' + this.id)
|
||||
this.replyInfo = resp.data
|
||||
this.issueList.forEach((issue, issueIndex) => {
|
||||
if (issue.itx === 1 && issue.iisdx) {
|
||||
//单选
|
||||
const rw = this.replyInfo.find(answer => answer.issueId === issue.iid)
|
||||
this.$set(this.issueList[issueIndex], 'rwid', rw ? rw.rwid : null)
|
||||
if (rw) {
|
||||
const worIndex = issue.wors.findIndex(v => v.wid === rw.rwid)
|
||||
this.$set(this.issueList[issueIndex]['wors'][worIndex], 'number', rw ? rw.number : 0)
|
||||
}
|
||||
} else if (issue.itx === 1 && !issue.iisdx) {
|
||||
//多选
|
||||
const rws = this.replyInfo.filter(answer => answer.issueId === issue.iid)
|
||||
this.$set(this.issueList[issueIndex], 'rwid', rws ? rws.map(v => v.rwid) : [])
|
||||
if (rws) {
|
||||
rws.forEach(rw => {
|
||||
const worIndex = issue.wors.findIndex(v => v.wid === rw.rwid)
|
||||
this.$set(issue.wors[worIndex], 'number', rw ? rw.number : 0)
|
||||
})
|
||||
}
|
||||
} else if (issue.itx === 2) {
|
||||
//填空题
|
||||
const rw = this.replyInfo.find(answer => answer.issueId === issue.iid)
|
||||
this.$set(this.issueList[issueIndex], 'rval', rw ? rw.rval : null)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
this.id = GetQueryString("id")
|
||||
await this.getQuestionData()
|
||||
await this.getReply()
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
@@ -34,14 +34,6 @@ layout("/layouts/platform.html"){
|
||||
color: red;
|
||||
}
|
||||
|
||||
#qsmEditor .w-e-text-container {
|
||||
height: 200px !important;
|
||||
}
|
||||
|
||||
#qsmEditor div {
|
||||
z-index: 0 !important;
|
||||
}
|
||||
|
||||
.btDiv {
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -229,7 +221,7 @@ layout("/layouts/platform.html"){
|
||||
<template #edit>
|
||||
<div v-if="editMode==='basicInfo'">
|
||||
<el-form :model="formData" :rules="formRules" label-position="right"
|
||||
label-width="120px" ref="addform">
|
||||
label-width="120px" ref="addForm">
|
||||
<vi-title2 title="基础设置"></vi-title2>
|
||||
|
||||
<el-form-item label="问卷类型" prop="qlx">
|
||||
@@ -238,76 +230,12 @@ layout("/layouts/platform.html"){
|
||||
<el-radio :label="1" border>投票调查</el-radio>
|
||||
<el-radio :label="2" border>答题</el-radio>
|
||||
<!-- <el-radio :label="3" border>购物调查</el-radio>-->
|
||||
<el-radio :label="4" border>意向选择</el-radio>
|
||||
<!-- <el-radio :label="4" border>意向选择</el-radio>-->
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item class="is-required" label="标题" prop="qtitle">
|
||||
<el-input placeholder="请填写标题" v-model="formData.qtitle"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-row v-show="![1,3,4].includes(formData.qlx)" :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item class="is-required" label="每日可答次数" label-width="120px"
|
||||
prop="qrkdcs">
|
||||
<el-input-number :max="100" :min="0"
|
||||
controls-position="right"
|
||||
placeholder="设0则不限制次数"
|
||||
style="width: 100%"
|
||||
v-model="formData.qrkdcs"></el-input-number>
|
||||
<div class="text-primary">设0则不限制次数</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="每日答题时间" prop="qdtkssj">
|
||||
<el-time-picker
|
||||
end-placeholder="结束时间"
|
||||
is-range
|
||||
placeholder="选择时间范围"
|
||||
range-separator="-"
|
||||
start-placeholder="开始时间"
|
||||
style="width: 100%"
|
||||
v-model="formData.qdtsj"
|
||||
value-format="HH:mm:ss">
|
||||
</el-time-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="开始时间" prop="startTime">
|
||||
<el-date-picker
|
||||
style="width: 100%"
|
||||
type="datetime"
|
||||
v-model="formData.startTime"
|
||||
value-format="timestamp">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="结束时间" prop="endTime">
|
||||
<el-date-picker
|
||||
:picker-options="endTimeOptions"
|
||||
style="width: 100%"
|
||||
type="datetime"
|
||||
v-model="formData.endTime"
|
||||
value-format="timestamp">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8" v-show="formData.qlx===4">
|
||||
<el-form-item label="自动选择默认项" label-width="150px" prop="autoSelect">
|
||||
<el-switch
|
||||
v-model="formData.autoSelect"
|
||||
>
|
||||
</el-switch>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-form-item label="说明" prop="qsm">
|
||||
<div id="qsmEditor"></div>
|
||||
<el-input placeholder="请填写标题" v-model="formData.qtitle" maxlength="200"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="参加人员" prop="activityUserScopeId">
|
||||
@@ -326,52 +254,236 @@ layout("/layouts/platform.html"){
|
||||
</el-form-item>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="出题模式" prop="ctMode">
|
||||
<el-radio-group v-model="formData.ctMode" size="small">
|
||||
<el-radio :label="1" border>定时定题</el-radio>
|
||||
<el-radio :label="2" border>随机题目</el-radio>
|
||||
</el-radio-group>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="开始时间" prop="startTime"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-date-picker
|
||||
style="width: 100%"
|
||||
type="datetime"
|
||||
v-model="formData.startTime"
|
||||
value-format="timestamp">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6" v-if="formData.ctMode===2">
|
||||
<el-form-item label="单次出题数量" prop="ctNum">
|
||||
<!--:max="formData.issues.length"-->
|
||||
<el-input-number :min="1"
|
||||
controls-position="right"
|
||||
<el-col :span="12">
|
||||
<el-form-item label="结束时间" prop="endTime"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-date-picker
|
||||
:picker-options="endTimeOptions"
|
||||
style="width: 100%"
|
||||
v-model="formData.ctNum"></el-input-number>
|
||||
type="datetime"
|
||||
v-model="formData.endTime"
|
||||
value-format="timestamp">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-form-item label="说明" prop="qsm">
|
||||
<text-editor v-model="formData.qsm"></text-editor>
|
||||
</el-form-item>
|
||||
|
||||
<vi-title2 title="出题设置"></vi-title2>
|
||||
|
||||
<el-form-item label="出题模式" prop="ctMode"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-radio-group v-model="formData.ctMode" size="small">
|
||||
<el-radio :label="1" border>定时定题</el-radio>
|
||||
<el-radio :label="2" border>随机题目</el-radio>
|
||||
<el-radio :label="3" border>常规模式</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="题目顺序打乱" prop="disruptingOrder"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-radio-group v-model="formData.disruptingOrder" size="small">
|
||||
<el-radio :label="true" border>打乱</el-radio>
|
||||
<el-radio :label="false" border>不变</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-row :gutter="20" v-if="formData.ctMode==2">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="是否抽奖" prop="isRaffle">
|
||||
<el-radio-group v-model="formData.isRaffle" size="small">
|
||||
<el-form-item label="单次随机题数" prop="ranDomSingleIssueNum"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-input-number :min="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
v-model="formData.ranDomSingleIssueNum"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="总共随机数" prop="ranDomSum"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-input-number :min="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
v-model="formData.ranDomSum"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20"
|
||||
v-if="formData.ctMode!=2 || (formData.ctMode==2 && formData.startTime && formData.endTime && moment(formData.endTime).diff(formData.startTime,'days') >= 1)">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="是否可重复答" prop="canRepeatedAnswer"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-radio-group v-model="formData.canRepeatedAnswer" size="small">
|
||||
<el-radio :label="true" border>是</el-radio>
|
||||
<el-radio :label="false" border>否</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6" v-if="formData.isRaffle">
|
||||
<el-form-item label="抽奖分数" prop="raffleScore">
|
||||
<el-input-number :min="1"
|
||||
<el-col :span="24">
|
||||
<el-form-item label="可重复答次数"
|
||||
prop="canRepeatedAnswerNum"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]"
|
||||
v-if="formData.canRepeatedAnswer">
|
||||
<el-input-number :min="0"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
v-model="formData.raffleScore"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6" v-if="formData.isRaffle">
|
||||
<el-form-item label="获奖人数" prop="raffleWinnerUserNum">
|
||||
<el-input-number :max="10000" :min="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
v-model="formData.raffleWinnerUserNum"></el-input-number>
|
||||
style="width: 300px"
|
||||
v-model="formData.canRepeatedAnswerNum"></el-input-number>
|
||||
<div class="text-primary">设0则为不限制</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<template>
|
||||
<vi-title2 title="分数统计设置"></vi-title2>
|
||||
<el-form-item label="分数统计" prop="calcScoreMode"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-radio-group v-model="formData.calcScoreMode" size="small">
|
||||
<el-radio :label="1" border>最高得分</el-radio>
|
||||
<el-radio :label="2" border>最新得分</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<vi-title2 title="抽奖设置"></vi-title2>
|
||||
<el-form-item label="是否抽奖" prop="isRaffle"
|
||||
:rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">
|
||||
<el-radio-group v-model="formData.isRaffle" size="small">
|
||||
<el-radio :label="true" border>是</el-radio>
|
||||
<el-radio :label="false" border>否</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
<el-form-item label="抽奖规则" prop="raffleRule" v-if="formData.isRaffle">
|
||||
<el-table :data="formData.raffleRule" border size="small">
|
||||
<el-table-column label="开始答题时间" prop="startAnswerDate">
|
||||
<template scope="{row,$index}">
|
||||
<el-form-item label-width="0"
|
||||
:prop="'raffleRule.'+$index+'.startAnswerDate'"
|
||||
:rules="[{required:true,message:'必填',trigger:['change','blur']}]">
|
||||
<el-date-picker
|
||||
v-model="row.startAnswerDate"
|
||||
type="datetime"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
placeholder="选择开始答题时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="结束答题时间" prop="endAnswerDate">
|
||||
<template scope="{row,$index}">
|
||||
<el-form-item label-width="0"
|
||||
:prop="'raffleRule.'+$index+'.endAnswerDate'"
|
||||
:rules="[{required:true,message:'必填',trigger:['change','blur']}]">
|
||||
<el-date-picker
|
||||
v-model="row.endAnswerDate"
|
||||
type="datetime"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
placeholder="选择结束答题时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="抽奖时间" prop="raffleTime">
|
||||
<template scope="{row,$index}">
|
||||
<el-form-item label-width="0"
|
||||
:prop="'raffleRule.'+$index+'.raffleTime'"
|
||||
:rules="[{required:true,message:'必填',trigger:['change','blur']}]">
|
||||
<el-date-picker
|
||||
v-model="row.raffleTime"
|
||||
type="datetime"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
placeholder="选择抽奖时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="抽奖分数" prop="raffleScore">
|
||||
<template scope="{row,$index}">
|
||||
<el-form-item label-width="0"
|
||||
:prop="'raffleRule.'+$index+'.raffleScore'"
|
||||
:rules="[{required:true,message:'必填',trigger:['change','blur']}]">
|
||||
<el-input-number :min="1"
|
||||
controls-position="right"
|
||||
style="width: 300px"
|
||||
placeholder="抽奖分数"
|
||||
v-model="row.raffleScore"></el-input-number>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="获奖人数" prop="raffleWinnerUserNum">
|
||||
<template scope="{row,$index}">
|
||||
<el-form-item label-width="0"
|
||||
:prop="'raffleRule.'+$index+'.raffleWinnerUserNum'"
|
||||
:rules="[{required:true,message:'必填',trigger:['change','blur']}]">
|
||||
<el-input-number :min="1"
|
||||
controls-position="right"
|
||||
style="width: 300px"
|
||||
placeholder="获奖人数"
|
||||
v-model="row.raffleWinnerUserNum"></el-input-number>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column width="100px">
|
||||
<template scope="{row}" slot="header">
|
||||
<el-button icon="el-icon-plus"
|
||||
size="mini"
|
||||
type="primary"
|
||||
@click="formData.raffleRule.push({})"
|
||||
></el-button>
|
||||
</template>
|
||||
<template scope="{$index}">
|
||||
<el-button size="mini"
|
||||
icon="el-icon-delete"
|
||||
type="danger"
|
||||
@click="formData.raffleRule.splice($index,1)"></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
|
||||
<!-- <el-form-item label="抽奖时间" prop="raffleTime"-->
|
||||
<!-- v-if="formData.isRaffle"-->
|
||||
<!-- :rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">-->
|
||||
<!-- <el-date-picker-->
|
||||
<!-- v-model="formData.raffleTime"-->
|
||||
<!-- type="datetime"-->
|
||||
<!-- value-format="yyyy-MM-dd HH:mm:ss"-->
|
||||
<!-- placeholder="选择抽奖时间">-->
|
||||
<!-- </el-date-picker>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="抽奖分数" prop="raffleScore"-->
|
||||
<!-- v-if="formData.isRaffle"-->
|
||||
<!-- :rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">-->
|
||||
<!-- <el-input-number :min="1"-->
|
||||
<!-- controls-position="right"-->
|
||||
<!-- style="width: 300px"-->
|
||||
<!-- v-model="formData.raffleScore"></el-input-number>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="获奖人数" prop="raffleWinnerUserNum"-->
|
||||
<!-- v-if="formData.isRaffle"-->
|
||||
<!-- :rules="[{required: true, message: '必填', trigger: ['blur', 'change']}]">-->
|
||||
<!-- <el-input-number :max="10000" :min="1"-->
|
||||
<!-- controls-position="right"-->
|
||||
<!-- style="width: 300px"-->
|
||||
<!-- v-model="formData.raffleWinnerUserNum"></el-input-number>-->
|
||||
<!-- </el-form-item>-->
|
||||
|
||||
<el-row type="flex" justify="end">
|
||||
<el-button @click="$refs.guava.index()" size="medium">取消</el-button>
|
||||
<el-button @click="modifyBasicInfo" type="primary">确定</el-button>
|
||||
@@ -710,7 +822,7 @@ layout("/layouts/platform.html"){
|
||||
|
||||
<el-row>
|
||||
<span>
|
||||
标题、提示
|
||||
标题提示:
|
||||
</span>
|
||||
|
||||
<el-button @click="openIssueName('iname')" plain size="small">
|
||||
@@ -724,7 +836,7 @@ layout("/layouts/platform.html"){
|
||||
|
||||
<el-row type="flex" style="flex-flow: row wrap;column-gap: 10px;margin:20px 0">
|
||||
<div>
|
||||
<span>题目类型</span>
|
||||
<span>题目类型:</span>
|
||||
<el-select
|
||||
@change="if(currentModifyIssue.itx==2){issueData[currentModifyIssueIndex].iplfs=1;issueData[currentModifyIssueIndex].iisdx=true;issueData[currentModifyIssueIndex].wors=[{}]}else{issueData[currentModifyIssueIndex].wors=[{wtxt:'选项1'},{wtxt:'选项2'}]}"
|
||||
placeholder="题型" size="small"
|
||||
@@ -787,8 +899,9 @@ layout("/layouts/platform.html"){
|
||||
</div>
|
||||
</el-row>
|
||||
|
||||
<el-row class="mb20">
|
||||
<span>显示日期</span>
|
||||
<!--定时定题模式下才需要设置显示日期-->
|
||||
<el-row class="mb20" v-if="questionData.ctMode==1">
|
||||
<span>显示日期:</span>
|
||||
<el-date-picker placeholder="请选择显示日期"
|
||||
size="small"
|
||||
type="date"
|
||||
@@ -798,16 +911,6 @@ layout("/layouts/platform.html"){
|
||||
</el-date-picker>
|
||||
</el-row>
|
||||
|
||||
<el-row class="mb20">
|
||||
<span>排序编号</span>
|
||||
<el-input
|
||||
v-if="questionData.ctMode==1"
|
||||
v-model="issueData[currentModifyIssueIndex].ipxbh"
|
||||
place="请输入排序编号"
|
||||
style="width: 80px"
|
||||
size="small"></el-input>
|
||||
</el-row>
|
||||
|
||||
<template v-if="issueData[currentModifyIssueIndex].itx===1">
|
||||
<vi-title2 title="选项设置"></vi-title2>
|
||||
<el-row v-if="currentModifyIssue.itx==1">
|
||||
@@ -950,7 +1053,6 @@ layout("/layouts/platform.html"){
|
||||
|
||||
</div>
|
||||
<script>
|
||||
let qsmEditor
|
||||
let upTxtEditor
|
||||
let cakeEditor
|
||||
let vue = new Vue({
|
||||
@@ -975,7 +1077,7 @@ layout("/layouts/platform.html"){
|
||||
year: new Date().getFullYear() + ''
|
||||
},
|
||||
viewData: {issue: [{word: []}]},
|
||||
formData: {issues: [{wors: [{}]}]},
|
||||
formData: {issues: [{wors: [{}]}], raffleRule: []},
|
||||
setTitleDialogVisible: false,
|
||||
formRules: {
|
||||
qtitle: [{required: true, message: '请填写标题', trigger: ['blur', 'change']}],
|
||||
@@ -1209,14 +1311,7 @@ layout("/layouts/platform.html"){
|
||||
this.$refs.guava.edit()
|
||||
this.editMode = 'basicInfo'
|
||||
setTimeout(() => {
|
||||
$('#qsmEditor').html("")
|
||||
qsmEditor = new wangEditor('#qsmEditor')
|
||||
qsmEditor.config.uploadImgShowBase64 = true
|
||||
qsmEditor.config.onchange = (html) => {
|
||||
this.$set(this.formData, "qsm", html)
|
||||
}
|
||||
qsmEditor.create()
|
||||
this.formData = {issues: [], qlx: 2, qrkdcs: 0}
|
||||
this.formData = {issues: [], qlx: 2, qrkdcs: 0, raffleRule: []}
|
||||
}, 300)
|
||||
|
||||
},
|
||||
@@ -1226,12 +1321,9 @@ layout("/layouts/platform.html"){
|
||||
const {code, data, msg} = await $.get(loc() + "/findBasicInfo", {qid: qid})
|
||||
if (code === 0) {
|
||||
setTimeout(() => {
|
||||
$('#qsmEditor').html(data.qsm)
|
||||
qsmEditor = new wangEditor('#qsmEditor')
|
||||
qsmEditor.config.onchange = (html) => {
|
||||
this.$set(this.formData, "qsm", html)
|
||||
if (data.raffleRule == null) {
|
||||
data.raffleRule = []
|
||||
}
|
||||
qsmEditor.create()
|
||||
this.formData = data
|
||||
if (!this.isNull(this.formData.qdtkssj) && !this.isNull(this.formData.qdtjssj)) {
|
||||
this.$set(this.formData, 'qdtsj', [this.formData.qdtkssj, this.formData.qdtjssj])
|
||||
@@ -1244,6 +1336,7 @@ layout("/layouts/platform.html"){
|
||||
}
|
||||
},
|
||||
async modifyBasicInfo() {
|
||||
|
||||
if (this.formData.qlx === 4) {
|
||||
if (this.formData.autoSelect && this.formData.endTime < new Date().getTime()) {
|
||||
this.$message.warning('结束时间必须要大于当前时间')
|
||||
@@ -1251,22 +1344,25 @@ layout("/layouts/platform.html"){
|
||||
}
|
||||
}
|
||||
|
||||
//答题 并且是 定时定题
|
||||
// if (this.formData.qlx === 2 && this.formData.ctMode === 1) {
|
||||
// if (this.formData.issues.some(v => v.displayDate != null) && this.formData.issues.some(v => v.displayDate == null)) {
|
||||
// this.$message.warning('显示日期只能全为空或者全不为空')
|
||||
this.$refs['addForm'].validate(async valid => {
|
||||
if (valid) {
|
||||
// if (this.formData.isRaffle && moment(this.formData.raffleTime).isBefore(moment(this.formData.endTime))) {
|
||||
// this.$message.warning('抽奖时间必须要大于活动结束时间')
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
const {code, msg} = await $.post(loc() + '/modifyBasicInfo', this.formData)
|
||||
const {code, msg} = await $.post(loc() + '/modifyBasicInfo', {
|
||||
question: JSON.stringify(this.formData)
|
||||
})
|
||||
if (code === 0) {
|
||||
this.notifySuccess(msg)
|
||||
this.$message.success(msg)
|
||||
this.$refs.guava.index()
|
||||
this.pageData()
|
||||
} else {
|
||||
this.notifyWarning(msg)
|
||||
this.$message.warning(msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//打开题目设置
|
||||
@@ -1295,14 +1391,23 @@ layout("/layouts/platform.html"){
|
||||
|
||||
//修改题目
|
||||
async doModifyIssues() {
|
||||
//答题 并且是 定时定题
|
||||
if (this.questionData.qlx === 2 && this.questionData.ctMode === 1) {
|
||||
if (this.issueData.some(v => v.displayDate != null) && this.issueData.some(v => v.displayDate == null)) {
|
||||
this.notifyWarning('显示日期只能全为空或者全不为空')
|
||||
//答题
|
||||
if (this.questionData.qlx === 2) {
|
||||
if (this.issueData.some(v => v.fraction == null || v.fraction === '')) {
|
||||
this.$message.warning('每题都需要设置分数')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//定时定题需要设置时间
|
||||
if (this.questionData.ctMode === 1) {
|
||||
if (this.issueData.some(v => v.displayDate == null || v.displayDate === '')) {
|
||||
this.$message.warning('每题都需要设置显示日期')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const confirm = await this.$confirm('您确定要提交吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
|
||||
@@ -40,7 +40,8 @@ layout("/layouts/platform.html"){
|
||||
<div class="search-item">
|
||||
<div class="search-item-label">工号姓名:</div>
|
||||
<div class="search-item-option">
|
||||
<el-input placeholder="输入关键字" v-model="pageForm.searchKeyword" maxlength="10"></el-input>
|
||||
<el-input placeholder="输入关键字" v-model="pageForm.searchKeyword"
|
||||
maxlength="10"></el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -113,6 +114,7 @@ layout("/layouts/platform.html"){
|
||||
<el-table-column
|
||||
:label="column.label"
|
||||
:prop="column.prop"
|
||||
:key="column.key"
|
||||
:sortable="column.sortable"
|
||||
align="center"
|
||||
header-align="center"
|
||||
@@ -122,6 +124,10 @@ layout("/layouts/platform.html"){
|
||||
<span @click="showDays(row)" style="color: #236eb4; cursor: pointer">{{ row.dayCount ? row.dayCount : 0 }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="每轮得分" prop="everyRandomScore"
|
||||
v-if="questionCtMode==2 && isSameDay"></el-table-column>
|
||||
|
||||
</el-table>
|
||||
|
||||
<!--# include("/layouts/pagination.html"){}#-->
|
||||
@@ -167,8 +173,8 @@ layout("/layouts/platform.html"){
|
||||
{prop: 'unionname', label: '工会'},
|
||||
{prop: 'mobile', label: '联系方式'},
|
||||
// {prop: 'answerTotal', label: '答题次数(第几回答题)', sortable: true},
|
||||
{prop: 'max_score', label: '得分'},
|
||||
{prop: 'answerDate', label: '答题日期'},
|
||||
{prop: 'score', label: '得分'},
|
||||
],
|
||||
pageForm: {
|
||||
unionId: '',
|
||||
@@ -179,8 +185,29 @@ layout("/layouts/platform.html"){
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
'guava': httpVueLoader('/components/plugins/Guava.vue')
|
||||
computed: {
|
||||
//判断是否为同一天
|
||||
isSameDay() {
|
||||
if (this.pageForm.questionId) {
|
||||
const currentQuestion = this.questions.find(v => v.qid === this.pageForm.questionId)
|
||||
if (currentQuestion) {
|
||||
const {startTime, endTime} = currentQuestion
|
||||
return moment(startTime).isSame(moment(endTime), 'day')
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
},
|
||||
questionCtMode(){
|
||||
if (this.pageForm.questionId) {
|
||||
const currentQuestion = this.questions.find(v => v.qid === this.pageForm.questionId)
|
||||
if (currentQuestion) {
|
||||
return currentQuestion.ctMode
|
||||
}
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showDays(row) {
|
||||
@@ -209,7 +236,7 @@ layout("/layouts/platform.html"){
|
||||
this.doSearch()
|
||||
},
|
||||
async getQuestion() {
|
||||
const {data} = await $.get(loc()+"/getQuestion", {year: this.pageForm.year})
|
||||
const {data} = await $.get(loc() + "/getQuestion", {year: this.pageForm.year})
|
||||
return data
|
||||
},
|
||||
async flushUnits() {
|
||||
|
||||
@@ -148,7 +148,7 @@ layout("/layouts/platform.html"){
|
||||
{prop: 'unionname', label: '工会'},
|
||||
{prop: 'mobile', label: '联系方式'},
|
||||
{prop: 'winDate', label: '中奖日期'},
|
||||
{prop: 'maxScore', label: '抽奖分数(最高分)'},
|
||||
{prop: 'score', label: '抽奖分数'},
|
||||
],
|
||||
pageForm: {
|
||||
unionId: '',
|
||||
|
||||
Reference in New Issue
Block a user