|  |  | 
 |  |  | import org.apache.commons.collections.CollectionUtils; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.checkerframework.checker.units.qual.C; | 
 |  |  | import org.springframework.beans.BeanUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             idPath = parent.getCompanyPath(); | 
 |  |  |             company.setHkParentId(parent.getHkId()); | 
 |  |  |             company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/"); | 
 |  |  |             company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName()); | 
 |  |  |         } | 
 |  |  | 
 |  |  |         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){ | 
 |  |  |                 //处理新增成功的数据,修改海康同步状态 | 
 |  |  | 
 |  |  |     } | 
 |  |  |     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)){ | 
 |  |  | 
 |  |  |                 .eq(Member::getIsdeleted,Constants.ZERO)) >0){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该部门下存在人员信息,不能进行删除操作!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Company company = new Company(); | 
 |  |  |         company.setId(id); | 
 |  |  |         company.setEditDate(new Date()); | 
 |  |  | 
 |  |  |         company.setHkDate(company.getHkDate()); | 
 |  |  |         companyMapper.updateById(company); | 
 |  |  |         //下发海康安防平台 | 
 |  |  |         if(StringUtils.isBlank(model.getHkId()) && Constants.equalsInteger(Constants.ONE,model.getHkStatus()) && !delHkOrg(model)){ | 
 |  |  |         if(StringUtils.isNotBlank(model.getHkId()) && Constants.equalsInteger(Constants.ONE,model.getHkStatus()) && !delHkOrg(model)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织删除下发失败,请确认该组织无下级组织或组织人员信息~"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | 
 |  |  |              if(companyJoinMapper.selectCount(new QueryWrapper<Company>().lambda() | 
 |  |  |                      .eq(Company::getIsdeleted,Constants.ZERO ) | 
 |  |  |                      .eq(Company::getType,Constants.ONE ) | 
 |  |  |                      .likeRight(Company::getCompanyPath,company.getCompanyPath())) >0){ | 
 |  |  |                      .ne(Company::getId,model.getId()) | 
 |  |  |                      .likeRight(Company::getCompanyPath,model.getCompanyPath())) >0){ | 
 |  |  |                  throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,下级部门存在内部组织,该部门不支持切换为相关方组织!~"); | 
 |  |  |              } | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |     @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.orderByDesc(Company::getCreateDate); | 
 |  |  |         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 | 
 |  |  | 
 |  |  |         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) { | 
 |  |  | 
 |  |  |         List<Company> companies = companyMapper.selectList(wrapper); | 
 |  |  |         return getCompanyTree( companies, null); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId){ | 
 |  |  |         if (CollectionUtils.isEmpty(companies)){ | 
 |  |  | 
 |  |  |         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); | 
 |  |  |         }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 |