|
|
@@ -2445,7 +2445,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, int pageNum, int pageSize) {
|
|
|
+ public IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, Integer dictId, int pageNum, int pageSize) {
|
|
|
// 参数校验
|
|
|
if (lon == null || lat == null) {
|
|
|
throw new IllegalArgumentException("经纬度参数不能为空");
|
|
|
@@ -2476,8 +2476,72 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
// 构建查询条件
|
|
|
QueryWrapper<StoreInfoVo> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
|
- // 如果指定了businessType,则根据传入的数值进行筛选
|
|
|
- if (businessType != null) {
|
|
|
+ // 如果传入了dictId,根据字典id查询经营板块、经营种类、分类并匹配店铺
|
|
|
+ if (dictId != null) {
|
|
|
+ // 根据dictId查询字典表记录
|
|
|
+ StoreDictionary dict = storeDictionaryMapper.selectById(dictId);
|
|
|
+ if (dict == null || dict.getDeleteFlag() == 1) {
|
|
|
+ throw new IllegalArgumentException("字典id不存在或已删除: " + dictId);
|
|
|
+ }
|
|
|
+
|
|
|
+ String typeName = dict.getTypeName();
|
|
|
+ String dictIdStr =dict.getDictId();
|
|
|
+
|
|
|
+ if ("business_section".equals(typeName)) {
|
|
|
+ // 如果是经营板块,直接匹配business_section
|
|
|
+ try {
|
|
|
+ Integer sectionId = Integer.parseInt(dictIdStr);
|
|
|
+ queryWrapper.eq("a.business_section", sectionId);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException("经营板块dictId格式错误: " + dictIdStr);
|
|
|
+ }
|
|
|
+ } else if ("business_type".equals(typeName)) {
|
|
|
+ // 如果是经营种类,需要:
|
|
|
+ // 1. 向上查找父级(经营板块)
|
|
|
+ // 2. 匹配business_section和business_types
|
|
|
+ StoreDictionary parentDict = storeDictionaryMapper.selectById(dict.getParentId());
|
|
|
+ if (parentDict == null || !"business_section".equals(parentDict.getTypeName())) {
|
|
|
+ throw new IllegalArgumentException("经营种类的父级不是经营板块,dictId: " + dictId);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Integer sectionId = Integer.parseInt(parentDict.getDictId());
|
|
|
+ queryWrapper.eq("a.business_section", sectionId);
|
|
|
+ // 使用FIND_IN_SET匹配business_types字段(逗号分隔)
|
|
|
+ queryWrapper.apply("FIND_IN_SET({0}, a.business_types) > 0", dictIdStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException("经营板块或经营种类dictId格式错误");
|
|
|
+ }
|
|
|
+ } else if ("business_classify".equals(typeName)) {
|
|
|
+ // 如果是分类,需要:
|
|
|
+ // 1. 向上查找父级(经营种类)
|
|
|
+ // 2. 向上查找祖父级(经营板块)
|
|
|
+ // 3. 匹配business_section、business_types和business_classify
|
|
|
+ StoreDictionary parentDict = storeDictionaryMapper.selectById(dict.getParentId());
|
|
|
+ if (parentDict == null || !"business_type".equals(parentDict.getTypeName())) {
|
|
|
+ throw new IllegalArgumentException("分类的父级不是经营种类,dictId: " + dictId);
|
|
|
+ }
|
|
|
+
|
|
|
+ StoreDictionary grandParentDict = storeDictionaryMapper.selectById(parentDict.getParentId());
|
|
|
+ if (grandParentDict == null || !"business_section".equals(grandParentDict.getTypeName())) {
|
|
|
+ throw new IllegalArgumentException("经营种类的父级不是经营板块,dictId: " + dictId);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Integer sectionId = Integer.parseInt(grandParentDict.getDictId());
|
|
|
+ queryWrapper.eq("a.business_section", sectionId);
|
|
|
+ // 使用FIND_IN_SET匹配business_types字段
|
|
|
+ queryWrapper.apply("FIND_IN_SET({0}, a.business_types) > 0", parentDict.getDictId());
|
|
|
+ // 使用FIND_IN_SET匹配business_classify字段
|
|
|
+ queryWrapper.apply("FIND_IN_SET({0}, a.business_classify) > 0", dictIdStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException("经营板块、经营种类或分类dictId格式错误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("不支持的字典类型: " + typeName + ", dictId: " + dictId);
|
|
|
+ }
|
|
|
+ } else if (businessType != null) {
|
|
|
+ // 如果指定了businessType,则根据传入的数值进行筛选
|
|
|
// 直接使用传入的数值作为business_section进行筛选
|
|
|
// KTV=3、洗浴汗蒸=4、按摩足浴=5,酒吧的数值未知(由调用方传入)
|
|
|
queryWrapper.eq("a.business_section", businessType);
|
|
|
@@ -2493,11 +2557,11 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
);
|
|
|
|
|
|
List<Integer> businessSectionIds = storeDictionaries.stream()
|
|
|
- .filter(dict -> StringUtils.isNotEmpty(dict.getDictId()))
|
|
|
+ .filter(d -> StringUtils.isNotEmpty(d.getDictId()))
|
|
|
.map(StoreDictionary::getDictId)
|
|
|
- .map(dictId -> {
|
|
|
+ .map(dictIdStr -> {
|
|
|
try {
|
|
|
- return Integer.parseInt(dictId);
|
|
|
+ return Integer.parseInt(dictIdStr);
|
|
|
} catch (NumberFormatException e) {
|
|
|
return null;
|
|
|
}
|