|
|
|
@ -17,7 +17,12 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import org.springframework.http.*; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.net.ConnectException; |
|
|
|
@ -36,7 +41,6 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.TimeoutException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @program: GOLD |
|
|
|
* @ClassName RedServiceImpl |
|
|
|
@ -58,10 +62,13 @@ public class RedServiceImpl implements RedService { |
|
|
|
private static final String BASE_URL = "http://localhost:8080"; |
|
|
|
private static final String PATHLIST = "/api/coupon/getRedPacket"; |
|
|
|
private static final String PATHLOGIN = "/api/user/toujiaoAppLogin"; |
|
|
|
private static final String PATH_REFUND = "/api/coupon/refundRedPacket"; |
|
|
|
|
|
|
|
private static final String CONSUME_PATH = "/api/coupon/updateCostRedPacket"; |
|
|
|
private static final HttpClient CLIENT = HttpClient.newHttpClient(); |
|
|
|
|
|
|
|
private final RestTemplate restTemplate = new RestTemplate(); |
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
@Autowired |
|
|
|
private RedMapper redMapper; |
|
|
|
@Autowired |
|
|
|
@ -220,26 +227,36 @@ public class RedServiceImpl implements RedService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String checkRed(String linkId)throws Exception { |
|
|
|
try { |
|
|
|
// 组装 form 表单参数 |
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
|
|
|
params.add("order_id", linkId); |
|
|
|
|
|
|
|
int a=0; |
|
|
|
int b=0; |
|
|
|
if (a==200){ |
|
|
|
if(b==1){ |
|
|
|
throw new BusinessException("红包抵扣不足以退款,请联系客户后再次尝试"); |
|
|
|
} |
|
|
|
} |
|
|
|
if(a==400) { |
|
|
|
throw new BusinessException("系统繁忙"); |
|
|
|
// log.warn("红包服务返回400状态码: {},响应: {}", resp.statusCode(), resp.body()); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
throw new BusinessException("系统异常"); |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, String>> request = |
|
|
|
new HttpEntity<>(params, headers); |
|
|
|
|
|
|
|
// 发送 POST 请求 |
|
|
|
ResponseEntity<String> response = |
|
|
|
restTemplate.postForEntity(BASE_URLDev+PATH_REFUND, request, String.class); |
|
|
|
|
|
|
|
// 解析返回 JSON |
|
|
|
JsonNode root = objectMapper.readTree(response.getBody()); |
|
|
|
|
|
|
|
int code = root.path("code").asInt(); |
|
|
|
boolean flag = root.path("data").path("flag").asBoolean(); |
|
|
|
|
|
|
|
// 业务判断 |
|
|
|
if (code == 200 && flag) { |
|
|
|
// 正常流程 |
|
|
|
updateOrderStatus(linkId); |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
|
|
|
|
return "{\"success\":true,\"msg\":\"成功\"}"; |
|
|
|
// false 或接口异常 |
|
|
|
throw new RuntimeException("红包校验失败,orderId=" + linkId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateOrderStatus(String linkId) throws Exception { |
|
|
|
try { |
|
|
|
|