大赛管理功能

This commit is contained in:
tiger_zhou 2024-03-07 16:47:41 +08:00
parent 164c26a01e
commit c0ed50ccdc
5 changed files with 833 additions and 756 deletions

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.controller.racetr;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.paper.PagerQuestionService;
import club.joylink.rtss.services.race.RacePaperService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
@ -12,6 +13,7 @@ import club.joylink.rtss.vo.race.RacePaper.RacePaperModuleVO;
import club.joylink.rtss.vo.race.RacePaper.RacePaperVO;
import club.joylink.rtss.vo.race.RacePaperQueryVO;
import club.joylink.rtss.vo.race.RaceTask.RacePaperSingleModuleGroupTask;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -33,6 +35,15 @@ public class RacePaperController {
@Autowired
private RacePaperService racePaperService;
@Autowired
private PagerQuestionService questionService;
@GetMapping("/questions")
public List<Long> queryQuestionFromPBank() {
return this.questionService.queryAllDefaultOrgPaperIds();
}
/**
* 创建试卷
*/

View File

@ -14,8 +14,9 @@ import java.util.List;
@Mapper
@Repository
public interface PaperQuestionDAO {
@Select("<script>" +
"select * from rts_paper_question where 1 = 1 " +
@Select("<script>" +
"select * from rts_paper_question where 1 = 1 " +
// "<choose>" +
// "<when test=\"projectCode == '"+ Project.DEFAULT_PROJECT_CODE +"'\">"+
// " and project_code is null" +
@ -24,48 +25,54 @@ public interface PaperQuestionDAO {
// " and project_code = #{projectCode} "+
// " </otherwise>" +
// "</choose>" +
" and org_id = #{companyId,jdbcType=BIGINT} " +
" and org_id = #{companyId,jdbcType=BIGINT} " +
// "<if test=\"companyIdList != null and companyIdList.size > 0\">"+
// "<foreach collection=\"companyIdList\" open=\" and company_id in (\" close=\")\" item=\"d\" separator=\",\">"+
// " #{d} "+
// "</foreach></if>"+
" and is_del= #{isDelete,jdbcType=INTEGER} " +
"<if test=\"types != null and types.size > 0\">"+
"<foreach collection=\"types\" open=\" and type in (\" close=\")\" item=\"d\" separator=\",\">"+
" #{d} "+
"</foreach></if>"+
"<if test=\"lable != null and lable.size > 0\"> " +
" <foreach collection=\"lable\" open=\" and (\" close=\")\" item=\"d\" separator=\" or \"> "+
" find_in_set(#{d},race_lable) > 0 "+
" </foreach>" +
"</if>" +
"</script>")
List<PaperQuestionWithBLOBs> findFromAndRaceLable(Long companyId,int isDelete, List<String> lable, List<String> types);
long countByExample(PaperQuestionExample example);
" and is_del= #{isDelete,jdbcType=INTEGER} " +
"<if test=\"types != null and types.size > 0\">" +
"<foreach collection=\"types\" open=\" and type in (\" close=\")\" item=\"d\" separator=\",\">" +
" #{d} " +
"</foreach></if>" +
"<if test=\"lable != null and lable.size > 0\"> " +
" <foreach collection=\"lable\" open=\" and (\" close=\")\" item=\"d\" separator=\" or \"> " +
" find_in_set(#{d},race_lable) > 0 " +
" </foreach>" +
"</if>" +
"</script>")
List<PaperQuestionWithBLOBs> findFromAndRaceLable(Long companyId, int isDelete, List<String> lable, List<String> types);
int deleteByExample(PaperQuestionExample example);
@Select("<script>" +
"select id from rts_paper_question where org_id = #{orgId} "
+ "</script>")
List<Long> findAllId(@Param("orgId") Long id);
int deleteByPrimaryKey(Long id);
long countByExample(PaperQuestionExample example);
int insert(PaperQuestionWithBLOBs record);
int deleteByExample(PaperQuestionExample example);
int insertSelective(PaperQuestionWithBLOBs record);
int deleteByPrimaryKey(Long id);
List<PaperQuestionWithBLOBs> selectByExampleWithBLOBs(PaperQuestionExample example);
int insert(PaperQuestionWithBLOBs record);
List<PaperQuestion> selectByExample(PaperQuestionExample example);
int insertSelective(PaperQuestionWithBLOBs record);
PaperQuestionWithBLOBs selectByPrimaryKey(Long id);
List<PaperQuestionWithBLOBs> selectByExampleWithBLOBs(PaperQuestionExample example);
int updateByExampleSelective(@Param("record") PaperQuestionWithBLOBs record, @Param("example") PaperQuestionExample example);
List<PaperQuestion> selectByExample(PaperQuestionExample example);
int updateByExampleWithBLOBs(@Param("record") PaperQuestionWithBLOBs record, @Param("example") PaperQuestionExample example);
PaperQuestionWithBLOBs selectByPrimaryKey(Long id);
int updateByExample(@Param("record") PaperQuestion record, @Param("example") PaperQuestionExample example);
int updateByExampleSelective(@Param("record") PaperQuestionWithBLOBs record, @Param("example") PaperQuestionExample example);
int updateByPrimaryKeySelective(PaperQuestionWithBLOBs record);
int updateByExampleWithBLOBs(@Param("record") PaperQuestionWithBLOBs record, @Param("example") PaperQuestionExample example);
int updateByPrimaryKeyWithBLOBs(PaperQuestionWithBLOBs record);
int updateByExample(@Param("record") PaperQuestion record, @Param("example") PaperQuestionExample example);
int updateByPrimaryKey(PaperQuestion record);
int updateByPrimaryKeySelective(PaperQuestionWithBLOBs record);
int updateByPrimaryKeyWithBLOBs(PaperQuestionWithBLOBs record);
int updateByPrimaryKey(PaperQuestion record);
}

View File

@ -15,91 +15,98 @@ import java.util.Collection;
import java.util.List;
public interface IOrgService {
OrgVO createTopOrg(TopOrgCreateVO topOrgCreateVO, AccountVO user);
List<OrgVO> queryAllTopOrg();
/**
* 查找默认组织
*
* @return
*/
Org findDefaultOrg();
PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO);
OrgVO createTopOrg(TopOrgCreateVO topOrgCreateVO, AccountVO user);
void confirmExist(Long orgId);
List<OrgVO> queryAllTopOrg();
OrgVO createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo);
PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO);
Org getEntity(long orgId);
void confirmExist(Long orgId);
Org findEntity(long orgId);
OrgVO createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo);
// TODO 20220922 将Project 修改为 String
Collection<Org> getEntities(String project, String status);
Org getEntity(long orgId);
// TODO 20220922 将Project 修改为 String
Collection<Org> findEntities(String project, String status);
Org findEntity(long orgId);
OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user);
// TODO 20220922 将Project 修改为 String
Collection<Org> getEntities(String project, String status);
/**
* 删除非顶级组织
*
* @param nonTopOrgId
*/
void deleteNonTopOrg(Long nonTopOrgId);
// TODO 20220922 将Project 修改为 String
Collection<Org> findEntities(String project, String status);
List<Org> findEntitiesByParentId(Long parentId, String orderBy, String status);
OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user);
/**
* 分页查询自己创建的班级
*/
PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
/**
* 删除非顶级组织
*
* @param nonTopOrgId
*/
void deleteNonTopOrg(Long nonTopOrgId);
/**
* 查询自己创建的班级
*/
List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
List<Org> findEntitiesByParentId(Long parentId, String orderBy, String status);
/**
* 获取该组织所属的顶级组织
*/
Org getTopOrgEntity(Long orgId);
/**
* 分页查询自己创建的班级
*/
PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
List<Org> findEntities(List<Long> orgIds, String status);
/**
* 查询自己创建的班级
*/
List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo);
/**
* 管理员分页查询组织
*/
Node<Object> adminQueryOrgTree(Long orgId);
/**
* 获取该组织所属的顶级组织
*/
Org getTopOrgEntity(Long orgId);
OrgVO get(Long id);
List<Org> findEntities(List<Long> orgIds, String status);
/**
* 查询这些考试关联的班级
*/
List<ExamDefinitionVO> queryByExamIds(List<Long> examIds, String status);
/**
* 管理员分页查询组织
*/
Node<Object> adminQueryOrgTree(Long orgId);
void confirmIsTopOrg(long id);
OrgVO get(Long id);
void confirmIsNonTopOrg(Long id);
/**
* 查询这些考试关联的班级
*/
List<ExamDefinitionVO> queryByExamIds(List<Long> examIds, String status);
List<Org> queryAllSubOrgs(Long orgId);
void confirmIsTopOrg(long id);
String getBindQrCode(long orgId, String project);
void confirmIsNonTopOrg(Long id);
/**
* 获取该用户所属的顶级组织
*/
Org getTopOrgOfUser(long userId);
List<Org> queryAllSubOrgs(Long orgId);
Org findTopOrgOfUser(long userId);
String getBindQrCode(long orgId, String project);
/**
* 查询该组织下的所有班级
* 目前组织结构仅有两级非顶级的就是班级
*/
List<OrgVO> listQueryCls(long topOrgId);
/**
* 获取该用户所属的顶级组织
*/
Org getTopOrgOfUser(long userId);
/**
* 查询组织信息可能返回null
*/
OrgVO query(Long id);
Org findTopOrgOfUser(long userId);
OrgVO getTopOrg(long topOrgId);
/**
* 查询该组织下的所有班级 目前组织结构仅有两级非顶级的就是班级
*/
List<OrgVO> listQueryCls(long topOrgId);
/**
* 查询组织信息可能返回null
*/
OrgVO query(Long id);
OrgVO getTopOrg(long topOrgId);
}

View File

@ -1,11 +1,13 @@
package club.joylink.rtss.services.org;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.Project;
import club.joylink.rtss.dao.OrgDAO;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.ISysUserService;
import club.joylink.rtss.services.QRCodeManager;
import club.joylink.rtss.services.cache.ICacheService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.ExamDefinitionVO;
@ -14,6 +16,8 @@ import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -28,444 +32,470 @@ import java.util.stream.Collectors;
@Service
public class OrgService implements IOrgService {
@Autowired
private OrgDAO orgDAO;
@Autowired
private IOrgUserService iOrgUserService;
@Autowired
private OrgDAO orgDAO;
@Autowired
private ISysUserService iSysUserService;
@Autowired
private IOrgUserService iOrgUserService;
@Autowired
private QRCodeManager qrCodeManager;
@Autowired
private ISysUserService iSysUserService;
@Autowired
private IOrgProjectService orgProjectService;
@Autowired
private QRCodeManager qrCodeManager;
@Transactional
@Override
public OrgVO createTopOrg(TopOrgCreateVO topOrgCreateVO, AccountVO user) {
confirmNameUnique(null, topOrgCreateVO.getName());
/* 处理 */
Org entity = topOrgCreateVO.toDB();
entity.setId(null);
entity.setCreatorId(user.getId());
entity.setCreateTime(LocalDateTime.now());
entity.setStatus(BusinessConsts.Org.Status.VALID);
this.orgDAO.insert(entity);
entity.setRootId(entity.getId());
orgDAO.updateByPrimaryKey(entity);
// 20220929 增加
orgProjectService.save(entity.getId(), topOrgCreateVO.getProjectCodes(), user);
return new OrgVO(entity, topOrgCreateVO.getProjectCodes());
@Autowired
private IOrgProjectService orgProjectService;
@Autowired
private ICacheService cacheService;
@Override
public Org findDefaultOrg() {
String defName = String.format("%s-org-default", Project.DEFAULT.name());
Object obj = this.cacheService.get(defName);
if (Objects.nonNull(obj)) {
return (Org) obj;
}
/**
* 确认名称唯一
*/
private void confirmNameUnique(Long orgId, String name) {
//名称检查
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andNameEqualTo(name);
if (orgId != null) {
criteria.andIdNotEqualTo(orgId);
}
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(orgDAO.countByExample(example) == 0,
"名称重复");
OrgExample orgExample = new OrgExample();
orgExample.createCriteria().andProjectCodeEqualTo(Project.DEFAULT.name());
List<Org> orgs = this.orgDAO.selectByExample(orgExample);
if (!CollectionUtils.isEmpty(orgs)) {
Org org = orgs.get(0);
this.cacheService.putExpired(defName, org, 600, TimeUnit.SECONDS);
return org;
}
return null;
}
@Override
public List<OrgVO> queryAllTopOrg() {
OrgExample example = new OrgExample();
example.createCriteria().andParentIdIsNull();
List<Org> orgs = this.orgDAO.selectByExample(example);
List<Long> orgIds = orgs.stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
return OrgVO.convert2VOList(orgs, orgProjects);
@Transactional
@Override
public OrgVO createTopOrg(TopOrgCreateVO topOrgCreateVO, AccountVO user) {
confirmNameUnique(null, topOrgCreateVO.getName());
/* 处理 */
Org entity = topOrgCreateVO.toDB();
entity.setId(null);
entity.setCreatorId(user.getId());
entity.setCreateTime(LocalDateTime.now());
entity.setStatus(BusinessConsts.Org.Status.VALID);
this.orgDAO.insert(entity);
entity.setRootId(entity.getId());
orgDAO.updateByPrimaryKey(entity);
// 20220929 增加
orgProjectService.save(entity.getId(), topOrgCreateVO.getProjectCodes(), user);
return new OrgVO(entity, topOrgCreateVO.getProjectCodes());
}
/**
* 确认名称唯一
*/
private void confirmNameUnique(Long orgId, String name) {
//名称检查
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andNameEqualTo(name);
if (orgId != null) {
criteria.andIdNotEqualTo(orgId);
}
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(orgDAO.countByExample(example) == 0,
"名称重复");
}
@Override
public PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria();
criteria.andParentIdIsNull().andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
Page<Org> page = (Page<Org>) orgDAO.selectByExample(example);
List<Long> orgIds = page.getResult().stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
List<OrgVO> voList = OrgVO.convert2VOList(page.getResult(), orgProjects);
return PageVO.convert(page, voList);
@Override
public List<OrgVO> queryAllTopOrg() {
OrgExample example = new OrgExample();
example.createCriteria().andParentIdIsNull();
List<Org> orgs = this.orgDAO.selectByExample(example);
List<Long> orgIds = orgs.stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
return OrgVO.convert2VOList(orgs, orgProjects);
}
@Override
public PageVO<OrgVO> pagedQueryAllTopOrg(OrgQueryVO queryVO) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria();
criteria.andParentIdIsNull().andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
Page<Org> page = (Page<Org>) orgDAO.selectByExample(example);
List<Long> orgIds = page.getResult().stream().map(Org::getId).collect(Collectors.toList());
List<OrgProject> orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds);
List<OrgVO> voList = OrgVO.convert2VOList(page.getResult(), orgProjects);
return PageVO.convert(page, voList);
}
@Override
public void confirmExist(Long orgId) {
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(orgDAO.selectByPrimaryKey(orgId),
String.format("id为[%s]的组织不存在", orgId));
@Override
public void confirmExist(Long orgId) {
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(orgDAO.selectByPrimaryKey(orgId),
String.format("id为[%s]的组织不存在", orgId));
}
@Transactional
@Override
public OrgVO createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo) {
//检查
Long topOrgId = loginInfo.getTopOrgId();
Long userId = loginInfo.getAccountVO().getId();
iOrgUserService.confirmUserIsTheRoleInThisOrg(userId, topOrgId, BusinessConsts.OrgRole.Admin);
Org cls = createNonTopOrg(createVO.getName(), topOrgId, topOrgId, userId);
iOrgUserService.create(cls.getId(), userId, BusinessConsts.OrgRole.Teacher);
return new OrgVO(cls);
}
@Override
public Org getEntity(long orgId) {
Org org = orgDAO.selectByPrimaryKey(orgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("id为[%s]的组织不存在", orgId));
return org;
}
@Override
public Org findEntity(long orgId) {
return orgDAO.selectByPrimaryKey(orgId);
}
@Override
public Collection<Org> getEntities(String project, String status) {
Collection<Org> orgs = findEntities(project, status);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(orgs, String.format("关联项目[%s]的组织不存在", project));
return orgs;
}
@Override
public Collection<Org> findEntities(@NonNull String project, String status) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andProjectCodeLike(String.format("%%%s%%", project));
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
}
@Transactional
@Override
public OrgVO createCls(NonTopOrgCreateVO createVO, LoginUserInfoVO loginInfo) {
//检查
Long topOrgId = loginInfo.getTopOrgId();
Long userId = loginInfo.getAccountVO().getId();
iOrgUserService.confirmUserIsTheRoleInThisOrg(userId, topOrgId, BusinessConsts.OrgRole.Admin);
Org cls = createNonTopOrg(createVO.getName(), topOrgId, topOrgId, userId);
iOrgUserService.create(cls.getId(), userId, BusinessConsts.OrgRole.Teacher);
return new OrgVO(cls);
}
@Override
public Org getEntity(long orgId) {
Org org = orgDAO.selectByPrimaryKey(orgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("id为[%s]的组织不存在", orgId));
return org;
}
@Override
public Org findEntity(long orgId) {
return orgDAO.selectByPrimaryKey(orgId);
}
@Override
public Collection<Org> getEntities(String project, String status) {
Collection<Org> orgs = findEntities(project, status);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(orgs, String.format("关联项目[%s]的组织不存在", project));
return orgs;
}
@Override
public Collection<Org> findEntities(@NonNull String project, String status) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andProjectCodeLike(String.format("%%%s%%", project));
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
}
@Override
public OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user) {
//校验
Org org = getEntity(id);
if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目");
@Override
public OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user) {
//校验
Org org = getEntity(id);
if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目");
// confirmProjectCodesNotRepeat(org.getId(), orgVO.getProjectCodes());
// 20220929 增加
orgProjectService.update(id, orgVO.getProjectCodes(), user);
}
confirmNameUnique(id, orgVO.getName());
//更新
org.setName(orgVO.getName());
// 20220929 增加
orgProjectService.update(id, orgVO.getProjectCodes(), user);
}
confirmNameUnique(id, orgVO.getName());
//更新
org.setName(orgVO.getName());
// org.setProjectCode(orgVO.getDBProjectCode());
org.setUpdateId(user.getId());
org.setUpdateTime(LocalDateTime.now());
this.orgDAO.updateByPrimaryKeySelective(org);
List<String> projects = orgProjectService.queryOrgProjectListByOrgId(org.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
}
org.setUpdateId(user.getId());
org.setUpdateTime(LocalDateTime.now());
this.orgDAO.updateByPrimaryKeySelective(org);
List<String> projects = orgProjectService.queryOrgProjectListByOrgId(org.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
}
@Override
public void deleteNonTopOrg(Long nonTopOrgId) {
confirmIsNonTopOrg(nonTopOrgId);
Org org = new Org();
org.setId(nonTopOrgId);
org.setStatus(BusinessConsts.Org.Status.DELETE);
orgDAO.updateByPrimaryKeySelective(org);
}
@Override
public void deleteNonTopOrg(Long nonTopOrgId) {
confirmIsNonTopOrg(nonTopOrgId);
Org org = new Org();
org.setId(nonTopOrgId);
org.setStatus(BusinessConsts.Org.Status.DELETE);
orgDAO.updateByPrimaryKeySelective(org);
}
@Override
public List<Org> findEntitiesByParentId(@NonNull Long parentId, String orderBy, String status) {
OrgExample example = new OrgExample();
if (StringUtils.hasText(orderBy)) {
example.setOrderByClause(orderBy);
}
OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(parentId);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
@Override
public List<Org> findEntitiesByParentId(@NonNull Long parentId, String orderBy, String status) {
OrgExample example = new OrgExample();
if (StringUtils.hasText(orderBy)) {
example.setOrderByClause(orderBy);
}
OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(parentId);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
}
@Override
public PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(loginInfo.getTopOrgId())
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
@Override
public PageVO<OrgVO> pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(loginInfo.getTopOrgId())
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
if (StringUtils.hasText(queryVO.getCreatorName())) {
List<Long> creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(creatorIds)) {
return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>());
} else {
criteria.andCreatorIdIn(creatorIds);
}
}
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<Org> page = (Page<Org>) orgDAO.selectByExample(example);
List<Long> creatorIds = page.stream().map(Org::getCreatorId).collect(Collectors.toList());
Map<Long, SysAccount> creatorMap = iSysUserService.findEntities(creatorIds, null).stream()
.collect(Collectors.toMap(SysAccount::getId, Function.identity()));
List<OrgVO> list = page.getResult().stream().map(entity -> {
int numberOfPeople = iOrgUserService.getQuantities(entity.getId(), BusinessConsts.OrgRole.Student);
return new OrgVO(entity, null, numberOfPeople, creatorMap.get(entity.getCreatorId()));
}).collect(Collectors.toList());
return PageVO.convert(page, list);
}
@Override
public List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria()
.andParentIdEqualTo(loginInfo.getTopOrgId())
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (queryVO != null) {
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
}
List<Org> clsList = orgDAO.selectByExample(example);
return clsList.stream().map(OrgVO::new).collect(Collectors.toList());
}
@Override
public Org getTopOrgEntity(Long orgId) {
Org entity = getEntity(orgId);
if (isTopOrg(entity)) {
return entity;
}
return getEntity(entity.getRootId());
}
@Override
public List<Org> findEntities(List<Long> orgIds, String status) {
if (CollectionUtils.isEmpty(orgIds)) {
return new ArrayList<>();
} else {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andIdIn(orgIds);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
}
}
@Override
public Node<Object> adminQueryOrgTree(Long orgId) {
/* 先筛选组织 */
OrgVO orgVO = get(orgId);
Map<Long, List<Org>> groupByParentIdOrg = findEntitiesByRootId(orgVO.getRootId(), null, BusinessConsts.Org.Status.VALID)
.stream().filter(o -> !isTopOrg(o)).collect(Collectors.groupingBy(Org::getParentId));
Node<Object> root = new Node<>(orgVO, Node.Type.ORG);
Map<Long, Node<Object>> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点
Map<Long, Node<Object>> orgId_node_map = new HashMap<>();
orgId_node_map.put(orgVO.getId(), root);
while (!orgId_node_map.isEmpty()) {
all_orgId_node_map.putAll(orgId_node_map);
Map<Long, Node<Object>> newMap = new HashMap<>();
orgId_node_map.forEach((k, v) -> {
List<Org> childOrgList = groupByParentIdOrg.get(k);
if (!CollectionUtils.isEmpty(childOrgList)) {
List<Node<Object>> children = childOrgList.stream().map(o -> {
Node<Object> node = new Node<>(new OrgVO(o), Node.Type.ORG);
newMap.put(o.getId(), node);
return node;
}).collect(Collectors.toList());
v.setChildren(children);
}
if (StringUtils.hasText(queryVO.getCreatorName())) {
List<Long> creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(creatorIds)) {
return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>());
} else {
criteria.andCreatorIdIn(creatorIds);
}
}
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<Org> page = (Page<Org>) orgDAO.selectByExample(example);
List<Long> creatorIds = page.stream().map(Org::getCreatorId).collect(Collectors.toList());
Map<Long, SysAccount> creatorMap = iSysUserService.findEntities(creatorIds, null).stream()
.collect(Collectors.toMap(SysAccount::getId, Function.identity()));
List<OrgVO> list = page.getResult().stream().map(entity -> {
int numberOfPeople = iOrgUserService.getQuantities(entity.getId(), BusinessConsts.OrgRole.Student);
return new OrgVO(entity, null, numberOfPeople, creatorMap.get(entity.getCreatorId()));
});
orgId_node_map = newMap;
}
/* 再查询用户 */
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByOrgIds(new ArrayList<>(all_orgId_node_map.keySet()), null);
Map<Long, List<OrgUser>> groupByOrgIdOrgUsers = orgUsers.stream().collect(Collectors.groupingBy(OrgUser::getOrgId));
List<Long> userIds = orgUsers.stream().map(OrgUser::getUserId).collect(Collectors.toList());
Map<Long, SysAccount> userMap = iSysUserService.findEntities(userIds, null)
.stream().collect(Collectors.toMap(SysAccount::getId, Function.identity()));
all_orgId_node_map.forEach((k, v) -> {
List<OrgUser> ous = groupByOrgIdOrgUsers.get(k);
if (!CollectionUtils.isEmpty(ous)) {
List<Node<Object>> children = ous.stream().map(ou -> {
OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId()));
return new Node<Object>(vo, Node.Type.USER);
}).collect(Collectors.toList());
return PageVO.convert(page, list);
}
@Override
public List<OrgVO> queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria()
.andParentIdEqualTo(loginInfo.getTopOrgId())
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
if (queryVO != null) {
if (StringUtils.hasText(queryVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", queryVO.getName()));
}
if (!CollectionUtils.isEmpty(v.getChildren())) {
children.addAll(v.getChildren());
}
List<Org> clsList = orgDAO.selectByExample(example);
return clsList.stream().map(OrgVO::new).collect(Collectors.toList());
}
v.setChildren(children);
}
});
return root;
}
@Override
public Org getTopOrgEntity(Long orgId) {
Org entity = getEntity(orgId);
if (isTopOrg(entity))
return entity;
return getEntity(entity.getRootId());
}
@Override
public OrgVO get(Long id) {
OrgVO vo = query(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(vo, String.format("[id:%s]的组织不存在", id));
return vo;
}
@Override
public List<Org> findEntities(List<Long> orgIds, String status) {
if (CollectionUtils.isEmpty(orgIds)) {
return new ArrayList<>();
} else {
OrgExample example = new OrgExample();
OrgExample.Criteria criteria = example.createCriteria().andIdIn(orgIds);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
return orgDAO.selectByExample(example);
}
@Override
public List<ExamDefinitionVO> queryByExamIds(List<Long> examIds, String status) {
if (CollectionUtils.isEmpty(examIds)) {
return new ArrayList<>();
}
return orgDAO.queryByExamIds(examIds, status);
}
@Override
public Node<Object> adminQueryOrgTree(Long orgId) {
/* 先筛选组织 */
OrgVO orgVO = get(orgId);
Map<Long, List<Org>> groupByParentIdOrg = findEntitiesByRootId(orgVO.getRootId(), null, BusinessConsts.Org.Status.VALID)
.stream().filter(o -> !isTopOrg(o)).collect(Collectors.groupingBy(Org::getParentId));
Node<Object> root = new Node<>(orgVO, Node.Type.ORG);
Map<Long, Node<Object>> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点
Map<Long, Node<Object>> orgId_node_map = new HashMap<>();
orgId_node_map.put(orgVO.getId(), root);
while (!orgId_node_map.isEmpty()) {
all_orgId_node_map.putAll(orgId_node_map);
Map<Long, Node<Object>> newMap = new HashMap<>();
orgId_node_map.forEach((k, v) -> {
List<Org> childOrgList = groupByParentIdOrg.get(k);
if (!CollectionUtils.isEmpty(childOrgList)) {
List<Node<Object>> children = childOrgList.stream().map(o -> {
Node<Object> node = new Node<>(new OrgVO(o), Node.Type.ORG);
newMap.put(o.getId(), node);
return node;
}).collect(Collectors.toList());
v.setChildren(children);
}
});
orgId_node_map = newMap;
}
/* 再查询用户 */
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByOrgIds(new ArrayList<>(all_orgId_node_map.keySet()), null);
Map<Long, List<OrgUser>> groupByOrgIdOrgUsers = orgUsers.stream().collect(Collectors.groupingBy(OrgUser::getOrgId));
List<Long> userIds = orgUsers.stream().map(OrgUser::getUserId).collect(Collectors.toList());
Map<Long, SysAccount> userMap = iSysUserService.findEntities(userIds, null)
.stream().collect(Collectors.toMap(SysAccount::getId, Function.identity()));
all_orgId_node_map.forEach((k, v) -> {
List<OrgUser> ous = groupByOrgIdOrgUsers.get(k);
if (!CollectionUtils.isEmpty(ous)) {
List<Node<Object>> children = ous.stream().map(ou -> {
OrgUserVO vo = new OrgUserVO(ou, userMap.get(ou.getUserId()));
return new Node<Object>(vo, Node.Type.USER);
}).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(v.getChildren())) {
children.addAll(v.getChildren());
}
v.setChildren(children);
}
});
return root;
/**
* 确认是顶级组织
*
* @param id
*/
@Override
public void confirmIsTopOrg(long id) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isTopOrg(id),
String.format("组织[%s]不是顶级组织", id));
}
/**
* 确认是非顶级组织
*/
@Override
public void confirmIsNonTopOrg(Long id) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!isTopOrg(id),
String.format("组织[%s]是顶级组织", id));
}
@Override
public List<Org> queryAllSubOrgs(Long orgId) {
OrgExample example = new OrgExample();
example.createCriteria()
.andParentIdEqualTo(orgId)
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
List<Org> orgs = this.orgDAO.selectByExample(example);
return orgs;
}
@Override
public String getBindQrCode(long orgId, String project) {
return qrCodeManager.getOrgBindCode(orgId, project);
}
@Override
public Org getTopOrgOfUser(long userId) {
Org org = findTopOrgOfUser(userId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("用户[%s]无所属顶级组织", userId));
return org;
}
@Override
public Org findTopOrgOfUser(long userId) {
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(userId, null);
if (CollectionUtils.isEmpty(orgUsers)) {
return null;
}
@Override
public OrgVO get(Long id) {
OrgVO vo = query(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(vo, String.format("[id:%s]的组织不存在", id));
return vo;
Long orgId = orgUsers.stream()
.filter(orgUser -> BusinessConsts.OrgRole.Admin.name().equals(orgUser.getRole())) //目前有管理员的一定是顶级组织
.findAny().orElse(orgUsers.get(0)).getOrgId();
Org org = getTopOrgEntity(orgId);
if (BusinessConsts.Org.Status.VALID.equals(org.getStatus())) {
return org;
} else {
return null;
}
}
@Override
public List<ExamDefinitionVO> queryByExamIds(List<Long> examIds, String status) {
if (CollectionUtils.isEmpty(examIds)) {
return new ArrayList<>();
}
return orgDAO.queryByExamIds(examIds, status);
@Override
public List<OrgVO> listQueryCls(long topOrgId) {
List<Org> clsList = findClsByTopOrgId(topOrgId);
return OrgVO.convert2VOList(clsList);
}
@Override
public OrgVO query(Long id) {
Org entity = findEntity(id);
if (entity == null) {
return null;
}
/**
* 确认是顶级组织
*
* @param id
*/
@Override
public void confirmIsTopOrg(long id) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isTopOrg(id),
String.format("组织[%s]不是顶级组织", id));
List<String> projects;
if (isTopOrg(entity)) {
projects = orgProjectService.queryOrgProjectListByOrgId(entity.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
} else {
projects = null;
}
return new OrgVO(entity, projects);
}
/**
* 确认是非顶级组织
*/
@Override
public void confirmIsNonTopOrg(Long id) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!isTopOrg(id),
String.format("组织[%s]是顶级组织", id));
@Override
public OrgVO getTopOrg(long topOrgId) {
Org org = getEntity(topOrgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isTopOrg(org),
String.format("[id:%s]的组织不是顶级组织", topOrgId));
List<String> projects = orgProjectService.queryOrgProjectListByOrgId(topOrgId)
.stream().map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
}
/**
* 查询该顶级组织下的班级
*/
private List<Org> findClsByTopOrgId(long topOrgId) {
OrgExample orgExample = new OrgExample();
orgExample.createCriteria().andRootIdEqualTo(topOrgId).andParentIdIsNull();
return orgDAO.selectByExample(orgExample);
}
/**
* 创建非顶级组织
*/
private Org createNonTopOrg(@NonNull String name, @NonNull Long parentId, @NonNull Long rootId, @NonNull Long creatorId) {
//检查顶级组织
confirmIsTopOrg(rootId);
//检查同级同名组织
List<Org> entities = findEntitiesByParentId(parentId, null, BusinessConsts.Org.Status.VALID);
if (!CollectionUtils.isEmpty(entities)) {
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(entities.stream().noneMatch(org -> org.getName().equals(name)),
String.format("上级为[%s]的同名组织已存在", parentId));
}
//创建新组织
Org org = new Org();
org.setName(name);
org.setParentId(parentId);
org.setRootId(rootId);
org.setCreatorId(creatorId);
org.setCreateTime(LocalDateTime.now());
org.setStatus(BusinessConsts.Org.Status.VALID);
orgDAO.insert(org);
return org;
}
@Override
public List<Org> queryAllSubOrgs(Long orgId) {
OrgExample example = new OrgExample();
example.createCriteria()
.andParentIdEqualTo(orgId)
.andStatusEqualTo(BusinessConsts.Org.Status.VALID);
List<Org> orgs = this.orgDAO.selectByExample(example);
return orgs;
private boolean isTopOrg(long orgId) {
return isTopOrg(getEntity(orgId));
}
private boolean isTopOrg(Org org) {
return org.getParentId() == null;
}
private List<Org> findEntitiesByRootId(Long rootId, String orderBy, String status) {
OrgExample example = new OrgExample();
if (StringUtils.hasText(orderBy)) {
example.setOrderByClause(orderBy);
}
@Override
public String getBindQrCode(long orgId, String project) {
return qrCodeManager.getOrgBindCode(orgId, project);
OrgExample.Criteria criteria = example.createCriteria().andRootIdEqualTo(rootId);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
@Override
public Org getTopOrgOfUser(long userId) {
Org org = findTopOrgOfUser(userId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(org, String.format("用户[%s]无所属顶级组织", userId));
return org;
}
@Override
public Org findTopOrgOfUser(long userId) {
List<OrgUser> orgUsers = iOrgUserService.findEntitiesByUserId(userId, null);
if (CollectionUtils.isEmpty(orgUsers))
return null;
Long orgId = orgUsers.stream()
.filter(orgUser -> BusinessConsts.OrgRole.Admin.name().equals(orgUser.getRole())) //目前有管理员的一定是顶级组织
.findAny().orElse(orgUsers.get(0)).getOrgId();
Org org = getTopOrgEntity(orgId);
if (BusinessConsts.Org.Status.VALID.equals(org.getStatus())) {
return org;
} else {
return null;
}
}
@Override
public List<OrgVO> listQueryCls(long topOrgId) {
List<Org> clsList = findClsByTopOrgId(topOrgId);
return OrgVO.convert2VOList(clsList);
}
@Override
public OrgVO query(Long id) {
Org entity = findEntity(id);
if (entity == null) {
return null;
}
List<String> projects;
if (isTopOrg(entity)) {
projects = orgProjectService.queryOrgProjectListByOrgId(entity.getId()).stream()
.map(OrgProject::getProjectCode).collect(Collectors.toList());
} else {
projects = null;
}
return new OrgVO(entity, projects);
}
@Override
public OrgVO getTopOrg(long topOrgId) {
Org org = getEntity(topOrgId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isTopOrg(org),
String.format("[id:%s]的组织不是顶级组织", topOrgId));
List<String> projects = orgProjectService.queryOrgProjectListByOrgId(topOrgId)
.stream().map(OrgProject::getProjectCode).collect(Collectors.toList());
return new OrgVO(org, projects);
}
/**
* 查询该顶级组织下的班级
*/
private List<Org> findClsByTopOrgId(long topOrgId) {
OrgExample orgExample = new OrgExample();
orgExample.createCriteria().andRootIdEqualTo(topOrgId).andParentIdIsNull();
return orgDAO.selectByExample(orgExample);
}
/**
* 创建非顶级组织
*/
private Org createNonTopOrg(@NonNull String name, @NonNull Long parentId, @NonNull Long rootId, @NonNull Long creatorId) {
//检查顶级组织
confirmIsTopOrg(rootId);
//检查同级同名组织
List<Org> entities = findEntitiesByParentId(parentId, null, BusinessConsts.Org.Status.VALID);
if (!CollectionUtils.isEmpty(entities)) {
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(entities.stream().noneMatch(org -> org.getName().equals(name)),
String.format("上级为[%s]的同名组织已存在", parentId));
}
//创建新组织
Org org = new Org();
org.setName(name);
org.setParentId(parentId);
org.setRootId(rootId);
org.setCreatorId(creatorId);
org.setCreateTime(LocalDateTime.now());
org.setStatus(BusinessConsts.Org.Status.VALID);
orgDAO.insert(org);
return org;
}
private boolean isTopOrg(long orgId) {
return isTopOrg(getEntity(orgId));
}
private boolean isTopOrg(Org org) {
return org.getParentId() == null;
}
private List<Org> findEntitiesByRootId(Long rootId, String orderBy, String status) {
OrgExample example = new OrgExample();
if (StringUtils.hasText(orderBy)) {
example.setOrderByClause(orderBy);
}
OrgExample.Criteria criteria = example.createCriteria().andRootIdEqualTo(rootId);
if (StringUtils.hasText(status)) {
criteria.andStatusEqualTo(status);
}
List<Org> orgs = orgDAO.selectByExample(example);
List<Org> orgs = orgDAO.selectByExample(example);
// BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(orgs,
// String.format("没有顶级组织id为[%s]的组织", rootId));
return orgs;
}
return orgs;
}
// /**
// * 确认这些项目没有被关联到其它的组织

View File

@ -2,10 +2,12 @@ package club.joylink.rtss.services.paper;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.paper.PaperQuestionDAO;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.paper.question.PaperQuestion;
import club.joylink.rtss.entity.paper.question.PaperQuestionExample;
import club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.org.OrgService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
@ -37,56 +39,69 @@ import java.util.stream.Collectors;
@Service
@Slf4j
public class PagerQuestionService {
@Resource
private PaperQuestionDAO questionDAO;
/**
* 创建对应的查询example
* @param queryVO 查询对象
* @param orgIdCanNull orgId是否可以为空
* @param queryLabelIsNull 当查询对象labels属性为空时 是否查询 tags is null
* @return
*/
public void createQueryExample(PaperQuestionExample.Criteria criteria,QuestionQueryVO queryVO, boolean orgIdCanNull,boolean queryLabelIsNull){
if(Objects.equals(false,orgIdCanNull)){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getOrgId()),"用户组织信息不能为空");
}
if (StringUtils.hasText(queryVO.getTopic())) {
criteria.andQuestionLike(String.format("%%%s%%", queryVO.getTopic()));
}
if (StringUtils.hasText(queryVO.getType())) {
criteria.andTypeEqualTo(queryVO.getType());
}
@Resource
private PaperQuestionDAO questionDAO;
if(Objects.nonNull(queryVO.getOrgId())){
criteria.andOrgIdEqualTo(queryVO.getOrgId());
@Resource
private OrgService orgService;
public List<Long> queryAllDefaultOrgPaperIds() {
Org org = this.orgService.findDefaultOrg();
if (Objects.isNull(org)) {
return Collections.emptyList();
}
return this.questionDAO.findAllId(org.getId());
}
/**
* 创建对应的查询example
*
* @param queryVO 查询对象
* @param orgIdCanNull orgId是否可以为空
* @param queryLabelIsNull 当查询对象labels属性为空时 是否查询 tags is null
* @return
*/
public void createQueryExample(PaperQuestionExample.Criteria criteria, QuestionQueryVO queryVO, boolean orgIdCanNull, boolean queryLabelIsNull) {
if (Objects.equals(false, orgIdCanNull)) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getOrgId()), "用户组织信息不能为空");
}
if (StringUtils.hasText(queryVO.getTopic())) {
criteria.andQuestionLike(String.format("%%%s%%", queryVO.getTopic()));
}
if (StringUtils.hasText(queryVO.getType())) {
criteria.andTypeEqualTo(queryVO.getType());
}
if (Objects.nonNull(queryVO.getOrgId())) {
criteria.andOrgIdEqualTo(queryVO.getOrgId());
}
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
if (Objects.equals(false, queryLabelIsNull) && StringUtils.hasText(queryVO.getLabels())) {
List<String> tmpLableList = Splitter.on(",").omitEmptyStrings().splitToList(queryVO.getLabels());
if (Objects.equals(false, CollectionUtils.isEmpty(tmpLableList))) {
StringBuilder sqlBuilder = new StringBuilder("(");
for (var i = 0; i < tmpLableList.size(); i++) {
String data = tmpLableList.get(i);
if (i != 0) {
sqlBuilder.append(" and ");
}
sqlBuilder.append(String.format(" find_in_set('%s',tags) > 0 ", data));
}
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
if(Objects.equals(false,queryLabelIsNull) && StringUtils.hasText(queryVO.getLabels())){
List<String> tmpLableList = Splitter.on(",").omitEmptyStrings().splitToList(queryVO.getLabels());
if(Objects.equals(false,CollectionUtils.isEmpty(tmpLableList))){
StringBuilder sqlBuilder = new StringBuilder("(");
for(var i = 0 ; i < tmpLableList.size();i++){
String data = tmpLableList.get(i);
if(i != 0){
sqlBuilder.append(" and ");
}
sqlBuilder.append(String.format(" find_in_set('%s',tags) > 0 ",data));
}
sqlBuilder.append(")");
Class<?> criteriaCls = criteria.getClass();
Class<?> generatedCriteriaCls = criteriaCls.getSuperclass();
try{
Method addCriterion = generatedCriteriaCls.getDeclaredMethod("addCriterion", String.class);
addCriterion.setAccessible(true);
addCriterion.invoke(criteria, sqlBuilder.toString());
}catch (Exception e){
log.error("拼写查询标签错误 msg:" + e.getMessage(),e);
}
}
}else {
criteria.andTagsIsNull();
sqlBuilder.append(")");
Class<?> criteriaCls = criteria.getClass();
Class<?> generatedCriteriaCls = criteriaCls.getSuperclass();
try {
Method addCriterion = generatedCriteriaCls.getDeclaredMethod("addCriterion", String.class);
addCriterion.setAccessible(true);
addCriterion.invoke(criteria, sqlBuilder.toString());
} catch (Exception e) {
log.error("拼写查询标签错误 msg:" + e.getMessage(), e);
}
}
} else {
criteria.andTagsIsNull();
}
/* if(!StringUtils.hasText(queryVO.getLabels())){
if(queryLabelIsNull) {
criteria.andTagsIsNull();
@ -115,258 +130,265 @@ public class PagerQuestionService {
}
}*/
}
/**
* 查询对应的类型标签对应的数量
*
* @param orgId 用户组织id
* @param type 类型
* @param labels 逗号隔开的标签
* @return
*/
public long queryCount(Long orgId, BusinessConsts.TheoryType type, String labels) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId), "组织信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(type == BusinessConsts.TheoryType.select
|| type == BusinessConsts.TheoryType.multi
|| type == BusinessConsts.TheoryType.judge, "查询类型只支持单选,多选,选择");
QuestionQueryVO queryVO = new QuestionQueryVO();
queryVO.setOrgId(orgId);
queryVO.setType(type.name());
queryVO.setLabels(labels);
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria, queryVO, false, false);
return this.questionDAO.countByExample(example);
}
/**
* 获取题库分页列表
*
* @param queryVO
* @param companyIdCanNull
* @return
*/
public PageVO<PaperQuestionVO> pagingQueryQuestions(QuestionQueryVO queryVO, boolean companyIdCanNull) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria, queryVO, companyIdCanNull, false);
Page<PaperQuestionWithBLOBs> page = (Page<PaperQuestionWithBLOBs>) this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(page.getResult());
return PageVO.convert(page, questionVOS);
}
/**
* 获取题型列表
*
* @param queryVO
* @param companyIdCanNull
* @return
*/
public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO, boolean companyIdCanNull) {
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria, queryVO, companyIdCanNull, false);
List<PaperQuestionWithBLOBs> list = this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS;
}
/**
* 获取题型所有数据
*
* @param questionId
* @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测false=检测
* @return
*/
public PaperQuestionVO getQuestion(Long questionId, boolean doNotCheckDel, boolean random) {
PaperQuestionWithBLOBs question = questionDAO.selectByPrimaryKey(questionId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(question), "没有找到对应的数据");
boolean isDel = question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal();
if (doNotCheckDel) {
isDel = true;
}
/**
* 查询对应的类型标签对应的数量
* @param orgId 用户组织id
* @param type 类型
* @param labels 逗号隔开的标签
* @return
*/
public long queryCount(Long orgId,BusinessConsts.TheoryType type,String labels){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId),"组织信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(type == BusinessConsts.TheoryType.select
|| type == BusinessConsts.TheoryType.multi
|| type == BusinessConsts.TheoryType.judge ,"查询类型只支持单选,多选,选择");
QuestionQueryVO queryVO = new QuestionQueryVO();
queryVO.setOrgId(orgId);
queryVO.setType(type.name());
queryVO.setLabels(labels);
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria,queryVO,false,false);
return this.questionDAO.countByExample(example);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isDel);
PaperQuestionVO questionVO = new PaperQuestionVO(question);
if (random) {
Collections.shuffle(questionVO.getOptionList());
}
return questionVO;
}
/**
* 获取题库分页列表
* @param queryVO  
* @param companyIdCanNull  
* @return
*/
public PageVO<PaperQuestionVO> pagingQueryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria,queryVO,companyIdCanNull,false);
Page<PaperQuestionWithBLOBs> page = (Page<PaperQuestionWithBLOBs>)this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(page.getResult());
return PageVO.convert(page, questionVOS);
}
/**
* 获取题型列表
* @param queryVO  
* @param companyIdCanNull  
* @return
*/
public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) {
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
this.createQueryExample(criteria,queryVO,companyIdCanNull,false);
List<PaperQuestionWithBLOBs> list = this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS;
}
/**
* 获取题型所有数据
* @param questionId  
* @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测false=检测
* @return
*/
public PaperQuestionVO getQuestion(Long questionId,boolean doNotCheckDel,boolean random) {
PaperQuestionWithBLOBs question = questionDAO.selectByPrimaryKey(questionId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(question),"没有找到对应的数据");
boolean isDel = question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal();
if(doNotCheckDel){
isDel = true;
}
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isDel);
PaperQuestionVO questionVO = new PaperQuestionVO(question);
if(random){
Collections.shuffle(questionVO.getOptionList());
}
return questionVO;
}
/**
* 检测题目是否正确
* @param questionId 题目id
* @param answerIds 检测的答案Id
* @return
*/
public boolean answer(Long questionId,List<Integer> answerIds){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
PaperQuestionVO vo = this.getQuestion(questionId,true,false);
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
/**
* 检测题目是否正确
*
* @param questionId 题目id
* @param answerIds 检测的答案Id
* @return
*/
public boolean answer(Long questionId, List<Integer> answerIds) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds), "题目答案不能为空");
PaperQuestionVO vo = this.getQuestion(questionId, true, false);
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
/* if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() == 1 ,"单选,判断题答案只能有一个!");
}else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() >= 2 ,"多选题答案最少需要2个");
}*/
Collections.sort(newAnswerList);
String answerStr = Joiner.on(",").skipNulls().join(newAnswerList);
if(Objects.equals(answerStr,vo.getAnswer())){
return true;
}
log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] ",questionId, answerStr,vo.getQuestionAnswer());
return false;
Collections.sort(newAnswerList);
String answerStr = Joiner.on(",").skipNulls().join(newAnswerList);
if (Objects.equals(answerStr, vo.getAnswer())) {
return true;
}
log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] ", questionId, answerStr, vo.getQuestionAnswer());
return false;
}
/**
* 获取所有公司组织下的标签
*
*/
public Collection<String> findAllLable(Long orgId,String type){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId),"组织id不能为空");
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
if(Objects.nonNull(type)){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.equals(type,BusinessConsts.TheoryType.select.name())
||Objects.equals(type,BusinessConsts.TheoryType.multi.name())
||Objects.equals(type,BusinessConsts.TheoryType.judge.name()),"查询类型只支持单选,多选,选择");
criteria.andTypeEqualTo(type);
}
criteria.andOrgIdEqualTo(orgId);
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
List<PaperQuestion> lableList = this.questionDAO.selectByExample(example);
if(CollectionUtils.isEmpty(lableList)){
return Collections.emptyList();
}
return lableList.stream().map(PaperQuestion::getTags).filter(StringUtils::hasText).flatMap(d-> Splitter.on(",").omitEmptyStrings()
.trimResults().splitToStream(d)).collect(Collectors.toSet());
/**
* 获取所有公司组织下的标签
*/
public Collection<String> findAllLable(Long orgId, String type) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId), "组织id不能为空");
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
if (Objects.nonNull(type)) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.equals(type, BusinessConsts.TheoryType.select.name())
|| Objects.equals(type, BusinessConsts.TheoryType.multi.name())
|| Objects.equals(type, BusinessConsts.TheoryType.judge.name()), "查询类型只支持单选,多选,选择");
criteria.andTypeEqualTo(type);
}
criteria.andOrgIdEqualTo(orgId);
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
List<PaperQuestion> lableList = this.questionDAO.selectByExample(example);
if (CollectionUtils.isEmpty(lableList)) {
return Collections.emptyList();
}
return lableList.stream().map(PaperQuestion::getTags).filter(StringUtils::hasText).flatMap(d -> Splitter.on(",").omitEmptyStrings()
.trimResults().splitToStream(d)).collect(Collectors.toSet());
}
/**
* 根据公司id和标签或类型查询
* @param companyId  
* @param queryVO  
* @return
*/
public List<PaperQuestionVO> queryQuestionsForRaceLable(Long companyId, PagerLableQueryVO queryVO) {
/**
* 根据公司id和标签或类型查询
*
* @param companyId
* @param queryVO
* @return
*/
public List<PaperQuestionVO> queryQuestionsForRaceLable(Long companyId, PagerLableQueryVO queryVO) {
/*boolean isDefault = Project.isDefault(projectCode);
List<Long> idList = null;
if(Objects.equals(false,isDefault)){
idList = this.queryFromProjectCode(projectCode);
}*/
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(companyId),"组织id不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(queryVO.allNotNullOrEmpty(),"查询内容不能为空");
int isDel = BusinessConsts.DBLogicDelete.NORMAL.ordinal();
List<PaperQuestionWithBLOBs> list = this.questionDAO.findFromAndRaceLable(companyId,isDel,queryVO.getLables(),queryVO.getTypes());
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS;
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(companyId), "组织id不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(queryVO.allNotNullOrEmpty(), "查询内容不能为空");
int isDel = BusinessConsts.DBLogicDelete.NORMAL.ordinal();
List<PaperQuestionWithBLOBs> list = this.questionDAO.findFromAndRaceLable(companyId, isDel, queryVO.getLables(), queryVO.getTypes());
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS;
}
/**
* 添加修改
*
* @param questionVO
* @param accountVO
*/
public void saveOrUpdate(PaperQuestionVO questionVO, AccountVO accountVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(questionVO.getOrgId()), "组织id不能为空");
this.checkQuestionType(questionVO, "题库目前只支持单选,多选和判断");
if (questionVO.isSelect() || questionVO.isJudge()) {
this.checkQuestionTypeForSelectAndJudge(questionVO, "单选或判断题正确答案有且只有一个!");
} else if (questionVO.isMulti()) {
this.checkQuestionTypeForMulti(questionVO, "多选题正确答案必须是2个以上");
}
if (StringUtils.hasText(questionVO.getTags())) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Splitter.on(",").splitToList(questionVO.getTags()).size() <= 1, "分类最多只能有1个");
}
PaperQuestionWithBLOBs question = questionVO.convert2DB();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(question.getQuestion().length() < 512, "问题字符长度不用超过512");
int wordCounts = questionVO.getOptionList().stream().map(d -> d.getContent().length()).reduce(0, Integer::sum);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(wordCounts < 512, "问题选项长度不用超过512");
question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now());
if (Objects.nonNull(questionVO.getId())) {
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(questionVO.getId());
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
Long exist = this.questionDAO.countByExample(example);
if (exist <= 0) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(true,
"未找到要修改的数据!");
}
questionDAO.updateByPrimaryKeyWithBLOBs(question);
} else {
questionDAO.insert(question);
}
}
/**
* 添加修改
* @param questionVO  
* @param accountVO  
*/
public void saveOrUpdate(PaperQuestionVO questionVO, AccountVO accountVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(questionVO.getOrgId()),"组织id不能为空");
this.checkQuestionType(questionVO,"题库目前只支持单选,多选和判断");
if (questionVO.isSelect() || questionVO.isJudge()) {
this.checkQuestionTypeForSelectAndJudge(questionVO,"单选或判断题正确答案有且只有一个!");
}else if(questionVO.isMulti()){
this.checkQuestionTypeForMulti(questionVO,"多选题正确答案必须是2个以上");
}
if(StringUtils.hasText(questionVO.getTags())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Splitter.on(",").splitToList(questionVO.getTags()).size() <= 1,"分类最多只能有1个");
}
PaperQuestionWithBLOBs question = questionVO.convert2DB();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(question.getQuestion().length() <512,"问题字符长度不用超过512");
int wordCounts = questionVO.getOptionList().stream().map(d->d.getContent().length()).reduce(0,Integer::sum);
private void checkQuestionType(PaperQuestionVO vo, String errStr) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue((Objects.equals(BusinessConsts.TheoryType.select.name(), vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.judge.name(), vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.multi.name(), vo.getType())), errStr);
}
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(wordCounts <512,"问题选项长度不用超过512");
question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now());
if(Objects.nonNull(questionVO.getId())){
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(questionVO.getId());
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
Long exist = this.questionDAO.countByExample(example);
if(exist <= 0){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(true,
"未找到要修改的数据!");
}
questionDAO.updateByPrimaryKeyWithBLOBs(question);
}else{
questionDAO.insert(question);
}
private void checkQuestionTypeForSelectAndJudge(PaperQuestionVO vo, String errStr) {
long answerCount = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount == 1, errStr);
}
}
private void checkQuestionTypeForMulti(PaperQuestionVO vo, String errStr) {
long answerCount = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount >= 2, errStr);
}
private void checkQuestionType(PaperQuestionVO vo ,String errStr){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue((Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())),errStr);
}
public void clearAllForOrgId(LoginUserInfoVO userInfoVO) {
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andOrgIdEqualTo(userInfoVO.getTopOrgId());
PaperQuestionWithBLOBs pq = new PaperQuestionWithBLOBs();
pq.setIsDel(BusinessConsts.DBLogicDelete.DELETE.ordinal());
questionDAO.updateByExampleSelective(pq, example);
}
private void checkQuestionTypeForSelectAndJudge(PaperQuestionVO vo,String errStr){
long answerCount = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount == 1,errStr);
}
@Transactional
public void importProjectQuestion(List<PaperQuestionVO> questions, Long companyId, AccountVO accountVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(companyId), "组织id不能为空");
questions.forEach(questionVO -> {
String topic = questionVO.getTopic();
this.checkQuestionType(questionVO, String.format("题库目前只支持单选,多选和判断,题序[%s]", questionVO.getId()));
if (questionVO.isSelect() || questionVO.isJudge()) {
this.checkQuestionTypeForSelectAndJudge(questionVO, String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(), topic));
} else if (questionVO.isMulti()) {
this.checkQuestionTypeForMulti(questionVO, String.format("题序[%s]:多选题[%s]正确答案应当至少有两个以上!", questionVO.getId(), topic));
}
if (StringUtils.hasText(questionVO.getTags())) {
List<String> tagList = Splitter.on(",").splitToList(questionVO.getTags());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(tagList.size() <= 1, "分类最多只能为1个");
}
});
private void checkQuestionTypeForMulti(PaperQuestionVO vo,String errStr){
long answerCount = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount >= 2,errStr);
}
public void clearAllForOrgId(LoginUserInfoVO userInfoVO){
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andOrgIdEqualTo(userInfoVO.getTopOrgId());
PaperQuestionWithBLOBs pq = new PaperQuestionWithBLOBs();
pq.setIsDel(BusinessConsts.DBLogicDelete.DELETE.ordinal());
questionDAO.updateByExampleSelective(pq,example);
}
@Transactional
public void importProjectQuestion(List<PaperQuestionVO> questions, Long companyId, AccountVO accountVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(companyId),"组织id不能为空");
questions.forEach(questionVO -> {
String topic = questionVO.getTopic();
this.checkQuestionType(questionVO,String.format("题库目前只支持单选,多选和判断,题序[%s]",questionVO.getId()));
if (questionVO.isSelect() || questionVO.isJudge()) {
this.checkQuestionTypeForSelectAndJudge(questionVO,String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic));
}else if(questionVO.isMulti()){
this.checkQuestionTypeForMulti(questionVO,String.format("题序[%s]:多选题[%s]正确答案应当至少有两个以上!", questionVO.getId(),topic));
}
if(StringUtils.hasText(questionVO.getTags())){
List<String> tagList = Splitter.on(",").splitToList(questionVO.getTags());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(tagList.size() <= 1 ,"分类最多只能为1个");
}
});
questions.forEach(questionVO -> {
PaperQuestionWithBLOBs question = questionVO.convert2DB();
question.setOrgId(companyId);
question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now());
questionDAO.insert(question);
});
questions.forEach(questionVO -> {
PaperQuestionWithBLOBs question = questionVO.convert2DB();
question.setOrgId(companyId);
question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now());
questionDAO.insert(question);
});
}
}
/**
* 删除 逻辑删除
* @param questionId 文本id
*/
public void deleteQuestion(List<Long> questionId) {
PaperQuestionExample example = new PaperQuestionExample();
example.createCriteria().andIdIn(questionId);
PaperQuestionWithBLOBs pq = new PaperQuestionWithBLOBs();
pq.setIsDel(BusinessConsts.DBLogicDelete.DELETE.ordinal());
questionDAO.updateByExampleSelective(pq,example);
}
/**
* 删除 逻辑删除
*
* @param questionId 文本id
*/
public void deleteQuestion(List<Long> questionId) {
PaperQuestionExample example = new PaperQuestionExample();
example.createCriteria().andIdIn(questionId);
PaperQuestionWithBLOBs pq = new PaperQuestionWithBLOBs();
pq.setIsDel(BusinessConsts.DBLogicDelete.DELETE.ordinal());
questionDAO.updateByExampleSelective(pq, example);
}
}