From 17e6f9cfcf1ead7896750cd3ff4679ac28c16f1e Mon Sep 17 00:00:00 2001 From: 199901012 Date: Thu, 1 Apr 2021 00:17:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?'=E6=8F=90=E4=BA=A4diam'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hai-cweb/src/test/common/RegionTest.java | 43 ++++++--- .../com/hai/schedule/SynchronizeCNPC.java | 91 +++++++++++++++++++ .../java/com/hai/common/utils/HttpsUtils.java | 38 ++++++++ 3 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java diff --git a/hai-cweb/src/test/common/RegionTest.java b/hai-cweb/src/test/common/RegionTest.java index 5bcf357b..e24a80f0 100644 --- a/hai-cweb/src/test/common/RegionTest.java +++ b/hai-cweb/src/test/common/RegionTest.java @@ -76,20 +76,37 @@ public class RegionTest { public void test(){ try { - Map map = new HashMap<>(); - map.put("appId", "js3w7K4W0SglB6bNPVjs3w7K4W0SglB6bNPV"); - map.put("appSecret", "SoIXquKSKT8s7sa6ySjfyBXxKTC4Jhqx7fiE1qT0XWrrnkScurMGsLdGrz5ThLo5"); - Long date = new Date().getTime(); - String signature = "mUGcV7CxPYRuzIWXd72bVknKYCXuT7d1tRxQUdVR9iAcxxTdmWC8lTo0rL5wDZwLmTwQnpCqeHz3MtAIVBrm99WmtPv93pRdgWcIkkgPt18pAFyavYrPt80Yh8iyFr8s"; - String sha256 = encodeBySHA256(signature + JSON.toJSONString(map) + date); - - - Map map2 = new HashMap<>(); - map2.put("signature", signature); - map2.put("body", JSON.toJSONString(map)); - map2.put("ts", date); - JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(map2)); + Map tokenMap = new HashMap<>(); + tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); + tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4"); + JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); System.out.println(jsonObject.toJSONString()); + if(jsonObject != null && jsonObject.getBoolean("success") == true) { + JSONObject data = jsonObject.getJSONObject("data"); + String token = data.getString("token"); + + Map bodyMap = new HashMap<>(); + bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA"); + bodyMap.put("pageNo", 1); + bodyMap.put("pageSize", 10); + bodyMap.put("startTime", "2021-3-31 00:00:00"); + bodyMap.put("endTime", "2021-3-31 23:00:00"); + bodyMap.put("customerCode", "48464274"); + + String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK"; + + Long date = new Date().getTime(); + String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date); + + Map headerMap = new HashMap<>(); + headerMap.put("sign", sha256); + headerMap.put("token", token); + headerMap.put("ts", date); + //map2.put("sign", sha256); + HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap); + //System.out.println(jsonObject.toJSONString()); + } + }catch (Exception e){ e.printStackTrace(); diff --git a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java new file mode 100644 index 00000000..2ddd87e9 --- /dev/null +++ b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java @@ -0,0 +1,91 @@ +package com.hai.schedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hai.common.utils.HttpsUtils; +import com.hai.entity.HighOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: 同步中石化接口 + * @Date: 2021/3/31 23:49 + */ +@Configuration +public class SynchronizeCNPC { + + private static Logger log = LoggerFactory.getLogger(SynchronizeCNPC.class); + + private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; + + @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + public void certification() { + Map tokenMap = new HashMap<>(); + tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); + tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4"); + JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); + System.out.println(jsonObject.toJSONString()); + if (jsonObject != null && jsonObject.getBoolean("success") == true) { + JSONObject data = jsonObject.getJSONObject("data"); + String token = data.getString("token"); + + Map bodyMap = new HashMap<>(); + bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA"); + bodyMap.put("pageNo", 1); + bodyMap.put("pageSize", 10); + bodyMap.put("startTime", "2021-3-31 00:00:00"); + bodyMap.put("endTime", "2021-3-31 23:00:00"); + bodyMap.put("customerCode", "48464274"); + + String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK"; + + Long date = new Date().getTime(); + String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date); + + Map headerMap = new HashMap<>(); + headerMap.put("sign", sha256); + headerMap.put("token", token); + headerMap.put("ts", date); + log.info(HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap).toJSONString()); + } + } + + public String encodeBySHA256(String str) { + try{ + MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); + messageDigest.reset(); + messageDigest.update(str.getBytes("UTF-8")); + return getFormattedText(messageDigest.digest()); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (Exception e) { + throw new RuntimeException(e); + } + return ""; + } + + private String getFormattedText(byte[] bytes) { + int len = bytes.length; + StringBuilder buf = new StringBuilder(len * 2); + // 把密文转换成十六进制的字符串形式 + for (int j=0;j> 4) & 0x0f]); + buf.append(HEX_DIGITS[bytes[j] & 0x0f]); + } + return buf.toString(); + } + +} diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index 89e0861e..8c442de3 100644 --- a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -221,6 +221,44 @@ public class HttpsUtils { return null; } + public static JSONObject doPost(String apiUrl, Map body, Map header) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + for (Map.Entry entry : header.entrySet()) { + httpPost.setHeader(entry.getKey(), entry.getValue().toString()); + } + StringEntity stringEntity = new StringEntity(JSON.toJSONString(body), "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/json"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } /** * 发送 POST 请求,JSON形式 * From ada630b7cbe1d04348394625b033aef94393eb24 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Thu, 1 Apr 2021 17:48:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?'=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hai-cweb/src/test/common/RegionTest.java | 4 +- .../com/hai/schedule/HighCouponSchedule.java | 2 +- .../com/hai/schedule/HighOrderSchedule.java | 2 +- .../com/hai/schedule/SynchronizeCNPC.java | 14 ++++--- .../java/com/hai/common/utils/HttpsUtils.java | 39 +++++++++++++++++++ 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/hai-cweb/src/test/common/RegionTest.java b/hai-cweb/src/test/common/RegionTest.java index e24a80f0..2627d97a 100644 --- a/hai-cweb/src/test/common/RegionTest.java +++ b/hai-cweb/src/test/common/RegionTest.java @@ -99,11 +99,11 @@ public class RegionTest { String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date); Map headerMap = new HashMap<>(); - headerMap.put("sign", sha256); headerMap.put("token", token); + headerMap.put("sign", sha256); headerMap.put("ts", date); //map2.put("sign", sha256); - HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap); + HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token,sha256 ,date); //System.out.println(jsonObject.toJSONString()); } diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java index 387ee4f1..70e689d0 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java @@ -20,7 +20,7 @@ public class HighCouponSchedule { private HighUserCouponService highUserCouponService; // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 - @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 + // @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 public void certification() { List userCoupons = highUserCouponService.getOverdueCoupon(); for (HighUserCoupon highUserCoupon : userCoupons) { diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java index 18fd3aef..9f38b305 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -24,7 +24,7 @@ public class HighOrderSchedule { @Resource private HighOrderService highOrderService; - @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 public void certification() { List orderList = highOrderService.getCloseOrder(); diff --git a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java index 2ddd87e9..48bbac9f 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java +++ b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java @@ -35,12 +35,12 @@ public class SynchronizeCNPC { tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4"); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); - System.out.println(jsonObject.toJSONString()); + log.error(jsonObject.toJSONString()); if (jsonObject != null && jsonObject.getBoolean("success") == true) { JSONObject data = jsonObject.getJSONObject("data"); String token = data.getString("token"); - Map bodyMap = new HashMap<>(); + Map bodyMap = new HashMap<>(); bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA"); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 10); @@ -50,14 +50,16 @@ public class SynchronizeCNPC { String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK"; - Long date = new Date().getTime(); + Long date = new Date().getTime(); String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date); - Map headerMap = new HashMap<>(); - headerMap.put("sign", sha256); + Map headerMap = new HashMap<>(); headerMap.put("token", token); + headerMap.put("sign", sha256); headerMap.put("ts", date); - log.info(HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap).toJSONString()); + //map2.put("sign", sha256); + JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); + log.error(object.toJSONString()); } } diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index 8c442de3..a9cd8910 100644 --- a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -303,6 +303,45 @@ public class HttpsUtils { return null; } + public static JSONObject doPost(String apiUrl, String str, String token, String sign, Long ts) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + httpPost.setHeader("token", token); + httpPost.setHeader("sign", sign); + httpPost.setHeader("ts", ts.toString()); + StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/json"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } + /** * 创建SSL安全连接 * From a28cbf77be4c4b53958aa672de7af2f71513fb14 Mon Sep 17 00:00:00 2001 From: 199901012 Date: Thu, 1 Apr 2021 23:39:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?'=E5=A2=9E=E5=8A=A0=E8=B7=9D=E7=A6=BB?= =?UTF-8?q?=E6=8E=92=E5=BA=8F'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HighMerchantStoreController.java | 12 +++--- .../cweb/controller/HighUserController.java | 12 +++++- hai-cweb/src/test/common/RegionTest.java | 7 ++++ hai-service/pom.xml | 17 +++++++++ .../com/hai/common/utils/CoordCommonUtil.java | 38 +++++++++++++++++++ .../com/hai/entity/HighMerchantStore.java | 12 +++++- .../main/java/com/hai/entity/HighUser.java | 6 ++- .../main/java/com/hai/model/UserModel.java | 20 ++++++++++ .../hai/service/HighMerchantStoreService.java | 8 ++++ .../hai/service/HighUserCouponService.java | 3 ++ .../impl/HighMerchantStoreServiceImpl.java | 21 ++++++++++ .../impl/HighUserCouponServiceImpl.java | 11 ++++++ 12 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/common/utils/CoordCommonUtil.java create mode 100644 hai-service/src/main/java/com/hai/model/UserModel.java diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java b/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java index 3210332d..52610f70 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java @@ -78,8 +78,8 @@ public class HighMerchantStoreController { @ResponseBody @ApiOperation(value = "根据卡卷查询门店列表") public ResponseData getStoreListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId, - @RequestParam(name = "pageNum", required = true) Integer pageNum, - @RequestParam(name = "pageSize", required = true) Integer pageSize) { + @RequestParam(name = "longitude", required = true) String longitude, + @RequestParam(name = "latitude", required = true) String latitude) { try { HighCoupon coupon = highCouponService.getCouponById(couponId); @@ -88,17 +88,17 @@ public class HighMerchantStoreController { } Map map = new HashMap<>(); map.put("merchantId", coupon.getMerchantId()); + map.put("longitude", longitude); + map.put("latitude", latitude); - PageHelper.startPage(pageNum, pageSize); - List storeList = highMerchantStoreService.getMerchantStoreList(map); - + List storeList = highMerchantStoreService.getStoreListByLongitude(map); if (storeList != null && storeList.size() > 0) { HighMerchant merchant = highMerchantService.getMerchantById(coupon.getMerchantId()); for (HighMerchantStore store : storeList) { store.setExt1(merchant.getMerchantLogo()); } } - return ResponseMsgUtil.success(new PageInfo<>(storeList)); + return ResponseMsgUtil.success(storeList); } catch (Exception e) { log.error("HighMerchantStoreController -> getStoreListByCoupon() error!",e); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java index dfa29ed5..ed4fcb9b 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java @@ -3,8 +3,11 @@ package com.cweb.controller; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighUser; +import com.hai.entity.HighUserCoupon; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; +import com.hai.service.HighUserCouponService; import com.hai.service.HighUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -37,6 +40,9 @@ public class HighUserController { @Resource private HighUserService highUserService; + @Resource + private HighUserCouponService highUserCouponService; + @RequestMapping(value = "/findUser", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据id查询详情") @@ -47,7 +53,11 @@ public class HighUserController { SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - return ResponseMsgUtil.success(highUserService.findByUserId(userInfoModel.getHighUser().getId())); + HighUser highUser = highUserService.findByUserId(userInfoModel.getHighUser().getId()); + if (highUser != null) { + highUser.setUnusedCouponNum( highUserCouponService.getCouponList(highUser.getId(), 1).size()); //未使用卡卷数量 + } + return ResponseMsgUtil.success(highUser); } catch (Exception e) { log.error("HighUserController --> findByUserId() error!", e); diff --git a/hai-cweb/src/test/common/RegionTest.java b/hai-cweb/src/test/common/RegionTest.java index 2627d97a..e13b25ef 100644 --- a/hai-cweb/src/test/common/RegionTest.java +++ b/hai-cweb/src/test/common/RegionTest.java @@ -3,10 +3,13 @@ package common; import com.CWebApplication; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageInfo; import com.hai.common.utils.HttpsUtils; +import com.hai.entity.HighMerchantStore; import com.hai.entity.SecRegion; import com.hai.service.CommonService; +import com.hai.service.HighMerchantStoreService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -35,6 +38,10 @@ public class RegionTest { @Resource private CommonService commonService; + @Resource + private HighMerchantStoreService highMerchantStoreService; + + private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; @Test diff --git a/hai-service/pom.xml b/hai-service/pom.xml index 2094d06a..b4de946e 100644 --- a/hai-service/pom.xml +++ b/hai-service/pom.xml @@ -281,6 +281,23 @@ easyexcel 2.2.6 + + org.gavaghan + geodesy + 1.1.3 + + + org.gavaghan + geodesy + 1.1.3 + compile + + + org.gavaghan + geodesy + 1.1.3 + compile + diff --git a/hai-service/src/main/java/com/hai/common/utils/CoordCommonUtil.java b/hai-service/src/main/java/com/hai/common/utils/CoordCommonUtil.java new file mode 100644 index 00000000..4e59b16e --- /dev/null +++ b/hai-service/src/main/java/com/hai/common/utils/CoordCommonUtil.java @@ -0,0 +1,38 @@ +package com.hai.common.utils; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/1 20:32 + */ +public class CoordCommonUtil { + + + private static final double EARTH_RADIUS = 6371000; // 平均半径,单位:m;不是赤道半径。赤道为6378左右 + + /** + * 获得球面(地球)上两个点之间的距离(坐标可以为WGS84、GCJ02等任何一种坐标,但两个点的坐标类型必须相同) + * + * @param lon1 起点的经度 + * @param lat1 起点的纬度 + * @param lon2 终点的经度 + * @param lat2 终点的纬度 + * @return 两点之间的距离,单位是米 + */ + public static double getDistance(Double lat1,Double lng1,Double lat2,Double lng2) { + // 经纬度(角度)转弧度。弧度用作参数,以调用Math.cos和Math.sin + double radiansAX = Math.toRadians(lng1); // A经弧度 + double radiansAY = Math.toRadians(lat1); // A纬弧度 + double radiansBX = Math.toRadians(lng2); // B经弧度 + double radiansBY = Math.toRadians(lat2); // B纬弧度 + + // 公式中“cosβ1cosβ2cos(α1-α2)+sinβ1sinβ2”的部分,得到∠AOB的cos值 + double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX) + + Math.sin(radiansAY) * Math.sin(radiansBY); +// System.out.println("cos = " + cos); // 值域[-1,1] + double acos = Math.acos(cos); // 反余弦值 +// System.out.println("acos = " + acos); // 值域[0,π] +// System.out.println("∠AOB = " + Math.toDegrees(acos)); // 球心角 值域[0,180] + return EARTH_RADIUS * acos; // 最终结果附上原文出处链接及本声明。 + } +} diff --git a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java index 658752ff..b4519948 100644 --- a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java +++ b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java @@ -104,8 +104,18 @@ public class HighMerchantStore implements Serializable { private String ext3; + private String distance; + private static final long serialVersionUID = 1L; + public String getDistance() { + return distance; + } + + public void setDistance(String distance) { + this.distance = distance; + } + public Long getId() { return id; } @@ -357,4 +367,4 @@ public class HighMerchantStore implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/HighUser.java b/hai-service/src/main/java/com/hai/entity/HighUser.java index 652345c4..6a8c6916 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUser.java +++ b/hai-service/src/main/java/com/hai/entity/HighUser.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.UserModel; + import java.io.Serializable; import java.util.Date; @@ -12,7 +14,7 @@ import java.util.Date; * 代码由工具生成 * **/ -public class HighUser implements Serializable { +public class HighUser extends UserModel implements Serializable { /** * 用户编号 */ @@ -271,4 +273,4 @@ public class HighUser implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/model/UserModel.java b/hai-service/src/main/java/com/hai/model/UserModel.java new file mode 100644 index 00000000..e24e3aea --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/UserModel.java @@ -0,0 +1,20 @@ +package com.hai.model; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/1 23:37 + */ +public class UserModel { + + // 未使用卡卷数量 + private Integer unusedCouponNum; + + public Integer getUnusedCouponNum() { + return unusedCouponNum; + } + + public void setUnusedCouponNum(Integer unusedCouponNum) { + this.unusedCouponNum = unusedCouponNum; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java index 5d542d25..ae0a1afa 100644 --- a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java +++ b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java @@ -1,5 +1,6 @@ package com.hai.service; +import com.github.pagehelper.PageInfo; import com.hai.entity.HighMerchantStore; import com.hai.model.HighMerchantStoreModel; @@ -55,4 +56,11 @@ public interface HighMerchantStoreService { **/ List getMerchantStoreList(Map map); + /** + * @Author 胡锐 + * @Description 查询门店列表(计算精度) + * @Date 2021/4/1 20:34 + **/ + List getStoreListByLongitude(Map map); + } diff --git a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java index 31605772..875cce2c 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java @@ -55,4 +55,7 @@ public interface HighUserCouponService { **/ HighUserCoupon getUserCoupon(Long userId, Long couponId); + + List getCouponList(Long userId,Integer status); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java index fcfca6ed..e5f66a64 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java @@ -1,9 +1,12 @@ package com.hai.service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.CoordCommonUtil; import com.hai.common.utils.MD5Util; import com.hai.dao.HighMerchantStoreMapper; import com.hai.entity.HighMerchantStore; @@ -14,15 +17,20 @@ import com.hai.service.HighMerchantStoreService; import com.hai.service.SecUserService; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.gavaghan.geodesy.GeodeticCalculator; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + +import static com.hai.common.utils.CoordCommonUtil.getDistance; @Service("highMerchantStoreService") public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { @@ -151,4 +159,17 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { example.setOrderByClause("create_time desc"); return highMerchantStoreMapper.selectByExample(example); } + + @Override + public List getStoreListByLongitude(Map map) { + List storeList = getMerchantStoreList(map); + for (HighMerchantStore store : storeList) { + double distance = CoordCommonUtil.getDistance(Double.valueOf(store.getLatitude()), Double.valueOf(store.getLongitude()), Double.valueOf(map.get("latitude").toString()), Double.valueOf(map.get("longitude").toString())); + store.setDistance(String.valueOf( Math.round(distance/100d)/10d)); + } + List collect = storeList.stream().sorted(Comparator.comparing(HighMerchantStore::getDistance)).collect(Collectors.toList()); + return collect; + } + + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java index a93781dc..76bc660e 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java @@ -92,4 +92,15 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { } return null; } + + @Override + public List getCouponList(Long userId, Integer status) { + HighUserCouponExample example = new HighUserCouponExample(); + HighUserCouponExample.Criteria criteria = example.createCriteria().andUserIdEqualTo(userId); + if (status != null) { + criteria.andStatusEqualTo(status); + } + example.setOrderByClause("create_time desc"); + return highUserCouponMapper.selectByExample(example); + } }