Browse Source

07 28 06 add accounting codes

hr 4 năm trước cách đây
mục cha
commit
f392d6526a

+ 22 - 0
src/main/java/com/imed/costaccount/model/dto/AccountingEditDTO.java

@@ -0,0 +1,22 @@
+package com.imed.costaccount.model.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+@Data
+public class AccountingEditDTO {
+
+    @NotNull(message = "id不能为空")
+    private Integer id;
+
+    @NotEmpty(message = "科目代码不能为空")
+    private String accountingCode;
+
+    @NotEmpty(message = "科目名称不能为空")
+    private String accountingName;
+
+    @NotNull(message = "会计科目类型不能为空")
+    private Integer accountingType;
+}

+ 8 - 0
src/main/java/com/imed/costaccount/service/AccountingService.java

@@ -2,6 +2,7 @@ package com.imed.costaccount.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 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.Accounting;
@@ -39,5 +40,12 @@ public interface AccountingService extends IService<Accounting> {
      * @return
      */
     List<SelectAccountingVO> selectAccounting(User user);
+
+    /**
+     * 编辑科目代码
+     * @param accountingEditDTO
+     * @param user
+     */
+    void updateAccount(AccountingEditDTO accountingEditDTO, User user);
 }
 

+ 45 - 5
src/main/java/com/imed/costaccount/service/impl/AccountingServiceImpl.java

@@ -8,23 +8,22 @@ 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 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;
 
-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 {
 
@@ -180,4 +179,45 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
         }
         return accountVOS;
     }
+
+    /**
+     * 编辑科目代码
+     *
+     * @param accountingEditDTO
+     * @param user
+     */
+    @Override
+    public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
+        Integer id = accountingEditDTO.getId();
+        List<Accounting> accounts = new ArrayList<>();
+        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
+    }
+
+    /**
+     * 得到自己还有所有的子节点
+     * @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;
+    }
 }

+ 5 - 1
src/main/java/com/imed/costaccount/service/impl/ResponsibilityDepartmentServiceImpl.java

@@ -43,7 +43,11 @@ public class ResponsibilityDepartmentServiceImpl
     public List<CenterDepartmentVO> getCenterDepart(User user) {
         List<CenterDepartmentVO> list = responsibilityService.getParentSon(user);
         for (CenterDepartmentVO centerDepartmentVO : list) {
-            for (CenterDepartmentVO departmentVO : centerDepartmentVO.getChild()) {
+            List<CenterDepartmentVO> child = centerDepartmentVO.getChild();
+            if (CollUtil.isEmpty(child)) {
+                child = new ArrayList<>();
+            }
+            for (CenterDepartmentVO departmentVO : child) {
                 List<DepartVO> departVOS = baseMapper.getDepartByCenterId(departmentVO.getResponsibilityId());
                 departmentVO.setDepartments(departVOS);
             }

+ 4 - 3
src/main/java/com/imed/costaccount/web/AccountingController.java

@@ -6,6 +6,7 @@ import java.util.Map;
 
 import com.imed.costaccount.common.util.Result;
 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;
@@ -73,10 +74,10 @@ public class AccountingController {
     /**
      * 修改
      */
-    @RequestMapping("/update")
-    public Result update(@RequestBody Accounting accounting){
+    @RequestMapping("/edit")
+    public Result update(@RequestBody @Valid AccountingEditDTO accountingEditDTO){
         User user = (User) SecurityUtils.getSubject().getPrincipal();
-//		accountingService.updateById(accounting,user);
+		accountingService.updateAccount(accountingEditDTO,user);
         return Result.ok();
     }