| | |
| | | package com.dsh.course.controller; |
| | | |
| | | |
| | | import cn.mb.cloud.common.data.controller.BaseController; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dsh.course.entity.TCourse; |
| | | import com.dsh.course.entity.TCoursePackagePayment; |
| | | import com.dsh.course.entity.TCoursePackageType; |
| | | import com.dsh.course.feignclient.model.ExerciseVideo; |
| | | import com.dsh.course.model.*; |
| | | import com.dsh.course.model.dto.CourseChangeStateDTO; |
| | | import com.dsh.course.model.dto.TQueryBenefitsVideosDTO; |
| | | import com.dsh.course.model.vo.TQueryBenefitsVideosVO; |
| | | import com.dsh.course.service.TCoursePackagePaymentService; |
| | | import com.dsh.course.service.TCoursePackageService; |
| | | import com.dsh.course.service.TCoursePackageTypeService; |
| | | import com.dsh.course.service.TCourseService; |
| | | import com.dsh.course.util.PageFactory; |
| | | import com.dsh.course.util.PayMoneyUtil; |
| | | import com.dsh.course.util.ResultUtil; |
| | | import com.dsh.course.util.TokenUtil; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Api |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping("") |
| | | public class CourseController { |
| | | public class CourseController extends BaseController { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger("business-log"); |
| | | |
| | |
| | | @Autowired |
| | | private TCoursePackageTypeService coursePackageTypeService; |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private TCoursePackagePaymentService coursePackagePaymentService; |
| | | |
| | | /** |
| | | * 上/下架 1为上架 2为下架 3为删除 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/course/changeState") |
| | | @ResponseBody |
| | | public Object changeState(@RequestBody CourseChangeStateDTO dto){ |
| | | |
| | | return courseService.changeState(dto); |
| | | } |
| | | |
| | | /** |
| | | * 通过课程ids获取课程 |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/course/getCourseByCourseIds") |
| | | public List<TQueryBenefitsVideosVO> getCourseByCourseIds(@RequestBody TQueryBenefitsVideosDTO query){ |
| | | |
| | | @PostMapping("/course/queryList") |
| | | return courseService.getCourseByCourseIds(query); |
| | | } |
| | | |
| | | @PostMapping("/base/course/queryList") |
| | | public List<ExerciseVideo> queryStuCourseAfterVideos(@RequestBody List<Integer> courseIds){ |
| | | List<ExerciseVideo> videos = new ArrayList<>(); |
| | | List<TCourse> list = courseService.list(new QueryWrapper<TCourse>() |
| | |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/course/queryCourseList") |
| | | @ApiOperation(value = "获取课程列表", tags = {"APP-课程列表"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CoursePackageListVo>> queryCourseList(@RequestBody CoursePackageList coursePackageList){ |
| | | public ResultUtil<List<CoursePackageListVo>> queryCourseList(CoursePackageList coursePackageList){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/course/queryCourseListOne") |
| | | @ApiOperation(value = "获取课程列表", tags = {"APP-课程列表"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CoursePackageListVo>> queryCourseListOne(CoursePackageList coursePackageList){ |
| | | try { |
| | | List<CoursePackageListVo> coursePackageListVos = coursePackageService.queryCourseListOne( coursePackageList); |
| | | return ResultUtil.success(coursePackageListVos); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/course/queryCourseInfo") |
| | | @ApiOperation(value = "获取课程详情", tags = {"APP-课程列表"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "课包id", name = "id", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = true), |
| | | @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true), |
| | | @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = false), |
| | | @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = false), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<CoursePackageInfo> queryCourseInfo(@RequestBody Integer id, @RequestBody String lon, @RequestBody String lat){ |
| | | public ResultUtil<CoursePackageInfo> queryCourseInfo(Integer id, String lon, String lat){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public ResultUtil paymentCourse(@RequestBody PaymentCourseVo paymentCourseVo){ |
| | | @ResponseBody |
| | | @PostMapping("/api/course/paymentCourse") |
| | | @ApiOperation(value = "支付课程", tags = {"APP-课程列表"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil paymentCourse(PaymentCourseVo paymentCourseVo){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Long couponId = paymentCourseVo.getCouponId(); |
| | | if(couponId==null || couponId==0){ |
| | | paymentCourseVo.setCouponId(null); |
| | | } |
| | | return coursePackageService.paymentCourse(uid, paymentCourseVo); |
| | | }catch (Exception e){ |
| | |
| | | } |
| | | } |
| | | |
| | | // 2.0 |
| | | @ResponseBody |
| | | @PostMapping("/api/course/paymentCourseCouponList") |
| | | @ApiOperation(value = "支付课程--完成后优惠券列表", tags = {"APP-课程列表"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil paymentCourseCouponList(Integer coursePackagePaymentConfigId){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | return coursePackageService.paymentCourseCouponList(uid, coursePackagePaymentConfigId); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 购买课程微信支付回调 |
| | | * @param request |
| | | * @param response |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/course/weChatPaymentCourseCallback") |
| | | public void weChatPaymentCourseCallback(HttpServletRequest request, HttpServletResponse response){ |
| | | try { |
| | | Map<String, String> map = payMoneyUtil.weixinpayCallback(request); |
| | | if(null != map){ |
| | | String code = map.get("out_trade_no"); |
| | | String transaction_id = map.get("transaction_id"); |
| | | String result = map.get("result"); |
| | | |
| | | List<TCoursePackagePayment> list = coursePackagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("state", 1).eq("code", code).eq("payType", 1)); |
| | | TCoursePackagePayment one = list.get(0); |
| | | if(one.getPayStatus() == 1){ |
| | | for (TCoursePackagePayment coursePackagePayment : list) { |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setOrderNumber(transaction_id); |
| | | } |
| | | coursePackagePaymentService.updateBatchById(list); |
| | | } |
| | | PrintWriter out = response.getWriter(); |
| | | out.write(result); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 购买课程支付宝回调 |
| | | * @param request |
| | | * @param response |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/course/aliPaymentCourseCallback") |
| | | public void aliPaymentCourseCallback(HttpServletRequest request, HttpServletResponse response){ |
| | | try { |
| | | Map<String, String> map = payMoneyUtil.alipayCallback(request); |
| | | if(null != map){ |
| | | String code = map.get("out_trade_no"); |
| | | String trade_no = map.get("trade_no"); |
| | | |
| | | List<TCoursePackagePayment> list = coursePackagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("state", 1).eq("code", code).eq("payType", 2)); |
| | | TCoursePackagePayment one = list.get(0); |
| | | if(one.getPayStatus() == 1){ |
| | | for (TCoursePackagePayment coursePackagePayment : list) { |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setOrderNumber(trade_no); |
| | | } |
| | | coursePackagePaymentService.updateBatchById(list); |
| | | } |
| | | PrintWriter out = response.getWriter(); |
| | | out.write("success"); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据id获取课程数据 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/queryCourseById") |
| | | public TCourse queryCourseById(@RequestBody Integer id){ |
| | | try { |
| | | return courseService.getById(id); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据名称获取数据 |
| | | * @param name |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/queryCourseByName") |
| | | public List<TCourse> queryCourseByName(@RequestBody String name){ |
| | | try { |
| | | return courseService.list(new QueryWrapper<TCourse>().like("name", name).eq("state", 1)); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取课程管理列表数据 |
| | | * @param queryCourseList |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/queryCourseLists") |
| | | public Page<Map<String, Object>> queryCourseLists(@RequestBody QueryCourseList queryCourseList){ |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryCourseList.getLimit(), queryCourseList.getOffset(), queryCourseList.getSort(), queryCourseList.getOrder()); |
| | | Page<Map<String, Object>> mapPage = page.setRecords(courseService.queryCourseList(page, queryCourseList)); |
| | | return mapPage; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加课程 |
| | | * @param course |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/addCourse") |
| | | public void addCourse(@RequestBody TCourse course){ |
| | | courseService.save(course); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编辑数据 |
| | | * @param course |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/editCourse") |
| | | public void editCourse(@RequestBody TCourse course){ |
| | | courseService.updateById(course); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除数据 |
| | | * @param id |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/delCourseById") |
| | | public void delCourseById(@RequestBody Integer id){ |
| | | TCourse course = courseService.getById(id); |
| | | if(null != course){ |
| | | course.setState(3); |
| | | courseService.updateById(course); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编辑数据状态 |
| | | * @param editCourseState |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/editCourseState") |
| | | public void editCourseState(@RequestBody EditCourseState editCourseState){ |
| | | TCourse course = courseService.getById(editCourseState.getId()); |
| | | if(null != course){ |
| | | course.setState(editCourseState.getState()); |
| | | courseService.updateById(course); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据类型获取数据 |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/course/queryCourseByType") |
| | | public List<TCourse> queryCourseByType(@RequestBody Integer type){ |
| | | return courseService.list(new QueryWrapper<TCourse>().eq("type", type).eq("state", 1)); |
| | | } |
| | | } |