|
@@ -0,0 +1,61 @@
|
|
|
|
|
+package com.usky.system.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
|
|
+import com.usky.system.domain.SystemDictRegion;
|
|
|
|
|
+import com.usky.system.mapper.SystemDictRegionMapper;
|
|
|
|
|
+import com.usky.system.service.SystemDictRegionService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 省市区字典服务
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class SystemDictRegionServiceImpl implements SystemDictRegionService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SystemDictRegionMapper systemDictRegionMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Map<String, String> checkAndBuildMap(String provinceCode, String cityCode, String districtCode) {
|
|
|
|
|
+ if (!StringUtils.hasText(provinceCode) || !StringUtils.hasText(cityCode) || !StringUtils.hasText(districtCode)) {
|
|
|
|
|
+ throw new BusinessException("省市区编码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ SystemDictRegion province = systemDictRegionMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<SystemDictRegion>().eq(SystemDictRegion::getCode, provinceCode).last("LIMIT 1"));
|
|
|
|
|
+ SystemDictRegion city = systemDictRegionMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<SystemDictRegion>().eq(SystemDictRegion::getCode, cityCode).last("LIMIT 1"));
|
|
|
|
|
+ SystemDictRegion district = systemDictRegionMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<SystemDictRegion>().eq(SystemDictRegion::getCode, districtCode).last("LIMIT 1"));
|
|
|
|
|
+ if (province == null || city == null || district == null) {
|
|
|
|
|
+ throw new BusinessException("省市区编码无效");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.equals(city.getParent(), province.getCode())) {
|
|
|
|
|
+ throw new BusinessException("市级编码与省级不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Objects.equals(district.getParent(), city.getCode())) {
|
|
|
|
|
+ throw new BusinessException("区级编码与市级不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, String> map = new HashMap<>(4);
|
|
|
|
|
+ map.put(provinceCode, province.getName());
|
|
|
|
|
+ map.put(cityCode, city.getName());
|
|
|
|
|
+ map.put(districtCode, district.getName());
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<SystemDictRegion> listByParentCode(String parentCode) {
|
|
|
|
|
+ if (!StringUtils.hasText(parentCode)) {
|
|
|
|
|
+ throw new BusinessException("父级编码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ return systemDictRegionMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<SystemDictRegion>().eq(SystemDictRegion::getParent, parentCode));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|