| | |
| | | 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; |
| | |
| | | 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; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.CompanyService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.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; |
| | | |
| | | /** |
| | | * 企业信息表Service实现 |
| | |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | checkUnique(company); |
| | | |
| | | Company insert = new Company(); |
| | | insert.setCreator(loginUserInfo.getId()); |
| | | insert.setCreateDate(new Date()); |
| | |
| | | IPage<Company> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.eq(Company::getId, pageWrap.getModel().getId()); |
| | | } |
| | |
| | | } |
| | | queryWrapper.orderByDesc(Company::getCreateDate); |
| | | queryWrapper.leftJoin(Category.class,Category::getId,Company::getCategoryId) |
| | | .leftJoin(SystemUser.class,SystemUser::getId,Company::getCreator); |
| | | .leftJoin(Member.class, Member::getId,Company::getHeadId); |
| | | queryWrapper.selectAll(Company.class) |
| | | .selectAs(Category::getName,Company::getCategoryName) |
| | | .selectAs(SystemUser::getRealname,Company::getCreatorName); |
| | | .selectAs(Member::getName,Company::getHeadName) |
| | | .selectAs(Member::getPhone,Company::getHeadPhone) |
| | | .select("count(t1.id) as countNum"); |
| | | IPage<Company> companyIPage = companyJoinMapper.selectJoinPage(page, Company.class, queryWrapper); |
| | | return PageData.from(companyIPage); |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 劳务公司唯一性校验 |
| | |
| | | .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(),"公司名称已存在"); |
| | | } |
| | | } |
| | | } |