Commit 4b812ef1 by tangyi

优化

parent 29716af8
Version v3.4.0 (2019-10-27)
--------------------------
改进:
* 修复若干bug
Version v3.4.0 (2019-9-14)
--------------------------
改进:
......
package com.github.tangyi.common.core.utils;
import lombok.extern.slf4j.Slf4j;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -13,6 +15,7 @@ import java.util.Date;
* @author tangyi
* @date 2019/4/28 16:03
*/
@Slf4j
public class DateUtils {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
......@@ -78,4 +81,54 @@ public class DateUtils {
public static LocalDateTime asLocalDateTime(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
/**
* 两个时间之差
*
* @param startDate startDate
* @param endDate endDate
* @return 分钟
*/
public static Integer getBetweenMinutes(Date startDate, Date endDate) {
int minutes = 0;
try {
if (startDate != null && endDate != null) {
long ss;
if (startDate.before(endDate)) {
ss = endDate.getTime() - startDate.getTime();
} else {
ss = startDate.getTime() - endDate.getTime();
}
minutes = (int) (ss / (60 * 1000));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return minutes;
}
/**
* 两个时间只差
*
* @param startDate startDate
* @param endDate endDate
* @return 秒数
*/
public static Integer getBetweenSecond(Date startDate, Date endDate) {
int seconds = 0;
try {
if (startDate != null && endDate != null) {
long ss;
if (startDate.before(endDate)) {
ss = endDate.getTime() - startDate.getTime();
} else {
ss = startDate.getTime() - endDate.getTime();
}
seconds = (int) (ss / (1000));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return seconds;
}
}
......@@ -32,23 +32,21 @@ services:
networks:
- net
# ---------------------------
# example
# ---------------------------
spring-microservice-exam-web-Spencer:
image: registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-web:latest
volumes:
# 挂载nginx的配置文件
- ./nginx.conf:/etc/nginx/nginx.conf
container_name: web-service-example
environment:
- TENANT_CODE=example
- GATEWAY_SERVICE_HOST=gateway-service
restart: always
ports:
- "88:80"
networks:
- net
# # ---------------------------
# # example
# # ---------------------------
# spring-microservice-exam-web-Spencer:
# image: registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/exam-web-example:latest
# volumes:
# # 挂载nginx的配置文件
# - ./nginx.conf:/etc/nginx/nginx.conf
# container_name: web-service-example
# env_file: docker-compose.env # 从文件中获取配置
# restart: always
# ports:
# - "88:80"
# networks:
# - net
networks:
net:
......
......@@ -17,6 +17,7 @@ MSC_SERVICE=$BASE_IMAGE_NAME/msc-service:$BSEE_IMAGE_TAG
MONITOR_SERVICE=$BASE_IMAGE_NAME/monitor-service:$BSEE_IMAGE_TAG
UI_SERVICE=$BASE_IMAGE_NAME/spring-microservice-exam-ui:$BSEE_IMAGE_TAG
WEB_SERVICE=$BASE_IMAGE_NAME/spring-microservice-exam-web:$BSEE_IMAGE_TAG
WEB_SERVICE_EXAMPLE=$BASE_IMAGE_NAME/exam-web-example:$BSEE_IMAGE_TAG
case "$1" in
......
......@@ -58,12 +58,19 @@ export function delAllSubject (obj) {
}
// 导出
export function exportSubject (obj) {
export function exportSubject (ids, examinationId, categoryId) {
let url = baseSubjectUrl + 'export?'
if (examinationId !== null && examinationId !== '') {
url = url + 'examinationId=' + examinationId
}
if (categoryId !== null && categoryId !== '') {
url = url + '&categoryId=' + categoryId
}
return request({
url: baseSubjectUrl + 'export',
url: url,
method: 'post',
responseType: 'arraybuffer',
headers: { 'filename': 'utf-8' },
data: obj
data: ids
})
}
......@@ -210,7 +210,7 @@ export default {
score: '成绩',
examTime: '考试时间',
submitStatus: '状态',
details: '成绩详情',
details: '详情',
marking: '批改'
},
knowledge: {
......
......@@ -29,7 +29,7 @@
</div>
<div class="card-panel-description">
<div class="card-panel-text">参加人数</div>
<count-to :start-val="0" :end-val="9280" :duration="2400" class="card-panel-num"/>
<count-to :start-val="0" :end-val="examUserNumber" :duration="2400" class="card-panel-num"/>
</div>
</div>
</el-col>
......@@ -59,7 +59,8 @@ export default {
data () {
return {
onlineUserNumber: 0,
examinationNumber: 0
examinationNumber: 0,
examUserNumber: 0
}
},
created () {
......@@ -80,6 +81,9 @@ export default {
if (isNotEmpty(data.examinationNumber)) {
this.examinationNumber = parseInt(data.examinationNumber)
}
if (isNotEmpty(data.examUserNumber)) {
this.examUserNumber = parseInt(data.examUserNumber)
}
}
}).catch(error => {
console.error(error)
......
......@@ -188,7 +188,7 @@
</el-dialog>
<!--题目管理列表-->
<el-dialog :visible.sync="dialogSubjectVisible" :title="$t('table.subjectManagement')" width="80%" top="10vh">
<el-dialog :visible.sync="dialogSubjectVisible" :title="$t('table.subjectManagement')" width="80%" top="5vh">
<div class="filter-container">
<el-input :placeholder="$t('table.subjectName')" v-model="subject.listQuery.subjectName" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilterSubject"/>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilterSubject">{{ $t('table.search') }}</el-button>
......@@ -1080,7 +1080,7 @@ export default {
cancelButtonText: '取消',
type: 'success'
}).then(() => {
exportSubject({ idString: '', examinationId: this.subject.examinationId }).then(response => {
exportSubject([], this.subject.examinationId).then(response => {
// 导出Excel
exportExcel(response)
})
......@@ -1096,7 +1096,7 @@ export default {
for (let i = 0; i < this.multipleSubjectSelection.length; i++) {
ids.push(this.multipleSubjectSelection[i].id)
}
exportSubject({ ids: ids, examinationId: '' }).then(response => {
exportSubject(ids, '').then(response => {
// 导出Excel
exportExcel(response)
})
......
......@@ -81,7 +81,7 @@
</el-dialog>
<!-- 批改 -->
<el-dialog :visible.sync="dialogMarkingVisible" :title="$t('table.examRecord.marking')" width="80%" top="10vh">
<el-dialog :visible.sync="dialogMarkingVisible" :title="$t('table.examRecord.marking')" width="80%" top="5vh">
<el-row :gutter="20">
<el-col :span="20" class="subject-box-card" v-loading="markLoading">
<el-form ref="dataAnswerForm" :model="tempAnswer" :label-position="labelPosition" label-width="100px">
......@@ -104,7 +104,7 @@
</el-col>
<el-col :span="6">
<el-form-item label="耗时:">
<span>{{tempAnswer | consumingFilter }}</span>
<span>{{ tempAnswer.duration }}</span>
</el-form-item>
</el-col>
</el-row>
......@@ -222,9 +222,6 @@ export default {
},
timeFilter (time) {
return formatDate(new Date(time), 'yyyy-MM-dd hh:mm')
},
consumingFilter(answer) {
return (answer.endTime - answer.startTime) / 1000 + 'ms'
}
},
data () {
......@@ -361,17 +358,17 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
exportObj({ idString: '' }).then(response => {
exportObj([]).then(response => {
// 导出Excel
exportExcel(response)
})
}).catch(() => {})
} else {
let ids = ''
let ids = []
for (let i = 0; i < this.multipleSelection.length; i++) {
ids += this.multipleSelection[i].id + ','
ids.push(this.multipleSelection[i].id)
}
exportObj({ idString: ids }).then(response => {
exportObj(ids).then(response => {
// 导出Excel
exportExcel(response)
})
......@@ -470,6 +467,12 @@ export default {
})
} else {
this.tempAnswer = response.data.data
// 题号
if (nextType === 1) {
this.currentIndex--
} else if (nextType === 0) {
this.currentIndex++
}
}
setTimeout(() => {
this.markLoading = false
......
......@@ -714,7 +714,7 @@ export default {
cancelButtonText: '取消',
type: 'success'
}).then(() => {
exportSubject({ idString: '', categoryId: this.currentCategoryId, type: this.listQuery.type }).then(response => {
exportSubject([], '', this.currentCategoryId).then(response => {
// 导出Excel
exportExcel(response)
})
......@@ -722,6 +722,7 @@ export default {
})
} else {
debugger
// 导出选中
this.$confirm('是否导出选中的题目?', '提示', {
confirmButtonText: '确定',
......@@ -729,10 +730,10 @@ export default {
type: 'success'
}).then(() => {
let ids = []
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id)
for (let i = 0; i < this.multipleSubjectSelection.length; i++) {
ids.push(this.multipleSubjectSelection[i].id)
}
exportSubject({ ids: ids, categoryId: '' }).then(response => {
exportSubject(ids, '', '').then(response => {
// 导出Excel
exportExcel(response)
})
......
......@@ -369,14 +369,14 @@ export default {
handleExportMenu () {
// 获取选中节点
const keys = this.$refs.menuTree.getCheckedKeys(true).concat(this.$refs.menuTree.getHalfCheckedKeys())
let menus = ''
let ids = []
if (keys.length === 0) {
this.$confirm('是否导出所有菜单?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'success'
}).then(() => {
exportObj({ idString: menus }).then(response => {
exportObj(ids).then(response => {
// 导出Excel
exportExcel(response)
})
......@@ -388,9 +388,9 @@ export default {
type: 'success'
}).then(() => {
for (let i = 0; i < keys.length; i++) {
menus = menus + keys[i] + ','
ids.push(keys[i])
}
exportObj({ idString: menus }).then(response => {
exportObj(ids).then(response => {
// 导出Excel
exportExcel(response)
})
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.github.tangyi.exam.api.constants;
/**
* @author tangyi
* @date 2019/5/3 14:41
*/
public class ExamExaminationRecordConstant {
/**
* 未提交
*/
public static final Integer STATUS_NOT_SUBMITTED = 0;
/**
* 已提交
*/
public static final Integer STATUS_SUBMITTED = 1;
/**
* 正在统计
*/
public static final Integer STATUS_CALCULATE = 2;
/**
* 统计完成
*/
public static final Integer STATUS_CALCULATED = 3;
}
......@@ -78,4 +78,9 @@ public class AnswerDto implements Serializable {
* 结束时间
*/
private Date endTime;
/**
* 耗时
*/
private String duration;
}
......@@ -134,4 +134,6 @@ public class ExaminationRecordDto extends BaseEntity<ExaminationRecordDto> {
* 提交状态 1-已提交 0-未提交
*/
private Integer submitStatus;
private String submitStatusName;
}
package com.github.tangyi.exam.api.enums;
/**
* @author tangyi
* @date 2019/10/22 21:44
*/
public enum SubmitStatusEnum {
NOT_SUBMITTED("未提交", 0),
SUBMITTED("已提交", 1),
CALCULATE("正在统计", 2),
CALCULATED("统计完成", 3);
private String name;
private Integer value;
SubmitStatusEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public static SubmitStatusEnum match(Integer value, SubmitStatusEnum defaultValue) {
if (value != null) {
for (SubmitStatusEnum item : SubmitStatusEnum.values()) {
if (item.value.equals(value)) {
return item;
}
}
}
return defaultValue;
}
}
......@@ -27,4 +27,12 @@ public interface ExaminationServiceClient {
*/
@GetMapping("/v1/examination/examinationCount")
ResponseBean<Integer> findExaminationCount(@RequestParam("tenantCode") String tenantCode);
/**
* 查询参与人数
* @param tenantCode tenantCode
* @return ResponseBean
*/
@GetMapping("/v1/examination/examUserCount")
ResponseBean<Integer> findExamUserCount(@RequestParam("tenantCode") String tenantCode);
}
......@@ -24,6 +24,12 @@ public class ExaminationServiceClientFallbackImpl implements ExaminationServiceC
return new ResponseBean<>(0);
}
@Override
public ResponseBean<Integer> findExamUserCount(String tenantCode) {
log.error("调用{}异常, {}, {}", "findExamUserCount", tenantCode, throwable);
return null;
}
public Throwable getThrowable() {
return throwable;
}
......
......@@ -80,7 +80,7 @@ public class CourseController extends BaseController {
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Course course) {
course.setTeacher(SysUtil.getTenantCode());
course.setTenantCode(SysUtil.getTenantCode());
return courseService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), course);
}
......
......@@ -11,6 +11,7 @@ import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.exam.api.dto.ExaminationRecordDto;
import com.github.tangyi.exam.api.dto.StartExamDto;
import com.github.tangyi.exam.api.enums.SubmitStatusEnum;
import com.github.tangyi.exam.api.module.Examination;
import com.github.tangyi.exam.api.module.ExaminationRecord;
import com.github.tangyi.exam.service.AnswerService;
......@@ -279,12 +280,14 @@ public class ExamRecordController extends BaseController {
ExaminationRecordDto recordDto = new ExaminationRecordDto();
recordDto.setId(tempExamRecord.getId());
recordDto.setExaminationName(examRecordExamination.getExaminationName());
//recordDto.setExamTime(tempExamRecord.getCreateDate());
recordDto.setStartTime(tempExamRecord.getStartTime());
recordDto.setEndTime(tempExamRecord.getEndTime());
recordDto.setDuration(ExamRecordUtil.getExamDuration(tempExamRecord.getStartTime(), tempExamRecord.getEndTime()));
recordDto.setScore(tempExamRecord.getScore());
recordDto.setUserId(tempExamRecord.getUserId());
recordDto.setCorrectNumber(tempExamRecord.getCorrectNumber());
recordDto.setInCorrectNumber(tempExamRecord.getInCorrectNumber());
recordDto.setSubmitStatus(tempExamRecord.getSubmitStatus());
recordDto.setSubmitStatusName(SubmitStatusEnum.match(tempExamRecord.getSubmitStatus(), SubmitStatusEnum.NOT_SUBMITTED).getName());
userIdSet.add(tempExamRecord.getUserId());
examRecordDtoList.add(recordDto);
}
......
......@@ -269,4 +269,19 @@ public class ExaminationController extends BaseController {
examination.setId(examinationId);
return new ResponseBean<>(examinationService.findListByExaminationId(examination));
}
/**
* 查询参与考试人数
*
* @param tenantCode tenantCode
* @return ResponseBean
* @author tangyi
* @date 2019/10/27 20:07:38
*/
@GetMapping("examUserCount")
public ResponseBean<Integer> findExamUserCount(@RequestParam @NotBlank String tenantCode) {
Examination examination = new Examination();
examination.setCommonValue(SysUtil.getUser(), SysUtil.getSysCode(), tenantCode);
return new ResponseBean<>(examinationService.findExamUserCount(examination));
}
}
......@@ -17,7 +17,6 @@ import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -27,11 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 题目controller
......@@ -171,14 +166,12 @@ public class SubjectController extends BaseController {
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "题目ID", required = true, dataType = "Long"),
@ApiImplicitParam(name = "examinationId", value = "考试ID", dataType = "Long"),
@ApiImplicitParam(name = "categoryId", value = "分类ID", dataType = "Long"),
@ApiImplicitParam(name = "type", value = "题目类型", required = true, dataType = "Integer", example = "3")
@ApiImplicitParam(name = "categoryId", value = "分类ID", dataType = "Long")
})
@Log("导出题目")
public void exportSubject(@RequestBody Long[] ids,
@RequestParam Long examinationId,
@RequestParam Long categoryId,
@RequestParam Integer type,
@RequestParam(required = false) Long examinationId,
@RequestParam(required = false) Long categoryId,
HttpServletRequest request,
HttpServletResponse response) {
try {
......@@ -187,26 +180,7 @@ public class SubjectController extends BaseController {
response.setContentType("multipart/form-data");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, Servlets.getDownName(request,
"题目信息" + DateUtils.localDateMillisToString(LocalDateTime.now()) + ".xlsx"));
List<SubjectDto> subjects = new ArrayList<>();
// 根据题目id导出
if (ArrayUtils.isNotEmpty(ids)) {
subjects = Stream.of(ids)
// 根据ID查找题目信息
.map(subjectService::get)
// 过滤收集
.filter(Objects::nonNull).collect(Collectors.toList());
} else if (examinationId != null) {
// 根据考试ID
SubjectDto subjectDto = new SubjectDto();
subjectDto.setExaminationId(examinationId);
subjects = subjectService.findList(subjectDto);
} else if (categoryId != null || type != null) {
// 根据分类ID、类型导出
SubjectDto subjectDto = new SubjectDto();
subjectDto.setCategoryId(categoryId);
subjectDto.setType(type);
subjects = subjectService.findListByType(subjectDto);
}
List<SubjectDto> subjects = subjectService.export(ids, examinationId, categoryId);
ExcelToolUtil.exportExcel(request.getInputStream(), response.getOutputStream(), MapUtil.java2Map(subjects),
SubjectUtil.getSubjectMap());
} catch (Exception e) {
......
......@@ -22,4 +22,14 @@ public interface ExaminationMapper extends CrudMapper<Examination> {
* @date 2019/3/1 15:32
*/
int findExaminationCount(Examination examination);
/**
* 查询参与考试人数
*
* @param examination examination
* @return int
* @author tangyi
* @date 2019/10/27 20:08:58
*/
int findExamUserCount(Examination examination);
}
......@@ -74,4 +74,14 @@ public interface ExaminationSubjectMapper extends CrudMapper<ExaminationSubject>
* @date 2019/10/07 20:40:16
*/
ExaminationSubject getPreviousByCurrentId(ExaminationSubject examinationSubject);
/**
* 根据分类id查询
*
* @param examinationSubject examinationSubject
* @return List
* @author tangyi
* @date 2019/10/24 21:47:24
*/
List<ExaminationSubject> findListByCategoryId(ExaminationSubject examinationSubject);
}
......@@ -2,7 +2,7 @@ package com.github.tangyi.exam.mq;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.common.security.tenant.TenantContextHolder;
import com.github.tangyi.exam.api.constants.ExamExaminationRecordConstant;
import com.github.tangyi.exam.api.enums.SubmitStatusEnum;
import com.github.tangyi.exam.api.module.Answer;
import com.github.tangyi.exam.api.module.ExaminationRecord;
import com.github.tangyi.exam.service.AnswerService;
......@@ -47,12 +47,12 @@ public class RabbitSubmitExaminationReceiver {
examRecord = examRecordService.get(examRecord);
if (examRecord == null)
return;
if (ExamExaminationRecordConstant.STATUS_NOT_SUBMITTED.equals(examRecord.getSubmitStatus()))
if (SubmitStatusEnum.NOT_SUBMITTED.getValue().equals(examRecord.getSubmitStatus()))
log.warn("考试:{}未提交", examRecord.getId());
if (ExamExaminationRecordConstant.STATUS_CALCULATE.equals(examRecord.getSubmitStatus()))
if (SubmitStatusEnum.CALCULATE.getValue().equals(examRecord.getSubmitStatus()))
log.warn("考试:{}正在统计成绩,请勿重复提交", examRecord.getId());
// 更新状态为正在统计
examRecord.setSubmitStatus(ExamExaminationRecordConstant.STATUS_CALCULATE);
examRecord.setSubmitStatus(SubmitStatusEnum.CALCULATE.getValue());
// 更新成功
if (examRecordService.update(examRecord) > 0) {
log.debug("考试:{}更新状态为正在统计成功", examRecord.getId());
......
......@@ -8,16 +8,17 @@ import com.github.tangyi.common.core.service.CrudService;
import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.exam.api.constants.AnswerConstant;
import com.github.tangyi.exam.api.constants.ExamExaminationRecordConstant;
import com.github.tangyi.exam.api.dto.AnswerDto;
import com.github.tangyi.exam.api.dto.StartExamDto;
import com.github.tangyi.exam.api.dto.SubjectDto;
import com.github.tangyi.exam.api.enums.SubmitStatusEnum;
import com.github.tangyi.exam.api.module.Answer;
import com.github.tangyi.exam.api.module.Examination;
import com.github.tangyi.exam.api.module.ExaminationRecord;
import com.github.tangyi.exam.api.module.ExaminationSubject;
import com.github.tangyi.exam.enums.SubjectTypeEnum;
import com.github.tangyi.exam.mapper.AnswerMapper;
import com.github.tangyi.exam.utils.ExamRecordUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
......@@ -204,7 +205,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
}
// 如果全部为选择题,则更新状态为统计完成,否则需要阅卷完成后才更改统计状态
if (!distinctAnswer.containsKey(SubjectTypeEnum.SHORT_ANSWER.name()))
record.setSubmitStatus(ExamExaminationRecordConstant.STATUS_CALCULATED);
record.setSubmitStatus(SubmitStatusEnum.CALCULATED.getValue());
// 保存成绩
record.setCommonValue(currentUsername, SysUtil.getSysCode());
record.setId(answer.getExamRecordId());
......@@ -240,7 +241,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
examRecord.setId(answer.getExamRecordId());
// 提交时间
examRecord.setEndTime(examRecord.getCreateDate());
examRecord.setSubmitStatus(ExamExaminationRecordConstant.STATUS_SUBMITTED);
examRecord.setSubmitStatus(SubmitStatusEnum.SUBMITTED.getValue());
// 1. 发送消息
amqpTemplate.convertAndSend(MqConstant.SUBMIT_EXAMINATION_QUEUE, answer);
// 2. 更新考试状态
......@@ -276,7 +277,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
examRecord.setCommonValue(currentUsername, applicationCode, tenantCode);
examRecord.setStartTime(examRecord.getCreateDate());
// 默认未提交状态
examRecord.setSubmitStatus(ExamExaminationRecordConstant.STATUS_NOT_SUBMITTED);
examRecord.setSubmitStatus(SubmitStatusEnum.NOT_SUBMITTED.getValue());
// 保存考试记录
if (examRecordService.insert(examRecord) > 0) {
startExamDto.setExamination(examination);
......@@ -482,6 +483,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
answer.setExamRecordId(recordId);
Answer userAnswer = this.getAnswer(answer);
BeanUtils.copyProperties(userAnswer, answerDto);
answerDto.setDuration(ExamRecordUtil.getExamDuration(userAnswer.getStartTime(), userAnswer.getEndTime()));
return answerDto;
}
......@@ -507,7 +509,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
// 总分
Integer score = answers.stream().mapToInt(Answer::getScore).sum();
examRecord.setScore(score);
examRecord.setSubmitStatus(ExamExaminationRecordConstant.STATUS_CALCULATED);
examRecord.setSubmitStatus(SubmitStatusEnum.CALCULATED.getValue());
examRecord.setCorrectNumber((int) correctNumber);
examRecord.setInCorrectNumber(answers.size() - examRecord.getCorrectNumber());
examRecordService.update(examRecord);
......
......@@ -115,6 +115,18 @@ public class ExaminationService extends CrudService<ExaminationMapper, Examinati
}
/**
* 查询参与考试人数
*
* @param examination examination
* @return int
* @author tangyi
* @date 2019/10/27 20:07:38
*/
public int findExamUserCount(Examination examination) {
return this.dao.findExamUserCount(examination);
}
/**
* 根据考试ID获取题目分页数据
*
* @param subjectDto subjectDto
......
......@@ -97,4 +97,16 @@ public class ExaminationSubjectService extends CrudService<ExaminationSubjectMap
public ExaminationSubject getPreviousByCurrentId(ExaminationSubject examinationSubject) {
return this.dao.getPreviousByCurrentId(examinationSubject);
}
/**
* 根据分类id查询
*
* @param examinationSubject examinationSubject
* @return List
* @author tangyi
* @date 2019/10/24 21:47:24
*/
public List<ExaminationSubject> findListByCategoryId(ExaminationSubject examinationSubject) {
return this.dao.findListByCategoryId(examinationSubject);
}
}
......@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 题目service
......@@ -447,4 +448,37 @@ public class SubjectService {
// 根据题目ID,类型获取题目的详细信息
return this.get(examinationSubject.getSubjectId(), examinationSubject.getType());
}
/**
* 导出
*
* @param ids ids
* @param examinationId examinationId
* @param categoryId categoryId
* @return List
*/
public List<SubjectDto> export(Long[] ids, Long examinationId, Long categoryId) {
List<SubjectDto> subjects = new ArrayList<>();
ExaminationSubject examinationSubject = new ExaminationSubject();
List<ExaminationSubject> examinationSubjects = new ArrayList<>();
// 根据题目id导出
if (ArrayUtils.isNotEmpty(ids)) {
for (Long id : ids) {
examinationSubject.setSubjectId(id);
examinationSubjects.addAll(examinationSubjectService.findListBySubjectId(examinationSubject));
}
} else if (examinationId != null) {
// 根据考试ID
examinationSubjects = examinationSubjectService.findListByExaminationId(examinationId);
} else if (categoryId != null) {
// 根据分类ID、类型导出
examinationSubject.setCategoryId(categoryId);
examinationSubjects = examinationSubjectService.findListByCategoryId(examinationSubject);
}
if (CollectionUtils.isNotEmpty(examinationSubjects)) {
for (ExaminationSubject es : examinationSubjects)
subjects.add(this.get(es.getSubjectId(), es.getType()));
}
return subjects;
}
}
package com.github.tangyi.exam.utils;
import com.github.tangyi.common.core.utils.DateUtils;
import java.util.Date;
import java.util.LinkedHashMap;
/**
......@@ -23,11 +26,30 @@ public class ExamRecordUtil {
map.put("examinationName", "考试名称");
map.put("userName", "考生名称");
map.put("deptName", "部门名称");
map.put("submitStatusName", "批改状态");
map.put("startTime", "开始时间");
map.put("endTime", "结束时间");
map.put("duration", "持续时间");
map.put("score", "成绩");
map.put("correctNumber", "正确题数");
map.put("inCorrectNumber", "错误题数");
map.put("submitStatus", "批改状态");
map.put("score", "成绩");
map.put("examTime", "考试时间");
return map;
}
/**
* 计算持续时间
* @param startTime startTime
* @param endTime endTime
* @return String
*/
public static String getExamDuration(Date startTime, Date endTime) {
// 持续时间
String suffix = "分钟";
Integer duration = DateUtils.getBetweenMinutes(startTime, endTime);
if (duration <= 0) {
duration = DateUtils.getBetweenSecond(startTime, endTime);
suffix = "秒";
}
return duration + suffix;
}
}
......@@ -78,7 +78,7 @@
<select id="findListById" resultMap="examRecordResultMap">
SELECT
<include refid="examRecordColumns"/>
FROM exam_record a
FROM exam_examination_record a
WHERE a.id IN
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
......
......@@ -89,6 +89,10 @@
<include refid="whereColumnList"/>
</select>
<select id="findExamUserCount" resultType="java.lang.Integer">
SELECT COUNT(*) FROM (SELECT * FROM exam_examination_record WHERE tenant_code = #{tenantCode} GROUP BY user_id) a
</select>
<insert id="insert">
insert into exam_examination (
id,
......
......@@ -97,6 +97,12 @@
WHERE a.subject_id <![CDATA[<]]> #{subjectId} AND a.examination_id = #{examinationId} ORDER BY subject_id DESC LIMIT 1
</select>
<select id="findListByCategoryId" resultMap="examinationSubjectResultMap">
SELECT
<include refid="examinationSubjectColumns"/>
FROM exam_examination_subject a WHERE a.category_id = #{categoryId}
</select>
<insert id="insert">
insert into exam_examination_subject (
id,
......
......@@ -24,4 +24,9 @@ public class DashboardDto implements Serializable {
* 考试数量
*/
private String examinationNumber;
/**
* 参与人数
*/
private String examUserNumber;
}
......@@ -53,6 +53,11 @@ public class DashboardController extends BaseController {
if (!ResponseUtil.isSuccess(examinationCountResponseBean))
throw new ServiceException("查询考试数量失败: " + examinationCountResponseBean.getMsg());
dashboardDto.setExaminationNumber(examinationCountResponseBean.getData().toString());
// 查询参与人数
ResponseBean<Integer> examUserCountResponseBean = examinationService.findExamUserCount(tenantCode);
if (!ResponseUtil.isSuccess(examUserCountResponseBean))
throw new ServiceException("查询参与人数失败: " + examUserCountResponseBean.getMsg());
dashboardDto.setExamUserNumber(examUserCountResponseBean.getData().toString());
return new ResponseBean<>(dashboardDto);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment