微调
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.njcn.jbsyncdata.service;
|
||||
|
||||
import com.njcn.jbsyncdata.pojo.ExcelData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IBusinessService {
|
||||
void testInterface(List<ExcelData> list);
|
||||
|
||||
void testInterfaceByUserId(List<ExcelData> list);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.njcn.jbsyncdata.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.njcn.jbsyncdata.component.TokenComponent;
|
||||
import com.njcn.jbsyncdata.pojo.ExcelData;
|
||||
import com.njcn.jbsyncdata.pojo.result.TokenResult;
|
||||
import com.njcn.jbsyncdata.service.IBusinessService;
|
||||
import com.njcn.jbsyncdata.util.RestTemplateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BusinessServiceImpl implements IBusinessService {
|
||||
|
||||
@Resource
|
||||
private TokenComponent tokenComponent;
|
||||
|
||||
@Override
|
||||
public void testInterface(List<ExcelData> list) {
|
||||
RestTemplateUtil restTemplateUtil = new RestTemplateUtil();
|
||||
TokenResult tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate();
|
||||
if (null == tokenWithRestTemplate) {
|
||||
log.error("token信息没有获取到");
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject;
|
||||
JSONObject jsonObjectSub;
|
||||
for (ExcelData excelData : list) {
|
||||
jsonObject = JSONUtil.createObj();
|
||||
jsonObjectSub = JSONUtil.createObj();
|
||||
jsonObject.set("page", 1);
|
||||
jsonObject.set("perPage", 50);
|
||||
List<String> psrIds = Stream.of(excelData.getStageID()).collect(Collectors.toList());
|
||||
jsonObjectSub.set("psrIds", psrIds);
|
||||
jsonObjectSub.set("psrType", "0401004");
|
||||
jsonObjectSub.set("astIds", new ArrayList<>());
|
||||
jsonObjectSub.set("astType", "");
|
||||
jsonObjectSub.set("termIds", new ArrayList<>());
|
||||
jsonObjectSub.set("termType", "");
|
||||
jsonObjectSub.set("measPointIds", new ArrayList<>());
|
||||
jsonObject.set("filter", jsonObjectSub);
|
||||
if (excelData.getStageID().equalsIgnoreCase("1502760751")) {
|
||||
log.error("组装后的json为:{}", jsonObject);
|
||||
}
|
||||
//组装好json开始发送请求
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("x-token", tokenWithRestTemplate.getAccess_token());
|
||||
ResponseEntity<String> response = restTemplateUtil.post(tokenComponent.getUrl().concat("/realMeasCenter/measPoint/commonQuery"), headers, jsonObject, String.class);
|
||||
log.error("请求接口,台区号为:{},结果为:{}", excelData.getStageID(), response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testInterfaceByUserId(List<ExcelData> list) {
|
||||
RestTemplateUtil restTemplateUtil = new RestTemplateUtil();
|
||||
TokenResult tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate();
|
||||
if (null == tokenWithRestTemplate) {
|
||||
log.error("token信息没有获取到");
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject;
|
||||
JSONObject jsonObjectSub;
|
||||
for (ExcelData excelData : list) {
|
||||
jsonObject = JSONUtil.createObj();
|
||||
jsonObjectSub = JSONUtil.createObj();
|
||||
jsonObject.set("page", 1);
|
||||
jsonObject.set("perPage", 50);
|
||||
jsonObject.set("startTime", "2023-10-07 00:00:00");
|
||||
jsonObject.set("endTime", "2023-10-07 23:59:59");
|
||||
List<String> userId = Stream.of("160".concat(excelData.getGenerationUserID())).collect(Collectors.toList());
|
||||
jsonObjectSub.set("consNos", userId);
|
||||
jsonObjectSub.set("consType", 3);
|
||||
|
||||
jsonObjectSub.set("astIds", new ArrayList<>());
|
||||
jsonObjectSub.set("astType", "");
|
||||
jsonObjectSub.set("psrIds", new ArrayList<>());
|
||||
jsonObjectSub.set("psrType", "");
|
||||
jsonObjectSub.set("measPointIds", new ArrayList<>());
|
||||
List<String> typeList = Stream.of("PhV_phsA","PhV_phsB","PhV_phsC").collect(Collectors.toList());
|
||||
jsonObjectSub.set("telemetryTypes", typeList);
|
||||
jsonObject.set("filter", jsonObjectSub);
|
||||
if (excelData.getStageID().equalsIgnoreCase("2226675026")) {
|
||||
log.error("组装后的json为:{}", jsonObject);
|
||||
}
|
||||
//组装好json开始发送请求
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("x-token", tokenWithRestTemplate.getAccess_token());
|
||||
ResponseEntity<String> response = restTemplateUtil.post(tokenComponent.getUrl().concat("/realMeasCenter/measPoint/commonQuery"), headers, jsonObject, String.class);
|
||||
log.error("请求接口,台区号为:{},结果为:{}", excelData.getStageID(), response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user