修复微信导入地址没有cityID的问题

This commit is contained in:
stivepeim
2021-10-09 15:18:46 +08:00
parent 15460f5fe7
commit ffd3014f16
3 changed files with 37 additions and 1 deletions

View File

@@ -32,4 +32,10 @@ public interface SystemCityService extends IService<SystemCity> {
List<Integer> getCityIdList();
SystemCity getCityByCityId(Integer cityId);
}
/**
* 根据城市名称获取城市详细数据
* @param cityName 城市名称
* @return 城市数据
*/
SystemCity getCityByCityName(String cityName);
}

View File

@@ -1,6 +1,7 @@
package com.zbkj.crmeb.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.constants.Constants;
import com.utils.RedisUtil;
@@ -173,5 +174,20 @@ public class SystemCityServiceImpl extends ServiceImpl<SystemCityDao, SystemCity
public void asyncRedis(Integer pid){
systemCityAsyncService.async(pid);
}
/**
* 根据城市名称获取城市详细数据
* @author 大粽子
* @param cityName 城市名称
* @return 城市数据
*/
@Override
public SystemCity getCityByCityName(String cityName) {
LambdaQueryWrapper<SystemCity> systemCityLambdaQueryWrapper = Wrappers.lambdaQuery();
systemCityLambdaQueryWrapper
.eq(SystemCity::getName,cityName)
.eq(SystemCity::getIsShow,1);
return getOne(systemCityLambdaQueryWrapper);
}
}

View File

@@ -1,5 +1,6 @@
package com.zbkj.crmeb.user.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -88,7 +89,20 @@ public class UserAddressServiceImpl extends ServiceImpl<UserAddressDao, UserAddr
userAddress.setCityId(request.getAddress().getCityId());
userAddress.setDistrict(request.getAddress().getDistrict());
userAddress.setProvince(request.getAddress().getProvince());
// 添加地址时cityId和城市名称不能同时为空如果id为空必须用城市名称自查后set CityId
if(request.getAddress().getCityId() == 0 && StringUtils.isBlank(request.getAddress().getCity())){
throw new CrmebException("请选择正确城市数据");
}
if(StringUtils.isNotBlank(request.getAddress().getCity()) && request.getAddress().getCityId() == 0){
SystemCity currentCity = systemCityService.getCityByCityName(request.getAddress().getCity());
if(ObjectUtil.isNull(currentCity)) throw new CrmebException("当前城市未找到!");
userAddress.setCityId(currentCity.getCityId());
}
//if(request.getAddress().getCityId() > 0 && StringUtils.isNotBlank(request.getAddress().getCity())){
checkCity(userAddress.getCityId());
//}
if(request.getAddress().getCityId() > 0 && StringUtils.isNotBlank(request.getAddress().getCity())){
checkCity(userAddress.getCityId());
}