44323
2023-11-02 eb88e1b9c634496b7840dca48898510f36357d46
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -184,8 +184,6 @@
            String[] end = value1.split(",");
            for (int i = 0; i < star.length; i++) {
    //                int index = star[i].indexOf(",");
    //
    //
    //                String result = value.substring(0, index).trim();
                String classStartTime = star[i];
                String[] split = classStartTime.split(":");
@@ -203,7 +201,7 @@
                Calendar e = Calendar.getInstance();
                e.setTime(date);
                e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 13);
                e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 14);
                long timeInMillis = e.getTimeInMillis();
                while (true){
@@ -234,7 +232,7 @@
                                .eq("coursePackageId", coursePackage.getId())
                                .eq("classDate", classDate.getTime())
                                .eq("endDate", endDate.getTime()));
                        if (list.size()+1>coursePackage.getMaxSubscribeNumber()){
                        if (list1.size()+1>coursePackage.getMaxSubscribeNumber()){
                            // 当前课包预约人数已满
                            return 5001;
                        }
@@ -269,6 +267,13 @@
    public Object changeState(@RequestBody CoursePackagePayDTO dto){
        return packagePaymentService.changeState(dto);
    }
    @GetMapping("/coursePackagePayment/courseStore/{appUserId}/{coursePackageId}")
    public List<TCoursePackagePayment> getByUserIdAndCoursePackageId(@PathVariable("appUserId") Integer appUserId,@PathVariable("coursePackageId") Integer coursePackageId){
        List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId", appUserId)
                .eq("coursePackageId", coursePackageId));
        return list;
    }
    /**
     * 获取购课记录
@@ -372,7 +377,6 @@
                }
            }
        }
        List<RegisterOrderVO> res = packagePaymentService.listAllRegister(query);
        // 该运营商下没有门店
        if (query.getStoresIds()!=null){
@@ -380,6 +384,9 @@
                List<RegisterOrderVO> registerOrderVOS = new ArrayList<>();
                return registerOrderVOS;
            }
        }else{
            List<RegisterOrderVO> registerOrderVOS = new ArrayList<>();
            return registerOrderVOS;
        }
        List<RegisterOrderVO> result = new ArrayList<>();
@@ -405,7 +412,8 @@
            re.setPhone(appUser.getPhone());
            re.setStoreName(store.getName());
            // 在这里添加条件来删除不满足要求的元素
            if (appUser.getInsertType() != query.getInsertType()) {
            if (query.getInsertType() !=null && appUser.getInsertType() != query.getInsertType()) {
                iterator.remove(); // 使用迭代器的 remove 方法删除元素
            }
        }
@@ -753,13 +761,13 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<AppUserVideoResponse>> queryAfterSourceList( CourseOfAfterRequest search){
    public ResultUtil<List<AppUserVideoResponse>> queryAfterSourceList( CourseOfAfterRequest search) throws Exception {
//        try {
//            Integer appUserId = tokenUtil.getUserIdFormRedis();
//
//            if(null == appUserId){
//                return ResultUtil.tokenErr();
//            }
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
//
//            List<Integer> courseIds = new ArrayList<>();
//            QueryWrapper<TCoursePackagePayment> queryWrapper = new QueryWrapper<TCoursePackagePayment>().eq("appUserId", appUserId)
@@ -773,7 +781,7 @@
//            }
            QueryWrapper<CoursePackageStudent> queryWrapper1 = new QueryWrapper<CoursePackageStudent>().eq("appUserId", 19);
            QueryWrapper<CoursePackageStudent> queryWrapper1 = new QueryWrapper<CoursePackageStudent>().eq("appUserId", appUserId);
            if (ToolUtil.isNotEmpty(search.getCourseTypeId())){
                queryWrapper1.eq("coursePackageId",search.getCourseTypeId());
            }
@@ -996,6 +1004,7 @@
     */
    @PostMapping("/base/coursePackage/alipayRegisteredCoursesCallback")
    public void alipayCallback(HttpServletRequest request, HttpServletResponse response){
        System.err.println("========支付宝支付回调========");
        try {
            Map<String, String> map = payMoneyUtil.alipayCallback(request);
            if(null != map){
@@ -1081,6 +1090,10 @@
    }
    @Autowired
    private  TCoursePackageService packageService;
    @Autowired
    CoursePackageStudentService studentService ;
    /**
     * 课程用于支付进行扣减
     * @param paymentDeductionClassHour
@@ -1094,58 +1107,202 @@
                    .eq("status", 1).eq("state", 1).gt("laveClassHours", 0));
            Integer classHour = paymentDeductionClassHour.getClassHour();
            for (TCoursePackagePayment coursePackagePayment : list) {
                if(coursePackagePayment.getLaveClassHours().compareTo(classHour) >= 0){
                if (coursePackagePayment.getLaveClassHours().compareTo(classHour) >= 0) {
                    coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() - classHour);
                    coursePackagePayment.setAppUserId(null);
                    packagePaymentService.updateById(coursePackagePayment);
                    // 2.0 少于3课时 推送
                    if(coursePackagePayment.getLaveClassHours()<=3){
                        Integer appUserId = coursePackagePayment.getAppUserId();
                        //调用推送
                        HttpHeaders headers = new HttpHeaders();
                        // 以表单的方式提交
                        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
                        String s1 = appUserId + "_" + "Three";
                        //定时修改排课状态
                        String s = internalRestTemplate.getForObject("http://mb-cloud-gateway/netty/sendMsgToClient?id="+s1, String.class);
                        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
                        if(jsonObject1.getIntValue("code") != 200){
                            System.err.println(jsonObject1.getString("msg"));
                    coursePackageSchedulingService.remove(new QueryWrapper<CoursePackageScheduling>().eq("courseId", coursePackagePayment.getCoursePackageId()));
                    coursePackageStudentService.remove(new QueryWrapper<CoursePackageStudent>().eq("coursePackageId", coursePackagePayment.getCoursePackageId()));
                    Student student = studentClient.queryStudentById(coursePackagePayment.getStudentId());
                    TCoursePackage tCoursePackage = packageService.getById(coursePackagePayment.getCoursePackageId());
                    String classWeeks = tCoursePackage.getClassWeeks();
                    List<Integer> week = week(classWeeks);
                    String[] split = tCoursePackage.getClassStartTime().split(",");
                    String[] split1 = tCoursePackage.getClassEndTime().split(",");
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    // 本周周几
                    int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date()) - 1;
                    for (Integer integer : week) {
                        if (integer < i) {
                            // 找下一周的时间
                            Calendar instance = Calendar.getInstance();
                            instance.add(Calendar.DATE, 7 - (i - integer));
                            Date time = instance.getTime();
                            for (int i1 = 0; i1 < split.length; i1++) {
                                CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                                coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                                Date parse = format1.parse(format.format(time) + " " + split[i1]);
                                Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
                                coursePackageScheduling.setClassDate(parse);
                                coursePackageScheduling.setEndDate(parse1);
                                coursePackageScheduling.setStatus(1);
                                coursePackageSchedulingService.save(coursePackageScheduling);
                                CoursePackageStudent student1 = new CoursePackageStudent();
                                student1.setAppUserId(student.getAppUserId());
                                student1.setStudentId(student.getId());
                                student1.setCoursePackageId(tCoursePackage.getId());
                                student1.setCoursePackagePaymentId(coursePackagePayment.getId());
                                student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                                student1.setSignInOrNot(1);
                                student1.setReservationStatus(1);
                                student1.setInsertTime(new Date());
                                studentService.save(student1);
                            }
                        } else if (integer > i) {
                            Calendar instance = Calendar.getInstance();
                            instance.add(Calendar.DATE, integer - i);
                            Date time1 = instance.getTime();
                            List<Date> list6 = new ArrayList<>();
                            list6.add(time1);
                            instance.add(Calendar.DATE, 7);
                            Date time2 = instance.getTime();
                            list6.add(time2);
                            for (Date time : list6) {
                                for (int i1 = 0; i1 < split.length; i1++) {
                                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                                    Date parse = format1.parse(format.format(time) + " " + split[i1]);
                                    Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
                                    coursePackageScheduling.setClassDate(parse);
                                    coursePackageScheduling.setEndDate(parse1);
                                    coursePackageScheduling.setStatus(1);
                                    coursePackageSchedulingService.save(coursePackageScheduling);
                                    CoursePackageStudent student1 = new CoursePackageStudent();
                                    student1.setAppUserId(student.getAppUserId());
                                    student1.setStudentId(student.getId());
                                    student1.setCoursePackageId(tCoursePackage.getId());
                                    student1.setCoursePackagePaymentId(coursePackagePayment.getId());
                                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                                    student1.setSignInOrNot(1);
                                    student1.setReservationStatus(1);
                                    student1.setInsertTime(new Date());
                                    studentService.save(student1);
                                }
                            }
                        } else {
                            Calendar instance = Calendar.getInstance();
                            instance.add(Calendar.DATE, 7);
                            Date time = instance.getTime();
                            for (int i1 = 0; i1 < split.length; i1++) {
                                CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                                coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                                Date parse = format1.parse(format.format(time) + " " + split[i1]);
                                Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
                                coursePackageScheduling.setClassDate(parse);
                                coursePackageScheduling.setEndDate(parse1);
                                coursePackageScheduling.setStatus(1);
                                coursePackageSchedulingService.save(coursePackageScheduling);
                                CoursePackageStudent student1 = new CoursePackageStudent();
                                student1.setAppUserId(student.getAppUserId());
                                student1.setStudentId(student.getId());
                                student1.setCoursePackageId(tCoursePackage.getId());
                                student1.setCoursePackagePaymentId(coursePackagePayment.getId());
                                student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                                student1.setSignInOrNot(1);
                                student1.setReservationStatus(1);
                                student1.setInsertTime(new Date());
                                studentService.save(student1);
                            }
                        }
                    }
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(classHour);
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
                    break;
                }else{
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(coursePackagePayment.getLaveClassHours());
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
                    coursePackagePayment.setLaveClassHours(0);
                    packagePaymentService.updateById(coursePackagePayment);
                        // 2.0 少于3课时 推送
                        if (coursePackagePayment.getLaveClassHours() <= 3) {
                            Integer appUserId = coursePackagePayment.getAppUserId();
                    classHour -= cancelledClasses.getCancelledClassesNumber();
                            //调用推送
                            HttpHeaders headers = new HttpHeaders();
                            // 以表单的方式提交
                            headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
                            String s1 = appUserId + "_" + "Three";
                            //定时修改排课状态
                            String s = internalRestTemplate.getForObject("http://mb-cloud-gateway/netty/sendMsgToClient?id=" + s1, String.class);
                            JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
                            if (jsonObject1.getIntValue("code") != 200) {
                                System.err.println(jsonObject1.getString("msg"));
                            }
                        }
                        CancelledClasses cancelledClasses = new CancelledClasses();
                        cancelledClasses.setType(2);
                        cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                        cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                        cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                        cancelledClasses.setCancelledClassesNumber(classHour);
                        cancelledClasses.setInsertTime(new Date());
                        cancelledClassesService.save(cancelledClasses);
                        break;
                    }else{
                        CancelledClasses cancelledClasses = new CancelledClasses();
                        cancelledClasses.setType(2);
                        cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                        cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                        cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                        cancelledClasses.setCancelledClassesNumber(coursePackagePayment.getLaveClassHours());
                        cancelledClasses.setInsertTime(new Date());
                        cancelledClassesService.save(cancelledClasses);
                        coursePackagePayment.setLaveClassHours(0);
                        packagePaymentService.updateById(coursePackagePayment);
                        classHour -= cancelledClasses.getCancelledClassesNumber();
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private List<Integer> week(String week){
        String[] split = week.split(";");
        ArrayList<Integer> integers = new ArrayList<>();
        for (String s : split) {
            switch (s){
                case "周一":
                    integers.add(1);
                    break;
                case "周二":
                    integers.add(2);
                    break;
                case "周三":
                    integers.add(3);
                    break;
                case "周四":
                    integers.add(4);
                    break;
                case "周五":
                    integers.add(5);
                    break;
                case "周六":
                    integers.add(6);
                    break;
                case "周日":
                    integers.add(7);
                    break;
            }
        }
        return integers;
    }
    /**
     * 取消赛事回退支付课时
     * @param paymentDeductionClassHour