Commit 0c52ff6a authored by duanruiming's avatar duanruiming

[update] 海信上载方案优化

parent 5de23bd5
...@@ -20,7 +20,9 @@ import net.wanji.utc.hisense.pojo.convert.HisenseLightStatusPojo; ...@@ -20,7 +20,9 @@ import net.wanji.utc.hisense.pojo.convert.HisenseLightStatusPojo;
import net.wanji.utc.hisense.pojo.dto.CrossSchemePhaseCountDownDTO; import net.wanji.utc.hisense.pojo.dto.CrossSchemePhaseCountDownDTO;
import net.wanji.utc.hisense.pojo.dto.PhaseCountDownDTO; import net.wanji.utc.hisense.pojo.dto.PhaseCountDownDTO;
import net.wanji.utc.hisense.service.SignalStatusService; import net.wanji.utc.hisense.service.SignalStatusService;
import net.wanji.utc.hisense.util.OkHttpClientUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -35,6 +37,11 @@ import java.util.stream.Collectors; ...@@ -35,6 +37,11 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class SignalStatusServiceImpl implements SignalStatusService { public class SignalStatusServiceImpl implements SignalStatusService {
@Value("${hisenseLightsStatus.shensiUrl}")
private String shensiUrl;
@Value("${hisenseLightsStatus.baiduUrl}")
private String baiduUrl;
@Override @Override
public List<SignalStatusLogPO> runningStatusAlarm(String crossId) { public List<SignalStatusLogPO> runningStatusAlarm(String crossId) {
return null; return null;
...@@ -127,7 +134,10 @@ public class SignalStatusServiceImpl implements SignalStatusService { ...@@ -127,7 +134,10 @@ public class SignalStatusServiceImpl implements SignalStatusService {
*/ */
@Override @Override
public void receiveLightStatus(List<HisenseLightStatusPojo> hisenseLightStatusPojos) throws Exception { public void receiveLightStatus(List<HisenseLightStatusPojo> hisenseLightStatusPojos) throws Exception {
ObjectMapper jackson = JacksonUtils.getInstance(); ObjectMapper jackson = JacksonUtils.getInstance();
//pushOtherCompany(hisenseLightStatusPojos, jackson, shensiUrl, baiduUrl);
if (!CollectionUtils.isEmpty(hisenseLightStatusPojos)) { if (!CollectionUtils.isEmpty(hisenseLightStatusPojos)) {
for (HisenseLightStatusPojo hisenseLightStatusPojo : hisenseLightStatusPojos) { for (HisenseLightStatusPojo hisenseLightStatusPojo : hisenseLightStatusPojos) {
String bodyStr = hisenseLightStatusPojo.getBody(); String bodyStr = hisenseLightStatusPojo.getBody();
...@@ -187,6 +197,20 @@ public class SignalStatusServiceImpl implements SignalStatusService { ...@@ -187,6 +197,20 @@ public class SignalStatusServiceImpl implements SignalStatusService {
} }
} }
private static void pushOtherCompany(List<HisenseLightStatusPojo> hisenseLightStatusPojos, ObjectMapper jackson,
String shensiUrl, String baiduUrl) {
try {
OkHttpClientUtil.jsonPost(shensiUrl, jackson.writeValueAsString(hisenseLightStatusPojos));
} catch (Exception e) {
log.error("海信灯态推送百度失败:{}", e);
}
try {
OkHttpClientUtil.jsonPost(baiduUrl, jackson.writeValueAsString(hisenseLightStatusPojos));
} catch (Exception e) {
log.error("海信灯态推送百度失败:{}", e);
}
}
/** /**
* 通过周期倒计时判断当前相位号,相位倒计时时间 * 通过周期倒计时判断当前相位号,相位倒计时时间
* *
......
...@@ -616,7 +616,7 @@ public class StaticInfoServiceImpl implements StaticInfoService { ...@@ -616,7 +616,7 @@ public class StaticInfoServiceImpl implements StaticInfoService {
// 计划ID - 取的是时段表号 // 计划ID - 取的是时段表号
crossSectionPO.setPlanId(dayplanDTO.getNDayPlanNumber()); crossSectionPO.setPlanId(dayplanDTO.getNDayPlanNumber());
//方案号 //方案号
Integer pattern = dayplanDTO.getNTimebaseAscPattern(); Integer pattern = (dayplanDTO.getNTimebaseAscPattern()+2)/3;
if (pattern == 85) { if (pattern == 85) {
//黃闪 //黃闪
crossSectionPO.setControlMode(3); crossSectionPO.setControlMode(3);
......
package net.wanji.utc.hisense.util; package net.wanji.utc.hisense.util;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.StringUtils; import net.wanji.common.utils.tool.StringUtils;
import okhttp3.*; import okhttp3.*;
...@@ -12,10 +13,11 @@ import java.io.IOException; ...@@ -12,10 +13,11 @@ import java.io.IOException;
* @Author zhouleilei * @Author zhouleilei
* @Date 2024/11/3 18:11 * @Date 2024/11/3 18:11
*/ */
@Slf4j
public class OkHttpClientUtil { public class OkHttpClientUtil {
public static String xmlPost(String url,String xmlContent){ public static String xmlPost(String url, String xmlContent) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(xmlContent)){ if (StringUtils.isBlank(url) || StringUtils.isBlank(xmlContent)) {
return null; return null;
} }
// 创建 OkHttpClient 实例 // 创建 OkHttpClient 实例
...@@ -40,6 +42,35 @@ public class OkHttpClientUtil { ...@@ -40,6 +42,35 @@ public class OkHttpClientUtil {
return null; return null;
} }
public static String jsonPost(String url, String json) throws Exception {
if (StringUtils.isBlank(url) || StringUtils.isBlank(json)) {
return null;
}
// 创建 OkHttpClient 实例
OkHttpClient client = new OkHttpClient();
// 创建请求体
RequestBody body = RequestBody.create(json, MediaType.get("application/json; charset=utf-8"));
// 创建请求
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
// 执行请求
try (Response response = client.newCall(request).execute()) {
// 获取响应体
if (response.code() == 200 && response.body() != null) {
String responseString = response.body().string();
log.info("远程服务调用成功,url:{}", url);
return responseString;
}
} catch (Exception e) {
log.error("OkHttpClientUtil远程服务url:{}, 调用异常:{}", url, e);
throw new Exception();
}
return null;
}
public static void main(String[] args) { public static void main(String[] args) {
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + /*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
......
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