Browse Source

no message

FengChaoYu 1 week ago
parent
commit
b580cc3846

+ 37 - 0
src/main/java/com/gree/mall/contest/bean/common/RegionBean.java

@@ -0,0 +1,37 @@
+package com.gree.mall.contest.bean.common;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class RegionBean {
+
+    @Schema(description = "经纬度")
+    private String lnglat;
+
+    @Schema(description = "省id")
+    private String provinceId;
+
+    @Schema(description ="省名称")
+    private String provinceName;
+
+    @Schema(description ="市id")
+    private String cityId;
+
+    @Schema(description = "市名称")
+    private String cityName;
+
+    @Schema(description = "区id")
+    private String areaId;
+
+    @Schema(description = "区名称")
+    private String areaName;
+
+    @Schema(description = "街道id")
+    private String lbsId;
+
+    @Schema(description = "街道名称")
+    private String name;
+
+
+}

+ 11 - 9
src/main/java/com/gree/mall/contest/controller/mini/coupon/MiniCouponController.java

@@ -11,6 +11,7 @@ import com.gree.mall.contest.constant.Constant;
 import com.gree.mall.contest.exception.RemoteServiceException;
 import com.gree.mall.contest.helper.ResponseHelper;
 import com.gree.mall.contest.logic.coupon.CouponLogic;
+import com.gree.mall.contest.logic.user.UserLogic;
 import com.gree.mall.contest.plus.entity.UserCoupon;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -37,6 +38,7 @@ import java.util.concurrent.locks.Lock;
 public class MiniCouponController {
 
     private final CouponLogic couponLogic;
+    private final UserLogic userLogic;
     private final RedisLockRegistry redisLockRegistry;
 
 
@@ -87,7 +89,7 @@ public class MiniCouponController {
             @Parameter(description = "用户id") @RequestParam(required = false) String userId,
             HttpServletRequest request
     ) throws RemoteServiceException {
-        List<CouponObtainBean> coupons = couponLogic.allObtainCoupou(userId,request);
+        List<CouponObtainBean> coupons = couponLogic.allObtainCoupou(userId, request);
         return ResponseHelper.success(coupons);
     }
 
@@ -95,19 +97,19 @@ public class MiniCouponController {
     @GetMapping("/obtain")
     @Operation(summary = "领券")
     public ResponseHelper obtain(HttpServletRequest request,
-            @Parameter(description = "用户id") @RequestParam(required = false) String userId,
-            @Parameter(description = "优惠券id") @RequestParam(required = false) List<String> couponIds
+                                 @Parameter(description = "用户id") @RequestParam(required = false) String userId,
+                                 @Parameter(description = "优惠券id") @RequestParam(required = false) List<String> couponIds
 
     ) throws RemoteServiceException, InterruptedException {
-        for(String couponId : couponIds) {
+        for (String couponId : couponIds) {
             Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COUPON + couponId);
-            if(!obtain.tryLock(10,TimeUnit.SECONDS)){
-                log.error("系统繁忙,领券失败,userId:{},couponId:{}",userId,couponId);
+            if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
+                log.error("系统繁忙,领券失败,userId:{},couponId:{}", userId, couponId);
                 continue;
             }
             try {
                 couponLogic.obtainCoupou(request, userId, couponId);
-            }finally {
+            } finally {
                 obtain.unlock();
             }
         }
@@ -145,10 +147,10 @@ public class MiniCouponController {
 
     @GetMapping("/transfer/coupon")
     @Operation(summary = "转赠优惠券")
-    public ResponseHelper<String> transferCoupon(HttpServletRequest request,@Parameter(description = "id", required = true) @RequestParam String userCouponId)
+    public ResponseHelper<String> transferCoupon(HttpServletRequest request, @Parameter(description = "id", required = true) @RequestParam String userCouponId)
             throws RemoteServiceException {
 
-        return ResponseHelper.success(couponLogic.transferCoupon(request,userCouponId));
+        return ResponseHelper.success(couponLogic.transferCoupon(request, userCouponId, userLogic));
     }
 
 

+ 47 - 0
src/main/java/com/gree/mall/contest/controller/pc/common/LbsAmapController.java

@@ -0,0 +1,47 @@
+package com.gree.mall.contest.controller.pc.common;
+
+import com.gree.mall.contest.bean.common.RegionBean;
+import com.gree.mall.contest.helper.ResponseHelper;
+import com.gree.mall.contest.logic.common.LbsAmapLogic;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequiredArgsConstructor
+@Slf4j
+@RestController
+@Tag(name = "高德地图API", description = "高德地图API")
+@RequestMapping("/pc/lbs/amap")
+public class LbsAmapController {
+
+    private final LbsAmapLogic lbsAmapLogic;
+
+
+    @PostMapping("region/query")
+    @Operation(summary = "根据经纬度反查省市区街道")
+    public ResponseHelper<RegionBean> detailRange(
+            @Parameter(description = "经度", required = true) @RequestParam String lng,
+            @Parameter(description = "纬度", required = true) @RequestParam String lat
+    ) {
+        RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(lng + "," + lat);
+        return ResponseHelper.success(regionBean);
+    }
+
+
+    @PostMapping("region/query2")
+    @Operation(summary = "根据中文地址反查经纬度省市区街道")
+    public ResponseHelper<RegionBean> queryRegion(@Parameter(description = "中文地址(越详细越好)", required = true) @RequestParam String address) {
+        String lnglat = lbsAmapLogic.getLocationByAddress(address);
+        RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(lnglat);
+        return ResponseHelper.success(regionBean);
+    }
+
+
+
+}

+ 100 - 0
src/main/java/com/gree/mall/contest/logic/common/LbsAmapLogic.java

@@ -0,0 +1,100 @@
+package com.gree.mall.contest.logic.common;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.gree.mall.contest.bean.common.RegionBean;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class LbsAmapLogic {
+
+    private static final String lbsWebKey = "428a7111e02ea8367a3b34804eaa025b";
+    /**
+     * 根据经纬度反查省市区街道
+     * @Param lng,lat
+     * @Return {"area":"番禺区","province":"广东省","city":"广州市","street":"大龙街道"}
+     */
+    public RegionBean getRegionByLngLat(String lnglat){
+        log.info("根据经纬度反查省市区街道:" + lnglat);
+        //String lnglat = lng + "," + lat;
+        //String lbsWebKey = "b772f8b0ace6bc96c04ae8e48f241e36";
+        String url = "https://restapi.amap.com/v3/geocode/regeo?key="+lbsWebKey+"&location="+lnglat;
+        String s = HttpUtil.get(url);
+        JSONObject jsonObject = new JSONObject(s);
+        String status = jsonObject.getStr("status");
+        if(!status.equals("1")){
+            return null;
+        }
+        JSONObject regeocode = jsonObject.getJSONObject("regeocode");
+        JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
+        Map<String,String> map = new HashMap<>();
+        map.put("province",addressComponent.getStr("province"));
+        if(addressComponent.getStr("city").equals("[]")) {
+            map.put("city", addressComponent.getStr("province"));
+        }else{
+            map.put("city", addressComponent.getStr("city"));
+        }
+        if(addressComponent.getStr("district").equals("[]")) {
+            map.put("area", addressComponent.getStr("city"));
+        }else{
+            map.put("area", addressComponent.getStr("district"));
+        }
+        map.put("street",addressComponent.getStr("township"));
+        //System.out.print(new JSONObject(map).toString());
+        log.info("根据经纬度反查地址,经纬度:{},反查的地址:{}",lnglat,new JSONObject(addressComponent));
+
+        String street = map.get("street");
+        String province = map.get("province");
+        String city = map.get("city");
+        String area = map.get("area");
+//        LbsAmap lbsAmap = this.getByRegion(province, city, area, street);
+//        if(lbsAmap == null){
+//            return null;
+//        }
+//        RegionBean regionBean = BeanUtil.copyProperties(lbsAmap, RegionBean.class);
+        RegionBean regionBean = new RegionBean();
+        regionBean.setLnglat(lnglat);
+        regionBean.setProvinceName(province);
+        regionBean.setCityName(city);
+        regionBean.setAreaName(area);
+        regionBean.setName(street);
+        return regionBean;
+    }
+
+
+    /**
+     * 根据地址反查经纬度
+     * @Param 中文地址(最好详细)
+     * @return lng,lat
+     */
+    public String getLocationByAddress(String address){
+        //String lbsWebKey = "b772f8b0ace6bc96c04ae8e48f241e36";
+        //String address = "广东省广州市天河区华景新城";
+        String url = "https://restapi.amap.com/v3/geocode/geo?key="+lbsWebKey+"&address="+address;
+        String s = HttpUtil.get(url);
+        JSONObject jsonObject = new JSONObject(s);
+        String status = jsonObject.getStr("status");
+        if(!status.equals("1")){
+            return null;
+        }
+        JSONArray geocodes = jsonObject.getJSONArray("geocodes");
+        if(CollectionUtils.isEmpty(geocodes))
+            return null;
+        Map<String, Object> map = (Map<String, Object>) geocodes.get(0);
+        String location = (String)map.get("location");
+        log.info("根据地址【{}】反查经纬度【{}】",address,new JSONObject(map));
+        return location;
+    }
+
+
+
+}

+ 3 - 4
src/main/java/com/gree/mall/contest/logic/coupon/CouponLogic.java

@@ -60,7 +60,6 @@ public class CouponLogic {
     private final RedisLockRegistry redisLockRegistry;
     private final CustomCoupouMapper customCoupouMapper;
     private final WechatLogic wechatLogic;
-    private final UserLogic userLogic;
     private final CoustomUserCouponMapper coustomUserCouponMapper;
 
     /**
@@ -778,7 +777,7 @@ public class CouponLogic {
     }
 
     @Transactional
-    public String transferCoupon(HttpServletRequest request, String userCouponId) throws RemoteServiceException {
+    public String transferCoupon(HttpServletRequest request, String userCouponId, UserLogic userLogic) throws RemoteServiceException {
         UserCoupon userCoupon = userCouponService.lambdaQuery()
                 .eq(UserCoupon::getId, userCouponId)
                 .eq(UserCoupon::getStatus, false)
@@ -824,7 +823,7 @@ public class CouponLogic {
                 throw new RemoteServiceException("优惠已被用户使用");
             }
 
-            transferCouponId = this.transfer(user.getUserId(), userCouponId, user.getCompanyWechatId(), user.getCompanyName());
+            transferCouponId = this.transfer(user.getUserId(), userCouponId, user.getCompanyWechatId(), user.getCompanyName(), userLogic);
         } catch (InterruptedException e) {
             log.error("", e);
             throw new RemoteServiceException("系统繁忙,请稍后再试");
@@ -834,7 +833,7 @@ public class CouponLogic {
         return transferCouponId;
     }
 
-    protected String transfer(String userId, String userCouponId, String companyWechatId, String companyName) {
+    protected String transfer(String userId, String userCouponId, String companyWechatId, String companyName, UserLogic userLogic) {
         UserCoupon userCoupon = userCouponService.lambdaQuery()
                 .eq(UserCoupon::getId, userCouponId)
                 .eq(UserCoupon::getStatus, false)

+ 7 - 0
src/main/resources/application-dev.properties

@@ -82,4 +82,11 @@ jwt.expire=7200
 knife4j.enable=true
 knife4j.setting.language=zh_cn
 
+#发票API
+tax.token.appid=zfire
+tax.token.appSecret=gsdfbsdtsbfffcxwrtfsdfvvxaggdsa
+tax.token.url=http://121.43.111.127:11111/com/token/get
+tax.invoice.url=http://121.43.111.127:11111/invoice/tax
+tax.invoice.title.url=http://121.43.111.127:11111/invoice/title
+
 

+ 8 - 1
src/main/resources/application-prd.properties

@@ -75,4 +75,11 @@ jwt.secret=zfire@2025_base_code_security_key_123456
 jwt.expire=7200
 
 knife4j.enable=false
-knife4j.setting.language=zh_cn
+knife4j.setting.language=zh_cn
+
+#发票API
+tax.token.appid=zfire
+tax.token.appSecret=gsdfbsdtsbfffcxwrtfsdfvvxaggdsa
+tax.token.url=${gjmall.url}/interface/com/token/get
+tax.invoice.url=${gjmall.url}/interface/invoice/tax
+tax.invoice.title.url=${gjmall.url}/interface/invoice/title

+ 8 - 1
src/main/resources/application-test.properties

@@ -68,4 +68,11 @@ jwt.secret=zfire@2025_base_code_security_key_123456
 jwt.expire=7200
 
 knife4j.enable=true
-knife4j.setting.language=zh_cn
+knife4j.setting.language=zh_cn
+
+#发票API
+tax.token.appid=zfire
+tax.token.appSecret=gsdfbsdtsbfffcxwrtfsdfvvxaggdsa
+tax.token.url=http://121.43.111.127:11111/com/token/get
+tax.invoice.url=http://121.43.111.127:11111/invoice/tax
+tax.invoice.title.url=http://121.43.111.127:11111/invoice/title