|
@@ -0,0 +1,152 @@
|
|
|
+package com.fjhx.area.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.area.entity.dto.AreaInfoSelectDto;
|
|
|
+import com.fjhx.area.entity.po.CustomizeArea;
|
|
|
+import com.fjhx.area.mapper.CustomizeAreaMapper;
|
|
|
+import com.fjhx.area.service.CustomizeAreaService;
|
|
|
+import com.fjhx.area.service.SetCustomizeAreaId;
|
|
|
+import com.fjhx.area.service.SetCustomizeAreaName;
|
|
|
+import com.ruoyi.common.constant.BaseSourceConstant;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 自定义地区表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-05-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CustomizeAreaServiceImpl extends ServiceImpl<CustomizeAreaMapper, CustomizeArea> implements CustomizeAreaService {
|
|
|
+
|
|
|
+ @DS(BaseSourceConstant.BASE)
|
|
|
+ @Override
|
|
|
+ public void setAreaId(List<? extends SetCustomizeAreaId> setAreaIdList) {
|
|
|
+
|
|
|
+ for (SetCustomizeAreaId item : setAreaIdList) {
|
|
|
+
|
|
|
+ // 国家id
|
|
|
+ Long countryId = item.getCountryId();
|
|
|
+
|
|
|
+ // 省/州 id
|
|
|
+ if (item.getProvinceId() == null) {
|
|
|
+
|
|
|
+ // 省名称
|
|
|
+ String provinceName = item.getProvinceName();
|
|
|
+
|
|
|
+ CustomizeArea customizeArea = getOne(q -> q
|
|
|
+ .eq(CustomizeArea::getParentId, countryId)
|
|
|
+ .eq(CustomizeArea::getName, provinceName));
|
|
|
+
|
|
|
+ if (customizeArea == null) {
|
|
|
+ customizeArea = new CustomizeArea();
|
|
|
+ customizeArea.setName(provinceName);
|
|
|
+ customizeArea.setChineseName(provinceName);
|
|
|
+ customizeArea.setLevelCode(2);
|
|
|
+ customizeArea.setParentId(countryId);
|
|
|
+ save(customizeArea);
|
|
|
+ }
|
|
|
+
|
|
|
+ item.setProvinceId(customizeArea.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 市id
|
|
|
+ if (item.getCityId() != null) {
|
|
|
+
|
|
|
+ // 市名称
|
|
|
+ String cityName = item.getCityName();
|
|
|
+
|
|
|
+ CustomizeArea customizeArea = getOne(q -> q
|
|
|
+ .eq(CustomizeArea::getParentId, item.getProvinceId())
|
|
|
+ .eq(CustomizeArea::getName, cityName));
|
|
|
+
|
|
|
+ if (customizeArea == null) {
|
|
|
+ customizeArea = new CustomizeArea();
|
|
|
+ customizeArea.setName(cityName);
|
|
|
+ customizeArea.setChineseName(cityName);
|
|
|
+ customizeArea.setLevelCode(3);
|
|
|
+ customizeArea.setParentId(item.getProvinceId());
|
|
|
+ save(customizeArea);
|
|
|
+ }
|
|
|
+
|
|
|
+ item.setCityId(customizeArea.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @DS(BaseSourceConstant.BASE)
|
|
|
+ @Override
|
|
|
+ public void setAreaName(List<? extends SetCustomizeAreaName> areaList) {
|
|
|
+ Set<Long> areaIdList = new HashSet<>();
|
|
|
+
|
|
|
+ for (SetCustomizeAreaName item : areaList) {
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getCountryId())) {
|
|
|
+ areaIdList.add(item.getCountryId());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getProvinceId())) {
|
|
|
+ areaIdList.add(item.getProvinceId());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getCityId())) {
|
|
|
+ areaIdList.add(item.getCityId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (areaIdList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 地区
|
|
|
+ List<CustomizeArea> areaInfoList = listByIds(areaIdList);
|
|
|
+
|
|
|
+ Map<Long, CustomizeArea> areaInfoMap = areaInfoList.stream().collect(Collectors.toMap(CustomizeArea::getId, item -> item));
|
|
|
+
|
|
|
+ for (SetCustomizeAreaName item : areaList) {
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getCountryId())) {
|
|
|
+ CustomizeArea customizeArea = areaInfoMap.get(item.getCountryId());
|
|
|
+ if (customizeArea != null) {
|
|
|
+ item.setCountryName(customizeArea.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getProvinceId())) {
|
|
|
+ CustomizeArea customizeArea = areaInfoMap.get(item.getProvinceId());
|
|
|
+ if (customizeArea != null) {
|
|
|
+ item.setProvinceName(customizeArea.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(item.getCityId())) {
|
|
|
+ CustomizeArea customizeArea = areaInfoMap.get(item.getCityId());
|
|
|
+ if (customizeArea != null) {
|
|
|
+ item.setCityName(customizeArea.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @DS(BaseSourceConstant.BASE)
|
|
|
+ @Override
|
|
|
+ public Map<Long, String> getAreaMapByIds(List<Long> idList) {
|
|
|
+ List<CustomizeArea> areaInfos = listByIds(idList);
|
|
|
+ return areaInfos.stream().collect(Collectors.toMap(CustomizeArea::getId, CustomizeArea::getName));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CustomizeArea> getList(AreaInfoSelectDto dto) {
|
|
|
+ String parentId = ObjectUtil.defaultIfNull(dto.getParentId(), "0");
|
|
|
+ return list(Wrappers.<CustomizeArea>lambdaQuery().eq(CustomizeArea::getParentId, parentId));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|