From f93bbcac5260ff621af8d332f39c48b50936c915 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Tue, 9 Aug 2022 14:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=9D=E8=B4=B9=E5=AE=9A?= =?UTF-8?q?=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 --- .../com/hai/schedule/HighOrderSchedule.java | 1 + .../java/com/hai/dao/HighOrderMapperExt.java | 1 + .../v1/controller/GzSinopecController.java | 272 ++++++++++++------ 3 files changed, 182 insertions(+), 92 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 4d410258..8bee713f 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -451,6 +451,7 @@ public class HighOrderSchedule { object.put("price" , highOrder.getPayRealPrice()); object.put("userId" , highOrder.getMemId()); object.put("orderId" , highOrder.getId()); + object.put("companyId" , highOrder.getCompanyId()); bsIntegralRebateService.integralRebate(object); 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 96b213d5..0850af7d 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java @@ -1274,6 +1274,7 @@ public interface HighOrderMapperExt { @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL), @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR), + @Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT), @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), diff --git a/v1/src/main/java/com/v1/controller/GzSinopecController.java b/v1/src/main/java/com/v1/controller/GzSinopecController.java index fe922367..7ba77376 100644 --- a/v1/src/main/java/com/v1/controller/GzSinopecController.java +++ b/v1/src/main/java/com/v1/controller/GzSinopecController.java @@ -1,21 +1,27 @@ package com.v1.controller; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.HuiLianTongConfig; +import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.dao.HighGasOrderPushMapper; +import com.hai.entity.ApiMerchants; import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighUser; import com.hai.enum_type.OrderPushType; import com.hai.model.ResponseData; +import com.hai.service.ApiMerchantsService; import com.hai.service.HighOpenApiService; import com.hai.service.HighUserService; import com.hai.service.SecConfigService; +import com.v1.config.ToolConfig; 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; @@ -41,49 +47,18 @@ public class GzSinopecController { private HighUserService highUserService; @Resource - private HighGasOrderPushMapper highGasOrderPushMapper; + private ApiMerchantsService apiMerchantsService; @Resource - private SecConfigService secConfigService; + private HighGasOrderPushMapper highGasOrderPushMapper; @Resource - private HuiLianTongConfig huiLianTongConfig; - - @RequestMapping(value = "/getGuizhouSinopecList", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "获取专属优惠券") - public ResponseData getUserExclusiveDiscount(@RequestParam(name = "useScope", required = false) Integer useScope, - @RequestParam(name = "phone", required = true) String phone, - @RequestParam(name = "year", required = false) String year) { - try { - - HighUser highUser = highUserService.findByPhone(phone); - - if (highUser == null || highUser.getStatus() == 0) { - log.error("getUserOrderPreList error!", "未找到用户"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前手机号暂无用户"); - } - - Map map = new HashMap<>(); - map.put("userId", highUser.getId()); - map.put("useScope", useScope); - if (year != null) { - map.put("createTimeS", year + "-01-01 00:00:00"); - map.put("createTimeE", year + "-12-31 23:59:59"); - } - - return ResponseMsgUtil.success(highOpenApiService.getUserCouponsList(map)); - - } catch (Exception e) { - log.error("HighOpenApiController --> getGuizhouSinopecList() error!", e); - return ResponseMsgUtil.exception(e); - } - } + private SecConfigService secConfigService; - @RequestMapping(value = "/getGuizhouSinopecList", method = RequestMethod.POST) + @RequestMapping(value = "/getGzSinopecList", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取贵州中石化电子卡券") - public ResponseData getGuizhouSinopecList(HttpServletRequest request) { + public ResponseData getGzSinopecList(@RequestBody JSONObject object , HttpServletRequest request) { try { String ip = ""; @@ -99,28 +74,63 @@ public class GzSinopecController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); } - // 获取token - String token = huiLianTongConfig.getToken(); + + if (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("timetable")) || + StringUtils.isBlank(object.getString("merchId")) || + StringUtils.isBlank(object.getString("sign")) + ) { + log.error("getRechargeProduct error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + Map map = new HashMap<>(); + map.put("timetable" , object.getString("timetable")); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + } + + if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { + log.error("getRechargeProduct error!", "请求时间超过15分钟!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } // 查询电子卡券类型 - JSONObject corpCouTypes = HuiLianTongConfig.getCorpCouTypes(token); - System.out.println(corpCouTypes.toJSONString()); - if (!corpCouTypes.getString("result").equals("success")) { - log.error("HighOpenApiController -> getGuizhouSinopecList() error!", "获取电子卡券列表失败"); + JSONObject corpCouTypes = HuiLianTongConfig.getHltFuelCoupList(); + if (!corpCouTypes.getString("respCode").equals("0000")) { + log.error("HighCouponController -> insertCoupon() error!","获取电子卡券列表失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取电子卡券列表失败"); } + // 参数解密 + JSONObject resolveResponseData = HuiLianTongUnionCardConfig.resolveResponse(corpCouTypes.getString("data")); - return ResponseMsgUtil.success(corpCouTypes.getJSONArray("data")); + return ResponseMsgUtil.success(resolveResponseData); } catch (Exception e) { log.error("HighCouponController -> getGuizhouSinopec() error!", e); return ResponseMsgUtil.exception(e); } } - @RequestMapping(value = "/checkCouponStatus", method = RequestMethod.POST) + + @RequestMapping(value = "/couJointDist", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "查询电子券状态") - public ResponseData checkCouponStatus(@RequestBody JSONObject object, HttpServletRequest request) { + @ApiOperation(value = "商户派发电子券") + public ResponseData couJointDist(@RequestBody JSONObject object, HttpServletRequest request) { try { String ip = ""; @@ -132,31 +142,101 @@ public class GzSinopecController { } if (!secConfigService.isConfig("IP_WHITE", ip)) { - log.error("getGuizhouSinopec error!", "非法ip地址,请联系管理人员!"); + log.error("couJointDist error!", "非法ip地址,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); } - // 获取token - String token = huiLianTongConfig.getToken(); + if (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("orderNo")) || + StringUtils.isBlank(object.getString("count")) || + StringUtils.isBlank(object.getString("couTypeCode")) || + StringUtils.isBlank(object.getString("phone")) || + StringUtils.isBlank(object.getString("timetable")) || + StringUtils.isBlank(object.getString("merchId")) || + StringUtils.isBlank(object.getString("sign")) + ) { + log.error("getRechargeProduct error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } - // 查询电子卡券类型 - JSONObject data = HuiLianTongConfig.getCouState(token, object.getString("couNo")); - if (!data.getString("result").equals("success")) { - log.error("HighOpenApiController -> insertCoupon() error!", "查询电子券状态失败"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询电子券状态失败"); + Map map = new HashMap<>(); + map.put("timetable" , object.getString("timetable")); + map.put("apiKey" , object.getString("apiKey")); + map.put("orderNo" , object.getString("orderNo")); + map.put("count" , object.getString("count")); + map.put("couTypeCode" , object.getString("couTypeCode")); + map.put("phone" , object.getString("phone")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + } + + if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { + log.error("getRechargeProduct error!", "请求时间超过15分钟!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + if (object.getInteger("count") > 5) { + log.error("getRechargeProduct error!", "下单数量限制5张!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "下单数量限制5张!"); + } + + // 下单请求 + JSONObject rechargeObject = HuiLianTongConfig.recharge(object.getString("orderNo"), + object.getInteger("count"), + object.getString("couTypeCode"), + object.getString("phone")); + if (!rechargeObject.getString("respCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败"); + } + JSONObject response = HuiLianTongUnionCardConfig.resolveResponse(rechargeObject.getString("data")); + + // 购买卡券 + JSONObject returnParam = HuiLianTongConfig.costRechargeOrder(response.getJSONObject("data").getString("rechargeOrderId")); + + if (returnParam != null && returnParam.getString("respCode").equals("0000")) { + // 解密 + JSONObject jsonObject = HuiLianTongUnionCardConfig.resolveResponse(returnParam.getString("data")); + JSONArray dataArray = JSONObject.parseObject(jsonObject.getString("data"), JSONArray.class); + + // 推送记录 + HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); + highGasOrderPush.setType(OrderPushType.type6.getType()); + highGasOrderPush.setOrderNo(object.getString("orderNo")); + highGasOrderPush.setCreateTime(new Date()); + highGasOrderPush.setCode(returnParam.getString("respCode")); + highGasOrderPush.setRequestContent(object.toJSONString()); + highGasOrderPush.setReturnContent(dataArray.toJSONString()); + highGasOrderPushMapper.insert(highGasOrderPush); + + return ResponseMsgUtil.success(dataArray); + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败"); } - return ResponseMsgUtil.success(data.getJSONObject("data")); } catch (Exception e) { - log.error("HighCouponController -> getGuizhouSinopec() error!", e); + log.error("HighOpenApiController -> couJointDist() error!", e); return ResponseMsgUtil.exception(e); } } - @RequestMapping(value = "/couJointDist", method = RequestMethod.POST) + @RequestMapping(value = "/getPayOrderByCouNo", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "商户派发电子券") - public ResponseData couJointDist(@RequestBody JSONObject object, HttpServletRequest request) { + @ApiOperation(value = "查询核销状态") + public ResponseData getPayOrderByCouNo(@RequestBody JSONObject object , HttpServletRequest request) { try { String ip = ""; @@ -168,55 +248,63 @@ public class GzSinopecController { } if (!secConfigService.isConfig("IP_WHITE", ip)) { - log.error("couJointDist error!", "非法ip地址,请联系管理人员!"); + log.error("getGuizhouSinopec error!", "非法ip地址,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); } - // 获取token - String token = huiLianTongConfig.getToken(); - // 商户派发电子券 - JSONObject returnParam = HuiLianTongConfig.couJointDist(token, object.getString("orderNo"), object.getString("couTypeCode"), object.getInteger("distCouCount"), object.getString("phone"), object.getString("thirdUserId")); - // 推送记录 - HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); - highGasOrderPush.setType(OrderPushType.type6.getType()); - highGasOrderPush.setOrderNo(object.getString("orderNo")); - highGasOrderPush.setCreateTime(new Date()); - highGasOrderPush.setCode(returnParam.getString("result")); - highGasOrderPush.setRequestContent(JSONObject.toJSONString(object)); - highGasOrderPush.setReturnContent(returnParam.toJSONString()); - highGasOrderPushMapper.insert(highGasOrderPush); - if (!returnParam.getString("result").equals("success")) { - log.error("HighOpenApiController -> couJointDist() error!", "商户派发电子券失败"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户派发电子券失败"); + if (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("timetable")) || + StringUtils.isBlank(object.getString("merchId")) || + StringUtils.isBlank(object.getString("couNo")) || + StringUtils.isBlank(object.getString("sign")) + ) { + log.error("getRechargeProduct error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); } - return ResponseMsgUtil.success(returnParam.getJSONArray("data")); - } catch (Exception e) { - log.error("HighOpenApiController -> couJointDist() error!", e); - return ResponseMsgUtil.exception(e); - } - } + Map map = new HashMap<>(); + map.put("timetable" , object.getString("timetable")); + map.put("apiKey" , object.getString("apiKey")); + map.put("couNo" , object.getString("couNo")); + map.put("merchId" , object.getString("merchId")); + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } - @RequestMapping(value = "/test", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "测试") - public ResponseData test(HttpServletRequest request) { - try { + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); - String ip = ""; + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + } - if (request.getHeader("x-forwarded-for") == null) { - ip = request.getRemoteAddr(); + if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { + log.error("getRechargeProduct error!", "请求时间超过15分钟!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + JSONObject jsonObject = HuiLianTongConfig.getPayOrderByCouNo(object.getString("couNo")); + if (jsonObject.getString("respCode").equals("0000")) { + JSONObject data = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); + + return ResponseMsgUtil.success(data); + } else { + log.error("getRechargeProduct error!", "查询失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "查询失败"); } - ip = request.getHeader("x-forwarded-for"); - return ResponseMsgUtil.success(ip); } catch (Exception e) { log.error("HighCouponController -> getGuizhouSinopec() error!", e); return ResponseMsgUtil.exception(e); } } + }