dev-discount
袁野 4 years ago
commit 8e1588d3af
  1. 12
      hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java
  2. 12
      hai-cweb/src/main/java/com/cweb/controller/HighUserController.java
  3. 50
      hai-cweb/src/test/common/RegionTest.java
  4. 2
      hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java
  5. 2
      hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java
  6. 93
      hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java
  7. 17
      hai-service/pom.xml
  8. 38
      hai-service/src/main/java/com/hai/common/utils/CoordCommonUtil.java
  9. 77
      hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java
  10. 10
      hai-service/src/main/java/com/hai/entity/HighMerchantStore.java
  11. 4
      hai-service/src/main/java/com/hai/entity/HighUser.java
  12. 20
      hai-service/src/main/java/com/hai/model/UserModel.java
  13. 8
      hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java
  14. 3
      hai-service/src/main/java/com/hai/service/HighUserCouponService.java
  15. 21
      hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java
  16. 11
      hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.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<String,Object> map = new HashMap<>();
map.put("merchantId", coupon.getMerchantId());
map.put("longitude", longitude);
map.put("latitude", latitude);
PageHelper.startPage(pageNum, pageSize);
List<HighMerchantStore> storeList = highMerchantStoreService.getMerchantStoreList(map);
List<HighMerchantStore> 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);

@ -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);

@ -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
@ -76,20 +83,37 @@ public class RegionTest {
public void test(){
try {
Map<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> headerMap = new HashMap<>();
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", JSON.toJSONString(bodyMap), token,sha256 ,date);
//System.out.println(jsonObject.toJSONString());
}
}catch (Exception e){
e.printStackTrace();

@ -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<HighUserCoupon> userCoupons = highUserCouponService.getOverdueCoupon();
for (HighUserCoupon highUserCoupon : userCoupons) {

@ -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<HighOrder> orderList = highOrderService.getCloseOrder();

@ -0,0 +1,93 @@
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<String, Object> 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));
log.error(jsonObject.toJSONString());
if (jsonObject != null && jsonObject.getBoolean("success") == true) {
JSONObject data = jsonObject.getJSONObject("data");
String token = data.getString("token");
Map<String,Object> 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<String,Object> headerMap = new HashMap<>();
headerMap.put("token", token);
headerMap.put("sign", sha256);
headerMap.put("ts", date);
//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());
}
}
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<len;j++){
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
}

@ -281,6 +281,23 @@
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

@ -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左右
/**
* 获得球面地球上两个点之间的距离坐标可以为WGS84GCJ02等任何一种坐标但两个点的坐标类型必须相同
*
* @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; // 最终结果附上原文出处链接及本声明。
}
}

@ -221,6 +221,44 @@ public class HttpsUtils {
return null;
}
public static JSONObject doPost(String apiUrl, Map<String,Object> body, Map<String,Object> 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<String, Object> 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形式
*
@ -265,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安全连接
*

@ -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;
}

@ -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 {
/**
* 用户编号
*/

@ -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;
}
}

@ -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<HighMerchantStore> getMerchantStoreList(Map<String, Object> map);
/**
* @Author 胡锐
* @Description 查询门店列表(计算精度)
* @Date 2021/4/1 20:34
**/
List<HighMerchantStore> getStoreListByLongitude(Map<String, Object> map);
}

@ -55,4 +55,7 @@ public interface HighUserCouponService {
**/
HighUserCoupon getUserCoupon(Long userId, Long couponId);
List<HighUserCoupon> getCouponList(Long userId,Integer status);
}

@ -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<HighMerchantStore> getStoreListByLongitude(Map<String, Object> map) {
List<HighMerchantStore> 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<HighMerchantStore> collect = storeList.stream().sorted(Comparator.comparing(HighMerchantStore::getDistance)).collect(Collectors.toList());
return collect;
}
}

@ -92,4 +92,15 @@ public class HighUserCouponServiceImpl implements HighUserCouponService {
}
return null;
}
@Override
public List<HighUserCoupon> 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);
}
}

Loading…
Cancel
Save