邝工更改
This commit is contained in:
@@ -9,14 +9,22 @@ import com.dianguang.cloud.ossservice.service.OSSFactory;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.client.reactive.ClientHttpRequest;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.reactive.function.BodyInserter;
|
||||||
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.HashMap;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Random;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpHeaders.USER_AGENT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,17 +86,65 @@ public class PromotionImageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邝工需求
|
* 邝工需求1
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/testRequest")
|
@PostMapping("/testRequest")
|
||||||
public RespBody testRequest(){
|
public RespBody testRequest(@RequestParam Map<String, Object> param)throws Exception{
|
||||||
int randomNumber = new Random().nextInt(6);
|
|
||||||
|
int randomNumber = new Random().nextInt(5);
|
||||||
List<Object> objects = new ArrayList<>();
|
List<Object> objects = new ArrayList<>();
|
||||||
|
CompletableFuture<RespBody> future = CompletableFuture.supplyAsync(() -> {
|
||||||
|
// 模拟耗时操作
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new IllegalStateException("Async task was interrupted");
|
||||||
|
}
|
||||||
|
System.out.println(LocalDateTime.now()+"+++返回订单结果+++");
|
||||||
|
try {
|
||||||
|
this.testRequest1(param);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
// 获取异步任务的结果(如果需要)
|
||||||
|
// 会阻塞,直到任务完成
|
||||||
|
System.out.println(LocalDateTime.now()+"异步++++++++++++++++++" );
|
||||||
return new RespBody(String.valueOf(randomNumber),objects);
|
return new RespBody(String.valueOf(randomNumber),objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/testRequest1")
|
||||||
|
public void testRequest1(@RequestParam Map<String, Object> param)throws Exception{
|
||||||
|
int randomNumber = new Random().nextInt(2) == 0 ? 2 : 3;
|
||||||
|
StringBuilder orderInfo = new StringBuilder();
|
||||||
|
String url = param.get("notify_url").toString().trim();
|
||||||
|
|
||||||
|
orderInfo.append("order_id=").append(param.get("order_on"));
|
||||||
|
orderInfo.append("&status=").append(randomNumber);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("++++++++++"+orderInfo.toString());
|
||||||
|
System.out.println("+++++++"+param);
|
||||||
|
|
||||||
|
|
||||||
|
WebClient webClient = WebClient.builder().build();
|
||||||
|
Mono<String> response = webClient.post()
|
||||||
|
.uri(url)
|
||||||
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
.body(BodyInserters.fromObject(orderInfo.toString()))
|
||||||
|
.retrieve()
|
||||||
|
.bodyToMono(String.class);
|
||||||
|
|
||||||
|
|
||||||
|
String responseMsg = response.block();
|
||||||
|
System.out.println(LocalDateTime.now()+"响应+++++++++++"+responseMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邝工需求
|
* 邝工需求2
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/testRequestBoolean")
|
@PostMapping("/testRequestBoolean")
|
||||||
@@ -101,6 +157,14 @@ public class PromotionImageController {
|
|||||||
return new RespBody("000000","fail");
|
return new RespBody("000000","fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 邝工需求3
|
||||||
|
*/
|
||||||
|
@PostMapping("/testSuccess")
|
||||||
|
public RespBody testSuccess(){
|
||||||
|
return new RespBody("000000","success");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ public class AdminWebConfig implements WebMvcConfigurer {
|
|||||||
registry.addInterceptor(new LoginInterceptor(redisUtil))
|
registry.addInterceptor(new LoginInterceptor(redisUtil))
|
||||||
.addPathPatterns()
|
.addPathPatterns()
|
||||||
// 如果有静态资源的时候可以在这个地方放行
|
// 如果有静态资源的时候可以在这个地方放行
|
||||||
.excludePathPatterns("/","/user/doLogin","/agency/mytest","/agency/queryAgency","/promotion/testRequest","/promotion/testRequestBoolean","/agency/sendmessage","/Alipay/pay");
|
.excludePathPatterns("/","/user/doLogin","/agency/mytest","/agency/queryAgency","/promotion/testRequest","/promotion/testRequestBoolean","/promotion/testSuccess","/agency/sendmessage","/Alipay/pay");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user