dev798
parent
88de15ced1
commit
8296126d9f
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -50,9 +50,10 @@ public class ProductController {
|
|||
return success(list);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("添加商品")
|
||||
@PostMapping("/productInsert")
|
||||
public R<Product>productInsert(@Valid @RequestBody ProductReq productReq){
|
||||
public R productInsert(@Valid @RequestBody ProductReq productReq){
|
||||
productService.productInsert(productReq);
|
||||
return R.ok(null,"添加成功");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.product.mapper;
|
|||
|
||||
import com.muyu.product.domain.DTO.Product;
|
||||
import com.muyu.product.domain.Resp.ProductResp;
|
||||
import com.muyu.product.domain.req.ProductReq;
|
||||
import com.muyu.product.domain.req.QueryProductReq;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -19,7 +18,8 @@ public interface ProductMapper {
|
|||
|
||||
void updateMothodId(Integer id);
|
||||
|
||||
Integer findProductNumber(ProductReq productReq);
|
||||
Integer findProductNumber(String productNumber);
|
||||
|
||||
|
||||
Integer deleteProduct(Integer id);
|
||||
}
|
||||
|
|
|
@ -35,10 +35,6 @@ import java.util.concurrent.Executors;
|
|||
@Log4j2
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
private final Integer min = 0;
|
||||
|
||||
private final Integer max = 5;
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
|
@ -54,33 +50,49 @@ public class ProductServiceImpl implements ProductService {
|
|||
private ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
|
||||
|
||||
public void checkProductParams(ProductReq productReq){
|
||||
CompletableFuture<ValidationResult>methodTypeFuture =
|
||||
CompletableFuture.supplyAsync(() -> checkMethodType(productReq),executor);
|
||||
CompletableFuture<ValidationResult>skuIdFuture =
|
||||
CompletableFuture.supplyAsync(() -> findSkuId(productReq),executor);
|
||||
CompletableFuture<ValidationResult>productNumberFuture =
|
||||
CompletableFuture.supplyAsync(() -> checkProductNumber(productReq),executor);
|
||||
CompletableFuture<String>allValidFuture =
|
||||
methodTypeFuture.thenCombine(skuIdFuture,
|
||||
(methodTypeResult,skuIdResult)->
|
||||
methodTypeResult.isValid()&& skuIdResult.isValid())
|
||||
.thenCombine(productNumberFuture,(previousResult,productNumberResult)
|
||||
->previousResult&&productNumberResult.isValid())
|
||||
.thenApply(allValid->allValid ? "所有检查通过":"存在检查未通过")
|
||||
.exceptionally(throwable -> "检验过程发送异常" + throwable.getMessage());
|
||||
// 检查产品参数
|
||||
public void checkProductParams(ProductReq productReq) {
|
||||
try {
|
||||
// 异步执行方法类型检查
|
||||
CompletableFuture<ValidationResult> methodTypeFuture =
|
||||
CompletableFuture.supplyAsync(() -> checkMethodType(productReq), executor);
|
||||
// 异步执行查找skuId检查
|
||||
CompletableFuture<ValidationResult> skuIdFuture =
|
||||
CompletableFuture.supplyAsync(() -> findSkuId(productReq), executor);
|
||||
// 异步执行产品编号检查
|
||||
CompletableFuture<ValidationResult> productNumberFuture =
|
||||
CompletableFuture.supplyAsync(() -> checkProductNumber(productReq), executor);
|
||||
|
||||
allValidFuture.thenAccept(System.out::println);
|
||||
}
|
||||
// 组合所有的异步任务,判断是否所有检查通过
|
||||
CompletableFuture<String> allValidFuture =
|
||||
CompletableFuture.allOf(methodTypeFuture, skuIdFuture, productNumberFuture)
|
||||
.thenApply(ignored -> {
|
||||
boolean allValid = methodTypeFuture.join().isValid()
|
||||
&& skuIdFuture.join().isValid()
|
||||
&& productNumberFuture.join().isValid();
|
||||
return allValid ? "所有检查通过" : "存在检查未通过";
|
||||
})
|
||||
.exceptionally(throwable -> "校验过程发生异常: " + throwable.getMessage());
|
||||
|
||||
private ValidationResult checkProductNumber(ProductReq productReq) {
|
||||
Integer productNumber = productMapper.findProductNumber(productReq);
|
||||
if(productNumber>=Integer.valueOf(Number.zero.getValue())){
|
||||
return new ValidationResult(false,"productNumber不能重复");
|
||||
// 输出结果
|
||||
allValidFuture.thenAccept(System.out::println);
|
||||
} catch (Exception e) {
|
||||
System.err.println("校验过程发生异常: " + e.getMessage());
|
||||
}
|
||||
return new ValidationResult(true,"通过");
|
||||
}
|
||||
|
||||
// 检查产品编号
|
||||
private ValidationResult checkProductNumber(ProductReq productReq) {
|
||||
try {
|
||||
Integer productNumber = productMapper.findProductNumber(String.valueOf(productReq.getProduct().getProductNumber()));
|
||||
if (productNumber < Integer.valueOf(Number.zero.getValue())) {
|
||||
return new ValidationResult(false, "productNumber不能重复");
|
||||
}
|
||||
return new ValidationResult(true, "productNumber检查通过");
|
||||
} catch (Exception e) {
|
||||
return new ValidationResult(false, "检查产品编号时发生异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
private ValidationResult findSkuId(ProductReq productReq) {
|
||||
Integer skuId = productSkuMapper.findSkuId(productReq.getProductSkus());
|
||||
if(skuId>=Integer.valueOf(Number.zero.getValue())){
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 111.231.174.71:8848
|
||||
namespace: addbe994-b6ee-4b87-bde0-76f34d2681bd
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
Loading…
Reference in New Issue