use of com.itrus.portal.db.EvidenceCallbackExample in project portal by ixinportal.
the class EvidenceCallbackTask method init.
public void init() {
try {
EvidenceCallbackExample callbackExample = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria = callbackExample.createCriteria();
criteria.andCounntLessThan(3);
List<EvidenceCallback> callbacks = callbackService.selectAll(callbackExample);
if (callbacks == null || callbacks.isEmpty()) {
log.error("暂无需系统存证回调");
return;
}
String url = null;
String app_id = null;
String secret_key = null;
// 需要回执报告
Map<Long, String> dataRet = new HashMap<Long, String>();
Map<Long, List<String>> data = new HashMap<Long, List<String>>();
Map<String, EvidenceCallback> cacheCallBackBySnMap = new HashMap<>();
for (int i = 0; i < callbacks.size() && i < 1000; i++) {
EvidenceCallback callback = callbacks.get(i);
cacheCallBackBySnMap.put(callback.getEvidenceSn(), callback);
if (callback.getAppServiceId() == null) {
if (data.containsKey(callback.getAppId())) {
data.get(callback.getAppId()).add(callback.getEvidenceSn());
} else {
List<String> sns = new ArrayList<String>();
sns.add(callback.getEvidenceSn());
data.put(callback.getAppId(), sns);
}
} else {
dataRet.put(callback.getAppId(), callback.getEvidenceSn());
}
}
// <---------------------------- 处理data start ------------------------------>
for (Map.Entry<Long, List<String>> entry : data.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
applicationInfo = infoService.selectById(entry.getKey());
}
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("message", "存证成功");
param.put("appId", app_id);
param.put("evidenceSns", JSONObject.toJSONString(entry.getValue()));
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + entry.getValue(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
if (retStr == null || ret_data.getInteger("status") != 1) {
log.error("EvidenceCallbackTask failure count [" + entry.getValue().size() + "]");
for (String sn : entry.getValue()) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(sn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(sn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(sn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
}
} else {
log.error("EvidenceCallbackTask success count [" + entry.getValue().size() + "]");
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", entry.getValue().toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(entry.getValue());
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
// for(String sn:entry.getValue()) {
// EvidenceBasicInformation basicInformation = informationService
// .getInformationBySn(sn, null);
// basicInformation.setIsCallback(1);
// sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKeySelective",
// basicInformation);
//
// EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
// EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
// criteria1.andEvidenceSnEqualTo(sn);
// sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample",
// callbackExample1);
//
// }
}
}
// <---------------------------- 处理dataRet start ------------------------------>
for (Entry<Long, String> entry : dataRet.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
applicationInfo = infoService.selectById(entry.getKey());
}
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
EvidenceBasicInformation basicInformation = informationService.getInformationBySn(entry.getValue(), null);
// 得到证据回执base64
String reportBase64 = null;
// reportBase64 = EvidenceSaveServiceApi.cacheReportBySnMap.get(basicInformation.getEvidenceSn());
if (StringUtils.isEmpty(reportBase64)) {
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
try {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取回执报告附件表信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria ec = enclosureExample.createCriteria();
ec.andEvidenceSnEqualTo(basicInformation.getEvidenceSn());
ec.andPdfTypeEqualTo("3");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
if (enclosures != null && !enclosures.isEmpty()) {
EvidenceEnclosure enclosure = enclosures.get(0);
// 调解密下载接口从原子服务拿到回执报告base64
reportBase64 = EvidenceSaveServiceApi.decryptedAndDownload(sqlSession, enclosure.getBuid(), realNameAuthentication.getRealNameddress());
} else {
// 调用生成回执报告方法
Map<String, Object> mapRet = null;
mapRet = reportTemplate.returnreceipt(basicInformation.getEvidenceSn(), applicationInfo, null);
if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
// 修改证据基本信息回执状态为已出
reportBase64 = (String) mapRet.get("pdfBase64");
basicInformation.setReceiptStatus(1);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
}
}
} else {
// EvidenceSaveServiceApi.cacheReportBySnMap.remove(basicInformation.getEvidenceSn());
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("appId", app_id);
param.put("evidenceSn", basicInformation.getEvidenceSn());
if (reportBase64 == null) {
param.put("message", "存证成功,回执报告生成失败!");
} else {
param.put("message", "存证成功");
param.put("reportBase64", reportBase64);
}
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + basicInformation.getEvidenceSn(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
String dataSn = basicInformation.getEvidenceSn();
Long appId = entry.getKey();
// 判断是否成功 true ——> 失败
if (retStr == null || ret_data.getInteger("status") != 1) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(dataSn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(dataSn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(dataSn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
} else {
List<String> sns = new ArrayList<>();
sns.add(dataSn);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(sns);
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
}
}
// <---------------------------- 处理dataRet end ------------------------------>
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
LogUtil.evidencelog(sqlSession, null, "存证回调接口", "失败原因:" + e.toString());
}
}
Aggregations