44323
2023-11-27 aa925d851857f50eff0556411366690d9a78a0e5
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
package com.dsh.course.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.CancelledClasses;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.feignclient.model.GetStuSessionList;
import com.dsh.course.feignclient.model.PurchaseRecordVo;
import com.dsh.course.service.CancelledClassesService;
import com.dsh.course.service.CourseCounsumService;
import com.dsh.course.service.TCoursePackagePaymentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Api
@CrossOrigin
@RestController
@RequestMapping("")
public class CancelSourceController {
 
    @Autowired
    private CancelledClassesService caceService;
 
 
    @Autowired
    private TCoursePackagePaymentService tcppService;
 
    private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
 
 
    /**
     * 获取课包对应的消费记录
     *
     * @param sessionList
     * @return
     */
    @PostMapping("/base/cancelSource/cancelList")
    public List<PurchaseRecordVo> getCancelCourseList(@RequestBody GetStuSessionList sessionList) {
        List<PurchaseRecordVo> purchaseRecordVos = new ArrayList<>();
        List<TCoursePackagePayment> tCoursePackagePayments = tcppService.list(new QueryWrapper<TCoursePackagePayment>()
                .between("insertTime", sessionList.getStartTime(), sessionList.getEndTime())
                .eq("appUserId", sessionList.getAppUserId())
                .eq("studentId", sessionList.getStuId()));
        if (tCoursePackagePayments.size() > 0) {
            List<Long> coursePackageIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getId).collect(Collectors.toList());
 
            List<CancelledClasses> list = caceService.list(new QueryWrapper<CancelledClasses>()
                    .in("coursePackageId", coursePackageIds)
                    .between("insertTime", sessionList.getStartTime(), sessionList.getEndTime()));
            if (list.size() > 0) {
                list.forEach(canse -> {
                    PurchaseRecordVo purchaseRecordVo = new PurchaseRecordVo();
                    purchaseRecordVo.setPurchaseTime(format.format(canse.getInsertTime()));
                    purchaseRecordVo.setPurchaseType("");
                    purchaseRecordVo.setPurchaseAmount("-" + canse.getCancelledClassesNumber());
                    purchaseRecordVos.add(purchaseRecordVo);
                });
            }
        }
        return purchaseRecordVos;
    }
 
 
}