44323
2023-11-27 aa925d851857f50eff0556411366690d9a78a0e5
cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java
@@ -123,9 +123,6 @@
    private RestTemplate internalRestTemplate;
    @Override
    public List<CoursePackagePaymentVO> listAll(CoursePackagePaymentQuery query) {
        return cpConfigMapper.listAll(query);
@@ -208,7 +205,8 @@
                if (!cityCode.equals(studentQeryDto.getCityCode())) {
                    iterator.remove(); // Remove the element from the list
                }
            }}
                }
            }
        }
        if (studentQeryDto.getStudentName()!=null&&studentQeryDto.getStudentName()!=""){
@@ -268,6 +266,7 @@
    /**
     * 获取课包购买人数
     *
     * @param coursePackageId
     * @return
     */
@@ -320,8 +319,10 @@
        }
        return responses;
    }
    @Autowired
    private TCourseService courseService;
    @Override
    public CourseOfVideoResponse queryVideoDetails(CourseWithDetailsRequest detailsRequest,Integer appUserId) {
        CourseOfVideoResponse response = new CourseOfVideoResponse();
@@ -404,9 +405,6 @@
//                .in("id",paysId ));
        System.out.println(tCoursePackagePayments);
        if (tCoursePackagePayments.size() > 0){
            try {
@@ -417,7 +415,7 @@
                    // 2.0
                    registerCourseVo.setType(coursePackage.getType());
                    registerCourseVo.setOrderId(tCoursePackagePayment.getOrderId());
                    registerCourseVo.setOrderId(tCoursePackagePayment.getOrderId().longValue());
                    registerCourseVo.setCoursePayId(tCoursePackagePayment.getId());
                    registerCourseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
                    registerCourseVo.setCoursePackTypeId(coursePackage.getCoursePackageTypeId());
@@ -498,55 +496,62 @@
    @Autowired
    private  TCoursePackageDiscountService coursePackageDiscountService;
    @Resource
    StoreClient storeClient;
    @Autowired
    private ICoursePackageOrderService coursePackageOrderService;
    @Autowired
    private ICoursePackageOrderStudentService coursePackageOrderStudentService;
    @Autowired
    private TCoursePackageService coursePackageService;
    @Override
    public CourseDetailsResponse queryRegisteredCourseDetails(Long coursePayId, Integer appUserId) {
    public CourseDetailsResponse queryRegisteredCourseDetails(Long coursePayId, Integer appUserId, String lon, String lat) {
        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());
        CoursePackageOrderStudent coursePackageOrderStudent = coursePackageOrderStudentService.getById(coursePayId);
        CoursePackageOrder coursePackageOrder = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>()
                .eq("appUserId", coursePackageOrderStudent.getAppUserId())
                .eq("coursePackageId", coursePackageOrderStudent.getCoursePackageId())
                .eq("payStatus", 2)
                .eq("state", 1)
                .like("studentIds", coursePackageOrderStudent.getStudentId())
                .orderByDesc("insertTime")
                .last(" limit 0, 1")
        );
        if (null != tCoursePackagePayment){
            TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
        response.setChooseHours(coursePackageOrder.getClassHours());
        if (null != coursePackageOrder) {
            TCoursePackage coursePackage = tcpmapper.selectById(coursePackageOrder.getCoursePackageId());
            if (coursePackage.getType()==2) {
                response.setTime(new SimpleDateFormat("yyyy.MM.dd").format(coursePackage.getStartTime()) + "-" + new SimpleDateFormat("yyyy.MM.dd").format(coursePackage.getEndTime()));
            }
            Store store = storeClient.queryStoreById(coursePackage.getStoreId());
            response.setStoreName(store.getName());
//            Store store = storeClient.queryStoreById(coursePackage.getStoreId());
//            response.setStoreName(store.getName());
//            response.setStoreCoverDrawing(store.getCoverDrawing());
//            response.setStoreAddress(store.getAddress());
//            response.setLon(store.getLon());
//            response.setLat(store.getLat());
//            if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){
//                Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
//                double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
//                response.setDistance(wgs84);
//            }
            response.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
            if (ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)) {
                Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
                double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                response.setDistance(wgs84);
            }
            response.setCoursePackageId(coursePackageOrder.getCoursePackageId());
            response.setCoverDrawing(coursePackage.getCoverDrawing());
            response.setDetailDrawing(coursePackage.getDetailDrawing());
            response.setCoursePackageName(coursePackage.getName());
            response.setCoursePayId(tCoursePackagePayment.getId());
            response.setCoursePayId(coursePackageOrder.getId());
            response.setType(coursePackage.getType());
            List<Integer> integers = StrUtils.dealStrToList(coursePackage.getClassWeeks());
            String classWeeks = coursePackage.getClassWeeks();
            if (integers.size() > 0){
                StringBuilder courWeeks = new StringBuilder("每"+classWeeks);
//                for (Integer integer : integers) {
//                    courWeeks.append(integer).append("、");
//                }
//                if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、'){
//                    courWeeks.deleteCharAt(courWeeks.length() - 1);
//                }
                response.setWeeks(courWeeks.toString());
            }
            ArrayList<String> classTime = new ArrayList<>();
@@ -564,17 +569,16 @@
            response.setCourseTimeFrame(joinedString);
//            response.setCourseTimeFrame(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime());
            response.setIntroduceDrawing(coursePackage.getIntroduceDrawing());
            Integer payType = tCoursePackagePayment.getPayType();
            BigDecimal cashPayment = tCoursePackagePayment.getCashPayment();
            Integer payType = coursePackageOrder.getPayType();
            BigDecimal cashPayment = coursePackageOrder.getCashPayment();
            double cashPaymentValue = 0.0;
            if(cashPayment!=null){
                 cashPaymentValue = cashPayment.doubleValue();
            }
            Integer playPaiCoin = tCoursePackagePayment.getPlayPaiCoin();
            Integer playPaiCoin = coursePackageOrder.getPlayPaiCoin();
            TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>()
                    .eq("coursePackageId",coursePackage.getId() )
                    .eq("type",1)
@@ -603,10 +607,7 @@
                    break;
            }
//            coursePackage.get
            response.setPayStatus(tCoursePackagePayment.getPayStatus());
            response.setPayStatus(coursePackageOrder.getPayStatus());
            List<CoursePackagePaymentConfigVo> list = new ArrayList<>();
@@ -737,8 +738,7 @@
                        coursePackagePaymentConfigVo.setVipPrice(null);
                    }
                }
                else{
                } else {
                    List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                            .eq("type", 1).eq("auditStatus", 2));
                    Double vipPrice = coursePackagePaymentConfig.getCashPayment();
@@ -754,11 +754,6 @@
                list.add(coursePackagePaymentConfigVo);
            });
            response.setList(list);
        }
        return response;
    }
@@ -934,7 +929,6 @@
    }
    public ResultUtil AlipayPayment(String code, BigDecimal request){
        TCoursePackagePaymentMapper baseMapper1 = this.baseMapper;
        ResultUtil alipay = payMoneyUtil.alipay("课包购买", "课包购买", "", code, request.toString(),
@@ -1006,7 +1000,6 @@
        appuClient.updateAppUser(appUser);
        return ResultUtil.success();
    }
    @Override
@@ -1119,8 +1112,7 @@
                            } else if(coursePackageStudent.getSignInOrNot()==2){
                                //已请假
                                recordVo.setStatus(5);
                            }
                            else if (start.after(new Date())){
                        } else if (start.after(new Date())) {
                                //待上课
                                recordVo.setStatus(1);
                            }
@@ -1164,6 +1156,7 @@
        return recordVoList;
    }
    public List<Integer>  getIds(Integer siteId) {
        HttpRequest httpRequest = HttpRequest.get("https://try.daowepark.com/v7/user_api/general/get_space_area?space_id=" + siteId);
        HttpResponse execute = httpRequest.execute();
@@ -1181,6 +1174,7 @@
        return ids;
    }
    @Override
    public ResultUtil insertVipPaymentCallback(String code, String orderNumber) {
        TCoursePackagePayment coursePackagePayment = this.baseMapper.getCoursePackagePaymentByCode(code);
@@ -1201,6 +1195,7 @@
    /**
     * 获取课包报名信息
     *
     * @param page
     * @param queryRegistrationRecord
     * @return
@@ -1239,10 +1234,6 @@
            Integer integer = cpsMapper.selectCount(new QueryWrapper<CoursePackageStudent>().eq("appUserId", appUserId)
                    .eq("studentId", studentId).eq("coursePackagePaymentId", id).eq("signInOrNot", 2));
            map.put("already", integer);
//            if (student != null && student.getName().equals("杨锴1")) {
//                map.put("totalClassHours", "测试");
//            }
            ;
        }
        return list;
    }
@@ -1250,6 +1241,7 @@
    /**
     * 获取未预约排课学员列表
     *
     * @param page
     * @param queryWalkInStudentList
     * @return
@@ -1300,9 +1292,9 @@
    @Override
    public List<PayCourseRes> getMyCourseList(Integer storeId, Integer appUserId) {
        // 找到购买的课包
        List<TCoursePackagePayment> tCoursePackagePayments = this.baseMapper.selectList(new LambdaQueryWrapper<TCoursePackagePayment>().eq(TCoursePackagePayment::getAppUserId, appUserId));
        List<CoursePackageOrderStudent> tCoursePackagePayments = coursePackageOrderStudentService.list(new LambdaQueryWrapper<CoursePackageOrderStudent>().eq(CoursePackageOrderStudent::getAppUserId, appUserId));
        ArrayList<PayCourseRes> payCourseRes = new ArrayList<>();
        for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) {
        for (CoursePackageOrderStudent tCoursePackagePayment : tCoursePackagePayments) {
            TCoursePackage tCoursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
            if (tCoursePackage.getType()!=1){
                continue;
@@ -1368,6 +1360,7 @@
        payCourseInfoReq.setDay(strings1);
        return payCourseInfoReq;
    }
    private static List<Integer> week(String week){
        String[] split = week.split(";");
        ArrayList<Integer> integers = new ArrayList<>();
@@ -1418,123 +1411,55 @@
        // 添加购买课时 paytyoe为7
        // 排课可期  判断课程时间段  添加排课表  添加上课记录表
        // 找到原来的课包 扣课时
        TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(req.getOldCourseId());
        if(req.getNum()>tCoursePackagePayment.getLaveClassHours()){
        CoursePackageOrderStudent coursePackageOrderStudent = coursePackageOrderStudentService.getById(req.getOldCourseId());
        if (req.getNum() > coursePackageOrderStudent.getLaveClassHours()) {
            return ResultUtil.error("当前课包课时数不足");
        }
        tCoursePackagePayment.setLaveClassHours(tCoursePackagePayment.getLaveClassHours()-req.getNum());
        this.baseMapper.updateHoursById(tCoursePackagePayment.getId(),-req.getNum());
        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", 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;
        TCoursePackage coursePackage = coursePackageService.getById(coursePackageOrderStudent.getCoursePackageId());
        TCoursePackage coursePackage1 = coursePackageService.getById(req.getCourseId());
        //判断剩余课时是否已经全部进行排课,如果排课需要删除已经排好的记录
        List<CoursePackageScheduling> list1 = coursePackageSchedulingService.list(new QueryWrapper<CoursePackageScheduling>()
                .eq("studentId", coursePackageOrderStudent.getStudentId()).eq("status", 1)
                .eq("type", 1).orderByDesc("classDate"));
        //已经排课但没有使用的课时数量
        int number = list1.size() * coursePackage.getNeedNum();
        Integer laveClassHours1 = coursePackageOrderStudent.getLaveClassHours();
        laveClassHours1 -= number;
        //需要购买使用的课时数
        Integer num = req.getNum();
        //需要删除多余的排课记录
        if(num.compareTo(laveClassHours1) > 0){
            //课时数差额
            int number1 = num - laveClassHours1;
            double o = number1 % coursePackage.getNeedNum();
            int l = 0;
            if(0 != o){
                l = 1;
            }
            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++;
            int n = Double.valueOf(number1 / coursePackage.getNeedNum()).intValue() + l;
            for (int i = 0; i < n; i++) {
                CoursePackageScheduling coursePackageScheduling = list1.get(i);
                coursePackageSchedulingService.getBaseMapper().deleteById(coursePackageScheduling.getId());
                coursePackageStudentService.getBaseMapper().delete(new QueryWrapper<CoursePackageStudent>()
                        .eq("coursePackageSchedulingId", coursePackageScheduling.getId()));
                }
            }
        }
//        TCoursePackage tCoursePackage = tcpmapper.selectById(req.getCourseId());
        // 添加课包
        TCoursePackagePayment tCoursePackagePayment1 = new TCoursePackagePayment();
//        tCoursePackagePayment1.setAppUserId(userId);
//        Student student = studentClient.queryDefaultStudent(userId);
//        // student ID
//
//        Integer sId=null;
//        if(student!=null){
//            tCoursePackagePayment1.setStudentId(student.getId());
//            sId=student.getId();
//        }
        tCoursePackagePayment1.setCoursePackageId(tCoursePackage.getId());
        tCoursePackagePayment1.setStudentId(req.getStuId());
        tCoursePackagePayment1.setPayType(7);
        tCoursePackagePayment1.setClassHours(req.getNum());
        tCoursePackagePayment1.setOriginalPrice(0.0);
        tCoursePackagePayment1.setTotalClassHours(req.getNum());
        tCoursePackagePayment1.setLaveClassHours(req.getNum());
        tCoursePackagePayment1.setAbsencesNumber(0);
        tCoursePackagePayment1.setPayUserType(1);
        tCoursePackagePayment1.setPayStatus(2);
        tCoursePackagePayment1.setPayUserId(userId);
        tCoursePackagePayment1.setStatus(1);
        tCoursePackagePayment1.setAppUserId(userId);
        tCoursePackagePayment1.setState(1);
        tCoursePackagePayment1.setInsertTime(new Date());
        this.baseMapper.insert(tCoursePackagePayment1);
        // 找出课包时间段
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String classStartTime = tCoursePackage.getClassStartTime();
        String classEndTime = tCoursePackage.getClassEndTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String classStartTime = coursePackage1.getClassStartTime();
        String classEndTime = coursePackage1.getClassEndTime();
        String[] split5 = classStartTime.split(",");
        String[] split6 = classEndTime.split(",");
        List<String> time = req.getTime();
        for (String s : time) {
            for (int i = 0; i < split5.length; i++) {
                CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                coursePackageScheduling.setType(3);
                coursePackageScheduling.setAppUserId(userId);
                coursePackageScheduling.setStudentId(req.getStuId());
                coursePackageScheduling.setCoursePackageId(req.getCourseId());
                try {
                    Date parse = format.parse(s + " " + split5[i]);
                    Date parse1 = format.parse(s + " " + split6[i]);
@@ -1546,8 +1471,8 @@
                    CoursePackageStudent student1 = new CoursePackageStudent();
                    student1.setAppUserId(userId);
                    student1.setStudentId(req.getStuId());
                    student1.setCoursePackageId(tCoursePackage.getId());
                    student1.setCoursePackagePaymentId(tCoursePackagePayment1.getId());
                    student1.setCoursePackageId(req.getCourseId());
                    student1.setCoursePackagePaymentId(coursePackageOrderStudent.getId());
                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                    student1.setSignInOrNot(1);
                    student1.setReservationStatus(1);
@@ -1561,19 +1486,12 @@
            }
        }
        coursePackageOrderStudent.setLaveClassHours(coursePackageOrderStudent.getLaveClassHours() - req.getNum());
        coursePackageOrderStudentService.updateById(coursePackageOrderStudent);
        // 2.0
//        TCourseInfoRecord tCourseInfoRecord = new TCourseInfoRecord();
//        tCourseInfoRecord.setUserId(userId);
//        tCourseInfoRecord.setCourseId(req.getCourseId());
//        tCourseInfoRecord.setName("体验购课");
//        tCourseInfoRecord.setNum(req.getNum());
//        tCourseInfoRecord.setTime(new Date());
//        tCourseInfoRecord.setType(2);
//        appuClient.addCourseInfoRecord(tCourseInfoRecord);
        CourseCounsum courseCounsum = new CourseCounsum();
        courseCounsum.setPaymentId(tCoursePackagePayment.getId());
        courseCounsum.setPaymentId(coursePackageOrderStudent.getId());
        courseCounsum.setChangeType(0);
        courseCounsum.setNum(req.getNum());
        courseCounsum.setInsertTime(new Date());
@@ -1582,8 +1500,7 @@
        courseCounsumService.save(courseCounsum);
        if(tCoursePackagePayment.getLaveClassHours()<=3){
        if (coursePackageOrderStudent.getLaveClassHours() <= 3) {
            Integer appUserId = userId;
            //调用推送
@@ -1617,7 +1534,6 @@
    public boolean updateHoursById(TCoursePackagePayment byId, int i) {
        return this.baseMapper.updateHoursById1(byId.getId(),i);
    }
    public static Date[] generateDateArray(int numDays,Date date) {