package com.ruoyi.system.service.company.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.system.domain.company.AreaInfo;
|
import com.ruoyi.system.domain.company.CompanyInfo;
|
import com.ruoyi.system.domain.dto.CompanyInfoDto;
|
import com.ruoyi.system.domain.vo.CompanyInfoVO;
|
import com.ruoyi.system.mapper.company.CompanyInfoMapper;
|
import com.ruoyi.system.service.company.IAreaInfoService;
|
import com.ruoyi.system.service.company.ICompanyInfoService;
|
import org.apache.commons.lang3.StringUtils;
|
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.Map;
|
import java.util.stream.Collectors;
|
|
|
@Service
|
public class CompanyInfoServiceImpl extends ServiceImpl<CompanyInfoMapper, CompanyInfo> implements ICompanyInfoService {
|
|
@Autowired
|
private IAreaInfoService areaInfoService;
|
|
/**
|
* 分页查询
|
*
|
* @param companyInfoVO
|
* @return
|
*/
|
@Override
|
public AjaxResult findCompanyInfoPage(CompanyInfoVO companyInfoVO) {
|
if (companyInfoVO.getPageSize() == null || companyInfoVO.getPageNum() == null) {
|
return AjaxResult.error("请求参数【pageSize,pageNum】不能为空!");
|
}
|
PageHelper.startPage(companyInfoVO.getPageNum(), companyInfoVO.getPageSize());
|
QueryWrapper queryWrapper = initQueryWrapper(companyInfoVO);
|
queryWrapper.orderByDesc(CompanyInfo.CREATE_TIME);
|
List<CompanyInfo> companyInfoList = this.list(queryWrapper);
|
PageInfo companyPageInfo = new PageInfo<>(companyInfoList);
|
List<CompanyInfoDto> companyInfoDtoList = initCompanyCity(companyPageInfo.getList());
|
companyPageInfo.setList(companyInfoDtoList);
|
return AjaxResult.success(companyPageInfo);
|
}
|
|
@Override
|
public List<CompanyInfoDto> findExportData(CompanyInfoVO companyInfoVO) {
|
return initCompanyCity(this.list(initQueryWrapper(companyInfoVO)));
|
}
|
|
|
public QueryWrapper initQueryWrapper(CompanyInfoVO companyInfoVO) {
|
QueryWrapper queryWrapper = new QueryWrapper();
|
if (StringUtils.isNoneEmpty(companyInfoVO.getCompanyName())) {
|
queryWrapper.like(CompanyInfo.COMPANY_NAME, companyInfoVO.getCompanyName());
|
}
|
if (StringUtils.isNoneEmpty(companyInfoVO.getCompanyDirector())) {
|
queryWrapper.like(CompanyInfo.COMPANY_DIRECTOR, companyInfoVO.getCompanyDirector());
|
}
|
if (StringUtils.isNoneEmpty(companyInfoVO.getCertificateNum())) {
|
queryWrapper.like(CompanyInfo.CERTIFICATE_NUM, companyInfoVO.getCertificateNum());
|
}
|
if (companyInfoVO.getIsValid() != null) {
|
if (companyInfoVO.getIsValid() == 0) {
|
queryWrapper.ge(CompanyInfo.VALIDITY_DATE_END, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date()));
|
} else {
|
queryWrapper.lt(CompanyInfo.VALIDITY_DATE_END, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date()));
|
}
|
}
|
if (companyInfoVO.getCompanyCity() != null) {
|
queryWrapper.eq(CompanyInfo.COMPANY_CITY, companyInfoVO.getCompanyCity());
|
}
|
queryWrapper.eq(CompanyInfo.IS_DELETE, 0);
|
return queryWrapper;
|
}
|
|
@Override
|
public Boolean checkIsExist(CompanyInfo companyInfo) {
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
//如果证书编号重复,则提示企业重复
|
queryWrapper.eq(CompanyInfo.CERTIFICATE_NUM, companyInfo.getCertificateNum());
|
queryWrapper.eq(CompanyInfo.IS_DELETE, 0);
|
|
return null;
|
}
|
|
@Override
|
public List<CompanyInfoDto> initCompanyCity(List<CompanyInfo> companyInfoDtoList) {
|
List<AreaInfo> areaInfos = areaInfoService.list();
|
Map<String, List<AreaInfo>> areaInfoMap = areaInfos.stream().collect(Collectors.groupingBy(AreaInfo::getId));
|
List<CompanyInfoDto> companyInfoDtoList1 = new ArrayList<>();
|
companyInfoDtoList.forEach(companyInfoDto -> {
|
CompanyInfoDto newCompanyInfoDto = new CompanyInfoDto();
|
BeanUtils.copyProperties(companyInfoDto, newCompanyInfoDto);
|
newCompanyInfoDto.setCompanyCityValue(companyInfoDto.getCompanyCity());
|
String companyCity = "";
|
if (StringUtils.isNotEmpty(newCompanyInfoDto.getCompanyCityValue()) && CollectionUtils.isNotEmpty(areaInfoMap.get(newCompanyInfoDto.getCompanyCityValue()))) {
|
companyCity = areaInfoMap.get(newCompanyInfoDto.getCompanyCityValue()).get(0).getCity() + areaInfoMap.get(newCompanyInfoDto.getCompanyCityValue()).get(0).getArea();
|
newCompanyInfoDto.setCity( areaInfoMap.get(newCompanyInfoDto.getCompanyCityValue()).get(0).getCity());
|
newCompanyInfoDto.setArea( areaInfoMap.get(newCompanyInfoDto.getCompanyCityValue()).get(0).getArea());
|
}
|
newCompanyInfoDto.setCompanyCity(companyCity);
|
companyInfoDtoList1.add(newCompanyInfoDto);
|
});
|
return companyInfoDtoList1;
|
}
|
}
|