Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/imed/costaccount/web/AccountingController.java
ljx 4 rokov pred
rodič
commit
7d25036a1f

+ 22 - 0
src/main/java/com/imed/costaccount/model/vo/SelectAccountingVO.java

@@ -0,0 +1,22 @@
+package com.imed.costaccount.model.vo;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SelectAccountingVO {
+
+    private Integer id;
+
+    @JsonIgnore
+    private Integer parentId;
+
+    private String allParentIds;
+
+    private String accountingName;
+
+    private List<SelectAccountingVO> child;
+}

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

@@ -5,6 +5,7 @@ import com.imed.costaccount.model.User;
 import com.imed.costaccount.model.dto.AccountingSaveDTO;
 import com.imed.costaccount.model.vo.AccountVO;
 import com.imed.costaccount.model.Accounting;
+import com.imed.costaccount.model.vo.SelectAccountingVO;
 
 import java.util.List;
 
@@ -31,5 +32,12 @@ public interface AccountingService extends IService<Accounting> {
      * @param user
      */
     void saveAccounting(AccountingSaveDTO accountingSaveDTO, User user);
+
+    /**
+     * 选择会计科目列表
+     * @param user
+     * @return
+     */
+    List<SelectAccountingVO> selectAccounting(User user);
 }
 

+ 48 - 0
src/main/java/com/imed/costaccount/service/impl/AccountingServiceImpl.java

@@ -10,6 +10,7 @@ import com.imed.costaccount.model.Accounting;
 import com.imed.costaccount.model.User;
 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;
@@ -132,4 +133,51 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
             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;
+    }
 }

+ 9 - 7
src/main/java/com/imed/costaccount/web/AccountingController.java

@@ -55,13 +55,15 @@ public class AccountingController {
     }
 
 
-//    @ApiOperation("选择会计科目列表")
-//    @PostMapping("/selectAccounting")
-//    public Result selectAccounting(){
-//        User user = (User) SecurityUtils.getSubject().getPrincipal();
-//        List<SelectAccountingVO> list = accountingService.selectAccounting(accountingSaveDTO,user);
-//        return Result.ok();
-//    }
+    @ApiOperation("选择会计科目列表")
+    @GetMapping("/selectAccounting")
+    public Result selectAccounting(){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+        List<SelectAccountingVO> list = accountingService.selectAccounting(user);
+        return Result.ok(list);
+    }
+
+
     /**
      * 修改
      */