|
@@ -10,6 +10,7 @@ import com.imed.costaccount.model.Accounting;
|
|
import com.imed.costaccount.model.User;
|
|
import com.imed.costaccount.model.User;
|
|
import com.imed.costaccount.model.dto.AccountingSaveDTO;
|
|
import com.imed.costaccount.model.dto.AccountingSaveDTO;
|
|
import com.imed.costaccount.model.vo.AccountVO;
|
|
import com.imed.costaccount.model.vo.AccountVO;
|
|
|
|
+import com.imed.costaccount.model.vo.SelectAccountingVO;
|
|
import com.imed.costaccount.service.AccountingService;
|
|
import com.imed.costaccount.service.AccountingService;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import org.apache.commons.beanutils.BeanUtilsBean;
|
|
import org.apache.commons.beanutils.BeanUtilsBean;
|
|
@@ -132,4 +133,51 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
throw new CostException(500, "会计科目代码已存在,请重新生成");
|
|
throw new CostException(500, "会计科目代码已存在,请重新生成");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 选择会计科目列表
|
|
|
|
+ *
|
|
|
|
+ * @param user
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<SelectAccountingVO> selectAccounting(User user) {
|
|
|
|
+ List<Accounting> list = this.list(
|
|
|
|
+ new LambdaQueryWrapper<Accounting>().select(Accounting::getId,Accounting::getAccountingName,Accounting::getParentId,Accounting::getAllParentIds)
|
|
|
|
+ .eq(Accounting::getHospId, user.getHospId())
|
|
|
|
+ );
|
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+ // 所有的
|
|
|
|
+ List<SelectAccountingVO> all = list.stream().map(i -> BeanUtil.convertObj(i, SelectAccountingVO.class)).collect(Collectors.toList());
|
|
|
|
+ // 顶层的
|
|
|
|
+ List<SelectAccountingVO> parents = all.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
|
|
|
|
+ List<SelectAccountingVO> accountVOS = new ArrayList<>();
|
|
|
|
+ for (SelectAccountingVO parent : parents) {
|
|
|
|
+ List<SelectAccountingVO> accountTree = this.getSelectAccountTree(parent, all);
|
|
|
|
+ accountVOS.addAll(accountTree);
|
|
|
|
+ }
|
|
|
|
+ return accountVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<SelectAccountingVO> getSelectAccountTree(SelectAccountingVO parent, List<SelectAccountingVO> all) {
|
|
|
|
+ List<SelectAccountingVO> accountVOS = new ArrayList<>();
|
|
|
|
+ for (SelectAccountingVO account : all) {
|
|
|
|
+ // 如果是父子关系
|
|
|
|
+ if (parent.getId().equals(account.getParentId())) {
|
|
|
|
+ List<SelectAccountingVO> child = parent.getChild();
|
|
|
|
+ if (CollUtil.isEmpty(child)) {
|
|
|
|
+ child = new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ child.add(account);
|
|
|
|
+ parent.setChild(child);
|
|
|
|
+ // 处理子节点
|
|
|
|
+ this.getSelectAccountTree(account, all);
|
|
|
|
+
|
|
|
|
+ accountVOS.add(parent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return accountVOS;
|
|
|
|
+ }
|
|
}
|
|
}
|