From e6eb127b2ef4f297b093dcd9a5b47be457f67043 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 29 一月 2026 14:29:05 +0800
Subject: [PATCH] feat(purchase): 碳立方对接
---
ruoyi-system/src/main/java/com/ruoyi/basic/service/impl/ProvinceServiceImpl.java | 141 +++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 129 insertions(+), 12 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/basic/service/impl/ProvinceServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/basic/service/impl/ProvinceServiceImpl.java
index 9c9aa6b..9a9aeb8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/basic/service/impl/ProvinceServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/basic/service/impl/ProvinceServiceImpl.java
@@ -1,22 +1,139 @@
package com.ruoyi.basic.service.impl;
-import com.ruoyi.basic.entity.Province;
-import com.ruoyi.basic.mapper.ProvinceMapper;
- import com.ruoyi.basic.service.ProvinceService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
+import com.ruoyi.basic.entity.City;
+import com.ruoyi.basic.entity.District;
+import com.ruoyi.basic.entity.Province;
+import com.ruoyi.basic.entity.dto.TreeSelectOption;
+import com.ruoyi.basic.mapper.CityMapper;
+import com.ruoyi.basic.mapper.DistrictMapper;
+import com.ruoyi.basic.mapper.ProvinceMapper;
+import com.ruoyi.basic.service.ProvinceService;
import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
-* <p>
- * 鐪佽〃 鏈嶅姟瀹炵幇绫�
- * </p>
-*
-* @author ruoyi
-* @since 2025-05-31
-*/
+ * <p>
+ * 鐪佽〃 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author ruoyi
+ * @since 2025-05-31
+ */
@Service
@RequiredArgsConstructor
- public class ProvinceServiceImpl extends ServiceImpl<ProvinceMapper, Province> implements ProvinceService {
+public class ProvinceServiceImpl extends ServiceImpl<ProvinceMapper, Province> implements ProvinceService {
+ @Autowired
+ private ProvinceMapper provinceMapper;
+
+ @Autowired
+ private CityMapper cityMapper;
+
+ @Autowired
+ private DistrictMapper districtMapper;
+
+ @Override
+ public List<TreeSelectOption> getAreaOptions() {
+ List<TreeSelectOption> res = new ArrayList<>();
+
+ // 鎵归噺鏌ヨ鎵�鏈夌渷浠�
+ List<Province> provinces = provinceMapper.selectList(null);
+ if (provinces.isEmpty()) {
+ return res;
+ }
+
+ // 鑾峰彇鎵�鏈夌渷浠絀D鐢ㄤ簬鎵归噺鏌ヨ鍩庡競
+ List<Long> provinceIds = provinces.stream()
+ .map(Province::getId)
+ .collect(Collectors.toList());
+
+ // 鎵归噺鏌ヨ鎵�鏈夊煄甯�
+ List<City> allCities = cityMapper.selectList(
+ new LambdaQueryWrapper<City>().in(City::getProvinceId, provinceIds));
+
+ // 灏嗗煄甯傛寜鐪佷唤ID鍒嗙粍
+ Map<Long, List<City>> cityMap = allCities.stream()
+ .collect(Collectors.groupingBy(City::getProvinceId));
+
+ // 鑾峰彇鎵�鏈夊煄甯侷D鐢ㄤ簬鎵归噺鏌ヨ鍖哄煙
+ List<Long> cityIds = allCities.stream()
+ .map(City::getId)
+ .collect(Collectors.toList());
+
+ // 鎵归噺鏌ヨ鎵�鏈夊尯鍩�
+ List<District> allDistricts = districtMapper.selectList(
+ new LambdaQueryWrapper<District>().in(District::getCityId, cityIds));
+
+ // 灏嗗尯鍩熸寜鍩庡競ID鍒嗙粍
+ Map<Long, List<District>> districtMap = allDistricts.stream()
+ .collect(Collectors.groupingBy(District::getCityId));
+
+ // 鏋勫缓鏍戝舰缁撴瀯
+ for (Province province : provinces) {
+ List<TreeSelectOption> cities = new ArrayList<>();
+
+ List<City> cityList = cityMap.get(province.getId());
+ if (cityList != null && !cityList.isEmpty()) {
+ for (City city : cityList) {
+ List<TreeSelectOption> districts = new ArrayList<>();
+
+ List<District> districtList = districtMap.get(city.getId());
+ if (districtList != null && !districtList.isEmpty()) {
+ for (District district : districtList) {
+ districts.add(new TreeSelectOption(district.getId().toString(),
+ district.getName(), district.getId(), null));
+ }
+ }
+
+ TreeSelectOption cityTreeSelectOption = new TreeSelectOption();
+ cityTreeSelectOption.setValue(city.getId().toString());
+ cityTreeSelectOption.setLabel(city.getName());
+ cityTreeSelectOption.setId(city.getId());
+ cityTreeSelectOption.setChildren(districts);
+
+ cities.add(cityTreeSelectOption);
+ }
+ }
+
+ TreeSelectOption treeSelectOption = new TreeSelectOption();
+ treeSelectOption.setValue(province.getId().toString());
+ treeSelectOption.setLabel(province.getName());
+ treeSelectOption.setId(province.getId());
+ treeSelectOption.setChildren(cities);
+ res.add(treeSelectOption);
+ }
+
+ return res;
}
+
+
+ @Override
+ public String getAreaDisplay(Long provinceId, Long cityId, Long districtId) {
+ Province province = provinceMapper.selectById(provinceId);
+ if (province == null) {
+ throw new RuntimeException("鐪佷笉瀛樺湪");
+ }
+ City city = cityMapper.selectById(cityId);
+ if (city == null) {
+ throw new RuntimeException("甯備笉瀛樺湪");
+ }
+ District district = districtMapper.selectById(districtId);
+ if (district == null) {
+ throw new RuntimeException("鍖轰笉瀛樺湪");
+ }
+
+ // 濡傛灉鐪佸拰甯傚悓鍚�
+ if (province.getName().equals(city.getName())) {
+ return province.getName() + " " + district.getName();
+ }
+ return province.getName() + city.getName() + district.getName();
+ }
+}
--
Gitblit v1.9.3