From 5c95fc57ad4017535d887e2c8245b91e145c9cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 26 Dec 2024 22:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CourseServiceImpl.java | 846 +++++++++--------- 1 file changed, 425 insertions(+), 421 deletions(-) diff --git a/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java b/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java index 48edf0d3..88f10b1a 100644 --- a/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java @@ -1,5 +1,6 @@ package com.sqx.modules.course.service.impl; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; @@ -76,7 +77,7 @@ public class CourseServiceImpl extends ServiceImpl implements new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - private static boolean sys=false; + private static boolean sys = false; @Override public Result insertCourse(Course course) { @@ -87,15 +88,15 @@ public class CourseServiceImpl extends ServiceImpl implements course.setCreateTime(df.format(new Date())); //设置更新时间 course.setUpdateTime(df.format(new Date())); - if(course.getCourseType().equals(2) || course.getCourseType().equals(3)){ + if (course.getCourseType().equals(2) || course.getCourseType().equals(3)) { baseMapper.insert(course); - CourseDetails courseDetails=new CourseDetails(); + CourseDetails courseDetails = new CourseDetails(); courseDetails.setCourseId(course.getCourseId()); courseDetails.setVideoUrl(course.getRemark()); courseDetails.setViewCount(0L); courseDetails.setPlayCompleteCount(0L); courseDetailsDao.insert(courseDetails); - }else{ + } else { baseMapper.insert(course); } return Result.success("操作成功!"); @@ -114,15 +115,15 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result selectCourse(Integer page, Integer limit, Long classifyId, String title,Integer isRecommend,Integer status, - Long bannerId,Integer sort,String token, Integer isPrice,Integer admin, Integer over, - Integer wxCourse,Integer dyCourse,Integer wxShow,Integer dyShow) { - Long userId=null; - if(admin==null){ - if(StringUtils.isNotEmpty(token)){ + public Result selectCourse(Integer page, Integer limit, Long classifyId, String title, Integer isRecommend, Integer status, + Long bannerId, Integer sort, String token, Integer isPrice, Integer admin, Integer over, + Integer wxCourse, Integer dyCourse, Integer wxShow, Integer dyShow) { + Long userId = null; + if (admin == null) { + if (StringUtils.isNotEmpty(token)) { Claims claims = jwtUtils.getClaimByToken(token); - if(claims != null && !jwtUtils.isTokenExpired(claims.getExpiration())){ - userId=Long.parseLong(claims.getSubject()); + if (claims != null && !jwtUtils.isTokenExpired(claims.getExpiration())) { + userId = Long.parseLong(claims.getSubject()); } } } @@ -135,72 +136,73 @@ public class CourseServiceImpl extends ServiceImpl implements calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0); - String startTime=sdf.format(calendar.getTime()); + String startTime = sdf.format(calendar.getTime()); // 一周第一天为周日,所以此处为下一周第一天 - calendar.setWeekDate(calendar.getWeekYear(), calendar.get(Calendar.WEEK_OF_YEAR)+1, 1); + calendar.setWeekDate(calendar.getWeekYear(), calendar.get(Calendar.WEEK_OF_YEAR) + 1, 1); calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59); - String endTime=sdf.format(calendar.getTime()); - if(admin==null){ + String endTime = sdf.format(calendar.getTime()); + if (admin == null) { IPage> mapIPage = baseMapper.selectCourse(pages, classifyId, title, isRecommend, status, bannerId, - sort, startTime, endTime, userId, isPrice, over,wxCourse,dyCourse,wxShow,dyShow); + sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse, wxShow, dyShow); sort = ObjectUtil.defaultIfNull(sort, 0); List> records = mapIPage.getRecords(); - if(sort != null && sort == 1){ - records = records.stream().sorted(Comparator.comparingLong(item -> (long)ObjectUtil.defaultIfNull(item.get("goodNum"),0L))).collect(Collectors.toList()); + if (sort != null && sort == 1) { + records = records.stream().sorted(Comparator.comparingLong(item -> Convert.toLong(item.get("goodNum")))).collect(Collectors.toList()); Collections.reverse(records); } - if(sort != null && sort == 2){ - records = records.stream().sorted(Comparator.comparingLong(item -> (long)ObjectUtil.defaultIfNull(item.get("weekGoodNum"),0L))).collect(Collectors.toList()); + if (sort != null && sort == 2) { + records = records.stream().sorted(Comparator.comparingLong(item -> Convert.toLong(item.get("weekGoodNum")))).collect(Collectors.toList()); Collections.reverse(records); } - for (Map map:records){ + for (Map map : records) { Object courseDetailsId = map.get("courseDetailsId"); Object courseId = map.get("courseId"); - if(courseDetailsId!=null){ + if (courseDetailsId != null) { CourseDetails courseDetails = courseDetailsDao.selectById(Long.parseLong(String.valueOf(courseDetailsId))); - if(courseDetails!=null){ - map.put("courseDetailsName",courseDetails.getCourseDetailsName()); - map.put("dyEpisodeId",courseDetails.getDyEpisodeId()); - map.put("wxCourseDetailsId",courseDetails.getWxCourseDetailsId()); + if (courseDetails != null) { + map.put("courseDetailsName", courseDetails.getCourseDetailsName()); + map.put("dyEpisodeId", courseDetails.getDyEpisodeId()); + map.put("wxCourseDetailsId", courseDetails.getWxCourseDetailsId()); } - }else{ + } else { //默认取第一集 CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("course_id", courseId) .orderByAsc("sort").last(" limit 1")); - if(courseDetails!=null){ - map.put("courseDetailsId",courseDetails.getCourseDetailsId()); - map.put("courseDetailsName",courseDetails.getCourseDetailsName()); - map.put("dyEpisodeId",courseDetails.getDyEpisodeId()); - map.put("wxCourseDetailsId",courseDetails.getWxCourseDetailsId()); + if (courseDetails != null) { + map.put("courseDetailsId", courseDetails.getCourseDetailsId()); + map.put("courseDetailsName", courseDetails.getCourseDetailsName()); + map.put("dyEpisodeId", courseDetails.getDyEpisodeId()); + map.put("wxCourseDetailsId", courseDetails.getWxCourseDetailsId()); } } } return Result.success().put("data", new PageUtils(mapIPage)); } IPage> mapIPage = baseMapper.selectCourseAdmin(pages, classifyId, title, isRecommend, status, bannerId, - sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse,wxShow,dyShow); + sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse, wxShow, dyShow); List> records = mapIPage.getRecords(); - if(sort != null && sort == 1){ - records = records.stream().sorted(Comparator.comparingLong(item -> (long)ObjectUtil.defaultIfNull(item.get("goodNum"),0L))).collect(Collectors.toList()); + sort = ObjectUtil.defaultIfNull(sort, 0); + if (sort != null && sort == 1) { + records = records.stream().sorted(Comparator.comparingLong(item -> Convert.toLong(item.get("goodNum")))).collect(Collectors.toList()); Collections.reverse(records); } - if(sort != null && sort == 2){ - records = records.stream().sorted(Comparator.comparingLong(item -> (long)ObjectUtil.defaultIfNull(item.get("weekGoodNum"),0L))).collect(Collectors.toList()); + if (sort != null && sort == 2) { + records = records.stream().sorted(Comparator.comparingLong(item -> Convert.toLong(item.get("weekGoodNum")))).collect(Collectors.toList()); Collections.reverse(records); } - for (Map map:records){ + for (Map map : records) { Object courseId = map.get("courseId"); //默认取第一集 CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("course_id", courseId) .orderByAsc("sort").last(" limit 1")); - if(courseDetails!=null){ - map.put("courseDetailsId",courseDetails.getCourseDetailsId()); - map.put("courseDetailsName",courseDetails.getCourseDetailsName()); - map.put("dyEpisodeId",courseDetails.getDyEpisodeId()); - map.put("wxCourseDetailsId",courseDetails.getWxCourseDetailsId()); + if (courseDetails != null) { + map.put("courseDetailsId", courseDetails.getCourseDetailsId()); + map.put("courseDetailsName", courseDetails.getCourseDetailsName()); + map.put("dyEpisodeId", courseDetails.getDyEpisodeId()); + map.put("wxCourseDetailsId", courseDetails.getWxCourseDetailsId()); } } return Result.success().put("data", new PageUtils(mapIPage)); @@ -235,16 +237,16 @@ public class CourseServiceImpl extends ServiceImpl implements }*/ @Override - public Result selectCourseById(Integer page,Integer limit,Long id,Integer good) { - Page pages=new Page<>(page,limit); - return Result.success().put("data", new PageUtils(courseDetailsDao.selectCoursePageByCourseId(pages,id,good))); + public Result selectCourseById(Integer page, Integer limit, Long id, Integer good) { + Page pages = new Page<>(page, limit); + return Result.success().put("data", new PageUtils(courseDetailsDao.selectCoursePageByCourseId(pages, id, good))); } @Override public Result selectCourseTitle(Integer page, Integer limit, String title, Long userId) { //分页 Page> pages = new Page<>(page, limit); - if(userId!=null){ + if (userId != null) { //记录或更新搜索内容 appSearchService.insetAppSearch(title, userId); } @@ -260,20 +262,20 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result synCourse(){ - if(sys){ + public Result synCourse() { + if (sys) { return Result.error("视频正在同步中,请稍等!"); } - sys=true; + sys = true; singleThreadPool.submit(new Runnable() { @Override public void run() { try { String value = commonInfoService.findOne(250).getValue(); String s = HttpClientUtil.doGet(value); - log.error("返回值:"+s); + log.error("返回值:" + s); JSONArray jsonArray = JSONArray.parseArray(s); - for (int i=2;i implements String picurl = jsonObject.getString("picurl"); String description = jsonObject.getString("description"); Course course = baseMapper.selectOne(new QueryWrapper().eq("title", cname)); - if(course==null){ - course=new Course(); + if (course == null) { + course = new Course(); course.setTitle(cname); course.setTitleImg(picurl); course.setPrice(BigDecimal.ZERO); @@ -297,7 +299,7 @@ public class CourseServiceImpl extends ServiceImpl implements course.setIsPrice(2); course.setViewCounts(0); baseMapper.insert(course); - }else{ + } else { course.setTitle(cname); course.setTitleImg(picurl); course.setImg(picurl); @@ -305,8 +307,8 @@ public class CourseServiceImpl extends ServiceImpl implements baseMapper.updateById(course); } Integer count = courseDetailsDao.selectCount(new QueryWrapper().eq("course_details_name", name)); - if(count==0){ - CourseDetails courseDetails=new CourseDetails(); + if (count == 0) { + CourseDetails courseDetails = new CourseDetails(); courseDetails.setCourseId(course.getCourseId()); courseDetails.setCourseDetailsName(name); courseDetails.setVideoUrl(m3u8url); @@ -319,7 +321,7 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetails.setViewCount(0L); courseDetails.setPlayCompleteCount(0L); courseDetailsDao.insert(courseDetails); - }else{ + } else { CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("course_details_name", name).last(" limit 1")); courseDetails.setCourseDetailsName(name); courseDetails.setVideoUrl(m3u8url); @@ -329,11 +331,11 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetailsDao.updateById(courseDetails); } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - log.error("同步视频出错:"+e.getMessage(),e); - }finally { - sys=false; + log.error("同步视频出错:" + e.getMessage(), e); + } finally { + sys = false; } } }); @@ -341,13 +343,13 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result updateCourseDetails(String ids,BigDecimal price,String content,String titleImg){ - for (String id:ids.split(",")){ + public Result updateCourseDetails(String ids, BigDecimal price, String content, String titleImg) { + for (String id : ids.split(",")) { CourseDetails courseDetails = courseDetailsDao.selectById(Long.parseLong(id)); courseDetails.setPrice(price); - if(price.doubleValue()==0){ + if (price.doubleValue() == 0) { courseDetails.setIsPrice(2); - }else{ + } else { courseDetails.setIsPrice(1); } courseDetails.setContent(content); @@ -358,8 +360,8 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result updateCourseStatus(String ids, Integer status){ - for (String id:ids.split(",")){ + public Result updateCourseStatus(String ids, Integer status) { + for (String id : ids.split(",")) { Course course = baseMapper.selectById(Long.parseLong(id)); course.setStatus(status); baseMapper.updateById(course); @@ -368,26 +370,25 @@ public class CourseServiceImpl extends ServiceImpl implements } - @Override - public Result deleteCourseByIds(String ids){ - for (String id:ids.split(",")){ + public Result deleteCourseByIds(String ids) { + for (String id : ids.split(",")) { baseMapper.deleteById(Long.parseLong(id)); - courseDetailsDao.delete(new QueryWrapper().eq("course_id",Long.parseLong(id))); + courseDetailsDao.delete(new QueryWrapper().eq("course_id", Long.parseLong(id))); } return Result.success(); } @Override - public Result deleteCourseDetailsByIds(String ids){ - for (String id:ids.split(",")){ + public Result deleteCourseDetailsByIds(String ids) { + for (String id : ids.split(",")) { courseDetailsDao.deleteById(Long.parseLong(id)); } return Result.success(); } @Override - public Result courseNotify(Long userId, Long courseId, Long courseDetailsId){ + public Result courseNotify(Long userId, Long courseId, Long courseDetailsId) { CourseUser courseUser = new CourseUser(); //设置短剧id courseUser.setCourseId(courseId); @@ -402,31 +403,31 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result dyVideoUpload(Long courseId){ + public Result dyVideoUpload(Long courseId) { uploadVideo(courseId); return Result.success(); } @Async - public void uploadVideo(Long courseId){ + public void uploadVideo(Long courseId) { try { String appid = commonInfoService.findOne(805).getValue(); Course course = baseMapper.selectById(courseId); List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper().eq("course_id", courseId)); - if(StringUtils.isEmpty(course.getDyImgId())){ + if (StringUtils.isEmpty(course.getDyImgId())) { //上传短剧封面图 - String imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("resource_type",2); - jsonObject.put("ma_app_id",appid); - JSONObject image_meta=new JSONObject(); - image_meta.put("url",course.getTitleImg()); - jsonObject.put("image_meta",image_meta); + String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("resource_type", 2); + jsonObject.put("ma_app_id", appid); + JSONObject image_meta = new JSONObject(); + image_meta.put("url", course.getTitleImg()); + jsonObject.put("image_meta", image_meta); String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); String err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:"+jsonObject1.toJSONString()); - if("0".equals(err_no)){ + log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); + if ("0".equals(err_no)) { JSONObject data = jsonObject1.getJSONObject("data"); JSONObject image_result = data.getJSONObject("image_result"); String open_pic_id = image_result.getString("open_pic_id"); @@ -434,32 +435,32 @@ public class CourseServiceImpl extends ServiceImpl implements baseMapper.updateById(course); } } - if(StringUtils.isEmpty(course.getDyCourseId())){ + if (StringUtils.isEmpty(course.getDyCourseId())) { //创建短剧 - String url="https://open.douyin.com/api/playlet/v2/video/create/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("ma_app_id",appid); - JSONObject album_info=new JSONObject(); - album_info.put("title",course.getTitle()); - album_info.put("seq_num",courseDetailsList.size()); - JSONArray cover_list=new JSONArray(); + String url = "https://open.douyin.com/api/playlet/v2/video/create/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("ma_app_id", appid); + JSONObject album_info = new JSONObject(); + album_info.put("title", course.getTitle()); + album_info.put("seq_num", courseDetailsList.size()); + JSONArray cover_list = new JSONArray(); cover_list.add(course.getDyImgId()); - album_info.put("cover_list",cover_list); - album_info.put("year",DateUtils.format(new Date(),"yyyy")); - album_info.put("album_status","3"); - album_info.put("recommendation",course.getTitle()); - album_info.put("desp",course.getDetails()); - JSONArray tag_list=new JSONArray(); - if(course.getCourseLabelIds()!=null ){ + album_info.put("cover_list", cover_list); + album_info.put("year", DateUtils.format(new Date(), "yyyy")); + album_info.put("album_status", "3"); + album_info.put("recommendation", course.getTitle()); + album_info.put("desp", course.getDetails()); + JSONArray tag_list = new JSONArray(); + if (course.getCourseLabelIds() != null) { String[] split = course.getCourseLabelIds().split(","); - for (String tag:split){ + for (String tag : split) { tag_list.add(tag); - if(tag_list.size()==3){ + if (tag_list.size() == 3) { break; } } } - album_info.put("tag_list",tag_list); + album_info.put("tag_list", tag_list); /*if(StringUtils.isNotEmpty(course.getLicenseNum()) || StringUtils.isNotEmpty(course.getRegistrationNum()) || StringUtils.isNotEmpty(course.getKeyRecordNum()) || StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ album_info.put("qualification","1"); @@ -477,69 +478,69 @@ public class CourseServiceImpl extends ServiceImpl implements }else{ }*/ - album_info.put("qualification","1"); - JSONObject record_audit_info=new JSONObject(); - JSONObject record_material=new JSONObject(); - record_material.put("name",course.getTitle()); - record_material.put("duration",course.getDuration()); - record_material.put("seqs_count",courseDetailsList.size()); - record_material.put("production_organisation",course.getProductionOrganisation()); + album_info.put("qualification", "1"); + JSONObject record_audit_info = new JSONObject(); + JSONObject record_material = new JSONObject(); + record_material.put("name", course.getTitle()); + record_material.put("duration", course.getDuration()); + record_material.put("seqs_count", courseDetailsList.size()); + record_material.put("production_organisation", course.getProductionOrganisation()); String director = course.getDirector(); String[] directors = director.split(","); - record_material.put("director",directors); + record_material.put("director", directors); String producer = course.getProducer(); String[] producers = producer.split(","); - record_material.put("producer",producers); + record_material.put("producer", producers); String actor = course.getActor(); String[] actors = actor.split(","); - record_material.put("actor",actors); - record_material.put("summary",course.getSummary()); + record_material.put("actor", actors); + record_material.put("summary", course.getSummary()); - String imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject imageJSON=new JSONObject(); - imageJSON.put("resource_type",2); - imageJSON.put("ma_app_id",appid); - JSONObject image_meta=new JSONObject(); - image_meta.put("url",course.getCostDistributionUri()); - imageJSON.put("image_meta",image_meta); + String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + JSONObject imageJSON = new JSONObject(); + imageJSON.put("resource_type", 2); + imageJSON.put("ma_app_id", appid); + JSONObject image_meta = new JSONObject(); + image_meta.put("url", course.getCostDistributionUri()); + imageJSON.put("image_meta", image_meta); String s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); String err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:"+jsonObject1.toJSONString()); - if("0".equals(err_no)){ + log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); + if ("0".equals(err_no)) { JSONObject data = jsonObject1.getJSONObject("data"); JSONObject image_result = data.getJSONObject("image_result"); String open_pic_id = image_result.getString("open_pic_id"); - record_material.put("cost_distribution_uri",open_pic_id); + record_material.put("cost_distribution_uri", open_pic_id); } - imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - imageJSON=new JSONObject(); - imageJSON.put("resource_type",2); - imageJSON.put("ma_app_id",appid); - image_meta=new JSONObject(); - image_meta.put("url",course.getAssuranceUri()); - imageJSON.put("image_meta",image_meta); + imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + imageJSON = new JSONObject(); + imageJSON.put("resource_type", 2); + imageJSON.put("ma_app_id", appid); + image_meta = new JSONObject(); + image_meta.put("url", course.getAssuranceUri()); + imageJSON.put("image_meta", image_meta); s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); jsonObject1 = JSONObject.parseObject(s); err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:"+jsonObject1.toJSONString()); - if("0".equals(err_no)){ + log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); + if ("0".equals(err_no)) { JSONObject data = jsonObject1.getJSONObject("data"); JSONObject image_result = data.getJSONObject("image_result"); String open_pic_id = image_result.getString("open_pic_id"); - record_material.put("assurance_uri",open_pic_id); + record_material.put("assurance_uri", open_pic_id); } - record_material.put("playlet_production_cost",course.getPlayletProductionCost()); - record_audit_info.put("record_material",record_material); - album_info.put("record_audit_info",record_audit_info); - jsonObject.put("album_info",album_info); + record_material.put("playlet_production_cost", course.getPlayletProductionCost()); + record_audit_info.put("record_material", record_material); + album_info.put("record_audit_info", record_audit_info); + jsonObject.put("album_info", album_info); s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); jsonObject1 = JSONObject.parseObject(s); err_no = jsonObject1.getString("err_no"); - log.info("抖音创建短剧:"+jsonObject1.toJSONString()); - if("0".equals(err_no)){ + log.info("抖音创建短剧:" + jsonObject1.toJSONString()); + if ("0".equals(err_no)) { JSONObject data = jsonObject1.getJSONObject("data"); String album_id = data.getString("album_id"); course.setDyCourseId(album_id); @@ -547,28 +548,28 @@ public class CourseServiceImpl extends ServiceImpl implements } } //上传视频 - for (CourseDetails courseDetails:courseDetailsList){ + for (CourseDetails courseDetails : courseDetailsList) { - if(StringUtils.isEmpty(courseDetails.getDyCourseDetailsId()) || courseDetails.getDyUrlStatus()==3){ - String imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("resource_type",1); - jsonObject.put("ma_app_id",appid); - JSONObject video_meta=new JSONObject(); - video_meta.put("url",courseDetails.getVideoUrl()); - video_meta.put("title",courseDetails.getCourseDetailsName()); - video_meta.put("description",courseDetails.getContent()); - if(courseDetails.getVideoUrl().contains(".mp4")){ - video_meta.put("format","mp4"); - }else{ - video_meta.put("format","m3u8"); + if (StringUtils.isEmpty(courseDetails.getDyCourseDetailsId()) || courseDetails.getDyUrlStatus() == 3) { + String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("resource_type", 1); + jsonObject.put("ma_app_id", appid); + JSONObject video_meta = new JSONObject(); + video_meta.put("url", courseDetails.getVideoUrl()); + video_meta.put("title", courseDetails.getCourseDetailsName()); + video_meta.put("description", courseDetails.getContent()); + if (courseDetails.getVideoUrl().contains(".mp4")) { + video_meta.put("format", "mp4"); + } else { + video_meta.put("format", "m3u8"); } - jsonObject.put("video_meta",video_meta); + jsonObject.put("video_meta", video_meta); String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); - log.info("抖音上传短剧视频:"+jsonObject1.toJSONString()); + log.info("抖音上传短剧视频:" + jsonObject1.toJSONString()); String err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { continue; } JSONObject data = jsonObject1.getJSONObject("data"); @@ -578,20 +579,20 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetails.setDyUrlStatus(1); courseDetailsDao.updateById(courseDetails); } - if(StringUtils.isEmpty(courseDetails.getDyImgId())){ + if (StringUtils.isEmpty(courseDetails.getDyImgId())) { //上传短剧封面图 - String imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("resource_type",2); - jsonObject.put("ma_app_id",appid); - JSONObject image_meta=new JSONObject(); - image_meta.put("url",courseDetails.getTitleImg()); - jsonObject.put("image_meta",image_meta); + String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("resource_type", 2); + jsonObject.put("ma_app_id", appid); + JSONObject image_meta = new JSONObject(); + image_meta.put("url", courseDetails.getTitleImg()); + jsonObject.put("image_meta", image_meta); String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); - log.info("抖音上传短剧视频封面:"+jsonObject1.toJSONString()); + log.info("抖音上传短剧视频封面:" + jsonObject1.toJSONString()); String err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { continue; } JSONObject data = jsonObject1.getJSONObject("data"); @@ -601,25 +602,25 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetailsDao.updateById(courseDetails); } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - log.error("抖音上传视频出错:"+e.getMessage(),e); + log.error("抖音上传视频出错:" + e.getMessage(), e); } } @Override - public Result dyVideoAudit(Long courseId){ + public Result dyVideoAudit(Long courseId) { String appid = commonInfoService.findOne(805).getValue(); Course course = baseMapper.selectById(courseId); - String url="https://open.douyin.com/api/playlet/v2/video/review/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("album_id",course.getDyCourseId()); - jsonObject.put("ma_app_id",appid); + String url = "https://open.douyin.com/api/playlet/v2/video/review/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("album_id", course.getDyCourseId()); + jsonObject.put("ma_app_id", appid); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); String err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(jsonObject1.getString("err_msg")); } JSONObject data = jsonObject1.getJSONObject("data"); @@ -631,17 +632,17 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result dyVideoUp(Long courseId){ + public Result dyVideoUp(Long courseId) { Course course = baseMapper.selectById(courseId); - String url="https://open.douyin.com/api/playlet/v2/album/online/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("album_id",course.getDyCourseId()); - jsonObject.put("operate","2"); - jsonObject.put("version",course.getDyVersion()); + String url = "https://open.douyin.com/api/playlet/v2/album/online/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("album_id", course.getDyCourseId()); + jsonObject.put("operate", "2"); + jsonObject.put("version", course.getDyVersion()); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); String err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(jsonObject1.getString("err_msg")); } course.setDyStatus(4); @@ -650,100 +651,101 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result setDyNotifyUrl(String notifyUrl){ - notifyUrl+="/sqx_fast/app/course/notifyUrl"; - String url="https://open.douyin.com/api/industry/v1/solution/set_impl"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("operator","管理员"); - jsonObject.put("release_reason","配置短剧回调地址"); - JSONArray industry_impl_list=new JSONArray(); - JSONObject jsonObject1=new JSONObject(); - jsonObject1.put("template_id",20001); - JSONArray open_ability_impl_list=new JSONArray(); - JSONObject jsonObject2=new JSONObject(); - jsonObject2.put("ability_identity","/msg/playlet/review/notify"); - jsonObject2.put("is_delete",false); - jsonObject2.put("test_url",notifyUrl); - jsonObject2.put("prod_url",notifyUrl); - jsonObject2.put("ability_type","2"); - jsonObject2.put("impl_name","短剧回调消息实现配置"); + public Result setDyNotifyUrl(String notifyUrl) { + notifyUrl += "/sqx_fast/app/course/notifyUrl"; + String url = "https://open.douyin.com/api/industry/v1/solution/set_impl"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("operator", "管理员"); + jsonObject.put("release_reason", "配置短剧回调地址"); + JSONArray industry_impl_list = new JSONArray(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("template_id", 20001); + JSONArray open_ability_impl_list = new JSONArray(); + JSONObject jsonObject2 = new JSONObject(); + jsonObject2.put("ability_identity", "/msg/playlet/review/notify"); + jsonObject2.put("is_delete", false); + jsonObject2.put("test_url", notifyUrl); + jsonObject2.put("prod_url", notifyUrl); + jsonObject2.put("ability_type", "2"); + jsonObject2.put("impl_name", "短剧回调消息实现配置"); open_ability_impl_list.add(jsonObject2); - jsonObject1.put("open_ability_impl_list",open_ability_impl_list); + jsonObject1.put("open_ability_impl_list", open_ability_impl_list); industry_impl_list.add(jsonObject1); - jsonObject.put("industry_impl_list",industry_impl_list); - jsonObject.put("app_config_item_list",new JSONArray()); + jsonObject.put("industry_impl_list", industry_impl_list); + jsonObject.put("app_config_item_list", new JSONArray()); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - log.error("抖音设置回调域名返回值:"+s); + log.error("抖音设置回调域名返回值:" + s); JSONObject jsonObject3 = JSONObject.parseObject(s); JSONObject data = jsonObject3.getJSONObject("data"); String err_no = data.getString("error_code"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(data.getString("description")); } return Result.success(); } @Override - public JSONObject notifyUrl(JSONObject jsonObject){ - log.info("抖音视频回调:"+jsonObject.toJSONString()); + public JSONObject notifyUrl(JSONObject jsonObject) { + log.info("抖音视频回调:" + jsonObject.toJSONString()); String type = jsonObject.getString("type"); JSONObject msg = jsonObject.getJSONObject("msg"); - if("upload_video".equals(type)){ + if ("upload_video".equals(type)) { String open_video_id = msg.getString("open_video_id"); String success = msg.getString("success"); CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_course_details_id", open_video_id)); - if(courseDetails!=null){ - if("true".equals(success)){ + if (courseDetails != null) { + if ("true".equals(success)) { courseDetails.setDyUrlStatus(2); - }else{ + } else { courseDetails.setDyUrlStatus(3); } courseDetailsDao.updateById(courseDetails); //获取是否所有的集都上传成功 如果成功 则添加集 Integer count = courseDetailsDao.selectCount(new QueryWrapper() - .eq("course_id",courseDetails.getCourseId()).in("dy_url_status", 1, 3)); - log.info("count"+count); - if(count==0){ + .eq("course_id", courseDetails.getCourseId()).in("dy_url_status", 1, 3)); + log.info("count" + count); + if (count == 0) { videoEdit(courseDetails); } } - }else if("album_audit".equals(type)){ + } else if ("album_audit".equals(type)) { String album_id = msg.getString("album_id"); Course course = baseMapper.selectOne(new QueryWrapper().eq("dy_course_id", album_id)); - if(course!=null){ + if (course != null) { String audit_status = msg.getString("audit_status"); - if("1".equals(audit_status)){ + if ("1".equals(audit_status)) { course.setDyStatus(3); course.setDyStatusContent(msg.getString("audit_msg")); - }else{ + } else { course.setDyStatus(2); course.setDyVersion(msg.getString("version")); } baseMapper.updateById(course); } - }if("episode_audit".equals(type)){ + } + if ("episode_audit".equals(type)) { String episode_id = msg.getString("episode_id"); CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_episode_id", episode_id)); - if(courseDetails!=null){ + if (courseDetails != null) { String audit_status = msg.getString("audit_status"); - if("1".equals(audit_status)){ + if ("1".equals(audit_status)) { courseDetails.setDyStatus(3); courseDetails.setDyStatusContent(msg.getString("audit_msg")); - }else{ + } else { courseDetails.setDyStatus(2); courseDetails.setDyVersion(msg.getString("version")); } courseDetailsDao.updateById(courseDetails); } } - JSONObject result=new JSONObject(); - result.put("err_no",0); - result.put("err_tips","success"); + JSONObject result = new JSONObject(); + result.put("err_no", 0); + result.put("err_tips", "success"); return result; } @Async - public void videoEdit(CourseDetails courseDetails){ + public void videoEdit(CourseDetails courseDetails) { //这里进行延迟操作 抖音不允许并发操作 try { Thread.sleep(5000); @@ -756,27 +758,27 @@ public class CourseServiceImpl extends ServiceImpl implements .eq("course_id", courseDetails.getCourseId()).orderByAsc("create_time")); String appid = commonInfoService.findOne(805).getValue(); Course course = baseMapper.selectById(courseDetails.getCourseId()); - String url="https://open.douyin.com/api/playlet/v2/video/edit/"; - JSONObject jsonObject1=new JSONObject(); - jsonObject1.put("album_id",course.getDyCourseId()); - jsonObject1.put("ma_app_id",appid); - int num=1; - JSONArray episode_info_list=new JSONArray(); - while (true){ + String url = "https://open.douyin.com/api/playlet/v2/video/edit/"; + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("album_id", course.getDyCourseId()); + jsonObject1.put("ma_app_id", appid); + int num = 1; + JSONArray episode_info_list = new JSONArray(); + while (true) { - CourseDetails courseDetails1 = courseDetailsList.get(num-1); - JSONObject episode=new JSONObject(); - episode.put("title",courseDetails1.getCourseDetailsName()); - episode.put("seq",num); - JSONArray cover_list=new JSONArray(); + CourseDetails courseDetails1 = courseDetailsList.get(num - 1); + JSONObject episode = new JSONObject(); + episode.put("title", courseDetails1.getCourseDetailsName()); + episode.put("seq", num); + JSONArray cover_list = new JSONArray(); cover_list.add(courseDetails1.getDyImgId()); - episode.put("cover_list",cover_list); - episode.put("open_video_id",courseDetails1.getDyCourseDetailsId()); + episode.put("cover_list", cover_list); + episode.put("open_video_id", courseDetails1.getDyCourseDetailsId()); episode_info_list.add(episode); - if(courseDetailsList.size()==num){ - jsonObject1.put("episode_info_list",episode_info_list); + if (courseDetailsList.size() == num) { + jsonObject1.put("episode_info_list", episode_info_list); String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); - log.info("绑定集:"+s); + log.info("绑定集:" + s); JSONObject jsonObject2 = JSONObject.parseObject(s); JSONObject data = jsonObject2.getJSONObject("data"); JSONObject episode_id_map = data.getJSONObject("episode_id_map"); @@ -790,11 +792,11 @@ public class CourseServiceImpl extends ServiceImpl implements } break; } - if(episode_info_list.size()%100==0){ - jsonObject1.put("episode_info_list",episode_info_list); + if (episode_info_list.size() % 100 == 0) { + jsonObject1.put("episode_info_list", episode_info_list); String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject2 = JSONObject.parseObject(s); - log.info("绑定集100:"+s); + log.info("绑定集100:" + s); JSONObject data = jsonObject2.getJSONObject("data"); JSONObject episode_id_map = data.getJSONObject("episode_id_map"); Map map = new HashMap<>(episode_id_map); @@ -805,7 +807,7 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetails2.setDyEpisodeId(String.valueOf(value)); courseDetailsDao.updateById(courseDetails2); } - episode_info_list=new JSONArray(); + episode_info_list = new JSONArray(); } num++; } @@ -815,28 +817,28 @@ public class CourseServiceImpl extends ServiceImpl implements } catch (InterruptedException e) { e.printStackTrace(); } - url="https://open.douyin.com/api/playlet/v2/album/bind/"; - jsonObject1=new JSONObject(); - jsonObject1.put("schema_bind_type","1"); + url = "https://open.douyin.com/api/playlet/v2/album/bind/"; + jsonObject1 = new JSONObject(); + jsonObject1.put("schema_bind_type", "1"); - for (CourseDetails courseDetails1:courseDetailsList){ - JSONObject single_schema_bind=new JSONObject(); - single_schema_bind.put("album_id",course.getDyCourseId()); - single_schema_bind.put("episode_id",courseDetails1.getDyEpisodeId()); - single_schema_bind.put("path","me/detail/detail"); - JSONArray params=new JSONArray(); - JSONObject param1=new JSONObject(); - param1.put("key","id"); - param1.put("value",String.valueOf(course.getCourseId())); - JSONObject param2=new JSONObject(); - param2.put("key","courseDetailsId"); - param2.put("value",String.valueOf(courseDetails1.getCourseDetailsId())); + for (CourseDetails courseDetails1 : courseDetailsList) { + JSONObject single_schema_bind = new JSONObject(); + single_schema_bind.put("album_id", course.getDyCourseId()); + single_schema_bind.put("episode_id", courseDetails1.getDyEpisodeId()); + single_schema_bind.put("path", "me/detail/detail"); + JSONArray params = new JSONArray(); + JSONObject param1 = new JSONObject(); + param1.put("key", "id"); + param1.put("value", String.valueOf(course.getCourseId())); + JSONObject param2 = new JSONObject(); + param2.put("key", "courseDetailsId"); + param2.put("value", String.valueOf(courseDetails1.getCourseDetailsId())); params.add(param1); params.add(param2); - single_schema_bind.put("params",params); - jsonObject1.put("single_schema_bind",single_schema_bind); + single_schema_bind.put("params", params); + jsonObject1.put("single_schema_bind", single_schema_bind); String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); - log.info("绑定页面返回值:"+s); + log.info("绑定页面返回值:" + s); //每次绑定完页面后 延迟后进行操作 try { Thread.sleep(5000); @@ -848,27 +850,27 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result uploadCourseDetails(Long courseDetailsId){ + public Result uploadCourseDetails(Long courseDetailsId) { String appid = commonInfoService.findOne(805).getValue(); CourseDetails courseDetails = courseDetailsDao.selectById(courseDetailsId); - String imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject=new JSONObject(); - jsonObject.put("resource_type",1); - jsonObject.put("ma_app_id",appid); - JSONObject video_meta=new JSONObject(); - video_meta.put("url",courseDetails.getVideoUrl()); - video_meta.put("title",courseDetails.getCourseDetailsName()); - video_meta.put("description",courseDetails.getContent()); - if(courseDetails.getVideoUrl().contains("mp4")){ - video_meta.put("format","mp4"); - }else{ - video_meta.put("format","m3u8"); + String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("resource_type", 1); + jsonObject.put("ma_app_id", appid); + JSONObject video_meta = new JSONObject(); + video_meta.put("url", courseDetails.getVideoUrl()); + video_meta.put("title", courseDetails.getCourseDetailsName()); + video_meta.put("description", courseDetails.getContent()); + if (courseDetails.getVideoUrl().contains("mp4")) { + video_meta.put("format", "mp4"); + } else { + video_meta.put("format", "m3u8"); } - jsonObject.put("video_meta",video_meta); + jsonObject.put("video_meta", video_meta); String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject1 = JSONObject.parseObject(s); String err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(jsonObject1.getString("err_msg")); } JSONObject data = jsonObject1.getJSONObject("data"); @@ -878,17 +880,17 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetails.setDyUrlStatus(1); courseDetailsDao.updateById(courseDetails); //上传短剧封面图 - imgUrl="https://open.douyin.com/api/playlet/v2/resource/upload/"; - jsonObject=new JSONObject(); - jsonObject.put("resource_type",2); - jsonObject.put("ma_app_id",appid); - JSONObject image_meta=new JSONObject(); - image_meta.put("url",courseDetails.getTitleImg()); - jsonObject.put("image_meta",image_meta); + imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; + jsonObject = new JSONObject(); + jsonObject.put("resource_type", 2); + jsonObject.put("ma_app_id", appid); + JSONObject image_meta = new JSONObject(); + image_meta.put("url", courseDetails.getTitleImg()); + jsonObject.put("image_meta", image_meta); s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); jsonObject1 = JSONObject.parseObject(s); err_no = jsonObject1.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(jsonObject1.getString("err_msg")); } data = jsonObject1.getJSONObject("data"); @@ -900,61 +902,61 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result updateDyCourse(Course course){ + public Result updateDyCourse(Course course) { baseMapper.updateById(course); - if(course.getDyCourseId()!=null){ + if (course.getDyCourseId() != null) { //已经提交抖音 同步抖音 String appid = commonInfoService.findOne(805).getValue(); - String url="https://open.douyin.com/api/playlet/v2/video/edit/"; - JSONObject jsonObject1=new JSONObject(); - jsonObject1.put("album_id",course.getDyCourseId()); - jsonObject1.put("ma_app_id",appid); + String url = "https://open.douyin.com/api/playlet/v2/video/edit/"; + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("album_id", course.getDyCourseId()); + jsonObject1.put("ma_app_id", appid); List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper().eq("course_id", course.getCourseId())); - JSONObject album_info=new JSONObject(); - album_info.put("title",course.getTitle()); - album_info.put("seq_num",courseDetailsList.size()); - JSONArray cover_list=new JSONArray(); + JSONObject album_info = new JSONObject(); + album_info.put("title", course.getTitle()); + album_info.put("seq_num", courseDetailsList.size()); + JSONArray cover_list = new JSONArray(); cover_list.add(course.getDyImgId()); - album_info.put("cover_list",cover_list); - album_info.put("year",DateUtils.format(new Date(),"yyyy")); - album_info.put("album_status","3"); - album_info.put("recommendation",course.getTitle()); - album_info.put("desp",course.getDetails()); - JSONArray tag_list=new JSONArray(); - if(course.getCourseLabelIds()!=null ){ + album_info.put("cover_list", cover_list); + album_info.put("year", DateUtils.format(new Date(), "yyyy")); + album_info.put("album_status", "3"); + album_info.put("recommendation", course.getTitle()); + album_info.put("desp", course.getDetails()); + JSONArray tag_list = new JSONArray(); + if (course.getCourseLabelIds() != null) { String[] split = course.getCourseLabelIds().split(","); - for (String tag:split){ + for (String tag : split) { tag_list.add(tag); - if(tag_list.size()==3){ + if (tag_list.size() == 3) { break; } } } - album_info.put("tag_list",tag_list); - if(StringUtils.isNotEmpty(course.getLicenseNum()) || StringUtils.isNotEmpty(course.getRegistrationNum()) || - StringUtils.isNotEmpty(course.getKeyRecordNum()) || StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ - album_info.put("qualification","2"); - JSONObject record_info=new JSONObject(); - if(StringUtils.isNotEmpty(course.getLicenseNum())){ - record_info.put("license_num",course.getLicenseNum()); - }else if(StringUtils.isNotEmpty(course.getRegistrationNum())){ - record_info.put("registration_num",course.getRegistrationNum()); - }else if(StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ - record_info.put("ordinary_record_num",course.getOrdinaryRecordNum()); - }else{ - record_info.put("key_record_num",course.getKeyRecordNum()); + album_info.put("tag_list", tag_list); + if (StringUtils.isNotEmpty(course.getLicenseNum()) || StringUtils.isNotEmpty(course.getRegistrationNum()) || + StringUtils.isNotEmpty(course.getKeyRecordNum()) || StringUtils.isNotEmpty(course.getOrdinaryRecordNum())) { + album_info.put("qualification", "2"); + JSONObject record_info = new JSONObject(); + if (StringUtils.isNotEmpty(course.getLicenseNum())) { + record_info.put("license_num", course.getLicenseNum()); + } else if (StringUtils.isNotEmpty(course.getRegistrationNum())) { + record_info.put("registration_num", course.getRegistrationNum()); + } else if (StringUtils.isNotEmpty(course.getOrdinaryRecordNum())) { + record_info.put("ordinary_record_num", course.getOrdinaryRecordNum()); + } else { + record_info.put("key_record_num", course.getKeyRecordNum()); } - album_info.put("record_info",record_info); - }else{ - album_info.put("qualification","1"); + album_info.put("record_info", record_info); + } else { + album_info.put("qualification", "1"); } - jsonObject1.put("album_info",album_info); - jsonObject1.put("episode_info_list",new JSONArray()); + jsonObject1.put("album_info", album_info); + jsonObject1.put("episode_info_list", new JSONArray()); String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); JSONObject jsonObject2 = JSONObject.parseObject(s); String err_no = jsonObject2.getString("err_no"); - if(!"0".equals(err_no)){ + if (!"0".equals(err_no)) { return Result.error(jsonObject2.getString("err_msg")); } } @@ -962,74 +964,75 @@ public class CourseServiceImpl extends ServiceImpl implements } @Override - public Result sysWxCourse(Integer freeNum, BigDecimal coursePrice,Integer maxGood,Integer minGood){ + public Result sysWxCourse(Integer freeNum, BigDecimal coursePrice, Integer maxGood, Integer minGood) { singleThreadPool.submit(() -> sysWxCourses(freeNum, coursePrice, maxGood, minGood)); return Result.success(); } - public void sysWxCourses(Integer freeNum, BigDecimal coursePrice,Integer maxGood,Integer minGood){ - try{ - int offset=0; + public void sysWxCourses(Integer freeNum, BigDecimal coursePrice, Integer maxGood, Integer minGood) { + try { + int offset = 0; String value = commonInfoService.findOne(887).getValue(); String http = commonInfoService.findOne(19).getValue(); Random rand = new Random(); - while (true){ - String url="https://api.weixin.qq.com/wxa/sec/vod/listdramas?access_token="+SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject=new JSONObject(); - jsonObject.put("offset",offset); - jsonObject.put("limit",100); + while (true) { + String url = "https://api.weixin.qq.com/wxa/sec/vod/listdramas?access_token=" + SenInfoCheckUtil.getMpToken(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("offset", offset); + jsonObject.put("limit", 100); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); JSONObject jsonObject1 = JSONObject.parseObject(s); - log.error("微信同步短剧返回值:"+jsonObject1.toJSONString()); + log.error("微信同步短剧返回值:" + jsonObject1.toJSONString()); String errcode = jsonObject1.getString("errcode"); - if(!"0".equals(errcode)){ - log.error("同步微信短剧失败:"+jsonObject1.getString("errmsg")); + if (!"0".equals(errcode)) { + log.error("同步微信短剧失败:" + jsonObject1.getString("errmsg")); break; } JSONArray drama_info_list = jsonObject1.getJSONArray("drama_info_list"); - if(drama_info_list==null || drama_info_list.size()==0){ + if (drama_info_list == null || drama_info_list.size() == 0) { break; } - for (int i=0;i().eq("title", name).eq("is_delete",0)); - if(course!=null){ + name = name.replace(" ", ""); + Course course = baseMapper.selectOne(new QueryWrapper().eq("title", name).eq("is_delete", 0)); + if (course != null) { course.setWxCourseId(jsonObject2.getString("drama_id")); baseMapper.updateById(course); - }else{ + } else { String[] split = value.split(","); int min = 0; // 指定范围的最小值(包含) - int max = split.length-1; // 指定范围的最大值(包含) + int max = split.length - 1; // 指定范围的最大值(包含) int randomNum1 = min + rand.nextInt(max - min + 1); int randomNum2 = min + rand.nextInt(max - min + 1); int randomNum3 = min + rand.nextInt(max - min + 1); - String courseLabel=split[randomNum1]+","+split[randomNum2]+","+split[randomNum3]; - String cover_url=jsonObject2.getString("cover_url"); + String courseLabel = split[randomNum1] + "," + split[randomNum2] + "," + split[randomNum3]; + String cover_url = jsonObject2.getString("cover_url"); //读取微信图片 保存到服务器本地 String[] splits = http.split("://"); // 上传文件路径 - String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/"+name+"/"+name+".jpg"; - File file=new File(filePath); + String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; + File file = new File(filePath); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } - HttpClientUtil.downloadImage(cover_url,filePath); - String img=http + "/file/uploadPath/duanju/"+name+"/" +name+".jpg";; + HttpClientUtil.downloadImage(cover_url, filePath); + String img = http + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; + ; - course=new Course(); + course = new Course(); course.setTitle(name); course.setTitleImg(img); course.setPrice(coursePrice); @@ -1050,68 +1053,70 @@ public class CourseServiceImpl extends ServiceImpl implements baseMapper.insert(course); } } - offset=offset+100; + offset = offset + 100; } //同步集 List courseList = baseMapper.selectList(new QueryWrapper().isNotNull("wx_course_id")); - for (Course course:courseList){ - offset=0; - while (true){ - String url="https://api.weixin.qq.com/wxa/sec/vod/listmedia?access_token="+SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject=new JSONObject(); - jsonObject.put("drama_id",Integer.parseInt(course.getWxCourseId())); - jsonObject.put("limit",100); - jsonObject.put("offset",offset); + for (Course course : courseList) { + offset = 0; + while (true) { + String url = "https://api.weixin.qq.com/wxa/sec/vod/listmedia?access_token=" + SenInfoCheckUtil.getMpToken(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("drama_id", Integer.parseInt(course.getWxCourseId())); + jsonObject.put("limit", 100); + jsonObject.put("offset", offset); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); JSONObject jsonObject1 = JSONObject.parseObject(s); String errcode = jsonObject1.getString("errcode"); - if(!"0".equals(errcode)){ - log.error("同步微信短剧集失败:"+jsonObject1.getString("errmsg")); + if (!"0".equals(errcode)) { + log.error("同步微信短剧集失败:" + jsonObject1.getString("errmsg")); break; } JSONArray media_info_list = jsonObject1.getJSONArray("media_info_list"); - if(media_info_list==null || media_info_list.size()==0){ + if (media_info_list == null || media_info_list.size() == 0) { break; } - int priceNum=media_info_list.size()-freeNum; + int priceNum = media_info_list.size() - freeNum; BigDecimal courseDetailsPrice = BigDecimal.ZERO; - if(priceNum>0){ + if (priceNum > 0) { courseDetailsPrice = coursePrice.divide(BigDecimal.valueOf(priceNum), 2, BigDecimal.ROUND_UP); } - for (int i=0;i() .eq("course_id", course.getCourseId()).like("course_details_name", name)); - if(courseDetails!=null){ + if (courseDetails != null) { courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); courseDetailsDao.updateById(courseDetails); - }else{ + } else { String cover_url = jsonObject2.getString("cover_url"); //读取微信图片 保存到服务器本地 String[] splits = http.split("://"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); // 上传文件路径 - String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/"+course.getTitle()+"/" +name+".jpg";; - File file=new File(filePath); + String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; + ; + File file = new File(filePath); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } - HttpClientUtil.downloadImage(cover_url,filePath); - String img=http + "/file/uploadPath/duanju/"+course.getTitle()+"/" +name+".jpg";; + HttpClientUtil.downloadImage(cover_url, filePath); + String img = http + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; + ; int goodNum = minGood + rand.nextInt(maxGood - minGood + 1); - courseDetails=new CourseDetails(); + courseDetails = new CourseDetails(); courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); courseDetails.setCourseId(course.getCourseId()); courseDetails.setCourseDetailsName(name); @@ -1121,10 +1126,10 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetails.setGoodNum(goodNum); courseDetails.setViewCount(0L); courseDetails.setPlayCompleteCount(0L); - if(i<=freeNum){ + if (i <= freeNum) { courseDetails.setPrice(BigDecimal.ZERO); courseDetails.setIsPrice(2); - }else{ + } else { courseDetails.setPrice(courseDetailsPrice); courseDetails.setIsPrice(1); } @@ -1132,32 +1137,32 @@ public class CourseServiceImpl extends ServiceImpl implements courseDetailsDao.insert(courseDetails); } } - offset=offset+100; + offset = offset + 100; } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - log.error("同步微信短剧失败:"+e.getMessage(),e); + log.error("同步微信短剧失败:" + e.getMessage(), e); } } @Override - public Result selectWxVideoUrl(String wxCourseDetailsIds){ - List> list=new ArrayList<>(); - for (String wxCourseDetailsIdStr:wxCourseDetailsIds.split(",")){ + public Result selectWxVideoUrl(String wxCourseDetailsIds) { + List> list = new ArrayList<>(); + for (String wxCourseDetailsIdStr : wxCourseDetailsIds.split(",")) { Long wxCourseDetailsId = Long.parseLong(wxCourseDetailsIdStr); - String url="https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token="+SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject=new JSONObject(); - jsonObject.put("media_id",wxCourseDetailsId); - jsonObject.put("t",(new Date().getTime()/1000)+7200); + String url = "https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token=" + SenInfoCheckUtil.getMpToken(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("media_id", wxCourseDetailsId); + jsonObject.put("t", (new Date().getTime() / 1000) + 7200); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); JSONObject jsonObject1 = JSONObject.parseObject(s); String errcode = jsonObject1.getString("errcode"); - if(!"0".equals(errcode)){ - log.error(wxCourseDetailsIdStr+" 获取微信播放链接失败:"+jsonObject1.getString("errmsg")); + if (!"0".equals(errcode)) { + log.error(wxCourseDetailsIdStr + " 获取微信播放链接失败:" + jsonObject1.getString("errmsg")); // return Result.error("获取微信播放链接失败:"+jsonObject1.getString("errmsg")); continue; } @@ -1165,20 +1170,20 @@ public class CourseServiceImpl extends ServiceImpl implements String duration = media_info.getString("duration"); String cover_url = media_info.getString("cover_url"); String mp4_url = media_info.getString("mp4_url"); - Map result=new HashMap<>(); - result.put("duration",duration); - result.put("cover_url",cover_url); - result.put("mp4_url",mp4_url); - result.put("wxCourseDetailsId",String.valueOf(wxCourseDetailsId)); + Map result = new HashMap<>(); + result.put("duration", duration); + result.put("cover_url", cover_url); + result.put("mp4_url", mp4_url); + result.put("wxCourseDetailsId", String.valueOf(wxCourseDetailsId)); list.add(result); } - return Result.success().put("data",list); + return Result.success().put("data", list); } @Override - public Result uploadWxCourse(Long courseId,Integer qualificationType,String registrationNumber, - String qualificationCertificateMaterialId,String costOfProduction,String costCommitmentLetterMaterialId){ - String url="https://api.weixin.qq.com/wxa/sec/vod/modifydramabasicinfo?access_token="+SenInfoCheckUtil.getMpToken(); + public Result uploadWxCourse(Long courseId, Integer qualificationType, String registrationNumber, + String qualificationCertificateMaterialId, String costOfProduction, String costCommitmentLetterMaterialId) { + String url = "https://api.weixin.qq.com/wxa/sec/vod/modifydramabasicinfo?access_token=" + SenInfoCheckUtil.getMpToken(); //储存信息 Course course = baseMapper.selectById(courseId); @@ -1190,25 +1195,24 @@ public class CourseServiceImpl extends ServiceImpl implements course.setWxCourseStatus(1); baseMapper.updateById(course); - JSONObject jsonObject=new JSONObject(); - jsonObject.put("drama_id",course.getWxCourseId()); - jsonObject.put("qualification_type",qualificationType); - jsonObject.put("registration_number",registrationNumber); - jsonObject.put("qualification_certificate_material_id",qualificationCertificateMaterialId); - jsonObject.put("cost_of_production",costOfProduction); - jsonObject.put("cost_commitment_letter_material_id",costCommitmentLetterMaterialId); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("drama_id", course.getWxCourseId()); + jsonObject.put("qualification_type", qualificationType); + jsonObject.put("registration_number", registrationNumber); + jsonObject.put("qualification_certificate_material_id", qualificationCertificateMaterialId); + jsonObject.put("cost_of_production", costOfProduction); + jsonObject.put("cost_commitment_letter_material_id", costCommitmentLetterMaterialId); String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); - log.error("提交微信备案审核:"+s); + log.error("提交微信备案审核:" + s); JSONObject jsonObject1 = JSONObject.parseObject(s); String errcode = jsonObject1.getString("errcode"); - if(!"0".equals(errcode)){ + if (!"0".equals(errcode)) { return Result.error(jsonObject1.getString("errmsg")); } return Result.success(); } - @Override public Result courseListExcelIn(MultipartFile file) throws IOException { List courseList = ExcelUtils.importExcel(file, 2, 1, CourseIn.class); @@ -1222,9 +1226,9 @@ public class CourseServiceImpl extends ServiceImpl implements //成功条数 int successIndex = 0; //空数据 - int emptyCount=0; + int emptyCount = 0; for (CourseIn courseIn : courseList) { - if(courseIn.getTitle()==null){ + if (courseIn.getTitle() == null) { emptyCount++; continue; } @@ -1256,12 +1260,12 @@ public class CourseServiceImpl extends ServiceImpl implements @Override public Result viewCourse(Long courseId, Long courseDetailsId, String type) { Course course = baseMapper.selectById(courseId); - if(course==null){ + if (course == null) { return Result.error("短剧不存在"); } CourseDetails details = courseDetailsDao.selectById(courseDetailsId); - if(details==null){ + if (details == null) { return Result.error("短剧集不存在"); }