|
@@ -14,6 +14,7 @@ import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
|
import com.tzld.piaoquan.wecom.utils.DateUtil;
|
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -31,6 +32,7 @@ import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_M
|
|
|
import static com.tzld.piaoquan.wecom.common.enums.ExceptionCodeEnum.PARAMS_ERROR;
|
|
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
|
|
@@ -106,8 +108,9 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
}
|
|
|
return map;
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("获取详情异常");
|
|
|
+ log.error("MessageAttachmentServiceImpl getVideDetail error", e);
|
|
|
}
|
|
|
+ return new HashMap<>();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -122,7 +125,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
}
|
|
|
return insertPage(staff.getCarrierId(), videoId, staff.getRemark());
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("MessageAttachmentService getPage error", e);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -151,38 +154,56 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
return data.getString("url");
|
|
|
}
|
|
|
|
|
|
- public String selectPage(Long videoId, String carrierId, String typeOne, String typeTwo) throws IOException {
|
|
|
- int pageSize = 20;
|
|
|
+ public String selectPage(Long videoId, String carrierId, String typeOne, String typeTwo) {
|
|
|
int totalPage = 1;
|
|
|
- for (int n = 1; n < totalPage + 1; n++) {
|
|
|
- String url = "https://api.piaoquantv.com/ad/put/flow/list/tencent?videoId=${videoId}&putScene=touliu&channel=tencentqw¤tPage=${page}&pageSize=${pageSize}"
|
|
|
- .replace("${videoId}", String.valueOf(videoId))
|
|
|
- .replace("${page}", String.valueOf(n))
|
|
|
- .replace("${pageSize}", String.valueOf(pageSize));
|
|
|
- String res = httpPoolClientDefault.get(url);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- JSONObject data = jsonObject.getJSONObject("data");
|
|
|
- if(data.getInteger("totalPage") != null){
|
|
|
- totalPage = data.getInteger("totalPage");
|
|
|
- }
|
|
|
- JSONArray objs = data.getJSONArray("objs");
|
|
|
- for (int i = 0; i < objs.size(); i++) {
|
|
|
- JSONObject obj = objs.getJSONObject(i);
|
|
|
- String putCarrierId = obj.getString("putCarrierId");
|
|
|
- String page = obj.getString("url");
|
|
|
- String putTypeOne = obj.getString("putTypeOne");
|
|
|
- String putTypeTwo = obj.getString("putTypeTwo");
|
|
|
- if (StringUtils.isEmpty(putCarrierId)
|
|
|
- || StringUtils.isEmpty(page)
|
|
|
- || StringUtils.isEmpty(putTypeOne)
|
|
|
- || StringUtils.isEmpty(putTypeTwo)) {
|
|
|
+ for (int n = 1; n <= totalPage; n++) {
|
|
|
+ String url = getUrl(videoId, n);
|
|
|
+ try {
|
|
|
+ String res = httpPoolClientDefault.get(url);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (data == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (putCarrierId.equals(carrierId) && putTypeOne.equals(typeOne) && putTypeTwo.equals(typeTwo)) {
|
|
|
- return page;
|
|
|
+ if (data.getInteger("totalPage") != null) {
|
|
|
+ totalPage = data.getInteger("totalPage");
|
|
|
+ }
|
|
|
+ JSONArray objs = data.getJSONArray("objs");
|
|
|
+ for (int i = 0; i < objs.size(); i++) {
|
|
|
+ JSONObject obj = objs.getJSONObject(i);
|
|
|
+ String putCarrierId = obj.getString("putCarrierId");
|
|
|
+ String page = obj.getString("url");
|
|
|
+ String putTypeOne = obj.getString("putTypeOne");
|
|
|
+ String putTypeTwo = obj.getString("putTypeTwo");
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(putCarrierId) || StringUtils.isEmpty(page) || StringUtils.isEmpty(putTypeOne) || StringUtils.isEmpty(putTypeTwo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (putCarrierId.equals(carrierId) && putTypeOne.equals(typeOne) && putTypeTwo.equals(typeTwo)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("Error fetching data from API for videoId: " + videoId + ", page: " + n, e);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private static String getUrl(Long videoId, int n) {
|
|
|
+ String baseUrl = "https://api.piaoquantv.com/ad/put/flow/list/tencent";
|
|
|
+ String putScene = "touliu";
|
|
|
+ String channel = "tencentqw";
|
|
|
+ int pageSize = 20;
|
|
|
+ return String.format(
|
|
|
+ "%s?videoId=%d&putScene=%s&channel=%s¤tPage=%d&pageSize=%d",
|
|
|
+ baseUrl,
|
|
|
+ videoId,
|
|
|
+ putScene,
|
|
|
+ channel,
|
|
|
+ n,
|
|
|
+ pageSize
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|