Commit 36062bc5 authored by wanglang's avatar wanglang

数据推送

parent 7f52d38b
...@@ -25,9 +25,9 @@ public class PushDataController { ...@@ -25,9 +25,9 @@ public class PushDataController {
@ApiOperation(value = "数据推送", response = ZybVo.class) @ApiOperation(value = "数据推送", response = R.class)
@PostMapping(value = "/push") @PostMapping(value = "/push")
public R pushData(@RequestBody @Validated DataDto dto) throws Exception { public R pushData(@Validated DataDto dto){
return pushDataService.pushData(dto); return pushDataService.pushData(dto);
} }
......
...@@ -15,7 +15,7 @@ public interface PushDataService { ...@@ -15,7 +15,7 @@ public interface PushDataService {
* @param dto * @param dto
* @return * @return
*/ */
R pushData(DataDto dto) throws Exception; R pushData(DataDto dto);
......
...@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.text.MessageFormat;
/** /**
* @Author: wl * @Author: wl
* @Date: 2023/3/24 * @Date: 2023/3/24
...@@ -32,12 +34,25 @@ public class PushDataServiceImpl implements PushDataService { ...@@ -32,12 +34,25 @@ public class PushDataServiceImpl implements PushDataService {
@Override @Override
public R pushData(DataDto dto) throws Exception { public R pushData(DataDto dto){
if (StringUtils.isEmpty(dto.getDataJson())){ if (StringUtils.isEmpty(dto.getDataJson())){
return R.failed("无法获取到推送数据"); return R.failed("无法获取到推送数据");
} }
log.info("获取原始数据成功,原始数据为:"+dto.getDataJson()); //转义处理
String result = HttpUtil.post(zybConfig.getUrl(), dto.getDataJson()); String soapui = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://server.zhejian.com/\">" +
"<soapenv:Header/>" +
"<soapenv:Body>" +
"<ser:all>" +
"<!--Optional:-->" +
"<arg0><![CDATA[" +
"{0}" +
"]]></arg0>" +
"</ser:all>" +
"</soapenv:Body>" +
"</soapenv:Envelope>";
String format = MessageFormat.format(soapui, dto.getDataJson());
log.info("获取原始数据成功,原始数据为:"+format);
String result = HttpUtil.post(zybConfig.getUrl(), format);
log.info("调用省直平台成功,转义前:" + result); log.info("调用省直平台成功,转义前:" + result);
result = StringEscapeUtils.unescapeXml(result); result = StringEscapeUtils.unescapeXml(result);
log.info("转义后:" + result); log.info("转义后:" + result);
...@@ -45,16 +60,8 @@ public class PushDataServiceImpl implements PushDataService { ...@@ -45,16 +60,8 @@ public class PushDataServiceImpl implements PushDataService {
return R.failed("调用省直平台推送失败"); return R.failed("调用省直平台推送失败");
} }
String substring = result.substring(result.indexOf("<data>"), result.indexOf("</data>") + 7); String substring = result.substring(result.indexOf("<data>"), result.indexOf("</data>") + 7);
//获取data数据
JSONObject jsonObject = JsonToXml2.xmltoJson(substring).getJSONObject("data");
log.info("获取data数据:" + new Gson().toJson(jsonObject));
ZybVo zybVo = JSON.toJavaObject(jsonObject, ZybVo.class);
log.info("实体类转换后:" + new Gson().toJson(zybVo));
if ("-1".equals(zybVo.getReturnCode())) {
return R.failed(zybVo.getMessage() + "," + zybVo.getErrorList().getError().getMessage());
}
log.info("单位申报成功"); log.info("单位申报成功");
return R.ok(zybVo); return R.ok(substring);
} }
......
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