dev
parent
70f899ca5f
commit
51361ad1ed
|
@ -30,8 +30,11 @@ public class RedisConfig {
|
|||
serializer.setObjectMapper(mapper);
|
||||
|
||||
redisTemplate.setValueSerializer(serializer);
|
||||
redisTemplate.setHashValueSerializer(serializer);
|
||||
//使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setKeySerializer(serializer);
|
||||
redisTemplate.setHashValueSerializer(serializer);
|
||||
// redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
|
|
@ -50,4 +50,24 @@ public class Constants {
|
|||
//微信支付
|
||||
public static String WECHAT_PAY = "weChatPay";
|
||||
|
||||
//题库版本前缀
|
||||
public static String QUESTION_VERSOPN_PREFIX = "QuestionVersion_";
|
||||
|
||||
//redis 有效期(单位秒)
|
||||
public static String REDIS_EXPIRE_TIME = "RedisExprieTime";
|
||||
|
||||
//考试题型数量配置项
|
||||
public static String TEST_QUESTION_TYPE_NUM = "TestQuestionTypeNum";
|
||||
|
||||
//配置项列表前缀
|
||||
public static String CONFIG_LIST_PREFIX = "configListOf_";
|
||||
|
||||
//配置项前缀
|
||||
public static String CONFIG_PREFIX = "configOf_";
|
||||
|
||||
//专项数量前缀
|
||||
public static String SPECIAL_NUM_PREFIX= "SpecialNum_";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ public class ErrorCode {
|
|||
// 业务异常编码,异常原因已知
|
||||
public static final String BUSINESS = "E008";
|
||||
|
||||
// 题库版本异常
|
||||
public static final String VERSION_ERROR = "4001";
|
||||
|
||||
public static final String NOT_SHOW = "NOO1";
|
||||
|
||||
private ErrorCode() {
|
||||
|
|
|
@ -42,7 +42,6 @@ public class TdQuestionController {
|
|||
return BaseResponse.success(tdQuestionService.queryQuestionById(queryDto));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据id列表获取题目")
|
||||
@PostMapping("/queryQuestionByIdList")
|
||||
public BaseResponse queryQuestionByIdList(@RequestBody QuestionQueryDto queryDto) {
|
||||
|
@ -50,14 +49,20 @@ public class TdQuestionController {
|
|||
return BaseResponse.success(tdQuestionService.queryQuestionByIdList(queryDto));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据查询条件获取题目")
|
||||
@PostMapping("/queryQuestion")
|
||||
public BaseResponse queryQuestion(@RequestBody QuestionQueryDto queryDto) {
|
||||
log.info("获取题型======>queryDto:{}", queryDto);
|
||||
log.info("根据查询条件获取题目======>queryDto:{}", queryDto);
|
||||
return BaseResponse.success(tdQuestionService.queryQuestion(queryDto));
|
||||
}
|
||||
|
||||
@ApiOperation("根据查询条件获取题目Id")
|
||||
@PostMapping("/queryQuestionId")
|
||||
public BaseResponse queryQuestionId(@RequestBody QuestionQueryDto queryDto) {
|
||||
log.info("根据查询条件获取题目Id======>queryDto:{}", queryDto);
|
||||
return BaseResponse.success(tdQuestionService.queryQuestionId(queryDto));
|
||||
}
|
||||
|
||||
@ApiOperation("获取模拟考试题目")
|
||||
@PostMapping("/getTestQuestion")
|
||||
public BaseResponse getTestQuestion(@RequestBody QuestionQueryDto queryDto) {
|
||||
|
@ -68,6 +73,13 @@ public class TdQuestionController {
|
|||
return BaseResponse.success(tdQuestionService.getTestQuestion(queryDto));
|
||||
}
|
||||
|
||||
@ApiOperation("获取模拟考试题目Id")
|
||||
@PostMapping("/getTestQuestionId")
|
||||
public BaseResponse getTestQuestionId(@RequestBody QuestionQueryDto queryDto) {
|
||||
log.info("根据查询条件获取题目Id======>queryDto:{}", queryDto);
|
||||
return BaseResponse.success(tdQuestionService.getTestQuestionId(queryDto));
|
||||
}
|
||||
|
||||
@ApiOperation("题目分类")
|
||||
@PostMapping("/questionCategory")
|
||||
public BaseResponse questionCategory(@RequestBody QuestionQueryDto queryDto) {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
|
||||
import com.jwl.driver.server.dto.TestSubmitDto;
|
||||
import com.jwl.driver.server.entity.TdQuestionVersion;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import com.jwl.driver.server.service.ITdQuestionVersionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 题库版本表; 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-09-03
|
||||
*/
|
||||
@Api(tags = "题库版本")
|
||||
@RestController
|
||||
@RequestMapping("/tdQuestionVersion")
|
||||
@Slf4j
|
||||
public class TdQuestionVersionController {
|
||||
|
||||
@Autowired
|
||||
private ITdQuestionVersionService versionService;
|
||||
|
||||
@ApiOperation("获取题库当前版本")
|
||||
@GetMapping("/currentVersion")
|
||||
public BaseResponse testSubmit(@RequestParam Integer carTypeId) {
|
||||
log.info("获取题库当前版本======>carTypeId:{}", carTypeId);
|
||||
return BaseResponse.success(versionService.currentVersion(carTypeId));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("题库版本更新")
|
||||
@PostMapping("/addVersion")
|
||||
public BaseResponse addVersion(@RequestBody TdQuestionVersion versionDto) {
|
||||
log.info("题库版本更新======>versionDto:{}", versionDto);
|
||||
if (Objects.isNull(versionDto.getCarTypeId())){
|
||||
throw new BusinessException("缺少必要参数");
|
||||
}
|
||||
|
||||
return BaseResponse.success(versionService.addVersion(versionDto));
|
||||
}
|
||||
|
||||
}
|
|
@ -140,4 +140,10 @@ public class QuestionQueryDto implements Serializable {
|
|||
@ApiModelProperty("是否密卷2")
|
||||
private Integer isExam2;
|
||||
|
||||
/**
|
||||
* 题库版本id
|
||||
*/
|
||||
@ApiModelProperty("题库版本id")
|
||||
private Long versionId;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.jwl.driver.server.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author 曹林
|
||||
* @description 考试题目类型蚕食
|
||||
* @create 2023/8/11 22:21
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TestQuestionTypeDto {
|
||||
|
||||
//科目
|
||||
private String subject;
|
||||
//判断题
|
||||
private Integer judgeNum;
|
||||
//单选题
|
||||
private Integer radioNum;
|
||||
//多选题
|
||||
private Integer multipleChoiceNum;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.jwl.driver.server.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 题库版本表;
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-09-03
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class TdQuestionVersion implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 题库版本
|
||||
*/
|
||||
@TableId(value = "VERSION_ID", type = IdType.AUTO)
|
||||
private Long versionId;
|
||||
|
||||
/**
|
||||
* 车型标识
|
||||
*/
|
||||
@TableField("CAR_TYPE_ID")
|
||||
private Integer carTypeId;
|
||||
|
||||
/**
|
||||
* 是否生效
|
||||
*/
|
||||
@TableField("IS_ACTIVE")
|
||||
private String isActive;
|
||||
|
||||
/**
|
||||
* 备注说明
|
||||
*/
|
||||
@TableField("DESCRIPTION")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_TIME")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,11 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
@ -77,6 +82,8 @@ public class TdSysConfig implements Serializable {
|
|||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_TIME")
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,11 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
@ -63,6 +68,8 @@ public class TdSysConfigList implements Serializable {
|
|||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_TIME")
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,13 @@ public interface TdQuestionMapper extends BaseMapper<TdQuestion> {
|
|||
*/
|
||||
List<QuestionVo> queryQuestion(@Param("queryDto") QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 获取考题id
|
||||
* @param queryDto
|
||||
* @return
|
||||
*/
|
||||
List<Long> queryQuestionId(@Param("queryDto") QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 随机查询考题
|
||||
* @param queryDto
|
||||
|
@ -33,6 +40,13 @@ public interface TdQuestionMapper extends BaseMapper<TdQuestion> {
|
|||
*/
|
||||
List<QuestionVo> queryQuestionByRandom(@Param("queryDto") QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 随机查询考题Id
|
||||
* @param queryDto
|
||||
* @return
|
||||
*/
|
||||
List<Long> queryQuestionIdByRandom(@Param("queryDto") QuestionQueryDto queryDto);
|
||||
|
||||
int updateQuestion(@Param("questionVo") QuestionVo questionVo);
|
||||
|
||||
/**
|
||||
|
@ -41,4 +55,6 @@ public interface TdQuestionMapper extends BaseMapper<TdQuestion> {
|
|||
* @return
|
||||
*/
|
||||
Map<String, Integer> querySpecialNum(@Param("queryDto") QuestionQueryDto queryDto);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.jwl.driver.server.mapper;
|
||||
|
||||
import com.jwl.driver.server.entity.TdQuestionVersion;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 题库版本表; Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-09-03
|
||||
*/
|
||||
public interface TdQuestionVersionMapper extends BaseMapper<TdQuestionVersion> {
|
||||
|
||||
}
|
|
@ -41,6 +41,13 @@ public interface ITdQuestionService extends IService<TdQuestion> {
|
|||
*/
|
||||
List<QuestionVo> queryQuestion(QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 根据查询条件获取题目Id
|
||||
* @param queryDto
|
||||
* @return
|
||||
*/
|
||||
List<Long> queryQuestionId(QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 获取考试题目
|
||||
* @param queryDto
|
||||
|
@ -48,6 +55,13 @@ public interface ITdQuestionService extends IService<TdQuestion> {
|
|||
*/
|
||||
List<QuestionVo> getTestQuestion(QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 获取考试题目Id
|
||||
* @param queryDto
|
||||
* @return
|
||||
*/
|
||||
List<Long> getTestQuestionId(QuestionQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 题目分类
|
||||
* @param queryDto
|
||||
|
@ -68,4 +82,5 @@ public interface ITdQuestionService extends IService<TdQuestion> {
|
|||
* @return
|
||||
*/
|
||||
Map<String,Integer> querySpecialNum(QuestionQueryDto queryDto);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.jwl.driver.server.service;
|
||||
|
||||
import com.jwl.driver.server.entity.TdQuestionVersion;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 题库版本表; 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-09-03
|
||||
*/
|
||||
public interface ITdQuestionVersionService extends IService<TdQuestionVersion> {
|
||||
|
||||
/**
|
||||
* 获取题库当前版本号
|
||||
* @param carTypeId
|
||||
* @return
|
||||
*/
|
||||
Long currentVersion(Integer carTypeId);
|
||||
|
||||
/**
|
||||
* 题库版本更新
|
||||
* @param versionDto
|
||||
* @return
|
||||
*/
|
||||
Boolean addVersion(TdQuestionVersion versionDto);
|
||||
}
|
|
@ -2,19 +2,30 @@ package com.jwl.driver.server.service.impl;
|
|||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.generator.config.IFileCreate;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.constant.ErrorCode;
|
||||
import com.jwl.driver.server.dto.QuestionQueryDto;
|
||||
import com.jwl.driver.server.dto.TestQuestionTypeDto;
|
||||
import com.jwl.driver.server.entity.TdQuestion;
|
||||
import com.jwl.driver.server.entity.TdSysConfig;
|
||||
import com.jwl.driver.server.entity.TdSysConfigList;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.mapper.TdQuestionMapper;
|
||||
import com.jwl.driver.server.redis.RedisCache;
|
||||
import com.jwl.driver.server.service.ITdQuestionService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jwl.driver.server.service.ITdQuestionVersionService;
|
||||
import com.jwl.driver.server.service.ITdSysConfigListService;
|
||||
import com.jwl.driver.server.service.ITdSysConfigService;
|
||||
import com.jwl.driver.server.vo.QuestionVo;
|
||||
import com.jwl.driver.server.vo.QusetionCategoryVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -30,6 +41,7 @@ import java.util.stream.Collectors;
|
|||
* @since 2023-08-10
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuestion> implements ITdQuestionService {
|
||||
|
||||
@Autowired
|
||||
|
@ -38,16 +50,24 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
@Autowired
|
||||
private ITdSysConfigListService configListService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private ITdQuestionVersionService versionService;
|
||||
|
||||
@Override
|
||||
public QuestionVo queryQuestionById(QuestionQueryDto queryDto) {
|
||||
|
||||
QuestionQueryDto newDto = new QuestionQueryDto()
|
||||
.setQuestionId(queryDto.getQuestionId());
|
||||
List<QuestionVo> questionVos = queryQuestion(newDto);
|
||||
return CollectionUtil.isEmpty(questionVos)? null : questionVos.get(0);
|
||||
return CollectionUtil.isEmpty(questionVos) ? null : questionVos.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuestionVo> queryQuestionByIdList(QuestionQueryDto queryDto) {
|
||||
|
||||
QuestionQueryDto newDto = new QuestionQueryDto()
|
||||
.setQuestionIdList(queryDto.getQuestionIdList());
|
||||
return queryQuestion(newDto);
|
||||
|
@ -55,61 +75,123 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
|
||||
@Override
|
||||
public List<QuestionVo> queryQuestion(QuestionQueryDto queryDto) {
|
||||
//校验题库版本是否一致
|
||||
checkQuestionVersion(queryDto.getCarTypeId(), queryDto.getVersionId());
|
||||
|
||||
List<QuestionVo> questionVos = this.getBaseMapper().queryQuestion(queryDto);
|
||||
questionOptionHandler(questionVos);
|
||||
return questionVos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryQuestionId(QuestionQueryDto queryDto) {
|
||||
//校验题库版本是否一致
|
||||
checkQuestionVersion(queryDto.getCarTypeId(), queryDto.getVersionId());
|
||||
|
||||
List<Long> questionIds = this.getBaseMapper().queryQuestionId(queryDto);
|
||||
return questionIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuestionVo> getTestQuestion(QuestionQueryDto queryDto) {
|
||||
|
||||
//校验题库版本是否一致
|
||||
checkQuestionVersion(queryDto.getCarTypeId(), queryDto.getVersionId());
|
||||
|
||||
List<QuestionVo> resultList = new ArrayList<>();
|
||||
|
||||
if (StrUtil.equals(Constants.SUBJECT_ONE,queryDto.getSubject())){
|
||||
//40道判断题 60道单选 每题1分
|
||||
TdSysConfig tdSysConfig = configService.queryConfigByKey(Constants.TEST_QUESTION_TYPE_NUM, queryDto.getCarTypeId());
|
||||
if (Objects.isNull(tdSysConfig)) {
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("获取信息异常");
|
||||
}
|
||||
|
||||
List<TestQuestionTypeDto> testQuestionTypeDtos = JSON.parseArray(tdSysConfig.getConfigJson(), TestQuestionTypeDto.class);
|
||||
Optional<TestQuestionTypeDto> optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst();
|
||||
if (optional.isPresent()) {
|
||||
TestQuestionTypeDto testQuestionTypeDto = optional.get();
|
||||
//判断题
|
||||
if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_ONE)
|
||||
.setNum(40);
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
|
||||
queryDto.setType(Constants.QUESTION_TYPE_TWO)
|
||||
.setNum(60);
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
|
||||
}else if(StrUtil.equals(Constants.SUBJECT_FOUR,queryDto.getSubject())){
|
||||
//20道判断题 20道单选 10道多选,每题2分,如果各车型不统一 可以配在数据库里
|
||||
queryDto.setType(Constants.QUESTION_TYPE_TWO)
|
||||
.setNum(20);
|
||||
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
queryDto.setType(Constants.QUESTION_TYPE_ONE)
|
||||
.setNum(20);
|
||||
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
queryDto.setType(Constants.QUESTION_TYPE_THREE)
|
||||
.setNum(10);
|
||||
.setNum(testQuestionTypeDto.getJudgeNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
}
|
||||
//单选
|
||||
if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_TWO)
|
||||
.setNum(testQuestionTypeDto.getRadioNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
}
|
||||
|
||||
//多选
|
||||
if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_THREE)
|
||||
.setNum(testQuestionTypeDto.getMultipleChoiceNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
|
||||
}
|
||||
}
|
||||
questionOptionHandler(resultList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getTestQuestionId(QuestionQueryDto queryDto) {
|
||||
//校验题库版本是否一致
|
||||
checkQuestionVersion(queryDto.getCarTypeId(), queryDto.getVersionId());
|
||||
|
||||
List<Long> resultList = new ArrayList<>();
|
||||
|
||||
TdSysConfig tdSysConfig = configService.queryConfigByKey(Constants.TEST_QUESTION_TYPE_NUM, queryDto.getCarTypeId());
|
||||
if (Objects.isNull(tdSysConfig)) {
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("获取信息异常");
|
||||
}
|
||||
|
||||
List<TestQuestionTypeDto> testQuestionTypeDtos = JSON.parseArray(tdSysConfig.getConfigJson(), TestQuestionTypeDto.class);
|
||||
Optional<TestQuestionTypeDto> optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst();
|
||||
if (optional.isPresent()) {
|
||||
TestQuestionTypeDto testQuestionTypeDto = optional.get();
|
||||
//判断题
|
||||
if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_ONE)
|
||||
.setNum(testQuestionTypeDto.getJudgeNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
|
||||
}
|
||||
//单选
|
||||
if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_TWO)
|
||||
.setNum(testQuestionTypeDto.getRadioNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
|
||||
}
|
||||
|
||||
//多选
|
||||
if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) {
|
||||
queryDto.setType(Constants.QUESTION_TYPE_THREE)
|
||||
.setNum(testQuestionTypeDto.getMultipleChoiceNum());
|
||||
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QusetionCategoryVo> questionCategory(QuestionQueryDto queryDto) {
|
||||
|
||||
List<QusetionCategoryVo> resultList = new ArrayList<>();
|
||||
//获取题目
|
||||
List<QuestionVo> tdQuestionVos = queryQuestionByIdList(queryDto);
|
||||
if (CollectionUtil.isEmpty(tdQuestionVos)){
|
||||
if (CollectionUtil.isEmpty(tdQuestionVos)) {
|
||||
return resultList;
|
||||
}
|
||||
//获取分类
|
||||
List<TdSysConfigList> categoryList = configListService.querySysConfigList(Constants.QUESTION_CATEGORY, Constants.DEFAULT_CARTYPE_ID);
|
||||
Map<String, String> categoryMap = categoryList.stream().collect(Collectors.toMap(TdSysConfigList::getConfigItemCode, TdSysConfigList::getConfigItemName, (v1, v2) -> v1));
|
||||
Map<String,Integer> totalMap = new HashMap<>();
|
||||
Map<String,List<Long>> errorQuestionIdMap = new HashMap<>();
|
||||
Map<String, Integer> totalMap = new HashMap<>();
|
||||
Map<String, List<Long>> errorQuestionIdMap = new HashMap<>();
|
||||
|
||||
for (QuestionVo tdQuestionVo : tdQuestionVos) {
|
||||
String category = tdQuestionVo.getCategory();
|
||||
if (StrUtil.isBlank(category)){
|
||||
if (StrUtil.isBlank(category)) {
|
||||
continue;
|
||||
}
|
||||
String[] split = category.split(",");
|
||||
|
@ -120,10 +202,10 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
List<Long> errorQuestionIdList = errorQuestionIdMap.get(s);
|
||||
errorQuestionIdList.add(tdQuestionVo.getQuestionId());
|
||||
} else {
|
||||
totalMap.put(s,1); //此时集合中没有该Key,所以将该字符作为键加入到集合中
|
||||
totalMap.put(s, 1); //此时集合中没有该Key,所以将该字符作为键加入到集合中
|
||||
List<Long> errorQuestionIdList = new ArrayList<>();
|
||||
errorQuestionIdList.add(tdQuestionVo.getQuestionId());
|
||||
errorQuestionIdMap.put(s,errorQuestionIdList);
|
||||
errorQuestionIdMap.put(s, errorQuestionIdList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +214,7 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
QusetionCategoryVo categoryVo = new QusetionCategoryVo()
|
||||
.setCategory(category)
|
||||
.setErrorQuestionIdList(errorQuestionIdMap.get(category))
|
||||
.setCategoryName(categoryMap.getOrDefault(category,"其他类型"))
|
||||
.setCategoryName(categoryMap.getOrDefault(category, "其他类型"))
|
||||
.setNum(totalMap.get(category));
|
||||
resultList.add(categoryVo);
|
||||
}
|
||||
|
@ -146,39 +228,97 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
|
||||
@Override
|
||||
public Map<String, Integer> querySpecialNum(QuestionQueryDto queryDto) {
|
||||
return this.getBaseMapper().querySpecialNum(queryDto);
|
||||
//校验题库版本是否一致
|
||||
checkQuestionVersion(queryDto.getCarTypeId(), queryDto.getVersionId());
|
||||
|
||||
Map<String, Integer> resultMap = redisCache.getCacheObject(Constants.SPECIAL_NUM_PREFIX + queryDto.getCarTypeId() + "_" + queryDto.getSubject());
|
||||
if (Objects.nonNull(resultMap)) {
|
||||
return resultMap;
|
||||
}
|
||||
resultMap = this.getBaseMapper().querySpecialNum(queryDto);
|
||||
|
||||
if (CollectionUtil.isEmpty(resultMap)) {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
TdSysConfig tdSysConfig = configService.queryConfigByKey(Constants.REDIS_EXPIRE_TIME, Constants.DEFAULT_CARTYPE_ID);
|
||||
if (Objects.isNull(tdSysConfig)) {
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("系统异常");
|
||||
}
|
||||
// 塞入redis中
|
||||
redisCache.setCacheObject(Constants.SPECIAL_NUM_PREFIX + queryDto.getCarTypeId() + "_" + queryDto.getSubject(), resultMap, Long.parseLong(tdSysConfig.getConfigValue()));
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 问题选项规整
|
||||
*/
|
||||
private void questionOptionHandler(List<QuestionVo> questionVos){
|
||||
if (CollectionUtil.isNotEmpty(questionVos)){
|
||||
private void questionOptionHandler(List<QuestionVo> questionVos) {
|
||||
if (CollectionUtil.isNotEmpty(questionVos)) {
|
||||
for (QuestionVo questionVo : questionVos) {
|
||||
//如果选项A没有值 则为判断题
|
||||
List<QuestionVo.QuestionOption> optionList = new ArrayList<>();
|
||||
if (StrUtil.isBlank(questionVo.getChooseA()) || StrUtil.equals(questionVo.getType(),Constants.QUESTION_TYPE_ONE)){
|
||||
optionList.add(new QuestionVo.QuestionOption("A","正确","1"));
|
||||
optionList.add(new QuestionVo.QuestionOption("B","错误","2"));
|
||||
}else {
|
||||
if (StrUtil.isBlank(questionVo.getChooseA()) || StrUtil.equals(questionVo.getType(), Constants.QUESTION_TYPE_ONE)) {
|
||||
optionList.add(new QuestionVo.QuestionOption("A", "正确", "1"));
|
||||
optionList.add(new QuestionVo.QuestionOption("B", "错误", "2"));
|
||||
} else {
|
||||
//起码ABCD都有
|
||||
optionList.add(new QuestionVo.QuestionOption("A",questionVo.getChooseA(),"1"));
|
||||
optionList.add(new QuestionVo.QuestionOption("B",questionVo.getChooseB(),"2"));
|
||||
optionList.add(new QuestionVo.QuestionOption("C",questionVo.getChooseC(),"3"));
|
||||
optionList.add(new QuestionVo.QuestionOption("D",questionVo.getChooseD(),"4"));
|
||||
optionList.add(new QuestionVo.QuestionOption("A", questionVo.getChooseA(), "1"));
|
||||
optionList.add(new QuestionVo.QuestionOption("B", questionVo.getChooseB(), "2"));
|
||||
optionList.add(new QuestionVo.QuestionOption("C", questionVo.getChooseC(), "3"));
|
||||
optionList.add(new QuestionVo.QuestionOption("D", questionVo.getChooseD(), "4"));
|
||||
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseE())){
|
||||
optionList.add(new QuestionVo.QuestionOption("E",questionVo.getChooseE(),"5"));
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseE())) {
|
||||
optionList.add(new QuestionVo.QuestionOption("E", questionVo.getChooseE(), "5"));
|
||||
}
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseF())){
|
||||
optionList.add(new QuestionVo.QuestionOption("F",questionVo.getChooseF(),"6"));
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseF())) {
|
||||
optionList.add(new QuestionVo.QuestionOption("F", questionVo.getChooseF(), "6"));
|
||||
}
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseG())){
|
||||
optionList.add(new QuestionVo.QuestionOption("G",questionVo.getChooseG(),"7"));
|
||||
if (StrUtil.isNotBlank(questionVo.getChooseG())) {
|
||||
optionList.add(new QuestionVo.QuestionOption("G", questionVo.getChooseG(), "7"));
|
||||
}
|
||||
}
|
||||
questionVo.setOptionList(optionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验题库是否一直
|
||||
*
|
||||
* @param carTypeId
|
||||
* @param version
|
||||
*/
|
||||
private void checkQuestionVersion(Integer carTypeId, Long version) {
|
||||
if (Objects.isNull(carTypeId) || Objects.isNull(version)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Long versionId = versionService.currentVersion(carTypeId);
|
||||
if (!Objects.equals(versionId, version)) {
|
||||
throw new BusinessException(ErrorCode.VERSION_ERROR, "题库版本不一致");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<TestQuestionTypeDto> testQuestionTypeDtos = new ArrayList<>();
|
||||
TestQuestionTypeDto dto1 = new TestQuestionTypeDto()
|
||||
.setSubject("1")
|
||||
.setJudgeNum(40)
|
||||
.setRadioNum(60)
|
||||
.setMultipleChoiceNum(0);
|
||||
TestQuestionTypeDto dto2 = new TestQuestionTypeDto()
|
||||
.setSubject("4")
|
||||
.setJudgeNum(20)
|
||||
.setRadioNum(20)
|
||||
.setMultipleChoiceNum(10);
|
||||
testQuestionTypeDtos.add(dto1);
|
||||
testQuestionTypeDtos.add(dto2);
|
||||
String jsonString = JSONArray.toJSONString(testQuestionTypeDtos);
|
||||
System.out.println(jsonString);
|
||||
|
||||
List<TestQuestionTypeDto> testQuestionTypeDtos1 = JSONArray.parseArray(jsonString, TestQuestionTypeDto.class);
|
||||
System.out.println(testQuestionTypeDtos1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package com.jwl.driver.server.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.entity.TdQuestionVersion;
|
||||
import com.jwl.driver.server.entity.TdSysConfig;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.mapper.TdQuestionVersionMapper;
|
||||
import com.jwl.driver.server.redis.RedisCache;
|
||||
import com.jwl.driver.server.service.ITdQuestionVersionService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jwl.driver.server.service.ITdSysConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 题库版本表; 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-09-03
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TdQuestionVersionServiceImpl extends ServiceImpl<TdQuestionVersionMapper, TdQuestionVersion> implements ITdQuestionVersionService {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private ITdSysConfigService configService;
|
||||
|
||||
@Override
|
||||
public Long currentVersion(Integer carTypeId) {
|
||||
|
||||
Integer value = redisCache.getCacheObject(Constants.QUESTION_VERSOPN_PREFIX + carTypeId);
|
||||
|
||||
if (value !=null){
|
||||
return value.longValue();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TdQuestionVersion> cond = new LambdaQueryWrapper<TdQuestionVersion>()
|
||||
.eq(TdQuestionVersion::getCarTypeId,carTypeId)
|
||||
.eq(TdQuestionVersion::getIsActive,Constants.IS_ACTIVE_TRUE);
|
||||
|
||||
TdQuestionVersion tdQuestionVersion = this.getBaseMapper().selectOne(cond);
|
||||
if (Objects.isNull(tdQuestionVersion)){
|
||||
throw new BusinessException("题库版本异常");
|
||||
}
|
||||
|
||||
TdSysConfig tdSysConfig = configService.queryConfigByKey(Constants.REDIS_EXPIRE_TIME, Constants.DEFAULT_CARTYPE_ID);
|
||||
if (Objects.isNull(tdSysConfig)){
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("系统未知异常");
|
||||
}
|
||||
// 塞入redis中
|
||||
redisCache.setCacheObject(Constants.QUESTION_VERSOPN_PREFIX + carTypeId,tdQuestionVersion.getVersionId(),Long.parseLong(tdSysConfig.getConfigValue()));
|
||||
return tdQuestionVersion.getVersionId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addVersion(TdQuestionVersion versionDto) {
|
||||
|
||||
LambdaQueryWrapper<TdQuestionVersion> cond = new LambdaQueryWrapper<TdQuestionVersion>()
|
||||
.eq(TdQuestionVersion::getCarTypeId,versionDto.getCarTypeId())
|
||||
.eq(TdQuestionVersion::getIsActive,Constants.IS_ACTIVE_TRUE);
|
||||
|
||||
TdQuestionVersion tdQuestionVersion = this.getBaseMapper().selectOne(cond);
|
||||
|
||||
if (Objects.nonNull(tdQuestionVersion)){
|
||||
tdQuestionVersion.setIsActive(Constants.IS_ACTIVE_FALSE);
|
||||
this.getBaseMapper().updateById(tdQuestionVersion);
|
||||
}
|
||||
TdQuestionVersion newVersion = new TdQuestionVersion();
|
||||
BeanUtils.copyProperties(versionDto,newVersion);
|
||||
newVersion.setCreateTime(LocalDateTime.now())
|
||||
.setIsActive(Constants.IS_ACTIVE_TRUE);
|
||||
this.baseMapper.insert(newVersion);
|
||||
//删除原redis
|
||||
redisCache.deleteObject(Constants.QUESTION_VERSOPN_PREFIX + versionDto.getCarTypeId());
|
||||
redisCache.deleteObjectLike(Constants.SPECIAL_NUM_PREFIX + versionDto.getCarTypeId() );
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,22 @@
|
|||
package com.jwl.driver.server.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.entity.TdSysConfig;
|
||||
import com.jwl.driver.server.entity.TdSysConfigList;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.mapper.TdSysConfigListMapper;
|
||||
import com.jwl.driver.server.redis.RedisCache;
|
||||
import com.jwl.driver.server.service.ITdSysConfigListService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jwl.driver.server.service.ITdSysConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -24,17 +28,44 @@ import java.util.stream.Collectors;
|
|||
* @since 2023-08-10
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TdSysConfigListServiceImpl extends ServiceImpl<TdSysConfigListMapper, TdSysConfigList> implements ITdSysConfigListService {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private ITdSysConfigService configService;
|
||||
|
||||
@Override
|
||||
public List<TdSysConfigList> querySysConfigList(String configKey, Integer carTypeId) {
|
||||
|
||||
List<TdSysConfigList> configLists = redisCache.getCacheObject(Constants.CONFIG_LIST_PREFIX + configKey + "_" + carTypeId);
|
||||
if (CollectionUtil.isNotEmpty(configLists)) {
|
||||
return configLists;
|
||||
}
|
||||
//redis中没有则查询数据库
|
||||
LambdaQueryWrapper<TdSysConfigList> queryWrapper = new LambdaQueryWrapper<TdSysConfigList>()
|
||||
.eq(TdSysConfigList::getCarTypeId, carTypeId)
|
||||
.eq(TdSysConfigList::getConfigKey, configKey)
|
||||
.eq(TdSysConfigList::getIsActive, Constants.IS_ACTIVE_TRUE)
|
||||
.orderByAsc(TdSysConfigList::getShowOrder);
|
||||
configLists = this.getBaseMapper().selectList(queryWrapper);
|
||||
|
||||
return this.getBaseMapper().selectList(queryWrapper);
|
||||
if (CollectionUtil.isEmpty(configLists)) {
|
||||
return configLists;
|
||||
}
|
||||
|
||||
//获取redis缓存时间
|
||||
TdSysConfig tdSysConfig = configService.queryConfigByKey(Constants.REDIS_EXPIRE_TIME, Constants.DEFAULT_CARTYPE_ID);
|
||||
if (Objects.isNull(tdSysConfig)) {
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("系统异常");
|
||||
}
|
||||
// 塞入redis中
|
||||
redisCache.setCacheObject(Constants.CONFIG_LIST_PREFIX + configKey + "_" + carTypeId, configLists, Long.parseLong(tdSysConfig.getConfigValue()));
|
||||
|
||||
return configLists;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
package com.jwl.driver.server.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.entity.TdSysConfig;
|
||||
import com.jwl.driver.server.entity.TdSysConfigList;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.mapper.TdSysConfigMapper;
|
||||
import com.jwl.driver.server.redis.RedisCache;
|
||||
import com.jwl.driver.server.service.ITdSysConfigService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -30,24 +32,50 @@ import java.util.stream.Collectors;
|
|||
@Slf4j
|
||||
public class TdSysConfigServiceImpl extends ServiceImpl<TdSysConfigMapper, TdSysConfig> implements ITdSysConfigService {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Override
|
||||
public TdSysConfig queryConfigByKey(String configKey, Integer carTypeId) {
|
||||
log.info("获取系统配置参数,configKey:{}", configKey);
|
||||
|
||||
TdSysConfig config = redisCache.getCacheObject(Constants.CONFIG_PREFIX + configKey + "_" + carTypeId);
|
||||
if (Objects.nonNull(config)){
|
||||
return config;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TdSysConfig> queryWrapper = new QueryWrapper<TdSysConfig>().lambda()
|
||||
.eq(TdSysConfig::getCarTypeId,carTypeId)
|
||||
.eq(TdSysConfig::getConfigKey, configKey)
|
||||
.eq(TdSysConfig::getIsActive, Constants.IS_ACTIVE_TRUE);
|
||||
return getOne(queryWrapper);
|
||||
config = getOne(queryWrapper);
|
||||
|
||||
if (Objects.isNull(config)){
|
||||
return config;
|
||||
}
|
||||
|
||||
//获取redis缓存时间
|
||||
TdSysConfig tdSysConfig = null;
|
||||
if (StrUtil.equals(configKey,Constants.REDIS_EXPIRE_TIME)){
|
||||
tdSysConfig = config;
|
||||
}else {
|
||||
tdSysConfig = queryConfigByKey(Constants.REDIS_EXPIRE_TIME, Constants.DEFAULT_CARTYPE_ID);
|
||||
}
|
||||
|
||||
if (Objects.isNull(tdSysConfig)) {
|
||||
log.info("config is not exist");
|
||||
throw new BusinessException("系统异常");
|
||||
}
|
||||
// 塞入redis中
|
||||
redisCache.setCacheObject(Constants.CONFIG_PREFIX + configKey + "_" + carTypeId, config, Long.parseLong(tdSysConfig.getConfigValue()));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryConfigValueByKey(String configKey, Integer carTypeId) {
|
||||
log.info("获取系统配置参数,configKey:{}", configKey);
|
||||
LambdaQueryWrapper<TdSysConfig> queryWrapper = new QueryWrapper<TdSysConfig>().lambda()
|
||||
.eq(TdSysConfig::getCarTypeId,carTypeId)
|
||||
.eq(TdSysConfig::getConfigKey, configKey)
|
||||
.eq(TdSysConfig::getIsActive, Constants.IS_ACTIVE_TRUE);
|
||||
TdSysConfig config = getOne(queryWrapper);
|
||||
TdSysConfig config = queryConfigByKey(configKey,carTypeId);
|
||||
if(null == config) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -188,5 +188,93 @@
|
|||
and IS_ACTIVE = '0'
|
||||
</select>
|
||||
|
||||
<select id="queryQuestionId" resultType="java.lang.Long">
|
||||
select
|
||||
tq.QUESTION_ID
|
||||
from td_question tq
|
||||
left join td_point_question tpq on tq.QUESTION_ID = tpq.QUESTION_ID and tq.CAR_TYPE_ID = tpq.CAR_TYPE_ID and
|
||||
tpq.IS_ACTIVE = '0'
|
||||
<where>
|
||||
tq.IS_ACTIVE = '0'
|
||||
<if test="queryDto.questionId !=null">
|
||||
and tq.QUESTION_ID = #{queryDto.questionId}
|
||||
</if>
|
||||
<if test="queryDto.questionIdList !=null and queryDto.questionIdList.size() > 0">
|
||||
and tq.QUESTION_ID in
|
||||
<foreach collection="queryDto.questionIdList" open="(" item="item" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="queryDto.chapter !=null and queryDto.chapter !=''">
|
||||
and tq.CHAPTER = #{queryDto.chapter}
|
||||
</if>
|
||||
<if test="queryDto.question !=null and queryDto.question !=''">
|
||||
and tq.QUESTION like concat('%' , #{queryDto.question} , '%')
|
||||
</if>
|
||||
<if test="queryDto.subject !=null and queryDto.subject !=''">
|
||||
and tq.SUBJECT = #{queryDto.subject}
|
||||
</if>
|
||||
<if test="queryDto.carTypeId !=null">
|
||||
and tq.CAR_TYPE_ID = #{queryDto.carTypeId}
|
||||
</if>
|
||||
<if test="queryDto.type !=null and queryDto.type != ''">
|
||||
and tq.TYPE = #{queryDto.type}
|
||||
</if>
|
||||
<if test="queryDto.isError !=null">
|
||||
and tq.IS_ERROR = #{queryDto.isError}
|
||||
</if>
|
||||
<if test="queryDto.isNew !=null">
|
||||
and tq.IS_NEW = #{queryDto.isNew}
|
||||
</if>
|
||||
<if test="queryDto.isImage !=null">
|
||||
and tq.IMAGE_URL is not null
|
||||
</if>
|
||||
<if test="queryDto.examKey !=null and queryDto.examKey != ''">
|
||||
and find_in_set(#{queryDto.examKey},tq.EXAM_KEYS)
|
||||
</if>
|
||||
<if test="queryDto.isVip !=null">
|
||||
and tq.IS_VIP = #{queryDto.isVip}
|
||||
</if>
|
||||
<if test="queryDto.isVip2 !=null">
|
||||
and tq.IS_VIP2 = #{queryDto.isVip2}
|
||||
</if>
|
||||
<if test="queryDto.isExam1 !=null">
|
||||
and tq.IS_EXAM1 = #{queryDto.isExam1}
|
||||
</if>
|
||||
<if test="queryDto.isExam2 !=null">
|
||||
and tq.IS_EXAM2 = #{queryDto.isExam2}
|
||||
</if>
|
||||
<if test="queryDto.cid !=null and queryDto.cid !=''">
|
||||
and find_in_set(#{queryDto.cid},tq.CIDS)
|
||||
</if>
|
||||
<if test="queryDto.category !=null and queryDto.category !=''">
|
||||
and find_in_set(#{queryDto.category},tq.CATEGORY)
|
||||
</if>
|
||||
<if test="queryDto.point !=null and queryDto.point !=''">
|
||||
and tpq.POINT = #{queryDto.point}
|
||||
</if>
|
||||
</where>
|
||||
group by tq.QUESTION_ID
|
||||
order by tq.SHOW_ORDER asc
|
||||
</select>
|
||||
|
||||
<select id="queryQuestionIdByRandom" resultType="java.lang.Long">
|
||||
select
|
||||
tq.QUESTION_ID
|
||||
from td_question tq
|
||||
<where>
|
||||
tq.IS_ACTIVE = '0'
|
||||
<if test="queryDto.subject !=null and queryDto.subject !=''">
|
||||
and tq.SUBJECT = #{queryDto.subject}
|
||||
</if>
|
||||
<if test="queryDto.carTypeId !=null">
|
||||
and tq.CAR_TYPE_ID = #{queryDto.carTypeId}
|
||||
</if>
|
||||
<if test="queryDto.type !=null">
|
||||
and tq.TYPE = #{queryDto.type}
|
||||
</if>
|
||||
</where>
|
||||
order by rand() limit ${queryDto.num};
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jwl.driver.server.mapper.TdQuestionVersionMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue