From d9eb0f8c99680c874879c39eaf53cfce178f0c5d Mon Sep 17 00:00:00 2001 From: 199901012 Date: Tue, 30 Mar 2021 23:26:16 +0800 Subject: [PATCH] =?UTF-8?q?'=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bweb/controller/HighCouponController.java | 19 +- .../HighGoodsPriceReferController.java | 2 +- .../cweb/controller/HighCouponController.java | 6 +- .../HighMerchantStoreController.java | 4 +- .../cweb/controller/HighOrderController.java | 2 +- .../cweb/controller/pay/OrderController.java | 4 +- hai-cweb/src/test/common/RegionTest.java | 50 ++- .../com/hai/schedule/HighCouponSchedule.java | 2 +- .../com/hai/schedule/HighOrderSchedule.java | 5 + .../src/main/resources/dev/application.yml | 6 +- .../src/main/resources/dev/config.properties | 5 - .../src/main/resources/prod/application.yml | 10 +- .../src/main/resources/prod/config.properties | 1 - .../java/com/hai/common/utils/HttpUtils.java | 311 ++++++++++++++++++ .../com/hai/common/utils}/HttpsUtils.java | 2 +- .../main/java/com/hai/entity/HighCoupon.java | 6 +- .../java/com/hai/entity/HighUserCoupon.java | 14 +- .../java/com/hai/model/HighCouponModel.java | 2 +- .../com/hai/service/HighCouponService.java | 10 +- .../hai/service/HighUserCouponService.java | 2 +- .../service/impl/HighCouponServiceImpl.java | 37 +-- .../service/impl/HighOrderServiceImpl.java | 2 +- .../impl/HighUserCouponServiceImpl.java | 14 +- 23 files changed, 440 insertions(+), 76 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/common/utils/HttpUtils.java rename {hai-cweb/src/main/java/com/cweb/config => hai-service/src/main/java/com/hai/common/utils}/HttpsUtils.java (99%) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java index f8211039..e1948ff4 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -1,6 +1,7 @@ package com.bweb.controller; import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.bweb.excelListener.ImportCouponListener; import com.bweb.model.ImportCouponModel; @@ -70,7 +71,7 @@ public class HighCouponController { @RequestMapping(value="/insertCoupon",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "增加卡卷") - public ResponseData insertCoupon(@RequestBody HighCouponModel highCoupon, HttpServletRequest request) { + public ResponseData insertCoupon(@RequestBody HighCoupon highCoupon, HttpServletRequest request) { try { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); @@ -153,7 +154,7 @@ public class HighCouponController { @RequestMapping(value="/updateCoupon",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "修改卡卷") - public ResponseData updateCoupon(@RequestBody HighCouponModel highCoupon, HttpServletRequest request) { + public ResponseData updateCoupon(@RequestBody HighCoupon highCoupon, HttpServletRequest request) { try { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); @@ -188,7 +189,7 @@ public class HighCouponController { map.put("couponName", highCoupon.getCouponName()); // 查询卡券 - HighCouponModel coupon = highCouponService.getCouponById(highCoupon.getId()); + HighCoupon coupon = highCouponService.getCouponById(highCoupon.getId()); if (coupon == null) { log.error("HighCouponController -> updateCoupon() error!","未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); @@ -260,7 +261,7 @@ public class HighCouponController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); // 查询卡券 - HighCouponModel coupon = highCouponService.getCouponById(id); + HighCoupon coupon = highCouponService.getCouponById(id); if (coupon == null) { log.error("HighCouponController -> upShelfApprove() error!","未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); @@ -354,15 +355,14 @@ public class HighCouponController { @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { - - Map map = new HashMap<>(); - SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); if (userInfoModel.getBsCompany() == null) { log.error("HighCouponController -> getCouponList() error!","权限不足"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); } + + Map map = new HashMap<>(); map.put("companyId", userInfoModel.getBsCompany().getId()); map.put("merchantId", merchantId); map.put("couponName", couponName); @@ -370,6 +370,7 @@ public class HighCouponController { map.put("displayArea", displayArea); map.put("status", status); + PageHelper.startPage(pageNum, pageSize); return ResponseMsgUtil.success(new PageInfo<>(highCouponService.getCouponList(map))); } catch (Exception e) { @@ -390,7 +391,7 @@ public class HighCouponController { UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); // 查找卡卷 - HighCouponModel coupon = highCouponService.getCouponById(couponId); + HighCoupon coupon = highCouponService.getCouponById(couponId); if (coupon == null) { log.error("HighCouponController -> writeStock() error!","未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); @@ -439,7 +440,7 @@ public class HighCouponController { } // 查找商户 - HighCouponModel coupon = highCouponService.getCouponById(couponId); + HighCoupon coupon = highCouponService.getCouponById(couponId); if (coupon == null) { log.error("HighCouponController -> writeStock() error!","未找到商户"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighGoodsPriceReferController.java b/hai-bweb/src/main/java/com/bweb/controller/HighGoodsPriceReferController.java index d1d66593..ca617c7f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighGoodsPriceReferController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighGoodsPriceReferController.java @@ -101,7 +101,7 @@ public class HighGoodsPriceReferController { // 卡卷 if (addGoodsPriceModel.getObjectType() == 1) { - HighCouponModel coupon = highCouponService.getCouponById(objectId); + HighCoupon coupon = highCouponService.getCouponById(objectId); if (coupon == null) { log.error("HighGoodsPriceReferController -> insertGoodsPriceRefer() error!","未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index 7fa24690..aeed4ba9 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -121,11 +121,7 @@ public class HighCouponController { map.put("status", status); PageHelper.startPage(pageNum, pageSize); - List list = highUserCouponService.getUserCouponList(map); - for (HighUserCouponModel highUserCouponModel : list) { - highUserCouponModel.setHighCouponModel(highCouponService.getCouponById(highUserCouponModel.getCouponId())); - } - return ResponseMsgUtil.success(new PageInfo<>(list)); + return ResponseMsgUtil.success(new PageInfo<>(highUserCouponService.getUserCouponList(map))); } catch (Exception e) { log.error("HighCouponController --> getUserCouponList() error!", e); 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 20594fa5..3210332d 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighMerchantStoreController.java @@ -82,7 +82,7 @@ public class HighMerchantStoreController { @RequestParam(name = "pageSize", required = true) Integer pageSize) { try { - HighCouponModel coupon = highCouponService.getCouponById(couponId); + HighCoupon coupon = highCouponService.getCouponById(couponId); if (coupon == null) { return ResponseMsgUtil.success(new PageInfo<>()); } @@ -93,7 +93,7 @@ public class HighMerchantStoreController { List storeList = highMerchantStoreService.getMerchantStoreList(map); if (storeList != null && storeList.size() > 0) { - HighMerchantModel merchant = highMerchantService.getMerchantById(coupon.getMerchantId()); + HighMerchant merchant = highMerchantService.getMerchantById(coupon.getMerchantId()); for (HighMerchantStore store : storeList) { store.setExt1(merchant.getMerchantLogo()); } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index ca03e504..94ec0467 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -91,7 +91,7 @@ public class HighOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡卷只能购买一张"); } // 查询卡卷信息 - HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); + HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); if (coupon == null) { log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java index 28ee5cc5..0c75b616 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java @@ -110,7 +110,7 @@ public class OrderController { // 商品类型 1:卡卷 2:金币充值 for (HighChildOrder childOrder : order.getHighChildOrderList()) { if (childOrder.getGoodsType() == 1) { - HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); + HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); // 支付类型:1.微信支付 2.金币支付 if (coupon.getPayType() != 1) { log.error("OrderController --> orderToPay() ERROR", "只支持微信支持"); @@ -190,7 +190,7 @@ public class OrderController { // 商品类型 1:卡卷 2:金币充值 for (HighChildOrder childOrder : order.getHighChildOrderList()) { if (childOrder.getGoodsType() == 2) { - HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); + HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); // 支付类型:1.微信支付 2.金币支付 if (coupon.getPayType() != 2) { log.error("OrderController --> orderToPay() ERROR", "只支持金币支持"); diff --git a/hai-cweb/src/test/common/RegionTest.java b/hai-cweb/src/test/common/RegionTest.java index f5d4d80b..5bcf357b 100644 --- a/hai-cweb/src/test/common/RegionTest.java +++ b/hai-cweb/src/test/common/RegionTest.java @@ -3,7 +3,7 @@ package common; import com.CWebApplication; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.cweb.config.HttpsUtils; +import com.hai.common.utils.HttpsUtils; import com.hai.entity.SecRegion; import com.hai.service.CommonService; @@ -16,10 +16,10 @@ import org.springframework.test.context.web.WebAppConfiguration; import javax.annotation.Resource; import java.io.FileOutputStream; import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.*; /** * @ClassName RegionTest @@ -35,6 +35,8 @@ public class RegionTest { @Resource private CommonService commonService; + private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; + @Test public void addLogs(){ try { @@ -77,7 +79,16 @@ public class RegionTest { Map map = new HashMap<>(); map.put("appId", "js3w7K4W0SglB6bNPVjs3w7K4W0SglB6bNPV"); map.put("appSecret", "SoIXquKSKT8s7sa6ySjfyBXxKTC4Jhqx7fiE1qT0XWrrnkScurMGsLdGrz5ThLo5"); - JSONObject jsonObject = HttpsUtils.doPost("http://oilcps.51vip.biz:33013/api-provider/api/open/merchant/token", map); + 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)); System.out.println(jsonObject.toJSONString()); }catch (Exception e){ @@ -85,4 +96,31 @@ public class RegionTest { } } + 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-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java index 387ee4f1..e4c5e52b 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 13830483..18fd3aef 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -1,5 +1,7 @@ package com.hai.schedule; +import com.alibaba.fastjson.JSONObject; +import com.hai.common.utils.HttpsUtils; import com.hai.entity.HighOrder; import com.hai.service.HighOrderService; import org.springframework.context.annotation.Configuration; @@ -7,7 +9,9 @@ import org.springframework.scheduling.annotation.Scheduled; import javax.annotation.Resource; import javax.xml.ws.RespectBinding; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @Auther: 胡锐 @@ -30,4 +34,5 @@ public class HighOrderSchedule { } } } + } diff --git a/hai-schedule/src/main/resources/dev/application.yml b/hai-schedule/src/main/resources/dev/application.yml index 5e945c93..481490a2 100644 --- a/hai-schedule/src/main/resources/dev/application.yml +++ b/hai-schedule/src/main/resources/dev/application.yml @@ -1,10 +1,10 @@ server: - port: 9302 + port: 9303 servlet: - context-path: /brest + context-path: /schedule #配置是否为debug模式,debug模式下,不开启权限校验 -debug: true +debug: false #datasource数据源设置 spring: diff --git a/hai-schedule/src/main/resources/dev/config.properties b/hai-schedule/src/main/resources/dev/config.properties index 669cf7ca..e69de29b 100644 --- a/hai-schedule/src/main/resources/dev/config.properties +++ b/hai-schedule/src/main/resources/dev/config.properties @@ -1,5 +0,0 @@ -wxAppId=wx01898d5209357d68 -wxAppSecret=5c52d0526fcdb425075f6d51381d5c03 - -fileUrl=F:/hurui_probject/filesystem -cmsPath=F:/hurui_probject/filesystem diff --git a/hai-schedule/src/main/resources/prod/application.yml b/hai-schedule/src/main/resources/prod/application.yml index f6b86858..8b5b61a4 100644 --- a/hai-schedule/src/main/resources/prod/application.yml +++ b/hai-schedule/src/main/resources/prod/application.yml @@ -1,7 +1,7 @@ server: - port: 9302 + port: 9303 servlet: - context-path: /crest + context-path: /schedule #配置是否为debug模式,debug模式下,不开启权限校验 debug: false @@ -9,8 +9,8 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://139.159.177.244:3306/hfkj?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 - username: hfkj + url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 + username: root password: HF123456. type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver @@ -51,7 +51,7 @@ spring: mybatis: mapperLocations: - - classpath*:sqlmap*/*.xml + - classpath*:sqlmap*/*.xml type-aliases-package: org.springboot.sample.entity diff --git a/hai-schedule/src/main/resources/prod/config.properties b/hai-schedule/src/main/resources/prod/config.properties index 5034a9fd..e69de29b 100644 --- a/hai-schedule/src/main/resources/prod/config.properties +++ b/hai-schedule/src/main/resources/prod/config.properties @@ -1 +0,0 @@ -fileUrl=/home/filesystem diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpUtils.java new file mode 100644 index 00000000..fe3496e6 --- /dev/null +++ b/hai-service/src/main/java/com/hai/common/utils/HttpUtils.java @@ -0,0 +1,311 @@ +package com.hai.common.utils; + +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HttpUtils { + + /** + * get + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doGet(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpGet request = new HttpGet(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + /** + * post form + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param bodys + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + Map bodys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (bodys != null) { + List nameValuePairList = new ArrayList(); + + for (String key : bodys.keySet()) { + nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); + } + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); + formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); + request.setEntity(formEntity); + } + + return httpClient.execute(request); + } + + /** + * Post String + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Post stream + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Put String + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Put stream + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Delete + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doDelete(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + private static String buildUrl(String host, String path, Map querys) throws UnsupportedEncodingException { + StringBuilder sbUrl = new StringBuilder(); + sbUrl.append(host); + if (!StringUtils.isBlank(path)) { + sbUrl.append(path); + } + if (null != querys) { + StringBuilder sbQuery = new StringBuilder(); + for (Map.Entry query : querys.entrySet()) { + if (0 < sbQuery.length()) { + sbQuery.append("&"); + } + if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { + sbQuery.append(query.getValue()); + } + if (!StringUtils.isBlank(query.getKey())) { + sbQuery.append(query.getKey()); + if (!StringUtils.isBlank(query.getValue())) { + sbQuery.append("="); + sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); + } + } + } + if (0 < sbQuery.length()) { + sbUrl.append("?").append(sbQuery); + } + } + + return sbUrl.toString(); + } + + private static HttpClient wrapClient(String host) { + HttpClient httpClient = new DefaultHttpClient(); + if (host.startsWith("https://")) { + sslClient(httpClient); + } + + return httpClient; + } + + private static void sslClient(HttpClient httpClient) { + try { + SSLContext ctx = SSLContext.getInstance("TLS"); + X509TrustManager tm = new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted(X509Certificate[] xcs, String str) { + + } + public void checkServerTrusted(X509Certificate[] xcs, String str) { + + } + }; + ctx.init(null, new TrustManager[] { tm }, null); + SSLSocketFactory ssf = new SSLSocketFactory(ctx); + ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + ClientConnectionManager ccm = httpClient.getConnectionManager(); + SchemeRegistry registry = ccm.getSchemeRegistry(); + registry.register(new Scheme("https", 443, ssf)); + } catch (KeyManagementException ex) { + throw new RuntimeException(ex); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/hai-cweb/src/main/java/com/cweb/config/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java similarity index 99% rename from hai-cweb/src/main/java/com/cweb/config/HttpsUtils.java rename to hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index 649429a6..89e0861e 100644 --- a/hai-cweb/src/main/java/com/cweb/config/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -1,4 +1,4 @@ -package com.cweb.config; +package com.hai.common.utils; import com.alibaba.fastjson.JSON; diff --git a/hai-service/src/main/java/com/hai/entity/HighCoupon.java b/hai-service/src/main/java/com/hai/entity/HighCoupon.java index e357c6fc..ba9bd52d 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCoupon.java +++ b/hai-service/src/main/java/com/hai/entity/HighCoupon.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighCouponModel; + import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; @@ -13,7 +15,7 @@ import java.util.Date; * 代码由工具生成 * **/ -public class HighCoupon implements Serializable { +public class HighCoupon extends HighCouponModel implements Serializable { /** * 主键 */ @@ -486,4 +488,4 @@ public class HighCoupon implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java b/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java index 0ddca157..07f8bd08 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighCouponModel; + import java.io.Serializable; import java.util.Date; @@ -61,6 +63,16 @@ public class HighUserCoupon implements Serializable { private String ext4; + private HighCouponModel highCouponModel; + + public HighCouponModel getHighCouponModel() { + return highCouponModel; + } + + public void setHighCouponModel(HighCouponModel highCouponModel) { + this.highCouponModel = highCouponModel; + } + private static final long serialVersionUID = 1L; public Long getId() { @@ -226,4 +238,4 @@ public class HighUserCoupon implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/model/HighCouponModel.java b/hai-service/src/main/java/com/hai/model/HighCouponModel.java index f252a423..1d513eb3 100644 --- a/hai-service/src/main/java/com/hai/model/HighCouponModel.java +++ b/hai-service/src/main/java/com/hai/model/HighCouponModel.java @@ -10,7 +10,7 @@ import java.util.List; * @Description: 卡卷模型 * @Date: 2021/3/11 22:27 */ -public class HighCouponModel extends HighCoupon { +public class HighCouponModel { // 商户名称 private String merchantName; diff --git a/hai-service/src/main/java/com/hai/service/HighCouponService.java b/hai-service/src/main/java/com/hai/service/HighCouponService.java index 95753075..27f6168b 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponService.java @@ -20,14 +20,14 @@ public interface HighCouponService { * @Description 增加卡卷业务 * @Date 2021/3/11 22:05 **/ - void insertCoupon(HighCouponModel highCouponModel); + void insertCoupon(HighCoupon highCouponModel); /** * @Author 胡锐 * @Description 修改卡卷业务 * @Date 2021/3/12 20:41 **/ - void updateCoupon(HighCouponModel highCouponModel); + void updateCoupon(HighCoupon highCouponModel); /** * @Author 胡锐 @@ -80,7 +80,7 @@ public interface HighCouponService { * @Description 根据id查询卡卷基本信息、赠送信息 * @Date 2021/3/14 16:58 **/ - HighCouponModel getCouponById(Long id); + HighCoupon getCouponById(Long id); /** * @@ -91,14 +91,14 @@ public interface HighCouponService { * @Param [id] * @return com.hai.model.HighCouponModel **/ - HighCouponModel getCouponDetail(Long id); + HighCoupon getCouponDetail(Long id); /** * @Author 胡锐 * @Description 获取卡卷集合 * @Date 2021/3/15 23:12 **/ - List getCouponList(Map map); + List getCouponList(Map map); /** * @Author 胡锐 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 e890f887..31605772 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java @@ -46,7 +46,7 @@ public interface HighUserCouponService { * @Description 查询用户列表 * @Date 2021/3/27 17:21 **/ - List getUserCouponList(Map map); + List getUserCouponList(Map map); /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java index a9c2d0af..960c2543 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java @@ -51,7 +51,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) - public void insertCoupon(HighCouponModel highCouponModel) { + public void insertCoupon(HighCoupon highCouponModel) { highCouponMapper.insert(highCouponModel); // 增加赠送卡卷 @@ -96,7 +96,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) - public void updateCoupon(HighCouponModel highCouponModel) { + public void updateCoupon(HighCoupon highCouponModel) { highCouponMapper.updateByPrimaryKey(highCouponModel); // 赠送卡卷 @@ -114,7 +114,7 @@ public class HighCouponServiceImpl implements HighCouponService { } } - HighCouponModel coupon = getCouponById(highCouponModel.getId()); + HighCoupon coupon = getCouponById(highCouponModel.getId()); // 如果卡卷销售价格进行了修改 if (!coupon.getSalesPrice().equals(highCouponModel.getSalesPrice())) { @@ -167,7 +167,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Transactional(propagation= Propagation.REQUIRES_NEW) public void upShelfApprove(Long id) { // 查询卡卷 - HighCouponModel coupon = getCouponById(id); + HighCoupon coupon = getCouponById(id); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } @@ -180,7 +180,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Transactional(propagation= Propagation.REQUIRES_NEW) public void upShelfApproveResult(HighApprove highApprove) { // 查询卡卷 - HighCouponModel couponDetail = getCouponDetail(highApprove.getObjectId()); + HighCoupon couponDetail = getCouponDetail(highApprove.getObjectId()); if (couponDetail == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } @@ -215,7 +215,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void ofShelfCoupon(Long id) { - HighCouponModel coupon = getCouponById(id); + HighCoupon coupon = getCouponById(id); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } @@ -232,7 +232,7 @@ public class HighCouponServiceImpl implements HighCouponService { @Override public void deleteCoupon(Long id) { - HighCouponModel coupon = getCouponById(id); + HighCoupon coupon = getCouponById(id); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } @@ -256,7 +256,7 @@ public class HighCouponServiceImpl implements HighCouponService { throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); } // 卡卷信息 - HighCouponModel coupon = getCouponById(highGoodsPriceRefer.getObjectId()); + HighCoupon coupon = getCouponById(highGoodsPriceRefer.getObjectId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } @@ -278,12 +278,12 @@ public class HighCouponServiceImpl implements HighCouponService { } @Override - public HighCouponModel getCouponById(Long id) { + public HighCoupon getCouponById(Long id) { HighCoupon highCoupon = highCouponMapper.selectByPrimaryKey(id); if (highCoupon == null) { return null; } - HighCouponModel model = new HighCouponModel(); + HighCoupon model = new HighCoupon(); BeanUtils.copyProperties(highCoupon, model); // 查询有效库存 model.setStockCount(highCouponCodeService.getStockCountByCoupon(highCoupon.getId())); @@ -305,12 +305,12 @@ public class HighCouponServiceImpl implements HighCouponService { } @Override - public HighCouponModel getCouponDetail(Long id) { + public HighCoupon getCouponDetail(Long id) { HighCoupon highCoupon = highCouponMapper.selectByPrimaryKey(id); if (highCoupon == null) { return null; } - HighCouponModel model = new HighCouponModel(); + HighCoupon model = new HighCoupon(); BeanUtils.copyProperties(highCoupon, model); // 查询有效库存 model.setSalesCount(highCouponCodeService.getStockCountByCoupon(highCoupon.getId())); @@ -318,7 +318,7 @@ public class HighCouponServiceImpl implements HighCouponService { } @Override - public List getCouponList(Map map) { + public List getCouponList(Map map) { HighCouponExample example = new HighCouponExample(); HighCouponExample.Criteria criteria = example.createCriteria(); @@ -346,16 +346,15 @@ public class HighCouponServiceImpl implements HighCouponService { criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); } + example.setOrderByClause("create_time desc"); List coupons = highCouponMapper.selectByExample(example); if (coupons != null && coupons.size() > 0) { - List models = JSON.parseArray(JSON.toJSONString(coupons), HighCouponModel.class); - for (HighCouponModel highCouponModel : models) { - highCouponModel.setMerchantName(highMerchantService.getMerchantById(highCouponModel.getMerchantId()).getMerchantName()); - highCouponModel.setStockCount(highCouponCodeService.getStockCountByCoupon(highCouponModel.getId())); + for (HighCoupon highCoupon : coupons) { + highCoupon.setMerchantName(highMerchantService.getMerchantById(highCoupon.getMerchantId()).getMerchantName()); + highCoupon.setStockCount(highCouponCodeService.getStockCountByCoupon(highCoupon.getId())); } - return models; } - return new ArrayList<>(); + return coupons; } @Override diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 8a9944e0..33dd2708 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -86,7 +86,7 @@ public class HighOrderServiceImpl implements HighOrderService { if (handselListByCoupon != null && handselListByCoupon.size() > 0) { for (HighCouponHandsel highCouponHandsel : handselListByCoupon) { // 查询卡卷信息 - HighCouponModel coupon = highCouponService.getCouponById(highCouponHandsel.getHandselCouponId()); + HighCoupon coupon = highCouponService.getCouponById(highCouponHandsel.getHandselCouponId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } 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 18f09549..a93781dc 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 @@ -5,6 +5,7 @@ import com.hai.dao.HighUserCouponMapper; import com.hai.entity.HighUserCoupon; import com.hai.entity.HighUserCouponExample; import com.hai.model.HighUserCouponModel; +import com.hai.service.HighCouponService; import com.hai.service.HighUserCouponService; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; @@ -26,6 +27,9 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { @Resource private HighUserCouponMapper highUserCouponMapper; + @Resource + private HighCouponService highCouponService; + @Override public void insertUserCoupon(HighUserCoupon highUserCoupon) { highUserCouponMapper.insert(highUserCoupon); @@ -56,7 +60,7 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { } @Override - public List getUserCouponList(Map map) { + public List getUserCouponList(Map map) { HighUserCouponExample example = new HighUserCouponExample(); HighUserCouponExample.Criteria criteria = example.createCriteria(); @@ -70,10 +74,12 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { example.setOrderByClause("create_time desc"); List highUserCoupons = highUserCouponMapper.selectByExample(example); - if (highUserCoupons != null && highUserCoupons.size() > 0) { - return JSON.parseArray(JSON.toJSONString(highUserCoupons), HighUserCouponModel.class); + if (highUserCoupons.size() > 0) { + for (HighUserCoupon highUserCoupon : highUserCoupons) { + highUserCoupon.setHighCouponModel(highCouponService.getCouponById(highUserCoupon.getCouponId())); + } } - return new ArrayList<>(); + return highUserCoupons; } @Override