This commit is contained in:
daihh
2022-11-15 09:40:00 +08:00
8 changed files with 263 additions and 2 deletions

View File

@@ -1,8 +1,83 @@
package com.xboe.module.exam.api;
import com.xboe.common.PageList;
import com.xboe.common.Pagination;
import com.xboe.common.utils.StringUtil;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
import com.xboe.module.exam.entity.AloneExam;
import com.xboe.module.exam.entity.AloneExamAnswer;
import com.xboe.module.exam.service.IAloneExamService;
import com.xboe.module.exam.vo.AloneExamQuery;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 对于与第三方对接的扩展接口
*/
public class AloneExamExtendApi {
@RestController
@RequestMapping(value = "/xboe/m/exam/alone-extend")
public class AloneExamExtendApi extends ApiBaseController {
@Resource
IAloneExamService aloneExamService;
/**
* 添加考试任务,针对单个用户
* */
@PostMapping("/save")
public JsonResponse<AloneExam> save(@RequestBody AloneExam aloneExam){
if(StringUtil.isNotBlank(aloneExam.getAid())){
return badRequest("缺少用户参数");
}
if(StringUtil.isNotBlank(aloneExam.getTestId())){
return badRequest("缺少考试信息");
}
if(StringUtil.isNotBlank(aloneExam.getRefId())){
return badRequest("缺少关联信息");
}
if(StringUtil.isNotBlank(aloneExam.getRefType())){
return badRequest("缺少关联类型");
}
try {
aloneExamService.save(aloneExam);
return success(aloneExam);
} catch (Exception e) {
return error("保存考试任务失败",e.getMessage());
}
}
/**
* 根据考试id,refType,refId查询考试任务
* */
@PostMapping("/pagelist")
public JsonResponse<PageList<AloneExam>> pagelist(Pagination pager, AloneExamQuery aloneExamQuery){
try {
PageList<AloneExam> page = aloneExamService.findPage(pager.getPageIndex(), pager.getPageSize(), aloneExamQuery);
return success(page);
} catch (Exception e) {
return error("查询考试任务失败",e.getMessage());
}
}
/**
* 根据考试idrefType,refId 用户id 查询用户答卷信息
* */
@PostMapping("/anser-page")
public JsonResponse<PageList<AloneExamAnswer>> answerpage(Pagination pager,AloneExamQuery aloneExamQuery){
try {
PageList<AloneExamAnswer> pageList = aloneExamService.answerPage(pager.getPageIndex(), pager.getPageSize(), aloneExamQuery);
return success(pageList);
} catch (Exception e) {
return error("查询用户答卷失败",e.getMessage());
}
}
}

View File

@@ -156,4 +156,21 @@ public class AloneExam extends IdBaseEntity {
this.endTime=endTime;
}
public AloneExam(String id,String aid,String testId,String testName,Integer testDuration,Integer times,Float score,Integer status,LocalDateTime taskTime,LocalDateTime startTime,LocalDateTime endTime,String refId,String refType) {
this.setId(id);
this.setAid(aid);
this.testId=testId;
this.testName=testName;
this.testDuration=testDuration;
this.times=times;
this.score=score;
this.status=status;
this.taskTime=taskTime;
this.startTime=startTime;
this.endTime=endTime;
this.refId=refId;
this.refType=refType;
}
}

View File

@@ -6,6 +6,7 @@ import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.module.exam.entity.AloneExam;
import com.xboe.module.exam.entity.AloneExamAnswer;
import com.xboe.module.exam.vo.AloneExamQuery;
/**
* 独立考试的处理。此信息无删除操作更新也只是更新answerJson字段
@@ -21,7 +22,35 @@ public interface IAloneExamService {
* @return
*/
PageList<AloneExam> findPage(int pageIndex,int pageSize,AloneExam aea,OrderCondition oc);
/**
* 用于第三方对接
* 查询个人的考试任务 根据考试idrefId,refType 查询
* @param pageIndex
* @param pageSize
* @param testId
* @param refId
* @param refType
* @return
*/
PageList<AloneExam> findPage(int pageIndex, int pageSize, AloneExamQuery examQuery);
/**
* 用于第三方对接
* 查询用户的答卷
* @param pageIndex
* @param pageSize
* @param testId
* @param refId
* @param refType
* @param aid
* */
PageList<AloneExamAnswer> answerPage(int pageIndex,int pageSize,AloneExamQuery aloneExamQuery);
/**
* 获取独立考试的信息,检查是否有独立考试
* @param aid
@@ -98,5 +127,10 @@ public interface IAloneExamService {
List<AloneExamAnswer> findList(String testId);
/**
* 保存考试任务
* */
void save(AloneExam aloneExam);
}

View File

@@ -5,6 +5,8 @@ import java.util.List;
import javax.annotation.Resource;
import com.xboe.common.utils.StringUtil;
import com.xboe.module.exam.vo.AloneExamQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -153,6 +155,11 @@ public class AloneExamServiceImpl implements IAloneExamService{
return list;
}
@Override
public void save(AloneExam aloneExam) {
aeDao.save(aloneExam);
}
@Override
public AloneExamAnswer get(String id) {
return dao.get(id);
@@ -213,6 +220,78 @@ public class AloneExamServiceImpl implements IAloneExamService{
return aeDao.findPage(query.builder());
}
@Override
public PageList<AloneExam> findPage(int pageIndex, int pageSize, AloneExamQuery examQuery) {
QueryBuilder builder = QueryBuilder.from(AloneExam.class.getSimpleName()+" a,"+ExamTest.class.getSimpleName()+" t");
builder.addField("new AloneExam(a.id,a.aid,a.testId,a.testName,a.testDuration,a.times,a.score,a.status,a.taskTime,t.entranceTime,t.deadlineTime,a.refId,a.refType)");
builder.setPageIndex(pageIndex);
builder.setPageSize(pageSize);
builder.addFilter(FieldFilters.eqField("a.testId","t.id"));
if(examQuery!=null){
OrderCondition order=null;
if(StringUtils.isNotBlank(examQuery.getOrderField())) {
if(examQuery.getOrderAsc()==null|| examQuery.getOrderAsc()) {
order=OrderCondition.asc(examQuery.getOrderField());
}else {
order=OrderCondition.desc(examQuery.getOrderField());
}
}else {
order=OrderCondition.desc("a.sysCreateTime");
}
if(StringUtil.isNotBlank(examQuery.getTestId())){
builder.addFilter(FieldFilters.eq("a.testId",examQuery.getTestId()));
}
if(StringUtil.isNotBlank(examQuery.getRefId())){
builder.addFilter(FieldFilters.eq("a.refId",examQuery.getRefId()));
}
if(StringUtil.isNotBlank(examQuery.getRefType())){
builder.addFilter(FieldFilters.eq("a.refType",examQuery.getRefType()));
}
}
PageList<AloneExam> page = aeDao.findPage(builder.builder());
return page;
}
@Override
public PageList<AloneExamAnswer> answerPage(int pageIndex, int pageSize, AloneExamQuery aloneExamQuery) {
QueryBuilder builder=QueryBuilder.from(AloneExam.class.getSimpleName()+" a,"+AloneExamAnswer.class.getSimpleName()+" aa");
builder.addField("new AloneExamAnswer(aa.id,aa.aid,aa.name,aa.testId,aa.testName,aa.arrange,aa.passLine,aa.status,aa.startTime,aa.endTime,aa.lastTime,aa.clientIp,aa.ucode,aa.score,aa.totalScore,aa.realScore,aa.useSecond)");
builder.setPageIndex(pageIndex);
builder.setPageSize(pageSize);
builder.addFilter(FieldFilters.eqField("a.id","aa.aloneId"));
if(aloneExamQuery!=null){
OrderCondition order=null;
if(StringUtil.isNotBlank(aloneExamQuery.getOrderField())){
if(aloneExamQuery.getOrderAsc()==null || aloneExamQuery.getOrderAsc()){
order=OrderCondition.asc(aloneExamQuery.getOrderField());
}else{
order=OrderCondition.desc(aloneExamQuery.getOrderField());
}
}else {
order=OrderCondition.desc("aa.sysCreateTime");
}
if(StringUtil.isNotBlank(aloneExamQuery.getTestId())){
builder.addFilter(FieldFilters.eq("a.testId",aloneExamQuery.getTestId()));
}
if(StringUtil.isNotBlank(aloneExamQuery.getRefId())){
builder.addFilter(FieldFilters.eq("a.refId",aloneExamQuery.getRefId()));
}
if(StringUtil.isNotBlank(aloneExamQuery.getRefType())){
builder.addFilter(FieldFilters.eq("a.refType",aloneExamQuery.getRefType()));
}
if(StringUtil.isNotBlank(aloneExamQuery.getAid())){
builder.addFilter(FieldFilters.eq("a.aid",aloneExamQuery.getAid()));
}
}
PageList<AloneExamAnswer> page = dao.findPage(builder.builder());
return page;
}
@Override
public AloneExam getAloneByAidAndTestId(String aid, String testId) {
AloneExam ae=aeDao.findOne(FieldFilters.eq("aid", aid),FieldFilters.eq("testId", testId));

View File

@@ -0,0 +1,19 @@
package com.xboe.module.exam.vo;
import lombok.Data;
@Data
public class AloneExamQuery {
private String testId;
private String refId;
private String refType;
private String orderField;
private Boolean orderAsc;
private String aid;
}

View File

@@ -116,6 +116,18 @@ public class Comments extends IdBaseEntity {
@Column(name = "favorites")
private Integer favorites;
/**
* 页面类型
* */
@Column(name = "page_type",length = 1)
private Integer pageType;
/**
*页面参数 默认是id
* */
@Column(name = "page_params",length = 50)
private String pageParams;
// /**
// * 最后回答时间

View File

@@ -39,6 +39,18 @@ public class Favorites extends IdBaseEntity {
@MetaInfo("标题")
@Column(name = "title", nullable = false,length=100)
private String title;
/**
* 页面类型
* */
@Column(name = "page_type",length = 1)
private Integer pageType;
/**
*页面参数 默认是id
* */
@Column(name = "page_params",length = 50)
private String pageParams;
/**
* 用于显示内容信息

View File

@@ -36,6 +36,19 @@ public class Shares extends IdBaseEntity {
private String objId;
/**
* 页面类型
* */
@Column(name = "page_type",length = 1)
private Integer pageType;
/**
*页面参数 默认是id
* */
@Column(name = "page_params",length = 50)
private String pageParams;
/**
* 分享内容