From 30a14783481d100a6503a56c902b47182e542c93 Mon Sep 17 00:00:00 2001 From: jiaosong <jiaosong6760@dingtalk.com> Date: 星期五, 08 十二月 2023 15:42:09 +0800 Subject: [PATCH] #组织树 和企业下的人员信息 人员卡信息 --- server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 55 insertions(+), 4 deletions(-) diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java index 3161c88..484823e 100644 --- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java +++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java @@ -1,5 +1,7 @@ package com.doumee.service.business.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.doumee.core.annotation.excel.ExcelColumn; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; @@ -7,6 +9,7 @@ import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; import com.doumee.core.utils.Utils; +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; @@ -18,12 +21,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import io.swagger.annotations.ApiModelProperty; import org.apache.commons.collections.CollectionUtils; import org.apache.shiro.SecurityUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * 浼佷笟淇℃伅琛⊿ervice瀹炵幇 @@ -50,7 +59,6 @@ LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); checkUnique(company); - Company insert = new Company(); insert.setCreator(loginUserInfo.getId()); insert.setCreateDate(new Date()); @@ -233,6 +241,7 @@ .leftJoin(SystemUser.class,SystemUser::getId,Company::getCreator); queryWrapper.selectAll(Company.class) .selectAs(Category::getName,Company::getCategoryName) + .select("count(t1.id) as countNum") .selectAs(SystemUser::getRealname,Company::getCreatorName); IPage<Company> companyIPage = companyJoinMapper.selectJoinPage(page, Company.class, queryWrapper); return PageData.from(companyIPage); @@ -243,6 +252,41 @@ QueryWrapper<Company> wrapper = new QueryWrapper<>(company); return companyMapper.selectCount(wrapper); } + + + @Override + public List<CompanyDTO> findCompanyTreePage(Integer type) { + + LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>(); + + wrapper.eq(Company::getIsdeleted,Constants.ZERO) + .eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type); + List<Company> companies = companyMapper.selectList(wrapper); + return getCompanyTree( companies, null); + } + + + private List<CompanyDTO> getCompanyTree(List<Company> companies, Integer parentId){ + if (CollectionUtils.isEmpty(companies)){ + return null; + } + List<Company> collect = companies.stream() + .filter(s -> Constants.equalsInteger(s.getParentId(), parentId)) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(companies)){ + return null; + } + List<CompanyDTO> companyDTOList = new ArrayList<>(); + for (int i = 0; i < collect.size(); i++) { + Company company = collect.get(i); + CompanyDTO companyDTO = new CompanyDTO(); + BeanUtils.copyProperties(company,companyDTO); + companyDTO.setCompanyDTOList(getCompanyTree(companies, company.getId())); + companyDTOList.add(companyDTO); + } + return companyDTOList; + } + /** * 鍔冲姟鍏徃鍞竴鎬ф牎楠� @@ -255,9 +299,16 @@ .eq(Company::getType,Constants.ZERO) .eq(Company::getName,company.getName()); List<Company> companies = companyMapper.selectList(wrapper); - - if (CollectionUtils.isNotEmpty(companies)){ - throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"浼佷笟淇℃伅宸插瓨鍦�"); + if (CollectionUtils.isEmpty(companies)){ + return; + } + //鏂板鐨勬儏鍐靛瓨鍦ㄨ褰� + if (Objects.isNull(company.getId())){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�"); + } + //淇敼鐨勬儏鍐靛瓨鍦ㄨ褰� 鍖归厤涓嶅埌 own + if (!companies.stream().map(s -> s.getId()).anyMatch(s -> s.equals(company.getId()))){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�"); } } } -- Gitblit v1.9.3