From 0dabc01b9ab4412b8da51ded0be3fc60ed794863 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Tue, 5 Jul 2022 10:14:03 +0800 Subject: [PATCH 01/13] =?UTF-8?q?api=E9=9C=80=E6=B1=82=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/dev/commonConfig.properties | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index a6b8996f..310670ba 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -66,9 +66,13 @@ JjAppSecret = xkf9eoq2cjh6uvzp0mtrga134lnibdw8 #LY LyNotifyUrl = https://hsgcs.dctpay.com/crest/czOrder/rechargeCallbackByLy -LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU -LyMemberId=18665 -LyPostUrl=https://cz.31994.cn/yrapi.php/ +#LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU +#LyMemberId=18665 +#LyPostUrl=https://cz.31994.cn/yrapi.php/ + +LyApiKey=UzMxo9SIL1tmFvWTwys7pQRGJqO3EChK +LyMemberId=11236 +LyPostUrl=http://cz.zt10010.com/yrapi.php/ unionAppId=7113783e75354df2a985efd3f31b9528 unionSecret=e2c731d2a026469aa6d218432f361653 From 541356d49ff8b23c796c7ac886466ba459d98076 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Tue, 5 Jul 2022 10:14:57 +0800 Subject: [PATCH 02/13] =?UTF-8?q?api=E9=9C=80=E6=B1=82=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/prod-9401/commonConfig.properties | 9 ++++++--- .../src/main/resources/prod/commonConfig.properties | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hai-service/src/main/resources/prod-9401/commonConfig.properties b/hai-service/src/main/resources/prod-9401/commonConfig.properties index 02f247fb..24f761e6 100644 --- a/hai-service/src/main/resources/prod-9401/commonConfig.properties +++ b/hai-service/src/main/resources/prod-9401/commonConfig.properties @@ -56,9 +56,12 @@ JjAppSecret = bf57pnqy8mkexr0v169c3g4odazwu2ij #LY LyNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByLy -LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU -LyMemberId=18665 -LyPostUrl=https://cz.31994.cn/yrapi.php/ +#LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU +#LyMemberId=18665 +#LyPostUrl=https://cz.31994.cn/yrapi.php/ +LyApiKey=UzMxo9SIL1tmFvWTwys7pQRGJqO3EChK +LyMemberId=11236 +LyPostUrl=http://cz.zt10010.com/yrapi.php/ unionAppId=ced46392acfe42be863fdfdd3e61164a unionSecret=a0f380bb22cd4ce2a8d35f3bf437d6fa diff --git a/hai-service/src/main/resources/prod/commonConfig.properties b/hai-service/src/main/resources/prod/commonConfig.properties index 02f247fb..6284c540 100644 --- a/hai-service/src/main/resources/prod/commonConfig.properties +++ b/hai-service/src/main/resources/prod/commonConfig.properties @@ -56,9 +56,12 @@ JjAppSecret = bf57pnqy8mkexr0v169c3g4odazwu2ij #LY LyNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByLy -LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU -LyMemberId=18665 -LyPostUrl=https://cz.31994.cn/yrapi.php/ +#LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU +##LyMemberId=18665 +##LyPostUrl=https://cz.31994.cn/yrapi.php/ +LyApiKey=UzMxo9SIL1tmFvWTwys7pQRGJqO3EChK +LyMemberId=11236 +LyPostUrl=http://cz.zt10010.com/yrapi.php/ unionAppId=ced46392acfe42be863fdfdd3e61164a unionSecret=a0f380bb22cd4ce2a8d35f3bf437d6fa From a860b4d79c7a9e31eded3a070f418d13770e4587 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Wed, 6 Jul 2022 14:17:13 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=9D=E8=B4=B9?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bweb/controller/HighTestController.java | 2 +- .../hai/service/impl/OutRechargeOrderServiceImpl.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java index 00cabd48..2f27f365 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java @@ -1 +1 @@ -package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighCouponCodeOtherMapper; import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; import com.hai.enum_type.OrderPushType; import com.hai.model.*; import com.hai.service.*; import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @Resource private HighCouponService highCouponService; @Resource private HighOilCardService oilCardService; @Resource private GoodsOrderServiceImpl goodsOrderService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private HighCouponCodeOtherMapper highCouponCodeOtherMapper; @Resource private HighUserCouponMapper highUserCouponMapper; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HighGasOilPriceOfficialService gasOilPriceOfficialService; @Resource private HighCouponAgentService couponAgentService; @Resource private HighCouponAgentService highCouponAgentService; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "orderNo", required = true) String orderNo, @RequestParam(name = "userPhone", required = true) String userPhone) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order != null) { for (HighChildOrder childOrder : order.getHighChildOrderList()) { HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); } // 获取token String token = huiLianTongConfig.getToken(); // 查询用户 HighUser highUser = highUserService.findByUserId(order.getMemId()); Map push = new HashMap<>(); push.put("token", token); push.put("couTypeCode", coupon.getCouponKey()); push.put("distCouCount", childOrder.getSaleCount()); push.put("userPhone", highUser.getPhone()); push.put("thirdUserId", highUser.getUnionId()); JSONObject returnParam = HuiLianTongConfig.couJointDist(token, orderNo, MapUtils.getString(push, "couTypeCode") , 1, userPhone, MapUtils.getString(push, "thirdUserId")); if (returnParam != null && returnParam.getString("result").equals("success")) { JSONArray dataArray = returnParam.getJSONArray("data"); for (Object data : dataArray) { JSONObject dataObject = (JSONObject) data; HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); couponCodeOther.setType(1); couponCodeOther.setOrderId(order.getId()); couponCodeOther.setChildOrderId(childOrder.getId()); couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); couponCodeOther.setCouNo(dataObject.getString("couNo")); couponCodeOther.setStatus(20); couponCodeOther.setCreateTime(new Date()); couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); highCouponCodeOtherMapper.insert(couponCodeOther); // 卡卷关联用户 HighUserCoupon highUserCoupon = new HighUserCoupon(); highUserCoupon.setMerchantId(coupon.getMerchantId()); highUserCoupon.setCouponId(coupon.getId()); highUserCoupon.setUserId(order.getMemId()); highUserCoupon.setCreateTime(new Date()); highUserCoupon.setQrCodeImg(dataObject.getString("couNo")); highUserCoupon.setUseEndTime(dataObject.getDate("validEndDate")); highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); } } // 推送记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setType(OrderPushType.type6.getType()); highGasOrderPush.setOrderNo(order.getOrderNo()); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(returnParam.getString("result")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); highGasOrderPush.setReturnContent(returnParam.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); } } else { // 查询兑换码 HighCouponAgentCode convertCode = highCouponAgentService.getConvertCode(orderNo); if (convertCode == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的兑换码"); } // 查询卡券 HighCoupon coupon = highCouponService.getCouponById(convertCode.getCouponId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的卡券"); } // 获取token String token = huiLianTongConfig.getToken(); Map push = new HashMap<>(); push.put("token", token); push.put("orderNo", convertCode.getConvertCode()); push.put("couTypeCode", coupon.getCouponKey()); push.put("distCouCount", 1); push.put("userPhone", userPhone); push.put("thirdUserId", userPhone); // 推送给高速 JSONObject returnParam = HuiLianTongConfig.couJointDist(token, MapUtils.getString(push, "orderNo"), MapUtils.getString(push, "couTypeCode"), MapUtils.getInteger(push, "distCouCount"), MapUtils.getString(push, "userPhone"), MapUtils.getString(push, "userPhone") ); if (returnParam != null && returnParam.getString("result").equals("success")) { JSONArray dataArray = returnParam.getJSONArray("data"); for (Object data : dataArray) { JSONObject dataObject = (JSONObject) data; HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); couponCodeOther.setType(1); couponCodeOther.setCouponAgentCodeId(convertCode.getId()); couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); couponCodeOther.setCouNo(dataObject.getString("couNo")); couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); couponCodeOther.setStatus(20); couponCodeOther.setCreateTime(new Date()); highCouponCodeOtherMapper.insert(couponCodeOther); } } // 推送记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setType(OrderPushType.type6.getType()); highGasOrderPush.setOrderNo(convertCode.getCouponCode()); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(returnParam.getString("result")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); highGasOrderPush.setReturnContent(returnParam.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); } return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighOrderController --> couJointDist() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/kfcRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "KFC退款") public ResponseData kfcRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { OrderRefundModel orderRefundModel = null; if (StringUtils.isNotBlank(orderNo)) { // 查询订单 HighOrder order = highOrderService.getOrderByOrderNo(orderNo); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款 if (order != null && order.getOrderStatus() == 2) { orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), "1609882817", order.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : order.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } order.setOrderStatus(4); order.setRefundTime(new Date()); order.setRefundPrice(order.getPayRealPrice()); highOrderService.updateOrder(order); return ResponseMsgUtil.success(orderRefundModel); } } } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/refreshGasPriceOfficial", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "刷新国标价") public ResponseData refreshGasPriceOfficial() { try { gasOilPriceOfficialService.refreshPriceOfficial(); gasOilPriceOfficialService.refreshGasPriceOfficial(null, null); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分账") public ResponseData wxProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.01"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 渝北区浩联物资经营部 param.put("transaction_id" , order.getPaySerialNo()); param.put("out_order_no" , order.getOrderNo()); param.put("nonce_str" , WxUtils.makeNonStr()); // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.profitsharing(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(porofitSharingAmount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); return ResponseMsgUtil.success(e); } } public String profitsharing(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); 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"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } 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 static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; 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(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderId", required = true) Long orderId) { try { outRechargeOrderService.rechargeOrderToRefund(orderId); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket( @RequestParam(name = "userId", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://139.159.177.244:9901/msg/websocket/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("请求成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighCouponCodeOtherMapper; import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; import com.hai.enum_type.OrderPushType; import com.hai.model.*; import com.hai.service.*; import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @Resource private HighCouponService highCouponService; @Resource private HighOilCardService oilCardService; @Resource private GoodsOrderServiceImpl goodsOrderService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private HighCouponCodeOtherMapper highCouponCodeOtherMapper; @Resource private HighUserCouponMapper highUserCouponMapper; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HighGasOilPriceOfficialService gasOilPriceOfficialService; @Resource private HighCouponAgentService couponAgentService; @Resource private HighCouponAgentService highCouponAgentService; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "orderNo", required = true) String orderNo, @RequestParam(name = "userPhone", required = true) String userPhone) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order != null) { for (HighChildOrder childOrder : order.getHighChildOrderList()) { HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); } // 获取token String token = huiLianTongConfig.getToken(); // 查询用户 HighUser highUser = highUserService.findByUserId(order.getMemId()); Map push = new HashMap<>(); push.put("token", token); push.put("couTypeCode", coupon.getCouponKey()); push.put("distCouCount", childOrder.getSaleCount()); push.put("userPhone", highUser.getPhone()); push.put("thirdUserId", highUser.getUnionId()); JSONObject returnParam = HuiLianTongConfig.couJointDist(token, orderNo, MapUtils.getString(push, "couTypeCode") , 1, userPhone, MapUtils.getString(push, "thirdUserId")); if (returnParam != null && returnParam.getString("result").equals("success")) { JSONArray dataArray = returnParam.getJSONArray("data"); for (Object data : dataArray) { JSONObject dataObject = (JSONObject) data; HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); couponCodeOther.setType(1); couponCodeOther.setOrderId(order.getId()); couponCodeOther.setChildOrderId(childOrder.getId()); couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); couponCodeOther.setCouNo(dataObject.getString("couNo")); couponCodeOther.setStatus(20); couponCodeOther.setCreateTime(new Date()); couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); highCouponCodeOtherMapper.insert(couponCodeOther); // 卡卷关联用户 HighUserCoupon highUserCoupon = new HighUserCoupon(); highUserCoupon.setMerchantId(coupon.getMerchantId()); highUserCoupon.setCouponId(coupon.getId()); highUserCoupon.setUserId(order.getMemId()); highUserCoupon.setCreateTime(new Date()); highUserCoupon.setQrCodeImg(dataObject.getString("couNo")); highUserCoupon.setUseEndTime(dataObject.getDate("validEndDate")); highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); } } // 推送记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setType(OrderPushType.type6.getType()); highGasOrderPush.setOrderNo(order.getOrderNo()); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(returnParam.getString("result")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); highGasOrderPush.setReturnContent(returnParam.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); } } else { // 查询兑换码 HighCouponAgentCode convertCode = highCouponAgentService.getConvertCode(orderNo); if (convertCode == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的兑换码"); } // 查询卡券 HighCoupon coupon = highCouponService.getCouponById(convertCode.getCouponId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的卡券"); } // 获取token String token = huiLianTongConfig.getToken(); Map push = new HashMap<>(); push.put("token", token); push.put("orderNo", convertCode.getConvertCode()); push.put("couTypeCode", coupon.getCouponKey()); push.put("distCouCount", 1); push.put("userPhone", userPhone); push.put("thirdUserId", userPhone); // 推送给高速 JSONObject returnParam = HuiLianTongConfig.couJointDist(token, MapUtils.getString(push, "orderNo"), MapUtils.getString(push, "couTypeCode"), MapUtils.getInteger(push, "distCouCount"), MapUtils.getString(push, "userPhone"), MapUtils.getString(push, "userPhone") ); if (returnParam != null && returnParam.getString("result").equals("success")) { JSONArray dataArray = returnParam.getJSONArray("data"); for (Object data : dataArray) { JSONObject dataObject = (JSONObject) data; HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); couponCodeOther.setType(1); couponCodeOther.setCouponAgentCodeId(convertCode.getId()); couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); couponCodeOther.setCouNo(dataObject.getString("couNo")); couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); couponCodeOther.setStatus(20); couponCodeOther.setCreateTime(new Date()); highCouponCodeOtherMapper.insert(couponCodeOther); } } // 推送记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setType(OrderPushType.type6.getType()); highGasOrderPush.setOrderNo(convertCode.getCouponCode()); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(returnParam.getString("result")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); highGasOrderPush.setReturnContent(returnParam.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); } return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighOrderController --> couJointDist() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/kfcRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "KFC退款") public ResponseData kfcRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { OrderRefundModel orderRefundModel = null; if (StringUtils.isNotBlank(orderNo)) { // 查询订单 HighOrder order = highOrderService.getOrderByOrderNo(orderNo); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款 if (order != null && order.getOrderStatus() == 2) { orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), "1609882817", order.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : order.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } order.setOrderStatus(4); order.setRefundTime(new Date()); order.setRefundPrice(order.getPayRealPrice()); highOrderService.updateOrder(order); return ResponseMsgUtil.success(orderRefundModel); } } } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/refreshGasPriceOfficial", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "刷新国标价") public ResponseData refreshGasPriceOfficial() { try { gasOilPriceOfficialService.refreshPriceOfficial(); gasOilPriceOfficialService.refreshGasPriceOfficial(null, null); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分账") public ResponseData wxProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.01"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 渝北区浩联物资经营部 param.put("transaction_id" , order.getPaySerialNo()); param.put("out_order_no" , order.getOrderNo()); param.put("nonce_str" , WxUtils.makeNonStr()); // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.profitsharing(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(porofitSharingAmount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); return ResponseMsgUtil.success(e); } } public String profitsharing(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); 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"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } 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 static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; 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(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderNo", required = true) String orderNo) { try { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); outRechargeOrderService.rechargeOrderToRefund(outRechargeOrder.getId()); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket( @RequestParam(name = "userId", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://139.159.177.244:9901/msg/websocket/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("请求成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/ReRequest", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData ReRequest( @RequestParam(name = "orderNo", required = true) String orderNo) { try { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); outRechargeOrderService.pollRequest(outRechargeOrder); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index 30846ad2..da66bed6 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -41,6 +41,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; @Service("outRechargeOrderService") public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @@ -141,7 +142,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { DateUtil.format(MapUtils.getString(map, "createTimeE"), "yyyy-MM-dd HH:mm:ss")); } - example.setOrderByClause("create_timed desc"); + example.setOrderByClause("create_timed ASC"); return outRechargeOrderMapper.selectByExample(example); } @@ -756,8 +757,8 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { // 查询充值子订单 Map childOrderMap103 = new HashMap<>(); - childOrderMap.put("parent_order_id", outRechargeOrder.getId()); - childOrderMap.put("status", 103); + childOrderMap103.put("parent_order_id", outRechargeOrder.getId()); + childOrderMap103.put("status", 103); List childOrderList103 = outRechargeChildOrderService.getListRechargeChildOrder(childOrderMap103); if (childOrderList103.size() > 0) { @@ -784,13 +785,14 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } for (String s : rechargePlatform) { + TimeUnit.SECONDS.sleep(1); + System.out.println("-----------------------------------------------------------------------------------------------------------------------------------------------------" + new Date()); // 尖椒充值 if (s.equals("1") && type == 1) { object.put("out_order_id", orderNo); object.put("amount", outRechargePrice.getRechargePrice()); object.put("mobile", outRechargeOrder.getRechargeContent()); object.put("notifyUrl", CommonSysConst.getSysConfig().getJjNotifyUrl()); - System.out.println("outRechargeOrder-----------------------------------------------------------------------------------------------------------------------------------------------------" + outRechargePrice.getRechargeType()); if (outRechargeOrder.getRechargeType() == 1) { object.put("is_fast", 1); } From 3cd01161b40e59ebd5c4959b493f1ecce2f45f07 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Wed, 6 Jul 2022 16:55:19 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=9D=E8=B4=B9?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hai/schedule/HighOrderSchedule.java | 15 +++++++++++---- .../service/impl/OutRechargeOrderServiceImpl.java | 12 ++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) 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 19f9dfec..2f3e9b28 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -23,6 +23,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @Auther: 胡锐 @@ -92,14 +93,15 @@ public class HighOrderSchedule { * @Param [] * @return void */ - @Scheduled(cron="0 0/5 * * * ?") //每10分钟执行一次 + @Scheduled(cron="0 0/1 * * * ?") //每10分钟执行一次 public void initRechargeOrder() { Map map = new HashMap<>(); map.put("payStatus" , String.valueOf(102)); map.put("rechargeStatus" , String.valueOf(204)); List orderList = outRechargeOrderService.getListRechargeOrder(map); - System.out.println("订单数量------------------------------------------------------------------------------" + orderList.size()); + System.out.println("话费定时任务 -> 开始循环数据:开始 需要操作的订单数量:" + orderList.size()); + if (orderList.size() > 0) { for (OutRechargeOrder order : orderList) { try { @@ -110,6 +112,7 @@ public class HighOrderSchedule { List childOrderList = rechargeChildOrderService.getListRechargeChildOrder(childOrderMap); + System.out.println("话费定时任务 -> 判断是否存在已支付订单:订单id:" + order.getId()); if (childOrderList.size() == 0) { Date rechargeTime = order.getCreateTimed(); Date currentTime = new Date(); @@ -117,14 +120,17 @@ public class HighOrderSchedule { // 判断快充 并且 充值时间小于6 if (order.getRechargeType() == 1 && hours < 6) { + System.out.println("话费定时任务 -> 请求快充:订单id:" + order.getId()); outRechargeOrderService.pollRequest(order); - return; + continue; } // 判断慢充 并且 充值时间小于72 if (order.getRechargeType() == 2 && hours < 72) { + System.out.println("话费定时任务 -> 请求慢充:订单id:" + order.getId()); outRechargeOrderService.pollRequest(order); - return; + continue; } + System.out.println("话费定时任务 -> 退款任务" + order.getId()); outRechargeOrderService.rechargeOrderToRefund(order.getId()); } @@ -133,6 +139,7 @@ public class HighOrderSchedule { } } } + System.out.println("话费定时任务 -> 结束任务"); } /** diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index da66bed6..bc215ca5 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -30,6 +30,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; @@ -46,6 +48,8 @@ import java.util.concurrent.TimeUnit; @Service("outRechargeOrderService") public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { + private static final Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class); + @Resource private OutRechargeOrderMapper outRechargeOrderMapper; @@ -730,7 +734,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { // 查询充值产品 OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(outRechargeOrder.getGoodsId(), null); - + System.out.println("话费定时任务 -> 需要重新充值:开始"); // 查询充值子订单 Map childOrderMap = new HashMap<>(); @@ -785,9 +789,8 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } for (String s : rechargePlatform) { - TimeUnit.SECONDS.sleep(1); - System.out.println("-----------------------------------------------------------------------------------------------------------------------------------------------------" + new Date()); // 尖椒充值 + System.out.println("话费定时任务 -> 需要重新充值:尖椒开始"); if (s.equals("1") && type == 1) { object.put("out_order_id", orderNo); object.put("amount", outRechargePrice.getRechargePrice()); @@ -808,12 +811,12 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } // 龙阅充值 if (s.equals("2") && type == 2) { + System.out.println("话费定时任务 -> 需要重新充值:龙阅开始"); object.put("out_trade_num", orderNo); object.put("product_id", outRechargePrice.getGoodsId()); object.put("mobile", outRechargeOrder.getRechargeContent()); object.put("notifyUrl", CommonSysConst.getSysConfig().getLyNotifyUrl()); JSONObject returnObject = RechargeConfig.rechargeOrderByLy(object); - System.out.println("龙阅请求回调地址---------------------" + CommonSysConst.getSysConfig().getLyNotifyUrl()); object.put("return_content", returnObject); if (returnObject != null && returnObject.getLong("errno") == 0) { childOrder.setStatus(102); @@ -854,6 +857,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { outRechargeOrder.setRechargeStatus(204); } outRechargeOrderService.updateOrder(outRechargeOrder); + System.out.println("话费定时任务 -> 需要重新充值:结束"); } @Override From 8724386e31c4f5165ea9a0b54590fb572c9d665c Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Thu, 7 Jul 2022 18:08:07 +0800 Subject: [PATCH 05/13] =?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 --- .../bweb/controller/HighGasController.java | 138 ++++++++++++------ .../controller/HighGasStaffController.java | 68 +++++++++ .../src/main/resources/dev/config.properties | 4 +- .../cweb/controller/HighOrderController.java | 21 +++ .../hai/common/security/AESEncodeUtil.java | 2 + .../com/hai/dao/HighChildOrderMapper.java | 17 ++- .../hai/dao/HighChildOrderSqlProvider.java | 28 ++++ .../java/com/hai/dao/HighGasStaffMapper.java | 17 ++- .../com/hai/dao/HighGasStaffSqlProvider.java | 14 ++ .../java/com/hai/dao/HighOrderMapperExt.java | 17 +++ .../java/com/hai/entity/HighChildOrder.java | 32 ++++ .../com/hai/entity/HighChildOrderExample.java | 130 +++++++++++++++++ .../java/com/hai/entity/HighGasStaff.java | 16 ++ .../com/hai/entity/HighGasStaffExample.java | 70 +++++++++ .../main/java/com/hai/entity/HighOrder.java | 10 ++ .../com/hai/enum_type/GasPositionType.java | 1 + .../com/hai/enum_type/UserObjectTypeEnum.java | 1 + .../java/com/hai/model/GasOrderModel.java | 9 ++ .../com/hai/service/HighOrderService.java | 16 ++ .../service/impl/HighGasStaffServiceImpl.java | 2 + .../service/impl/HighOrderServiceImpl.java | 10 ++ 21 files changed, 567 insertions(+), 56 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighGasController.java b/hai-bweb/src/main/java/com/bweb/controller/HighGasController.java index 056bd7be..d2eeb5d8 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighGasController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighGasController.java @@ -111,41 +111,80 @@ public class HighGasController { Map param = new HashMap<>();; param.put("gasName", userInfoModel.getMerchantStore().getStoreName()); - Map history = new HashMap<>(); - // 历史加油总金额 - Map historyTotal = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,4,6,7"); - history.put("totalPrice", historyTotal.get("price")); - history.put("totalCount", historyTotal.get("count")); - - // 历史加油金额 - Map historyIncomet = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,6,7"); - history.put("incomePrice", historyIncomet.get("price")); - history.put("incomeCount", historyIncomet.get("count")); - - // 历史退款 - Map historyRefund = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "4"); - history.put("refundPrice", historyRefund.get("price")); - history.put("refundCount", historyRefund.get("count")); - param.put("history", history); - - - Map today = new HashMap<>(); - // 今日加油总金额 - Map todayTotal = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,4,6,7"); - today.put("totalPrice", todayTotal.get("price")); - today.put("totalCount", todayTotal.get("count")); - - // 今日加油金额 - Map todayIncomet = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,6,7"); - today.put("incomePrice", todayIncomet.get("price")); - today.put("incomeCount", todayIncomet.get("count")); - - // 今日退款 - Map todayRefund = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "4"); - today.put("refundPrice", todayRefund.get("price")); - today.put("refundCount", todayRefund.get("count")); - param.put("today", today); + if (userInfoModel.getSecUser().getObjectType().equals(UserObjectTypeEnum.type8.getType()) + && userInfoModel.getGasStaff().getPositionType().equals(GasPositionType.status2.getStatus())) { + + Map history = new HashMap<>(); + // 历史加油总金额 + Map historyTotal = highOrderService.getGasStaffHistoryOrderCount(userInfoModel.getGasStaff().getId(), "2,3,4,6,7"); + history.put("totalPrice", historyTotal.get("price")); + history.put("totalCount", historyTotal.get("count")); + + // 历史加油金额 + Map historyIncomet = highOrderService.getGasStaffHistoryOrderCount(userInfoModel.getGasStaff().getId(), "2,3,6,7"); + history.put("incomePrice", historyIncomet.get("price")); + history.put("incomeCount", historyIncomet.get("count")); + + // 历史退款 + Map historyRefund = highOrderService.getGasStaffHistoryOrderCount(userInfoModel.getGasStaff().getId(), "4"); + history.put("refundPrice", historyRefund.get("price")); + history.put("refundCount", historyRefund.get("count")); + param.put("history", history); + + + Map today = new HashMap<>(); + // 今日加油总金额 + Map todayTotal = highOrderService.getGasStaffTheDayOrderCount(userInfoModel.getGasStaff().getId(), "2,3,4,6,7"); + today.put("totalPrice", todayTotal.get("price")); + today.put("totalCount", todayTotal.get("count")); + + // 今日加油金额 + Map todayIncomet = highOrderService.getGasStaffTheDayOrderCount(userInfoModel.getGasStaff().getId(), "2,3,6,7"); + today.put("incomePrice", todayIncomet.get("price")); + today.put("incomeCount", todayIncomet.get("count")); + + // 今日退款 + Map todayRefund = highOrderService.getGasStaffTheDayOrderCount(userInfoModel.getGasStaff().getId(), "4"); + today.put("refundPrice", todayRefund.get("price")); + today.put("refundCount", todayRefund.get("count")); + param.put("today", today); + } else { + Map history = new HashMap<>(); + // 历史加油总金额 + Map historyTotal = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,4,6,7"); + history.put("totalPrice", historyTotal.get("price")); + history.put("totalCount", historyTotal.get("count")); + + // 历史加油金额 + Map historyIncomet = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,6,7"); + history.put("incomePrice", historyIncomet.get("price")); + history.put("incomeCount", historyIncomet.get("count")); + + // 历史退款 + Map historyRefund = highOrderService.getGasHistoryOrderCount(userInfoModel.getMerchantStore().getId(), "4"); + history.put("refundPrice", historyRefund.get("price")); + history.put("refundCount", historyRefund.get("count")); + param.put("history", history); + + + Map today = new HashMap<>(); + // 今日加油总金额 + Map todayTotal = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,4,6,7"); + today.put("totalPrice", todayTotal.get("price")); + today.put("totalCount", todayTotal.get("count")); + + // 今日加油金额 + Map todayIncomet = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "2,3,6,7"); + today.put("incomePrice", todayIncomet.get("price")); + today.put("incomeCount", todayIncomet.get("count")); + + // 今日退款 + Map todayRefund = highOrderService.getGasTheDayOrderCount(userInfoModel.getMerchantStore().getId(), "4"); + today.put("refundPrice", todayRefund.get("price")); + today.put("refundCount", todayRefund.get("count")); + param.put("today", today); + } return ResponseMsgUtil.success(param); } catch (Exception e) { @@ -159,6 +198,7 @@ public class HighGasController { @ApiOperation(value = "查询油站订单列表") public ResponseData getGasOrderList(@RequestParam(name = "orderNo", required = false) String orderNo, @RequestParam(name = "storeId", required = false) Long storeId, + @RequestParam(name = "staffId", required = false) Long staffId, @RequestParam(name = "status", required = false) Integer status, @RequestParam(name = "createTimeS", required = false) Long createTimeS, @RequestParam(name = "createTimeE", required = false) Long createTimeE, @@ -170,7 +210,7 @@ public class HighGasController { log.error("HighGasController -> disabledOil() error!",""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); } - Map param = new HashMap<>();; + Map param = new HashMap<>(); // 用户来源 0:超级管理员 1:公司 2:商户 3:门店 4. 代理商 5.充值后台工商 6.团油代理商 7.团油业务员 8. 加油站员工 if (userInfoModel.getSecUser().getObjectType().equals(2)) { if (storeId != null) { @@ -191,15 +231,20 @@ public class HighGasController { } else { param.put("storeId", 0); } - } + param.put("gasStaffId", staffId); } else if (userInfoModel.getSecUser().getObjectType().equals(3)) { param.put("storeId", userInfoModel.getMerchantStore().getId()); + param.put("gasStaffId", staffId); } else if (userInfoModel.getSecUser().getObjectType().equals(8)) { - param.put("storeId", userInfoModel.getMerchantStore().getId()); - + if (userInfoModel.getGasStaff().getPositionType().equals(GasPositionType.status1.getStatus())) { + param.put("storeId", userInfoModel.getMerchantStore().getId()); + } + if (userInfoModel.getGasStaff().getPositionType().equals(GasPositionType.status2.getStatus())) { + param.put("gasStaffId", userInfoModel.getGasStaff().getId()); + } } else { log.error("HighGasController -> disabledOil() error!",""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); @@ -260,6 +305,7 @@ public class HighGasController { @ApiOperation(value = "导出油站订单") public ResponseData exportGasOrder(@RequestParam(name = "orderNo", required = false) String orderNo, @RequestParam(name = "storeId", required = false) Long storeId, + @RequestParam(name = "staffId", required = false) Long staffId, @RequestParam(name = "status", required = false) Integer status, @RequestParam(name = "createTimeS", required = false) Long createTimeS, @RequestParam(name = "createTimeE", required = false) Long createTimeE) { @@ -290,20 +336,24 @@ public class HighGasController { } else { param.put("storeId", 0); } - } + param.put("gasStaffId", staffId); } else if (userInfoModel.getSecUser().getObjectType().equals(3)) { param.put("storeId", userInfoModel.getMerchantStore().getId()); + param.put("gasStaffId", staffId); } else if (userInfoModel.getSecUser().getObjectType().equals(8)) { - param.put("storeId", userInfoModel.getMerchantStore().getId()); - + if (userInfoModel.getGasStaff().getPositionType().equals(GasPositionType.status1.getStatus())) { + param.put("storeId", userInfoModel.getMerchantStore().getId()); + } + if (userInfoModel.getGasStaff().getPositionType().equals(GasPositionType.status2.getStatus())) { + param.put("gasStaffId", userInfoModel.getGasStaff().getId()); + } } else { log.error("HighGasController -> disabledOil() error!",""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); } - param.put("orderNo", orderNo); param.put("createTimeS", createTimeS); param.put("createTimeE", createTimeE); @@ -317,6 +367,7 @@ public class HighGasController { List headList = new ArrayList<>(); headList.add("订单号"); headList.add("油站名称"); + headList.add("加油员"); headList.add("油品类型"); headList.add("油品油号"); headList.add("油枪号"); @@ -337,6 +388,7 @@ public class HighGasController { data = new ArrayList<>(); data.add(orderModel.getOrderNo()); data.add(orderModel.getGasName()); + data.add(StringUtils.isNotBlank(orderModel.getGasStaffName())?orderModel.getGasStaffName():"未知"); data.add(orderModel.getGasOilType().equals("1") ? "汽油": "柴油"); data.add(orderModel.getGasOilNo() + "#"); data.add(orderModel.getGasGunNo() + "号"); @@ -357,7 +409,7 @@ public class HighGasController { if (!file.exists()) { file.mkdirs(); } - EasyExcel.write(fileUrl+pathName).head(generationHead(headList)).sheet("油卡").doWrite(dataList); + EasyExcel.write(fileUrl+pathName).head(generationHead(headList)).sheet("加油订单").doWrite(dataList); return ResponseMsgUtil.success(pathName); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighGasStaffController.java b/hai-bweb/src/main/java/com/bweb/controller/HighGasStaffController.java index c1f58211..1f2778d1 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighGasStaffController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighGasStaffController.java @@ -1,28 +1,45 @@ package com.bweb.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.bweb.config.SysConst; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.hai.common.Base64Util; +import com.hai.common.QRCodeGenerator; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.security.AESEncodeUtil; import com.hai.common.security.UserCenter; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.IDGenerator; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.config.CommonSysConst; import com.hai.entity.HighGasStaff; +import com.hai.entity.HighMerchantStore; import com.hai.enum_type.GasStaffStatus; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.CommonService; import com.hai.service.HighGasStaffService; +import com.hai.service.HighMerchantStoreService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.utils.URLEncodedUtils; +import org.bouncycastle.util.encoders.UrlBase64Encoder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Base64; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -36,6 +53,9 @@ public class HighGasStaffController { @Resource private HighGasStaffService gasStaffService; + @Resource + private HighMerchantStoreService merchantStoreService; + @Resource private CommonService commonService; @@ -112,6 +132,54 @@ public class HighGasStaffController { } } + @RequestMapping(value="/queryQrCode",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询二维码") + public ResponseData queryQrCode(@RequestBody JSONObject body) { + try { + if (body.getLong("gasStaffId") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 查询员工信息 + HighGasStaff gasStaff = gasStaffService.getStaffDetailById(body.getLong("gasStaffId")); + if (gasStaff == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到员工信息"); + } + + if (StringUtils.isBlank(gasStaff.getQrCodeImgUrl())) { + + // 查询加油站 + HighMerchantStore merchantStore = merchantStoreService.getDetailById(gasStaff.getMerchantStoreId()); + if (merchantStore == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到加油站信息"); + } + // 查询秘钥 + String key = commonService.getDictionaryCodeName("QR_CODE_SIGN_KEY", "1"); + if (StringUtils.isBlank(key)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败"); + } + + // 员工ID签名 + String signId = AESEncodeUtil.base64Encode(AESEncodeUtil.aesEncryptToBytes(gasStaff.getId().toString(), key)); + + // 生成二维码 + String param = CommonSysConst.getSysConfig().getHsgDomainName()+"/hsgH5?accountId=000000&gasKey=" + merchantStore.getStoreKey() + "&staffCode=" + URLEncoder.encode(signId, "UTF-8"); + String qrCodeImgUrl = DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(1) +".jpg"; + QRCodeGenerator.generateQRCodeImage(param, 350, 350, SysConst.getSysConfig().getFileUrl()+"/gasStaff/"+qrCodeImgUrl); + + gasStaff.setQrCodeImgUrl(qrCodeImgUrl); + gasStaffService.updateStaff(gasStaff); + } + + return ResponseMsgUtil.success(gasStaff.getQrCodeImgUrl()); + + } catch (Exception e) { + log.error("HighGasStaffController -> queryQrCode() error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value="/disabled",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "禁用员工") diff --git a/hai-bweb/src/main/resources/dev/config.properties b/hai-bweb/src/main/resources/dev/config.properties index 25674f3d..da0992f7 100644 --- a/hai-bweb/src/main/resources/dev/config.properties +++ b/hai-bweb/src/main/resources/dev/config.properties @@ -1,5 +1,5 @@ -#fileUrl=/home/project/hsg/filesystem -fileUrl=/Volumes/work/code/filesystem/ +fileUrl=/home/project/hsg/filesystem +#fileUrl=/Volumes/work/code/filesystem/ cmsPath=/home/project/hsg/filesystem/cmsPath agentQrCode=/home/project/hsg/filesystem/agentQrCode agentQrCodeWxUrl=https://hsgcs.dctpay.com/wx/?action=ic&id= 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 6809c109..228d03d6 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -8,6 +8,7 @@ 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.security.AESEncodeUtil; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; @@ -38,6 +39,7 @@ import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; +import java.net.URLDecoder; import java.util.*; import java.util.stream.Collectors; @@ -94,6 +96,9 @@ public class HighOrderController { @Resource private HighGasDiscountOilPriceService gasDiscountOilPriceService; + @Resource + private HighGasStaffService gasStaffService; + @RequestMapping(value="/addOrder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "增加订单") @@ -241,6 +246,22 @@ public class HighOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已达到每日加油次数上限"); } + if (StringUtils.isNotBlank(highOrder.getGasStaffCode())) { + String qrCodeSignKey = commonService.getDictionaryCodeName("QR_CODE_SIGN_KEY", "柴油"); + if (StringUtils.isBlank(qrCodeSignKey)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知秘钥"); + } + String staffId = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(URLDecoder.decode(highOrder.getGasStaffCode(),"UTF-8")), qrCodeSignKey); + + // 查询员工 + HighGasStaff gasStaff = gasStaffService.getStaffDetailById(Long.parseLong(staffId)); + if (gasStaff == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知收银员"); + } + childOrder.setGasStaffId(gasStaff.getId()); + childOrder.setGasStaffName(gasStaff.getName()); + } + // 查询门店 HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(childOrder.getGoodsId()); if (store == null) { diff --git a/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java b/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java index 81c35c16..5f33aa77 100644 --- a/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java +++ b/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java @@ -7,6 +7,7 @@ import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; import java.math.BigInteger; +import java.net.URLDecoder; import java.security.SecureRandom; import java.util.Base64; @@ -63,6 +64,7 @@ public class AESEncodeUtil { public static void main(String[] args) throws Exception{ long currentTimeMillis = System.currentTimeMillis(); + System.out.println(URLDecoder.decode("Ble3spwlvhIa%2FArAa2cq0Q%3D%3D", "UTF-8")); System.out.println(AESEncodeUtil.aesDecrypt(Base64Util.decode("ZStZUjRIcFl5SVo4MEhzSU96MldDUEFZa3lmbUhpNTdKMGhCVytIY3NJaz0"))); /* String content = "{\"create_time\":1573544092110,\"order_serial_no\":\"40280e816db49c0b016db4a2c31f0004\",\"product_code\":\"8a9e80045cf85e54015cf8809fcd\",\"product_name\":\"平安发票贷\",\"uscc\":\"91370781687233838E\"}"; System.out.println("加密前" + content); diff --git a/hai-service/src/main/java/com/hai/dao/HighChildOrderMapper.java b/hai-service/src/main/java/com/hai/dao/HighChildOrderMapper.java index 01b0ad14..e252526a 100644 --- a/hai-service/src/main/java/com/hai/dao/HighChildOrderMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighChildOrderMapper.java @@ -54,7 +54,8 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { "gas_price_vip, gas_price_official, ", "gas_oil_liters, gas_discount, ", "gas_oil_subsidy, gas_liters_preferences, ", - "gas_price_preferences, gas_salesman_id, ", + "gas_price_preferences, gas_staff_id, ", + "gas_staff_name, gas_salesman_id, ", "gas_salesman_name, gas_agent_id, ", "gas_agent_name, gas_org_id, ", "gas_org_name, ext_1, ", @@ -75,7 +76,8 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { "#{gasPriceVip,jdbcType=DECIMAL}, #{gasPriceOfficial,jdbcType=DECIMAL}, ", "#{gasOilLiters,jdbcType=DECIMAL}, #{gasDiscount,jdbcType=DECIMAL}, ", "#{gasOilSubsidy,jdbcType=DECIMAL}, #{gasLitersPreferences,jdbcType=DECIMAL}, ", - "#{gasPricePreferences,jdbcType=DECIMAL}, #{gasSalesmanId,jdbcType=BIGINT}, ", + "#{gasPricePreferences,jdbcType=DECIMAL}, #{gasStaffId,jdbcType=BIGINT}, ", + "#{gasStaffName,jdbcType=VARCHAR}, #{gasSalesmanId,jdbcType=BIGINT}, ", "#{gasSalesmanName,jdbcType=VARCHAR}, #{gasAgentId,jdbcType=BIGINT}, ", "#{gasAgentName,jdbcType=VARCHAR}, #{gasOrgId,jdbcType=BIGINT}, ", "#{gasOrgName,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ", @@ -123,6 +125,8 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { @Result(column="gas_oil_subsidy", property="gasOilSubsidy", jdbcType=JdbcType.DECIMAL), @Result(column="gas_liters_preferences", property="gasLitersPreferences", jdbcType=JdbcType.DECIMAL), @Result(column="gas_price_preferences", property="gasPricePreferences", jdbcType=JdbcType.DECIMAL), + @Result(column="gas_staff_id", property="gasStaffId", jdbcType=JdbcType.BIGINT), + @Result(column="gas_staff_name", property="gasStaffName", jdbcType=JdbcType.VARCHAR), @Result(column="gas_salesman_id", property="gasSalesmanId", jdbcType=JdbcType.BIGINT), @Result(column="gas_salesman_name", property="gasSalesmanName", jdbcType=JdbcType.VARCHAR), @Result(column="gas_agent_id", property="gasAgentId", jdbcType=JdbcType.BIGINT), @@ -145,8 +149,9 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { "sale_count, total_price, giveaway_type, child_orde_status, praise_status, gas_oil_no, ", "gas_gun_no, gas_oil_type, gas_order_no, gas_price_platform, gas_price_gun, gas_price_vip, ", "gas_price_official, gas_oil_liters, gas_discount, gas_oil_subsidy, gas_liters_preferences, ", - "gas_price_preferences, gas_salesman_id, gas_salesman_name, gas_agent_id, gas_agent_name, ", - "gas_org_id, gas_org_name, ext_1, ext_2, ext_3, ext_4, ext_5, ext_6", + "gas_price_preferences, gas_staff_id, gas_staff_name, gas_salesman_id, gas_salesman_name, ", + "gas_agent_id, gas_agent_name, gas_org_id, gas_org_name, ext_1, ext_2, ext_3, ", + "ext_4, ext_5, ext_6", "from high_child_order", "where id = #{id,jdbcType=BIGINT}" }) @@ -183,6 +188,8 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { @Result(column="gas_oil_subsidy", property="gasOilSubsidy", jdbcType=JdbcType.DECIMAL), @Result(column="gas_liters_preferences", property="gasLitersPreferences", jdbcType=JdbcType.DECIMAL), @Result(column="gas_price_preferences", property="gasPricePreferences", jdbcType=JdbcType.DECIMAL), + @Result(column="gas_staff_id", property="gasStaffId", jdbcType=JdbcType.BIGINT), + @Result(column="gas_staff_name", property="gasStaffName", jdbcType=JdbcType.VARCHAR), @Result(column="gas_salesman_id", property="gasSalesmanId", jdbcType=JdbcType.BIGINT), @Result(column="gas_salesman_name", property="gasSalesmanName", jdbcType=JdbcType.VARCHAR), @Result(column="gas_agent_id", property="gasAgentId", jdbcType=JdbcType.BIGINT), @@ -240,6 +247,8 @@ public interface HighChildOrderMapper extends HighChildOrderMapperExt { "gas_oil_subsidy = #{gasOilSubsidy,jdbcType=DECIMAL},", "gas_liters_preferences = #{gasLitersPreferences,jdbcType=DECIMAL},", "gas_price_preferences = #{gasPricePreferences,jdbcType=DECIMAL},", + "gas_staff_id = #{gasStaffId,jdbcType=BIGINT},", + "gas_staff_name = #{gasStaffName,jdbcType=VARCHAR},", "gas_salesman_id = #{gasSalesmanId,jdbcType=BIGINT},", "gas_salesman_name = #{gasSalesmanName,jdbcType=VARCHAR},", "gas_agent_id = #{gasAgentId,jdbcType=BIGINT},", diff --git a/hai-service/src/main/java/com/hai/dao/HighChildOrderSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighChildOrderSqlProvider.java index bde7e53c..80f9f769 100644 --- a/hai-service/src/main/java/com/hai/dao/HighChildOrderSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighChildOrderSqlProvider.java @@ -152,6 +152,14 @@ public class HighChildOrderSqlProvider { sql.VALUES("gas_price_preferences", "#{gasPricePreferences,jdbcType=DECIMAL}"); } + if (record.getGasStaffId() != null) { + sql.VALUES("gas_staff_id", "#{gasStaffId,jdbcType=BIGINT}"); + } + + if (record.getGasStaffName() != null) { + sql.VALUES("gas_staff_name", "#{gasStaffName,jdbcType=VARCHAR}"); + } + if (record.getGasSalesmanId() != null) { sql.VALUES("gas_salesman_id", "#{gasSalesmanId,jdbcType=BIGINT}"); } @@ -241,6 +249,8 @@ public class HighChildOrderSqlProvider { sql.SELECT("gas_oil_subsidy"); sql.SELECT("gas_liters_preferences"); sql.SELECT("gas_price_preferences"); + sql.SELECT("gas_staff_id"); + sql.SELECT("gas_staff_name"); sql.SELECT("gas_salesman_id"); sql.SELECT("gas_salesman_name"); sql.SELECT("gas_agent_id"); @@ -398,6 +408,14 @@ public class HighChildOrderSqlProvider { sql.SET("gas_price_preferences = #{record.gasPricePreferences,jdbcType=DECIMAL}"); } + if (record.getGasStaffId() != null) { + sql.SET("gas_staff_id = #{record.gasStaffId,jdbcType=BIGINT}"); + } + + if (record.getGasStaffName() != null) { + sql.SET("gas_staff_name = #{record.gasStaffName,jdbcType=VARCHAR}"); + } + if (record.getGasSalesmanId() != null) { sql.SET("gas_salesman_id = #{record.gasSalesmanId,jdbcType=BIGINT}"); } @@ -486,6 +504,8 @@ public class HighChildOrderSqlProvider { sql.SET("gas_oil_subsidy = #{record.gasOilSubsidy,jdbcType=DECIMAL}"); sql.SET("gas_liters_preferences = #{record.gasLitersPreferences,jdbcType=DECIMAL}"); sql.SET("gas_price_preferences = #{record.gasPricePreferences,jdbcType=DECIMAL}"); + sql.SET("gas_staff_id = #{record.gasStaffId,jdbcType=BIGINT}"); + sql.SET("gas_staff_name = #{record.gasStaffName,jdbcType=VARCHAR}"); sql.SET("gas_salesman_id = #{record.gasSalesmanId,jdbcType=BIGINT}"); sql.SET("gas_salesman_name = #{record.gasSalesmanName,jdbcType=VARCHAR}"); sql.SET("gas_agent_id = #{record.gasAgentId,jdbcType=BIGINT}"); @@ -632,6 +652,14 @@ public class HighChildOrderSqlProvider { sql.SET("gas_price_preferences = #{gasPricePreferences,jdbcType=DECIMAL}"); } + if (record.getGasStaffId() != null) { + sql.SET("gas_staff_id = #{gasStaffId,jdbcType=BIGINT}"); + } + + if (record.getGasStaffName() != null) { + sql.SET("gas_staff_name = #{gasStaffName,jdbcType=VARCHAR}"); + } + if (record.getGasSalesmanId() != null) { sql.SET("gas_salesman_id = #{gasSalesmanId,jdbcType=BIGINT}"); } diff --git a/hai-service/src/main/java/com/hai/dao/HighGasStaffMapper.java b/hai-service/src/main/java/com/hai/dao/HighGasStaffMapper.java index ef3c8780..eda69347 100644 --- a/hai-service/src/main/java/com/hai/dao/HighGasStaffMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighGasStaffMapper.java @@ -42,15 +42,15 @@ public interface HighGasStaffMapper extends HighGasStaffMapperExt { "insert into high_gas_staff (merchant_store_id, avatar, ", "`name`, telephone, ", "position_type, position_name, ", - "`status`, create_time, ", - "update_time, ext_1, ", - "ext_2, ext_3)", + "qr_code_img_url, `status`, ", + "create_time, update_time, ", + "ext_1, ext_2, ext_3)", "values (#{merchantStoreId,jdbcType=BIGINT}, #{avatar,jdbcType=VARCHAR}, ", "#{name,jdbcType=VARCHAR}, #{telephone,jdbcType=VARCHAR}, ", "#{positionType,jdbcType=INTEGER}, #{positionName,jdbcType=VARCHAR}, ", - "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{updateTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{qrCodeImgUrl,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighGasStaff record); @@ -68,6 +68,7 @@ public interface HighGasStaffMapper extends HighGasStaffMapperExt { @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR), @Result(column="position_type", property="positionType", jdbcType=JdbcType.INTEGER), @Result(column="position_name", property="positionName", jdbcType=JdbcType.VARCHAR), + @Result(column="qr_code_img_url", property="qrCodeImgUrl", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -80,7 +81,7 @@ public interface HighGasStaffMapper extends HighGasStaffMapperExt { @Select({ "select", "id, merchant_store_id, avatar, `name`, telephone, position_type, position_name, ", - "`status`, create_time, update_time, ext_1, ext_2, ext_3", + "qr_code_img_url, `status`, create_time, update_time, ext_1, ext_2, ext_3", "from high_gas_staff", "where id = #{id,jdbcType=BIGINT}" }) @@ -92,6 +93,7 @@ public interface HighGasStaffMapper extends HighGasStaffMapperExt { @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR), @Result(column="position_type", property="positionType", jdbcType=JdbcType.INTEGER), @Result(column="position_name", property="positionName", jdbcType=JdbcType.VARCHAR), + @Result(column="qr_code_img_url", property="qrCodeImgUrl", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -118,6 +120,7 @@ public interface HighGasStaffMapper extends HighGasStaffMapperExt { "telephone = #{telephone,jdbcType=VARCHAR},", "position_type = #{positionType,jdbcType=INTEGER},", "position_name = #{positionName,jdbcType=VARCHAR},", + "qr_code_img_url = #{qrCodeImgUrl,jdbcType=VARCHAR},", "`status` = #{status,jdbcType=INTEGER},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "update_time = #{updateTime,jdbcType=TIMESTAMP},", diff --git a/hai-service/src/main/java/com/hai/dao/HighGasStaffSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighGasStaffSqlProvider.java index 620cccd1..d0f2fec5 100644 --- a/hai-service/src/main/java/com/hai/dao/HighGasStaffSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighGasStaffSqlProvider.java @@ -52,6 +52,10 @@ public class HighGasStaffSqlProvider { sql.VALUES("position_name", "#{positionName,jdbcType=VARCHAR}"); } + if (record.getQrCodeImgUrl() != null) { + sql.VALUES("qr_code_img_url", "#{qrCodeImgUrl,jdbcType=VARCHAR}"); + } + if (record.getStatus() != null) { sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } @@ -92,6 +96,7 @@ public class HighGasStaffSqlProvider { sql.SELECT("telephone"); sql.SELECT("position_type"); sql.SELECT("position_name"); + sql.SELECT("qr_code_img_url"); sql.SELECT("`status`"); sql.SELECT("create_time"); sql.SELECT("update_time"); @@ -143,6 +148,10 @@ public class HighGasStaffSqlProvider { sql.SET("position_name = #{record.positionName,jdbcType=VARCHAR}"); } + if (record.getQrCodeImgUrl() != null) { + sql.SET("qr_code_img_url = #{record.qrCodeImgUrl,jdbcType=VARCHAR}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } @@ -182,6 +191,7 @@ public class HighGasStaffSqlProvider { sql.SET("telephone = #{record.telephone,jdbcType=VARCHAR}"); sql.SET("position_type = #{record.positionType,jdbcType=INTEGER}"); sql.SET("position_name = #{record.positionName,jdbcType=VARCHAR}"); + sql.SET("qr_code_img_url = #{record.qrCodeImgUrl,jdbcType=VARCHAR}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); @@ -222,6 +232,10 @@ public class HighGasStaffSqlProvider { sql.SET("position_name = #{positionName,jdbcType=VARCHAR}"); } + if (record.getQrCodeImgUrl() != null) { + sql.SET("qr_code_img_url = #{qrCodeImgUrl,jdbcType=VARCHAR}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{status,jdbcType=INTEGER}"); } diff --git a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java index 1b3c8122..f2c88454 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java @@ -1081,6 +1081,14 @@ public interface HighOrderMapperExt { " and to_days(pay_time) = to_days(now())"}) Map selectGasTheDayOrderCount(@Param("storeId") Long storeId, @Param("status") String status); + @Select({" select" + + " case when SUM(b.total_price) is null then 0 else SUM(b.total_price) end price," + + " count(1) count" + + " from high_child_order a,high_order b " + + " where a.order_id = b.id and goods_type = 3 and gas_staff_id = #{gasStaffId} and b.order_status in (${status}) " + + " and to_days(pay_time) = to_days(now())"}) + Map selectGasStaffTheDayOrderCount(@Param("gasStaffId") Long gasStaffId, @Param("status") String status); + @Select({" select" + " case when SUM(b.total_price) is null then 0 else SUM(b.total_price) end price," + " count(1) count" + @@ -1088,6 +1096,13 @@ public interface HighOrderMapperExt { " where a.order_id = b.id and goods_type = 3 and goods_id = #{storeId} and b.order_status in (${status}) "}) Map selectGasHistoryOrderCount(@Param("storeId") Long storeId, @Param("status") String status); + @Select({" select" + + " case when SUM(b.total_price) is null then 0 else SUM(b.total_price) end price," + + " count(1) count" + + " from high_child_order a,high_order b " + + " where a.order_id = b.id and goods_type = 3 and gas_staff_id = #{gasStaffId} and b.order_status in (${status}) "}) + Map selectGasStaffHistoryOrderCount(@Param("gasStaffId") Long gasStaffId, @Param("status") String status); + @Select({ ""}) List getUserCouponsList(@Param("map") Map map); + + + @Select({" 100 ]]> "}) + Integer receiveDiscountCount(@Param("userId") Long userId, @Param("discountId") Long discountId); } diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscount.java b/hai-service/src/main/java/com/hai/entity/HighDiscount.java index 24986d9c..b577a2e5 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscount.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscount.java @@ -69,6 +69,11 @@ public class HighDiscount implements Serializable { */ private BigDecimal discountPrice; + /** + * 领取次数 + */ + private Integer receiveNumber; + /** * 领取有效天数 */ @@ -200,6 +205,14 @@ public class HighDiscount implements Serializable { this.discountPrice = discountPrice; } + public Integer getReceiveNumber() { + return receiveNumber; + } + + public void setReceiveNumber(Integer receiveNumber) { + this.receiveNumber = receiveNumber; + } + public Integer getEffectiveDay() { return effectiveDay; } @@ -303,6 +316,7 @@ public class HighDiscount implements Serializable { && (this.getDiscountType() == null ? other.getDiscountType() == null : this.getDiscountType().equals(other.getDiscountType())) && (this.getDiscountCondition() == null ? other.getDiscountCondition() == null : this.getDiscountCondition().equals(other.getDiscountCondition())) && (this.getDiscountPrice() == null ? other.getDiscountPrice() == null : this.getDiscountPrice().equals(other.getDiscountPrice())) + && (this.getReceiveNumber() == null ? other.getReceiveNumber() == null : this.getReceiveNumber().equals(other.getReceiveNumber())) && (this.getEffectiveDay() == null ? other.getEffectiveDay() == null : this.getEffectiveDay().equals(other.getEffectiveDay())) && (this.getSalesEndTime() == null ? other.getSalesEndTime() == null : this.getSalesEndTime().equals(other.getSalesEndTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) @@ -330,6 +344,7 @@ public class HighDiscount implements Serializable { result = prime * result + ((getDiscountType() == null) ? 0 : getDiscountType().hashCode()); result = prime * result + ((getDiscountCondition() == null) ? 0 : getDiscountCondition().hashCode()); result = prime * result + ((getDiscountPrice() == null) ? 0 : getDiscountPrice().hashCode()); + result = prime * result + ((getReceiveNumber() == null) ? 0 : getReceiveNumber().hashCode()); result = prime * result + ((getEffectiveDay() == null) ? 0 : getEffectiveDay().hashCode()); result = prime * result + ((getSalesEndTime() == null) ? 0 : getSalesEndTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); @@ -360,6 +375,7 @@ public class HighDiscount implements Serializable { sb.append(", discountType=").append(discountType); sb.append(", discountCondition=").append(discountCondition); sb.append(", discountPrice=").append(discountPrice); + sb.append(", receiveNumber=").append(receiveNumber); sb.append(", effectiveDay=").append(effectiveDay); sb.append(", salesEndTime=").append(salesEndTime); sb.append(", createTime=").append(createTime); diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountExample.java b/hai-service/src/main/java/com/hai/entity/HighDiscountExample.java index 7e6bca34..f5708b9d 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountExample.java @@ -826,6 +826,66 @@ public class HighDiscountExample { return (Criteria) this; } + public Criteria andReceiveNumberIsNull() { + addCriterion("receive_number is null"); + return (Criteria) this; + } + + public Criteria andReceiveNumberIsNotNull() { + addCriterion("receive_number is not null"); + return (Criteria) this; + } + + public Criteria andReceiveNumberEqualTo(Integer value) { + addCriterion("receive_number =", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberNotEqualTo(Integer value) { + addCriterion("receive_number <>", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberGreaterThan(Integer value) { + addCriterion("receive_number >", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberGreaterThanOrEqualTo(Integer value) { + addCriterion("receive_number >=", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberLessThan(Integer value) { + addCriterion("receive_number <", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberLessThanOrEqualTo(Integer value) { + addCriterion("receive_number <=", value, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberIn(List values) { + addCriterion("receive_number in", values, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberNotIn(List values) { + addCriterion("receive_number not in", values, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberBetween(Integer value1, Integer value2) { + addCriterion("receive_number between", value1, value2, "receiveNumber"); + return (Criteria) this; + } + + public Criteria andReceiveNumberNotBetween(Integer value1, Integer value2) { + addCriterion("receive_number not between", value1, value2, "receiveNumber"); + return (Criteria) this; + } + public Criteria andEffectiveDayIsNull() { addCriterion("effective_day is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountService.java b/hai-service/src/main/java/com/hai/service/HighDiscountService.java index 8661c42b..e727f3b3 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountService.java @@ -33,6 +33,13 @@ public interface HighDiscountService { **/ HighDiscount getDiscountById(Long id); + /** + * 根据优惠券key查询 + * @param discountKey + * @return + */ + HighDiscount getDiscountByKey(String discountKey); + /** * @Author 胡锐 * @Description 查询优惠券列表 diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java index b3cfb23f..becdd024 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java @@ -15,11 +15,18 @@ public interface HighDiscountUserRelService { /** * @Author 胡锐 - * @Description 领取优惠券 + * @Description 领取优惠券code * @Date 2021/4/4 15:12 **/ void receiveDiscount(Long userId,Long codeId); + /** + * @Author 胡锐 + * @Description 领取优惠券 + * @Date 2021/4/4 15:12 + **/ + void receive(Long userId, Long discountAgentId); + /** * @Author 胡锐 * @Description 修改 @@ -62,5 +69,12 @@ public interface HighDiscountUserRelService { **/ List getExpiredDiscount(); + /** + * 领取优惠券统计 + * @param userId + * @param discountId + * @return + */ + Integer receiveDiscountCount(Long userId,Long discountId); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountServiceImpl.java index 56be673e..949804e8 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountServiceImpl.java @@ -39,6 +39,17 @@ public class HighDiscountServiceImpl implements HighDiscountService { return highDiscountMapper.selectByPrimaryKey(id); } + @Override + public HighDiscount getDiscountByKey(String discountKey) { + HighDiscountExample example = new HighDiscountExample(); + example.createCriteria().andDiscountKeyEqualTo(discountKey).andStatusNotEqualTo(0); + List list = highDiscountMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + @Override public List getDiscount(Map map) { HighDiscountExample example = new HighDiscountExample(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index 282748af..f7b9360c 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -51,7 +51,6 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic if(code == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在"); } - // 状态 0:删除 1:待领取 2:待使用 3:已使用 4:已过期 5: 已分配 if(code.getStatus() != 1 && code.getStatus() != 5) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在或已被领取"); @@ -67,6 +66,18 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic rel.setStockCount(rel.getStockCount() - 1); highDiscountAgentRelService.updateDiscountAgentRel(rel); + // 查询优惠券信息 + HighDiscount discount = highDiscountService.getDiscountById(rel.getDiscountId()); + if (discount == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券信息"); + } + if (!discount.getStatus().equals(2)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期"); + } + if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) < discount.getReceiveNumber()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线"); + } + // 校验卡卷状态 if (rel.getHighDiscount().getStatus() != 2) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券已过期"); @@ -106,6 +117,61 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) + public void receive(Long userId, Long discountAgentId) { + // 查询优惠券与代理商关系 + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelById(discountAgentId); + if (discountAgentRel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券"); + } + // 查询优惠券信息 + HighDiscount discount = discountAgentRel.getHighDiscount(); + if (discount == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券"); + } + if (!discount.getStatus().equals(2)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期"); + } + if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) < discount.getReceiveNumber()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线"); + } + // 查询可分配的优惠券code + List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId()); + if (discountAgentCodeList.size() == 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已无库存"); + } + HighDiscountAgentCode code = discountAgentCodeList.get(0); + code.setStatus(2); + highDiscountAgentCodeService.updateCode(code); + + // 查询优惠券信息 + discountAgentRel.setStockCount(discountAgentRel.getStockCount() - 1); + highDiscountAgentRelService.updateDiscountAgentRel(discountAgentRel); + + HighDiscountUserRel userRel = new HighDiscountUserRel(); + userRel.setDiscountId(discountAgentRel.getDiscountId()); + userRel.setAgentId(discountAgentRel.getAgentId()); + userRel.setUserId(userId); + userRel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + userRel.setCreateTime(new Date()); + userRel.setDiscountAgentCodeId(code.getId()); + // 计算使用有效期 + Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); + userEndTime.add(Calendar.DATE, discountAgentRel.getHighDiscount().getEffectiveDay()); + + if (userEndTime.getTime().compareTo(discountAgentRel.getHighDiscount().getSalesEndTime()) == 1) { + userRel.setUseEndTime(discountAgentRel.getHighDiscount().getSalesEndTime()); + } else { + userRel.setUseEndTime(userEndTime.getTime()); + } + highDiscountUserRelMapper.insert(userRel); + } + @Override public void updateDiscountUserRel(HighDiscountUserRel highDiscountUserRel) { highDiscountUserRelMapper.updateByPrimaryKey(highDiscountUserRel); @@ -171,4 +237,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic example.createCriteria().andStatusEqualTo(1).andUseEndTimeLessThanOrEqualTo(new Date()); return highDiscountUserRelMapper.selectByExample(example); } + + @Override + public Integer receiveDiscountCount(Long userId, Long discountId) { + return highDiscountUserRelMapper.receiveDiscountCount(userId, discountId); + } } From c8b3bfabd9f9df61249509a3f2e7e69afd7c4c52 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Sat, 9 Jul 2022 12:12:44 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=9C=BA=E5=BB=B6=E8=BF=9F=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hai/service/impl/HighOrderServiceImpl.java | 6 ------ 1 file changed, 6 deletions(-) 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 7802c161..e2209bf3 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 @@ -1685,9 +1685,6 @@ public class HighOrderServiceImpl implements HighOrderService { childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() ), 1); - - Thread.sleep(6000); - sp.print(device.getDeviceSn(), SpPrinterTemplate.oilClientStubTemp( childOrder.getGoodsName(), @@ -1719,9 +1716,6 @@ public class HighOrderServiceImpl implements HighOrderService { childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() )); - - Thread.sleep(6000); - mqttProviderConfig.publish(2, false, device.getDeviceImei(), ZkcPrinterTemplate.oilClientStubTemp( childOrder.getGoodsName(), From 6c81bea10789a6a6bf50f72a021e1a48380f8dbc Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 11 Jul 2022 10:35:55 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=B0=8F=E7=A5=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cweb/controller/HighTestController.java | 2 +- .../com/hai/config/SpPrinterTemplate.java | 18 +- .../com/hai/config/ZkcPrinterTemplate.java | 182 ++++++++++++++++++ .../service/impl/HighOrderServiceImpl.java | 55 +++--- 4 files changed, 226 insertions(+), 31 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java index d50d4e63..a9ae367d 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java @@ -1 +1 @@ -package com.cweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; import com.hai.common.Base64Util; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.security.SessionObject; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.bouncycastle.util.encoders.UrlBase64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.util.IdGenerator; import org.springframework.web.bind.annotation.*; import sun.nio.cs.StreamEncoder; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HighMerchantService highMerchantService; @Resource private HighMerchantStoreService highMerchantStoreService; @Resource private HighGasOilPriceService highGasOilPriceService; @Resource private HighOrderService highOrderService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private UnionPayConfig unionPayConfig; @Resource private UnionStagingPayConfig unionStagingPayConfig; @Resource private UnionUserConfig unionUserConfig; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOilCardService oilCardService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private MqttProviderConfig mqttProviderConfig; @Autowired private WebSocket webSocket; @RequestMapping(value = "/wxGasProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "wxGasProfitsharing") public ResponseData wxGasProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { // 查询订单 HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.05"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee); // 计算分账金额 手续费后的价格 * 0.05 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); this.wxGasProfitsharing(order.getExt1(), order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } public void wxGasProfitsharing(String appid,String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", appid); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(out_order_no); sharingRecord.setTransactionId(transaction_id); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } @RequestMapping(value = "/addPrinter", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData addPrinter(HttpServletRequest request) { try { SpPrinterConfig spPrinterConfig = new SpPrinterConfig(); return ResponseMsgUtil.success( spPrinterConfig.addPrinter( "1540500213", "bxpjpnh4", "丹凤加油站打印机" ) ); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryThirdOrderDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单结果查询") public ResponseData queryThirdOrderDretail(HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryThirdOrderDetail("HF2022051214411536507")); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/spPrint", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "发送打印机消息") public ResponseData spPrint(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : highOrder.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); new Thread(() -> { try { SpPrinterConfig sp = new SpPrinterConfig(); sp.print(store.getDeviceSn(), SpPrinterTemplate.oilCashierStubTemp( highChildOrder.getGoodsName(), highOrder.getOrderNo(), DateUtil.date2String(highOrder.getPayTime(), "yyyy-MM-dd HH:mm:ss"), "嗨森逛", highChildOrder.getGasGunNo(), highChildOrder.getGasOilNo(), highChildOrder.getGasOilLiters().toString(), highOrder.getTotalPrice().toString() ), 1); Thread.sleep(6000); sp.print(store.getDeviceSn(), SpPrinterTemplate.oilClientStubTemp( highChildOrder.getGoodsName(), highOrder.getOrderNo(), DateUtil.date2String(highOrder.getPayTime(), "yyyy-MM-dd HH:mm:ss"), "嗨森逛", highChildOrder.getGasGunNo(), highChildOrder.getGasOilNo(), highChildOrder.getGasOilLiters().toString(), highOrder.getTotalPrice().toString() ), 1); } catch (Exception e) { e.printStackTrace(); } }).start(); } return ResponseMsgUtil.success("发送成功"); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/text2audio", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "文本转语音") public ResponseData text2audio(HttpServletRequest request) { try { return ResponseMsgUtil.success(baiduVoiceService.text2audio("加油站收款400元")); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getGasDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData getGasDetail(@RequestParam(name = "cardNo", required = true) String cardNo, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(cardNo)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryGasInfoByGasId", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据油站 id 拉取最新的油站数据") public ResponseData queryGasInfoByGasId(@RequestParam(name = "gasId", required = true) String gasId, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(gasId)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } // // @RequestMapping(value = "/getMobile", method = RequestMethod.GET) // @ResponseBody // @ApiOperation(value = "话费充值") // public ResponseData getMobile( // @RequestParam(name = "orderNo", required = true) String orderNo, // @RequestParam(name = "amount", required = true) Integer amount, // @RequestParam(name = "phone", required = true) String phone, // HttpServletRequest request) { // try { // return ResponseMsgUtil.success(outRechargeOrderService.getMobile(phone,amount,orderNo)); // // } catch (Exception e) { // log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); // return ResponseMsgUtil.exception(e); // } // } @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/detectTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "检测加油站") public ResponseData detectTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } Map param = new HashMap<>(); param.put("merchantId", merchant.getId()); List stores = highMerchantStoreService.getMerchantStoreList(param); for (HighMerchantStore store : stores) { JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(store.getStoreKey()); if (jsonObject != null && jsonObject.getString("code").equals("200")) { JSONObject result = jsonObject.getJSONObject("result"); store.setStatus(result.getInteger("gasStatus")); } else { store.setStatus(0); } highMerchantStoreService.updateMerchantStoreDetail(store); } return ResponseMsgUtil.success("初始化完成"); } /* @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } */ @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyPriceDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyPriceDetail() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyPriceDetail("LW000115995", "92")); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF2022031509263475105","20JY000575",1,"18385214742", "oArhO6QZSIJAcawo1Wwx5cKKZ0ns")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/tradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData tradeQuery(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData zwrefund() { try { return ResponseMsgUtil.success(UnionPayConfig.cancel(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF" + System.currentTimeMillis(), "31720220622093814132759")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay(HttpServletRequest request) { try { // return ResponseMsgUtil.success(RequestUtils.getIpAddress(request)); return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, "HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(unionUserConfig.getBackendToken()); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionStagingPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联分期支付") public ResponseData unionStagingPay(HttpServletRequest request) { try { /* String orderNo = DateUtil.format(new Date(), DateUtil.YMDHMS); orderNo += IDGenerator.nextId(28 - orderNo.length());*/ String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(unionStagingPayConfig.advancePay( orgTrace, orgTrace, new BigDecimal("1"), CommonSysConst.getSysConfig().getUnionStagingPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryStaging", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期查询") public ResponseData queryStaging(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.queryStaging(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } /* @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "退款") public ResponseData orderToRefund(HttpServletRequest request) { try { OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund("4200001301202202035413938093", new BigDecimal("30.80"), new BigDecimal("16.90")); return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } }*/ @RequestMapping(value = "/query", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单查询") public ResponseData query(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.query(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款") public ResponseData mposrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.standardRefund(orgTrace,oriOrgTrace ,new BigDecimal("1"), "", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposfindrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款查询") public ResponseData mposfindrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.mposfindrefund(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket(@RequestParam(name = "orderNo", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://127.0.0.1:9901/msg/test/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("null"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mqttPush", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "mqttPush") public void mqttPush(@RequestParam(name = "orderNo", required = true) String orderNo, @RequestParam(name = "topic", required = true) String topic) { try { /* HighOrder order = highOrderService.getOrderByOrderNo("HF2022061411034235002"); for (HighChildOrder childOrder : order.getHighChildOrderList()) { String printText = ZkcPrinterTemplate.oilCashierStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() ); System.out.println(printText); mqttProviderConfig.publish(2, false, topic, ZkcPrinterTemplate.hexStringToString(printText)); }*/ /* for (int i = 1; i < 100; i++) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write(("序号:" + i + " ,打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); stream.write(0x0A); stream.write(0x0A); stream.write(0x0A); stream.write(0x0A); // 发送消息 mqttProviderConfig.publish(2, false, topic, getPrinterBytes(stream.toByteArray(), 1, "UTF-8")); }*/ HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder childOrder : order.getHighChildOrderList()) { // highOrderService.printGasOrder(childOrder.getGoodsId(), order.getOrderNo()); mqttProviderConfig.publish(2, false, topic, ZkcPrinterTemplate.oilCashierStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() )); } // Thread.sleep(6000); // return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> mqttPush() error!", e); // return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/gasPageQueryAllStation", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "gasPageQueryAllStation") public ResponseData gasPageQueryAllStation() { try { return ResponseMsgUtil.success(ShellGroupService.gasPageQueryAllStation(1, 50)); } catch (Exception e) { log.error("HighOrderController --> gasPageQueryAllStation() error!", e); return ResponseMsgUtil.exception(e); } } public static String hexStringToString(String s) { if (s == null || s.equals("")) { return null; } s = s.replace(" ", ""); byte[] baKeyword = new byte[s.length() / 2]; for (int i = 0; i < baKeyword.length; i++) { try { baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16)); } catch (Exception e) { e.printStackTrace(); } } try { s = new String(baKeyword, "UTF-8"); } catch (Exception e1) { e1.printStackTrace(); } return s; } /** * 获取打印内容,适用于云打印机 * @param printText 打印文本 * @param pageCount 打印联数 * @param encodingStr 编码方式,默认UTF-8 * @return */ public byte[] getPrinterBytes(final byte[] printText, final int pageCount, String encodingStr) { try { byte[] array = new byte[printText.length + 9]; array[0] = 30; array[1] = 16; array[2] =(byte) pageCount;//打印份数 int num = array.length - 5; array[3] = (byte)(num >> 8); //array[4] = (byte)((uint)num & 0xFFu); array[4] = (byte)(num & 0xFF); for (int i = 0; i < printText.length; i++) { array[i+ 5] = printText[i]; } array[array.length - 4] = 27; array[array.length - 3] = 99; byte[] crc16CodeArray =getCRC(printText); array[array.length - 2] = crc16CodeArray[0]; array[array.length - 1] = crc16CodeArray[1]; return array; /* if(encodingStr.equals("")){ encodingStr="UTF-8"; } byte[] msgByte = printText; // 消息数组 final byte[] dataByte = new byte[msgByte.length + 9]; dataByte[0] = 0x1E; dataByte[1] = 0x10; dataByte[2] = (byte) pageCount;// 打印多联 // 有效数据长度 final int len = dataByte.length - 5; dataByte[3] = (byte) (len >> 8); dataByte[4] = (byte) (len & 0xff); // 数据内容 System.arraycopy(msgByte, 0, dataByte, 5, msgByte.length); // 标识字节 dataByte[dataByte.length - 4] = 0x1b; dataByte[dataByte.length - 3] = 0x63; // 打印内容CRC校验 final byte[] dtCRC = getCRC(msgByte); dataByte[dataByte.length - 2] = (byte) (dtCRC[0]); dataByte[dataByte.length - 1] = (byte) (dtCRC[1]); msgByte = dataByte; return msgByte;*/ } catch (Exception ex) { System.out.println(ex.getStackTrace()); } return null; } /** * 获取打印内容,适用于云打印机 * @param printText 打印文本 * @param pageCount 打印联数 * @param encodingStr 编码方式,默认UTF-8 * @return */ public byte[] getPrinterBytes(final String printText, final int pageCount, String encodingStr) { try { if(encodingStr.equals("")){ encodingStr="UTF-8"; } byte[] msgByte = printText.getBytes(encodingStr); // 消息数组 final byte[] dataByte = new byte[msgByte.length + 9]; dataByte[0] = 0x1E; dataByte[1] = 0x10; dataByte[2] = (byte) pageCount;// 打印多联 // 有效数据长度 final int len = dataByte.length - 5; dataByte[3] = (byte) (len >> 8); dataByte[4] = (byte) (len & 0xff); // 数据内容 System.arraycopy(msgByte, 0, dataByte, 5, msgByte.length); // 标识字节 dataByte[dataByte.length - 4] = 0x1b; dataByte[dataByte.length - 3] = 0x63; // 打印内容CRC校验 final byte[] dtCRC = getCRC(msgByte); dataByte[dataByte.length - 2] = (byte) (dtCRC[0]); dataByte[dataByte.length - 1] = (byte) (dtCRC[1]); msgByte = dataByte; return msgByte; } catch (Exception ex) { System.out.println(ex.getStackTrace()); } return null; } private static int[] CRC16Table = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; private static byte[] getCRC(byte[] bytes) { int crc = 0xFFFF; // 初始值 for (byte b : bytes) { crc = (crc >> 8) ^ CRC16Table[(crc ^ b) & 0xff]; } byte[] b = new byte[2]; b[0] = (byte) ((crc >> 8)^0xff); b[1] = (byte) ((crc & 0xff)^0xff); return b; } private static final char[] HEXES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * byte数组 转换成 16进制小写字符串 */ private String bytes2Hex(byte[] bytes) { if (bytes == null || bytes.length == 0) { return null; } StringBuilder hex = new StringBuilder(); for (byte b : bytes) { hex.append(HEXES[(b >> 4) & 0x0F]); hex.append(HEXES[b & 0x0F]); } return hex.toString(); } } \ No newline at end of file +package com.cweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; import com.hai.common.Base64Util; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.security.SessionObject; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.bouncycastle.util.encoders.UrlBase64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.util.IdGenerator; import org.springframework.web.bind.annotation.*; import sun.nio.cs.StreamEncoder; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HighMerchantService highMerchantService; @Resource private HighMerchantStoreService highMerchantStoreService; @Resource private HighGasOilPriceService highGasOilPriceService; @Resource private HighOrderService highOrderService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private UnionPayConfig unionPayConfig; @Resource private UnionStagingPayConfig unionStagingPayConfig; @Resource private UnionUserConfig unionUserConfig; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOilCardService oilCardService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private MqttProviderConfig mqttProviderConfig; @Autowired private WebSocket webSocket; @RequestMapping(value = "/wxGasProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "wxGasProfitsharing") public ResponseData wxGasProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { // 查询订单 HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.05"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee); // 计算分账金额 手续费后的价格 * 0.05 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); this.wxGasProfitsharing(order.getExt1(), order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } public void wxGasProfitsharing(String appid,String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", appid); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(out_order_no); sharingRecord.setTransactionId(transaction_id); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } @RequestMapping(value = "/addPrinter", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData addPrinter(HttpServletRequest request) { try { SpPrinterConfig spPrinterConfig = new SpPrinterConfig(); return ResponseMsgUtil.success( spPrinterConfig.addPrinter( "1540500213", "bxpjpnh4", "丹凤加油站打印机" ) ); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryThirdOrderDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单结果查询") public ResponseData queryThirdOrderDretail(HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryThirdOrderDetail("HF2022051214411536507")); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/spPrint", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "发送打印机消息") public ResponseData spPrint(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : highOrder.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); new Thread(() -> { try { highOrderService.printGasOrder(store.getId(), highOrder); } catch (Exception e) { e.printStackTrace(); } }).start(); } return ResponseMsgUtil.success("发送成功"); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/text2audio", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "文本转语音") public ResponseData text2audio(HttpServletRequest request) { try { return ResponseMsgUtil.success(baiduVoiceService.text2audio("加油站收款400元")); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getGasDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData getGasDetail(@RequestParam(name = "cardNo", required = true) String cardNo, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(cardNo)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryGasInfoByGasId", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据油站 id 拉取最新的油站数据") public ResponseData queryGasInfoByGasId(@RequestParam(name = "gasId", required = true) String gasId, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(gasId)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } // // @RequestMapping(value = "/getMobile", method = RequestMethod.GET) // @ResponseBody // @ApiOperation(value = "话费充值") // public ResponseData getMobile( // @RequestParam(name = "orderNo", required = true) String orderNo, // @RequestParam(name = "amount", required = true) Integer amount, // @RequestParam(name = "phone", required = true) String phone, // HttpServletRequest request) { // try { // return ResponseMsgUtil.success(outRechargeOrderService.getMobile(phone,amount,orderNo)); // // } catch (Exception e) { // log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); // return ResponseMsgUtil.exception(e); // } // } @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/detectTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "检测加油站") public ResponseData detectTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } Map param = new HashMap<>(); param.put("merchantId", merchant.getId()); List stores = highMerchantStoreService.getMerchantStoreList(param); for (HighMerchantStore store : stores) { JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(store.getStoreKey()); if (jsonObject != null && jsonObject.getString("code").equals("200")) { JSONObject result = jsonObject.getJSONObject("result"); store.setStatus(result.getInteger("gasStatus")); } else { store.setStatus(0); } highMerchantStoreService.updateMerchantStoreDetail(store); } return ResponseMsgUtil.success("初始化完成"); } /* @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } */ @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyPriceDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyPriceDetail() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyPriceDetail("LW000115995", "92")); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF2022031509263475105","20JY000575",1,"18385214742", "oArhO6QZSIJAcawo1Wwx5cKKZ0ns")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/tradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData tradeQuery(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData zwrefund() { try { return ResponseMsgUtil.success(UnionPayConfig.cancel(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF" + System.currentTimeMillis(), "31720220622093814132759")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay(HttpServletRequest request) { try { // return ResponseMsgUtil.success(RequestUtils.getIpAddress(request)); return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, "HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(unionUserConfig.getBackendToken()); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionStagingPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联分期支付") public ResponseData unionStagingPay(HttpServletRequest request) { try { /* String orderNo = DateUtil.format(new Date(), DateUtil.YMDHMS); orderNo += IDGenerator.nextId(28 - orderNo.length());*/ String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(unionStagingPayConfig.advancePay( orgTrace, orgTrace, new BigDecimal("1"), CommonSysConst.getSysConfig().getUnionStagingPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryStaging", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期查询") public ResponseData queryStaging(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.queryStaging(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } /* @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "退款") public ResponseData orderToRefund(HttpServletRequest request) { try { OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund("4200001301202202035413938093", new BigDecimal("30.80"), new BigDecimal("16.90")); return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } }*/ @RequestMapping(value = "/query", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单查询") public ResponseData query(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.query(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款") public ResponseData mposrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.standardRefund(orgTrace,oriOrgTrace ,new BigDecimal("1"), "", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposfindrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款查询") public ResponseData mposfindrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.mposfindrefund(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket(@RequestParam(name = "orderNo", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://127.0.0.1:9901/msg/test/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("null"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mqttPush", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "mqttPush") public void mqttPush(@RequestParam(name = "orderNo", required = true) String orderNo, @RequestParam(name = "topic", required = true) String topic) { try { /* HighOrder order = highOrderService.getOrderByOrderNo("HF2022061411034235002"); for (HighChildOrder childOrder : order.getHighChildOrderList()) { String printText = ZkcPrinterTemplate.oilCashierStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() ); System.out.println(printText); mqttProviderConfig.publish(2, false, topic, ZkcPrinterTemplate.hexStringToString(printText)); }*/ /* for (int i = 1; i < 100; i++) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write(("序号:" + i + " ,打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); stream.write(0x0A); stream.write(0x0A); stream.write(0x0A); stream.write(0x0A); // 发送消息 mqttProviderConfig.publish(2, false, topic, getPrinterBytes(stream.toByteArray(), 1, "UTF-8")); }*/ HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder childOrder : order.getHighChildOrderList()) { // highOrderService.printGasOrder(childOrder.getGoodsId(), order.getOrderNo()); mqttProviderConfig.publish(2, false, topic, ZkcPrinterTemplate.oilCashierStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), order.getMemPhone(), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() )); } // Thread.sleep(6000); // return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> mqttPush() error!", e); // return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/gasPageQueryAllStation", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "gasPageQueryAllStation") public ResponseData gasPageQueryAllStation() { try { return ResponseMsgUtil.success(ShellGroupService.gasPageQueryAllStation(1, 50)); } catch (Exception e) { log.error("HighOrderController --> gasPageQueryAllStation() error!", e); return ResponseMsgUtil.exception(e); } } public static String hexStringToString(String s) { if (s == null || s.equals("")) { return null; } s = s.replace(" ", ""); byte[] baKeyword = new byte[s.length() / 2]; for (int i = 0; i < baKeyword.length; i++) { try { baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16)); } catch (Exception e) { e.printStackTrace(); } } try { s = new String(baKeyword, "UTF-8"); } catch (Exception e1) { e1.printStackTrace(); } return s; } /** * 获取打印内容,适用于云打印机 * @param printText 打印文本 * @param pageCount 打印联数 * @param encodingStr 编码方式,默认UTF-8 * @return */ public byte[] getPrinterBytes(final byte[] printText, final int pageCount, String encodingStr) { try { byte[] array = new byte[printText.length + 9]; array[0] = 30; array[1] = 16; array[2] =(byte) pageCount;//打印份数 int num = array.length - 5; array[3] = (byte)(num >> 8); //array[4] = (byte)((uint)num & 0xFFu); array[4] = (byte)(num & 0xFF); for (int i = 0; i < printText.length; i++) { array[i+ 5] = printText[i]; } array[array.length - 4] = 27; array[array.length - 3] = 99; byte[] crc16CodeArray =getCRC(printText); array[array.length - 2] = crc16CodeArray[0]; array[array.length - 1] = crc16CodeArray[1]; return array; /* if(encodingStr.equals("")){ encodingStr="UTF-8"; } byte[] msgByte = printText; // 消息数组 final byte[] dataByte = new byte[msgByte.length + 9]; dataByte[0] = 0x1E; dataByte[1] = 0x10; dataByte[2] = (byte) pageCount;// 打印多联 // 有效数据长度 final int len = dataByte.length - 5; dataByte[3] = (byte) (len >> 8); dataByte[4] = (byte) (len & 0xff); // 数据内容 System.arraycopy(msgByte, 0, dataByte, 5, msgByte.length); // 标识字节 dataByte[dataByte.length - 4] = 0x1b; dataByte[dataByte.length - 3] = 0x63; // 打印内容CRC校验 final byte[] dtCRC = getCRC(msgByte); dataByte[dataByte.length - 2] = (byte) (dtCRC[0]); dataByte[dataByte.length - 1] = (byte) (dtCRC[1]); msgByte = dataByte; return msgByte;*/ } catch (Exception ex) { System.out.println(ex.getStackTrace()); } return null; } /** * 获取打印内容,适用于云打印机 * @param printText 打印文本 * @param pageCount 打印联数 * @param encodingStr 编码方式,默认UTF-8 * @return */ public byte[] getPrinterBytes(final String printText, final int pageCount, String encodingStr) { try { if(encodingStr.equals("")){ encodingStr="UTF-8"; } byte[] msgByte = printText.getBytes(encodingStr); // 消息数组 final byte[] dataByte = new byte[msgByte.length + 9]; dataByte[0] = 0x1E; dataByte[1] = 0x10; dataByte[2] = (byte) pageCount;// 打印多联 // 有效数据长度 final int len = dataByte.length - 5; dataByte[3] = (byte) (len >> 8); dataByte[4] = (byte) (len & 0xff); // 数据内容 System.arraycopy(msgByte, 0, dataByte, 5, msgByte.length); // 标识字节 dataByte[dataByte.length - 4] = 0x1b; dataByte[dataByte.length - 3] = 0x63; // 打印内容CRC校验 final byte[] dtCRC = getCRC(msgByte); dataByte[dataByte.length - 2] = (byte) (dtCRC[0]); dataByte[dataByte.length - 1] = (byte) (dtCRC[1]); msgByte = dataByte; return msgByte; } catch (Exception ex) { System.out.println(ex.getStackTrace()); } return null; } private static int[] CRC16Table = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; private static byte[] getCRC(byte[] bytes) { int crc = 0xFFFF; // 初始值 for (byte b : bytes) { crc = (crc >> 8) ^ CRC16Table[(crc ^ b) & 0xff]; } byte[] b = new byte[2]; b[0] = (byte) ((crc >> 8)^0xff); b[1] = (byte) ((crc & 0xff)^0xff); return b; } private static final char[] HEXES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * byte数组 转换成 16进制小写字符串 */ private String bytes2Hex(byte[] bytes) { if (bytes == null || bytes.length == 0) { return null; } StringBuilder hex = new StringBuilder(); for (byte b : bytes) { hex.append(HEXES[(b >> 4) & 0x0F]); hex.append(HEXES[b & 0x0F]); } return hex.toString(); } } \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java b/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java index fee25810..88fb65ff 100644 --- a/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java +++ b/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java @@ -1,5 +1,9 @@ package com.hai.config; +import com.hai.common.utils.DateUtil; + +import java.util.Date; + /** * 商鹏打印机模板 * @author hurui @@ -21,17 +25,20 @@ public class SpPrinterTemplate { public static String oilCashierStubTemp(String gasName, String orderNo, String payTime, + String phone, String source, String gunNo, String oilNo, String oilLiters, - String orderPrice) { + String orderPrice) throws Exception { String str = "" + gasName + "
" + "(收银员存根)
" + "------------------------------
" + "流水:" + orderNo + "
" + "------------------------------
" + - "时间:" + payTime + "
" + + "打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "
" + + "支付时间:" + payTime + "
" + + "电话:" + phone.substring(0, 3) + "****" + phone.substring(7) + "
" + "来源:" + source + "
" + "油枪:"+ gunNo + "号
" + "油品:" + oilNo + "#
" + @@ -60,17 +67,20 @@ public class SpPrinterTemplate { public static String oilClientStubTemp(String gasName, String orderNo, String payTime, + String phone, String source, String gunNo, String oilNo, String oilLiters, - String orderPrice) { + String orderPrice) throws Exception { String str = "" + gasName + "
" + "(客户存根)
" + "------------------------------
" + "流水:" + orderNo + "
" + "------------------------------
" + - "时间:" + payTime + "
" + + "打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "
" + + "支付时间:" + payTime + "
" + + "电话:" + phone.substring(0, 3) + "****" + phone.substring(7) + "
" + "来源:" + source + "
" + "油枪:"+ gunNo + "号
" + "油品:" + oilNo + "#
" + diff --git a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java index c6139e26..abdf415e 100644 --- a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java +++ b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java @@ -11,6 +11,180 @@ import java.util.Date; */ public class ZkcPrinterTemplate { + /** + * 加油站 + * @param gasName 油站名称 + * @param orderNo 订单号 + * @param payTime 支付时间 + * @param source 来源 + * @param gunNo 抢号 + * @param oilNo 油号 + * @param oilLiters 升数 + * @param orderPrice 加油金额 + * @return + */ + public static byte[] oilTemp(String gasName, + String orderNo, + String payTime, + String phone, + String source, + String gunNo, + String oilNo, + String oilLiters, + String orderPrice) throws Exception { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + // 居中 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + + stream.write(gasName.getBytes("UTF-8")); + stream.write(0x0A); + stream.write("(收银员存根)".getBytes("UTF-8")); + stream.write(0x0A); + + // 左对齐 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x00); + + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("流水号:" + orderNo).getBytes("UTF-8")); + stream.write(0x0A); + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("支付时间:" + payTime).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("来源:嗨森逛".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("油枪:" + gunNo).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("油品:" + oilNo).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("升数:" + oilLiters + "升").getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("实际加油升数以加油机为准!".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x0E); + + stream.write("加油金额".getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("¥" + orderPrice).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x21); + stream.write(0x00); + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + stream.write("开心又省钱;来“ 嗨森逛 ”".getBytes("UTF-8")); + + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + + + // 居中 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + + stream.write(gasName.getBytes("UTF-8")); + stream.write(0x0A); + stream.write("(客户存根)".getBytes("UTF-8")); + stream.write(0x0A); + + // 左对齐 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x00); + + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("流水号:" + orderNo).getBytes("UTF-8")); + stream.write(0x0A); + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("支付时间:" + payTime).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("来源:嗨森逛".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("油枪:" + gunNo).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("油品:" + oilNo).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(("升数:" + oilLiters + "升").getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("实际加油升数以加油机为准!".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x0E); + + stream.write("加油金额".getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("¥" + orderPrice).getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x21); + stream.write(0x00); + stream.write("--------------------------------".getBytes("UTF-8")); + stream.write(0x0A); + + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + stream.write("开心又省钱;来“ 嗨森逛 ”".getBytes("UTF-8")); + + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + return getPrinterBytes(stream.toByteArray(), 1, "UTF-8"); + } + /** * 加油站收银员存根模板 * @param gasName 油站名称 @@ -26,6 +200,7 @@ public class ZkcPrinterTemplate { public static byte[] oilCashierStubTemp(String gasName, String orderNo, String payTime, + String phone, String source, String gunNo, String oilNo, @@ -60,6 +235,9 @@ public class ZkcPrinterTemplate { stream.write(("支付时间:" + payTime).getBytes("UTF-8")); stream.write(0x0A); + stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8")); + stream.write(0x0A); + stream.write("来源:嗨森逛".getBytes("UTF-8")); stream.write(0x0A); @@ -119,6 +297,7 @@ public class ZkcPrinterTemplate { public static byte[] oilClientStubTemp(String gasName, String orderNo, String payTime, + String phone, String source, String gunNo, String oilNo, @@ -154,6 +333,9 @@ public class ZkcPrinterTemplate { stream.write(("支付时间:" + payTime).getBytes("UTF-8")); stream.write(0x0A); + stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8")); + stream.write(0x0A); + stream.write("来源:嗨森逛".getBytes("UTF-8")); stream.write(0x0A); 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 e2209bf3..0390f0f9 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 @@ -1674,28 +1674,42 @@ public class HighOrderServiceImpl implements HighOrderService { new Thread(() -> { try { SpPrinterConfig sp = new SpPrinterConfig(); - sp.print(device.getDeviceSn(), - SpPrinterTemplate.oilCashierStubTemp( - childOrder.getGoodsName(), - order.getOrderNo(), - DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), - "嗨森逛", - childOrder.getGasGunNo(), - childOrder.getGasOilNo(), - childOrder.getGasOilLiters().toString(), - order.getTotalPrice().toString() - ), 1); - sp.print(device.getDeviceSn(), + + String printStr = SpPrinterTemplate.oilCashierStubTemp( + childOrder.getGoodsName(), + order.getOrderNo(), + DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), + order.getMemPhone(), + "嗨森逛", + childOrder.getGasGunNo(), + childOrder.getGasOilNo(), + childOrder.getGasOilLiters().toString(), + order.getTotalPrice().toString() + ) + "




" + + SpPrinterTemplate.oilClientStubTemp( + childOrder.getGoodsName(), + order.getOrderNo(), + DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), + order.getMemPhone(), + "嗨森逛", + childOrder.getGasGunNo(), + childOrder.getGasOilNo(), + childOrder.getGasOilLiters().toString(), + order.getTotalPrice().toString() + ) + "
"; + sp.print(device.getDeviceSn(), printStr, 1); + /* sp.print(device.getDeviceSn(), SpPrinterTemplate.oilClientStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), + order.getMemPhone(), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() - ), 1); + ), 1);*/ } catch (Exception e) { e.printStackTrace(); } @@ -1706,28 +1720,17 @@ public class HighOrderServiceImpl implements HighOrderService { new Thread(() -> { try { mqttProviderConfig.publish(2, false, device.getDeviceImei(), - ZkcPrinterTemplate.oilCashierStubTemp( + ZkcPrinterTemplate.oilTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), + order.getMemPhone(), "嗨森逛", childOrder.getGasGunNo(), childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() )); - mqttProviderConfig.publish(2, false, device.getDeviceImei(), - ZkcPrinterTemplate.oilClientStubTemp( - childOrder.getGoodsName(), - order.getOrderNo(), - DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), - "嗨森逛", - childOrder.getGasGunNo(), - childOrder.getGasOilNo(), - childOrder.getGasOilLiters().toString(), - order.getTotalPrice().toString() - )); - } catch (Exception e) { e.getMessage(); } From 49e1471d4e5b276891db33492a2ff46b9029eb9d Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 11 Jul 2022 14:41:05 +0800 Subject: [PATCH 09/13] =?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 --- .../com/hai/config/ZkcPrinterTemplate.java | 2 ++ .../service/impl/HighOrderServiceImpl.java | 19 ++++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java index abdf415e..2bc51261 100644 --- a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java +++ b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java @@ -279,6 +279,8 @@ public class ZkcPrinterTemplate { stream.write(0x0A); stream.write(0x0A); stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); return getPrinterBytes(stream.toByteArray(), 1, "UTF-8"); } 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 0390f0f9..e024e5e0 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 @@ -1685,7 +1685,8 @@ public class HighOrderServiceImpl implements HighOrderService { childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() - ) + "




" + + ) + "
"; + /* + SpPrinterTemplate.oilClientStubTemp( childOrder.getGoodsName(), order.getOrderNo(), @@ -1696,20 +1697,8 @@ public class HighOrderServiceImpl implements HighOrderService { childOrder.getGasOilNo(), childOrder.getGasOilLiters().toString(), order.getTotalPrice().toString() - ) + "
"; + ) + "
";*/ sp.print(device.getDeviceSn(), printStr, 1); - /* sp.print(device.getDeviceSn(), - SpPrinterTemplate.oilClientStubTemp( - childOrder.getGoodsName(), - order.getOrderNo(), - DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), - order.getMemPhone(), - "嗨森逛", - childOrder.getGasGunNo(), - childOrder.getGasOilNo(), - childOrder.getGasOilLiters().toString(), - order.getTotalPrice().toString() - ), 1);*/ } catch (Exception e) { e.printStackTrace(); } @@ -1720,7 +1709,7 @@ public class HighOrderServiceImpl implements HighOrderService { new Thread(() -> { try { mqttProviderConfig.publish(2, false, device.getDeviceImei(), - ZkcPrinterTemplate.oilTemp( + ZkcPrinterTemplate.oilCashierStubTemp( childOrder.getGoodsName(), order.getOrderNo(), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), From 54ef27e2e92718263a5038bbb0794dff6090c478 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 11 Jul 2022 16:33:39 +0800 Subject: [PATCH 10/13] =?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 --- .../java/com/cweb/controller/HighUserDiscountController.java | 2 +- .../com/hai/service/impl/HighDiscountUserRelServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java index 6fde72c8..26dc7bf0 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -103,7 +103,7 @@ public class HighUserDiscountController { JSONObject jsonObject = JSONObject.parseObject(reqBody); String discountAgentCode = jsonObject.getString("code"); - if (StringUtils.isNotBlank(discountAgentCode)) { + if (StringUtils.isBlank(discountAgentCode)) { log.error("HighDiscountController -> receiveDiscount() error!", "参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index f7b9360c..2acc324d 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -137,7 +137,7 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线"); } // 查询可分配的优惠券code - List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId()); + List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByStatus(discountAgentRel.getId(), 1); if (discountAgentCodeList.size() == 0) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已无库存"); } From c82ca24c2deab53b7152277fbec80c3911edcb13 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 11 Jul 2022 17:32:38 +0800 Subject: [PATCH 11/13] =?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 --- .../src/main/java/com/hai/dao/HighOrderMapperExt.java | 1 + .../src/main/java/com/hai/model/GasOrderModel.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java index 1b3c8122..189a86f2 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java @@ -1099,6 +1099,7 @@ public interface HighOrderMapperExt { " b.deduction_price deductionPrice," + " b.pay_real_price payRealPrice," + " b.order_status status," + + " REPLACE(b.mem_phone, SUBSTR(b.mem_phone,4,4), '****') merPhone," + " a.goods_name gasName," + " (select address from high_merchant_store where id = a.goods_id) gasAddress," + " a.goods_img gasLogo," + diff --git a/hai-service/src/main/java/com/hai/model/GasOrderModel.java b/hai-service/src/main/java/com/hai/model/GasOrderModel.java index eff9bc3d..15b38e57 100644 --- a/hai-service/src/main/java/com/hai/model/GasOrderModel.java +++ b/hai-service/src/main/java/com/hai/model/GasOrderModel.java @@ -17,6 +17,7 @@ public class GasOrderModel { private BigDecimal deductionPrice; private BigDecimal payRealPrice; private Integer status; + private String merPhone; private String gasLogo; private String gasName; private String gasAddress; @@ -37,6 +38,14 @@ public class GasOrderModel { private Boolean printStatus; private Integer printNum; + public String getMerPhone() { + return merPhone; + } + + public void setMerPhone(String merPhone) { + this.merPhone = merPhone; + } + public Boolean getPrintStatus() { return printStatus; } From 5f00efc54bd6843fcd3979f770b5e93f1c6f2fd0 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 12 Jul 2022 14:07:53 +0800 Subject: [PATCH 12/13] =?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 --- .../controller/HighDiscountController.java | 27 +++++++++++++++++++ .../cweb/controller/HighOrderController.java | 9 ++++--- .../HighUserDiscountController.java | 1 + .../hai/common/security/AESEncodeUtil.java | 3 +-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java index 3882861b..60fb2430 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java @@ -23,6 +23,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; @@ -83,6 +84,32 @@ public class HighDiscountController { } } + @RequestMapping(value="/getDiscountByCode",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据Code查询优惠券") + public ResponseData getDiscountByCode(@RequestParam(name = "code", required = true) String code) { + try { + String discountAgentId; + try { + discountAgentId = AESEncodeUtil.aesDecrypt(URLDecoder.decode(code, "UTF-8")); + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); + } + + // 查询优惠券与代理商关系id + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelById(Long.parseLong(discountAgentId)); + if (discountAgentRel == null) { + log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); + } + return ResponseMsgUtil.success(discountAgentRel); + + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountByQrCode() error!",e); + return ResponseMsgUtil.exception(e); + } + } @RequestMapping(value="/getDiscountByDiscountAgentId",method = RequestMethod.GET) @ResponseBody 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 228d03d6..c307692b 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -247,10 +247,11 @@ public class HighOrderController { } if (StringUtils.isNotBlank(highOrder.getGasStaffCode())) { - String qrCodeSignKey = commonService.getDictionaryCodeName("QR_CODE_SIGN_KEY", "柴油"); + String qrCodeSignKey = commonService.getDictionaryCodeName("QR_CODE_SIGN_KEY", "1"); if (StringUtils.isBlank(qrCodeSignKey)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知秘钥"); } + String staffId = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(URLDecoder.decode(highOrder.getGasStaffCode(),"UTF-8")), qrCodeSignKey); // 查询员工 @@ -258,8 +259,10 @@ public class HighOrderController { if (gasStaff == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知收银员"); } - childOrder.setGasStaffId(gasStaff.getId()); - childOrder.setGasStaffName(gasStaff.getName()); + if (gasStaff.getMerchantStoreId().equals(childOrder.getGoodsId())) { + childOrder.setGasStaffId(gasStaff.getId()); + childOrder.setGasStaffName(gasStaff.getName()); + } } // 查询门店 diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java index 26dc7bf0..20a01b23 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -139,6 +139,7 @@ public class HighUserDiscountController { } } + @RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取用户的优惠券列表") diff --git a/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java b/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java index 5f33aa77..b967be6c 100644 --- a/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java +++ b/hai-service/src/main/java/com/hai/common/security/AESEncodeUtil.java @@ -64,8 +64,7 @@ public class AESEncodeUtil { public static void main(String[] args) throws Exception{ long currentTimeMillis = System.currentTimeMillis(); - System.out.println(URLDecoder.decode("Ble3spwlvhIa%2FArAa2cq0Q%3D%3D", "UTF-8")); - System.out.println(AESEncodeUtil.aesDecrypt(Base64Util.decode("ZStZUjRIcFl5SVo4MEhzSU96MldDUEFZa3lmbUhpNTdKMGhCVytIY3NJaz0"))); + System.out.println(AESEncodeUtil.aesDecrypt(URLDecoder.decode("mL4laIILGps4E58w8sbseQ%3D%3D", "UTF-8"))); /* String content = "{\"create_time\":1573544092110,\"order_serial_no\":\"40280e816db49c0b016db4a2c31f0004\",\"product_code\":\"8a9e80045cf85e54015cf8809fcd\",\"product_name\":\"平安发票贷\",\"uscc\":\"91370781687233838E\"}"; System.out.println("加密前" + content); From 762101b6e0df099b3fb56ed5cc773bf73578b2e0 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 12 Jul 2022 15:37:44 +0800 Subject: [PATCH 13/13] =?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 --- .../bweb/controller/HighDiscountAgentRelController.java | 2 +- hai-cweb/src/main/java/com/cweb/config/AuthConfig.java | 1 + .../java/com/cweb/controller/HighDiscountController.java | 7 ++++++- .../java/com/cweb/controller/HighOrderController.java | 8 +++++++- .../java/com/hai/dao/HighDiscountUserRelMapperExt.java | 2 +- .../hai/service/impl/HighDiscountUserRelServiceImpl.java | 4 ++-- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java index 1044f0b5..79847183 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java @@ -149,7 +149,7 @@ public class HighDiscountAgentRelController { String param = URLEncoder.encode(AESEncodeUtil.aesEncrypt(id.toString()), "UTF-8"); - String url = CommonSysConst.getSysConfig().getHsgDomainName() + "?p=" + param; + String url = CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=000001&key=&code=" + param; return ResponseMsgUtil.success(url); diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 8f932e5a..ff756154 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -97,6 +97,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/couponAgent/convertCodeDetail") .excludePathPatterns("/coupon/getCouponById") .excludePathPatterns("/discount/getDiscountByQrCode") + .excludePathPatterns("/discount/getDiscountByCode") .excludePathPatterns("/discount/getDiscountById") .excludePathPatterns("/discount/getCouponByDiscount") .excludePathPatterns("/discountPackage/getDiscountPackageList") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java index 60fb2430..17211dd8 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java @@ -17,6 +17,7 @@ import com.hai.service.HighDiscountCouponRelService; import com.hai.service.HighDiscountService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @@ -89,6 +90,7 @@ public class HighDiscountController { @ApiOperation(value = "根据Code查询优惠券") public ResponseData getDiscountByCode(@RequestParam(name = "code", required = true) String code) { try { + System.out.println(code); String discountAgentId; try { discountAgentId = AESEncodeUtil.aesDecrypt(URLDecoder.decode(code, "UTF-8")); @@ -96,7 +98,10 @@ public class HighDiscountController { log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); } - + if (StringUtils.isBlank(discountAgentId)) { + log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); + } // 查询优惠券与代理商关系id HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelById(Long.parseLong(discountAgentId)); if (discountAgentRel == null) { 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 c307692b..b05d8989 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -252,7 +252,13 @@ public class HighOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知秘钥"); } - String staffId = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(URLDecoder.decode(highOrder.getGasStaffCode(),"UTF-8")), qrCodeSignKey); + String staffId; + try { + staffId = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(URLDecoder.decode(highOrder.getGasStaffCode(),"UTF-8")), qrCodeSignKey); + } catch (Exception e) { + log.error("HighOrderController --> addOrder() error!", "收银员code解析失败"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "收银员code解析失败"); + } // 查询员工 HighGasStaff gasStaff = gasStaffService.getStaffDetailById(Long.parseLong(staffId)); diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapperExt.java index 4e81ee5d..ae6b984c 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapperExt.java @@ -41,6 +41,6 @@ public interface HighDiscountUserRelMapperExt { List getUserCouponsList(@Param("map") Map map); - @Select({" 100 ]]> "}) + @Select({""}) Integer receiveDiscountCount(@Param("userId") Long userId, @Param("discountId") Long discountId); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index 2acc324d..84dfc3e0 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -133,8 +133,8 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic if (!discount.getStatus().equals(2)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期"); } - if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) < discount.getReceiveNumber()) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线"); + if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) >= discount.getReceiveNumber()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "领取数量已达到上线"); } // 查询可分配的优惠券code List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByStatus(discountAgentRel.getId(), 1);