Ver Fonte

商家平台端门店装修

qrs há 3 semanas atrás
pai
commit
9fa3bdc8f2

+ 301 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/config/GaoDeMapUtil.java

@@ -0,0 +1,301 @@
+package shop.alien.storeplatform.config;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import shop.alien.entity.store.EssentialCityCode;
+import shop.alien.mapper.EssentialCityCodeMapper;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 高德地图工具类
+ *
+ * @author ssk
+ * @version 1.0.0
+ * @discription 打死你个龟孙
+ * @since 1937-7-7
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class GaoDeMapUtil {
+
+    @Value("${gaode.key}")
+    private String key;
+
+    @Value("${gaode.geoUrl}")
+    private String geoUrl;
+
+    @Value("${gaode.geoListUrl}")
+    private String geoListUrl;
+
+    @Value("${gaode.getDistrict}")
+    private String getDistrict;
+
+    @Value("${gaode.distanceUrl}")
+    private String distanceUrl;
+
+    @Value("${gaode.distanceTypeUrl}")
+    private String distanceTypeUrl;
+
+    @Value("${gaode.nearUrl}")
+    private String nearUrl;
+
+    @Value("${gaode.subwayUrl}")
+    private String subwayUrl;
+
+    @Value("${gaode.addressUrl}")
+    private String addressUrl;
+
+    private final EssentialCityCodeMapper essentialCityCodeMapper;
+
+    /**
+     * 地址转经纬度
+     *
+     * @param address 地址
+     * @return 经纬度
+     */
+    public String getLonAndLatByAddress(String address) {
+        String formattedUrl = String.format(geoUrl, address, key);
+        JSONObject obj = getResponse(formattedUrl);
+        if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+            JSONArray geocodesArray = obj.getJSONArray("geocodes");
+            if (geocodesArray != null && !geocodesArray.isEmpty()) {
+                JSONObject jobJSON = geocodesArray.getJSONObject(0);
+                return jobJSON.getString("location");
+            } else {
+                log.error("AddressLocationUtil.getLonAndLatByAddress ERROR 未找到与地址匹配的经纬度信息");
+                return "ERROR 未找到与地址匹配的经纬度信息";
+            }
+        } else {
+            log.error("AddressLocationUtil.getLonAndLatByAddress ERROR 地址转换经纬度失败");
+            return "ERROR 地址转换经纬度失败";
+        }
+    }
+
+    /**
+     * 地址转经纬度
+     *
+     * @param address 地址
+     * @return 经纬度
+     */
+    public JSONObject getInputPrompt(String address, String city) {
+        //如果按照城市查询
+        String cityCode = "";
+        if (StringUtils.isNotEmpty(city)) {
+            EssentialCityCode essentialCityCode = essentialCityCodeMapper.selectOne(new LambdaQueryWrapper<EssentialCityCode>().eq(EssentialCityCode::getAreaName, city));
+            if (null != essentialCityCode) {
+                cityCode = essentialCityCode.getCityCode().toString();
+            }
+        }
+        String formattedUrl = String.format(geoListUrl, address, key, cityCode);
+        JSONObject obj = getResponse(formattedUrl);
+        return obj;
+    }
+
+    /**
+     * 地址转经纬度
+     * cityCode:城市编码
+     *
+     * @return
+     */
+    public JSONObject getDistrict(String cityCode) {
+        String formattedUrl = String.format(getDistrict, key, cityCode);
+        JSONObject obj = getResponse(formattedUrl);
+        return obj;
+    }
+
+    /**
+     * 计算两个经纬度的距离
+     *
+     * @param longitudeOne 经度1
+     * @param latitudeOne  纬度1
+     * @param longitudeTwo 经度2
+     * @param latitudeTwo  纬度2
+     * @return distance
+     */
+    public Double getDistance(String longitudeOne, String latitudeOne, String longitudeTwo, String latitudeTwo) {
+        try {
+            String urlString = String.format(distanceUrl, key, longitudeOne, latitudeOne, longitudeTwo, latitudeTwo);
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONArray resultsArray = obj.getJSONArray("results");
+                if (resultsArray != null && !resultsArray.isEmpty()) {
+                    JSONObject resultJSON = resultsArray.getJSONObject(0);
+                    return Double.parseDouble(resultJSON.getString("distance"));
+                } else {
+                    log.error("AddressLocationUtil.getDistance ERROR 计算距离失败,结果为空");
+                    return null;
+                }
+            } else {
+                log.error("AddressLocationUtil.getDistance ERROR 计算距离失败");
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("AddressLocationUtil.getDistance ERROR {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * 计算两个经纬度的距离
+     *
+     * @param longitudeOne 经度1
+     * @param latitudeOne  纬度1
+     * @param longitudeTwo 经度2
+     * @param latitudeTwo  纬度2
+     * @return distance
+     */
+    public Double getDistanceStraightLine(String longitudeOne, String latitudeOne, String longitudeTwo, String latitudeTwo) {
+        try {
+            String urlString = String.format(distanceTypeUrl, key, longitudeOne, latitudeOne, longitudeTwo, latitudeTwo, 0);
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONArray resultsArray = obj.getJSONArray("results");
+                if (resultsArray != null && !resultsArray.isEmpty()) {
+                    JSONObject resultJSON = resultsArray.getJSONObject(0);
+                    return Double.parseDouble(resultJSON.getString("distance"));
+                } else {
+                    log.error("AddressLocationUtil.getDistance ERROR 计算距离失败,结果为空");
+                    return null;
+                }
+            } else {
+                log.error("AddressLocationUtil.getDistance ERROR 计算距离失败");
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("AddressLocationUtil.getDistance ERROR {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * 获取附近商家、建筑等信息
+     *
+     * @param longitude 经度
+     * @param latitude  纬度
+     * @return
+     */
+    public JSONArray getNear(String longitude, String latitude) {
+        try {
+            String urlString = String.format(nearUrl, longitude, latitude, key, 10000, 20, 1);
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONArray resultsArray = obj.getJSONArray("pois");
+                return resultsArray;
+            }
+        } catch (Exception e) {
+            log.error("AddressLocationUtil.getNear ERROR {}", e.getMessage());
+        }
+        return new JSONArray();
+    }
+
+    /**
+     * 获取10公里范围内的商场
+     *
+     * @param longitude 经度
+     * @param latitude  纬度
+     * @return 商场列表
+     */
+    public JSONArray getNearbyShoppingMalls(String longitude, String latitude) {
+        try {
+            // 使用高德地图POI搜索接口,搜索类型为商场(060100)
+            String urlString = String.format(nearUrl, longitude, latitude, key, 10000, 20, 1) + "&types=060100";
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONArray resultsArray = obj.getJSONArray("pois");
+                return resultsArray;
+            }
+        } catch (Exception e) {
+            log.error("GaoDeMapUtil.getNearbyShoppingMalls ERROR {}", e.getMessage());
+        }
+        return new JSONArray();
+    }
+
+    public JSONObject getNearbySubway(String longitude, String latitude) {
+        try {
+            // 使用高德地图POI搜索接口,搜索类型为地铁站(010100)
+            String encodedKeywords = URLEncoder.encode("地铁站", "UTF-8");
+            String urlString = String.format(
+                    subwayUrl,
+                    key, latitude, longitude, encodedKeywords, 1000, 150500);
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONObject pois = obj.getJSONArray("pois").getJSONObject(0);
+                return pois;
+            }
+        } catch (Exception e) {
+            log.error("GaoDeMapUtil.getNearbySubway ERROR {}", e.getMessage());
+        }
+        return new JSONObject();
+    }
+
+    /**
+     * 通过经纬度获取地址信息
+     *
+     * @param longitude
+     * @param latitude
+     * @param radius
+     * @param extensions
+     * @return
+     */
+    public Map<String, String> getAddressByLonAndLat(String longitude, String latitude, String radius, String extensions) {
+        String formattedUrl = String.format(addressUrl, longitude, latitude, key, radius, extensions);
+        JSONObject obj = getResponse(formattedUrl);
+        try {
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                Map<String, String> address = new HashMap<>();
+                JSONObject regeocodeObject = obj.getJSONObject("regeocode");
+                JSONObject addressComponent = regeocodeObject.getJSONObject("addressComponent");
+                address.put("city", addressComponent.getString("city"));
+                address.put("district", addressComponent.getString("district"));
+                address.put("province", addressComponent.getString("province"));
+                JSONObject streetNumber = addressComponent.getJSONObject("streetNumber");
+                address.put("street", streetNumber.getString("street"));
+                address.put("streetNumber", streetNumber.getString("number"));
+                JSONObject pois = regeocodeObject.getJSONArray("pois").getJSONObject(0);
+                address.put("poiName", pois.getString("name"));
+                return address;
+            }
+        } catch (Exception e) {
+            log.error("GaoDeMapUtil.getAddressByLonAndLat ERROR {}", e.getMessage());
+        }
+        return new HashMap<>();
+    }
+
+    /**
+     * 创建请求
+     *
+     * @param serverUrl 请求地址
+     * @return JSONObject
+     */
+    private JSONObject getResponse(String serverUrl) {
+        StringBuilder result = new StringBuilder();
+        try {
+            URL url = new URL(serverUrl);
+            URLConnection conn = url.openConnection();
+            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+            in.close();
+        } catch (Exception e) {
+            log.error("AddressLocationUtil.getResponse ERROR {}", e.getMessage());
+            return null;
+        }
+        return JSONObject.parseObject(result.toString());
+    }
+}

+ 11 - 4
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformInfoController.java

@@ -1,15 +1,13 @@
 package shop.alien.storeplatform.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiOperationSupport;
-import io.swagger.annotations.ApiSort;
+import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreInfo;
 import shop.alien.entity.store.dto.StoreInfoDto;
+import shop.alien.entity.store.vo.StoreMainInfoVo;
 import shop.alien.storeplatform.service.StorePlatformInfoService;
 
 @Slf4j
@@ -39,4 +37,13 @@ public class StorePlatformInfoController {
         }
     }
 
+    @ApiOperation(value = "门店详细信息")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "门店id", dataType = "Long", paramType = "query", required = true)})
+    @GetMapping("/getDetail")
+    public R<StoreMainInfoVo> getDetail(Integer id) {
+        log.info("StoreInfoController.getDetail?id={}", id);
+        return R.data(storePlatformInfoService.getDetail(id));
+    }
+
 }

+ 1 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformMenuController.java

@@ -18,7 +18,7 @@ import java.util.List;
  * @since 2024-12-05
  */
 @Slf4j
-@Api(tags = {"二期-门店菜单"})
+@Api(tags = {"商户平台-门店菜单"})
 @ApiSort(4)
 @CrossOrigin
 @RestController

+ 2 - 2
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformOfficialAlbumController.java

@@ -21,11 +21,11 @@ import java.util.List;
  * @since 2025-07-16
  */
 @Slf4j
-@Api(tags = {"二期-官方相册"})
+@Api(tags = {"商户平台-官方相册"})
 @ApiSort(1)
 @CrossOrigin
 @RestController
-@RequestMapping("/store/official")
+@RequestMapping("/storePlatformOfficial")
 @RequiredArgsConstructor
 public class StorePlatformOfficialAlbumController {
     private final StorePlatformOfficialAlbumService storeOfficialAlbumService;

+ 12 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformRenovationController.java

@@ -5,8 +5,10 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.StoreBusinessInfo;
 import shop.alien.entity.store.vo.StoreDictionaryVo;
 import shop.alien.entity.store.vo.StoreMainInfoVo;
+import shop.alien.storeplatform.service.StorePlatformInfoService;
 import shop.alien.storeplatform.service.StorePlatformRenovationService;
 
 import java.util.ArrayList;
@@ -23,6 +25,8 @@ public class StorePlatformRenovationController {
 
     private final StorePlatformRenovationService storePlatformRenovationService;
 
+    private final StorePlatformInfoService storePlatformInfoService;
+
     @ApiOperation(value = "web端查询经营板块信息")
     @ApiOperationSupport(order = 6)
     @GetMapping("/getBusinessSection")
@@ -47,4 +51,12 @@ public class StorePlatformRenovationController {
         return R.data(storePlatformRenovationService.getDecorationDetail(id));
     }
 
+    @ApiOperation(value = "门店装修-门店营业时间")
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "门店id", dataType = "Long", paramType = "query", required = true)})
+    @GetMapping("/getStoreInfoBusinessHours")
+    public R<List<StoreBusinessInfo>> getStoreInfoBusinessHours(Integer id) {
+        log.info("StoreInfoController.getStoreInfoBusinessHours?id={}", id);
+        return R.data(storePlatformInfoService.getStoreInfoBusinessHours(id));
+    }
+
 }

+ 14 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformInfoService.java

@@ -1,8 +1,12 @@
 package shop.alien.storeplatform.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.store.StoreBusinessInfo;
 import shop.alien.entity.store.StoreInfo;
 import shop.alien.entity.store.dto.StoreInfoDto;
+import shop.alien.entity.store.vo.StoreMainInfoVo;
+
+import java.util.List;
 
 public interface StorePlatformInfoService extends IService<StoreInfo> {
 
@@ -13,4 +17,14 @@ public interface StorePlatformInfoService extends IService<StoreInfo> {
      */
     int saveOrUpdateStoreInfo(StoreInfoDto storeInfo);
 
+    List<StoreBusinessInfo> getStoreInfoBusinessHours(Integer id);
+
+    /**
+     * 门店详情
+     *
+     * @param id 门店id
+     * @return StoreMainInfoVo
+     */
+    StoreMainInfoVo getDetail(Integer id);
+
 }

+ 100 - 4
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformInfoServiceImpl.java

@@ -1,6 +1,8 @@
 package shop.alien.storeplatform.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
@@ -11,14 +13,15 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.dto.StoreInfoDto;
+import shop.alien.entity.store.vo.StoreMainInfoVo;
+import shop.alien.entity.store.vo.StoreMenuVo;
 import shop.alien.mapper.*;
+import shop.alien.storeplatform.config.GaoDeMapUtil;
 import shop.alien.storeplatform.service.NearMeService;
 import shop.alien.storeplatform.service.StorePlatformInfoService;
+import shop.alien.util.common.DistanceUtil;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -41,6 +44,18 @@ public class StorePlatformInfoServiceImpl extends ServiceImpl<StoreInfoMapper, S
 
     private final NearMeService nearMeService;
 
+    private final StoreBusinessInfoMapper storeBusinessInfoMapper;
+
+    private final StoreImgMapper storeImgMapper;
+
+    private final StoreMenuMapper storeMenuMapper;
+
+    private final StoreLabelMapper storeLabelMapper;
+
+    private final StoreUserMapper storeUserMapper;
+
+    private final GaoDeMapUtil gaoDeMapUtil;
+
     @Override
     public int saveOrUpdateStoreInfo(StoreInfoDto storeInfodto) {
         if (storeInfodto.getId() != null) {
@@ -193,4 +208,85 @@ public class StorePlatformInfoServiceImpl extends ServiceImpl<StoreInfoMapper, S
         return Objects.nonNull(cityCode) ? cityCode.getAreaName() : "";
     }
 
+    @Override
+    public List<StoreBusinessInfo> getStoreInfoBusinessHours(Integer id) {
+        //营业时间
+        List<StoreBusinessInfo> storeBusinessInfoList = storeBusinessInfoMapper.selectList(new LambdaQueryWrapper<StoreBusinessInfo>().eq(StoreBusinessInfo::getStoreId, id));
+        return storeBusinessInfoList;
+    }
+
+    /**
+     * 门店详情
+     *
+     * @return StoreMainInfoVo
+     */
+    @Override
+    public StoreMainInfoVo getDetail(Integer id) {
+
+        StoreInfo storeInfo = storeInfoMapper.selectById(id);
+        if(storeInfo == null){
+            return null;
+        }
+        StoreMainInfoVo storeMainInfoVo = storeInfoMapper.getStoreInfo(id);
+
+        //判断门店是否到期
+        if (ObjectUtils.isNotEmpty(storeMainInfoVo.getExpirationTime())) {
+            if (new Date().after(storeMainInfoVo.getExpirationTime())) {
+                storeMainInfoVo.setExpirationFlag(0);
+            }else {
+                storeMainInfoVo.setExpirationFlag(1);
+            }
+        }else {
+            storeMainInfoVo.setExpirationFlag(1);
+        }
+
+        //存入门店地址、
+        storeMainInfoVo.setStoreAddress(storeInfo.getStoreAddress());
+        //入口图
+        LambdaQueryWrapper<StoreImg> inletsUrlQueryWrapper = new LambdaQueryWrapper<>();
+        inletsUrlQueryWrapper.eq(StoreImg::getImgType, 1);
+        inletsUrlQueryWrapper.eq(StoreImg::getStoreId, id);
+        List<StoreImg> inletsUrlList = storeImgMapper.selectList(inletsUrlQueryWrapper);
+        storeMainInfoVo.setInletsUrl(inletsUrlList.stream().sorted(Comparator.comparing(StoreImg::getImgSort)).map(StoreImg::getImgUrl).collect(Collectors.toList()));
+        //相册
+        LambdaQueryWrapper<StoreImg> albumUrlQueryWrapper = new LambdaQueryWrapper<>();
+        albumUrlQueryWrapper.eq(StoreImg::getImgType, 2);
+        albumUrlQueryWrapper.eq(StoreImg::getStoreId, id);
+        List<StoreImg> albumUrlList = storeImgMapper.selectList(albumUrlQueryWrapper);
+        storeMainInfoVo.setAlbumUrl(albumUrlList.stream().sorted(Comparator.comparing(StoreImg::getImgSort)).map(StoreImg::getImgUrl).collect(Collectors.toList()));
+        //推荐菜
+        storeMainInfoVo.setRecommendUrl(storeMenuMapper.getStoreMenuList(id, 1).stream().sorted(Comparator.comparing(StoreMenuVo::getImgSort)).collect(Collectors.toList()));
+        //菜单
+        storeMainInfoVo.setMenuUrl(storeMenuMapper.getStoreMenuList(id, 0).stream().sorted(Comparator.comparing(StoreMenuVo::getImgSort)).collect(Collectors.toList()));
+        //门店标签
+        storeMainInfoVo.setStoreLabel(storeLabelMapper.selectOne(new LambdaQueryWrapper<StoreLabel>().eq(StoreLabel::getStoreId, id)));
+        //营业时间
+        storeMainInfoVo.setStoreBusinessInfo(storeBusinessInfoMapper.selectList(new LambdaQueryWrapper<StoreBusinessInfo>().eq(StoreBusinessInfo::getStoreId, id)));
+        //门店头像
+        LambdaQueryWrapper<StoreImg> eq = new LambdaQueryWrapper<StoreImg>().eq(StoreImg::getImgType, 10).eq(StoreImg::getStoreId, id);
+        StoreImg storeImg = storeImgMapper.selectOne(eq);
+        storeMainInfoVo.setHeadImgUrl(storeImg != null ? storeImg.getImgUrl() : "");
+        List<StoreUser> storeUsers = storeUserMapper.selectList(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()));
+        for (StoreUser storeUser : storeUsers) {
+            storeMainInfoVo.setLogoutFlagUser(storeUser.getLogoutFlag());
+        }
+        // 计算店铺到最近地铁站的距离
+        JSONObject nearbySubway = gaoDeMapUtil.getNearbySubway(storeMainInfoVo.getStorePosition().split(",")[0], storeMainInfoVo.getStorePosition().split(",")[1]);
+        // 地铁名
+        String subWayName = nearbySubway.getString("name");
+        storeMainInfoVo.setSubwayName(subWayName);
+        // 地铁站经纬度
+        String subWayJing = nearbySubway.getString("location") == null ? null : nearbySubway.getString("location").split(",")[0];
+        String subWayWei = nearbySubway.getString("location") == null ? null : nearbySubway.getString("location").split(",")[1];
+        if ((subWayJing != null && !subWayJing.isEmpty()) && (subWayWei != null && !subWayWei.isEmpty())) {
+            double storeJing = Double.parseDouble(storeMainInfoVo.getStorePosition().split(",")[0]);
+            double storeWei = Double.parseDouble(storeMainInfoVo.getStorePosition().split(",")[1]);
+            double storeDistance2 = DistanceUtil.haversineCalculateDistance(Double.parseDouble(subWayJing), Double.parseDouble(subWayWei), storeJing, storeWei);
+            storeMainInfoVo.setDistance2(storeDistance2);
+        } else {
+            storeMainInfoVo.setDistance2(0);
+        }
+        return storeMainInfoVo;
+    }
+
 }