直接上代码
1、入参是List
@Override
@Transactional(rollbackFor = Exception.class)
public void insertAccountTree(List<Tagl25TacAccount> tagl25TacAccounts) {
for (Tagl25TacAccount tagl25TacAccount : tagl25TacAccounts) {
Tagl25TacAccountCriteria tagl25Criteria = new Tagl25TacAccountCriteria();
tagl25Criteria.createCriteria().andCodeEqualTo(tagl25TacAccount.getCode()).andParentSidIsNull();
Tagl25TacAccount tagl25 = iTagl25TacAccountService.doRead(tagl25Criteria);
if (null == tagl25) {
iTagl25TacAccountService.doInsert(tagl25TacAccount);
}
getChildren(tagl25TacAccount.getChildList(), tagl25TacAccount.getSysId());
}
}
public Tagl25TacAccount getChildren(List<Tagl25TacAccount> tagl25TacAccount, BigDecimal sysId) {
if (null != tagl25TacAccount) {
for (Tagl25TacAccount tacAccount : tagl25TacAccount) {
Tagl25TacAccount tagl25 = getAgl25ByCodeAndParentSid(tacAccount.getCode(), tacAccount.getParentSid());
if (null == tagl25) {
//这里将子的父id赋值,获取的是上一个父id
tacAccount.setParentSid(sysId);
iTagl25TacAccountService.doInsert(tacAccount);
}
getChildren(tacAccount.getChildList(), tacAccount.getSysId());
}
}
return null;
}