package cn.stylefeng.guns.modular.business.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.ListUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.stylefeng.guns.modular.business.dto.BaseIdNameDTO;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestQuestionOptionDTO;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestTopicDTO;
|
import cn.stylefeng.guns.modular.business.dto.request.MentalTestTopicAddUpdateRequest;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestClass;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestResultSet;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestTopic;
|
import cn.stylefeng.guns.modular.business.service.IMentalTestClassService;
|
import cn.stylefeng.guns.modular.business.service.IMentalTestResultSetService;
|
import cn.stylefeng.guns.modular.business.service.IMentalTestTopicService;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
|
import cn.stylefeng.roses.kernel.rule.enums.DeleteEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* 心理测试题库管理类
|
*
|
* @author guo
|
*/
|
@RestController
|
@Api(tags = "心理测试题库管理类")
|
@ApiResource(name = "心理测试题库管理类", resBizType = ResBizTypeEnum.BUSINESS)
|
@RequestMapping("/business")
|
public class MentalTestTopicController {
|
|
@Resource
|
private IMentalTestClassService mentalTestClassService;
|
|
@Resource
|
private IMentalTestTopicService mentalTestTopicService;
|
|
@Resource
|
private IMentalTestResultSetService mentalTestResultSetService;
|
|
@ApiOperation("题库类型(选择)列表")
|
@GetResource(name = "题库类型(选择)列表", path = "/classSelectList")
|
public ResponseData<List<MentalTestClass>> classSelectList() {
|
List<MentalTestClass> list = mentalTestClassService.list(
|
Wrappers.<MentalTestClass>lambdaQuery()
|
.eq(MentalTestClass::getIsDelete, DeleteEnum.NOT_DELETE.getCode())
|
.eq(MentalTestClass::getStatusFlag, StatusEnum.ENABLE.getCode())
|
);
|
|
return new SuccessResponseData(list);
|
}
|
|
@ApiOperation("题库(选择)列表")
|
@GetResource(name = "题库(选择)列表", path = "/topicSelectList")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "title", value = "标题", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "testType", value = "测试类型:0免费,1付费", dataTypeClass = Integer.class),
|
})
|
public ResponseData<List<BaseIdNameDTO>> topicSelectList(String title, Integer testType) {
|
List<BaseIdNameDTO> list = mentalTestTopicService.list(
|
Wrappers.<MentalTestTopic>lambdaQuery()
|
.eq(MentalTestTopic::getIsDelete, DeleteEnum.NOT_DELETE.getCode())
|
.like(StrUtil.isNotBlank(title), MentalTestTopic::getTitle, title)
|
.eq(testType != null, MentalTestTopic::getTestType, testType)
|
).stream().map(
|
o -> BaseIdNameDTO.builder()
|
.id(o.getId())
|
.name(o.getTitle())
|
.build()
|
).collect(Collectors.toList());
|
|
return new SuccessResponseData(list);
|
}
|
|
/**
|
* 添加心理测试题库
|
*/
|
@ApiOperation("添加心理测试题库")
|
@PostResource(name = "添加心理测试题库", path = "/mentalTestTopic/add")
|
@BusinessLog
|
public ResponseData<?> add(@RequestBody MentalTestTopicAddUpdateRequest req) {
|
this.mentalTestTopicService.saveTopic(req);
|
return new SuccessResponseData<>();
|
}
|
|
/**
|
* 删除心理测试题库
|
*/
|
@ApiOperation("删除心理测试题库")
|
@PostResource(name = "删除心理测试题库", path = "/mentalTestTopic/delete")
|
@BusinessLog
|
public ResponseData<?> delete(@RequestParam String ids) {
|
if (StrUtil.isBlank(ids)) {
|
return new ErrorResponseData<>("500", "id不能为空");
|
}
|
LambdaUpdateWrapper<MentalTestTopic> lambdaUpdateWrapper = new LambdaUpdateWrapper<MentalTestTopic>().set(MentalTestTopic::getIsDelete, true);
|
lambdaUpdateWrapper.in(MentalTestTopic::getId, ListUtil.toList(ids.split(",")));
|
this.mentalTestTopicService.update(lambdaUpdateWrapper);
|
return new SuccessResponseData<>();
|
}
|
|
/**
|
* 修改心理测试题库
|
*/
|
@ApiOperation(value = "修改心理测试题库")
|
@PostResource(name = "修改心理测试题库", path = "/mentalTestTopic/edit")
|
@BusinessLog
|
public ResponseData<?> edit(@RequestBody MentalTestTopicAddUpdateRequest req) {
|
// 用户购买数量
|
MentalTestTopic mentalTestTopic = mentalTestTopicService.getById(req.getId());
|
if (mentalTestTopic != null && mentalTestTopic.getTestPeopleNum() > 0) {
|
// 仅修改标题
|
this.mentalTestTopicService.update(
|
Wrappers.<MentalTestTopic>lambdaUpdate()
|
.set(MentalTestTopic::getTitle, req.getTitle())
|
.eq(MentalTestTopic::getId, req.getId())
|
);
|
return new SuccessResponseData<>("用户已购买仅标题修改成功");
|
} else {
|
// 全量修改
|
this.mentalTestTopicService.editTopic(req);
|
return new SuccessResponseData<>();
|
}
|
}
|
|
/**
|
* 修改心理测试题库状态
|
*/
|
@ApiOperation("修改心理测试题库状态")
|
@PostResource(name = "修改心理测试题库状态", path = "/mentalTestTopic/updateStatus")
|
@BusinessLog
|
public ResponseData<?> updateStatus(String ids, Integer status) {
|
if (StrUtil.isBlank(ids)) {
|
return new ErrorResponseData<>("500", "id不能为空");
|
}
|
LambdaUpdateWrapper<MentalTestTopic> lambdaUpdateWrapper = new LambdaUpdateWrapper<MentalTestTopic>().set(MentalTestTopic::getStatusFlag, status);
|
lambdaUpdateWrapper.in(MentalTestTopic::getId, ListUtil.toList(ids.split(",")));
|
this.mentalTestTopicService.update(lambdaUpdateWrapper);
|
return new SuccessResponseData<>();
|
}
|
|
/**
|
* 获取心理测试题库详情
|
*/
|
@ApiOperation("获取心理测试题库详情")
|
@GetResource(name = "获取心理测试题库详情", path = "/mentalTestTopic/detail/{id}", requiredPermission = false)
|
public ResponseData<MentalTestTopicDTO> detail(@PathVariable("id") Long id) {
|
// 心理测试题库信息
|
MentalTestTopic mentalTestTopic = this.mentalTestTopicService.getById(id);
|
MentalTestTopicDTO dto = BeanUtil.toBean(mentalTestTopic, MentalTestTopicDTO.class);
|
|
// 获取心理测试问题、选项
|
List<MentalTestQuestionOptionDTO> questionList = mentalTestTopicService.getQuestionOptionByTopicId(Long.valueOf(id));
|
dto.setQuestionList(questionList);
|
|
// 获取结果区间配置
|
List<MentalTestResultSet> resultSetList = mentalTestResultSetService.list(
|
Wrappers.<MentalTestResultSet>lambdaQuery()
|
.eq(MentalTestResultSet::getTopicId, id)
|
);
|
dto.setResultSetList(resultSetList);
|
|
return new SuccessResponseData<>(dto);
|
}
|
|
/**
|
* 获取心理测试题库列表
|
*/
|
@ApiOperation("获取心理测试题库列表")
|
@GetResource(name = "获取心理测试题库列表", path = "/mentalTestTopic/list", requiredPermission = false)
|
public ResponseData<List<MentalTestTopic>> list(MentalTestTopic mentalTestTopic) {
|
LambdaQueryWrapper<MentalTestTopic> lambdaQueryWrapper = new LambdaQueryWrapper<MentalTestTopic>()
|
.eq(MentalTestTopic::getIsDelete, DeleteEnum.NOT_DELETE.getCode())
|
.eq(MentalTestTopic::getStatusFlag, mentalTestTopic.getStatusFlag() == null ? StatusEnum.ENABLE.getCode() : mentalTestTopic.getStatusFlag())
|
.eq(StrUtil.isNotBlank(mentalTestTopic.getTitle()), MentalTestTopic::getTitle, mentalTestTopic.getTitle())
|
.eq(mentalTestTopic.getTestType() != null, MentalTestTopic::getTestType, mentalTestTopic.getTestType())
|
.eq(mentalTestTopic.getConsultOne() != null, MentalTestTopic::getConsultOne, mentalTestTopic.getConsultOne())
|
.eq(mentalTestTopic.getResultCalculateMode() != null, MentalTestTopic::getResultCalculateMode, mentalTestTopic.getResultCalculateMode())
|
.orderByDesc(MentalTestTopic::getId);
|
List<MentalTestTopic> list = mentalTestTopicService.list(lambdaQueryWrapper);
|
return new SuccessResponseData<>(list.stream()
|
.filter(o -> {
|
boolean flag = true;
|
if (StrUtil.isNotBlank(mentalTestTopic.getClassId())) {
|
flag = false;
|
if (StrUtil.isNotBlank(o.getClassId())) {
|
String[] idArr = o.getClassId().split(",");
|
List<String> reqIdList = Arrays.stream(mentalTestTopic.getClassId().split(",")).collect(Collectors.toList());
|
flag = Stream.of(idArr).anyMatch(reqIdList::contains);
|
}
|
}
|
return flag;
|
})
|
.collect(Collectors.toList())
|
);
|
}
|
|
/**
|
* 获取心理测试题库列表(分页)
|
*/
|
@ApiOperation("获取心理测试题库列表(分页)")
|
@GetResource(name = "获取心理测试题库列表(分页)", path = "/mentalTestTopic/page", requiredPermission = false)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认20)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "title", value = "测试标题", dataTypeClass = String.class, paramType = "query"),
|
@ApiImplicitParam(name = "statusFlag", value = "状态:1正常,2下架", dataTypeClass = Integer.class, paramType = "query"),
|
})
|
public ResponseData<PageResult<MentalTestTopic>> page(Integer pageNo, Integer pageSize, String title, Integer statusFlag) {
|
LambdaQueryWrapper<MentalTestTopic> lambdaQueryWrapper = new LambdaQueryWrapper<MentalTestTopic>()
|
.eq(MentalTestTopic::getIsDelete, DeleteEnum.NOT_DELETE.getCode())
|
.like(StrUtil.isNotBlank(title), MentalTestTopic::getTitle, title)
|
.eq(statusFlag != null && statusFlag != -1, MentalTestTopic::getStatusFlag, statusFlag)
|
.orderByDesc(MentalTestTopic::getId);
|
Page<MentalTestTopic> page = this.mentalTestTopicService.page(PageFactory.page(pageNo, pageSize), lambdaQueryWrapper);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
}
|