|
|
@@ -27,10 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -100,16 +97,34 @@ public class DianzhongConfigServiceImpl implements IDianzhongConfigService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void movieImageToOss() {
|
|
|
+ List<DianzhongMovieConfig> movieConfigs = dianzhongConfigMapper.toUploadImageList();
|
|
|
+ for (DianzhongMovieConfig config : movieConfigs) {
|
|
|
+ String coverImgUrl = config.getCoverImgUrl();
|
|
|
+ if (StringUtils.isEmpty(coverImgUrl) || StringUtils.isEmpty(config.getMovieId())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String ossUrl = toOssUrl(coverImgUrl);
|
|
|
+ if (StringUtils.isEmpty(ossUrl) || Objects.equals(ossUrl, coverImgUrl)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ config.setCoverImgUrl(ossUrl);
|
|
|
+ log.info("点众剧目封面图片上传OSS成功,movieId: {}, url: {}", config.getMovieId(), ossUrl);
|
|
|
+ dianzhongConfigMapper.updateMovieImage(config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void pullMoviePage(int offset, int limit) throws IOException {
|
|
|
log.info("拉取: 点众剧目,offset: {}, limit: {}", offset, limit);
|
|
|
String url = "https://vip.wqxsw.com/admin/referral/book/index?sort=idx&order=desc&offset="+offset+"&limit="+limit+"&filter=%7B%7D&op=%7B%7D&_="+System.currentTimeMillis();
|
|
|
//免费付费剧目ID相同,拉一次就可以
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
- headers.put("Cookie", "PHPSESSID=a2t3dp59hn92sjm0a7spe82b2s; keeplogin=29581%7C604800%7C1755853777%7Cea024be2fbc5c0604c25514f216e178f");
|
|
|
+ headers.put("Cookie", "PHPSESSID=rugckd38052ap4nolfddg8hqb0; keeplogin=29581%7C604800%7C1756117312%7Cb3589600a14a145812da60e005c31943");
|
|
|
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
headers.put("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
headers.put("x-requested-with", "XMLHttpRequest");
|
|
|
-
|
|
|
+ headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0");
|
|
|
String res = HttpUtils.httpGet(url, null, headers);
|
|
|
if (StringUtils.isNotEmpty(res)){
|
|
|
pullMovieInfo(res);
|
|
|
@@ -127,12 +142,17 @@ public class DianzhongConfigServiceImpl implements IDianzhongConfigService {
|
|
|
if (rows==null || rows.isEmpty()){
|
|
|
return;
|
|
|
}
|
|
|
+ List<String> movieIds = dianzhongConfigMapper.getAllMovieIds();
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
JSONObject minfo = rows.getJSONObject(i);
|
|
|
+ String movieId = minfo.getString("bookId");
|
|
|
+ if (movieIds.contains(movieId)){ //已经录入过的 跳过
|
|
|
+ continue;
|
|
|
+ }
|
|
|
DianzhongMovieConfig config = new DianzhongMovieConfig();
|
|
|
- config.setMovieId(minfo.getString("bookId"));
|
|
|
+ config.setMovieId(movieId);
|
|
|
config.setMovieName(minfo.getString("bookName"));
|
|
|
- config.setCoverImgUrl(minfo.getString("coverCutWap"));
|
|
|
+ config.setCoverImgUrl(toOssUrl(minfo.getString("coverCutWap")));
|
|
|
config.setChapterCount(minfo.getInteger("totalChapterNum"));
|
|
|
config.setFreeChapterCount(minfo.getInteger("freeChapterNum"));
|
|
|
config.setType1(minfo.getString("bookTypeOne"));
|
|
|
@@ -142,8 +162,29 @@ public class DianzhongConfigServiceImpl implements IDianzhongConfigService {
|
|
|
config.setInfoJson(minfo.toJSONString());
|
|
|
|
|
|
dianzhongConfigMapper.insertConfigSelective(config);
|
|
|
+ movieIds.add(movieId);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ private String toOssUrl(String fileUrl){
|
|
|
+ try {
|
|
|
+ String url = "https://api.deepthink.artlinkworld.cn/ossUp/uploadFileByUrl";
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("url", fileUrl);
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
+ if (StringUtils.isEmpty(s)){
|
|
|
+ log.error("点众封面图片上传OSS失败,url: {}", fileUrl);
|
|
|
+ return fileUrl;
|
|
|
+ }
|
|
|
+ JSONObject res = JSON.parseObject(s);
|
|
|
+ if (res.getInteger("code") != 200 && res.getInteger("code")!= 0){
|
|
|
+ log.error("点众封面图片上传OSS失败,url: {}, msg: {}", fileUrl, res.getString("msg"));
|
|
|
+ return fileUrl;
|
|
|
+ }
|
|
|
+ return res.getString("result");
|
|
|
+ }catch (Exception ignored){
|
|
|
+ return fileUrl;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|