lisy
2023-08-09 525e21bf383c9cb4bfe18c72ebcb4fd6ef74db7c
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.dsh.course.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.entity.CoursePackagePaymentConfig;
import com.dsh.course.entity.TCoursePackage;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.entity.TCoursePackageType;
import com.dsh.course.feignclient.model.StoreOfCourseVo;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.feignclient.other.model.Store;
import com.dsh.course.model.BaseVo;
import com.dsh.course.model.QueryCoursePackageLists;
import com.dsh.course.model.vo.response.Details;
import com.dsh.course.model.vo.response.ExchangeCoursePackageResponse;
import com.dsh.course.service.ICoursePackagePaymentConfigService;
import com.dsh.course.service.TCoursePackageDiscountService;
import com.dsh.course.service.TCoursePackagePaymentService;
import com.dsh.course.service.TCoursePackageService;
import com.dsh.course.util.PageFactory;
import com.dsh.course.util.ResultUtil;
import com.dsh.course.util.TokenUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
 
/**
 * @author zhibing.pu
 * @date 2023/7/5 9:58
 */
@RestController
@RequestMapping("")
public class CoursePackageController {
 
    @Autowired
    private TCoursePackageService coursePackageService;
 
 
    @Autowired
    private TCoursePackageDiscountService tcpdService;
 
    @Resource
    private StoreClient storeClient;
 
    @Resource
    private TCoursePackagePaymentService tcppmenService;
 
    @Resource
    private ICoursePackagePaymentConfigService icppconfigService;
 
 
    @Autowired
    private TokenUtil tokenUtil;
 
    /**
     * 根据id获取课包
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/queryCoursePackageById")
    public TCoursePackage queryCoursePackageById(@RequestBody Integer id){
        try {
            TCoursePackage coursePackage = coursePackageService.getById(id);
            return coursePackage;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
 
    /**
     * 本周福利列表
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/weekLimitedBenefit")
    @ApiOperation(value = "本周福利-限时折扣列表", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "discountType",value = "默认显示 限时折扣 (1限时折扣 2赠送课时)",dataType = "int"),
            @ApiImplicitParam(name = "lon",value = "经度",dataType = "String"),
            @ApiImplicitParam(name = "lat",value = "纬度",dataType = "String"),
    })
    public ResultUtil<List<Details>> thisWeeksBenefitList(Integer discountType, String lon, String lat){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tcpdService.getWeeksBenefitCourse(appUserId,discountType,lon,lat));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 折扣课包详情
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/discountCourseDatas")
    @ApiOperation(value = "本周福利-折扣课包详情", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "coursePackageDiscountId",value = "限时折扣配置id/赠送课时配置id",dataType = "int"),
            @ApiImplicitParam(name = "lon",value = "经度",dataType = "String"),
            @ApiImplicitParam(name = "lat",value = "纬度",dataType = "String"),
    })
    public ResultUtil<ExchangeCoursePackageResponse> discountCourseDatas(Integer coursePackageDiscountId,String lon,String lat){
        try {
            return ResultUtil.success(tcpdService.getWeekFreeCourseDetails(coursePackageDiscountId,lat,lon));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/coursePack/courseList")
    public List<StoreOfCourseVo> getStoreOfCourseList(@RequestBody Integer storeId){
        List<StoreOfCourseVo> courseVoList = new ArrayList<>();
        Store store = storeClient.queryStoreById(storeId);
        List<TCoursePackage> list = coursePackageService.list(new QueryWrapper<TCoursePackage>()
                .eq("storeId", storeId)
                .eq("auditStatus",2)
                .eq("state",1));
        if (list.size() >  0){
            for (TCoursePackage coursePackage : list) {
                int count = tcppmenService.count(new QueryWrapper<TCoursePackagePayment>()
                        .eq("coursePackageId",coursePackage.getId()));
                StoreOfCourseVo courseVo = new StoreOfCourseVo();
                courseVo.setCourseId(coursePackage.getId());
                courseVo.setName(coursePackage.getName()+"(" + store.getName() + ")");
                courseVo.setClassStartTime(coursePackage.getClassStartTime() +"-"+ coursePackage.getClassEndTime());
                courseVo.setApplicantsNumber(count);
                List<CoursePackagePaymentConfig> list1 = icppconfigService.list(new QueryWrapper<CoursePackagePaymentConfig>()
                        .eq("coursePackageId",coursePackage.getId()));
//                取价格最低的课时
                CoursePackagePaymentConfig minConfig = list1.stream()
                        .min(Comparator.comparingDouble(CoursePackagePaymentConfig::getCashPayment))
                        .orElse(null);
                if (minConfig != null){
                    courseVo.setClassHours(minConfig.getClassHours());
                    courseVo.setOriginalPrice(minConfig.getCashPayment());
                }
 
                courseVoList.add(courseVo);
            }
        }
        return courseVoList;
    }
 
    /**
     * 根据id获取课包
     * @param coursePackConfigId
     * @return
     */
    @ResponseBody
    @PostMapping("/base/coursePackage/queryConfigCoursePackData")
    public CoursePackagePaymentConfig queryConfigCoursePackData(@RequestBody Integer coursePackConfigId){
        return icppconfigService.getById(coursePackConfigId);
    }
 
 
    /**
     * 获取课包管理列表数据
     * @param queryCoursePackageLists
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackage/queryCoursePackageLists")
    public Page<Map<String, Object>> queryCoursePackageLists(@RequestBody QueryCoursePackageLists queryCoursePackageLists){
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryCoursePackageLists.getLimit(), queryCoursePackageLists.getOffset(), queryCoursePackageLists.getSort(), queryCoursePackageLists.getOrder());
        Page<Map<String, Object>> mapPage = page.setRecords(coursePackageService.queryCoursePackageLists(page, queryCoursePackageLists));
        return mapPage;
    }
}