From 3b759ef71bb48f9bb6f8445770d20e8ea7921788 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 06 一月 2026 13:58:14 +0800
Subject: [PATCH] Merge branch 'wuhuyancao' of http://139.186.142.91:10010/r/productDev/dmvisit into wuhuyancao

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java | 1392 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 1,355 insertions(+), 37 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
index 2c9996d..34f3fb1 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -1,13 +1,22 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.dingtalk.api.response.OapiV2DepartmentGetResponse;
+import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.config.DataSyncConfig;
 import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.dingTalk.DingTalk;
+import com.doumee.core.erp.ErpConstants;
+import com.doumee.core.erp.model.openapi.request.erp.OrgListRequest;
+import com.doumee.core.erp.model.openapi.response.erp.ERPApiResponse;
+import com.doumee.core.erp.model.openapi.response.erp.ErpOrgListResponse;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.haikang.model.HKConstants;
 import com.doumee.core.haikang.model.param.BaseResponse;
@@ -17,14 +26,19 @@
 import com.doumee.core.haikang.model.param.respose.OrgOrUserAddResponse;
 import com.doumee.core.haikang.model.param.respose.OrgUpdateFailureResponse;
 import com.doumee.core.haikang.service.HKService;
-import com.doumee.core.model.LoginUserInfo;
-import com.doumee.core.model.PageData;
-import com.doumee.core.model.PageWrap;
+import com.doumee.core.jiandaoyun.api.arch.DeptApiClient;
+import com.doumee.core.jiandaoyun.constants.HttpConstant;
+import com.doumee.core.jiandaoyun.model.dept.DeptEntityModel;
+import com.doumee.core.wms.model.response.WmsBaseDataResponse;
+import com.doumee.core.wms.model.response.WmsBaseResponse;
+import com.doumee.service.business.third.model.LoginUserInfo;
+import com.doumee.service.business.third.model.PageData;
+import com.doumee.service.business.third.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.MemberMapper;
+import com.doumee.dao.business.dao.MemberMapper;
 import com.doumee.dao.business.dao.CompanyMapper;
 import com.doumee.dao.business.dao.join.CompanyJoinMapper;
 import com.doumee.dao.business.model.Company;
@@ -41,6 +55,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import shade.com.alibaba.fastjson2.JSONArray;
+import shade.com.alibaba.fastjson2.JSONObject;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -64,6 +80,9 @@
 
     @Autowired
     private CompanyJoinMapper companyJoinMapper;
+
+    @Autowired
+    private DingTalk dingTalk;
 
     @Override
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
@@ -97,12 +116,19 @@
             if(StringUtils.isBlank(parent.getHkId())){
                 throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛~");
             }
-            if(Constants.equalsInteger(parent.getType(),Constants.ZERO)){
-                //濡傛灉鐖剁骇鏄浉鍏虫柟缁勭粐锛屼笅绾т笉鑳藉缓绔嬪唴閮ㄧ粍缁�
-                if(Constants.equalsInteger(company.getType(),Constants.ONE)){
-                    throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐩稿叧鏂圭粍缁囷紝涓嬬骇涓嶈兘寤虹珛鍐呴儴缁勭粐~");
+            if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
+                if(!Constants.equalsInteger(company.getType(),parent.getType())){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
                 }
+            }else if(Objects.isNull(parent.getType())){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
             }
+//            if(Constants.equalsInteger(parent.getType(),Constants.ZERO)){
+//                //濡傛灉鐖剁骇鏄浉鍏虫柟缁勭粐锛屼笅绾т笉鑳藉缓绔嬪唴閮ㄧ粍缁�
+//                if(Constants.equalsInteger(company.getType(),Constants.ONE)){
+//                    throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐩稿叧鏂圭粍缁囷紝涓嬬骇涓嶈兘寤虹珛鍐呴儴缁勭粐~");
+//                }
+//            }
             idPath = parent.getCompanyPath();
             company.setHkParentId(parent.getHkId());
             company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
@@ -118,6 +144,7 @@
         company.setHkDate(company.getCreateDate());
         company.setEditDate(company.getCreateDate());
         company.setEditor(company.getCreator());
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
         company.setHkId(UUID.randomUUID().toString().replace("-",""));
         companyMapper.insert(company);
         //涓嬪彂娴峰悍瀹夐槻骞冲彴
@@ -135,7 +162,7 @@
         List<OrgAddRequest> addList = new ArrayList<>();
         addList.add(getOrgAddModel(company));
         BaseResponse<OrgOrUserAddResponse> result =  HKService.addBatchOrg(addList);
-        if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
+        if(result !=null && StringUtils.equals(result.getCode(), HKConstants.RESPONSE_SUCCEE)){
             OrgOrUserAddResponse data = result.getData();
             if(data.getSuccesses()!=null && data.getSuccesses().size()>0){
                 //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
@@ -150,8 +177,8 @@
         OrgEditRequest request = (getOrgHkEditModel(company));
         BaseResponse result =  HKService.editOrg(request);
         if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
-                //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
-                return true;
+            //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
+            return true;
         }
         return false;
     }
@@ -161,7 +188,7 @@
         request.setIndexCodes(new String[]{company.getHkId()});
         BaseResponse<List<OrgUpdateFailureResponse>> result =  HKService.delBatchOrg(request);
         if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
-                //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
+            //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
             if(result.getData()!=null && result.getData().size()==0){
                 return true;
             }
@@ -169,7 +196,6 @@
 
         return false;
     }
-
 
     private OrgAddRequest getOrgAddModel(Company c ) {
         OrgAddRequest model = new OrgAddRequest();
@@ -209,6 +235,7 @@
         insert.setCode(company.getCode());
         insert.setParentId(company.getParentId());
         insert.setLinkName(company.getLinkName());
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
         insert.setLinkPhone(company.getLinkPhone());
         companyMapper.insert(insert);
         return insert.getId();
@@ -272,7 +299,7 @@
         if(company.getId() == null|| StringUtils.isBlank(company.getName())){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
-        if(company.getType()!=null && !(company.getType() ==0 || company.getType() ==1)){
+        if(company.getType()!=null && !(company.getType() ==-1 || company.getType() ==0 || company.getType() ==1)){
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝缁勭粐绫诲瀷涓嶆纭紝璇锋寜瑕佹眰濉啓~");
         }
         //鏌ヨ鍚嶇О涓嶈兘閲嶅
@@ -290,40 +317,42 @@
         if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅涓嶅瓨鍦▇");
         }
-         if( Constants.equalsInteger(Constants.ONE,model.getType())&& Constants.equalsInteger(Constants.ZERO,company.getType())){
-        //濡傛灉鐢卞唴閮ㄧ粍缁囧垏鎹㈡垚鍐呴儴缁勭粐锛屾帓鏌ヤ笅绾х粍缁囨槸鍚︽湁鍐呴儴缁勭粐
-             if(companyJoinMapper.selectCount(new QueryWrapper<Company>().lambda()
-                     .eq(Company::getIsdeleted,Constants.ZERO )
-                     .eq(Company::getType,Constants.ONE )
-                     .ne(Company::getId,model.getId())
-                     .likeRight(Company::getCompanyPath,model.getCompanyPath())) >0){
-                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝涓嬬骇閮ㄩ棬瀛樺湪鍐呴儴缁勭粐锛岃閮ㄩ棬涓嶆敮鎸佸垏鎹负鐩稿叧鏂圭粍缁囷紒~");
-             }
-        }
+
+//         if( Constants.equalsInteger(Constants.ONE,model.getType())&& Constants.equalsInteger(Constants.ZERO,company.getType())){
+//        //濡傛灉鐢卞唴閮ㄧ粍缁囧垏鎹㈡垚鍐呴儴缁勭粐锛屾帓鏌ヤ笅绾х粍缁囨槸鍚︽湁鍐呴儴缁勭粐
+//             if(companyJoinMapper.selectCount(new QueryWrapper<Company>().lambda()
+//                     .eq(Company::getIsdeleted,Constants.ZERO )
+//                     .eq(Company::getType,Constants.ONE )
+//                     .ne(Company::getId,model.getId())
+//                     .likeRight(Company::getCompanyPath,model.getCompanyPath())) >0){
+//                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝涓嬬骇閮ㄩ棬瀛樺湪鍐呴儴缁勭粐锛岃閮ㄩ棬涓嶆敮鎸佸垏鎹负鐩稿叧鏂圭粍缁囷紒~");
+//             }
+//        }
+        company.setType(null);
         company.setEditDate(new Date());
         company.setEditor(user.getId());
         company.setHkStatus(Constants.ONE);
         company.setHkDate(company.getHkDate());
         company.setHkId(StringUtils.defaultString(model.getHkId(),UUID.randomUUID().toString().replace("-","")));
         company.setParentId(null);//涓嶆敮鎸佷慨鏀圭埗绾�
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
         companyMapper.updateById(company);
         //鏇存柊鐨刢ompanyPath
         String newName = model.getCompanyNamePath().replace(model.getName(),company.getName());
         companyMapper.update(null,new UpdateWrapper<Company>().lambda()
-                        .setSql("company_name_path=REPLACE(company_name_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
-                        .setSql("hk_company_path=REPLACE(hk_company_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
+                .setSql("company_name_path=REPLACE(company_name_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
+                .setSql("hk_company_path=REPLACE(hk_company_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
                 .likeRight(Company::getCompanyPath,model.getCompanyPath()));
         //涓嬪彂娴峰悍瀹夐槻骞冲彴
         if(StringUtils.isNotBlank(model.getHkId())){
-             if(!editHkOrg(company)){
-                 throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
-             }
+            if(!editHkOrg(company)){
+                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
+            }
         }else{//濡傛灉娌℃湁涓嬪彂杩囷紝鐩存帴鏂板缓瀹夐槻骞冲彴缁勭粐
             if(!addHkOrg(company)){
                 throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
             }
         }
-
     }
 
     @Override
@@ -356,8 +385,114 @@
 
     @Override
     public List<Company> findList(Company company) {
-        QueryWrapper<Company> wrapper = new QueryWrapper<>(company);
-        return companyMapper.selectList(wrapper);
+        MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
+        if (company.getId() != null) {
+            queryWrapper.eq(Company::getId, company.getId());
+        }
+        if (company.getCreator() != null) {
+            queryWrapper.eq(Company::getCreator, company.getCreator());
+        }
+        if (company.getCreateDate() != null) {
+            queryWrapper.ge(Company::getCreateDate, Utils.Date.getStart(company.getCreateDate()));
+            queryWrapper.le(Company::getCreateDate, Utils.Date.getEnd(company.getCreateDate()));
+        }
+        if (company.getEditor() != null) {
+            queryWrapper.eq(Company::getEditor, company.getEditor());
+        }
+        if (company.getEditDate() != null) {
+            queryWrapper.ge(Company::getEditDate, Utils.Date.getStart(company.getEditDate()));
+            queryWrapper.le(Company::getEditDate, Utils.Date.getEnd(company.getEditDate()));
+        }
+        if (company.getIsdeleted() != null) {
+            queryWrapper.eq(Company::getIsdeleted, company.getIsdeleted());
+        }
+        if (company.getName() != null) {
+            queryWrapper.like(Company::getName, company.getName());
+        }
+        if (company.getRemark() != null) {
+            queryWrapper.eq(Company::getRemark, company.getRemark());
+        }
+        if (company.getStatus() != null) {
+            queryWrapper.eq(Company::getStatus, company.getStatus());
+        }
+        if (company.getSortnum() != null) {
+            queryWrapper.eq(Company::getSortnum, company.getSortnum());
+        }
+        if (company.getImgurl() != null) {
+            queryWrapper.eq(Company::getImgurl, company.getImgurl());
+        }
+        if (company.getType() != null) {
+            queryWrapper.eq(Company::getType, company.getType());
+        }
+        if (company.getCategoryId() != null) {
+            queryWrapper.eq(Company::getCategoryId, company.getCategoryId());
+        }
+        if (company.getCode() != null) {
+            queryWrapper.eq(Company::getCode, company.getCode());
+        }
+        if (company.getParentId() != null) {
+            queryWrapper.eq(Company::getParentId, company.getParentId());
+        }
+        if (company.getLinkName() != null) {
+            queryWrapper.eq(Company::getLinkName, company.getLinkName());
+        }
+        if (company.getLinkPhone() != null) {
+            queryWrapper.eq(Company::getLinkPhone, company.getLinkPhone());
+        }
+        if (company.getHkId() != null) {
+            queryWrapper.eq(Company::getHkId, company.getHkId());
+        }
+        if (company.getHkStatus() != null) {
+            queryWrapper.eq(Company::getHkStatus, company.getHkStatus());
+        }
+        if (company.getHkDate() != null) {
+            queryWrapper.ge(Company::getHkDate, Utils.Date.getStart(company.getHkDate()));
+            queryWrapper.le(Company::getHkDate, Utils.Date.getEnd(company.getHkDate()));
+        }
+        if (company.getErpId() != null) {
+            queryWrapper.eq(Company::getErpId, company.getErpId());
+        }
+        if (company.getErpDate() != null) {
+            queryWrapper.ge(Company::getErpDate, Utils.Date.getStart(company.getErpDate()));
+            queryWrapper.le(Company::getErpDate, Utils.Date.getEnd(company.getErpDate()));
+        }
+        if (company.getErpStatus() != null) {
+            queryWrapper.eq(Company::getErpStatus, company.getErpStatus());
+        }
+        if (company.getDdId() != null) {
+            queryWrapper.eq(Company::getDdId, company.getDdId());
+        }
+        if (company.getDdDate() != null) {
+            queryWrapper.ge(Company::getDdDate, Utils.Date.getStart(company.getDdDate()));
+            queryWrapper.le(Company::getDdDate, Utils.Date.getEnd(company.getDdDate()));
+        }
+        if (company.getDdStatus() != null) {
+            queryWrapper.eq(Company::getDdStatus, company.getDdStatus());
+        }
+        if (company.getFsId() != null) {
+            queryWrapper.eq(Company::getFsId, company.getFsId());
+        }
+        if (company.getFsStatus() != null) {
+            queryWrapper.eq(Company::getFsStatus, company.getFsStatus());
+        }
+        if (company.getFsDate() != null) {
+            queryWrapper.ge(Company::getFsDate, Utils.Date.getStart(company.getFsDate()));
+            queryWrapper.le(Company::getFsDate, Utils.Date.getEnd(company.getFsDate()));
+        }
+        if (company.getQueryHiddenDanger() != null && Constants.equalsInteger(company.getQueryHiddenDanger(),Constants.ONE)) {
+            queryWrapper.apply(" t.id in ( select hdp.COMPANY_ID from hidden_danger_param hdp where hdp.ISDELETED = 0 and hdp.STATUS = 0 and hdp.TYPE = 0  ) ");
+        }
+        queryWrapper.orderByAsc(Company::getPinyin);
+        queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
+        queryWrapper.select(" t.* ")
+                .select("(select count(m.id) from member m where m.COMPANY_ID=t.id and m.ISDELETED=0) as countNum") ;
+        queryWrapper.select("t1.name",Company::getParentName);
+        queryWrapper.select("t1.company_path",Company::getParentCompanyPath);
+        queryWrapper.apply(" t.isdeleted = 0 ") ;
+        queryWrapper.eq(Objects.nonNull(company.getStatus()),Company::getStatus,Constants.ZERO);
+        queryWrapper.like(StringUtils.isNotBlank(company.getName()),Company::getName,company.getName());
+        queryWrapper.like(StringUtils.isNotBlank(company.getParentName()),"c.name",company.getParentName());
+        return companyMapper.selectList(queryWrapper);
     }
 
     @Override
@@ -459,10 +594,9 @@
             queryWrapper.ge(Company::getFsDate, Utils.Date.getStart(pageWrap.getModel().getFsDate()));
             queryWrapper.le(Company::getFsDate, Utils.Date.getEnd(pageWrap.getModel().getFsDate()));
         }
-        queryWrapper.orderByDesc(Company::getCreateDate);
         queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
         /*        .leftJoin(Member.class, Member::getId,Company::getHeadId)*/
-      /*  queryWrapper.leftJoin(" company c on c.id=t.parent_id");*/
+        /*  queryWrapper.leftJoin(" company c on c.id=t.parent_id");*/
         queryWrapper.selectAll(Company.class)
                 .select("(select count(m.id) from member m where m.COMPANY_ID=t.id and m.ISDELETED=0) as countNum") ;
         queryWrapper.select("t1.name",Company::getParentName);
@@ -470,6 +604,7 @@
         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getStatus()),Company::getStatus,Constants.ZERO);
         queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Company::getName,pageWrap.getModel().getName());
         queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getParentName()),"c.name",pageWrap.getModel().getParentName());
+        queryWrapper.orderByAsc(Company::getSortnum);
         IPage<Company> companyIPage = companyJoinMapper.selectJoinPage(page, Company.class, queryWrapper);
         return PageData.from(companyIPage);
     }
@@ -498,7 +633,8 @@
         LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
 
         wrapper.eq(Company::getIsdeleted,Constants.ZERO)
-                .eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type);
+                .eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type)
+                .orderByAsc(Company::getSortnum);
         List<Company> companies = companyMapper.selectList(wrapper);
         return getCompanyTree( companies, null);
     }
@@ -512,7 +648,8 @@
         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());
+            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());
         }
@@ -550,6 +687,7 @@
         if (CollectionUtils.isEmpty(companies)){
             return;
         }
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
         //鏂板鐨勬儏鍐靛瓨鍦ㄨ褰�
         if (Objects.isNull(company.getId())){
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�");
@@ -576,7 +714,15 @@
         queryWrapper.leftJoin(Member.class,Member::getId,Company::getHeadId);
         queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Company::getEditor);
         queryWrapper.eq(Company::getIsdeleted,Constants.ZERO);
-        queryWrapper.eq(type!=null,Company::getType,type);
+        if(Objects.nonNull(type) && ( Constants.equalsInteger(type,Constants.ONE) || Constants.equalsInteger(type,Constants.ZERO))){
+//            queryWrapper.eq(type!=null,Company::getType,type);
+            queryWrapper.apply("( t.type = "+type+" or t.type  = -1  )");
+        }else if(Objects.nonNull(type) &&  Constants.equalsInteger(type,Constants.TWO)){
+            String companySpecialId = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SPECIAL_COMPANY_ID).getCode();
+            if(StringUtils.isNotBlank(companySpecialId)){
+                queryWrapper.apply(" (find_in_set('"+companySpecialId+"',REPLACE(t.company_path,'/',','))  or t.parent_id  is null  )  ");
+            }
+        }
         queryWrapper.orderByAsc(true,"t.sortnum");
         List<Company> companyList = companyJoinMapper.selectJoinList(Company.class,queryWrapper);
         //閰嶇疆缁勫憳浜哄憳绫诲瀷鏉ユ簮鏂瑰紡 0鑷缓 1ERP
@@ -638,7 +784,1179 @@
         for (Company updCompany:companyPool) {
             companyMapper.updateById(updCompany);
         }
+    }
 
+
+
+    // org_dept_create 閮ㄩ棬鏂板缓 {"timeStamp":"1758783935796","eventId":"0c779adba04143958a3960e8e36bbce5","deptId":[1040735458]}
+    // org_dept_modify 閮ㄩ棬淇敼 {"timeStamp":"1758785791639","eventId":"6c2d8c7a61a7419e8928fda3effb3bf4","deptId":[1040735458]}
+    // org_dept_remove 閮ㄩ棬鍒犻櫎 {"timeStamp":"1758785817760","eventId":"47e289f334e041719ed354052da474de","deptId":[1040735458]}
+
+    @Override
+    public void ddPushCompanyInfo(String eventType, JSONObject eventData)  {
+        try {
+            JSONArray jsonArray = eventData.getJSONArray("deptId");
+            if(jsonArray.isEmpty()){
+                return;
+            }
+            if(eventType.equals("org_dept_remove")){
+                //鍒犻櫎瀵瑰簲閮ㄩ棬淇℃伅
+                List<Long> deptIdList = new ArrayList<>();
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    Long deptId = jsonArray.getLong(i);
+                    deptIdList.add(deptId);
+                }
+                if(CollectionUtils.isNotEmpty(deptIdList)){
+                    syncDelCompany( companyMapper.selectList(new QueryWrapper<Company>()
+                            .lambda()
+                            .eq(Company::getIsdeleted,Constants.ZERO)
+                            .in(Company::getErpId,deptIdList)
+                    ));
+                }
+            }else if(eventType.equals("org_dept_create")||eventType.equals("org_dept_modify")){
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    Company company  = companyMapper.selectOne(new QueryWrapper<Company>().lambda()
+                            .eq(Company::getIsdeleted,Constants.ZERO)
+                            .eq(Company::getErpId,jsonArray.getLong(i))
+                    );
+                    OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse = dingTalk.syncDepartmentInfo(jsonArray.getLong(i));
+                    Company param = new Company();
+                    param.setName(deptGetResponse.getName());
+                    param.setErpId(deptGetResponse.getDeptId().toString());
+                    param.setErpParentId(deptGetResponse.getParentId().toString());
+                    if(Objects.isNull(company)){
+                        param.setSortnum(deptGetResponse.getOrder().intValue());//榛樿鏈�涓婇潰
+                        getAddCompanyModel(param);
+                    }else{
+                        getUpdateCompanyModel(param,company);
+                    }
+                }
+            }
+        }catch (Exception e){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"鏁版嵁鍚屾澶辫触");
+        }
+
+    }
+
+    private void doHkDeleteOrg(List<Integer> delIds,List<String> delHkIds,  Date date) {
+        if(delHkIds.size() == 0){
+            return;
+        }
+        OrgDelRequest request = new OrgDelRequest();
+        request.setIndexCodes( delHkIds.toArray(new String[]{}));
+        BaseResponse<List<OrgUpdateFailureResponse>> result =  HKService.delBatchOrg(request);
+        if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
+            List<String> fIds = new ArrayList<>();
+            if(result.getData()!=null){
+                for(OrgUpdateFailureResponse r : result.getData()){
+                    if(r.getCode().equals("0x00052102")){
+                        //涓嶅瓨鍦ㄧ殑涔熺畻鍒犻櫎鎴愬姛
+                        fIds.add(r.getOrgIndexCode());//鍒犻櫎澶辫触鐨勬暟鎹泦鍚�
+                    }
+                }
+            }
+            //鏍囪鍒犻櫎鎴愬姛鐨勬暟鎹紙娴峰悍瀵规帴鐘舵�佷负宸插悓姝ワ紝锛屽悓姝ュけ璐ョ殑浠嶄负寰呭悓姝ワ紝绛変笅涓�娆$户缁鐞嗭紝鐭ラ亾鍏ㄩ儴鍒犻櫎瀹屾瘯锛�
+            companyMapper.update(null,new UpdateWrapper<Company>().lambda()
+                    .set(Company::getHkStatus,Constants.ONE)
+                    .set(Company::getHkDate,date)
+                    .set(Company::getHkId,null )
+                    .in(Company::getId, delIds)
+                    .notIn(fIds.size()>0,Company::getHkId, fIds));
+            companyMapper.update(null,new UpdateWrapper<Company>().lambda()
+                    .set(Company::getHkStatus,Constants.ZERO)
+                    .set(Company::getHkDate,date)
+                    .in(Company::getId, delIds)
+                    .in(fIds.size()>0,Company::getHkId, fIds));
+        }
+    }
+
+    @Override
+    public String syncDDCompany()  {
+        try {
+            List<OapiV2DepartmentGetResponse.DeptGetResponse> list = dingTalk.syncAllDDDepartmentList();
+            if(list !=null && list.size()>0){
+                List<Company> addList = new ArrayList<>();
+                List<Company> updateList = new ArrayList<>();
+                List<Company> delIds = new ArrayList<>();//淇敼涓轰娇鐢ㄩ拤閽塱d  erpId
+                List<Company>  allList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+                        .eq(Company::getIsdeleted,Constants.ZERO).eq(Company::getType,Constants.ONE));
+                dealCompanyChangeList(list,addList,updateList,delIds,allList);
+                if(delIds.size()>0){
+                    syncDelCompany(delIds);
+                }
+                return "鍚屾鏁版嵁锛氭柊澧炪��"+addList.size()+"銆戞潯锛屾洿鏂般��"+updateList.size()+"銆戞潯锛屽垹闄ゃ��"+delIds.size()+"銆戞潯";
+            }else{
+                throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鍚屾閽夐拤鏁版嵁涓虹┖锛�");
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鍚屾閽夐拤鏁版嵁寮傚父锛�");
+        }
+    }
+    @Override
+    public String syncJdyCompany() {
+        //{
+        //  "dept_no": 1,//鏁板瓧 1 涓烘牴閮ㄩ棬缂栧彿銆�483636217锛氳姕婀栧競鍏徃
+        //  "has_child": true
+        //}
+        DeptApiClient deptApiClient = new DeptApiClient(systemDictDataBiz.queryByCode(Constants.JDY_CONFIG, Constants.JDY_API_KEY).getCode()
+                ,systemDictDataBiz.queryByCode(Constants.JDY_CONFIG, Constants.JDY_API_HOST).getCode());
+        try {
+            int root = 1;
+            try {
+                root = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.JDY_CONFIG, Constants.JDY_COMPANY_ROOT_NO).getCode());
+            }catch (Exception e){
+
+            }
+            Map<String, Object> result =  deptApiClient.deptList(root,true,deptApiClient.getDefaultVersion());
+            if(result!=null && result.get("departments")!=null ){
+                TypeReference<List<DeptEntityModel>> typeReference =     new TypeReference<List<DeptEntityModel>>(){};
+                Object obj = result.get("departments");
+                List<DeptEntityModel> list =  com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(obj), typeReference.getType());
+                list = sortJdyListBYParent(list,root);
+                if(list !=null && list.size()>0){
+                    List<Company> addList = new ArrayList<>();
+                    List<Company> updateList = new ArrayList<>();
+                    List<Company> delIds = new ArrayList<>();//淇敼涓轰娇鐢ㄩ拤閽塱d  erpId
+                    List<Company>  allList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+                            .eq(Company::getIsdeleted,Constants.ZERO).eq(Company::getType,Constants.ONE));
+                    dealCompanyChangeListJdy(list,addList,updateList,delIds,allList);
+                    if(delIds.size()>0){
+                        syncDelCompany(delIds);
+                    }
+                    return "鍚屾鏁版嵁锛氭柊澧炪��"+addList.size()+"銆戞潯锛屾洿鏂般��"+updateList.size()+"銆戞潯锛屽垹闄ゃ��"+delIds.size()+"銆戞潯";
+                }else{
+                    throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鍚屾绠�鍗曚簯鏁版嵁涓虹┖锛�");
+                }
+            }
+        }catch (BusinessException e){
+            throw  e;
+        }catch (Exception e){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鍚屾鏁版嵁寮傚父锛�"+e.getMessage());
+        }
+        return null;
+    }
+
+    private List<DeptEntityModel> sortJdyListBYParent(List<DeptEntityModel> list, int root) {
+        List<DeptEntityModel> all = new ArrayList<>();
+        for(DeptEntityModel t : list){
+            if(Constants.equalsInteger( t.getParent_no(),root)){
+                all.add(t);
+                if(hasChildCompany(list,t.getDept_no())){
+                    all.addAll(sortJdyListBYParent(list,t.getDept_no()));
+                }
+            }
+        }
+        return  all;
+    }
+
+
+    private boolean hasChildCompany(List<DeptEntityModel> list, Integer deptNo) {
+        for(DeptEntityModel t : list){
+            if(Constants.equalsInteger( t.getParent_no(),deptNo)){
+               return true;
+            }
+        }
+        return  false;
+    }
+
+    public static void main(String[] args) {
+        String temp = " [{" +
+                "\"dept_no\": 567064650," +
+                "\"name\": \"瀹¤娲鹃┗鍔瀄"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567064650\"" +
+                "}, {" +
+                "\"dept_no\": 567086523," +
+                "\"name\": \"姹熷寳鍒嗗眬\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567086523\"" +
+                "}, {" +
+                "\"dept_no\": 567354485," +
+                "\"name\": \"绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567354485\"" +
+                "}, {" +
+                "\"dept_no\": 567303494," +
+                "\"name\": \"绾鐩戝療瀹わ紙宸″療棰嗗灏忕粍鍔炲叕瀹わ級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567303494\"" +
+                "}, {" +
+                "\"dept_no\": 566874731," +
+                "\"name\": \"鏃犱负甯傚眬绂婚��浼戝姙\"," +
+                "\"parent_no\": 566426902," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566874731\"" +
+                "}, {" +
+                "\"dept_no\": 566426902," +
+                "\"name\": \"绂婚��浼戜汉鍛樺\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566426902\"" +
+                "}, {" +
+                "\"dept_no\": 566981590," +
+                "\"name\": \"鐗╂祦涓績\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566981590\"" +
+                "}, {" +
+                "\"dept_no\": 566499662," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566499662\"" +
+                "}, {" +
+                "\"dept_no\": 567258434," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567258434\"" +
+                "}, {" +
+                "\"dept_no\": 567458554," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊绉戯紙鍐呴儴涓撳崠绠$悊鐩戠潱绉戙�佺ń鏌ユ敮闃燂級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567458554\"" +
+                "}, {" +
+                "\"dept_no\": 567139640," +
+                "\"name\": \"婀炬矚鍖哄眬绂婚��浼戝姙\"," +
+                "\"parent_no\": 566426902," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567139640\"" +
+                "}, {" +
+                "\"dept_no\": 566379775," +
+                "\"name\": \"淇℃伅涓績\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566379775\"" +
+                "}, {" +
+                "\"dept_no\": 567298538," +
+                "\"name\": \"浼佷笟绠$悊绉慭"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567298538\"" +
+                "}, {" +
+                "\"dept_no\": 567073617," +
+                "\"name\": \"鍔炲叕瀹"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567073617\"" +
+                "}, {" +
+                "\"dept_no\": 566496812," +
+                "\"name\": \"绻佹槍鍖哄眬绂婚��浼戝姙\"," +
+                "\"parent_no\": 566426902," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566496812\"" +
+                "}, {" +
+                "\"dept_no\": 566643894," +
+                "\"name\": \"鍗楅櫟鍘垮眬绂婚��浼戝姙\"," +
+                "\"parent_no\": 566426902," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566643894\"" +
+                "}, {" +
+                "\"dept_no\": 566699927," +
+                "\"name\": \"娉曡绉戯紙瑙勮寖绠$悊鍔炲叕瀹わ級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566699927\"" +
+                "}, {" +
+                "\"dept_no\": 567034633," +
+                "\"name\": \"鍏氬缓缇ゅ洟绉戯紙宸ヤ細鍔炲叕瀹わ級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567034633\"" +
+                "}, {" +
+                "\"dept_no\": 567095650," +
+                "\"name\": \"甯傚眬锛堝叕鍙革級棰嗗\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567095650\"" +
+                "}, {" +
+                "\"dept_no\": 566464722," +
+                "\"name\": \"璐㈠姟绠$悊绉慭"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566464722\"" +
+                "}, {" +
+                "\"dept_no\": 567249497," +
+                "\"name\": \"鑺滄箹甯傚眬鐩村睘鍒嗗眬\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567249497\"" +
+                "}, {" +
+                "\"dept_no\": 567266572," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567266572\"" +
+                "}, {" +
+                "\"dept_no\": 567394584," +
+                "\"name\": \"绂婚��浼戜汉鍛樺\"," +
+                "\"parent_no\": 566426902," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567394584\"" +
+                "}, {" +
+                "\"dept_no\": 566952603," +
+                "\"name\": \"瀹夊叏绠$悊绉慭"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566952603\"" +
+                "}, {" +
+                "\"dept_no\": 567418536," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567418536\"" +
+                "}, {" +
+                "\"dept_no\": 567080624," +
+                "\"name\": \"钀ラ攢涓績\"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567080624\"" +
+                "}, {" +
+                "\"dept_no\": 567395495," +
+                "\"name\": \"浜哄姏璧勬簮绉慭"," +
+                "\"parent_no\": 483636217," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567395495\"" +
+                "}, {" +
+                "\"dept_no\": 566852695," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級鍔炲叕瀹"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566852695\"" +
+                "}, {" +
+                "\"dept_no\": 566597911," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級瑗勫畨鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566597911\"" +
+                "}, {" +
+                "\"dept_no\": 567383562," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567383562\"" +
+                "}, {" +
+                "\"dept_no\": 566596757," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566596757\"" +
+                "}, {" +
+                "\"dept_no\": 567126588," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級鍩庡尯鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567126588\"" +
+                "}, {" +
+                "\"dept_no\": 567423457," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567423457\"" +
+                "}, {" +
+                "\"dept_no\": 567444447," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級楂樻矡鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567444447\"" +
+                "}, {" +
+                "\"dept_no\": 566688696," +
+                "\"name\": \"鏃犱负甯傚眬锛堣惀閿�閮級涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566688696\"" +
+                "}, {" +
+                "\"dept_no\": 567308492," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567308492\"" +
+                "}, {" +
+                "\"dept_no\": 567311569," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 566499662," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567311569\"" +
+                "}, {" +
+                "\"dept_no\": 566586834," +
+                "\"name\": \"鐗╂祦涓績鍌ㄩ厤閮╘"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566586834\"" +
+                "}, {" +
+                "\"dept_no\": 567052635," +
+                "\"name\": \"绋芥煡闃焅"," +
+                "\"parent_no\": 566930600," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567052635\"" +
+                "}, {" +
+                "\"dept_no\": 567250603," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567250603\"" +
+                "}, {" +
+                "\"dept_no\": 566714645," +
+                "\"name\": \"鐗╂祦涓績閫佽揣閮╘"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566714645\"" +
+                "}, {" +
+                "\"dept_no\": 567400554," +
+                "\"name\": \"鐗╂祦涓績缁煎悎閮╘"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567400554\"" +
+                "}, {" +
+                "\"dept_no\": 901575528," +
+                "\"name\": \"鐗╂祦涓績鎶�鏈儴\"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"901575528\"" +
+                "}, {" +
+                "\"dept_no\": 567406402," +
+                "\"name\": \"鐗╂祦涓績瀹変繚閮╘"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567406402\"" +
+                "}, {" +
+                "\"dept_no\": 667523393," +
+                "\"name\": \"鐗╂祦涓績棰嗗\"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"667523393\"" +
+                "}, {" +
+                "\"dept_no\": 567052636," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567052636\"" +
+                "}, {" +
+                "\"dept_no\": 567351557," +
+                "\"name\": \"鐗╂祦涓績涓浆绔橽"," +
+                "\"parent_no\": 566981590," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567351557\"" +
+                "}, {" +
+                "\"dept_no\": 567052634," +
+                "\"name\": \"姹熷寳鍒嗗眬鍔炲叕瀹"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567052634\"" +
+                "}, {" +
+                "\"dept_no\": 567359469," +
+                "\"name\": \"鍝佺墝閮╘"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567359469\"" +
+                "}, {" +
+                "\"dept_no\": 821923828," +
+                "\"name\": \"缁煎悎閮╘"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"821923828\"" +
+                "}, {" +
+                "\"dept_no\": 567151607," +
+                "\"name\": \"姹熷寳鍒嗗眬涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567151607\"" +
+                "}, {" +
+                "\"dept_no\": 567297546," +
+                "\"name\": \"甯傚満閮╘"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567297546\"" +
+                "}, {" +
+                "\"dept_no\": 566867618," +
+                "\"name\": \"缁堢閮╘"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566867618\"" +
+                "}, {" +
+                "\"dept_no\": 567314532," +
+                "\"name\": \"璁㈠崟閮╘"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567314532\"" +
+                "}, {" +
+                "\"dept_no\": 566848639," +
+                "\"name\": \"姹熷寳鍒嗗眬鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566848639\"" +
+                "}, {" +
+                "\"dept_no\": 567272560," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級瀵勯�掔粍\"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567272560\"" +
+                "}, {" +
+                "\"dept_no\": 566564826," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566564826\"" +
+                "}, {" +
+                "\"dept_no\": 567471441," +
+                "\"name\": \"姹熷寳鍒嗗眬瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567471441\"" +
+                "}, {" +
+                "\"dept_no\": 711701716," +
+                "\"name\": \"姹熷寳鍒嗗眬鍩庡寳鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯锛塡"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"711701716\"" +
+                "}, {" +
+                "\"dept_no\": 567103611," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567103611\"" +
+                "}, {" +
+                "\"dept_no\": 664801291," +
+                "\"name\": \"姹熷寳鍒嗗眬浜屽潩鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯锛塡"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"664801291\"" +
+                "}, {" +
+                "\"dept_no\": 566323801," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級鍔炲叕瀹"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566323801\"" +
+                "}, {" +
+                "\"dept_no\": 567343637," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級鍩庡尯鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567343637\"" +
+                "}, {" +
+                "\"dept_no\": 567087584," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567087584\"" +
+                "}, {" +
+                "\"dept_no\": 567058556," +
+                "\"name\": \"瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567058556\"" +
+                "}, {" +
+                "\"dept_no\": 566930600," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566930600\"" +
+                "}, {" +
+                "\"dept_no\": 566592977," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567086523," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566592977\"" +
+                "}, {" +
+                "\"dept_no\": 567283502," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567283502\"" +
+                "}, {" +
+                "\"dept_no\": 567571030," +
+                "\"name\": \"鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567571030\"" +
+                "}, {" +
+                "\"dept_no\": 566605742," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566605742\"" +
+                "}, {" +
+                "\"dept_no\": 567044634," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567044634\"" +
+                "}, {" +
+                "\"dept_no\": 566835635," +
+                "\"name\": \"鍔炲叕瀹"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566835635\"" +
+                "}, {" +
+                "\"dept_no\": 566844724," +
+                "\"name\": \"鍩庡崡鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 567249497," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566844724\"" +
+                "}, {" +
+                "\"dept_no\": 566633782," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566633782\"" +
+                "}, {" +
+                "\"dept_no\": 566884644," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566884644\"" +
+                "}, {" +
+                "\"dept_no\": 566656760," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566656760\"" +
+                "}, {" +
+                "\"dept_no\": 567127606," +
+                "\"name\": \"婀炬矚鍖哄眬锛堣惀閿�閮級涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 567258434," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567127606\"" +
+                "}, {" +
+                "\"dept_no\": 566965621," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566965621\"" +
+                "}, {" +
+                "\"dept_no\": 566889723," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級鍩庡尯鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566889723\"" +
+                "}, {" +
+                "\"dept_no\": 573565486," +
+                "\"name\": \"鍗楅櫟鍘垮眬锛堣惀閿�閮級鍔炲叕瀹"," +
+                "\"parent_no\": 567266572," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"573565486\"" +
+                "}, {" +
+                "\"dept_no\": 566880674," +
+                "\"name\": \"鍗楅櫟鍘垮眬绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 567354485," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566880674\"" +
+                "}, {" +
+                "\"dept_no\": 567176623," +
+                "\"name\": \"绻佹槍鍘垮眬绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 567354485," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567176623\"" +
+                "}, {" +
+                "\"dept_no\": 567314533," +
+                "\"name\": \"鑺滄箹甯傚眬绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 567354485," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567314533\"" +
+                "}, {" +
+                "\"dept_no\": 567340287," +
+                "\"name\": \"鏃犱负鍘垮眬绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 567354485," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567340287\"" +
+                "}, {" +
+                "\"dept_no\": 566636715," +
+                "\"name\": \"鑺滄箹鍘垮眬绂诲矖閫�鍏讳汉鍛榎"," +
+                "\"parent_no\": 567354485," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566636715\"" +
+                "}, {" +
+                "\"dept_no\": 567368506," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級鐩戝療娉曡鍔瀄"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567368506\"" +
+                "}, {" +
+                "\"dept_no\": 567354486," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級鍔炲叕瀹"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567354486\"" +
+                "}, {" +
+                "\"dept_no\": 566960827," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級涓撳崠鐩戠潱绠$悊鍔炲叕瀹わ紙鍐呴儴涓撳崠绠$悊鐩戠潱鍔炲叕瀹ゃ�佺ń鏌ュぇ闃燂級\"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566960827\"" +
+                "}, {" +
+                "\"dept_no\": 566649730," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級鍩庡尯鐑熻崏涓撳崠绠$悊鎵�锛堟湇鍔$珯銆佺ń鏌ヤ腑闃燂級\"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566649730\"" +
+                "}, {" +
+                "\"dept_no\": 566455834," +
+                "\"name\": \"绻佹槍鍖哄眬锛堣惀閿�閮級瀹㈡埛鏈嶅姟閮╘"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566455834\"" +
+                "}, {" +
+                "\"dept_no\": 566975648," +
+                "\"name\": \"棰嗗鐝瓙\"," +
+                "\"parent_no\": 567418536," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"566975648\"" +
+                "}, {" +
+                "\"dept_no\": 822153494," +
+                "\"name\": \"鍖哄煙鍒嗕腑蹇僜"," +
+                "\"parent_no\": 567458554," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"822153494\"" +
+                "}, {" +
+                "\"dept_no\": 567328559," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊绉戯紙鍐呴儴涓撳崠绠$悊鐩戠潱绉戙�佺ń鏌ユ敮闃燂級琛屽姩缁刓"," +
+                "\"parent_no\": 567458554," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567328559\"" +
+                "}, {" +
+                "\"dept_no\": 567476616," +
+                "\"name\": \"涓撳崠鐩戠潱绠$悊绉戯紙鍐呴儴涓撳崠绠$悊鐩戠潱绉戙�佺ń鏌ユ敮闃燂級鏁版嵁鍒嗘瀽缁刓"," +
+                "\"parent_no\": 567458554," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"567476616\"" +
+                "}, {" +
+                "\"dept_no\": 821950791," +
+                "\"name\": \"鐜板満妫�鏌ョ粍\"," +
+                "\"parent_no\": 822153494," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"821950791\"" +
+                "}, {" +
+                "\"dept_no\": 922652428," +
+                "\"name\": \"缁煎悎绠$悊缁刓"," +
+                "\"parent_no\": 822153494," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"922652428\"" +
+                "}, {" +
+                "\"dept_no\": 822188538," +
+                "\"name\": \"鏁版嵁鍒嗘瀽缁刓"," +
+                "\"parent_no\": 822153494," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"822188538\"" +
+                "}, {" +
+                "\"dept_no\": 981649568," +
+                "\"name\": \"閮ㄩ棬棰嗗\"," +
+                "\"parent_no\": 567080624," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"981649568\"" +
+                "}, {" +
+                "\"dept_no\": 982346282," +
+                "\"name\": \"閮ㄩ棬棰嗗\"," +
+                "\"parent_no\": 567458554," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"982346282\"" +
+                "}, {" +
+                "\"dept_no\": 998004621," +
+                "\"name\": \"閮ㄩ棬棰嗗\"," +
+                "\"parent_no\": 822153494," +
+                "\"type\": 0," +
+                "\"status\": 1," +
+                "\"integrate_id\": \"998004621\"" +
+                "}]" ;
+       TypeReference typeReference =
+                new TypeReference<     List<DeptEntityModel> >() {
+                };
+         List<DeptEntityModel> list = com.alibaba.fastjson.JSONObject.parseObject(temp, typeReference.getType());
+        CompanyServiceImpl obj = new CompanyServiceImpl();
+        list = obj.sortJdyListBYParent(list,483636217);
+        list.size();
+
+    }
+
+    private void dealCompanyChangeListJdy(List<DeptEntityModel> list, List<Company> addList, List<Company> updateList,
+                                          List<Company> delIds, List<Company> allList) {
+        Date date = new Date();
+        for(DeptEntityModel respone : list){
+            Company param = new Company();
+            param.setName(respone.getName());
+            param.setErpId(respone.getDept_no().toString());
+            param.setErpParentId(respone.getParent_no() !=null?respone.getParent_no() .toString():null);
+            param.setSortnum(respone.getSeq()!=null?respone.getSeq().intValue():null);//榛樿鏈�涓婇潰
+            //鏍规嵁erpid鏌ヨ浼佷笟淇℃伅锛屽垽鏂槸鏂板杩樻槸鏇存柊
+            Company company = findCompanyByERPId(allList,respone.getDept_no().toString());
+            if(company == null){
+                //灏佽鏂板缁勭粐瀵硅薄鏁版嵁
+                addList.add(getAddCompanyModel(param));
+            }else{
+                updateList.add(getUpdateCompanyModel(param,company));
+            }
+        }
+        if(allList!=null && allList.size()>0){
+            for(Company  c : allList){
+                if(!isCompanyDeletedJdy(c,list)){
+                    delIds.add(c);
+                }
+            }
+        }
+    }
+    private void dealCompanyChangeList(List<OapiV2DepartmentGetResponse.DeptGetResponse> list, List<Company> addList,
+                                       List<Company> updateList, List<Company> delIds, List<Company> allList) {
+        Date date = new Date();
+        for(OapiV2DepartmentGetResponse.DeptGetResponse respone : list){
+            Company param = new Company();
+            param.setName(respone.getName());
+            param.setErpId(respone.getDeptId().toString());
+            param.setErpParentId(respone.getParentId().toString());
+            param.setSortnum(respone.getOrder().intValue());//榛樿鏈�涓婇潰
+            //鏍规嵁erpid鏌ヨ浼佷笟淇℃伅锛屽垽鏂槸鏂板杩樻槸鏇存柊
+            Company company = findCompanyByERPId(allList,respone.getDeptId().toString());
+            if(company == null){
+                //濡傛灉鏄柊澧�
+                //灏佽鏂板缁勭粐瀵硅薄鏁版嵁
+                addList.add(getAddCompanyModel(param));
+            }else{
+                updateList.add(getUpdateCompanyModel(param,company));
+            }
+        }
+        if(allList!=null && allList.size()>0){
+            for(Company  c : allList){
+                if(!isCompanyDeleted(c,list)){
+                    delIds.add(c);
+                }
+            }
+        }
+    }
+
+    /**
+     * 鏁寸悊閽夐拤鍚屾 鏂板缁勭粐瀵硅薄
+     * @return
+     */
+    private Company getAddCompanyModel(Company param ) {
+        return  syncDDAddCompanyModel(param);
+    }
+
+    /**
+     * 鏁寸悊閽夐拤鍚屾 鏂板 闇�瑕佷慨鏀圭殑缁勭粐瀵硅薄
+     * @param param
+     * @param company
+     * @return
+     */
+    private Company getUpdateCompanyModel(Company param, Company company) {
+        return syncDDEditCompanyModel(param,company);
+    }
+
+    /**
+     * 鏍规嵁ERPID  鍒ゆ柇鏁版嵁鏄惁宸插湪闆嗗悎閲屽瓨鍦�
+     * @param allList
+     * @param id
+     * @return
+     */
+    private Company findCompanyByERPId(List<Company> allList, String id) {
+        if(allList!=null){
+            for(Company com :allList){
+                if(StringUtils.equals(com.getErpId(),id)){
+                    return com;
+                }
+            }
+        }
+        return  null;
+    }
+
+    private boolean isCompanyDeleted(Company c, List<OapiV2DepartmentGetResponse.DeptGetResponse> list) {
+        for(OapiV2DepartmentGetResponse.DeptGetResponse m : list){
+            if(StringUtils.equals(c.getErpId(),m.getDeptId().toString())){
+                return  true;
+            }
+        }
+        return false;
+    }
+    private boolean isCompanyDeletedJdy(Company c, List<DeptEntityModel> list) {
+        for(DeptEntityModel  m : list){
+            if(StringUtils.equals(c.getErpId(),m.getDept_no().toString())){
+                return  true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * 鏁寸悊 閽夐拤鍚屾鐨� 缁勭粐淇℃伅
+     * @param param
+     * @return
+     */
+    public Company syncDDAddCompanyModel(Company param ){
+        Company  company = new Company();
+        company.setCreateDate(new Date());
+        company.setIsdeleted(Constants.ZERO);
+        company.setStatus(Constants.ZERO);
+
+        company.setName(param.getName());
+        company.setErpId(param.getErpId() );
+        company.setErpParentId(param.getErpParentId());
+        company.setSortnum(param.getSortnum());//榛樿鏈�涓婇潰
+
+        company.setType(Constants.ONE);
+        String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
+        String jdyRootId = systemDictDataBiz.queryByCode(Constants.JDY_CONFIG,Constants.JDY_COMPANY_ROOT_NO).getCode();
+        Company root =getRootCompanyModel(rootOrgId,jdyRootId);
+        company.setHkParentId(rootOrgId);
+        company.setCompanyPath(company.getId()+"/");//鍚嶇О璺緞
+        company.setCompanyNamePath(company.getName());//鍚嶇О璺緞
+        String idPath = "";
+        if(StringUtils.isNotBlank(param.getErpParentId())){
+            Company parent = companyMapper.selectOne(new QueryWrapper<Company>().lambda().eq(Company::getErpId,param.getErpParentId())
+                    .eq(Company::getIsdeleted,Constants.ZERO).last(" limit 1 "));
+            if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
+                //鐖剁骇涓嶅瓨鍦ㄧ殑锛岀洿鎺ユ寕鍦ㄦ牴缁勭粐涓�
+                parent = root;
+            }
+            if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
+                if(!Constants.equalsInteger(company.getType(),parent.getType())){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
+                }
+            }else if(Objects.isNull(parent.getType())){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
+            }
+            idPath = parent.getCompanyPath();
+            company.setHkParentId(parent.getHkId());
+            company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
+            company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
+            company.setParentId(parent.getId());
+        }
+        company.setHkCompanyPath(company.getCompanyNamePath());
+        company.setCreateDate(new Date());
+        company.setIsdeleted(Constants.ZERO);
+        company.setHkStatus(Constants.ZERO);
+        company.setStatus(Constants.ZERO);
+        company.setHkDate(company.getCreateDate());
+        company.setEditDate(company.getCreateDate());
+        company.setEditor(company.getCreator());
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
+        companyMapper.insert(company);
+
+        company.setHkId(UUID.randomUUID().toString().replace("-",""));
+        Company com = new Company();
+        com.setId(company.getId());
+        com.setCompanyPath(idPath+company.getId()+"/");
+        companyMapper.updateById(com);
+        //涓嬪彂娴峰悍瀹夐槻骞冲彴
+    /*    Boolean issueStatus = addHkOrg(company);
+        Company com = new Company();
+        com.setId(company.getId());
+        com.setHkId(issueStatus?company.getHkId():null);
+        com.setHkStatus(issueStatus?Constants.ONE:Constants.TWO);
+        companyMapper.updateById(com);*/
+        return company;
+    }
+
+    /**
+     * 鍐呯疆鏍圭粍缁�
+     * @param rootOrgId
+     * @return
+     */
+    private Company getRootCompanyModel(String rootOrgId,String erpId) {
+        Company root = companyMapper.selectOne(new QueryWrapper<Company>().lambda()
+                .eq(Company::getIsdeleted,Constants.ZERO)
+                .isNull(Company::getParentId)
+                .last(" limit 1 "));
+        if(root== null){
+            String name =systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_NAME).getCode();
+            name =StringUtils.defaultString(name,"鏍圭粍缁�");
+            root = new Company();
+            root.setCreateDate(new Date());
+            root.setEditDate(new Date());
+            root.setName(name);
+            root.setType(-1);
+            root.setHkId(rootOrgId);
+            root.setHkStatus(Constants.ONE);
+            root.setIsdeleted(Constants.ZERO);
+            root.setStatus(Constants.ZERO);
+            root.setErpId(erpId);
+            root.setHkCompanyPath(rootOrgId+"/");
+            root.setCompanyNamePath(root.getName());
+            root.setHkDate(new Date());
+            root.setRemark("榛樿鏍圭粍缁�");
+            companyMapper.insert(root);
+            root.setCompanyPath(root.getId()+"/");
+            companyMapper.updateById(root);
+        }
+        return root;
+
+    }
+
+
+    public Company syncDDEditCompanyModel(Company param,Company company){
+        company.setErpParentId(param.getErpParentId().toString());
+        String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
+        String jdyRootId = systemDictDataBiz.queryByCode(Constants.JDY_CONFIG,Constants.JDY_COMPANY_ROOT_NO).getCode();
+        Company root =getRootCompanyModel(rootOrgId,jdyRootId);
+        String idPath = "";
+        if(StringUtils.isNotBlank(company.getErpParentId())){
+            Company parent = companyMapper.selectOne(new QueryWrapper<Company>().lambda()
+                    .eq(Company::getErpId,company.getErpParentId())
+                    .eq(Company::getType,Constants.ONE)
+                    .eq(Company::getIsdeleted,Constants.ZERO)
+                    .last("limit 1 "));
+            if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
+              parent =root;
+            }
+           /*if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
+                if(!Constants.equalsInteger(company.getType(),parent.getType())){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
+                }
+            }else if(Objects.isNull(parent.getType())){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝缁勭粐淇℃伅閿欒");
+            }*/
+            idPath = parent.getCompanyPath();
+            company.setHkParentId(parent.getHkId());
+            company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
+            company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
+            company.setParentId(parent.getId());
+        }
+
+        company.setName(param.getName());
+        company.setErpId(param.getErpId());
+        company.setSortnum(param.getSortnum());//榛樿鏈�涓婇潰
+        company.setEditDate(new Date());
+//        company.setHkCompanyPath(company.getCompanyNamePath());
+        company.setHkStatus(Constants.ZERO);
+        company.setStatus(Constants.ZERO);
+        company.setHkDate(company.getCreateDate());
+        company.setEditDate(company.getCreateDate());
+        company.setEditor(company.getCreator());
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
+        companyMapper.updateById(company);
+        //涓嬪彂娴峰悍瀹夐槻骞冲彴
+     /*   Boolean issueStatus = editHkOrg(company);
+        Company com = new Company();
+        com.setId(company.getId());
+        com.setHkId(issueStatus?company.getHkId():null);
+        com.setHkStatus(issueStatus?Constants.ONE:Constants.TWO);
+        com.setCompanyPath(idPath+company.getId()+"/");
+        companyMapper.updateById(com);*/
+        return company;
+    }
+
+
+
+    public void syncDelCompany(List<Company> companyList ){
+/*        List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>()
+                .lambda()
+                .eq(Company::getIsdeleted,Constants.ZERO)
+                .in(Company::getId,deptIdList)
+        );*/
+        if(CollectionUtils.isNotEmpty(companyList)){
+            List<Integer> delIds = companyList.stream().map(i->i.getId()).collect(Collectors.toList());
+            List<String> delHKIds = companyList.stream().filter(i->StringUtils.isNotBlank(i.getHkId())).map(i->i.getHkId()).collect(Collectors.toList());
+            //鏍囪涓氬姟鍒犻櫎
+            companyMapper.update(new UpdateWrapper<Company>().lambda()
+                    .set(Company::getIsdeleted,Constants.ONE)
+                    .set(Company::getEditDate,new Date())
+                    .in(Company::getId,delIds)
+            );
+            //娴峰悍鍒犻櫎鐨勬暟鎹紝杩涜鍒犻櫎
+            doHkDeleteOrg(delIds,delHKIds,new Date());
+        }
     }
 
 }

--
Gitblit v1.9.3