Commit e89aed7a authored by yangyang's avatar yangyang

碳银对接 - 碳银接口对接

parent 902a7a75
......@@ -296,7 +296,7 @@ public class TanYinApiUtils {
*/
public <T> PageInfo<T> parsePageResponse(String desc, HttpResponse response, Class<T> resultClass) {
// 记录请求的响应信息到日志,包括描述、HTTP状态码和响应体。
log.info("响应 => 碳银{}接口,httpCode:{}, response:{}", desc, response.getStatus(), response.body());
log.debug("响应 => 碳银{}接口,httpCode:{}, response:{}", desc, response.getStatus(), response.body());
// 将响应体解析为TanYinBaseResultDTO对象,其中包含分页数据。
TanYinBaseResultDTO<JSONObject> listResult = JSONObject.parseObject(response.body(), TanYinBaseResultDTO.class);
......@@ -318,10 +318,11 @@ public class TanYinApiUtils {
TanYinPageResultDTO tanYinPageResultDTO = JSONObject.parseObject(listResult.getData().toJSONString(), TanYinPageResultDTO.class);
// 将分页数据中的列表数据转换为指定类型的集合。
if (tanYinPageResultDTO.getList() != null) {
List<T> newList = (List<T>) tanYinPageResultDTO.getList().parallelStream().map(json -> JSON.toJavaObject((JSON) json, resultClass)).collect(Collectors.toList());
// 将转换后的集合设置到PageInfo对象中。
pageInfo.setList(newList);
}
// 设置分页信息,包括总页数、每页大小、当前页码和总记录数。
pageInfo.setPages(tanYinPageResultDTO.getTotalPage() == null ? 0 : tanYinPageResultDTO.getTotalPage());
......
......@@ -51,7 +51,7 @@ public class TanYinConstant {
public static final HashMap<String, String> intoNetWorkStatus = new HashMap<String, String>() {
{
put("0", "普通并网");
put("0", "固定全额上网");
}
};
......
......@@ -92,9 +92,6 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
@Resource (type = TanYinApiUtils.class)
private TanYinApiUtils tanYinApiUtils;
@Resource (type = RedisUtils.class)
private RedisUtils redisUtils;
@Resource (type = TanYinCustomerInfoMapper.class)
private TanYinCustomerInfoMapper tanYinCustomerInfoMapper;
......@@ -165,7 +162,7 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
private final static String pageNo = "1";
private final static String pageSize = "200";
private final static String pageSize = "999";
/**
* 每隔 10分钟通过并网时间段同步碳银对应范围内的项目信息
......@@ -180,12 +177,14 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
@Override
public void customerInfoList() {
try {
String startDate = LocalDate.now().minusMonths(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String endDate = LocalDate.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
log.info("-------碳银同步项目信息开始: {} ------- ", sdf.format(new Date()));
Map<String, Object> params = MapBuilder.<String, Object>create()
.put("pageNo", pageNo)
.put("pageSize", pageSize)// 每页行数
.put("startDate", LocalDate.now().minusYears(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))// 开始时间 YYYY-MM-dd
.put("endDate", LocalDate.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))// 结束时间 YYYY-MM-dd
.put("startDate", startDate)// 开始时间 YYYY-MM-dd
.put("endDate", endDate)// 结束时间 YYYY-MM-dd
.build();
PageInfo<TanYinCustomerInfo> tanYinCustomerInfos = tanYinApiUtils.postPage("客户信息", apiUrl + TanYinConstant.customerInfoUrl, JSON.toJSONString(params), null, TanYinCustomerInfo.class);
if (tanYinCustomerInfos == null || CollectionUtils.isEmpty(tanYinCustomerInfos.getList())) {
......@@ -193,8 +192,14 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
return;
}
for (TanYinCustomerInfo tanYinCustomerInfo : tanYinCustomerInfos.getList()) {
TanYinCustomerInfo oldTanYinCustomerInfo = tanYinCustomerInfoMapper.selectOne(new QueryWrapper<TanYinCustomerInfo>().eq("project_no", tanYinCustomerInfo.getProjectNo()).eq("customer_id_no", tanYinCustomerInfo.getCustomerIdNo()).eq("customer_phone", tanYinCustomerInfo.getCustomerPhone()).orderByDesc("create_time").last("limit 1"));
if (oldTanYinCustomerInfo == null) {
tanYinCustomerInfo.setCreateTime(System.currentTimeMillis());
tanYinCustomerInfoMapper.insert(tanYinCustomerInfo);
} else {
tanYinCustomerInfo.setCreateTime(oldTanYinCustomerInfo.getCreateTime());
tanYinCustomerInfoMapper.insert(tanYinCustomerInfo);
}
}
log.info("-------碳银同步项目信息结束: {} ------- ", sdf.format(new Date()));
} catch (Exception e) {
......@@ -219,9 +224,7 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
long ts = System.currentTimeMillis();
log.info("-------碳银同步电站开始: {} ------- ", ts);
List<String> projectNos = tanYinCustomerInfoMapper.listProjectNo();
projectNos.add("TF2024060312382700202");
String powerDate = "2024-07-17";
// String powerDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String powerDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
if (CollectionUtils.isEmpty(projectNos)) {
log.warn("-------碳银同步电站结束: 未同步到项目信息 -------");
return;
......@@ -286,14 +289,16 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
// jpStation.setPrice();
// jpStation.setModuleCount(ObjectUtils.isEmpty(Math.toIntExact(golangStationDetail.getModule())) ? 0 : Math.toIntExact(golangStationDetail.getModule()));
jpStation.setOnGridType(TanYinConstant.intoNetWorkStatus.get("0")); // 没有该字段默认写死
// jpStation.setOnGridTime();
// 去tanyin_customer_info 查询并网时间
TanYinCustomerInfo tanYinCustomerInfo = tanYinCustomerInfoMapper.selectOne(new QueryWrapper<TanYinCustomerInfo>().eq("project_no", tanYinStationInfo.getProjectNo()).eq("customer_id_no", tanYinStationInfo.getCustomerIdNo()).eq("customer_phone", tanYinStationInfo.getCustomerPhone()).orderByDesc("create_time").last(" limit 1"));
// 收益 = 发电量 * 0.45 @wujiang 确认过
jpStation.setOnGridTime(tanYinCustomerInfo != null ? new Date(tanYinCustomerInfo.getElectricContractPass()) : null);
jpStation.setDayIncome(tanYinStationInfo.getDayPower() != null ? Double.parseDouble(tanYinStationInfo.getDayPower()) * 0.45 : 0.0);
jpStation.setMonthIncome(tanYinStationInfo.getMonthPower() != null ? Double.parseDouble(tanYinStationInfo.getMonthPower()) * 0.45 : 0.0);
jpStation.setYearIncome(tanYinStationInfo.getYearPower() != null ? Double.parseDouble(tanYinStationInfo.getYearPower()) * 0.45 : 0.0);
jpStation.setCumulativeIncome(tanYinStationInfo.getTotalPower() != null ? Double.parseDouble(tanYinStationInfo.getTotalPower()) * 0.45 : 0.0);
jpStation.setArea(tanYinStationInfo.getArea());
// jpStation.setEmail();
// jpStation.setAccessTime();
// jpStation.setCreateTime();
// jpStation.setRatedPower();
jpStation.setType("家庭户用");
......@@ -562,10 +567,8 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
jpStationMap.put(tanYinInveterInfo.getProjectNo(), jpStation);
}
// 逆变器没有就空着
// jpInverter.setDayPowerGeneration(jpStation.getDayGenerate());
// jpInverter.setMonthPowerGeneration(jpStation.getMonthGenerate());
// jpInverter.setYearPowerGeneration(jpStation.getYearGenerate());
// jpInverter.setTotalPowerGeneration(jpStation.getAccumulatedPower());
jpInverter.setMonthPowerGeneration(jpStation.getMonthGenerate());
jpInverter.setYearPowerGeneration(jpStation.getYearGenerate());
jpInverter.setStationName(jpStation.getName());
jpInverter.setAddr(jpStation.getAddress());
jpInverter.setCapacity(jpStation.getCapacity());
......@@ -669,7 +672,7 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
.setGenerationHours(jpInverter.getDayPowerGeneration() / jpInverter.getCapacity());
}
// hygfjpInverterHistory.setPowerGeneration(tanYinInveterInfoDTO.getWatt());
hygfjpInverterHistory.setPowerGeneration(tanYinInveterInfoDTO.getWatt() != null ? Double.parseDouble(tanYinInveterInfoDTO.getWatt()) : null);
if (org.springframework.util.ObjectUtils.isEmpty(hygfjpInverterHistory.getCreatedTime())) {
hygfjpInverterHistory.setCreatedTime(System.currentTimeMillis());
hygfjpInverterHistoryMapper.insert(hygfjpInverterHistory);
......
......@@ -79,4 +79,4 @@ tanYin.api.apiUrl=https://userauth.tanwin.cn
tanYin.api.clientSecret=rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey=yx10001
dataRequestScheduled.tanYin=0 0/10 * * * *
dataRequestScheduled.tanYin.warn=0 0/1 * * * *
\ No newline at end of file
dataRequestScheduled.tanYin.warn=0 0/5 * * * *
\ No newline at end of file
......@@ -51,4 +51,4 @@ tanYin.api.apiUrl=https://userauth.tanwin.cn
tanYin.api.clientSecret=rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey=yx10001
dataRequestScheduled.tanYin=0 0/10 * * * *
dataRequestScheduled.tanYin.warn=0 0/1 * * * *
\ No newline at end of file
dataRequestScheduled.tanYin.warn=0 0/5 * * * *
\ No newline at end of file
......@@ -79,4 +79,4 @@ tanYin.api.apiUrl=https://userauth.tanwin.cn
tanYin.api.clientSecret=rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey=yx10001
dataRequestScheduled.tanYin=0 0/10 * * * *
dataRequestScheduled.tanYin.warn=0 0/1 * * * *
\ No newline at end of file
dataRequestScheduled.tanYin.warn=0 0/5 * * * *
\ No newline at end of file
......@@ -53,4 +53,4 @@ tanYin.api.apiUrl=https://userauth.tanwin.cn
tanYin.api.clientSecret=rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey=yx10001
dataRequestScheduled.tanYin=0 0/10 * * * *
dataRequestScheduled.tanYin.warn=0 0/1 * * * *
\ No newline at end of file
dataRequestScheduled.tanYin.warn=0 0/5 * * * *
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment