Commit 81d8cd97 authored by 5359's avatar 5359

中登网开发

parent ab3d984d
......@@ -20,6 +20,7 @@ import com.hand.app.zhongDengWang.ws.login.WSLoginServiceService;
import com.hand.app.zhongDengWang.dto.FndAtmAttachmentDto;
import com.hand.app.zhongDengWang.mapper.FndAtmAttachmentMapper;
import com.hand.hap.core.IRequest;
import com.hand.hap.lock.components.DatabaseLockProvider;
import com.hand.hap.system.dto.DTOStatus;
import com.rfp.sm.utils.SM2Utils;
import org.json.XML;
......@@ -28,10 +29,13 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Service
public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
......@@ -50,6 +54,13 @@ public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
FndAtmAttachmentMapper fndAtmAttachmentMapper;
@Autowired
FndZhongDengBatchMapper fndZhongDengBatchMapper;
@Autowired
private DatabaseLockProvider databaseLockProvider;
/**
* Use private final lock objects to synchronize classes that may interact with untrusted code
*/
private final Object lock = new Object();
@Value("${zdw.login.clientKey}")
......@@ -177,45 +188,14 @@ public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
/***
* 融资租赁-登记入口方法;
* @param request
* @param batchId
* @param
* @param
***/
public JSONObject initRegisterService(IRequest request, Long batchId) {
public void registerThread(IRequest request, List<FndZhongDengBatch> fndZhongDengBatches, String loginToken) {
JSONObject resultJson = new JSONObject();
/*根据批次ID获取所有上报请求id*/
List<FndZhongDengBatch> fndZhongDengBatches = new ArrayList<>();
FndZhongDengBatch fndZhongDengBatch = new FndZhongDengBatch();
fndZhongDengBatch.setBatchId(batchId);
fndZhongDengBatches = fndZhongDengBatchMapper.select(fndZhongDengBatch);
if (fndZhongDengBatches.size() == 0) {
resultJson.put("code", "000");
resultJson.put("info", "000");
return resultJson;
}
/*获取中登网登录loginToken*/
loginToken = getRegisterToken();
/*返回结果loginToken解析,如果返回异常退出当前请求*/
if (loginToken.contains("Error")) {
String errorCode = "-1";
String errorInfo = "-1";
if (errorCode.contains(":")) {
errorCode = loginToken.split(":")[1];
if (errorCode.contains("_")) {
errorCode = loginToken.split("_")[0];
errorInfo = loginToken.split("_")[1];
}
}
resultJson.put("code", errorCode);
resultJson.put("info", errorInfo);
} else {
List<FndZhongDengLines> fndZhongDengLinesList = new ArrayList<>();
/*根据传入ids循环上报中登网*/
List<FndZhongDengLines> fndZhongDengLinesList = new ArrayList<>();
/*根据传入ids循环上报中登网*/
synchronized (lock) {
for (FndZhongDengBatch batch : fndZhongDengBatches) {
FndZhongDengLines fndZhongDengLines = new FndZhongDengLines();
......@@ -223,14 +203,10 @@ public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
fndZhongDengLines = fndZhongDengLinesMapper.selectByPrimaryKey(fndZhongDengLines);
if (Objects.nonNull(fndZhongDengLines) && "UPING".equalsIgnoreCase(fndZhongDengLines.getUpStatus())) {
String xmlFileContent = "";
String attachmentZipPath = "";
try {
String registerResult = "";
String registerNumber = "";
String authorizationCode = "";
String error = "";
org.json.JSONObject returnJson;
String xmlFileContent = "";
String attachmentZipPath = "";
FndAtmAttachmentDto fndAtmAttachmentDto = new FndAtmAttachmentDto();
fndAtmAttachmentDto.setAttachmentId(fndZhongDengLines.getAttachmentXmlId());
......@@ -249,9 +225,15 @@ public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
} else {
returns = "<feedback>\n<registertype>LR</registertype>\n<registerresult>001</registerresult>\n<registernumber>I0000001</registernumber>\n<authorizationcode>A0000001</authorizationcode>\n<errors>\n<error>\n" + resultJson.getString("info") + "</error>\n</errors>\n</feedback>\n";
}
System.out.println("dddd" + new String(returns));
/*解析接口返回结果*/
org.json.JSONObject returnJson;
returnJson = XML.toJSONObject(returns);
String registerResult = "";
String registerNumber = "";
String authorizationCode = "";
String error = "";
registerResult = returnJson.getJSONObject("feedback").getString("registerresult");
registerNumber = returnJson.getJSONObject("feedback").getString("registernumber");
authorizationCode = returnJson.getJSONObject("feedback").getString("authorizationcode");
......@@ -271,23 +253,154 @@ public class ZdwWsRequestsServiceImpl implements IZdwWsRequestsService {
fndZhongDengLines.setUpDate(new Date());
fndZhongDengLines.set__status(DTOStatus.UPDATE);
System.out.println("dddd" + new String(returns));
} catch (RuntimeException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
fndZhongDengLines.setUpStatus("FAIL");
fndZhongDengLines.setReturnMsg(e.getMessage());
}
fndZhongDengLinesList.add(fndZhongDengLines);
}
}
if (fndZhongDengLinesList.size() > 0) {
fndZhongDengLinesService.batchUpdate(request, fndZhongDengLinesList);
}
}
}
/***
* 融资租赁-登记入口方法;
* @param request
* @param batchId
***/
public JSONObject initRegisterService(IRequest request, Long batchId) {
JSONObject resultJson = new JSONObject();
/*根据批次ID获取所有上报请求id*/
List<FndZhongDengBatch> fndZhongDengBatches = new ArrayList<>();
FndZhongDengBatch fndZhongDengBatch = new FndZhongDengBatch();
fndZhongDengBatch.setBatchId(batchId);
fndZhongDengBatches = fndZhongDengBatchMapper.select(fndZhongDengBatch);
if (fndZhongDengBatches.size() == 0) {
resultJson.put("code", "000");
resultJson.put("info", "000");
return resultJson;
}
/*获取中登网登录loginToken*/
loginToken = getRegisterToken();
/*返回结果loginToken解析,如果返回异常退出当前请求*/
if (loginToken.contains("Error")) {
String errorCode = "-1";
String errorInfo = "-1";
if (errorCode.contains(":")) {
errorCode = loginToken.split(":")[1];
if (errorCode.contains("_")) {
errorCode = loginToken.split("_")[0];
errorInfo = loginToken.split("_")[1];
}
}
resultJson.put("code", errorCode);
resultJson.put("info", errorInfo);
} else {
final List<FndZhongDengBatch> fndZhongDengBatchList = fndZhongDengBatches;
/*启用新线程进行异步处理中登网接口请求*/
ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
cachedThreadPool.execute(new Runnable() {
public void run() {
// do
try {
registerThread(request, fndZhongDengBatchList, loginToken);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
/*关闭线程*/
cachedThreadPool.shutdown();
// List<FndZhongDengLines> fndZhongDengLinesList = new ArrayList<>();
// /*根据传入ids循环上报中登网*/
// for (FndZhongDengBatch batch : fndZhongDengBatches) {
//
// FndZhongDengLines fndZhongDengLines = new FndZhongDengLines();
// fndZhongDengLines.setLineId(batch.getLineId());
// fndZhongDengLines = fndZhongDengLinesMapper.selectByPrimaryKey(fndZhongDengLines);
//
// if (Objects.nonNull(fndZhongDengLines) && "UPING".equalsIgnoreCase(fndZhongDengLines.getUpStatus())) {
// String xmlFileContent = "";
// String attachmentZipPath = "";
// try {
// String registerResult = "";
// String registerNumber = "";
// String authorizationCode = "";
// String error = "";
// org.json.JSONObject returnJson;
//
// FndAtmAttachmentDto fndAtmAttachmentDto = new FndAtmAttachmentDto();
// fndAtmAttachmentDto.setAttachmentId(fndZhongDengLines.getAttachmentXmlId());
// fndAtmAttachmentDto = fndAtmAttachmentMapper.selectByPrimaryKey(fndAtmAttachmentDto);
//
// /*解析xml文件内容*/
// xmlFileContent = new String(ClientUtils.getxmlFileContent(fndAtmAttachmentDto.getFilePath()));
//
// /*插入接口日志表*/
// if ("INIT".equalsIgnoreCase(fndZhongDengLines.getUpStage())) {
// resultJson = registerInit(fndZhongDengLines.getTypebz(), platformAuthCode, loginToken, fndAtmAttachmentDto.getFileName(), xmlFileContent, fndZhongDengLines.getLineId());
// }
// String returns = "";
// if ("0".equalsIgnoreCase(resultJson.getString("code"))) {
// returns = resultJson.getString("info");
// } else {
// returns = "<feedback>\n<registertype>LR</registertype>\n<registerresult>001</registerresult>\n<registernumber>I0000001</registernumber>\n<authorizationcode>A0000001</authorizationcode>\n<errors>\n<error>\n" + resultJson.getString("info") + "</error>\n</errors>\n</feedback>\n";
// }
//
// /*解析接口返回结果*/
// returnJson = XML.toJSONObject(returns);
// registerResult = returnJson.getJSONObject("feedback").getString("registerresult");
// registerNumber = returnJson.getJSONObject("feedback").getString("registernumber");
// authorizationCode = returnJson.getJSONObject("feedback").getString("authorizationcode");
//
// /*成功*/
// if (Objects.nonNull(registerResult) && "001".equalsIgnoreCase(registerResult)) {
// fndZhongDengLines.setRegisterNumber(registerNumber);
// fndZhongDengLines.setAuthorizationCode(authorizationCode);
// fndZhongDengLines.setUpStatus("SUCCESS");
// fndZhongDengLines.setReturnMsg("上报成功");
// /*失败*/
// } else {
// error = returnJson.getJSONObject("feedback").getString("errors");
// fndZhongDengLines.setUpStatus("FAIL");
// fndZhongDengLines.setReturnMsg(error);
// }
//
// fndZhongDengLines.setUpDate(new Date());
// fndZhongDengLines.set__status(DTOStatus.UPDATE);
//
// System.out.println("dddd" + new String(returns));
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// fndZhongDengLines.setUpStatus("FAIL");
// fndZhongDengLines.setReturnMsg(e.getMessage());
// }
//
// fndZhongDengLinesList.add(fndZhongDengLines);
// }
//
// }
//
// if (fndZhongDengLinesList.size() > 0) {
// fndZhongDengLinesService.batchUpdate(request, fndZhongDengLinesList);
// }
resultJson.put("code", "000");
resultJson.put("info", "000");
......
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