package com.xiaopeng.operation.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.xiaopeng.common.redis.service.RedisService;
|
import com.xiaopeng.operation.mapper.XpOpenCityMapper;
|
import com.xiaopeng.api.model.operation.XpOpenCity;
|
import com.xiaopeng.operation.service.XpOpenCityService;
|
import com.xiaopeng.operation.vo.OpenCityListVO;
|
import com.xiaopeng.operation.vo.XpOpenCityNextVo;
|
import com.xiaopeng.operation.vo.XpOpenCityVo;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 开通城市 服务实现类
|
* </p>
|
*
|
* @author liu
|
* @since 2026-02-03
|
*/
|
@Service
|
public class XpOpenCityServiceImpl extends ServiceImpl<XpOpenCityMapper, XpOpenCity> implements XpOpenCityService {
|
|
|
|
@Override
|
public XpOpenCityVo citiesList() {
|
XpOpenCityVo xpOpenCityVo = new XpOpenCityVo();
|
List<XpOpenCity> xpOpenCities = this.baseMapper.selectList(new LambdaQueryWrapper<XpOpenCity>().eq(XpOpenCity::getStatus, 1));
|
if(!xpOpenCities.isEmpty()){
|
List<XpOpenCityNextVo> xpOpenCityNextVos = new ArrayList<>();
|
for (XpOpenCity xpOpenCity : xpOpenCities) {
|
XpOpenCityNextVo xpOpenCityNextVo = new XpOpenCityNextVo();
|
xpOpenCityNextVo.setName(xpOpenCity.getCityName());
|
xpOpenCityNextVo.setAdcode(xpOpenCity.getCityCode());
|
xpOpenCityNextVo.setId(xpOpenCity.getId());
|
xpOpenCityNextVos.add(xpOpenCityNextVo);
|
}
|
xpOpenCityVo.setCities(xpOpenCityNextVos);
|
xpOpenCityVo.setTotal(xpOpenCities.size());
|
}
|
return xpOpenCityVo;
|
}
|
|
@Override
|
public List<OpenCityListVO> getOpenCityListForAdmin() {
|
// 1. 查询所有启用状态的开通城市
|
List<XpOpenCity> xpOpenCities = this.baseMapper.selectList(
|
new LambdaQueryWrapper<XpOpenCity>()
|
.eq(XpOpenCity::getStatus, 1)
|
.orderByAsc(XpOpenCity::getId)
|
);
|
|
// 2. 转换为VO,处理区/县级拼接逻辑
|
return xpOpenCities.stream()
|
.map(city -> {
|
OpenCityListVO vo = new OpenCityListVO();
|
vo.setId(city.getId());
|
|
// 关键逻辑:判断是否为区/县级配置
|
if (StringUtils.isNotBlank(city.getDistrictName())) {
|
// 区/县级:拼接市名 + 区/县名
|
vo.setName(city.getCityName() + city.getDistrictName());
|
vo.setCode(city.getDistrictCode());
|
} else {
|
// 城市级:只返回市名
|
vo.setName(city.getCityName());
|
vo.setCode(city.getCityCode());
|
}
|
|
return vo;
|
})
|
.collect(Collectors.toList());
|
}
|
}
|