From a1a51a92fd386ff07a7f05e40076508430a3c026 Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期二, 15 十一月 2022 14:30:33 +0800
Subject: [PATCH] #feat 订单、商品、用户地址、评价 接口新增

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java |   55 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java
index 30d72c2..7f0508e 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java
@@ -1,33 +1,33 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.panzhihua.common.model.dtos.community.convenient.ConvenientElevatingPointDTO;
-import com.panzhihua.common.model.dtos.community.convenient.ConvenientMerchantDTO;
 import com.panzhihua.common.model.dtos.community.convenient.PageConvenientElevatingPointDTO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.convenient.ConvenientElevatingPointVO;
-import com.panzhihua.common.utlis.Snowflake;
 import com.panzhihua.service_community.dao.ComActDAO;
 import com.panzhihua.service_community.dao.ConvenientElevatingPointDAO;
+import com.panzhihua.service_community.dao.ConvenientMerchantDAO;
 import com.panzhihua.service_community.model.dos.ComActDO;
 import com.panzhihua.service_community.model.dos.ConvenientElevatingPointDO;
 import com.panzhihua.service_community.model.dos.ConvenientMerchantDO;
-import com.panzhihua.service_community.model.dos.ConvenientServiceCategoryDO;
 import com.panzhihua.service_community.service.ConvenientElevatingPointService;
+import com.panzhihua.service_community.util.MapDistance;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import static java.util.Objects.isNull;
 import static java.util.Objects.nonNull;
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
 
 /**
  * @ClassName: ConvenientElevatingPointServiceImpl
@@ -40,9 +40,12 @@
 public class ConvenientElevatingPointServiceImpl extends ServiceImpl<ConvenientElevatingPointDAO, ConvenientElevatingPointDO> implements ConvenientElevatingPointService {
     @Resource
     private ComActDAO comActDAO;
+    @Resource
+    private ConvenientMerchantDAO convenientMerchantDAO;
 
     /**
      * 分页查询
+     *
      * @param pageConvenientElevatingPointDTO
      * @return
      */
@@ -57,6 +60,7 @@
 
     /**
      * 新增
+     *
      * @param convenientElevatingPointDTO
      * @return
      */
@@ -64,11 +68,11 @@
     @Transactional(rollbackFor = Exception.class)
     public R addPoint(ConvenientElevatingPointDTO convenientElevatingPointDTO) {
         ConvenientElevatingPointDO convenientElevatingPointDO = new ConvenientElevatingPointDO();
-        BeanUtils.copyProperties(convenientElevatingPointDTO,convenientElevatingPointDO);
+        BeanUtils.copyProperties(convenientElevatingPointDTO, convenientElevatingPointDO);
         String communityId = convenientElevatingPointDTO.getCommunityId();
         if (nonNull(communityId)) {
-            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",")+1)));
-            if(comActDO!=null){
+            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",") + 1)));
+            if (comActDO != null) {
                 convenientElevatingPointDO.setCommunityName(comActDO.getName());
             }
         }
@@ -78,6 +82,7 @@
 
     /**
      * 修改
+     *
      * @param convenientElevatingPointDTO
      * @return
      */
@@ -91,8 +96,8 @@
         }
         String communityId = convenientElevatingPointDTO.getCommunityId();
         if (nonNull(communityId)) {
-            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",")+1)));
-            if(comActDO!=null){
+            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",") + 1)));
+            if (comActDO != null) {
                 convenientElevatingPointDO.setCommunityName(comActDO.getName());
             }
         }
@@ -105,7 +110,7 @@
     @Override
     public R deletePoint(Long pointId, Long operator) {
         ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(pointId);
-        if (convenientElevatingPointDO.getPrepareGoodsNum() > 0){
+        if (convenientElevatingPointDO.getPrepareGoodsNum() > 0) {
             return R.fail("该提货点暂时无法删除!若想删除需保证待提货数量为0");
         }
         int result = this.baseMapper.deletePointById(pointId, operator);
@@ -120,4 +125,32 @@
         ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(pointId);
         return R.ok(convenientElevatingPointDO);
     }
+
+    public R findPointByMerchantId(Long merchantId, String lat, String lng) {
+        ConvenientMerchantDO convenientMerchantDO = convenientMerchantDAO.selectById(merchantId);
+        //服务最远距离 km
+        Integer serviceRange = convenientMerchantDO.getServiceRange();
+
+        Map<Object, Object> around = MapDistance.getAround(convenientMerchantDO.getLat(), convenientMerchantDO.getLon(), serviceRange * 1000 + "");
+        String maxLat = around.get("maxLat").toString();
+        String minLat = around.get("minLat").toString();
+        String minLng = around.get("minLng").toString();
+        String maxLng = around.get("maxLng").toString();
+        List<ConvenientElevatingPointDO> convenientElevatingPointDOS = this.baseMapper.selectList(
+                new LambdaQueryWrapper<ConvenientElevatingPointDO>()
+                        .ge(ConvenientElevatingPointDO::getLat, minLng)
+                        .le(ConvenientElevatingPointDO::getLat, maxLng)
+                        .ge(ConvenientElevatingPointDO::getLon, minLat)
+                        .le(ConvenientElevatingPointDO::getLon, maxLat));
+        List<ConvenientElevatingPointVO> convenientElevatingPointVOS = new ArrayList<>();
+        convenientElevatingPointDOS.forEach(f -> {
+            ConvenientElevatingPointVO convenientElevatingPointVO = new ConvenientElevatingPointVO();
+            BeanUtils.copyProperties(f, convenientElevatingPointVO);
+            Double distance = MapDistance.distanceOfTwoPoints(lng, lat, f.getLon(), f.getLat());
+            convenientElevatingPointVO.setDistance(distance);
+            convenientElevatingPointVOS.add(convenientElevatingPointVO);
+        });
+        return R.ok(convenientElevatingPointVOS);
+
+    }
 }

--
Gitblit v1.7.1