From 1c20c8231980a8d4b91688ff8641a06d3b2f68ab Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 14 十月 2025 16:34:22 +0800
Subject: [PATCH] 改bug

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java |  274 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 227 insertions(+), 47 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 e94f81f..b2edb5a 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
@@ -17,20 +17,21 @@
 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.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.CompanyMapper;
-import com.doumee.dao.business.join.CompanyJoinMapper;
-import com.doumee.dao.business.model.Category;
+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;
 import com.doumee.dao.business.model.Member;
-import com.doumee.service.business.CompanyService;
 import com.doumee.dao.business.vo.CompanyTree;
+import com.doumee.dao.system.model.SystemUser;
+import com.doumee.service.business.CompanyService;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -54,6 +55,8 @@
     @Autowired
     private CompanyMapper companyMapper;
     @Autowired
+    private MemberMapper memberMapper;
+    @Autowired
     private DataSyncConfig dataSyncConfig;
     @Autowired
     private SystemDictDataBiz systemDictDataBiz;
@@ -67,9 +70,11 @@
         if(StringUtils.isBlank(company.getName())){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
+        if(company.getType()==null || !(company.getType() ==0 || company.getType() ==1)){
+            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝缁勭粐绫诲瀷涓嶆纭紝璇锋寜瑕佹眰濉啓~");
+        }
         //鏌ヨ鍚嶇О涓嶈兘閲嶅
         if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
-//                .eq(Company::getType,Constants.ONE)
                 .eq(Company::getName,company.getName())
                 .eq(Company::getIsdeleted,Constants.ZERO)) >0){
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝缁勭粐鍚嶇О涓嶈兘閲嶅~");
@@ -79,7 +84,10 @@
             user = company.getLoginUserInfo();
         }
         String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
+        company.setCompanyPath(company.getId()+"/");//鍚嶇О璺緞
+        company.setCompanyNamePath(company.getName());//鍚嶇О璺緞
         company.setHkParentId(rootOrgId);
+        String idPath = "";
         if(company.getParentId() !=null){
             Company parent = findById(company.getParentId());
             if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
@@ -88,30 +96,53 @@
             if(StringUtils.isBlank(parent.getHkId())){
                 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()+"/");
+            company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
         }
+        company.setHkCompanyPath(company.getCompanyNamePath());
         company.setCreateDate(new Date());
         company.setCreator(user.getId());
         company.setIsdeleted(Constants.ZERO);
         company.setHkStatus(Constants.ONE);
         company.setStatus(Constants.ZERO);
-        company.setHkDate(company.getHkDate());
+        company.setSortnum(0);//榛樿鏈�涓婇潰
+        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);
         //涓嬪彂娴峰悍瀹夐槻骞冲彴
         if(!addHkOrg(company)){
             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
         }
+        Company com = new Company();
+        com.setId(company.getId());
+        com.setCompanyPath(idPath+company.getId()+"/");
+        companyMapper.updateById(com);
         return company.getId();
     }
 
     private boolean addHkOrg(Company company) {
         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){
                 //澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
@@ -133,6 +164,7 @@
     }
     private boolean delHkOrg(Company company) {
         OrgDelRequest request =new OrgDelRequest();
+
         request.setIndexCodes(new String[]{company.getHkId()});
         BaseResponse<List<OrgUpdateFailureResponse>> result =  HKService.delBatchOrg(request);
         if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
@@ -161,6 +193,7 @@
         return  model;
     }
     @Override
+    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
     public Integer createLaborServices(Company company) {
         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         if(loginUserInfo ==null){
@@ -183,23 +216,31 @@
         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();
     }
 
     @Override
+    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
     public void deleteById(Integer id,    LoginUserInfo user ) {
         if(id== null ){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
-
         Company model = findById(id);
         if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅涓嶅瓨鍦▇");
         }
-        if(StringUtils.isBlank(model.getHkId())){
-            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛,鏆備笉鏀寔淇敼锛岃灏濊瘯鍒犻櫎鍚庨噸鏂版坊鍔爚");
+        if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
+                .eq(Company::getParentId,model.getId())
+                .eq(Company::getIsdeleted,Constants.ZERO)) >0){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝璇ラ儴闂ㄥ瓨鍦ㄤ笅绾ч儴闂紝涓嶈兘杩涜鍒犻櫎鎿嶄綔锛�");
+        }
+        if(memberMapper.selectCount(new QueryWrapper<Member>().lambda()
+                .eq(Member::getCompanyId,model.getId())
+                .eq(Member::getIsdeleted,Constants.ZERO)) >0){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝璇ラ儴闂ㄤ笅瀛樺湪浜哄憳淇℃伅锛屼笉鑳借繘琛屽垹闄ゆ搷浣滐紒");
         }
 
         Company company = new Company();
@@ -211,7 +252,7 @@
         company.setHkDate(company.getHkDate());
         companyMapper.updateById(company);
         //涓嬪彂娴峰悍瀹夐槻骞冲彴
-        if(!delHkOrg(model)){
+        if(StringUtils.isNotBlank(model.getHkId()) && Constants.equalsInteger(Constants.ONE,model.getHkStatus()) && !delHkOrg(model)){
             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍒犻櫎涓嬪彂澶辫触锛岃纭璇ョ粍缁囨棤涓嬬骇缁勭粐鎴栫粍缁囦汉鍛樹俊鎭瘇");
         }
     }
@@ -239,9 +280,11 @@
         if(company.getId() == null|| StringUtils.isBlank(company.getName())){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
+        if(company.getType()!=null && !(company.getType() ==0 || company.getType() ==1)){
+            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝缁勭粐绫诲瀷涓嶆纭紝璇锋寜瑕佹眰濉啓~");
+        }
         //鏌ヨ鍚嶇О涓嶈兘閲嶅
         if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
-//                .eq(Company::getType,Constants.ONE)
                 .eq(Company::getName,company.getName())
                 .ne(Company::getId,company.getId())
                 .eq(Company::getIsdeleted,Constants.ZERO)) >0){
@@ -255,22 +298,42 @@
         if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅涓嶅瓨鍦▇");
         }
-        if(StringUtils.isBlank(model.getHkId())){
-            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(model.getHkId());
+        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+"')")
+                .likeRight(Company::getCompanyPath,model.getCompanyPath()));
         //涓嬪彂娴峰悍瀹夐槻骞冲彴
-        if(StringUtils.isNotBlank(company.getHkId())
-                && Constants.equalsObject(Constants.ONE,model.getHkId())
-                && !editHkOrg(company)){
-            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
+        if(StringUtils.isNotBlank(model.getHkId())){
+             if(!editHkOrg(company)){
+                 throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
+             }
+        }else{//濡傛灉娌℃湁涓嬪彂杩囷紝鐩存帴鏂板缓瀹夐槻骞冲彴缁勭粐
+            if(!addHkOrg(company)){
+                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍚屾涓嬪彂澶辫触锛岃绋嶅悗閲嶈瘯");
+            }
         }
-
     }
 
     @Override
@@ -303,8 +366,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
@@ -406,21 +575,17 @@
             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(Category.class,Category::getId,Company::getCategoryId);
+        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")
-                /*.select("c.name as parentName");*/
-                  .selectAs(Category::getName,Company::getCategoryName);
-                   /*   .selectAs(Member::getName,Company::getHeadName)
-                    .selectAs(Member::getPhone,Company::getHeadPhone)
-                    .select("count(t1.id) as countNum");*/
-//        queryWrapper.eq(Company::getType,Constants.ZERO);
+                .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.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);
     }
@@ -429,7 +594,7 @@
     public void updateStatusById(Company company) {
         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         if(loginUserInfo==null){
-            loginUserInfo = company.getLoginUserInfo()
+            loginUserInfo = company.getLoginUserInfo();
         }
         company.setEditDate(new Date());
         company.setEditor(loginUserInfo.getId());
@@ -437,13 +602,11 @@
         companyMapper.updateById(company);
     }
 
-
     @Override
     public long count(Company company) {
         QueryWrapper<Company> wrapper = new QueryWrapper<>(company);
         return companyMapper.selectCount(wrapper);
     }
-
 
     @Override
     public List<CompanyDTO> findCompanyTreePage(Integer type) {
@@ -451,11 +614,11 @@
         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);
     }
-
 
     private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId){
         if (CollectionUtils.isEmpty(companies)){
@@ -466,7 +629,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());
         }
@@ -499,12 +663,12 @@
         QueryWrapper<Company> wrapper = new QueryWrapper<>();
         wrapper.lambda()
                 .eq(Company::getIsdeleted,Constants.ZERO)
-                .eq(Company::getType,Constants.ZERO)
                 .eq(Company::getName,company.getName());
         List<Company> companies = companyMapper.selectList(wrapper);
         if (CollectionUtils.isEmpty(companies)){
             return;
         }
+        company.setPinyin(Constants.getChinesePingyin(company.getName()));
         //鏂板鐨勬儏鍐靛瓨鍦ㄨ褰�
         if (Objects.isNull(company.getId())){
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�");
@@ -521,11 +685,26 @@
     public List<Company> companyTree(Integer type) {
         MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper.selectAll(Company.class);
+        queryWrapper.selectAs(SystemUser::getRealname,Company::getEditorName);
         queryWrapper.selectAs(Member::getName,Company::getHeadName);
         queryWrapper.selectAs(Member::getPhone,Company::getHeadPhone);
+        queryWrapper.select("t1.name",Company::getParentName);
+        queryWrapper.select("t1.company_path",Company::getParentCompanyPath);
+        queryWrapper.select("t1.type",Company::getParentType);
+        queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
         queryWrapper.leftJoin(Member.class,Member::getId,Company::getHeadId);
+        queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Company::getEditor);
         queryWrapper.eq(Company::getIsdeleted,Constants.ZERO);
-        queryWrapper.eq(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
         CompanyTree treeBuild = new CompanyTree(companyList, dataSyncConfig.getOrgUserDataOrigin());
@@ -567,7 +746,8 @@
             if (currentMenuIndex - 1 < 0) {
                 return;
             }
-            Company preMenu = companyPool.remove(currentMenuIndex - 1);
+            Company preMenu = companyPool.get(currentMenuIndex - 1);
+            companyPool.remove(currentMenuIndex - 1);
             companyPool.add(currentMenuIndex, preMenu);
         }
         // 涓嬬Щ

--
Gitblit v1.9.3