Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
walker-sheng 2020-12-01 19:05:58 +08:00
commit b72588b6ab
12 changed files with 110 additions and 37 deletions

View File

@ -23,7 +23,7 @@ public interface SysUserDAO extends MyBatisBaseDao<SysUser, Long, SysUserExample
" nationcode, email, wx_id, \n" +
" wx_union_id, wm_open_id, `status`, \n" +
" roles, `offline`, create_time, \n" +
" update_user_id, update_time)\n"+
" update_user_id, update_time)\n" +
" values " +
" <foreach collection=\"list\" item=\"entity\" separator=\",\"> " +
" (#{entity.account,jdbcType=VARCHAR}, #{entity.name,jdbcType=VARCHAR}, #{entity.nickname,jdbcType=VARCHAR}, \n" +
@ -44,4 +44,48 @@ public interface SysUserDAO extends MyBatisBaseDao<SysUser, Long, SysUserExample
" GROUP BY DATE(create_time);" +
"</script>")
List<DailyLiveQuantityVO> statisticsDailyRegister(@Param("beginDate") LocalDate beginDate, @Param("endDate") LocalDate endDate);
// @Results(value = {
// @Result(column = "id", property = "id"),
// @Result(column = "account", property = "account"),
// @Result(column = "name", property = "name"),
// @Result(column = "nickname", property = "nickname"),
// @Result(column = "avatar_path", property = "avatarPath"),
// @Result(column = "password", property = "password"),
// @Result(column = "mobile", property = "mobile"),
// @Result(column = "nationcode", property = "nationcode"),
// @Result(column = "email", property = "email"),
// @Result(column = "wx_id", property = "wxId"),
// @Result(column = "wx_union_id", property = "wxUnionId"),
// @Result(column = "wm_open_id", property = "wmOpenId"),
// @Result(column = "status", property = "status"),
// @Result(column = "roles", property = "roles"), //这行有问题
// @Result(column = "create_time", property = "createTime"),
// @Result(column = "company_id", property = "companyId"),
// @Result(column = "company.name", property = "companyName")
// })
// @Select("<script>" +
// "select\n" +
// " <if test=\"distinct\">\n" +
// " distinct\n" +
// " </if>\n" +
// " <include refid=\"Base_Column_List\" />\n" +
// " , company.name" +
// " from sys_user left join company on sys_user.company_id = company.id\n" +
// " <if test=\"_parameter != null\">\n" +
// " <include refid=\"Example_Where_Clause\" />\n" +
// " </if>\n" +
// " <if test=\"orderByClause != null\">\n" +
// " order by ${orderByClause}\n" +
// " </if>\n" +
// " <if test=\"limit != null\">\n" +
// " <if test=\"offset != null\">\n" +
// " limit ${offset}, ${limit}\n" +
// " </if>\n" +
// " <if test=\"offset == null\">\n" +
// " limit ${limit}\n" +
// " </if>\n" +
// " </if>" +
// "</script>")
// List<UserVO> selectUserWithCompanyName(SysUserExample example);
}

View File

@ -1,5 +1,9 @@
package club.joylink.rtss.exception;
import org.springframework.util.StringUtils;
import java.util.Objects;
public class BaseException extends RuntimeException {
private IExceptionMessage exceptionMessage;
@ -29,6 +33,9 @@ public class BaseException extends RuntimeException {
}
public String getVoMessage() {
if (!StringUtils.isEmpty(super.getMessage())) {
return super.getMessage();
}
return this.exceptionMessage.getMessage();
}
}

View File

@ -50,9 +50,10 @@ public enum BusinessExceptionAssertEnum implements BusinessExceptionAssert {
LOGIN_INFO_ERROR(40003, "login info error"),
LOGIN_EXPIRED(40004, "login expired"),
NOT_LOGIN(40005, "not login"),
WECHAT_CODE_EXPIRED(40029, "wechat code expired"),
INVALID_CLIENT(40031, "invalid client"),
INCORRECT_VERIFICATION_CODE(40051, "incorrect verification code"),
THIRD_SERVICE_CALL_EXCEPTION(40071, "the third service call exception"),
THIRD_SERVICE_CALL_EXCEPTION(40071, "the third service call exception")
;
int code;

View File

@ -71,6 +71,9 @@ public class LessonService implements ILessonService {
@Autowired
private StudentRelLessonClassDAO studentRelLessonClassDAO;
@Autowired
private IExamService iExamService;
@Override
public LessonTreeVO getLessonTree(Long id, UserVO userVO) {
LessonTreeVO lessonTreeVO = new LessonTreeVO();
@ -616,7 +619,7 @@ public class LessonService implements ILessonService {
if (Objects.nonNull(existedDefaultLesson)) {
lesson.setId(existedDefaultLesson.getId());
lessonDAO.updateByPrimaryKey(lesson);
//存在默认课程删除旧版本章节及关联实训数据
//存在默认课程删除旧版本章节考试及关联实训数据
LsLessonVersionExample versionExample = new LsLessonVersionExample();
versionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId());
lessonVersionDAO.deleteByExample(versionExample);
@ -654,7 +657,7 @@ public class LessonService implements ILessonService {
List<Training> examTrainings = new ArrayList<>(20);
int orderNum = 1;
Random random = new Random();
Map<String, Map<String, List<Training>>> trainings = iTrainingV1Service.findEntities(mapVO.getId())
Map<String, Map<String, List<Training>>> trainings = iTrainingV1Service.findEntities(mapVO.getId(), prdType)
.stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType)));
for (BusinessConsts.Training.Type type : BusinessConsts.Training.Type.values()) {
Map<String, List<Training>> collect = trainings.get(type.name());

View File

@ -13,6 +13,7 @@ import club.joylink.rtss.vo.SmsResponse;
import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.VdCode;
import club.joylink.rtss.vo.client.CompanyVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.UserConfigVO;
import club.joylink.rtss.vo.client.map.MapVO;
@ -33,6 +34,7 @@ import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@ -83,6 +85,9 @@ public class SysUserService implements ISysUserService {
@Autowired
private CompanyDAO companyDAO;
@Autowired
private ICompanyService iCompanyService;
@Override
public UserVO findUserByAccountAndPassword(String account, String password) {
SysUserExample example = new SysUserExample();
@ -230,6 +235,13 @@ public class SysUserService implements ISysUserService {
}
Page<SysUser> page = (Page<SysUser>) this.sysUserDAO.selectByExample(example);
List<UserVO> userVOS = UserVO.convert2VO(page.getResult());
Map<Integer, CompanyVO> companyMap = iCompanyService.queryOrganizations().stream()
.collect(Collectors.toMap(CompanyVO::getId, Function.identity()));
userVOS.forEach(user -> {
if (user.getCompanyId() != null) {
user.setCompanyName(companyMap.get(user.getCompanyId()).getName());
}
});
return PageVO.convert(page, userVOS);
}

View File

@ -51,9 +51,6 @@ public class UserExamService implements IUserExamService {
@Autowired
private LsLessonDAO lessonDAO;
@Autowired
private ISysUserService iSysUserService;
@Override
@Transactional
public UserExamVO generateExamInstance(long examId, UserVO userVO) {
@ -73,7 +70,7 @@ public class UserExamService implements IUserExamService {
// 判断是否在考试时间之内
if (examDef.getStartTime() != null) {
LocalDateTime now = LocalDateTime.now();
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime())&&now.isBefore(examDef.getEndTime()));
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime()) && now.isBefore(examDef.getEndTime()));
}
// 保存用户考试信息
UserExam userExam = new UserExam();
@ -89,28 +86,30 @@ public class UserExamService implements IUserExamService {
ruleExample.createCriteria().andExamIdEqualTo(examId);
List<ExamDefinitionRules> rules = this.examDefinitionRulesDAO.selectByExample(ruleExample);
BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionNotEmpty(rules);
//确认课程存在
LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson);
//查询实训生成试卷
Map<String, Map<String, List<Training>>> trainings = iTrainingService.findEntities(lesson.getMapId(), lesson.getPrdType())
.stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType)));
for (ExamDefinitionRules rule : rules) {
// 根据课程所属产品的编码和规则中实训类型查找实训
LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson);
TrainingExample te = new TrainingExample();
TrainingExample.Criteria criteria = te.createCriteria()
.andMapIdEqualTo(lesson.getMapId())
.andPrdTypeEqualTo(lesson.getPrdType())
.andTypeEqualTo(rule.getTrainingType());
List<Training> collect;
if (StringUtils.hasText(rule.getOperateType())) {
criteria.andOperateTypeEqualTo(rule.getOperateType());
collect = trainings.get(rule.getTrainingType()).get(rule.getOperateType());
} else {
collect = new ArrayList<>();
for (List<Training> value : trainings.get(rule.getTrainingType()).values()) {
collect.addAll(value);
}
}
// 符合生成规则的实训
List<Training> trainings = this.trainingDAO.selectByExample(te);
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(trainings.size() > rule.getNum());
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(collect.size() > rule.getNum());
// 随机生成考试并保存
boolean flag = true;
List<UserExamQuestionsVO> questionsVOs = new ArrayList<>();
while (flag) {
Random random = new Random();
int i = random.nextInt(trainings.size());
Long trainId = trainings.get(i).getId();
int i = random.nextInt(collect.size());
Long trainId = collect.get(i).getId();
// 保存考试题目
UserExamQuestions questions = new UserExamQuestions();
questions.setPoint(rule.getPoint());
@ -121,10 +120,10 @@ public class UserExamService implements IUserExamService {
this.userExamQuestionsMapper.insert(questions);
// 返回考试题目
UserExamQuestionsVO userExamQuestionsVO = new UserExamQuestionsVO(questions);
userExamQuestionsVO.setTrainingName(trainings.get(i).getName());
userExamQuestionsVO.setTrainingName(collect.get(i).getName());
questionsVOs.add(userExamQuestionsVO);
// 从集合中剔除已使用实训
trainings.remove(i);
collect.remove(i);
if (questionsVOs.size() == rule.getNum()) {
flag = false;
}

View File

@ -1,13 +1,12 @@
package club.joylink.rtss.services;
import club.joylink.rtss.configuration.configProp.WeChatConfig;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.cache.ICacheService;
import club.joylink.rtss.configuration.configProp.WeChatConfig;
import club.joylink.rtss.vo.wx.WmUserSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.util.Objects;
@ -46,7 +45,7 @@ public class WxApiService implements IWxApiService {
WmUserSession wmUserSession = (WmUserSession) this.iCacheService.get(WmUserSession.getCacheKey(wmCode));
if(Objects.isNull(wmUserSession)) {
wmUserSession = restTemplate.getForObject(weChatConfig.getCode2SessionUrl(wmCode), WmUserSession.class);
BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.assertHasText(wmUserSession.getOpenid(),
BusinessExceptionAssertEnum.WECHAT_CODE_EXPIRED.assertHasText(wmUserSession.getOpenid(),
String.format("小程序code为%s微信返回的错误消息errcode:'%s', errmsg:%s", wmCode, wmUserSession.getErrcode(), wmUserSession.getErrmsg()));
iCacheService.putExpired(WmUserSession.getCacheKey(wmCode), wmUserSession, 5, TimeUnit.MINUTES);
}

View File

@ -180,21 +180,21 @@ public class QuestionBankService implements IQuestionBankService {
if (questionVO.isSelect() || questionVO.isJudge()) {
long answerCount = questionVO.getOptionList().stream().filter(QuestionOptionVO::getCorrect).count();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount == 1,
String.format("单选或判断题[%s]正确答案应当有且只有一个!", topic));
String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic));
}
if (questionVO.isFill() || questionVO.isAnswer()) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
questionVO.getOptionList().stream().allMatch(QuestionOptionVO::getCorrect),
String.format("填空或问答题[%s]不能有错误选项!", topic));
String.format("题序[%s]:填空或问答题[%s]不能有错误选项!", questionVO.getId(),topic));
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
questionVO.getOptionList().stream().noneMatch(op -> Objects.isNull(op.getOrder())),
String.format("填空或问答题[%s]选项缺少序号!", topic));
String.format("题序[%s]:填空或问答题[%s]选项缺少序号!", questionVO.getId(),topic));
if (questionVO.getOptionList().stream().anyMatch(op -> Objects.isNull(op.getOrder()))) {
questionVO.getOptionList().sort(Comparator.comparing(QuestionOptionVO::getOrder));
AtomicInteger i = new AtomicInteger(1);
questionVO.getOptionList().forEach(o -> {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(o.getOrder(), i.getAndIncrement(),
String.format("填空或问答题[%s]选项序号不对!", topic));
String.format("题序[%s]:填空或问答题[%s]选项序号不对!", questionVO.getId(), topic));
});
}

View File

@ -186,5 +186,5 @@ public interface ITrainingV1Service {
* 根据地图id查询实训
* @return
*/
List<Training> findEntities(Long mapId);
List<Training> findEntities(Long mapId, String prdType);
}

View File

@ -689,9 +689,9 @@ public class TrainingV1Service implements ITrainingV1Service {
}
@Override
public List<Training> findEntities(Long mapId) {
public List<Training> findEntities(Long mapId, String prdType) {
TrainingExample example = new TrainingExample();
example.createCriteria().andMapIdEqualTo(mapId);
example.createCriteria().andMapIdEqualTo(mapId).andPrdTypeEqualTo(prdType);
return trainingDAO.selectByExample(example);
}
}

View File

@ -33,6 +33,12 @@ public class UserQueryVO extends PageQueryVO {
@ApiModelProperty(value = "手机号")
private String mobile;
/**
* 单位名称
*/
@ApiModelProperty(value = "单位名称")
private String companyId;
/**
* 角色
*/

View File

@ -1,17 +1,17 @@
package club.joylink.rtss.vo;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.SysUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@ -102,6 +102,8 @@ public class UserVO implements Serializable {
private Integer companyId;
private String companyName;
public UserVO() {}
public UserVO(SysUser sysUser) {