private Map<String,Object> syncTran(Map<String,Object> param, CacheSession session) {
Map<String,Object> paramMap = new HashMap<String,Object>();
paramMap.put("txnStatus", CommonContant.TXN_STATUS_SUCCEED);
paramMap.put("isSynchronized",BmpBlockChainConstant.IS_SYNCHRONIZED_N);
List<ZBcmBlockTranLog> blockTranLogs= zBcmBlockTranLogMapper.selectTranLogHash(paramMap);
List<ZBcmBlockTran> blockTrans = zBcmBlockTranMapper.selectByExample(new ZBcmBlockTranExample());
List<String> bizHashList = new ArrayList<String>();
if(blockTranLogs != null && blockTranLogs.size()>0){
if(blockTrans != null){
for(ZBcmBlockTranLog blockTranLog:blockTranLogs){
boolean isEuqalFlag = false;
for(ZBcmBlockTran tran: blockTrans){
if(tran.getBizHashCode().equals(blockTranLog.getBizHash())){
isEuqalFlag = true;
break;
}
}
if(!isEuqalFlag){
bizHashList.add(blockTranLog.getBizHash());
}
}
}else {
for (ZBcmBlockTranLog blockTranLog:blockTranLogs){
bizHashList.add(blockTranLog.getBizHash());
}
}
}
List<ZBcmBlockTran> addTranList = new ArrayList<ZBcmBlockTran>();
if(bizHashList != null){
for(String bizHash:bizHashList){
Transaction transaction = bmpBlockChainService.getTransactionByTradeHash(bizHash);
if(transaction != null){
ZBcmBlockTran tranBlock = new ZBcmBlockTran();
String blockNum = String.valueOf(transaction.getBlockNumber());
tranBlock.setId(UUIDGeneratorUtil.get32UUID());
tranBlock.setBizHashCode(transaction.getHash());
tranBlock.setBlockNumber(blockNum);
tranBlock.setFromAcc(transaction.getFrom());
tranBlock.setGas(new BigDecimal(transaction.getGas()));
tranBlock.setGasPrice(new BigDecimal(transaction.getGasPrice()));
tranBlock.setBlkHash(transaction.getBlockHash());
tranBlock.setInputInfo(transaction.getInput());
tranBlock.setNonce(String.valueOf(transaction.getNonce()));
tranBlock.setTranR(transaction.getR());
tranBlock.setTranS(transaction.getS());
tranBlock.setToAcc(transaction.getTo());
tranBlock.setTransactionIndex(String.valueOf(transaction.getTransactionIndex()));
tranBlock.setTranV(String.valueOf(transaction.getV()));
tranBlock.setTranValue(new BigDecimal(transaction.getValue()));
HpbBlock.Block hpbBlock = bmpBlockChainService.queryBlockByBlockNum(blockNum);
tranBlock.setTranTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(hpbBlock.getTimestamp().multiply(new BigInteger("1000")).longValue()).getTime()));
tranBlock.setInputPlainText(bmpBlockChainService.decryptTransInputMsg(transaction.getInput()));
tranBlock.setIsSynchronized(BmpBlockChainConstant.IS_SYNCHRONIZED_N);
addTranList.add(tranBlock);
}
}
if(addTranList !=null && addTranList.size()>0){
if(zBcmBlockTranMapper.insertList(addTranList)>0){
addTranList.forEach(tranLog ->{
Map<String, Object> mapUpdate = new HashMap<>();
mapUpdate.put("isSynchronized",BmpBlockChainConstant.IS_SYNCHRONIZED_Y);
mapUpdate.put("bizHash",tranLog.getBizHashCode());
zBcmBlockTranLogMapper.updateIsSynchronizedToY(mapUpdate);
});
}
}
}
param.putAll(MapUtils.getMap(param,"param"));
Integer pageNum=MapUtils.getInteger(param, "page");
Integer pageSize=MapUtils.getInteger(param, "rows");
pageNum = (pageNum==null? 1:pageNum);
pageSize= (pageSize==null? 10:pageSize);
PageHelper.startPage(pageNum,pageSize);
List<ZBcmBlockTran> list = zBcmBlockTranMapper.selectByCondition(param);
list.forEach(reTran -> {
reTran.setTranValue(reTran.getTranValue().divide(new BigDecimal(CommonContant.AMT_MULTIPLE),2));
});
PageInfo pageInfo = new PageInfo(list);
param.clear();
param.put(BcConstant.TOTAL_SIZE,pageInfo.getTotal());
param.put(BcConstant.PAGENUM,pageInfo.getPageNum());
param.put(BcConstant.PAGESIZE,pageInfo.getPageSize());
param.put("rows",list);
return param;
}
java 表数据同步示例
最新推荐文章于 2024-07-06 02:14:39 发布