HashBasedTable<Integer, Integer, Model> countModel = HashBasedTable.create();
使用: countModel.put(x,x,boj);调用put方法添加值;
public HashBasedTable<Integer, Integer, Model> setModel (HashBasedTable<Integer, Integer, AccountModel> countModel, Integer.......){
countModel.put(userId,coinType, acc);
return countModel;
);
public void updateAccountsAndSaveFlows(HashBasedTable<Integer, Integer, AccountModel> accountMap,
HashBasedTable<Integer, Integer, List<FlowBase>> flowMap) throws AntConcurrenceException {
Set<Integer> userIdKeys = accountMap.rowKeySet();
Object[] keyArr = userIdKeys.toArray();
Arrays.sort(keyArr);
for(Object userId: keyArr ){
Integer id = Integer.parseInt(userId.toString());
Map<Integer, AccountModel> coinAccMap = accountMap.row(id);
for(Entry<Integer, AccountModel> entry :coinAccMap.entrySet()){
AccountModel increment = entry.getValue();
AccountSpot account = queryByUserIdAndType(id,entry.getKey());
List<FlowBase> flowList = flowMap.get(userId,entry.getKey());
if(account==null){
account = new AccountSpot();
account.setUserId(id);
account.setType(increment.getCoinType());
account.setAvailBalance(increment.getAvailIncrement());
account.setFrozenBlance(increment.getFrozenIncrement());
account.setVersion(0);
}
updateAccoutAndSaveFlows(account,increment.getAvailIncrement(),increment.getFrozenIncrement(),flowList);
}
}
}
public void updateAccoutAndSaveFlows(AccountSpot spot,BigDecimal availIncrement,BigDecimal frozenIncrement, List<FlowBase> flowList)
throws AntConcurrenceException {
//更新账户信息
updateAccountSpot(spot,availIncrement,frozenIncrement);
/*记录流水列表*/
BigDecimal accAmount = spot.getAvailBalance();
if(flowList!=null&&!flowList.isEmpty()){
/*循环更新流水表中的操作后账户余额*/
for(int i = 0;i<flowList.size();i++){
//操作后账户余额
accAmount = BigDecimalUtils.add(accAmount, flowList.get(i).getAmount());
flowList.get(i).setAccAmount(accAmount);
}
for(FlowBase flow:flowList){
flowDao.save(flow);
}
}
}
public FlowBase save(FlowBase flow) {
if(flow instanceof FlowHlc){
int userId = flow.getUserId();
String tableName = getTableNameByCoin(userId,CoinType.HLC.code());
if(!commonDao.checkTableExist(tableName)) createFlowTable(tableName);
insertFlow(tableName,flow);
}else if(flow instanceof FlowHyc){
int userId = flow.getUserId();
String tableName = getTableNameByCoin(userId,CoinType.HYC.code());;
if(!commonDao.checkTableExist(tableName)) createFlowTable(tableName);
insertFlow(tableName,flow);
}else{
dao.save(flow);
}
return flow;
}