From 6765787baa5e0b771d71f865c4deb776367410c4 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 13 八月 2024 13:38:19 +0800
Subject: [PATCH] 修复bug

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 104 insertions(+), 15 deletions(-)

diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
index de5e2d6..19b9e48 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.config.DataSyncConfig;
 import com.doumee.core.annotation.excel.ExcelColumn;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
@@ -19,24 +20,25 @@
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.admin.request.UpdateCompanySortDTO;
 import com.doumee.dao.admin.response.CompanyDTO;
 import com.doumee.dao.business.CompanyMapper;
 import com.doumee.dao.business.join.CompanyJoinMapper;
-import com.doumee.dao.business.model.Category;
-import com.doumee.dao.business.model.Company;
-import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.system.dto.UpdateSystemMenuSortDTO;
+import com.doumee.dao.system.model.SystemMenu;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.CompanyService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.doumee.service.common.tree.CompanyTree;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
-import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -55,6 +57,8 @@
 
     @Autowired
     private CompanyMapper companyMapper;
+    @Autowired
+    private DataSyncConfig dataSyncConfig;
     @Autowired
     private SystemDictDataBiz systemDictDataBiz;
 
@@ -82,11 +86,10 @@
             if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
                 throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇缁勭粐淇℃伅涓嶅瓨鍦▇");
             }
-            if(StringUtils.isBlank(parent.getHkParentId())){
+            if(StringUtils.isBlank(parent.getHkId())){
                 throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛~");
-
             }
-            company.setHkParentId(parent.getHkParentId());
+            company.setHkParentId(parent.getHkId());
         }
         company.setCreateDate(new Date());
         company.setCreator(user.getId());
@@ -199,6 +202,7 @@
         if(StringUtils.isBlank(model.getHkId())){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛,鏆備笉鏀寔淇敼锛岃灏濊瘯鍒犻櫎鍚庨噸鏂版坊鍔爚");
         }
+
         Company company = new Company();
         company.setId(id);
         company.setEditDate(new Date());
@@ -440,24 +444,29 @@
     @Override
     public List<CompanyDTO> findCompanyTreePage(Integer type) {
         //閰嶇疆缁勫憳浜哄憳绫诲瀷鏉ユ簮鏂瑰紡 0鑷缓 1ERP
-        String origin = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ORG_USER_ORIGIN).getCode();
         LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
 
         wrapper.eq(Company::getIsdeleted,Constants.ZERO)
                 .eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type);
         List<Company> companies = companyMapper.selectList(wrapper);
-        return getCompanyTree( companies, null,origin);
+        return getCompanyTree( companies, null);
     }
 
 
-    private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId,String origin){
+    private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId){
         if (CollectionUtils.isEmpty(companies)){
             return null;
         }
-        List<Company> collect = companies.stream()
-                                        .filter(s -> (StringUtils.equals(origin, Constants.ONE+"")?StringUtils.equals(s.getErpParentId(), parentId):StringUtils.equals(s.getParentId()+"", parentId)))
-                                        .collect(Collectors.toList());
-        if (CollectionUtils.isEmpty(companies)){
+        int  origin =Constants.formatIntegerNum(dataSyncConfig.getOrgUserDataOrigin());
+        List<Company> collect = null;
+        if(origin == DataSyncConfig.origin.erp){
+            collect=  companies.stream().filter(s -> ( StringUtils.defaultString(s.getErpParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+        }else if(origin == DataSyncConfig.origin.hk){
+            collect= companies.stream().filter(s -> ( StringUtils.defaultString(s.getHkParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+        }else{
+            collect=  companies.stream().filter(s -> (StringUtils.defaultString(s.getParentId()+"","").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+        }
+        if (CollectionUtils.isEmpty(collect)){
             return null;
         }
         List<CompanyDTO> companyDTOList = new ArrayList<>();
@@ -465,7 +474,13 @@
             Company company = collect.get(i);
             CompanyDTO companyDTO = new CompanyDTO();
             BeanUtils.copyProperties(company,companyDTO);
-            companyDTO.setCompanyDTOList(getCompanyTree(companies,StringUtils.equals(origin, Constants.ONE+"")?company.getErpId(): company.getId()+"",origin));
+            String pId = company.getId()+"";
+            if(origin == 1){
+                pId = company.getErpId();
+            }else if(origin == 2){
+                pId = company.getHkParentId();
+            }
+            companyDTO.setCompanyDTOList(getCompanyTree(companies,pId));
             companyDTOList.add(companyDTO);
         }
         return companyDTOList;
@@ -495,4 +510,78 @@
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�");
         }
     }
+
+
+
+    @Override
+    public List<Company> companyTree(Integer type) {
+        MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
+        queryWrapper.selectAll(Company.class);
+        queryWrapper.selectAs(Member::getName,Company::getHeadName);
+        queryWrapper.selectAs(Member::getPhone,Company::getHeadPhone);
+        queryWrapper.leftJoin(Member.class,Member::getId,Company::getHeadId);
+        queryWrapper.eq(Company::getIsdeleted,Constants.ZERO);
+        queryWrapper.eq(Company::getType,type);
+        List<Company> companyList = companyJoinMapper.selectJoinList(Company.class,queryWrapper);
+        //閰嶇疆缁勫憳浜哄憳绫诲瀷鏉ユ簮鏂瑰紡 0鑷缓 1ERP
+        CompanyTree treeBuild = new CompanyTree(companyList, dataSyncConfig.getOrgUserDataOrigin());
+        companyList = treeBuild.buildTree();
+        return companyList;
+    }
+
+
+    @Override
+    public void updateSort(UpdateCompanySortDTO dto) {
+        Company company = companyMapper.selectById(dto.getId());
+        if(Objects.isNull(company)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+
+        List<Company> companyPool;
+        if (company.getParentId() == null) {
+            companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+                    .eq(Company::getIsdeleted,Constants.ZERO)
+                    .isNull(Company::getParentId)
+                    .orderByAsc(Company::getSortnum)
+            );
+        } else {
+            companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+                    .eq(Company::getIsdeleted,Constants.ZERO)
+                    .eq(Company::getParentId,company.getParentId())
+                    .orderByAsc(Company::getSortnum)
+            );
+        }
+        int currentMenuIndex = 0;
+        for (int i = 0; i < companyPool.size(); i++) {
+            if (companyPool.get(i).getId().equals(dto.getId())) {
+                currentMenuIndex = i;
+                break;
+            }
+        }
+        // 涓婄Щ
+        if ("top".equals(dto.getDirection())) {
+            if (currentMenuIndex - 1 < 0) {
+                return;
+            }
+            Company preMenu = companyPool.remove(currentMenuIndex - 1);
+            companyPool.add(currentMenuIndex, preMenu);
+        }
+        // 涓嬬Щ
+        else {
+            if (currentMenuIndex + 1 > companyPool.size() - 1) {
+                return;
+            }
+            Company nextMenu = companyPool.remove(currentMenuIndex + 1);
+            companyPool.add(currentMenuIndex, nextMenu);
+        }
+        for (int i = 0; i < companyPool.size(); i++) {
+            companyPool.get(i).setSortnum(i);
+        }
+
+        for (Company updCompany:companyPool) {
+            companyMapper.updateById(updCompany);
+        }
+
+    }
+
 }

--
Gitblit v1.9.3