|
@@ -0,0 +1,118 @@
|
|
|
+package cn.com.taiji.algorithm.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.com.taiji.algorithm.model.VideoCatalog;
|
|
|
+import cn.com.taiji.algorithm.service.IVideoCatalogService;
|
|
|
+import cn.com.taiji.algorithm.service.IVideoTreeService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description
|
|
|
+ *
|
|
|
+ * @Author yangyue
|
|
|
+ * @Date 2021/11/18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class VideoTreeServiceImpl implements IVideoTreeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IVideoCatalogService catalogService;
|
|
|
+
|
|
|
+ @Value("${taiji.clientId}")
|
|
|
+ private String clientId;
|
|
|
+
|
|
|
+ @Value("${taiji.clientSecret}")
|
|
|
+ private String clientSecret;
|
|
|
+
|
|
|
+ String url = "http://10.110.80.31:8888";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void httpsPost() {
|
|
|
+ MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("client_id",clientId);
|
|
|
+ params.add("client_secret",clientSecret);
|
|
|
+ params.add("grant_type","client_credentials");
|
|
|
+
|
|
|
+ String tokenUrl = url + "/tglserver/token";
|
|
|
+ log.info(tokenUrl);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ HttpEntity httpEntity = new HttpEntity(params,headers);
|
|
|
+ ResponseEntity<Map> result2 = restTemplate.postForEntity(tokenUrl, httpEntity, Map.class);
|
|
|
+ log.info(result2.getBody().toString());
|
|
|
+ String token = result2.getBody().get("token_type") + " " + result2.getBody().get("access_token");
|
|
|
+ log.info(token);
|
|
|
+
|
|
|
+ //获取目录(行政规划)
|
|
|
+
|
|
|
+ headers.clear();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ headers.add("Authorization", token);
|
|
|
+ HttpEntity reqEntity = new HttpEntity(headers);
|
|
|
+
|
|
|
+ String parentCode = "0";
|
|
|
+ String platformid = "0";
|
|
|
+ String deviceUrl = url + "/api/CommonApi/GetOrganizationList?client_id="+clientId+"&parentCode="+parentCode+"&platformid="+platformid;
|
|
|
+
|
|
|
+ // log.info(deviceUrl);
|
|
|
+ ResponseEntity<JSONObject> exchange = restTemplate.exchange(deviceUrl, HttpMethod.GET, reqEntity,JSONObject.class);
|
|
|
+ log.info(exchange.getBody().toString());
|
|
|
+ JSONObject resData = exchange.getBody();
|
|
|
+ JSONArray jsonArray = resData.getJSONArray("List");
|
|
|
+ List<VideoCatalog> catalogs = JSONArray.parseArray(jsonArray.toJSONString(), VideoCatalog.class);
|
|
|
+ if (null != catalogs && catalogs.size() > 0) {
|
|
|
+ // orgChildNodes.addAll(catalogs);
|
|
|
+ // catalogs.forEach(o -> {
|
|
|
+ // // catalogService.saveOrUpdate(o,new LambdaQueryWrapper<VideoCatalog>()
|
|
|
+ // // .eq(VideoCatalog::getPlatformId, o.getPlatformId()));
|
|
|
+ // });
|
|
|
+ getChildNodes(restTemplate,reqEntity,catalogs,url + "/api/CommonApi/GetOrganizationList?client_id="+clientId);
|
|
|
+ catalogService.saveBatch(orgChildNodes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static List<VideoCatalog> orgChildNodes = new ArrayList<VideoCatalog>();
|
|
|
+
|
|
|
+ //根据父节点递归所有子节点
|
|
|
+ public void getChildNodes(RestTemplate restTemplate, HttpEntity reqEntity, List<VideoCatalog> list, String url) {
|
|
|
+ for (VideoCatalog catalog : list) {
|
|
|
+
|
|
|
+ orgChildNodes.add(catalog);
|
|
|
+ String catalogUrl = url + "&parentCode="+catalog.getAreaCode()+"&platformid="+catalog.getPlatformId();
|
|
|
+ ResponseEntity<JSONObject> exchange = restTemplate.exchange(catalogUrl, HttpMethod.GET, reqEntity,JSONObject.class);
|
|
|
+ log.info(exchange.getBody().toString());
|
|
|
+ JSONObject resData = exchange.getBody();
|
|
|
+ JSONArray jsonArray = resData.getJSONArray("List");
|
|
|
+ List<VideoCatalog> catalogs = JSONArray.parseArray(jsonArray.toJSONString(), VideoCatalog.class);
|
|
|
+ for (VideoCatalog log : catalogs) {
|
|
|
+ //遍历出父id等于参数的id,add进子节点集合
|
|
|
+ if (catalog.getParentCode().equals(log.getParentCode())) {
|
|
|
+ //递归遍历下一级
|
|
|
+ getChildNodes(restTemplate,reqEntity,list,url);
|
|
|
+ // orgChildNodes.add(log);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // return orgChildNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|