dev-discount
胡锐 2 years ago
commit 8bd4c6366b
  1. 1
      hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java
  2. 1
      hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java
  3. 272
      v1/src/main/java/com/v1/controller/GzSinopecController.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);

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

@ -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<String, Object> 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<String , Object> 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<String , Object> 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<String , Object> 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);
}
}
}

Loading…
Cancel
Save