优化话费定时任务代码

dev-discount
袁野 2 years ago
parent 11415b2f40
commit ff0c2b148f
  1. 2
      hai-bweb/src/main/java/com/bweb/controller/HighTestController.java
  2. 2
      hai-order/src/main/java/com/web/controller/OrderPayController.java
  3. 189
      hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java
  4. 19
      hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java
  5. 71
      hai-service/src/main/java/com/hai/openApi/model/ApiMobileProductModel.java
  6. 48
      hai-service/src/main/java/com/hai/openApi/service/ApiMobileRechargeProductService.java
  7. 68
      hai-service/src/main/java/com/hai/openApi/service/impl/ApiMobileRechargeProductServiceImpl.java
  8. 2
      hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java
  9. 1
      hai-service/src/main/java/com/hai/order/type/OrderProductType.java
  10. 4
      hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java
  11. 14
      v1/src/main/java/com/v1/config/ApiCommonConfig.java
  12. 61
      v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java
  13. 19
      v1/src/main/java/com/v1/controller/business/GzSinopecController.java
  14. 51
      v1/src/main/java/com/v1/controller/business/MobileRechargeController.java
  15. 9
      v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java
  16. 195
      v1/src/main/java/com/v1/controller/business/StarbucksController.java

File diff suppressed because one or more lines are too long

@ -104,6 +104,8 @@ public class OrderPayController {
public ResponseData wechatPay(@RequestBody JSONObject body) { public ResponseData wechatPay(@RequestBody JSONObject body) {
try { try {
System.out.println("微信支付===================" + body);
if (body == null if (body == null
|| StringUtils.isBlank(body.getString("orderNo")) || StringUtils.isBlank(body.getString("orderNo"))
// || body.getInteger("openIdType") == null // || body.getInteger("openIdType") == null

@ -1,189 +0,0 @@
package com.web.controller.business;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.pay.WechatPayUtil;
import com.hai.common.security.UserCenter;
import com.hai.config.UnionPayConfig;
import com.hai.config.WxMsgConfig;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.enum_type.OrderPushType;
import com.hai.enum_type.OrderStatusEnum;
import com.hai.enum_type.RechargePayType;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderChildStatus;
import com.hai.service.*;
import com.hai.service.impl.OutRechargeOrderServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Controller
@RequestMapping(value = "telChargeCallback")
@Api(value = "话费充值回调业务")
public class OrderTelChargeCallbackController {
private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class);
@Resource
private OutRechargeOrderService outRechargeOrderService;
@Resource
private OutRechargeChildOrderService outRechargeChildOrderService;
@RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST)
@ApiOperation(value = "尖椒充值回调")
@ResponseBody
public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
try {
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
log.info("============回调任务Start=============");
log.info("尖椒订单充值-回调参数: " + dataObject);
log.info("============回调任务End=============");
// 判断是否充值成功
if (dataObject.getInteger("status") == 3) {
// 充值成功操作
outRechargeOrderService.completeOrder(dataObject.getString("out_order_id"));
} else {
// 充值失败操作
callbackResult(dataObject.getString("out_order_id"));
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("SUCCESS");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
@RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST)
@ApiOperation(value = "龙阅充值回调")
@ResponseBody
public void rechargeCallbackByLy(
@RequestParam(name = "out_trade_num", required = true) String out_trade_num,
@RequestParam(name = "userid", required = true) Long userid,
@RequestParam(name = "state", required = true) Long state,
@RequestBody String reqBodyStr ,
HttpServletRequest request, HttpServletResponse response) {
try {
log.info("============回调任务Start=============");
log.info("龙阅订单充值-回调参数: " + reqBodyStr);
log.info("============回调任务End=============");
// 判断是否充值成功
if (state == 1) {
outRechargeOrderService.completeOrder(out_trade_num);
} else {
callbackResult(out_trade_num);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("SUCCESS");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
@RequestMapping(value = "/rechargeCallbackByHg", method = RequestMethod.POST)
@ApiOperation(value = "畅停充值回调")
@ResponseBody
public void rechargeCallbackByHg(
@RequestParam(name = "mchid", required = false) String mchid,
@RequestParam(name = "out_order_id", required = false) String out_order_id,
@RequestParam(name = "orderid", required = true) String orderid,
@RequestParam(name = "return_time", required = false) String return_time,
@RequestParam(name = "return_price", required = false) String return_price,
@RequestParam(name = "recharge_price", required = false) String recharge_price,
@RequestParam(name = "price", required = false) String price,
@RequestParam(name = "status", required = true) String status,
@RequestParam(name = "phone", required = false) String phone,
@RequestParam(name = "secret_key", required = false) String secret_key,
HttpServletResponse response) {
try {
JSONObject dataObject = new JSONObject();
dataObject.put("mchid" , mchid);
dataObject.put("out_order_id" , out_order_id);
dataObject.put("orderid" , orderid);
dataObject.put("return_time" , return_time);
dataObject.put("return_price" , return_price);
dataObject.put("recharge_price" , recharge_price);
dataObject.put("price" , price);
dataObject.put("status" , status);
dataObject.put("phone" , phone);
dataObject.put("secret_key" , secret_key);
log.info("============回调任务Start=============");
log.info("畅停订单充值-回调参数: " + dataObject);
log.info("============回调任务End=============");
// 判断是否充值成功 并发送微信小程序服务通知
if (Objects.equals(status, "1")) {
outRechargeOrderService.completeOrder(orderid);
} else {
// 充值失败操作
callbackResult(orderid);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("success");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
// 充值回调结果处理
private void callbackResult(String orderNo) {
// 查询充值订单
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderNo(orderNo);
OutRechargeChildOrder childOrder = rechargeOrder.getOutRechargeChildOrders().get(0);
childOrder.setStatus(103);
childOrder.setUpdateTime(new Date());
outRechargeChildOrderService.updateOrder(childOrder);
rechargeOrder.setRechargeStatus(205);
outRechargeOrderService.updateOrder(rechargeOrder);
}
}

@ -59,4 +59,23 @@ public class PriceComputeConfig {
return true; return true;
} }
/**
* @Author Sum1Dream
* @Name computationPriceCost
* @Description // 计算折扣价格
* @Date 09:25 2023/3/13
* @Param discount 折扣
* @Param price 原价
* @Return java.math.BigDecimal
*/
public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price) {
return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
//
// public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price , BigDecimal 成本) {
// return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
//
// }
} }

@ -0,0 +1,71 @@
package com.hai.openApi.model;
import java.math.BigDecimal;
public class ApiMobileProductModel {
/**
* 主键
*/
private Long productId;
/**
* 运营商 1 电信 2.移动 3.联通
*/
private Integer operatorType;
/**
* 折扣比例
*/
private BigDecimal discount;
/**
* 充值金额
*/
private BigDecimal rechargePrice;
/**
* 成本价格
*/
private BigDecimal costPrice;
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public Integer getOperatorType() {
return operatorType;
}
public void setOperatorType(Integer operatorType) {
this.operatorType = operatorType;
}
public BigDecimal getDiscount() {
return discount;
}
public void setDiscount(BigDecimal discount) {
this.discount = discount;
}
public BigDecimal getRechargePrice() {
return rechargePrice;
}
public void setRechargePrice(BigDecimal rechargePrice) {
this.rechargePrice = rechargePrice;
}
public BigDecimal getCostPrice() {
return costPrice;
}
public void setCostPrice(BigDecimal costPrice) {
this.costPrice = costPrice;
}
}

@ -0,0 +1,48 @@
package com.hai.openApi.service;
import com.hai.entity.ApiMerchants;
import com.hai.entity.ApiProduct;
import com.hai.openApi.model.ApiMobileProductModel;
import java.util.List;
/**
* @serviceName ApiMobileRechargeProductService.java
* @author Sum1Dream
* @version 1.0.0
* @Description // 话费产品业务
* @createTime 11:36 2023/3/10
**/
public interface ApiMobileRechargeProductService {
/**
* @Author Sum1Dream
* @Name getMobileProductByList
* @Description // 查询话费充值产品
* @Date 11:35 2023/3/10
* @Param []
* @Return java.util.List<com.hai.openApi.model.ApiMobileProductModel>
*/
List<ApiProduct> getApiProductByList();
/**
* @Author Sum1Dream
* @Name findMobileProduct
* @Description // 查询话费产品
* @Date 11:36 2023/3/10
* @Param [id]
* @Return com.hai.entity.ApiProduct
*/
ApiProduct findMobileProduct(Long id);
/**
* @Author Sum1Dream
* @Name getMobileProductByList
* @Description // 拼装话费产品
* @Date 11:35 2023/3/10
* @Param []
* @Return java.util.List<com.hai.openApi.model.ApiMobileProductModel>
*/
List<ApiMobileProductModel> getMobileProductByList(String mchId);
}

@ -0,0 +1,68 @@
package com.hai.openApi.service.impl;
import com.hai.dao.ApiProductMapper;
import com.hai.entity.*;
import com.hai.openApi.config.PriceComputeConfig;
import com.hai.openApi.model.ApiMobileProductModel;
import com.hai.openApi.service.ApiMchProductService;
import com.hai.openApi.service.ApiMobileRechargeProductService;
import com.hai.order.type.OrderProductType;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("apiMobileRechargeProductService")
public class ApiMobileRechargeProductServiceImpl implements ApiMobileRechargeProductService {
@Resource
private ApiProductMapper apiProductMapper;
@Resource
private ApiMchProductService apiMchProductService;
@Resource
private PriceComputeConfig priceComputeConfig;
@Override
public List<ApiProduct> getApiProductByList() {
ApiProductExample example = new ApiProductExample();
example.createCriteria().andStatusEqualTo(101);
return apiProductMapper.selectByExample(example);
}
@Override
public ApiProduct findMobileProduct(Long id) {
return null;
}
@Override
public List<ApiMobileProductModel> getMobileProductByList(String mchId) {
Map<String, Object> mapProduct = new HashMap<>();
mapProduct.put("mchId" , mchId);
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE9.getNumber());
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct);
List<ApiMobileProductModel> list = new ArrayList<>();
List<ApiProduct> apiProducts = getApiProductByList();
for (ApiProduct product : apiProducts) {
ApiMobileProductModel productModel = new ApiMobileProductModel();
productModel.setDiscount(apiMchProducts.getDiscount());
productModel.setProductId(product.getId());
productModel.setRechargePrice(product.getRechargePrice());
productModel.setOperatorType(product.getOperatorType());
productModel.setCostPrice(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , product.getRechargePrice()));
list.add(productModel);
}
return list;
}
}

@ -59,7 +59,7 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ
mchProductMap.put("merchantId" , merchantStore.getMerchantId()); mchProductMap.put("merchantId" , merchantStore.getMerchantId());
ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap); ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap);
BigDecimal price = dataObject.getBigDecimal("refuelPrice").multiply(mchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_DOWN); BigDecimal price = priceComputeConfig.computationPriceCost(mchProduct.getDiscount() , dataObject.getBigDecimal("refuelPrice"));
// 判断金额是否充足 // 判断金额是否充足
if (apiMerchants.getAmounts().compareTo(price) < 0) { if (apiMerchants.getAmounts().compareTo(price) < 0) {

@ -19,6 +19,7 @@ public enum OrderProductType {
PRODUCT_TYPE8(8, "汇联通工会卡充值", "orderLogo/hlt.png", "HLT_CONFIG"), PRODUCT_TYPE8(8, "汇联通工会卡充值", "orderLogo/hlt.png", "HLT_CONFIG"),
PRODUCT_TYPE9(9, "话费充值" , "orderLogo/calls.png", "CALLS_CONFIG"), PRODUCT_TYPE9(9, "话费充值" , "orderLogo/calls.png", "CALLS_CONFIG"),
PRODUCT_TYPE10(10, "电影票" ,"" , ""), PRODUCT_TYPE10(10, "电影票" ,"" , ""),
PRODUCT_TYPE11(11, "贵州中石化" , "", "GZ_SINOPEC_CONFIG"),
; ;
private Integer number; private Integer number;

@ -631,7 +631,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
if (status == 0 || status == 3 || status == 99) { if (status == 0 || status == 3 || status == 99) {
return; return;
} else if (status == 1) { } else if (status == 1) {
completeOrder(outRechargeOrder.getOrderNo()); completeOrder(childOrder.getOrderNo());
} }
// 修改充值记录状态 // 修改充值记录状态
@ -863,7 +863,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
if (status == 2 || status == -1) { if (status == 2 || status == -1) {
refundOrder(outRechargeOrder.getId() , childOrder); refundOrder(outRechargeOrder.getId() , childOrder);
} else if (status == 1) { } else if (status == 1) {
completeOrder(outRechargeOrder.getOrderNo()); completeOrder(childOrder.getOrderNo());
} }
} }

@ -17,21 +17,11 @@ import java.util.Map;
@Configuration @Configuration
public class ApiCommonConfig { public class ApiCommonConfig {
@Resource
private ApiMchProductService ApiMchProductService;
@Resource @Resource
private HighGasOilGunNoService highGasOilGunNoService; private HighGasOilGunNoService highGasOilGunNoService;
public BigDecimal computationPriceCost(String mchId , Integer productType , BigDecimal price) { public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price) {
return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
Map<String , Object> map = new HashMap<>();
map.put("mchId" , mchId);
map.put("productType" , productType);
ApiMchProduct apiMchProduct = ApiMchProductService.findByMap(map);
return price.multiply(apiMchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
} }

@ -5,8 +5,10 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.QianZhuConfig;
import com.hai.entity.ApiMerchants; import com.hai.entity.ApiMerchants;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.order.type.OrderProductType;
import com.hai.service.*; import com.hai.service.*;
import com.v1.config.ToolConfig; import com.v1.config.ToolConfig;
import com.v1.controller.RechargeProductController; import com.v1.controller.RechargeProductController;
@ -38,6 +40,9 @@ public class ApiMerchantsController {
@Resource @Resource
private SecConfigService secConfigService; private SecConfigService secConfigService;
@Resource
private ApiIpAddressService apiIpAddressService;
@RequestMapping(value = "/checkAccountBalance", method = RequestMethod.POST) @RequestMapping(value = "/checkAccountBalance", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询帐户余额") @ApiOperation(value = "查询帐户余额")
@ -95,4 +100,60 @@ public class ApiMerchantsController {
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value = "/getAllCities", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询可用城市")
public ResponseData getAllCities(@RequestBody JSONObject object , HttpServletRequest request ) {
try {
String ip = "";
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for");
}
if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("sign"))
) {
log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) {
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
if (apiMerchants == null) {
log.error("getRechargeProduct error!", "帐户错误!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
}
Map<String , Object> map = new HashMap<>();
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);
}
JSONObject jsonObject = QianZhuConfig.getAllCities();
return ResponseMsgUtil.success(jsonObject.getString("data"));
} catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(e);
}
}
} }

@ -13,6 +13,7 @@ import com.hai.entity.ApiMerchants;
import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighGasOrderPush;
import com.hai.enum_type.OrderPushType; import com.hai.enum_type.OrderPushType;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.order.type.OrderProductType;
import com.hai.service.ApiMerchantsService; import com.hai.service.ApiMerchantsService;
import com.hai.service.SecConfigService; import com.hai.service.SecConfigService;
import com.v1.config.ToolConfig; import com.v1.config.ToolConfig;
@ -91,9 +92,9 @@ public class GzSinopecController {
log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); log.error("getRechargeProduct error!", "错误商户,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
} }
if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限!"); log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
} }
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
@ -170,9 +171,9 @@ public class GzSinopecController {
log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); log.error("getRechargeProduct error!", "错误商户,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
} }
if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限!"); log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
} }
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
@ -261,9 +262,9 @@ public class GzSinopecController {
log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); log.error("getRechargeProduct error!", "错误商户,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
} }
if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限!"); log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
} }
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {

@ -1,4 +1,4 @@
package com.v1.controller; package com.v1.controller.business;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
@ -6,12 +6,12 @@ import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.ApiMerchants; import com.hai.entity.ApiMerchants;
import com.hai.entity.HighOrder;
import com.hai.entity.SecConfig;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.model.SelfOilStationModel; import com.hai.openApi.service.ApiMobileRechargeProductService;
import com.hai.order.type.OrderProductType;
import com.hai.service.*; import com.hai.service.*;
import com.v1.config.ToolConfig; import com.v1.config.ToolConfig;
import com.v1.controller.RechargeProductController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -26,16 +26,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
@RequestMapping(value = "/selfOilStation") @RequestMapping(value = "/mobileRecharge")
@Api(value = "自建站接口") @Api(value = "话费充值业务")
public class SelfOilStationController { public class MobileRechargeController {
private static Logger log = LoggerFactory.getLogger(SelfOilStationController.class); private static Logger log = LoggerFactory.getLogger(RechargeProductController.class);
@Resource @Resource
private ApiMerchantsService apiMerchantsService; private ApiMerchantsService apiMerchantsService;
@ -44,17 +42,16 @@ public class SelfOilStationController {
private SecConfigService secConfigService; private SecConfigService secConfigService;
@Resource @Resource
private HighOrderService highOrderService; private ApiMobileRechargeProductService mobileRechargeProductService;
@Resource @Resource
private ApiIpAddressService apiIpAddressService; private ApiIpAddressService apiIpAddressService;
@RequestMapping(value = "/getMobileProduct", method = RequestMethod.POST)
@RequestMapping(value = "/getSelfOilStationOrderList", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "获取自建站订单") @ApiOperation(value = "获取话费充值产品")
public ResponseData getSelfOilStationOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { public ResponseData getMobileProduct(@RequestBody JSONObject object , HttpServletRequest request ) {
try { try {
String ip = ""; String ip = "";
@ -71,7 +68,6 @@ public class SelfOilStationController {
} }
if (StringUtils.isBlank(object.getString("apiKey")) || if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("timetable")) ||
StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("sign")) StringUtils.isBlank(object.getString("sign"))
) { ) {
@ -82,12 +78,16 @@ public class SelfOilStationController {
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
if (apiMerchants == null) { if (apiMerchants == null) {
log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); log.error("getRechargeProduct error!", "帐户号错误!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
} }
if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE9.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
}
Map<String , Object> map = new HashMap<>(); Map<String , Object> map = new HashMap<>();
map.put("timetable" , object.getString("timetable"));
map.put("apiKey" , object.getString("apiKey")); map.put("apiKey" , object.getString("apiKey"));
map.put("merchId" , object.getString("merchId")); map.put("merchId" , object.getString("merchId"));
@ -96,24 +96,11 @@ public class SelfOilStationController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
} }
if (!secConfigService.isConfig("SELF_OIL_STATION_CONFIG" , object.getString("merchId"))) { return ResponseMsgUtil.success(mobileRechargeProductService.getMobileProductByList(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.TIME_OUT);
}
SecConfig config = secConfigService.findByCodeType(object.getString("merchId"));
return ResponseMsgUtil.success(highOrderService.getSelfOilStationOrderList(config.getCodeValue()));
} catch (Exception e) { } catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e); log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
} }

@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -113,12 +114,13 @@ public class RefuelOnlineController {
List<ApiMchProduct> apiMchProducts = apiMchProductService.getListMchProduct(mapProduct); List<ApiMchProduct> apiMchProducts = apiMchProductService.getListMchProduct(mapProduct);
Map<String, Object> mapMerchant; Map<String, Object> mapMerchant = new HashMap<>();;
Map<Long, BigDecimal> discountMap = new HashMap<>();
List<HighMerchantStore> merchantStores = new ArrayList<>(); List<HighMerchantStore> merchantStores = new ArrayList<>();
for (ApiMchProduct mchProduct : apiMchProducts) { for (ApiMchProduct mchProduct : apiMchProducts) {
mapMerchant = new HashMap<>();
mapMerchant.put("merchantId" , mchProduct.getMerchantId()); mapMerchant.put("merchantId" , mchProduct.getMerchantId());
discountMap.put(mchProduct.getMerchantId() , mchProduct.getDiscount());
merchantStores.addAll(highMerchantStoreService.getMerchantStoreList(mapMerchant)); merchantStores.addAll(highMerchantStoreService.getMerchantStoreList(mapMerchant));
} }
@ -135,11 +137,12 @@ public class RefuelOnlineController {
List<HighGasOilPrice> gasOilPrices = gasOilPriceService.getGasOilPriceByStore(merchantStore.getId()); List<HighGasOilPrice> gasOilPrices = gasOilPriceService.getGasOilPriceByStore(merchantStore.getId());
List<ApiGasOliPriceModel> list = new ArrayList<>(); List<ApiGasOliPriceModel> list = new ArrayList<>();
for (HighGasOilPrice gasOilPrice : gasOilPrices) { for (HighGasOilPrice gasOilPrice : gasOilPrices) {
ApiGasOliPriceModel gasOliPriceModel = new ApiGasOliPriceModel(); ApiGasOliPriceModel gasOliPriceModel = new ApiGasOliPriceModel();
gasOliPriceModel.setPriceCost(apiCommonConfig.computationPriceCost(object.getString("merchId") , OrderProductType.PRODUCT_TYPE6.getNumber() , gasOilPrice.getPriceGun())); gasOliPriceModel.setPriceCost(apiCommonConfig.computationPriceCost(discountMap.get(merchantStore.getMerchantId()), gasOilPrice.getPriceGun()));
gasOliPriceModel.setPriceGun(gasOilPrice.getPriceGun()); gasOliPriceModel.setPriceGun(gasOilPrice.getPriceGun());
gasOliPriceModel.setPriceOfficial(gasOilPrice.getPriceOfficial()); gasOliPriceModel.setPriceOfficial(gasOilPrice.getPriceOfficial());
gasOliPriceModel.setOilNo(gasOilPrice.getOilNo()); gasOliPriceModel.setOilNo(gasOilPrice.getOilNo());

@ -0,0 +1,195 @@
package com.v1.controller.business;
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.QianZhuConfig;
import com.hai.entity.ApiMerchants;
import com.hai.entity.ApiStarbucksProducts;
import com.hai.model.ResponseData;
import com.hai.order.type.OrderProductType;
import com.hai.service.*;
import com.v1.controller.ThirdPartyController;
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;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/starbucks")
@Api(value = "星巴克业务")
public class StarbucksController {
private static Logger log = LoggerFactory.getLogger(ThirdPartyController.class);
@Resource
private ApiMerchantsService apiMerchantsService;
@Resource
private SecConfigService secConfigService;
@Resource
private ApiIpAddressService apiIpAddressService;
@Resource
private ApiProductService apiProductService;
@RequestMapping(value = "/starbucksStore", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询星巴克门店")
public ResponseData starbucksStore(@RequestBody JSONObject object , HttpServletRequest request ) {
try {
String ip = "";
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for");
}
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) {
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("lat")) ||
StringUtils.isBlank(object.getString("lon")) ||
StringUtils.isBlank(object.getString("sign"))
) {
log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
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(OrderProductType.PRODUCT_TYPE1.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
}
Map<String , Object> map = new HashMap<>();
map.put("apiKey" , object.getString("apiKey"));
map.put("merchId" , object.getString("merchId"));
map.put("lat" , object.getString("lat"));
map.put("lon" , object.getString("lon"));
if (!secConfigService.isSignVerify(map , object.getString("sign"))) {
log.error("getRechargeProduct error!", "签名校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
JSONObject jsonObject = QianZhuConfig.getStarbucksStore(object.getString("lat") , object.getString("lon"));
if (jsonObject.getBoolean("success")) {
return ResponseMsgUtil.success(jsonObject.getString("data"));
} else {
log.error("getRechargeProduct error!", "查询失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message"));
}
} catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getStarbucksProducts", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询星巴克商品")
public ResponseData getStarbucksProducts(@RequestBody JSONObject object , HttpServletRequest request ) {
try {
String ip = "";
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for");
}
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) {
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("sign"))
) {
log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
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(OrderProductType.PRODUCT_TYPE1.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
}
Map<String , Object> map = new HashMap<>();
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);
}
Map<String, Object> mapProduct = new HashMap<>();
List<ApiStarbucksProducts> list = apiProductService.getStarbucksProducts(mapProduct);
for (ApiStarbucksProducts starbucksProducts : list) {
if (starbucksProducts.getMarketGrandePrice().compareTo(new BigDecimal(1000)) > 0) {
starbucksProducts.setMarketGrandePrice(null);
}
if (starbucksProducts.getMarketTallPrice().compareTo(new BigDecimal(1000)) > 0) {
starbucksProducts.setMarketTallPrice(null);
}
if (starbucksProducts.getMarketVentiPrice().compareTo(new BigDecimal(1000)) > 0) {
starbucksProducts.setMarketVentiPrice(null);
}
starbucksProducts.setSalesTallPrice(starbucksProducts.getMarketTallPrice());
starbucksProducts.setSalesVentiPrice(starbucksProducts.getMarketVentiPrice());
starbucksProducts.setSalesGrandePrice(starbucksProducts.getMarketGrandePrice());
}
return ResponseMsgUtil.success(list);
} catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}
Loading…
Cancel
Save