Explorar o código

企微部门 树状查询 添加

xgb hai 6 días
pai
achega
d83f29fa98

+ 19 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwDeptController.java

@@ -7,6 +7,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.ServletUtils;
+import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
@@ -120,4 +121,22 @@ public class QwDeptController extends BaseController
     {
         return toAjax(qwDeptService.deleteQwDeptByIds(ids));
     }
+
+    /**
+     * @Description: 获取企微部门 按Treeselect返回 每一个企微主体有自己的部门,按企微主体查询
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2025/10/30 9:33
+     */
+    @GetMapping("/treeselect")
+    public AjaxResult treeselect(QwDept qwDept)
+    {
+        if(StringUtils.isEmpty(qwDept.getCorpId())){
+            return AjaxResult.error("请选择企微主体");
+        }
+        List<QwDept> depts = qwDeptService.selectQwDeptList(qwDept);
+        return AjaxResult.success(qwDeptService.buildDeptTreeSelect(depts));
+    }
+
 }

+ 2 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyServiceImpl.java

@@ -434,7 +434,8 @@ public class CompanyServiceImpl implements ICompanyService
                 orderMap.setOrderId(order.getId());
                 orderMap.setTuiMoneyStatus(1);
                 storeOrderMapper.updateFsStoreOrder(orderMap);
-                BigDecimal money = order.getPayMoney().add(order.getPayRemain());
+                // order.getPayRemain() 数据库实际没有这个字段了 直接使用 应付金额
+                BigDecimal money = order.getPayPrice();
                 company.setMoney(company.getMoney().add(money));
                 companyMapper.updateCompany(company);
                 CompanyMoneyLogs log=new CompanyMoneyLogs();

+ 48 - 0
fs-service/src/main/java/com/fs/qw/domain/QwDeptTreeSelect.java

@@ -0,0 +1,48 @@
+package com.fs.qw.domain;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class QwDeptTreeSelect implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+    private String label;
+    private List<QwDeptTreeSelect> children;
+
+    // 构造方法
+    public QwDeptTreeSelect() {
+    }
+
+    public QwDeptTreeSelect(Long id, String label) {
+        this.id = id;
+        this.label = label;
+        this.children = new ArrayList<>();
+    }
+
+    // getter和setter
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public List<QwDeptTreeSelect> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<QwDeptTreeSelect> children) {
+        this.children = children;
+    }
+}

+ 3 - 0
fs-service/src/main/java/com/fs/qw/service/IQwDeptService.java

@@ -2,6 +2,7 @@ package com.fs.qw.service;
 
 import com.fs.common.core.domain.R;
 import com.fs.qw.domain.QwDept;
+import com.fs.qw.domain.QwDeptTreeSelect;
 
 import java.util.List;
 
@@ -69,4 +70,6 @@ public interface IQwDeptService
      * @return 结果
      */
     public int deleteQwDeptById(Long id);
+
+    List<QwDeptTreeSelect> buildDeptTreeSelect(List<QwDept> depts);
 }

+ 69 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwDeptServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.qw.service.impl;
 
 import com.fs.common.core.domain.R;
 import com.fs.qw.domain.QwDept;
+import com.fs.qw.domain.QwDeptTreeSelect;
 import com.fs.qw.mapper.QwDeptMapper;
 import com.fs.qw.service.IQwDeptService;
 import com.fs.qwApi.domain.QwDeptResult;
@@ -10,7 +11,11 @@ import com.fs.qwApi.service.QwApiService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 企业微信部门Service业务层处理
@@ -129,4 +134,68 @@ public class QwDeptServiceImpl implements IQwDeptService
     {
         return qwDeptMapper.deleteQwDeptById(id);
     }
+
+    /**
+     * @Description: 按TreeSelect结构返回部门
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2025/10/30 9:37
+     */
+    @Override
+    /**
+     * 将部门列表转换为TreeSelect树形结构
+     */
+    public List<QwDeptTreeSelect> buildDeptTreeSelect(List<QwDept> deptList) {
+        if (deptList == null || deptList.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        // 按父部门ID分组
+        Map<Long, List<QwDept>> deptMap = deptList.stream()
+                .collect(Collectors.groupingBy(QwDept::getParentid));
+
+        // 获取所有根部门(parentId = 0)
+        List<QwDept> rootDepts = deptMap.getOrDefault(0L, new ArrayList<>());
+
+        // 构建树形结构
+        return rootDepts.stream()
+                .map(dept -> buildTreeSelect(dept, deptMap))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * 递归构建TreeSelect节点
+     */
+    private QwDeptTreeSelect buildTreeSelect(QwDept dept, Map<Long, List<QwDept>> deptMap) {
+        return buildTreeSelect(dept, deptMap, 0);
+    }
+
+    /**
+     * 递归构建TreeSelect节点,最多5级
+     */
+    private QwDeptTreeSelect buildTreeSelect(QwDept dept, Map<Long, List<QwDept>> deptMap, int depth) {
+        // 限制最多5级,避免死循环
+        if (depth > 5) {
+            return new QwDeptTreeSelect(dept.getId(), dept.getDeptName());
+        }
+
+        QwDeptTreeSelect treeSelect = new QwDeptTreeSelect(dept.getId(), dept.getDeptName());
+
+        // 获取当前部门的子部门
+        List<QwDept> children = deptMap.get(dept.getDeptId());
+        if (children != null && !children.isEmpty()) {
+            // 递归构建子节点
+            List<QwDeptTreeSelect> childNodes = children.stream()
+                    .map(child -> buildTreeSelect(child, deptMap, depth + 1))
+                    .collect(Collectors.toList());
+            treeSelect.setChildren(childNodes);
+        }
+
+        return treeSelect;
+    }
+
+
+
+
 }