郑永安
2023-06-19 451e341df739f387201914b67323efa1c4f4c8d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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;
    }
}