From 0fe1f723f6fb85f25c945bd88c774f4a3142a818 Mon Sep 17 00:00:00 2001
From: lisy <linlangsur163@163.com>
Date: 星期四, 03 八月 2023 11:52:19 +0800
Subject: [PATCH] 修复app端使用福利的课时详情接口;新增app端的编辑学员、设为默认接口

---
 cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java |  321 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 252 insertions(+), 69 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
index 1b0d7a6..5b8cfea 100644
--- a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
+++ b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -2,29 +2,24 @@
 
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.dsh.course.entity.TCoursePackage;
-import com.dsh.course.entity.TCoursePackageDiscount;
-import com.dsh.course.entity.TCoursePackagePayment;
-import com.dsh.course.entity.TCoursePackageType;
 import com.dsh.course.entity.*;
+import com.dsh.course.feignclient.account.AppUserClient;
 import com.dsh.course.feignclient.account.StudentClient;
+import com.dsh.course.feignclient.account.model.AppUser;
+import com.dsh.course.feignclient.account.model.Student;
 import com.dsh.course.feignclient.model.*;
+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.dto.DiscountJsonDto;
 import com.dsh.course.model.vo.CourseDetailRequest;
 import com.dsh.course.model.vo.RegisterCourseVo;
-import com.dsh.course.model.vo.request.ClasspaymentRequest;
-import com.dsh.course.model.vo.request.CourseOfAfterRequest;
-import com.dsh.course.model.vo.request.CourseWithDetailsRequest;
-import com.dsh.course.model.vo.request.UpdateCourseVideoStatusRequest;
+import com.dsh.course.model.vo.request.*;
 import com.dsh.course.model.vo.response.AppUserVideoResponse;
 import com.dsh.course.model.vo.response.CourseDetailsResponse;
 import com.dsh.course.model.vo.response.CourseOfVideoResponse;
 import com.dsh.course.service.*;
-import com.dsh.course.util.DateUtil;
-import com.dsh.course.util.ResultUtil;
-import com.dsh.course.util.StrUtils;
-import com.dsh.course.util.TokenUtil;
+import com.dsh.course.util.*;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
@@ -37,11 +32,17 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 @Api
@@ -62,14 +63,18 @@
     @Autowired
     private TCoursePackageDiscountService tcpdService;
 
-    @Autowired
-    private PostCourseVideoService pcvService;
 
     @Autowired
-    private CoursePackageStudentService cpsService;
+    private ICoursePackagePaymentConfigService icppcService;
 
     @Autowired
-    private CancelledClassesService cacService;
+    private UserVideoDetailsService uvdsService;
+
+    @Autowired
+    private TCourseService tcService;
+
+    @Resource
+    private StudentClient studentClient;
 
     @Autowired
     private TCoursePackageTypeService coursePackageTypeService;
@@ -80,6 +85,14 @@
     @Autowired
     private CancelledClassesService cancelledClassesService;
 
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+    @Resource
+    private AppUserClient auClitn;
+
+    @Resource
+    private StoreClient sreClient;
+
     private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
 
     /**
@@ -87,11 +100,13 @@
      * @param stuId 学员id
      * @return  课包列表
      */
+    @ResponseBody
     @PostMapping("/base/coursePack/queryPayment")
-    public List<StuCourseResp> getStuCoursePackagePayment(@RequestParam("stuId") Integer stuId,@RequestParam("appUserId") Integer appUserId){
+    public List<StuCourseResp> getStuCoursePackagePayment(@RequestBody Integer stuId){
         List<StuCourseResp> resps = new ArrayList<>();
+        Student student = studentClient.queryStudentById(stuId);
         List<TCoursePackagePayment> byUserId = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .eq("appUserId",appUserId)
+                .eq("appUserId",student.getAppUserId())
                 .eq("studentId",stuId));
 
         if (byUserId.size() > 0 ){
@@ -103,6 +118,8 @@
                 resp.setTotalCourseNums(tCoursePackagePayment.getTotalClassHours());
                 resp.setResidueNums(tCoursePackagePayment.getLaveClassHours());
                 resp.setDeductionNums(tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours());
+                String afterDayDate = DateUtil.getAfterDayDate2(tCoursePackage.getInsertTime(),tCoursePackage.getValidDays() + "");
+                resp.setPeriodOfValidity(afterDayDate);
                 resps.add(resp);
             }
         }
@@ -113,21 +130,52 @@
      *
      * 获取发布的 课包列表
      */
+    @ResponseBody
     @PostMapping("/base/coursePack/storeOfCourse")
-    public List<CourseOfStoreVo> getStuCourseWithStores(){
-        List<CourseOfStoreVo> courseOfStoreVos = tcpService.queryStoreOfCourse();
-        if (courseOfStoreVos.size() > 0){
-            for (CourseOfStoreVo courseOfStoreVo : courseOfStoreVos) {
-                String[] split = courseOfStoreVo.getClassWeeks().split(";");
-                List<Integer> integers = new ArrayList<>();
-                for (String s : split) {
-                    int num = Integer.parseInt(s);
-                    integers.add(num);
+    public List<CourseOfStoreVo> getStuCourseWithStores(@RequestBody WeeksOfCourseRest courseRest){
+        List<CourseOfStoreVo> course = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            Date parse = simpleDateFormat.parse(courseRest.getTime());
+            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+                    .eq("appUserId",courseRest.getAppUserId() )
+                    .eq("studentId",courseRest.getStuId())
+                    .eq("payStatus",2)
+                    .eq("status",1)
+                    .eq("state",1)
+                    .groupBy("coursePackageId"));
+            if (list.size() >  0){
+                for (TCoursePackagePayment tCoursePackagePayment : list) {
+                    TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
+                    CoursePackagePaymentConfig paymentConfig = icppcService.getOne(new QueryWrapper<CoursePackagePaymentConfig>()
+                            .eq("coursePackageId",tCoursePackage.getId() )
+                            .eq("classHours",tCoursePackagePayment.getClassHours()));
+//                    获取课程有效结束时间,判断 查询的日期parse 是否在有效期范围内
+                    Date expirationDate = DateTimeHelper.getExpirationDate(tCoursePackagePayment.getInsertTime(),tCoursePackage.getValidDays());
+                    System.out.println(expirationDate.after(parse));
+                    String classWeeks = tCoursePackage.getClassWeeks();
+                    System.out.println(StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse)));
+                    if (expirationDate.after(parse) && StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))){
+                        CourseOfStoreVo storeVo = new CourseOfStoreVo();
+                        storeVo.setCourseId(tCoursePackage.getId());
+                        storeVo.setCourseName(tCoursePackage.getName());
+                        storeVo.setClassStartTime(tCoursePackage.getClassStartTime());
+                        storeVo.setClassEndTime(tCoursePackage.getClassEndTime());
+                        storeVo.setStoreId(tCoursePackage.getStoreId());
+                        Store store = sreClient.queryStoreById(tCoursePackage.getStoreId());
+                        storeVo.setStoreAddress(store.getAddress());
+                        storeVo.setLat(store.getLat());
+                        storeVo.setLon(store.getLon());
+                        storeVo.setCoursePrice(ToolUtil.isEmpty(paymentConfig.getCashPayment()) ? (double) paymentConfig.getPlayPaiCoin():paymentConfig.getCashPayment());
+                        course.add(storeVo);
+                    }
                 }
-                courseOfStoreVo.setClassWeekList(integers);
             }
+            System.out.println(course);
+            return course;
+        } catch (ParseException e) {
+            return null;
         }
-        return tcpService.queryStoreOfCourse();
     }
 
 
@@ -159,13 +207,13 @@
     }
 
     @PostMapping("/base/coursePack/paymentCourse")
-    public List<PurchaseRecordVo> queryCourseDetails(@RequestParam("startTime") Date startTime, @RequestParam("endTime") Date  endTime,@RequestParam("stuId") Integer stuId, @RequestParam("appUserId") Integer appUserId) {
+    public List<PurchaseRecordVo> queryCourseDetails(@RequestBody GetStuSessionList sessionList) {
         List<PurchaseRecordVo> purchaseRecordVos = new ArrayList<>();
 
         List<TCoursePackagePayment> coursePackage = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .between("insertTime", startTime,endTime)
-                .eq("appUserId",appUserId)
-                .eq("studentId",stuId));
+                .between("insertTime", sessionList.getStartTime(),sessionList.getEndTime())
+                .eq("appUserId",sessionList.getAppUserId())
+                .eq("studentId",sessionList.getStuId()));
         if (coursePackage.size() > 0 ){
             coursePackage.forEach( cspackage -> {
                 PurchaseRecordVo recordVo = new PurchaseRecordVo();
@@ -233,33 +281,9 @@
             if (integers.size() > 0){
                 StringBuilder courWeeks = new StringBuilder("每");
                 for (Integer integer : integers) {
-                    switch (integer){
-                        case 1:
-                            courWeeks.append("周一、");
-                            break;
-                        case 2:
-                            courWeeks.append("周二、");
-                            break;
-                        case 3:
-                            courWeeks.append("周三、");
-                            break;
-                        case 4:
-                            courWeeks.append("周四、");
-                            break;
-                        case 5:
-                            courWeeks.append("周五、");
-                            break;
-                        case 6:
-                            courWeeks.append("周六、");
-                            break;
-                        case 7:
-                            courWeeks.append("周末、");
-                            break;
-                        default:
-                            break;
-                    }
+                    courWeeks.append(integer).append("、");
                 }
-                if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == ','){
+                if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、'){
                     courWeeks.deleteCharAt(courWeeks.length() - 1);
                 }
                 courseVo.setCourseWeek(courWeeks.toString());
@@ -304,11 +328,23 @@
     @PostMapping("/base/coursePack/afterCourseTwos")
     public List<AfterVideoVo> getAfterCourseTwos(@RequestParam("appUserId") Integer appUserId){
         List<AfterVideoVo> videoVos = new ArrayList<>();
-        List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .eq("appUserId", appUserId));
-        List<Integer> coursePackageIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
-//        List<PostCourseVideo> videoList = pcvService.queryAllVideoNoneShow(coursePackageIds);
-        // TODO: 2023/7/6 两个课后视频
+        List<UserVideoDetails> list = uvdsService.list(new QueryWrapper<UserVideoDetails>()
+                .eq("appUserId",appUserId)
+                .eq("state",1));
+        if (list.size() > 0 ){
+            List<Integer> courseIds = list.stream().map(UserVideoDetails::getCourseId).collect(Collectors.toList());
+            List<TCourse> courseList = tcService.list(new QueryWrapper<TCourse>()
+                    .in("id",courseIds)
+                    .eq("type",1)
+                    .eq("state",1)
+                    .last("ORDER BY insertTime desc LIMIT 2"));
+            for (TCourse tCourse : courseList) {
+                AfterVideoVo videoVo = new AfterVideoVo();
+                videoVo.setCourseId(tCourse.getId());
+                videoVo.setCourseUrl(tCourse.getCourseVideo());
+                videoVos.add(videoVo);
+            }
+        }
         return videoVos;
     }
 
@@ -321,10 +357,20 @@
                 .eq("state",1));
     }
 
+    @PostMapping("/base/coursePack/allAmountPayRecordOfUser")
+    public List<TCoursePackagePayment> getAmountPayRecord(@RequestBody BillingDataRequestVo billingDataRequestVo){
+        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+                .eq("appUserId",billingDataRequestVo.getAppUserId())
+                .notIn("payType",3)
+                .eq("payStatus",2)
+                .eq("state",1)
+                .between("insertTime",billingDataRequestVo.getMonthStart(),billingDataRequestVo.getMonthEnd()));
+    }
+
 
     @ResponseBody
     @PostMapping("/api/course/queryArrangeCourseList")
-    @ApiOperation(value = "获取布置课程列表", tags = {"APP-课程列表"})
+    @ApiOperation(value = "课后练习-获取布置课程列表", tags = {"APP-开始上课"})
     @ApiImplicitParams({
     })
     public ResultUtil<List<BaseVo>> queryArrangePackageType(){
@@ -356,7 +402,7 @@
      */
     @ResponseBody
     @PostMapping("/api/startCource/afterSourceList")
-    @ApiOperation(value = "课后视频课表", tags = {"APP-开始上课"})
+    @ApiOperation(value = "课后练习-课后视频列表", tags = {"APP-开始上课"})
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
     })
@@ -385,7 +431,7 @@
      */
     @ResponseBody
     @PostMapping("/api/startCource/afterSourceDetail")
-    @ApiOperation(value = "课后视频详情", tags = {"APP-开始上课"})
+    @ApiOperation(value = "课后练习-课后视频详情", tags = {"APP-开始上课"})
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
     })
@@ -478,14 +524,15 @@
     @ApiOperation(value = "已报名课程详情", tags = {"APP-开始上课"})
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+            @ApiImplicitParam(name = "coursePayId" ,value = "课包记录id",dataType = "long"),
     })
-    public ResultUtil<CourseDetailsResponse> getRegisteredData( Integer coursePackageId){
+    public ResultUtil<CourseDetailsResponse> getRegisteredData( Integer coursePayId){
         try {
             Integer appUserId = tokenUtil.getUserIdFormRedis();
             if(null == appUserId){
                 return ResultUtil.tokenErr();
             }
-            return ResultUtil.success(packagePaymentService.queryRegisteredCourseDetails(coursePackageId,appUserId));
+            return ResultUtil.success(packagePaymentService.queryRegisteredCourseDetails(coursePayId,appUserId));
         }catch (Exception e){
             return ResultUtil.runErr();
         }
@@ -513,6 +560,58 @@
         }
 
     }
+
+
+
+    /**
+     * 课包续课支付宝支付回调接口
+     */
+    @PostMapping("/base/coursePackage/alipayRegisteredCoursesCallback")
+    public void alipayCallback(HttpServletRequest request, HttpServletResponse response){
+        try {
+            Map<String, String> map = payMoneyUtil.alipayCallback(request);
+            if(null != map){
+                String out_trade_no = map.get("out_trade_no");
+                String transaction_id = map.get("transaction_id");
+                ResultUtil resultUtil = packagePaymentService.insertVipPaymentCallback(out_trade_no, transaction_id);
+                if(resultUtil.getCode() == 200){
+                    PrintWriter out = response.getWriter();
+                    out.write("success");
+                    out.flush();
+                    out.close();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 课包续课微信支付回调接口
+     */
+    @PostMapping("/base/coursePackage/wechatRegisteredCoursesCallback")
+    public void weChatCallback(HttpServletRequest request, HttpServletResponse response){
+        try {
+            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
+            if(null != map){
+                String out_trade_no = map.get("out_trade_no");
+                String transaction_id = map.get("transaction_id");
+                String result = map.get("result");
+                ResultUtil resultUtil = packagePaymentService.insertVipPaymentCallback(out_trade_no, transaction_id);
+                if(resultUtil.getCode() == 200){
+                    PrintWriter out = response.getWriter();
+                    out.write(result);
+                    out.flush();
+                    out.close();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
 
 
     /**
@@ -605,4 +704,88 @@
             e.printStackTrace();
         }
     }
+
+
+    /**
+     * 课包续费玩湃币支付
+     * @param
+     */
+    @PostMapping("/coursePackagePayment/courseRenewPlayPaiPay")
+    public int paymentWanpaiRenewCourse(@RequestBody PlayPaiGoldCoursePackage coursePackage){
+        try {
+            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
+            if (null == userIdFormRedis){
+                return 2;
+            }
+            CoursePackagePaymentConfig paymentConfig = icppcService.getById(coursePackage.getCoursePayConfigId());
+            AppUser appUser = auClitn.queryAppUser(userIdFormRedis);
+            if (appUser.getPlayPaiCoins() < paymentConfig.getPlayPaiCoin()){
+                return 3;
+            }
+            TCoursePackagePayment packagePayment = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>()
+                    .eq("code",coursePackage.getCode() ));
+            packagePayment.setPayStatus(2);
+            packagePayment.setPayUserId(userIdFormRedis);
+            packagePayment.setClassHours(paymentConfig.getClassHours());
+            packagePayment.setPlayPaiCoin(paymentConfig.getPlayPaiCoin());
+            packagePayment.setTotalClassHours(paymentConfig.getClassHours());
+            packagePayment.setLaveClassHours(paymentConfig.getClassHours());
+            packagePaymentService.updateById(packagePayment);
+
+            appUser.setPlayPaiCoins(appUser.getPlayPaiCoins()-paymentConfig.getPlayPaiCoin());
+            auClitn.updateAppUser(appUser);
+        } catch (Exception e) {
+            return 4;
+        }
+        return 1;
+    }
+
+    @PostMapping("/base/coursePack/getPaymentCoursePackage")
+    public TCoursePackagePayment getCoursePackagePaymentByCode(@RequestBody String code){
+        return packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>()
+                .eq("code",code));
+    }
+
+    @PostMapping("/base/coursePack/delPaymentCoursePackage")
+    public boolean delPaymentCoursePackage(@RequestBody Integer payId){
+        return packagePaymentService.removeById(payId);
+    }
+    @PostMapping("/base/coursePack/updatePaymentCoursePackage")
+    public boolean updatePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){
+        return packagePaymentService.update(packagePayment,new QueryWrapper<TCoursePackagePayment>()
+                .eq("id",packagePayment.getId()));
+    }
+
+    @PostMapping("/base/coursePack/savePaymentCoursePackage")
+    public boolean savePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){
+        return packagePaymentService.save(packagePayment);
+    }
+
+
+    @PostMapping("/base/coursePack/obtainStudentClassDetails")
+    public List<RecordAppoint> obtainStudentClassDetailsData(@RequestBody Integer stuId){
+        try {
+            Integer appUserId = tokenUtil.getUserIdFormRedis();
+            return packagePaymentService.obtainStuClassDetails(stuId,appUserId);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new RuntimeException();
+        }
+    }
+
+
+    @PostMapping("/base/coursePack/getCoursePackageConfig")
+    public List<CoursePackagePaymentConfig> getCourseConfigList(@RequestBody Integer coursePackageId){
+        return icppcService.list(new QueryWrapper<CoursePackagePaymentConfig>()
+                .eq("coursePackageId",coursePackageId));
+    }
+
+
+
+    @PostMapping("/base/coursePack/getCoursePackagePaymentOfCode")
+    public List<TCoursePackagePayment> getCoursePackagePaymentOfCode(@RequestBody String code){
+        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+                .eq("code",code));
+    }
+
 }

--
Gitblit v1.7.1