| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @PostMapping(value = "/delete") |
| | | public R delete(String ids) { |
| | | String[] split = ids.split(","); |
| | | List<Integer> courseIds = new ArrayList<>(); |
| | | for (String id : split) { |
| | | |
| | | courseService.removeById(id); |
| | | coursePartService.remove(Wrappers.lambdaQuery(TCoursePart.class).eq(TCoursePart::getCourseId,id)); |
| | | courseCommentService.remove(Wrappers.lambdaQuery(TCourseComment.class).eq(TCourseComment::getCourseId,id)); |
| | | |
| | | courseIds.add(Integer.parseInt(id)); |
| | | } |
| | | courseService.removeBatchByIds(courseIds); |
| | | coursePartService.remove(Wrappers.lambdaQuery(TCoursePart.class).in(TCoursePart::getCourseId,courseIds)); |
| | | courseCommentService.remove(Wrappers.lambdaQuery(TCourseComment.class).in(TCourseComment::getCourseId,courseIds)); |
| | | return R.ok(); |
| | | } |
| | | //编辑 |
| | |
| | | @PostMapping(value = "/list") |
| | | public R<Page<TCourse>> list(@RequestBody CourseQuery informationQuery) { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | Page<TCourse> page = courseService.lambdaQuery() |
| | | .like(!StringUtils.isEmpty(informationQuery.getName()), TCourse::getCourseName, informationQuery.getName()) |
| | | .eq(informationQuery.getRegionId() != null, TCourse::getRegionId, informationQuery.getRegionId()) |
| | | .eq(informationQuery.getTechnicalId() != null, TCourse::getTechnicalId, informationQuery.getTechnicalId()) |
| | | .eq(informationQuery.getMajorId() != null, TCourse::getMajorId, informationQuery.getMajorId()) |
| | | .eq(informationQuery.getLevel() != null, TCourse::getLevel, informationQuery.getLevel()) |
| | | .orderByDesc(TCourse::getCommitteeSort) |
| | | .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize())); |
| | | |
| | | Page<TCourse> page; |
| | | if (informationQuery.getSortType()==1){ |
| | | page = courseService.lambdaQuery() |
| | | .like(!StringUtils.isEmpty(informationQuery.getName()), TCourse::getCourseName, informationQuery.getName()) |
| | | .eq(informationQuery.getRegionId() != null, TCourse::getRegionId, informationQuery.getRegionId()) |
| | | .eq(informationQuery.getTechnicalId() != null, TCourse::getTechnicalId, informationQuery.getTechnicalId()) |
| | | .eq(informationQuery.getMajorId() != null, TCourse::getMajorId, informationQuery.getMajorId()) |
| | | .eq(informationQuery.getLevel() != null, TCourse::getLevel, informationQuery.getLevel()) |
| | | .orderByDesc(TCourse::getCreateTime) |
| | | .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize())); |
| | | }else { |
| | | page = courseService.lambdaQuery() |
| | | .like(!StringUtils.isEmpty(informationQuery.getName()), TCourse::getCourseName, informationQuery.getName()) |
| | | .eq(informationQuery.getRegionId() != null, TCourse::getRegionId, informationQuery.getRegionId()) |
| | | .eq(informationQuery.getTechnicalId() != null, TCourse::getTechnicalId, informationQuery.getTechnicalId()) |
| | | .eq(informationQuery.getMajorId() != null, TCourse::getMajorId, informationQuery.getMajorId()) |
| | | .eq(informationQuery.getLevel() != null, TCourse::getLevel, informationQuery.getLevel()) |
| | | .orderByDesc(TCourse::getCommitteeSort) |
| | | .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize())); |
| | | } |
| | | |
| | | Set<Long> cacheSet = redisCache.getCacheSet("COURSE:" + userId); |
| | | |
| | | for (TCourse record : page.getRecords()) { |
| | | TRegion byId = regionService.getById(record.getRegionId()); |
| | | record.setRegionName(byId.getProvinceName()+"-"+byId.getName()); |
| | | TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId() ); |
| | | TTitleMajor byId2 = majorService.getById(record.getMajorId()); |
| | | record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName()); |
| | | List<TCourse> records = page.getRecords(); |
| | | List<Long> technicalId = records.stream().map(TCourse::getTechnicalId).collect(Collectors.toList()); |
| | | List<TTechnicalTitle> tTechnicalTitles = tTechnicalTitleService.lambdaQuery().in(TTechnicalTitle::getId, technicalId).list(); |
| | | List<Long> majorId = records.stream().map(TCourse::getMajorId).collect(Collectors.toList()); |
| | | List<TTitleMajor> tTitleMajors = majorService.lambdaQuery().in(TTitleMajor::getId, majorId).list(); |
| | | List<Integer> regionId = records.stream().map(TCourse::getRegionId).collect(Collectors.toList()); |
| | | List<TRegion> regions = regionService.lambdaQuery().in(TRegion::getId,regionId).list(); |
| | | List<Long> ids = records.stream().map(TCourse::getId).collect(Collectors.toList()); |
| | | List<TOrder> orders = orderService.lambdaQuery() |
| | | .eq(TOrder::getGoodType, 1) |
| | | .eq(TOrder::getPaymentStatus, 2) |
| | | .in(TOrder::getGoodId, ids).list(); |
| | | for (TCourse record : records) { |
| | | TTechnicalTitle tTechnicalTitle = tTechnicalTitles.stream().filter(e -> e.getId().equals(record.getTechnicalId())).findFirst().orElse(null); |
| | | TTitleMajor tTitleMajor = tTitleMajors.stream().filter(e -> e.getId().equals(record.getMajorId())).findFirst().orElse(null); |
| | | TRegion region = regions.stream().filter(e -> e.getId().equals(record.getRegionId())).findFirst().orElse(null); |
| | | record.setRegionName(region.getProvinceName()+"-"+region.getName()); |
| | | record.setTechnicalName(tTechnicalTitle.getTitileName()+"-"+tTitleMajor.getMajorName()); |
| | | if (cacheSet!=null){ |
| | | if (cacheSet.contains(record.getId())){ |
| | | record.setIsCollect(1); |
| | |
| | | }else { |
| | | record.setStudyNum(cacheSet1.size()); |
| | | } |
| | | |
| | | int count = orders.stream().filter(e -> e.getGoodId().equals(record.getId())).collect(Collectors.toList()).size(); |
| | | record.setBuyNum(count); |
| | | } |
| | | return R.ok(page); |
| | | } |
| | |
| | | @PostMapping(value = "/other") |
| | | public R<List<TCourse>> other(@RequestParam Long id) { |
| | | List<TCourse> list = courseService.lambdaQuery().ne(TCourse::getId, id).last("limit 3").list(); |
| | | |
| | | List<Integer> regionId = list.stream().map(TCourse::getRegionId).collect(Collectors.toList()); |
| | | List<TRegion> regions = regionService.lambdaQuery().in(TRegion::getId,regionId).list(); |
| | | List<Long> technicalId = list.stream().map(TCourse::getTechnicalId).collect(Collectors.toList()); |
| | | List<TTechnicalTitle> tTechnicalTitles = tTechnicalTitleService.lambdaQuery().in(TTechnicalTitle::getId,technicalId).list(); |
| | | List<Long> majorId = list.stream().map(TCourse::getMajorId).collect(Collectors.toList()); |
| | | List<TTitleMajor> tTitleMajors = majorService.lambdaQuery().in(TTitleMajor::getId,majorId).list(); |
| | | for (TCourse record : list) { |
| | | TRegion byId = regionService.getById(record.getRegionId()); |
| | | record.setRegionName(byId.getProvinceName()+"-"+byId.getName()); |
| | | TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId() ); |
| | | TTitleMajor byId2 = majorService.getById(record.getMajorId()); |
| | | record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName()); |
| | | TRegion region = regions.stream().filter(e -> e.getId().equals(record.getRegionId())).findFirst().orElse(null); |
| | | TTechnicalTitle tTechnicalTitle = tTechnicalTitles.stream().filter(e -> e.getId().equals(record.getTechnicalId())).findFirst().orElse(null); |
| | | TTitleMajor tTitleMajor = tTitleMajors.stream().filter(e -> e.getId().equals(record.getMajorId())).findFirst().orElse(null); |
| | | record.setRegionName(region.getProvinceName()+"-"+region.getName()); |
| | | record.setTechnicalName(tTechnicalTitle.getTitileName()+"-"+tTitleMajor.getMajorName()); |
| | | } |
| | | return R.ok(list); |
| | | } |
| | |
| | | |
| | | TCourse record = courseService.getById(courseId); |
| | | |
| | | TRegion byId = regionService.getById(record.getRegionId()); |
| | | record.setRegionName(byId.getProvinceName()+"-"+byId.getName()); |
| | | TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId() ); |
| | | TTitleMajor byId2 = majorService.getById(record.getMajorId()); |
| | | record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName()); |
| | | TRegion region = regionService.getById(record.getRegionId()); |
| | | record.setRegionName(region.getProvinceName()+"-"+region.getName()); |
| | | TTechnicalTitle technicalTitle = tTechnicalTitleService.getById(record.getTechnicalId() ); |
| | | TTitleMajor tTitleMajor = majorService.getById(record.getMajorId()); |
| | | record.setTechnicalName(technicalTitle.getTitileName()+"-"+tTitleMajor.getMajorName()); |
| | | |
| | | |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | |
| | | record.setIsPay(0); |
| | | } |
| | | |
| | | Set<Object> cacheSet1 = redisCache.getCacheSet("STUDY:" + courseId); |
| | | if (cacheSet1==null){ |
| | | Set<Object> studySet = redisCache.getCacheSet("STUDY:" + courseId); |
| | | if (studySet==null){ |
| | | record.setStudyNum(0); |
| | | }else { |
| | | record.setStudyNum(cacheSet1.size()); |
| | | record.setStudyNum(studySet.size()); |
| | | } |
| | | |
| | | Set<Object> cacheSet2 = redisCache.getCacheSet("COLLECT:" + courseId); |
| | | if (cacheSet2==null){ |
| | | Set<Object> collectSet = redisCache.getCacheSet("COLLECT:" + courseId); |
| | | if (collectSet==null){ |
| | | record.setCollectNum(0); |
| | | }else { |
| | | record.setCollectNum(cacheSet2.size()); |
| | | record.setCollectNum(collectSet.size()); |
| | | } |
| | | |
| | | return R.ok(record); |
| | |
| | | @PostMapping(value = "/view") |
| | | public R view(Long courseId) { |
| | | |
| | | TCourse byId = courseService.getById(courseId); |
| | | byId.setVisitNum(byId.getVisitNum()+1); |
| | | courseService.updateById(byId); |
| | | TCourse course = courseService.getById(courseId); |
| | | course.setVisitNum(course.getVisitNum()+1); |
| | | courseService.updateById(course); |
| | | return R.ok(); |
| | | |
| | | } |
| | |
| | | @PostMapping(value = "/create") |
| | | public R buy( @RequestParam Long id) throws AlipayApiException { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | TCourse byId = courseService.getById(id); |
| | | TCourse course = courseService.getById(id); |
| | | |
| | | String code = "KC" + WeChatUtil.generateTradeNumber(); |
| | | TOrder order = new TOrder(); |
| | |
| | | order.setUserId(userId); |
| | | order.setGoodType(1); |
| | | order.setGoodId(id); |
| | | order.setOrderAmount(byId.getCoursePrice()); |
| | | order.setPaymentAmount(byId.getCoursePrice()); |
| | | if (byId.getCoursePrice().compareTo(new BigDecimal(0))==0){ |
| | | order.setOrderAmount(course.getCoursePrice()); |
| | | order.setPaymentAmount(course.getCoursePrice()); |
| | | if (course.getCoursePrice().compareTo(new BigDecimal(0))==0){ |
| | | order.setPaymentStatus(2); |
| | | |
| | | } |
| | |
| | | @ApiOperation(value = "购买",tags = {"web教学视频查询"}) |
| | | @PostMapping(value = "/buy") |
| | | public R<PayDto> buy(@RequestParam Integer type, @RequestParam Long orderId) throws AlipayApiException { |
| | | TOrder byId = orderService.getById(orderId); |
| | | TOrder order = orderService.getById(orderId); |
| | | if (type == 1) { |
| | | com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest prepayRequest = new com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest(); |
| | | prepayRequest.setAppid(weChatConfig.appId); |
| | | prepayRequest.setMchid(weChatConfig.merchantId); |
| | | prepayRequest.setOutTradeNo(byId.getCode()); |
| | | prepayRequest.setOutTradeNo(order.getCode()); |
| | | prepayRequest.setDescription("购买课程"); |
| | | prepayRequest.setNotifyUrl("http://www.zhipingwang.com.cn:8081/call-back/buy"); |
| | | prepayRequest.setNotifyUrl("https://0ifzoxq2516g.guyubao.com/call-back/buy"); |
| | | com.wechat.pay.java.service.payments.nativepay.model.Amount amount = new com.wechat.pay.java.service.payments.nativepay.model.Amount(); |
| | | amount.setTotal(byId.getPaymentAmount().multiply(new BigDecimal(100)).intValue()); |
| | | amount.setTotal(order.getPaymentAmount().multiply(new BigDecimal(100)).intValue()); |
| | | prepayRequest.setAmount(amount); |
| | | // 调用下单方法,得到应答 |
| | | PrepayResponse response; |
| | |
| | | } |
| | | return null; |
| | | } else { |
| | | String qrCode = AlipayTradePagePay.pay("购买课程",byId.getCode(),byId.getPaymentAmount().toString()); |
| | | String qrCode = AlipayTradePagePay.pay("购买课程",order.getCode(),order.getPaymentAmount().toString()); |
| | | PayDto payDto = new PayDto(); |
| | | payDto.setOrderId(orderId); |
| | | payDto.setQrCode(qrCode); |
| | |
| | | while (num <= 30) { |
| | | int min = 2000; |
| | | Thread.sleep(min); |
| | | Boolean check = AlipayTradeQuery.check(byId.getCode()); |
| | | Boolean check = AlipayTradeQuery.check(order.getCode()); |
| | | if (check){ |
| | | byId.setPaymentStatus(2); |
| | | byId.setPaymentType(2); |
| | | byId.setPayTime(LocalDateTime.now()); |
| | | orderService.updateById(byId); |
| | | order.setPaymentStatus(2); |
| | | order.setPaymentType(2); |
| | | order.setPayTime(LocalDateTime.now()); |
| | | orderService.updateById(order); |
| | | |
| | | if (byId.getGoodType()==1){ |
| | | if (order.getGoodType()==1){ |
| | | try { |
| | | TCourse byId1 = courseService.getById(byId.getGoodId()); |
| | | TCourse byId1 = courseService.getById(order.getGoodId()); |
| | | byId1.setBuyNum(byId1.getBuyNum()+1); |
| | | courseService.updateById(byId1); |
| | | }catch (Exception e){ |
| | |
| | | |
| | | if (!cacheSet.isEmpty()) { |
| | | Page<TCourse> page = courseService.lambdaQuery().in(TCourse::getId, cacheSet).page(Page.of(basePage.getPageNum(), basePage.getPageSize())); |
| | | for (TCourse record : page.getRecords()) { |
| | | Set<Object> cacheSet1 = redisCache.getCacheSet("STUDY:" + record.getId()); |
| | | if (cacheSet1==null){ |
| | | record.setStudyNum(0); |
| | | }else { |
| | | record.setStudyNum(cacheSet1.size()); |
| | | } |
| | | } |
| | | return R.ok(page); |
| | | }else { |
| | | return R.ok(new Page<>()); |