liujie
15 小时以前 74f8b8074a2fb391b5363b4dca5f99bf31993430
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
package com.supersavedriving.driver.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.supersavedriving.driver.modular.system.dao.BranchOfficeMapper;
import com.supersavedriving.driver.modular.system.model.BranchOffice;
import com.supersavedriving.driver.modular.system.model.TBranchOfficeArea;
import com.supersavedriving.driver.modular.system.service.IBranchOfficeService;
import com.supersavedriving.driver.modular.system.service.ITBranchOfficeAreaService;
import com.supersavedriving.driver.modular.system.warpper.OpenCityWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
 
/**
* 分公司逻辑类
* @author pzb
* @Date 2023/2/3 14:48
*/
@Service
public class BranchOfficeServiceImpl extends ServiceImpl<BranchOfficeMapper, BranchOffice> implements IBranchOfficeService {
 
    @Autowired
    private ITBranchOfficeAreaService branchOfficeAreaService;
 
    /**
     * 根据城市code获取开通区域
     * @param cityCode  城市code
     * @return
     * @throws Exception
     */
    @Override
    public List<OpenCityWarpper> queryOpenDistrict(String cityCode) throws Exception {
        List<TBranchOfficeArea> branchOfficeAreas = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>().eq("cityCode", cityCode));
        if(CollectionUtils.isEmpty(branchOfficeAreas)){
            return new ArrayList<>();
        }
        List<Integer> officeIds = branchOfficeAreas.stream().map(TBranchOfficeArea::getBranchOfficeId).collect(Collectors.toList());
        officeIds = officeIds.stream().distinct().collect(Collectors.toList());
        List<BranchOffice> branchOffices = this.selectList(new EntityWrapper<BranchOffice>().in("id", officeIds).eq("status", 1));
        List<OpenCityWarpper> district = new ArrayList<>();
        for (BranchOffice branchOffice : branchOffices) {
            branchOfficeAreas.stream().filter(tBranchOfficeArea -> tBranchOfficeArea.getBranchOfficeId().equals(branchOffice.getId())).forEach(tBranchOfficeArea -> {
                OpenCityWarpper openCityWarpper = new OpenCityWarpper();
                openCityWarpper.setCode(tBranchOfficeArea.getAreaCode());
                openCityWarpper.setName(tBranchOfficeArea.getAreaName());
                district.add(openCityWarpper);
            });
//            OpenCityWarpper openCityWarpper = new OpenCityWarpper();
//            openCityWarpper.setCode(null != branchOffice.getDistrictCode() ? branchOffice.getDistrictCode() : branchOffice.getCityCode());
//            openCityWarpper.setName(null != branchOffice.getDistrictName() ? branchOffice.getDistrictName() : branchOffice.getCityName());
//            district.add(openCityWarpper);
        }
        return district;
    }
}