提交代码

master
胡锐 2 months ago
parent aecf86062c
commit ef533b3286
  1. 2
      bweb/src/main/java/com/bweb/controller/BsAgentMerController.java
  2. 54
      bweb/src/main/java/com/bweb/controller/TestController.java
  3. 12
      service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java
  4. 36
      service/src/main/java/com/hfkj/common/utils/HttpsUtils.java
  5. 46
      service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java
  6. 1
      service/src/main/java/com/hfkj/model/AgentMerAllot.java
  7. 334
      service/src/main/java/com/hfkj/openapi/service/ApiGasOrderService.java
  8. 2
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentApiAccountServiceImpl.java
  9. 8
      service/src/main/java/com/hfkj/service/agent/impl/BsAgentMerServiceImpl.java

@ -171,6 +171,7 @@ public class BsAgentMerController {
@RequestParam(name = "merSourceType", required = false) Long merSourceType, @RequestParam(name = "merSourceType", required = false) Long merSourceType,
@RequestParam(name = "merNo", required = false) String merNo, @RequestParam(name = "merNo", required = false) String merNo,
@RequestParam(name = "merName", required = false) String merName, @RequestParam(name = "merName", required = false) String merName,
@RequestParam(name = "status", required = false) Integer status,
@RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize) { @RequestParam(name = "pageSize", required = true) Integer pageSize) {
try { try {
@ -180,6 +181,7 @@ public class BsAgentMerController {
param.put("merSourceType", merSourceType); param.put("merSourceType", merSourceType);
param.put("merNo", StringUtils.isNotBlank(merNo)?merNo:null); param.put("merNo", StringUtils.isNotBlank(merNo)?merNo:null);
param.put("merName", StringUtils.isNotBlank(merName)?merName:null); param.put("merName", StringUtils.isNotBlank(merName)?merName:null);
param.put("status", status);
if (userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) { if (userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
param.put("agentId", agentId); param.put("agentId", agentId);

@ -1,13 +1,18 @@
package com.bweb.controller; package com.bweb.controller;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.hfkj.channel.gas.newlink.NewLinkRequestService;
import com.hfkj.channel.gas.shell.CqShellPetroleumRequestService; import com.hfkj.channel.gas.shell.CqShellPetroleumRequestService;
import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode; import com.hfkj.common.exception.SysCode;
import com.hfkj.common.pay.util.SignatureUtil;
import com.hfkj.common.utils.HttpUtils; import com.hfkj.common.utils.HttpUtils;
import com.hfkj.common.utils.HttpsUtils; import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.MD5Util; import com.hfkj.common.utils.MD5Util;
@ -28,6 +33,9 @@ import com.hfkj.service.sec.SecUserLoginLogService;
import com.hfkj.service.sec.SecUserService; import com.hfkj.service.sec.SecUserService;
import com.hfkj.sysenum.SecUserObjectTypeEnum; import com.hfkj.sysenum.SecUserObjectTypeEnum;
import com.hfkj.sysenum.SecUserStatusEnum; import com.hfkj.sysenum.SecUserStatusEnum;
import com.hfkj.sysenum.gas.GasOilPriceStatusEnum;
import com.hfkj.sysenum.merchant.MerchantSourceTypeEnum;
import com.hfkj.sysenum.merchant.MerchantStatusEnum;
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;
@ -38,7 +46,13 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Controller @Controller
@RequestMapping(value="/test") @RequestMapping(value="/test")
@ -62,6 +76,46 @@ public class TestController {
@Resource @Resource
private CommonService commonService; private CommonService commonService;
@RequestMapping(value="testApiPush",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "测试api推送")
public ResponseData testApiPush() {
try {
// 最新全量加油站数据
List<Object> gasDataList = new ArrayList<>();
// 初始化页数
Integer totalPageNum = 3;
for (int pageIndex = 1; pageIndex <= totalPageNum;pageIndex++) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("appId", "hffeab7fdb44d4f1");
paramMap.put("pageNum", pageIndex);
paramMap.put("pageSize", 100);
paramMap.put("sign", SignatureUtil.createSign(paramMap, "3a9b2772b9a2d319a9b18e55fa30246d"));
// 查询油站
JSONObject object = HttpsUtils.doPost("https://oil.dctpay.com/openapi/gas/queryList", JSON.toJSONString(paramMap));
// 总页数
totalPageNum = object.getJSONObject("return_data").getInteger("totalPageNum");
// 加入全量数据集合
gasDataList.addAll(object.getJSONObject("return_data").getJSONArray("gasInfoList"));
}
return ResponseMsgUtil.success(gasDataList);
/* Map<String,Object> param = new HashMap<>();
param.put("appId", "hf7356c71fb97ab0");
param.put("gasNo", "10019");
param.put("gunNo", "4");
param.put("oilNo", "95");
param.put("orderNo", System.currentTimeMillis());
param.put("refuelingAmount", "100");
param.put("userPhone", "17726395120");
param.put("sign", "string");
return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9805/openapi/gasOrder/push", JSONObject.toJSONString(param)));
*/
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="test",method = RequestMethod.GET) @RequestMapping(value="test",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "加油站全量缓存") @ApiOperation(value = "加油站全量缓存")

@ -39,14 +39,13 @@ public class SignatureUtil {
* @throws Exception * @throws Exception
*/ */
public static Boolean checkSign(String checkSign,Object param, String key) { public static Boolean checkSign(String checkSign,Object param, String key) {
return true; Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class);
/* Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class);
// 去除签名 // 去除签名
map.remove("sign"); map.remove("sign");
if (checkSign.equals(createSign(map, key))) { if (checkSign.equals(createSign(map, key))) {
return true; return true;
} }
return false;*/ return false;
} }
/** /**
@ -87,10 +86,11 @@ public class SignatureUtil {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String paramStr = "{\n" + String paramStr = "{\n" +
" \"appId\": \"hf7356c71fb97ab0\",\n" + " \"appId\": \"hffeab7fdb44d4f1\",\n" +
" \"orderNo\": \"123456\"" + " \"orderNo\": \"test10021001\",\n" +
" \"refundReason\": \"测试退款\"" +
"}"; "}";
String sign = createSign(JSONObject.parseObject(paramStr), "8aef995ff71485dc19b36e35f04c4016"); String sign = createSign(JSONObject.parseObject(paramStr), "3a9b2772b9a2d319a9b18e55fa30246d");
System.out.println(sign); System.out.println(sign);
} }

@ -389,6 +389,42 @@ public class HttpsUtils {
return null; return null;
} }
public static String doApiPost(String apiUrl, JSONObject json) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return httpStr;
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static JSONObject doHuiLianTongPost(String apiUrl) { public static JSONObject doHuiLianTongPost(String apiUrl) {
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) { if (apiUrl.startsWith("https")) {

@ -79,6 +79,52 @@ public interface BsAgentMerMapperExt {
" <if test='param.isAgentAllot != null and param.isAgentAllot == false'> and a.agentId is null </if>" + " <if test='param.isAgentAllot != null and param.isAgentAllot == false'> and a.agentId is null </if>" +
" GROUP BY a.merId " + " GROUP BY a.merId " +
" </script> "}) " </script> "})
/* @Select("<script>" +
" SELECT" +
" a.agentMerId," +
" a.merSourceType," +
" a.provinceCode," +
" a.provinceName," +
" a.merNo," +
" a.merName," +
" a.merAddress," +
" a.agentName," +
" a.`status`," +
" a.createTime" +
" FROM" +
" (" +
" SELECT" +
" a.id merId," +
" a.source_type merSourceType," +
" a.province_code provinceCode," +
" a.province_name provinceName," +
" a.mer_no merNo," +
" a.mer_name merName," +
" a.address merAddress," +
" a.`status`," +
" b.id agentMerId," +
" b.agent_id agentId," +
" b.agent_name agentName," +
" b.agent_staff_id agentStaffId," +
" b.agent_staff_name agentStaffName," +
" b.create_time createTime " +
" FROM" +
" bs_merchant a" +
" LEFT JOIN (select id,mer_id,agent_id,agent_name,agent_staff_id,agent_staff_name,create_time from bs_agent_mer " +
" where agent_id = #{param.agentId} and `status` <![CDATA[ <> ]]> 0 " +
" <if test='param.isAgentStaffAllot != null and param.isAgentStaffAllot == true'> and agent_staff_id = #{param.agentStaffId} and mer_id in (select mer_id from bs_agent_mer where agent_staff_id = #{param.agentStaffId} and `status` <![CDATA[ <> ]]> 0) </if>" +
" <if test='param.isAgentStaffAllot != null and param.isAgentStaffAllot == false'> and mer_id not in (select mer_id from bs_agent_mer where agent_staff_id = #{param.agentStaffId} and `status` <![CDATA[ <> ]]> 0) </if>" +
" GROUP BY mer_id) b on b.mer_id = a.id" +
" WHERE a.`status` <![CDATA[ <> 0 ]]> ) a " +
" WHERE 1 = 1 " +
" <if test='param.provinceCode != null'> and a.provinceCode = #{param.provinceCode} </if>" +
" <if test='param.merSourceType != null'> and a.merSourceType = #{param.merSourceType} </if>" +
" <if test='param.merNo != null'> and a.merNo like concat('%',#{param.merNo},'%') </if>" +
" <if test='param.merName != null'> and a.merName like concat('%',#{param.merName},'%') </if>" +
" <if test='param.isAgentAllot != null and param.isAgentAllot == true'> and a.agentId is not null </if>" +
" <if test='param.isAgentAllot != null and param.isAgentAllot == false'> and a.agentId is null </if>" +
" <if test='param.status != null'> and a.status = #{param.status} </if>" +
" </script>")*/
List<AgentMerAllot> getAllotList(@Param("param") Map<String,Object> param); List<AgentMerAllot> getAllotList(@Param("param") Map<String,Object> param);
@Select("<script> " + @Select("<script> " +

@ -21,5 +21,6 @@ public class AgentMerAllot {
private String agentName; private String agentName;
private Date createTime; private Date createTime;
private String agentStaff; private String agentStaff;
private Integer status;
} }

@ -45,7 +45,9 @@ import com.hfkj.sysenum.merchant.MerchantStatusEnum;
import com.hfkj.sysenum.order.OrderPayTypeEnum; import com.hfkj.sysenum.order.OrderPayTypeEnum;
import com.hfkj.sysenum.order.OrderRefundStatusEnum; import com.hfkj.sysenum.order.OrderRefundStatusEnum;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -54,6 +56,7 @@ import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -91,12 +94,15 @@ public class ApiGasOrderService {
private BsOrderRefundService orderRefundService; private BsOrderRefundService orderRefundService;
@Resource @Resource
private BsGasOilPriceService gasOilPriceService; private BsGasOilPriceService gasOilPriceService;
@Resource
private RedisTemplate<String, Object> redisTemplate;
private final String LOCK_KEY = "AGENT_API_PUSH_ORDER_LOCK_";
/** /**
* 推送加油订单 * 推送加油订单
* @param request * @param request
* @return * @return
*/ */
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) @Transactional(propagation= Propagation.NEVER)
public ResponseOrderPushModel pushOrder(Long agentId,RequestOrderPushModel request) throws Exception { public ResponseOrderPushModel pushOrder(Long agentId,RequestOrderPushModel request) throws Exception {
// 交易油站权限 // 交易油站权限
BsAgentMer agentMer = agentMerService.getDetailByAgent(agentId, request.getGasNo()); BsAgentMer agentMer = agentMerService.getDetailByAgent(agentId, request.getGasNo());
@ -131,94 +137,129 @@ public class ApiGasOrderService {
if (agent == null) { if (agent == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未知的接入方"); throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未知的接入方");
} }
// 创建加油订单
BsGasOrder gasOrder = new BsGasOrder(); return createOrder(agent, gasDetail, oilPrice, request);
gasOrder.setAgentId(agent.getId()); }
gasOrder.setAgentName(agent.getName());
gasOrder.setAbnormal(false); /**
gasOrder.setMerNo(gasDetail.getMerNo()); * 创建订单
gasOrder.setChannelType(gasDetail.getSourceType()); */
gasOrder.setOrderNo(request.getOrderNo()); @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class})
gasOrder.setUserPhone(request.getUserPhone()); public ResponseOrderPushModel createOrder(BsAgent agent, BsMerchant gasDetail, GasOilPriceModel oilPrice, RequestOrderPushModel request) throws InterruptedException {
gasOrder.setMerChainBrandId(gasDetail.getChainBrandId()); // 锁编号
gasOrder.setMerChainBrandName(gasDetail.getChainBrandName()); String lockKey = LOCK_KEY+agent.getId();
gasOrder.setMerId(gasDetail.getId()); // 获取锁
gasOrder.setMerName(gasDetail.getMerName()); Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
gasOrder.setMerAddress(gasDetail.getAddress()); if (Boolean.TRUE.equals(lock)) {
gasOrder.setStatus(OrderOilStatus.STATUS2.getNumber()); try {
gasOrder.setReceiptStatus(GasOrderReceiptStatusEnum.status0.getStatus()); // 锁超时时间 15秒
redisTemplate.expire(lockKey, 15, TimeUnit.SECONDS);
// 油价信息 // 创建加油订单
gasOrder.setGasRefuelPrice(request.getRefuelingAmount()); BsGasOrder gasOrder = new BsGasOrder();
gasOrder.setGasOilNo(request.getOilNo()); gasOrder.setAgentId(agent.getId());
gasOrder.setGasGunNo(request.getGunNo()); gasOrder.setAgentName(agent.getName());
gasOrder.setGasOilType(oilPrice.getOilType()); gasOrder.setAbnormal(false);
gasOrder.setGasPriceGun(oilPrice.getPriceGun()); gasOrder.setMerNo(gasDetail.getMerNo());
gasOrder.setGasPriceVip(oilPrice.getPriceVip()); gasOrder.setChannelType(gasDetail.getSourceType());
gasOrder.setGasPriceCost(oilPrice.getPriceGun()); gasOrder.setOrderNo(request.getOrderNo());
gasOrder.setGasPriceOfficial(oilPrice.getPriceOfficial()); gasOrder.setUserPhone(request.getUserPhone());
gasOrder.setGasPricePlatform(oilPrice.getPriceGun()); gasOrder.setMerChainBrandId(gasDetail.getChainBrandId());
gasOrder.setGasDiscount(new BigDecimal("0")); gasOrder.setMerChainBrandName(gasDetail.getChainBrandName());
gasOrder.setGasOilSubsidy(new BigDecimal("0")); gasOrder.setMerId(gasDetail.getId());
gasOrder.setGasLitersPreferences(new BigDecimal("0")); gasOrder.setMerName(gasDetail.getMerName());
gasOrder.setGasPricePreferences(new BigDecimal("0")); gasOrder.setMerAddress(gasDetail.getAddress());
gasOrder.setCreateType(GasOrderCreateType.TYPE2.getNumber()); gasOrder.setStatus(OrderOilStatus.STATUS2.getNumber());
gasOrder.setGasOilLiters(gasOrder.getGasRefuelPrice().divide(gasOrder.getGasPriceGun(), 2, BigDecimal.ROUND_HALF_UP)); gasOrder.setReceiptStatus(GasOrderReceiptStatusEnum.status0.getStatus());
// 结算信息 // 油价信息
gasOrder.setTotalDeductionPrice(new BigDecimal("0")); gasOrder.setGasRefuelPrice(request.getRefuelingAmount());
gasOrder.setDeductionCouponPrice(new BigDecimal("0")); gasOrder.setGasOilNo(request.getOilNo());
gasOrder.setDeductionOilPrice(new BigDecimal("0")); gasOrder.setGasGunNo(request.getGunNo());
gasOrder.setPayablePrice(request.getRefuelingAmount()); gasOrder.setGasOilType(oilPrice.getOilType());
gasOrder.setGasRefuelPrice(request.getRefuelingAmount()); gasOrder.setGasPriceGun(oilPrice.getPriceGun());
gasOrder.setGasServiceFeeRate(new BigDecimal("0")); gasOrder.setGasPriceVip(oilPrice.getPriceVip());
gasOrder.setGasServiceFeePrice(new BigDecimal("0")); gasOrder.setGasPriceCost(oilPrice.getPriceGun());
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type1.getNumber())) { gasOrder.setGasPriceOfficial(oilPrice.getPriceOfficial());
// 油站结算 公式 1. 加油升数 * (油枪价 - 优惠价) = 优惠金额 2. 加油金额 - 优惠金额 = 扣款金额 gasOrder.setGasPricePlatform(oilPrice.getPriceGun());
BigDecimal gasSettlePrice = gasOrder.getGasRefuelPrice().subtract( gasOrder.setGasDiscount(new BigDecimal("0"));
// 优惠金额 gasOrder.setGasOilSubsidy(new BigDecimal("0"));
gasOrder.getGasOilLiters().multiply(oilPrice.getPriceGun().subtract(oilPrice.getPriceVip()))); gasOrder.setGasLitersPreferences(new BigDecimal("0"));
gasOrder.setGasSettlePrice(gasSettlePrice); gasOrder.setGasPricePreferences(new BigDecimal("0"));
gasOrder.setCreateType(GasOrderCreateType.TYPE2.getNumber());
gasOrder.setGasOilLiters(gasOrder.getGasRefuelPrice().divide(gasOrder.getGasPriceGun(), 2, BigDecimal.ROUND_HALF_UP));
// 结算信息
gasOrder.setTotalDeductionPrice(new BigDecimal("0"));
gasOrder.setDeductionCouponPrice(new BigDecimal("0"));
gasOrder.setDeductionOilPrice(new BigDecimal("0"));
gasOrder.setPayablePrice(request.getRefuelingAmount());
gasOrder.setGasRefuelPrice(request.getRefuelingAmount());
gasOrder.setGasServiceFeeRate(new BigDecimal("0"));
gasOrder.setGasServiceFeePrice(new BigDecimal("0"));
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type1.getNumber())) {
// 油站结算 公式 1. 加油升数 * (油枪价 - 优惠价) = 优惠金额 2. 加油金额 - 优惠金额 = 扣款金额
BigDecimal gasSettlePrice = gasOrder.getGasRefuelPrice().subtract(
// 优惠金额
gasOrder.getGasOilLiters().multiply(oilPrice.getPriceGun().subtract(oilPrice.getPriceVip())));
gasOrder.setGasSettlePrice(gasSettlePrice);
} else {
gasOrder.setGasSettlePrice(gasOrder.getGasRefuelPrice());
}
gasOrder.setGasAgentSettlePrice(gasOrder.getGasRefuelPrice());
// 油站是否开启班组
BsGasClassGroupTask groupTask = gasClassGroupTaskService.getCurrentTaskByMerId(gasDetail.getId());
if (groupTask != null) {
gasOrder.setGasClassGroupId(groupTask.getGasClassGroupId());
gasOrder.setGasClassGroupName(groupTask.getGasClassGroupName());
gasOrder.setGasClassGroupTaskId(groupTask.getId());
}
gasOrderService.addGasOrder(gasOrder);
// 代理商扣款
Map<String,Object> consumeParam = new HashMap<>();
consumeParam.put("sourceType", MerchantAccountRecordSourceTypeEnum.type2.getType());
consumeParam.put("sourceOrderNo", gasOrder.getOrderNo());
consumeParam.put("sourceOrderContent", "加油订单:"+gasOrder.getOrderNo());
agentApiAccountService.consume(agent.getId(), gasOrder.getGasAgentSettlePrice(), consumeParam);
// 处理支付后的加油业务
oilHandle(gasOrder);
// 加油业务是否异常
if (gasOrder.getAbnormal().equals(true)) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, gasOrder.getAbnormalContent());
}
ResponseOrderPushModel response = new ResponseOrderPushModel();
response.setOrderNo(gasOrder.getOrderNo());
response.setChannelType(gasOrder.getChannelType());
response.setChannelOrderNo(gasOrder.getChannelOrderNo());
// 释放锁
redisTemplate.delete(lockKey);
return response;
} catch (BaseException e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
// 释放锁
redisTemplate.delete(lockKey);
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "创建订单失败");
}
} else { } else {
gasOrder.setGasSettlePrice(gasOrder.getGasRefuelPrice()); Thread.sleep(100);
} createOrder(agent,gasDetail,oilPrice,request);
gasOrder.setGasAgentSettlePrice(gasOrder.getGasRefuelPrice());
// 油站是否开启班组
BsGasClassGroupTask groupTask = gasClassGroupTaskService.getCurrentTaskByMerId(gasDetail.getId());
if (groupTask != null) {
gasOrder.setGasClassGroupId(groupTask.getGasClassGroupId());
gasOrder.setGasClassGroupName(groupTask.getGasClassGroupName());
gasOrder.setGasClassGroupTaskId(groupTask.getId());
} }
gasOrderService.addGasOrder(gasOrder); throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "创建加油订单失败");
// 代理商扣款
Map<String,Object> consumeParam = new HashMap<>();
consumeParam.put("sourceType", MerchantAccountRecordSourceTypeEnum.type2.getType());
consumeParam.put("sourceOrderNo", gasOrder.getOrderNo());
consumeParam.put("sourceOrderContent", "加油订单:"+gasOrder.getOrderNo());
agentApiAccountService.consume(agentId, gasOrder.getGasAgentSettlePrice(), consumeParam);
// 处理支付后的加油业务
oilHandle(gasOrder);
// 加油业务是否异常
if (gasOrder.getAbnormal().equals(true)) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, gasOrder.getAbnormalContent());
}
ResponseOrderPushModel response = new ResponseOrderPushModel();
response.setOrderNo(gasOrder.getOrderNo());
response.setChannelType(gasOrder.getChannelType());
response.setChannelOrderNo(gasOrder.getChannelOrderNo());
return response;
} }
/** /**
* 退款订单 * 退款订单
* @param request * @param request
* @return * @return
* @throws Exception * @throws Exception
*/ */
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) @Transactional(propagation= Propagation.REQUIRES_NEW,isolation = Isolation.SERIALIZABLE,rollbackFor= {RuntimeException.class})
public String refundOrder(Long agentId,RequestOrderRefundModel request) { public String refundOrder(Long agentId,RequestOrderRefundModel request) {
// 查询加油订单 // 查询加油订单
BsGasOrder gasOrder = gasOrderService.getDetailByOrderNo(request.getOrderNo()); BsGasOrder gasOrder = gasOrderService.getDetailByOrderNo(request.getOrderNo());
@ -264,53 +305,53 @@ public class ApiGasOrderService {
singleThreadExecutor.submit(new Runnable() { singleThreadExecutor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type2.getNumber())) { try {
// 团油 // 退款金额
try { refundPrice(gasOrder,orderRefund);
// 请求团油渠道申请退款 orderRefund.setRefundStatus(OrderRefundStatusEnum.status2.getCode());
JSONObject object = NewLinkRequestService.refuelingOrderRefund(gasOrder.getUserPhone(), gasOrder.getOrderNo(), orderRefund.getRefundRemark()); orderRefund.setFinishTime(new Date());
if (object == null || !object.getString("code").equals("200")) { orderRefundService.editData(orderRefund);
gasOrder.setAbnormal(true);
gasOrder.setAbnormalContent("渠道申请退款失败!原因:" + object.getString("message")); gasOrder.setStatus(OrderOilStatus.STATUS4.getNumber());
gasOrderService.updateGasOrder(gasOrder); gasOrder.setRefundTime(orderRefund.getFinishTime());
gasOrderService.updateGasOrder(gasOrder);
} catch (BaseException e) {
orderRefund.setRefundStatus(OrderRefundStatusEnum.status3.getCode());
orderRefund.setRefundFailReason("退款失败!");
orderRefundService.editData(orderRefund);
gasOrder.setStatus(OrderOilStatus.STATUS6.getNumber());
gasOrder.setReceiptFailRemark(orderRefund.getRefundFailReason());
gasOrderService.updateGasOrder(gasOrder);
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
orderRefund.setRefundStatus(OrderRefundStatusEnum.status3.getCode());
orderRefund.setRefundFailReason("退款失败!");
orderRefundService.editData(orderRefund);
gasOrder.setStatus(OrderOilStatus.STATUS6.getNumber());
gasOrder.setReceiptFailRemark(orderRefund.getRefundFailReason());
gasOrderService.updateGasOrder(gasOrder);
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "请求退款失败");
} finally {
// 退款成功通知
if (gasOrder.getStatus().equals(OrderOilStatus.STATUS4.getNumber())) {
// 代理参数
BsAgentApiParam apiParam = agentApiParamService.getParamByAppId(request.getAppId());
if (apiParam != null && StringUtils.isNotBlank(apiParam.getOrderRefundNotify())) {
// 通知数据
OrderRefundNotifyModel refundNotify = new OrderRefundNotifyModel();
refundNotify.setOrderNo(orderRefund.getOrderNo());
refundNotify.setChannelType(gasOrder.getChannelType());
refundNotify.setChannelOrderNo(gasOrder.getChannelOrderNo());
refundNotify.setRefundResult(orderRefund.getRefundStatus() == 2 ? true : false);
refundNotify.setRefundFailReason(orderRefund.getRefundFailReason());
refundNotify.setSign(SignatureUtil.createSign(refundNotify, apiParam.getAppSecret()));
HttpsUtils.doApiPost(apiParam.getOrderRefundNotify(), JSONObject.parseObject(JSONObject.toJSONString(refundNotify), JSONObject.class));
} }
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "请求退款失败");
}
} else {
try {
// 退款
agentApiAccountService.refund(gasOrder.getAgentId(),gasOrder.getGasRefuelPrice(), orderRefund);
orderRefund.setRefundStatus(OrderRefundStatusEnum.status2.getCode());
orderRefund.setFinishTime(new Date());
orderRefundService.editData(orderRefund);
gasOrder.setStatus(OrderOilStatus.STATUS4.getNumber());
gasOrder.setRefundTime(orderRefund.getFinishTime());
gasOrderService.updateGasOrder(gasOrder);
} catch (Exception e) {
orderRefund.setRefundStatus(OrderRefundStatusEnum.status3.getCode());
orderRefund.setRefundFailReason("退款失败!");
orderRefundService.editData(orderRefund);
gasOrder.setStatus(OrderOilStatus.STATUS6.getNumber());
gasOrder.setReceiptFailRemark(orderRefund.getRefundFailReason());
gasOrderService.updateGasOrder(gasOrder);
}
// 退款通知
// 代理参数
BsAgentApiParam apiParam = agentApiParamService.getParamByAppId(request.getAppId());
if (apiParam != null && StringUtils.isNotBlank(apiParam.getOrderRefundNotify())) {
// 通知数据
OrderRefundNotifyModel refundNotify = new OrderRefundNotifyModel();
refundNotify.setOrderNo(orderRefund.getOrderNo());
refundNotify.setChannelType(gasOrder.getChannelType());
refundNotify.setChannelOrderNo(gasOrder.getChannelOrderNo());
refundNotify.setRefundResult(orderRefund.getRefundStatus() == 2 ? true : false);
refundNotify.setRefundFailReason(orderRefund.getRefundFailReason());
refundNotify.setSign(SignatureUtil.createSign(refundNotify, apiParam.getAppSecret()));
HttpsUtils.doPost(apiParam.getOrderRefundNotify(), JSONObject.parseObject(JSONObject.toJSONString(refundNotify), JSONObject.class));
} }
} }
} }
@ -318,6 +359,49 @@ public class ApiGasOrderService {
return "ok"; return "ok";
} }
/**
* 退款金额
* @param gasOrder
* @param orderRefund
* @return
*/
private void refundPrice(BsGasOrder gasOrder, BsOrderRefund orderRefund) {
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type2.getNumber())) {
// 团油
try {
// 请求团油渠道申请退款
JSONObject object = NewLinkRequestService.refuelingOrderRefund(gasOrder.getUserPhone(), gasOrder.getOrderNo(), orderRefund.getRefundRemark());
if (object == null || !object.getString("code").equals("200")) {
gasOrder.setAbnormal(true);
gasOrder.setAbnormalContent("渠道申请退款失败!原因:" + object.getString("message"));
gasOrderService.updateGasOrder(gasOrder);
}
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "请求退款失败");
}
} else {
try {
// 代理商退款退款
agentApiAccountService.refund(gasOrder.getAgentId(),gasOrder.getGasRefuelPrice(), orderRefund);
// 退款到油站
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type1.getNumber())) {
merchantAccountService.refund(gasOrder.getMerNo(),gasOrder.getGasSettlePrice(),orderRefund);
}
orderRefund.setRefundStatus(OrderRefundStatusEnum.status2.getCode());
orderRefund.setFinishTime(new Date());
orderRefundService.editData(orderRefund);
gasOrder.setStatus(OrderOilStatus.STATUS4.getNumber());
gasOrder.setRefundTime(orderRefund.getFinishTime());
gasOrderService.updateGasOrder(gasOrder);
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "请求退款失败");
}
}
}
/** /**
* 查询订单详情 * 查询订单详情
* @param request * @param request

@ -14,6 +14,8 @@ import com.hfkj.sysenum.merchant.MerchantAccountRecordTypeEnum;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;

@ -147,7 +147,11 @@ public class BsAgentMerServiceImpl implements BsAgentMerService {
.flatMapToLong(num -> LongStream.of(num.getId())).boxed() .flatMapToLong(num -> LongStream.of(num.getId())).boxed()
.collect(Collectors.toList()); .collect(Collectors.toList());
example.clear(); example.clear();
example.createCriteria().andAgentStaffIdIn(staffIdList).andMerNoIn(merNoArray).andStatusNotEqualTo(0);
BsAgentMerExample.Criteria criteria = example.createCriteria().andMerNoIn(merNoArray).andStatusNotEqualTo(0);
if (!staffIdList.isEmpty()) {
criteria.andAgentStaffIdIn(staffIdList);
}
agentMerMapper.updateByExampleSelective(agentMer, example); agentMerMapper.updateByExampleSelective(agentMer, example);
for (String merNo : merNoArray) { for (String merNo : merNoArray) {
@ -291,7 +295,7 @@ public class BsAgentMerServiceImpl implements BsAgentMerService {
// 通知代理 // 通知代理
JSONObject notifyParam = JSONObject.parseObject(JSONObject.toJSONString(gasInfo), JSONObject.class); JSONObject notifyParam = JSONObject.parseObject(JSONObject.toJSONString(gasInfo), JSONObject.class);
notifyParam.put("sign", SignatureUtil.createSign(notifyParam, apiParam.getAppSecret())); notifyParam.put("sign", SignatureUtil.createSign(notifyParam, apiParam.getAppSecret()));
HttpsUtils.doPost(apiParam.getMerInfoNotify(), notifyParam); HttpsUtils.doApiPost(apiParam.getMerInfoNotify(), notifyParam);
} catch (Exception e) { } catch (Exception e) {
System.out.println("通知代理商:"+apiParam.getAgentId()+"失败"+e.getMessage()); System.out.println("通知代理商:"+apiParam.getAgentId()+"失败"+e.getMessage());
} }

Loading…
Cancel
Save