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;
|
}
|
}
|