nickchange
2023-11-21 41b60f3df5f3054aad44307c13a26b14f3b32ac0
cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java
@@ -468,6 +468,14 @@
        AppUser appUser = appuClient.queryAppUser(appUserId);
        CourseDetailsResponse response = new CourseDetailsResponse();
        TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(coursePayId);
        List<TCoursePackagePayment> tCoursePackagePayments = this.baseMapper.selectList(new QueryWrapper<TCoursePackagePayment>().eq("appUserId", appUserId).eq("coursePackageId", tCoursePackagePayment.getCoursePackageId()));
        List<Integer> stuIds = new ArrayList<>();
        for (TCoursePackagePayment coursePackagePayment : tCoursePackagePayments) {
            stuIds.add(coursePackagePayment.getStudentId());
        }
        response.setStuIds(stuIds);
        response.setChooseHours(tCoursePackagePayment.getClassHours());
        if (null != tCoursePackagePayment){
            TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
@@ -537,16 +545,16 @@
                }
            }
//            switch (payType) {
//                case 1:
//                case 2:
//                    response.setAmount(cashPaymentValue);
//                    response.setVipAmount(discountMember);
//                    break;
//                case 3:
//                    response.setWpGold(playPaiCoin);
//                    break;
//            }
            switch (payType) {
                case 1:
                case 2:
                    response.setAmount(cashPaymentValue);
                    response.setVipAmount(discountMember);
                    break;
                case 3:
                    response.setWpGold(playPaiCoin);
                    break;
            }
//            coursePackage.get
@@ -661,6 +669,22 @@
                    }
                    coursePackagePaymentConfigVo.setPaymentPrice(paymentPrice);
                    TCoursePackageDiscount discount = coursePackageDiscountService.getOne(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                            .eq("type", 2).eq("auditStatus", 2));
                    Double continuingMember = JSON.parseObject(discount.getContent()).getDouble("continuingUser");
                    Double vipcontinuingMember = JSON.parseObject(discount.getContent()).getDouble("continuingMember");
                    if (coursePackagePaymentConfigVo.getPaymentPrice()>continuingMember){
                        coursePackagePaymentConfigVo.setPaymentPrice(continuingMember);
                    }
                    if (coursePackagePaymentConfigVo.getVipPrice()>vipcontinuingMember){
                        coursePackagePaymentConfigVo.setVipPrice(vipcontinuingMember);
                    }
                    if (coursePackagePaymentConfigVo.getPaymentPrice()<coursePackagePaymentConfigVo.getVipPrice()){
                        coursePackagePaymentConfigVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment());
                        coursePackagePaymentConfigVo.setVipPrice(null);
@@ -682,7 +706,7 @@
                }
                list.add(coursePackagePaymentConfigVo);
            });
//            coursePackageInfo.setList(list);
            response.setList(list);
@@ -957,7 +981,7 @@
        if (tCoursePackagePayments.size() > 0 ){
//            int pageNum = 1; // 页码
            int pageSize = 100; // 每页记录数
            int pageSize = 10; // 每页记录数
            Page<CoursePackageStudent> page = new Page<>(pageNum, pageSize);
//            for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) {
@@ -1010,6 +1034,7 @@
//                        String classStartTime = coursePackage.getClassStartTime();
//                        String classEndTime = coursePackage.getClassEndTime();
                            //这里是过滤今天之后的数据
//                        if (byId == null||byId.getClassDate().after(new Date())){
//                            continue;
//                        }
@@ -1059,7 +1084,7 @@
//                                CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>()
//                                        .eq("coursePackageId",coursePackageStudent.getCoursePackageId()));
                                CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>()
                                        .eq("coursePackageSchedulingId",byId.getId()));
                                        .eq("coursePackageSchedulingId",byId.getId()).last("limit 1"));
                                if (ToolUtil.isNotEmpty(cancelledClasses)){
                                    recordVo.setStatus(3);
                                    // 消课 到课状态0 旷课
@@ -1232,6 +1257,9 @@
        ArrayList<PayCourseRes> payCourseRes = new ArrayList<>();
        for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) {
            TCoursePackage tCoursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
            if (tCoursePackage.getType()!=1){
                continue;
            }
            if(tCoursePackage.getStoreId().equals(storeId)){
                PayCourseRes payCourseRes1 = new PayCourseRes();
                payCourseRes1.setId(tCoursePackagePayment.getId());
@@ -1335,7 +1363,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public ResultUtil payCourse(PayCourseReq req,Integer userId){
    public ResultUtil payCourse(PayCourseReq req,Integer userId) throws ParseException {
        // 扣除 原来的课时数
        // 添加购买课时 paytyoe为7
        // 排课可期  判断课程时间段  添加排课表  添加上课记录表
@@ -1347,69 +1375,78 @@
        tCoursePackagePayment.setLaveClassHours(tCoursePackagePayment.getLaveClassHours()-req.getNum());
        this.baseMapper.updateHoursById(tCoursePackagePayment.getId(),-req.getNum());
//
//        List<CoursePackageStudent> studentCourse = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("studentId", coursePackagePayment.getStudentId()).eq("coursePackageId", coursePackagePayment.getCoursePackageId()));
//        List<Long> collect = studentCourse.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList());
        List<CoursePackageStudent> studentCourse = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("studentId", tCoursePackagePayment.getStudentId()).eq("coursePackageId", tCoursePackagePayment.getCoursePackageId()));
        List<Long> collect = studentCourse.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList());
        List<CoursePackageScheduling> list = coursePackageSchedulingService.list(new QueryWrapper<CoursePackageScheduling>().in("id", collect).le("classDate", new Date()));
        coursePackageSchedulingService.remove(new QueryWrapper<CoursePackageScheduling>().in("id",collect).le("classDate", new Date()));
        List<Long> collect1 = list.stream().map(CoursePackageScheduling::getId).collect(Collectors.toList());
//        coursePackageSchedulingService.remove(new QueryWrapper<CoursePackageScheduling>().in("id",collect));
//        coursePackageStudentService.remove(new QueryWrapper<CoursePackageStudent>().eq("studentId", paymentDeductionClassHour.getId()).eq("coursePackageId", coursePackagePayment.getCoursePackageId()));
//
//        TCoursePackage tCoursePackage = packageService.getById(tCoursePackagePayment.getCoursePackageId());
//        String classWeeks = tCoursePackage.getClassWeeks();
//        List<Integer> week = week(classWeeks);
//
//        TCoursePackagePayment pay = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("coursePackageId", tCoursePackagePayment.getCoursePackageId()).eq("studentId", tCoursePackagePayment.getStudentId()));
//
//
//        Date today = new Date();
//
//        Integer laveClassHours = pay.getLaveClassHours();
//        Integer codeTime = tCoursePackage.getCodeTime();
//        Integer can = laveClassHours/codeTime;
//
//        int count = 0;
//        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");
//
//        Date[] dates = generateDateArray(14,today);
//        for (Date date : dates) {
//            if (count==can){
//                break;
//            }
//            int wei =  cn.hutool.core.date.DateUtil.dayOfWeek(date);
//            if (week.contains(wei)){
//                for (int i1 = 0; i1 < split.length; i1++) {
//                    if (count==can){
//                        break;
//                    }
//                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
//                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
//                    Date parse = format1.parse(format.format(date) + " " + split[i1]);
//                    Date parse1 = format1.parse(format.format(date) + " " + split1[i1]);
//                    coursePackageScheduling.setClassDate(parse);
//                    coursePackageScheduling.setEndDate(parse1);
//                    coursePackageScheduling.setStatus(1);
//                    coursePackageSchedulingService.save(coursePackageScheduling);
//                    CoursePackageStudent student1 = new CoursePackageStudent();
//                    student1.setAppUserId(pay.getAppUserId());
//                    student1.setStudentId(pay.getStudentId());
//                    student1.setCoursePackageId(pay.getCoursePackageId());
//                    student1.setCoursePackagePaymentId(pay.getId());
//                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
//                    student1.setSignInOrNot(1);
//                    student1.setReservationStatus(1);
//                    student1.setInsertTime(new Date());
//                    studentService.save(student1);
//                    count++;
//                }
//            }
//        }
        coursePackageStudentService.remove(new QueryWrapper<CoursePackageStudent>().eq("studentId", tCoursePackagePayment.getStudentId()).eq("coursePackageId", tCoursePackagePayment.getCoursePackageId()));
        TCoursePackage tCoursePackage = tcpmapper.selectById(req.getCourseId());
        String classWeeks = tCoursePackage.getClassWeeks();
        List<Integer> week = week(classWeeks);
        TCoursePackagePayment pay = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("coursePackageId", tCoursePackagePayment.getCoursePackageId()).eq("studentId", tCoursePackagePayment.getStudentId()));
        Date today = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        today = calendar.getTime();
        Integer laveClassHours = pay.getLaveClassHours();
        Integer codeTime = tCoursePackage.getCodeTime();
        Integer can = laveClassHours/codeTime;
        int count = 0;
        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");
        Date[] dates = generateDateArray(14,today);
        for (Date date : dates) {
            if (count==can){
                break;
            }
            int wei =  cn.hutool.core.date.DateUtil.dayOfWeek(date);
            if (week.contains(wei)){
                for (int i1 = 0; i1 < split.length; i1++) {
                    if (count==can){
                        break;
                    }
                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                    Date parse = format1.parse(format.format(date) + " " + split[i1]);
                    Date parse1 = format1.parse(format.format(date) + " " + split1[i1]);
                    coursePackageScheduling.setClassDate(parse);
                    coursePackageScheduling.setEndDate(parse1);
                    coursePackageScheduling.setStatus(1);
                    coursePackageSchedulingService.save(coursePackageScheduling);
                    CoursePackageStudent student1 = new CoursePackageStudent();
                    student1.setAppUserId(pay.getAppUserId());
                    student1.setStudentId(pay.getStudentId());
                    student1.setCoursePackageId(pay.getCoursePackageId());
                    student1.setCoursePackagePaymentId(pay.getId());
                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                    student1.setSignInOrNot(1);
                    student1.setReservationStatus(1);
                    student1.setInsertTime(new Date());
                    coursePackageStudentService.save(student1);
                    count++;
                }
            }
        }
//        TCoursePackage tCoursePackage = tcpmapper.selectById(req.getCourseId());
        // 添加课包
        TCoursePackagePayment tCoursePackagePayment1 = new TCoursePackagePayment();
//        tCoursePackagePayment1.setAppUserId(userId);
@@ -1438,19 +1475,19 @@
        tCoursePackagePayment1.setInsertTime(new Date());
        this.baseMapper.insert(tCoursePackagePayment1);
        // 找出课包时间段
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String classStartTime = tCoursePackage.getClassStartTime();
        String classEndTime = tCoursePackage.getClassEndTime();
        String[] split = classStartTime.split(",");
        String[] split1 = classEndTime.split(",");
        String[] split5 = classStartTime.split(",");
        String[] split6 = classEndTime.split(",");
        List<String> time = req.getTime();
        for (String s : time) {
            for (int i = 0; i < split.length; i++) {
            for (int i = 0; i < split5.length; i++) {
                CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                try {
                    Date parse = format.parse(s + " " + split[i]);
                    Date parse1 = format.parse(s + " " + split1[i]);
                    Date parse = format.parse(s + " " + split5[i]);
                    Date parse1 = format.parse(s + " " + split6[i]);
                    coursePackageScheduling.setClassDate(parse);
                    coursePackageScheduling.setEndDate(parse1);
                    coursePackageScheduling.setStatus(1);