| | |
| | | package com.dsh.course.service.impl; |
| | | |
| | | import com.dsh.course.entity.TCoursePackagePayment; |
| | | import com.dsh.course.mapper.TCoursePackagePaymentMapper; |
| | | import com.dsh.course.service.TCoursePackagePaymentService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.course.entity.*; |
| | | import com.dsh.course.feignclient.account.CoachClient; |
| | | import com.dsh.course.feignclient.account.model.Coach; |
| | | import com.dsh.course.feignclient.activity.BenefitVideoClient; |
| | | import com.dsh.course.feignclient.activity.model.BenefitsVideos; |
| | | import com.dsh.course.feignclient.other.StoreClient; |
| | | import com.dsh.course.feignclient.other.model.Store; |
| | | import com.dsh.course.mapper.*; |
| | | import com.dsh.course.model.dto.DiscountJsonDto; |
| | | 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.response.AppUserVideoResponse; |
| | | import com.dsh.course.model.vo.response.CourseDetailsResponse; |
| | | import com.dsh.course.model.vo.response.CourseOfVideoResponse; |
| | | import com.dsh.course.service.TCoursePackagePaymentService; |
| | | import com.dsh.course.util.ResultUtil; |
| | | import com.dsh.course.util.StrUtils; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TCoursePackagePaymentServiceImpl extends ServiceImpl<TCoursePackagePaymentMapper, TCoursePackagePayment> implements TCoursePackagePaymentService { |
| | | |
| | | |
| | | @Resource |
| | | private BenefitVideoClient bfvoClient; |
| | | |
| | | |
| | | @Resource |
| | | private UserVideoDetailsMapper uvdmapper; |
| | | |
| | | @Resource |
| | | private PostCourseVideoMapper pcvMapper; |
| | | |
| | | @Resource |
| | | private TCoursePackageMapper tcpmapper; |
| | | |
| | | @Resource |
| | | private StoreClient stoClient; |
| | | |
| | | @Resource |
| | | private CoachClient coachClient; |
| | | |
| | | @Resource |
| | | private CoursePackageStudentMapper cpsMapper; |
| | | |
| | | @Resource |
| | | private CancelledClassesMapper cacMapper; |
| | | |
| | | @Resource |
| | | private TCoursePackageDiscountMapper tcpdMapper; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取课包购买人数 |
| | | * @param coursePackageId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<TCoursePackagePayment> queryAllCoursePackage(Integer stuId,Integer appUserId) { |
| | | return this.baseMapper.queryAllCoursePackage(stuId,appUserId); |
| | | public Integer queryCountNumber(Integer coursePackageId) { |
| | | return this.baseMapper.queryCountNumber(coursePackageId); |
| | | } |
| | | |
| | | @Override |
| | | public List<AppUserVideoResponse> queryAfterVideo(CourseOfAfterRequest search,List<Integer> courseIds) { |
| | | List<AppUserVideoResponse> responses = new ArrayList<>(); |
| | | List<PostCourseVideo> videoList = pcvMapper.selectList(new QueryWrapper<PostCourseVideo>() |
| | | .eq("coursePackageId", courseIds)); |
| | | |
| | | if (videoList.size() > 0){ |
| | | List<Integer> videoIds = videoList.stream().map(PostCourseVideo::getCourseId).collect(Collectors.toList()); |
| | | List<UserVideoDetails> userVideoDetails = uvdmapper.selectList(new QueryWrapper<UserVideoDetails>() |
| | | .in("courseId", videoIds)); |
| | | if (userVideoDetails.size() > 0){ |
| | | for (UserVideoDetails userVideoDetail : userVideoDetails) { |
| | | AppUserVideoResponse response = new AppUserVideoResponse(); |
| | | TCoursePackage coursePackage = tcpmapper.selectById(userVideoDetail.getCoursePackageId()); |
| | | response.setPackageName(coursePackage.getName()); |
| | | response.setCoursePackageId(userVideoDetail.getCoursePackageId()); |
| | | BenefitsVideos videosWithIds = bfvoClient.getVideosWithIds(userVideoDetail.getCourseId()); |
| | | response.setVideoId(userVideoDetail.getCourseId()); |
| | | response.setCoverImage(videosWithIds.getCover()); |
| | | if (null != search.getSearch()){ |
| | | // 根据正则模糊匹配 |
| | | String pattern = ".*" + search.getSearch() + ".*"; |
| | | Pattern regex = Pattern.compile(pattern); |
| | | Matcher matcher = regex.matcher(videosWithIds.getName()); |
| | | if (matcher.matches()) { |
| | | response.setVideoName(videosWithIds.getName()); |
| | | } |
| | | }else { |
| | | response.setVideoName(videosWithIds.getName()); |
| | | } |
| | | response.setSynopsis(videosWithIds.getIntroduction()); |
| | | response.setIntegral(videosWithIds.getIntegral()); |
| | | response.setStudyStatus(userVideoDetail.getState()); |
| | | responses.add(response); |
| | | } |
| | | Collections.sort(responses, Comparator.comparing(AppUserVideoResponse::getStudyStatus)); |
| | | } |
| | | } |
| | | return responses; |
| | | } |
| | | |
| | | @Override |
| | | public CourseOfVideoResponse queryVideoDetails(CourseWithDetailsRequest detailsRequest,Integer appUserId) { |
| | | CourseOfVideoResponse response = new CourseOfVideoResponse(); |
| | | BenefitsVideos videosWithIds = bfvoClient.getVideosWithIds(detailsRequest.getVideoId()); |
| | | TCoursePackage coursePackage = tcpmapper.selectById(detailsRequest.getCoursePackageId()); |
| | | if (null != videosWithIds && null != coursePackage){ |
| | | response.setCoursePackageId(coursePackage.getId()); |
| | | response.setVideoId(videosWithIds.getId()); |
| | | response.setVideoURL(videosWithIds.getVideos()); |
| | | response.setVideoName(videosWithIds.getName()); |
| | | response.setIntegral(videosWithIds.getIntegral()); |
| | | UserVideoDetails userVideoDetails = uvdmapper.selectOne(new QueryWrapper<UserVideoDetails>() |
| | | .eq("appUserId",appUserId ) |
| | | .eq("coursePackageId",coursePackage.getId()) |
| | | .eq("courseId",videosWithIds.getId())); |
| | | |
| | | response.setStudyStatus(userVideoDetails.getState()); |
| | | response.setPackageName(coursePackage.getName()); |
| | | response.setSynopsis(videosWithIds.getIntroduction()); |
| | | response.setDetailedDiagram(coursePackage.getIntroduceDrawing()); |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | | public String updateVideoStatus(UpdateCourseVideoStatusRequest detailsRequest, Integer appUserId) { |
| | | UserVideoDetails userVideoDetails = uvdmapper.selectOne(new QueryWrapper<UserVideoDetails>() |
| | | .eq("appUserId",appUserId ) |
| | | .eq("coursePackageId",detailsRequest.getCoursePackageId()) |
| | | .eq("courseId",detailsRequest.getVideoId()) |
| | | ); |
| | | if (null != userVideoDetails && userVideoDetails.getState() ==1 && detailsRequest.getIsOver() == 1){ |
| | | userVideoDetails.setState(2); |
| | | userVideoDetails.setUpdateTime(new Date()); |
| | | uvdmapper.updateById(userVideoDetails); |
| | | return "SUCCESS"; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<RegisterCourseVo> queryRegisteredCourseList(CourseOfAfterRequest courseTypeId, Integer appUserId) { |
| | | List<RegisterCourseVo> courseVos = new ArrayList<>(); |
| | | List<TCoursePackagePayment> tCoursePackagePayments = this.list(new QueryWrapper<TCoursePackagePayment>() |
| | | .eq("appUserId",appUserId )); |
| | | if (tCoursePackagePayments.size() > 0){ |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | RegisterCourseVo registerCourseVo = new RegisterCourseVo(); |
| | | registerCourseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId()); |
| | | registerCourseVo.setPackageImg(coursePackage.getCoverDrawing()); |
| | | String storeAndCourse = coursePackage.getName()+"("+ store.getName() +")"; |
| | | registerCourseVo.setCourseNameStore(storeAndCourse); |
| | | registerCourseVo.setCourseTime(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime()); |
| | | Coach coach = coachClient.queryCoachById(coursePackage.getCoachId()); |
| | | registerCourseVo.setCourseTeacher(coach.getName()); |
| | | List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>() |
| | | .eq("coursePackageId",coursePackage.getId()) |
| | | .eq("studentId",appUserId )); |
| | | registerCourseVo.setCourseNums(coursePackageStudents.size() * 2); |
| | | registerCourseVo.setPayStatus(tCoursePackagePayment.getPayStatus()); |
| | | courseVos.add(registerCourseVo); |
| | | } |
| | | } |
| | | return courseVos; |
| | | } |
| | | |
| | | @Override |
| | | public CourseDetailsResponse queryRegisteredCourseDetails(Integer coursePackageId, Integer appUserId) { |
| | | CourseDetailsResponse response = new CourseDetailsResponse(); |
| | | List<TCoursePackagePayment> tCoursePackagePayments = this.list(new QueryWrapper<TCoursePackagePayment>() |
| | | .eq("coursePackageId",coursePackageId ) |
| | | .eq("appUserId",appUserId)); |
| | | |
| | | if (tCoursePackagePayments.size() > 0){ |
| | | TCoursePackagePayment tCoursePackagePayment = tCoursePackagePayments.get(0); |
| | | TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); |
| | | response.setCoursePackageId(tCoursePackagePayment.getCoursePackageId()); |
| | | response.setCoverDrawing(coursePackage.getCoverDrawing()); |
| | | response.setCoursePackageName(coursePackage.getName()); |
| | | List<Integer> integers = StrUtils.dealStrToList(coursePackage.getClassWeeks()); |
| | | 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; |
| | | } |
| | | } |
| | | if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == ','){ |
| | | courWeeks.deleteCharAt(courWeeks.length() - 1); |
| | | } |
| | | response.setWeeks(courWeeks.toString()); |
| | | } |
| | | response.setCourseTimeFrame(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime()); |
| | | response.setIntroduceDrawing(coursePackage.getIntroduceDrawing()); |
| | | |
| | | Integer payType = tCoursePackagePayment.getPayType(); |
| | | BigDecimal cashPayment = tCoursePackagePayment.getCashPayment(); |
| | | double cashPaymentValue = cashPayment.doubleValue(); |
| | | Integer playPaiCoin = tCoursePackagePayment.getPlayPaiCoin(); |
| | | TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>() |
| | | .eq("coursePackageId",coursePackage.getId() ) |
| | | .eq("type",1) |
| | | .eq("auditStatus",2)); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | String content = coursePackageDiscount.getContent(); |
| | | double discountMember = 0.0; |
| | | DiscountJsonDto discountJsonDto = null; |
| | | try { |
| | | discountJsonDto = objectMapper.readValue(content, DiscountJsonDto.class); |
| | | discountMember = discountJsonDto.getDiscountMember(); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | switch (payType) { |
| | | case 1: |
| | | case 2: |
| | | response.setAmount(cashPaymentValue); |
| | | response.setVipAmount(discountMember); |
| | | break; |
| | | case 3: |
| | | response.setWpGold(playPaiCoin); |
| | | break; |
| | | } |
| | | response.setPayStatus(tCoursePackagePayment.getPayStatus()); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil ContinuationOrpaymentCourse(Integer userIdFormRedis, ClasspaymentRequest request) { |
| | | // TODO: 2023/7/5 报名课程支付 |
| | | switch (request.getPayType()){ |
| | | case 1: |
| | | WeChatPayment(); |
| | | break; |
| | | case 2: |
| | | AlipayPayment(); |
| | | break; |
| | | case 3: |
| | | PlaypaiGoldPayment(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | public void WeChatPayment(){ |
| | | |
| | | } |
| | | |
| | | public void AlipayPayment(){ |
| | | |
| | | } |
| | | |
| | | public void PlaypaiGoldPayment(){ |
| | | |
| | | } |
| | | |
| | | } |