|
@@ -0,0 +1,92 @@
|
|
|
+package com.fjhx.area.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+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.AreaInfo;
|
|
|
+import com.fjhx.area.mapper.AreaInfoMapper;
|
|
|
+import com.fjhx.area.service.AreaInfoService;
|
|
|
+import com.fjhx.area.service.ISetAreaName;
|
|
|
+import com.ruoyi.common.constant.DatasourceConstant;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+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-03-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AreaInfoServiceImpl extends ServiceImpl<AreaInfoMapper, AreaInfo> implements AreaInfoService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AreaInfo> getList(AreaInfoSelectDto dto) {
|
|
|
+ String parentId = ObjectUtil.defaultIfNull(dto.getParentId(), "0");
|
|
|
+ return list(Wrappers.<AreaInfo>lambdaQuery().eq(AreaInfo::getParentId, parentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
+ @DS(DatasourceConstant.SLAVE_NAME)
|
|
|
+ @Override
|
|
|
+ public void setAreaName(List<ISetAreaName> areaList) {
|
|
|
+ Set<String> areaIdList = new HashSet<>();
|
|
|
+
|
|
|
+ for (ISetAreaName iSetAreaName : areaList) {
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getCountryId())) {
|
|
|
+ areaIdList.add(iSetAreaName.getCountryId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getProvinceId())) {
|
|
|
+ areaIdList.add(iSetAreaName.getProvinceId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getCityId())) {
|
|
|
+ areaIdList.add(iSetAreaName.getCityId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (areaIdList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<AreaInfo> areaInfoList = listByIds(areaIdList);
|
|
|
+
|
|
|
+ Map<String, AreaInfo> areaInfoMap = areaInfoList.stream().collect(Collectors.toMap(AreaInfo::getId, item -> item));
|
|
|
+
|
|
|
+ for (ISetAreaName iSetAreaName : areaList) {
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getCountryId())) {
|
|
|
+ AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getCountryId());
|
|
|
+ if (areaInfo != null) {
|
|
|
+ iSetAreaName.setCountryName(areaInfo.getChineseName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getProvinceId())) {
|
|
|
+ AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getProvinceId());
|
|
|
+ if (areaInfo != null) {
|
|
|
+ iSetAreaName.setProvinceName(areaInfo.getChineseName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(iSetAreaName.getCityId())) {
|
|
|
+ AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getCityId());
|
|
|
+ if (areaInfo != null) {
|
|
|
+ iSetAreaName.setCityName(areaInfo.getChineseName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|