This commit is contained in:
xzb 2022-10-10 10:26:13 +08:00
parent ceadaccb3b
commit 575c58c739
6 changed files with 134 additions and 29 deletions

View File

@ -103,6 +103,19 @@ public class PaperApiTestController {
rt.setAccount("18710717058");
System.out.println(JsonUtils.writeValueAsString(rt));
}
public static void findPaperUserForClassReqVo(){
FindPaperUserForClassReqVo rt = new FindPaperUserForClassReqVo();
rt.setClassId(56L);
rt.setPcId(1L);
System.out.println(JsonUtils.writeValueAsString(rt));
}
public static void findPaperUserForAccountReqVo(){
FindPaperUserForAccountReqVo rt = new FindPaperUserForAccountReqVo();
rt.setPcId(1L);
rt.setOrgId(56L);
rt.setAccount("18710717058");
System.out.println(JsonUtils.writeValueAsString(rt));
}
public static void main(String[]args){
createPaperCompositionReqVo();
paperCompositionBasicVo();
@ -113,5 +126,7 @@ public class PaperApiTestController {
paperSubmitAnswerReqVo();
findPaperUserForCompositionReqVo();
findPaperCompositionByAccountReqVo();
findPaperUserForClassReqVo();
findPaperUserForAccountReqVo();
}
}

View File

@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 用户试卷
*/
@ -42,7 +44,7 @@ public class PaperUserController {
*/
@GetMapping("/user/{puId}")
public PaperUserWholeVo findPaperUser(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) {
return this.paperUserService.findPaperUser(puId, user);
return this.paperUserService.findPaperUser(puId);
}
/**
* 删除用户试卷
@ -50,7 +52,7 @@ public class PaperUserController {
*/
@DeleteMapping("/user/{puId}")
public void deletePaperUser(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user){
this.paperUserService.deletePaperUser(puId,user);
this.paperUserService.deletePaperUser(puId);
}
/**
* 开始答题
@ -59,7 +61,7 @@ public class PaperUserController {
*/
@PostMapping("/user/{puId}/start")
public void paperStart(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) {
this.paperUserService.paperStart(puId, user);
this.paperUserService.paperStart(puId);
}
/**
@ -69,7 +71,7 @@ public class PaperUserController {
*/
@PostMapping("/user/{puId}/submit")
public PaperSubmitRspVo paperSubmit(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) {
return this.paperUserService.paperSubmit(puId, user);
return this.paperUserService.paperSubmit(puId);
}
/**
@ -100,14 +102,20 @@ public class PaperUserController {
*/
@PostMapping("/user/page/composition")
public PageVO<PaperUserInfoVo>findPaperUserByPage(@RequestBody FindPaperUserForCompositionReqVo req, @RequestAttribute AccountVO user){
return this.paperUserFindPageService.findPaperUserByPage(req,user);
return this.paperUserFindPageService.findPaperUserByPage(req);
}
/**
* 教师查看某个班级的某个试卷蓝图的所有用户试卷
* 查看某个班级的某个试卷蓝图的所有学生试卷
*/
@PostMapping("/user/page/class")
public PageVO<PaperUserInfoVo>findPaperUserByPageForClass(@RequestBody FindPaperUserForClassReqVo req, @RequestAttribute AccountVO user){
return this.paperUserFindPageService.findPaperUserByPageForClass(req);
}
/**
* 查看某个账户的某个试卷蓝图的用户试卷
*/
@PostMapping("/user/list/account")
public List<PaperUserInfoVo> findPaperUserForAccount(@RequestBody FindPaperUserForAccountReqVo req, @RequestAttribute AccountVO user){
return this.paperUserFindPageService.findPaperUserForAccount(req);
}
}

View File

@ -2,16 +2,19 @@ package club.joylink.rtss.services.paper;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.OrgUserDAO;
import club.joylink.rtss.dao.SysAccountDAO;
import club.joylink.rtss.dao.paper.PaperCompositionDAO;
import club.joylink.rtss.dao.paper.PaperUserDAO;
import club.joylink.rtss.entity.OrgUser;
import club.joylink.rtss.entity.OrgUserExample;
import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.SysAccountExample;
import club.joylink.rtss.entity.paper.PaperComposition;
import club.joylink.rtss.entity.paper.PaperUser;
import club.joylink.rtss.entity.paper.PaperUserExample;
import club.joylink.rtss.exception.PaperExceptionAssert;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.paper.FindPaperUserForAccountReqVo;
import club.joylink.rtss.vo.paper.FindPaperUserForClassReqVo;
import club.joylink.rtss.vo.paper.FindPaperUserForCompositionReqVo;
import club.joylink.rtss.vo.paper.PaperUserInfoVo;
@ -23,6 +26,7 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户试卷分页查询业务实现
@ -35,7 +39,28 @@ public class PaperUserFindPageService {
private PaperUserDAO paperUserDAO;
@Autowired
private OrgUserDAO orgUserDAO;
@Autowired
private SysAccountDAO sysAccountDAO;
/**
* 教师查看某个学生的某个试卷蓝图的用户试卷
*/
@Transactional(readOnly = true)
public List<PaperUserInfoVo> findPaperUserForAccount(FindPaperUserForAccountReqVo req){
PaperComposition pc = paperCompositionDAO.selectByPrimaryKey(req.getPcId());
PaperExceptionAssert.PcExisted.assertNotNull(pc,"试卷定义不存在");
//
List<OrgUser> orgUserList = this.findAllOrgUsers(req.getOrgId(),req.getAccount());
if(!CollectionUtils.isEmpty(orgUserList)){
PaperUserExample paperUserExample = new PaperUserExample();
List<Long>userIds = orgUserList.stream().map(u->{return u.getUserId();}).collect(Collectors.toList());
paperUserExample.createCriteria().andPcIdEqualTo(pc.getId()).andUserIdIn(userIds);
List<PaperUser> paperUserList = this.paperUserDAO.selectByExample(paperUserExample);
if(!CollectionUtils.isEmpty(paperUserList)){
return paperUserList.stream().map(pu->{return PaperUserConvertor.convert(pc,pu);}).collect(Collectors.toList());
}
}
return new ArrayList<>();
}
/**
* 教师根据班级查询某个试卷蓝图的所有用户试卷基本信息
*/
@ -48,7 +73,9 @@ public class PaperUserFindPageService {
PaperUserExample example = new PaperUserExample();
PaperUserExample.Criteria c = example.createCriteria();
c.andPcIdEqualTo(req.getPcId());
c.andUserIdIn(findAllClassStudents(req.getClassId()));
List<Long> students= findAllClassStudents(req.getClassId());
PaperExceptionAssert.PdValid.assertTrue(!CollectionUtils.isEmpty(students),String.format("班级[%s]内没有学生",req.getClassId()));
c.andUserIdIn(students);
switch (req.getFindType()){
case Pass:c.andScoreIsNotNull().andScoreGreaterThanOrEqualTo(pc.getPassScore());break;
case NotPass:c.andScoreIsNotNull().andScoreLessThan(pc.getPassScore());break;
@ -74,13 +101,7 @@ public class PaperUserFindPageService {
List<PaperUser> pContent = this.paperUserDAO.selectByExample(example);
if (null != pContent) {
pContent.forEach(t -> {
PaperUserInfoVo pi = new PaperUserInfoVo();
pi.setPcId(pc.getId());
pi.setName(pc.getName());
pi.setProfile(pc.getProfile());
pi.setOrgId(pc.getOrgId());
pi.setPaper(PaperUserConvertor.convert(t));
page.getList().add(pi);
page.getList().add(PaperUserConvertor.convert(pc,t));
});
}
}
@ -92,7 +113,7 @@ public class PaperUserFindPageService {
* 分页查询某个试卷蓝图的所有用户试卷基本信息
*/
@Transactional(readOnly = true)
public PageVO<PaperUserInfoVo> findPaperUserByPage(FindPaperUserForCompositionReqVo req, AccountVO user) {
public PageVO<PaperUserInfoVo> findPaperUserByPage(FindPaperUserForCompositionReqVo req) {
PageVO<PaperUserInfoVo> page = new PageVO<>();
//
PaperComposition pc = paperCompositionDAO.selectByPrimaryKey(req.getPcId());
@ -124,13 +145,7 @@ public class PaperUserFindPageService {
List<PaperUser> pContent = this.paperUserDAO.selectByExample(example);
if (null != pContent) {
pContent.forEach(t -> {
PaperUserInfoVo pi = new PaperUserInfoVo();
pi.setPcId(pc.getId());
pi.setName(pc.getName());
pi.setProfile(pc.getProfile());
pi.setOrgId(pc.getOrgId());
pi.setPaper(PaperUserConvertor.convert(t));
page.getList().add(pi);
page.getList().add(PaperUserConvertor.convert(pc,t));
});
}
}
@ -153,4 +168,30 @@ public class PaperUserFindPageService {
}
return rt;
}
/**
* 根据组织id和账户信息查询
*/
private List<OrgUser>findAllOrgUsers(Long orgId,String account){
SysAccountExample accountExample = new SysAccountExample();
SysAccountExample.Criteria accountC = accountExample.or();
accountC.andAccountEqualTo(account);
//
SysAccountExample.Criteria mobileC = accountExample.or();
mobileC.andMobileEqualTo(account);
//
SysAccountExample.Criteria emailC = accountExample.or();
emailC.andEmailEqualTo(account);
//
List<SysAccount> accounts = sysAccountDAO.selectByExample(accountExample);
if(!CollectionUtils.isEmpty(accounts)){
OrgUserExample orgUserExample = new OrgUserExample();
orgUserExample.createCriteria().andOrgIdEqualTo(orgId).andUserIdIn(accounts.stream().map(a->{return a.getId();}).collect(Collectors.toList()));
List<OrgUser>userList=orgUserDAO.selectByExample(orgUserExample);
if(!CollectionUtils.isEmpty(userList)){
return userList;
}
}
//
return new ArrayList<>();
}
}

View File

@ -55,7 +55,7 @@ public class PaperUserService {
* @param puId 用户试卷id
*/
@Transactional(readOnly = true)
public PaperUserWholeVo findPaperUser(Long puId, AccountVO user) {
public PaperUserWholeVo findPaperUser(Long puId) {
PaperUser paper = paperUserDAO.selectByPrimaryKey(puId);
PaperExceptionAssert.PuExisted.assertNotNull(paper, "用户试卷不存在");
//
@ -78,7 +78,7 @@ public class PaperUserService {
* @param puId 用户试卷id
*/
@Transactional(rollbackFor = Exception.class)
public void deletePaperUser(Long puId, AccountVO user) {
public void deletePaperUser(Long puId) {
//删除试卷试题关联表
PaperUserQuestionExample puqExample = new PaperUserQuestionExample();
puqExample.createCriteria().andPuIdEqualTo(puId);
@ -93,7 +93,7 @@ public class PaperUserService {
* @param puId 用户试卷id
*/
@Transactional(rollbackFor = Exception.class)
public void paperStart(Long puId, AccountVO user) {
public void paperStart(Long puId) {
PaperUser paper = paperUserDAO.selectByPrimaryKey(puId);
PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在puId = " + puId);
PaperExceptionAssert.PuNotStart.assertNull(paper.getStartTime(), "用户已经开始答题");
@ -109,7 +109,7 @@ public class PaperUserService {
* @param puId 用户试卷id
*/
@Transactional(rollbackFor = Exception.class)
public PaperSubmitRspVo paperSubmit(Long puId, AccountVO user) {
public PaperSubmitRspVo paperSubmit(Long puId) {
PaperUser paper = paperUserDAO.selectByPrimaryKey(puId);
PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在puId = " + puId);
PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题");

View File

@ -0,0 +1,30 @@
package club.joylink.rtss.vo.paper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 查询某个账户的用户试卷
*/
@Data
public class FindPaperUserForAccountReqVo {
/**
* 试卷蓝图id
*/
@JsonSerialize(using = ToStringSerializer.class)
@NotNull
private Long pcId;
/**
* 组织id
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long orgId;
/**
* 账户信息账号电话号码或邮箱地址
*/
@NotNull
private String account;
}

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.vo.paper.convertor;
import club.joylink.rtss.entity.paper.PaperComposition;
import club.joylink.rtss.entity.paper.PaperUser;
import club.joylink.rtss.vo.paper.PaperUserInfoVo;
import club.joylink.rtss.vo.paper.PaperUserVo;
public class PaperUserConvertor {
@ -18,4 +20,13 @@ public class PaperUserConvertor {
to.setCreateTime(from.getCreateTime());
return to;
}
public static PaperUserInfoVo convert(PaperComposition pc,PaperUser t){
PaperUserInfoVo pi = new PaperUserInfoVo();
pi.setPcId(pc.getId());
pi.setName(pc.getName());
pi.setProfile(pc.getProfile());
pi.setOrgId(pc.getOrgId());
pi.setPaper(PaperUserConvertor.convert(t));
return pi;
}
}