|
@@ -15,7 +15,6 @@ import com.imed.costaccount.model.vo.SelectAccountingVO;
|
|
|
import com.imed.costaccount.service.AccountingService;
|
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.beanutils.BeanUtilsBean;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -187,18 +186,81 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
|
* @param user
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
|
|
|
Integer id = accountingEditDTO.getId();
|
|
|
- List<Accounting> accounts = new ArrayList<>();
|
|
|
+ this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
|
|
|
Accounting byId = this.getById(id);
|
|
|
- // TODO: 2021/7/28 校验
|
|
|
- accounts.add(byId);
|
|
|
- // 如果是顶层的修改
|
|
|
- getAndAllChild(Arrays.asList(id), user.getHospId(), accounts);
|
|
|
- log.info("得到所有的这个下面的列表:{}", accounts);
|
|
|
- Map<Integer, List<Accounting>> map = accounts.stream().collect(Collectors.groupingBy(Accounting::getId));
|
|
|
- // 删除所有的列表
|
|
|
-// this.remove
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -220,4 +282,23 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
|
|
|
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);
|
|
|
+ }
|
|
|
}
|