|
@@ -8,23 +8,21 @@ import com.imed.costaccount.common.exception.CostException;
|
|
|
import com.imed.costaccount.mapper.AccountingMapper;
|
|
|
import com.imed.costaccount.model.Accounting;
|
|
|
import com.imed.costaccount.model.User;
|
|
|
+import com.imed.costaccount.model.dto.AccountingEditDTO;
|
|
|
import com.imed.costaccount.model.dto.AccountingSaveDTO;
|
|
|
import com.imed.costaccount.model.vo.AccountVO;
|
|
|
import com.imed.costaccount.model.vo.SelectAccountingVO;
|
|
|
import com.imed.costaccount.service.AccountingService;
|
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
|
-import org.apache.commons.beanutils.BeanUtilsBean;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-
|
|
|
+@Slf4j
|
|
|
@Service("accountingService")
|
|
|
public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Accounting> implements AccountingService {
|
|
|
|
|
@@ -150,7 +148,15 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
// 所有的
|
|
|
- List<SelectAccountingVO> all = list.stream().map(i -> BeanUtil.convertObj(i, SelectAccountingVO.class)).collect(Collectors.toList());
|
|
|
+ List<SelectAccountingVO> all = list.stream().map(i ->{
|
|
|
+ SelectAccountingVO vo = new SelectAccountingVO();
|
|
|
+ vo.setValue(i.getId());
|
|
|
+ vo.setLabel(i.getAccountingName());
|
|
|
+ vo.setChildren(null);
|
|
|
+ vo.setParentId(i.getParentId());
|
|
|
+ vo.setAllParentIds(i.getAllParentIds());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
// 顶层的
|
|
|
List<SelectAccountingVO> parents = all.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
|
|
|
List<SelectAccountingVO> accountVOS = new ArrayList<>();
|
|
@@ -165,13 +171,13 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
|
List<SelectAccountingVO> accountVOS = new ArrayList<>();
|
|
|
for (SelectAccountingVO account : all) {
|
|
|
// 如果是父子关系
|
|
|
- if (parent.getId().equals(account.getParentId())) {
|
|
|
- List<SelectAccountingVO> child = parent.getChild();
|
|
|
+ if (parent.getValue().equals(account.getParentId())) {
|
|
|
+ List<SelectAccountingVO> child = parent.getChildren();
|
|
|
if (CollUtil.isEmpty(child)) {
|
|
|
child = new ArrayList<>();
|
|
|
}
|
|
|
child.add(account);
|
|
|
- parent.setChild(child);
|
|
|
+ parent.setChildren(child);
|
|
|
// 处理子节点
|
|
|
this.getSelectAccountTree(account, all);
|
|
|
|
|
@@ -180,4 +186,127 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
|
}
|
|
|
return accountVOS;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑科目代码
|
|
|
+ *
|
|
|
+ * @param accountingEditDTO
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
|
|
|
+ Integer id = accountingEditDTO.getId();
|
|
|
+ this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
|
|
|
+ Accounting byId = this.getById(id);
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new CostException(500, "当前选中会计科目已被移除");
|
|
|
+ }
|
|
|
+ // 直接修改
|
|
|
+ byId.setAccountingCode(accountingEditDTO.getAccountingCode());
|
|
|
+ byId.setAccountingName(accountingEditDTO.getAccountingName());
|
|
|
+ byId.setCreateTime(System.currentTimeMillis());
|
|
|
+ byId.setAccountingType(accountingEditDTO.getAccountingType());
|
|
|
+ this.updateById(byId);
|
|
|
+// this.removeById(id);
|
|
|
+// Accounting accounting = BeanUtil.convertObj(byId, Accounting.class);
|
|
|
+// saveAccount(accountingEditDTO, user, byId, accounting);
|
|
|
+// List<Accounting> list = new ArrayList<>();
|
|
|
+// this.getAndAllChild(Arrays.asList(id), user.getHospId(), list);
|
|
|
+// log.info("list:{}", list);
|
|
|
+// if (CollUtil.isEmpty(list)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// // 第一个子节点
|
|
|
+// List<Accounting> childList = list.stream().filter(i -> i.getParentId().equals(id)).collect(Collectors.toList());
|
|
|
+// if (CollUtil.isEmpty(childList)) {
|
|
|
+// throw new CostException(500, "数据异常");
|
|
|
+// }
|
|
|
+// childList.forEach(i -> {
|
|
|
+// i.setParentId(accounting.getId());
|
|
|
+// String allParentIds = setAllParentIds(byId);
|
|
|
+// i.setAllParentIds(allParentIds);
|
|
|
+// });
|
|
|
+// this.updateBatchById(childList);
|
|
|
+//
|
|
|
+//
|
|
|
+ }
|
|
|
+
|
|
|
+// private String setAllParentIds(Accounting byId) {
|
|
|
+// Integer parentId = byId.getParentId();
|
|
|
+// // 不是顶层的
|
|
|
+// String allParentIds = "0";
|
|
|
+// if (parentId != 0) {
|
|
|
+// String oldParentIds = byId.getAllParentIds();
|
|
|
+// if ("0".equals(oldParentIds)) {
|
|
|
+// allParentIds = parentId + "";
|
|
|
+// } else {
|
|
|
+// allParentIds = oldParentIds + "-" + parentId;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return allParentIds;
|
|
|
+// }
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public void saveAccount(AccountingEditDTO accountingEditDTO, User user, Accounting byId, Accounting accounting) {
|
|
|
+ this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
|
|
|
+ accounting.setAccountingCode(accounting.getAccountingCode());
|
|
|
+ accounting.setCreateTime(System.currentTimeMillis());
|
|
|
+ // 新增逻辑
|
|
|
+ Integer parentId = byId.getParentId();
|
|
|
+ // 不是顶层的
|
|
|
+ String allParentIds = "0";
|
|
|
+ if (parentId != 0) {
|
|
|
+ String oldParentIds = byId.getAllParentIds();
|
|
|
+ if ("0".equals(oldParentIds)) {
|
|
|
+ allParentIds = parentId + "";
|
|
|
+ } else {
|
|
|
+ allParentIds = oldParentIds + "-" + parentId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ accounting.setHospId(user.getHospId());
|
|
|
+ accounting.setParentId(parentId);
|
|
|
+ accounting.setAllParentIds(allParentIds);
|
|
|
+ accounting.setCreateTime(System.currentTimeMillis());
|
|
|
+ this.save(accounting);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到自己还有所有的子节点
|
|
|
+ * @param ids
|
|
|
+ * @param accounts
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Accounting> getAndAllChild(List<Integer> ids, Integer hospId, List<Accounting> accounts) {
|
|
|
+
|
|
|
+ List<Accounting> list = this.list(
|
|
|
+ new LambdaQueryWrapper<Accounting>()
|
|
|
+ .in(Accounting::getParentId, ids).eq(Accounting::getHospId,hospId)
|
|
|
+ );
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return accounts;
|
|
|
+ }
|
|
|
+ accounts.addAll(list);
|
|
|
+ this.getAndAllChild(list.stream().map(Accounting::getId).collect(Collectors.toList()), hospId, accounts);
|
|
|
+ return accounts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public void deleteAccount(Integer id, User user) {
|
|
|
+ List<Accounting> list = new ArrayList<>();
|
|
|
+ List<Accounting> andAllChild = this.getAndAllChild(Arrays.asList(id), user.getHospId(), list);
|
|
|
+ if (CollUtil.isEmpty(andAllChild)) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+ List<Integer> collect = andAllChild.stream().map(Accounting::getId).collect(Collectors.toList());
|
|
|
+ collect.add(id);
|
|
|
+ this.removeByIds(collect);
|
|
|
+ }
|
|
|
}
|