package cn.stylefeng.rest.modular.user.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.util.ObjUtil;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestMyMentalAppointmentDTO;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestMyTestOrderDTO;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO;
|
import cn.stylefeng.guns.modular.business.dto.MentalTestTopicAndRecordDTO;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestRecord;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestResult;
|
import cn.stylefeng.guns.modular.business.entity.MentalTestTopic;
|
import cn.stylefeng.guns.modular.business.entity.OrderMentalTest;
|
import cn.stylefeng.guns.modular.business.service.*;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.rule.enums.MentalAppointmentStatusEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.OrderStatusFlagEnum;
|
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 com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
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.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
|
/**
|
* 主页接口-html富文本页面
|
*
|
* @author goupan
|
* @date 2024/01/02
|
*/
|
@RestController
|
@Api(tags = "心理测试接口")
|
@ApiResource(name = "心理测试接口")
|
@RequestMapping("/mentalTest")
|
public class MyMentalTestController {
|
|
@Resource
|
private IMentalTestRecordService mentalTestRecordService;
|
|
@Resource
|
private IMentalTestResultService mentalTestResultService;
|
|
@Resource
|
private IOrderMentalTestService orderMentalTestService;
|
|
@Resource
|
private IOrderConsultOneService orderConsultOneService;
|
|
@Resource
|
private IMentalTestTopicService mentalTestTopicService;
|
|
@Resource
|
private IMentalAppointmentService mentalAppointmentService;
|
|
@ApiOperation(value = "我的性格分析预约")
|
@GetResource(name = "我的性格分析预约", path = "/myMentalAppointment")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "consultantName",value = "咨询师名称")
|
})
|
public ResponseData<List<MentalTestMyMentalAppointmentDTO>> myMentalAppointment(String consultantName) {
|
// 获取当前登录用户信息
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
Long userId = loginUser.getUserId();
|
|
List<MentalTestMyMentalAppointmentDTO> list = mentalAppointmentService.myMentalAppointment(
|
userId,
|
consultantName,
|
Arrays.asList(
|
MentalAppointmentStatusEnum.WAIT_SERVICE.getCode(),
|
MentalAppointmentStatusEnum.IN_SERVICE.getCode(),
|
MentalAppointmentStatusEnum.DONE.getCode()
|
)
|
);
|
return new SuccessResponseData(list);
|
}
|
|
@ApiOperation(value = "我的测试")
|
@GetResource(name = "我的测试", path = "/myTestTopic")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "topicId",value = "题库ID")
|
})
|
public ResponseData<List<MentalTestMyTestTopicDTO>> myTestTopic(Long topicId) {
|
// 获取当前登录用户信息
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
Long userId = loginUser.getUserId();
|
|
// 查询测试记录
|
List<MentalTestMyTestTopicDTO> list = mentalTestRecordService.myTestTopic(userId, topicId);
|
if (CollUtil.isEmpty(list)) {
|
return new ErrorResponseData<>("无测试记录!");
|
}
|
|
List<Long> topicIdList = list.stream().map(o -> o.getTopicId()).collect(Collectors.toList());
|
List<MentalTestResult> mentalTestResultAll = mentalTestResultService.list(
|
Wrappers.<MentalTestResult>lambdaQuery()
|
.eq(MentalTestResult::getUserId, userId)
|
.in(MentalTestResult::getTopicId, topicIdList)
|
.groupBy(MentalTestResult::getTopicId)
|
);
|
List<OrderMentalTest> orderMentalTestAll = orderMentalTestService.list(
|
Wrappers.<OrderMentalTest>lambdaQuery()
|
.eq(OrderMentalTest::getUserId, userId)
|
.eq(OrderMentalTest::getStatusFlag, OrderStatusFlagEnum.PAY_SUCCESS.getCode())
|
.in(OrderMentalTest::getGoodsId, topicIdList)
|
.groupBy(OrderMentalTest::getGoodsId)
|
);
|
|
return new SuccessResponseData(list.stream().map(o -> {
|
// 是否后台创建
|
o.setIsBack(orderMentalTestAll.stream().filter(oo -> oo.getOrderNo().equals(o.getAnswerNo())).findFirst().map(OrderMentalTest::getIsBack).orElse(false));
|
|
// 是否测试
|
o.setTestFlag(mentalTestResultAll.stream().filter(oo -> oo.getTopicId().equals(o.getTopicId())).findFirst().isPresent());
|
|
// 是否购买
|
o.setPayFlag(orderMentalTestAll.stream().filter(oo -> oo.getGoodsId().equals(o.getTopicId())).findFirst().isPresent());
|
|
return o;
|
}).collect(Collectors.toList()));
|
}
|
|
@ApiOperation(value = "我的测试(订单)")
|
@GetResource(name = "我的测试(订单)", path = "/myTestOrder")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "topicId",value = "题库ID")
|
})
|
public ResponseData<List<MentalTestMyTestOrderDTO>> myTestOrder(Long topicId) {
|
// 获取当前登录用户信息
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
Long userId = loginUser.getUserId();
|
|
// 查询测试记录
|
List<MentalTestMyTestOrderDTO> list = mentalTestRecordService.myTestOrder(userId, topicId);
|
if (CollUtil.isEmpty(list)) {
|
return new ErrorResponseData<>("无测试订单!");
|
}
|
|
List<Long> topicIdList = list.stream().map(o -> o.getGoodsId()).collect(Collectors.toList());
|
List<OrderMentalTest> orderMentalTestAll = orderMentalTestService.list(
|
Wrappers.<OrderMentalTest>lambdaQuery()
|
.eq(OrderMentalTest::getUserId, userId)
|
.eq(OrderMentalTest::getStatusFlag, OrderStatusFlagEnum.PAY_SUCCESS.getCode())
|
.in(OrderMentalTest::getGoodsId, topicIdList)
|
.groupBy(OrderMentalTest::getGoodsId)
|
);
|
|
return new SuccessResponseData(list.stream().map(o -> {
|
// 是否购买
|
o.setPayFlag(orderMentalTestAll.stream().filter(oo -> oo.getGoodsId().equals(o.getGoodsId())).findFirst().isPresent());
|
return o;
|
}).collect(Collectors.toList()));
|
}
|
|
@ApiOperation(value = "获取心理测试结果")
|
@GetResource(name = "获取心理测试结果", path = "/mentalTestRecord/{id}")
|
public ResponseData<MentalTestTopicAndRecordDTO> mentalTestRecord(@PathVariable("id") Long id) {
|
MentalTestRecord mentalTestRecord = mentalTestRecordService.getById(id);
|
Assert.notNull(mentalTestRecord, "测试记录不存在!");
|
MentalTestTopicAndRecordDTO dto = new MentalTestTopicAndRecordDTO();
|
if (mentalTestRecord != null) {
|
MentalTestTopic topic = mentalTestTopicService.getById(mentalTestRecord.getTopicId());
|
if (topic != null) {
|
BeanUtil.copyProperties(topic, dto);
|
}
|
// 覆盖题库id
|
BeanUtil.copyProperties(mentalTestRecord, dto);
|
}
|
|
// 是否后台创建
|
OrderMentalTest orderMentalTest = orderMentalTestService.getOrderByNo(mentalTestRecord.getAnswerNo());
|
dto.setIsBack(Optional.ofNullable(orderMentalTest).map(OrderMentalTest::getIsBack).orElse(false));
|
|
// 是否支付1v1咨询订单
|
dto.setIsPayOrderConsultOne(orderConsultOneService.getIsPayOrderConsultOne(mentalTestRecord.getOrderConsultOneId(), null));
|
|
return new SuccessResponseData(dto);
|
}
|
|
@ApiOperation(value = "获取心理测试结果(订单)")
|
@GetResource(name = "获取心理测试结果(订单)", path = "/mentalTestRecordByOrder")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "orderNo",value = "订单编号"),
|
@ApiImplicitParam(name = "topicId",value = "题库ID"),
|
})
|
public ResponseData<MentalTestTopicAndRecordDTO> mentalTestRecordByOrder(String orderNo, Long topicId) {
|
MentalTestRecord mentalTestRecord = mentalTestRecordService.getOne(
|
Wrappers.<MentalTestRecord>lambdaQuery()
|
.eq(ObjUtil.isNotEmpty(orderNo), MentalTestRecord::getAnswerNo, orderNo)
|
.eq(ObjUtil.isNotEmpty(topicId), MentalTestRecord::getTopicId, topicId)
|
.orderByDesc(MentalTestRecord::getCreateTime)
|
.last("LIMIT 1")
|
);
|
Assert.notNull(mentalTestRecord, "没有该记录!");
|
|
// 心理题库信息
|
MentalTestTopicAndRecordDTO dto = new MentalTestTopicAndRecordDTO();
|
if (mentalTestRecord != null) {
|
MentalTestTopic topic = mentalTestTopicService.getById(mentalTestRecord.getTopicId());
|
if (topic != null) {
|
BeanUtil.copyProperties(topic, dto);
|
}
|
BeanUtil.copyProperties(mentalTestRecord, dto);
|
|
// 是否后台创建
|
OrderMentalTest orderMentalTest = orderMentalTestService.getOrderByNo(mentalTestRecord.getAnswerNo());
|
dto.setIsBack(Optional.ofNullable(orderMentalTest).map(OrderMentalTest::getIsBack).orElse(false));
|
|
// 是否支付1v1咨询订单
|
dto.setIsPayOrderConsultOne(orderConsultOneService.getIsPayOrderConsultOne(mentalTestRecord.getOrderConsultOneId(), null));
|
}
|
return new SuccessResponseData(dto);
|
}
|
|
}
|