|
|
|
@ -9,6 +9,7 @@ import com.ruoyi.quartz.domain.dto.*; |
|
|
|
|
import com.ruoyi.quartz.mapper.DouYinMapper; |
|
|
|
|
import com.ruoyi.quartz.service.DouYinService; |
|
|
|
|
import com.ruoyi.quartz.util.DouYinUTils; |
|
|
|
|
import org.apache.ibatis.annotations.Param; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
@ -20,6 +21,7 @@ import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author liangjiawei |
|
|
|
@ -263,30 +265,34 @@ public class DouYinServiceImpl implements DouYinService { |
|
|
|
|
@Override |
|
|
|
|
public void getDouYinVideoInfo() { |
|
|
|
|
List<DouYinAuthorizedInfoDTO> douYinAuthorizedInfoDTOList = this.getAllDouYinAuthorizedInfo(); |
|
|
|
|
int cursor = 0; |
|
|
|
|
Long cursor = 0L; |
|
|
|
|
int count = 10; |
|
|
|
|
int isResume = 0; |
|
|
|
|
List<DouYinVideoInFoDTO> addList = new ArrayList(); |
|
|
|
|
|
|
|
|
|
List<DouYinVideoInFoDTO> newAddList = new ArrayList(); |
|
|
|
|
for (DouYinAuthorizedInfoDTO item : douYinAuthorizedInfoDTOList) { |
|
|
|
|
while (isResume == 0) { |
|
|
|
|
JSONObject videoList = DouYinUTils.videoListURL(item.getOpenId(), cursor, count, item.getAccessToken()); |
|
|
|
|
JSONObject videoListDataJson = JSONObject.parseObject(videoList.toString()); |
|
|
|
|
if (videoListDataJson.get("error_code").equals("0")) { |
|
|
|
|
cursor = videoListDataJson.getByte("cursor"); |
|
|
|
|
if (!videoListDataJson.get("has_more").equals("true")) { |
|
|
|
|
JSONObject videoListDataJson = JSONObject.parseObject(videoList.get("data").toString()); |
|
|
|
|
if (videoListDataJson.get("error_code").toString().equals("0")) { |
|
|
|
|
cursor = Long.parseLong(videoListDataJson.get("cursor").toString()); |
|
|
|
|
if (videoListDataJson.get("has_more").toString().equals("false")) { |
|
|
|
|
isResume = 1; |
|
|
|
|
} |
|
|
|
|
//处理数据插入
|
|
|
|
|
List<DouYinVideoInFoDTO> dataJsonList = videoListDataJson.getList("list", DouYinVideoInFoDTO.class); |
|
|
|
|
if (addList.size() < 1000) { |
|
|
|
|
addList.addAll(dataJsonList); |
|
|
|
|
|
|
|
|
|
if (newAddList.size() < 1000) { |
|
|
|
|
newAddList.addAll(dataJsonList.stream().filter(i->i.getVideoStatus().equals("1")).collect(Collectors.toList())); |
|
|
|
|
} else { |
|
|
|
|
//批量插入视频信息
|
|
|
|
|
douYinMapper.addDouYinVideoInFoList(addList, item.getOpenId(), item.getOrganCode()); |
|
|
|
|
// douYinMapper.addDouYinVideoInFoList(newAddList, item.getOpenId(), item.getOrganCode());
|
|
|
|
|
this.addDouYinVideoInFo(newAddList, item.getOpenId(), item.getOrganCode()); |
|
|
|
|
//清空
|
|
|
|
|
dataJsonList.clear(); |
|
|
|
|
newAddList.clear(); |
|
|
|
|
//添加
|
|
|
|
|
addList.addAll(dataJsonList); |
|
|
|
|
newAddList.addAll(dataJsonList.stream().filter(i->i.getVideoStatus().equals("1")).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
DouyinErrorLogDTO douyinErrorLogDTO = new DouyinErrorLogDTO(); |
|
|
|
@ -294,11 +300,23 @@ public class DouYinServiceImpl implements DouYinService { |
|
|
|
|
douyinErrorLogDTO.setDescribe("获取分享数量异常"); |
|
|
|
|
douYinMapper.adddouyinErrorLog(douyinErrorLogDTO); |
|
|
|
|
} |
|
|
|
|
if (!addList.isEmpty()) { |
|
|
|
|
//批量插入视频信息
|
|
|
|
|
douYinMapper.addDouYinVideoInFoList(addList, item.getOpenId(), item.getOrganCode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (!newAddList.isEmpty()) { |
|
|
|
|
//批量插入视频信息
|
|
|
|
|
this.addDouYinVideoInFo(newAddList, item.getOpenId(), item.getOrganCode()); |
|
|
|
|
// douYinMapper.addDouYinVideoInFoList(newAddList, item.getOpenId(), item.getOrganCode());
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addDouYinVideoInFo(List<DouYinVideoInFoDTO> list, @Param("openId") String openId, @Param("organCode") String organCode){ |
|
|
|
|
list.stream().forEach(item->{ |
|
|
|
|
try { |
|
|
|
|
douYinMapper.addDouYinVideoInFo(item,openId,organCode); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|