guohongjin
2024-05-01 1901fceb6ddaa56a57f3131191454554c3e77e68
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package cn.stylefeng.guns.modular.business.controller;
 
import cn.hutool.core.collection.CollUtil;
import cn.stylefeng.guns.modular.business.dto.MentalTestRecordPageDTO;
import cn.stylefeng.guns.modular.business.dto.OrderMentalTestDetailDTO;
import cn.stylefeng.guns.modular.business.dto.OrderMentalTestPageDTO;
import cn.stylefeng.guns.modular.business.dto.request.CreateOrderMentalTestRequest;
import cn.stylefeng.guns.modular.business.entity.OrderConsultOne;
import cn.stylefeng.guns.modular.business.entity.OrderMentalTest;
import cn.stylefeng.guns.modular.business.service.IMentalTestRecordService;
import cn.stylefeng.guns.modular.business.service.IOrderConsultOneService;
import cn.stylefeng.guns.modular.business.service.IOrderMentalTestService;
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.OrderStatusFlagEnum;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
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.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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 心理测试订单管理类
 * @author guo
 */
@RestController
@Api(tags = "心理测试订单")
@ApiResource(name = "心理测试订单", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping("/business")
public class OrderMentalTestController  {
 
    @Resource
    private IOrderMentalTestService orderMentalTestService;
 
    @Resource
    private IOrderConsultOneService orderConsultOneService;
 
    @Resource
    private IMentalTestRecordService mentalTestRecordService;
 
    /**
     * 添加心理测试订单
     */
    @ApiOperation("添加心理测试订单")
    @PostResource(name = "添加心理测试订单", path = "/orderMentalTest/add")
    @BusinessLog
    public ResponseData<?> add(@RequestBody CreateOrderMentalTestRequest req) {
        OrderMentalTest o = this.orderMentalTestService.createOrderMentalTest(req.getUserId(), req.getTopicId(), false, true);
        return new SuccessResponseData<>(o);
    }
 
    /**
     * 获取心理测试订单详情
     */
    @ApiOperation("获取心理测试订单详情")
    @GetResource(name = "获取心理测试订单详情", path = "/orderMentalTest/detail/{id}", requiredPermission = false)
    public ResponseData<OrderMentalTestDetailDTO> detail(@PathVariable("id") Long id) {
        // 心理测试订单
        OrderMentalTestDetailDTO mto = this.orderMentalTestService.getInfoById(id);
 
        // 是否支付1v1咨询订单
        mto.setIsPayOrderConsultOne(orderConsultOneService.getIsPayOrderConsultOne(null, mto.getOrderNo()));
        return new SuccessResponseData(mto);
    }
 
    /**
     * 获取心理测试订单列表(分页)
     */
    @ApiOperation("心理测试订单(分页)")
    @GetResource(name = "获取心理测试订单(分页)", path = "/orderMentalTestPage", 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 = "nickName", value = "测试用户", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "telephone", value = "联系电话", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "testType", value = "测试类型:0免费,1付费", dataTypeClass = Integer.class, paramType = "query"),
    })
    public ResponseData<PageResult<OrderMentalTestPageDTO>> orderMentalTestPage(Integer pageNo, Integer pageSize, String title, String nickName, String telephone, Integer testType) {
        Page<OrderMentalTestPageDTO> page = this.orderMentalTestService.getPage(PageFactory.page(pageNo, pageSize), title, nickName, telephone, testType, OrderStatusFlagEnum.PAY_SUCCESS.getCode(), 1);
 
        // 查询支付成功的1v1咨询订单
        List<OrderConsultOne> payOrderConsultOneList = orderConsultOneService.list(
                Wrappers.<OrderConsultOne>lambdaQuery()
                        .select(OrderConsultOne::getMentalTestOrderNo)
                        .eq(OrderConsultOne::getStatusFlag, OrderStatusFlagEnum.PAY_SUCCESS.getCode())
                        .in(CollUtil.isNotEmpty(page.getRecords()), OrderConsultOne::getMentalTestOrderNo, page.getRecords().stream().map(OrderMentalTestPageDTO::getOrderNo).collect(Collectors.toList()))
        );
 
        page.getRecords().forEach(mto ->
                mto.setIsPayOrderConsultOne(payOrderConsultOneList.stream().filter(po -> po.getMentalTestOrderNo().equals(mto.getOrderNo())).findFirst().isPresent())
        );
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
    //@ApiOperation("心理测试记录(分页)")
    @GetResource(name = "心理测试记录(分页)", path = "/mentalTestRecordPage")
    @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 = "nickName", value = "测试用户", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "telephone", value = "联系电话", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "testType", value = "测试类型:0免费,1付费", dataTypeClass = Integer.class, paramType = "query"),
    })
    public ResponseData<PageResult<MentalTestRecordPageDTO>> mentalTestRecordPage(Integer pageNo, Integer pageSize, String title, String nickName, String telephone, Integer testType) {
        Page<MentalTestRecordPageDTO> page = this.mentalTestRecordService.getPage(PageFactory.page(pageNo, pageSize), title, nickName, telephone, testType);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
}