|
@@ -4,6 +4,7 @@ package cn.fastfun.controller.api;
|
|
|
import cn.fastfun.service.ProductService;
|
|
|
import cn.fastfun.service.entity.Product;
|
|
|
import cn.fastfun.service.entity.QueryParamForProduct;
|
|
|
+import cn.fastfun.util.ResolveUtil;
|
|
|
import cn.fastfun.util.VerifyUtil;
|
|
|
import com.bridge.dto.*;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -28,64 +29,43 @@ public class ProductController {
|
|
|
|
|
|
// 针对产品规格这一项进行操作
|
|
|
if(product.getSnType().equals("产品规格")){
|
|
|
-
|
|
|
- String[] SnTypeDescList = product.getSnTypeDesc().split(" ");
|
|
|
- List<Product> productSpecification = new ArrayList<>();
|
|
|
-
|
|
|
- String chemicalSystemCode = product.getSnTypeCode().substring(0,1);
|
|
|
- String chemicalSystemDesc = SnTypeDescList[0];
|
|
|
- String batteryPlatformCode = product.getSnTypeCode().substring(1,2);
|
|
|
- String batteryPlatformDesc = SnTypeDescList[1];
|
|
|
- String capacityCode = product.getSnTypeCode().substring(2,4);
|
|
|
- String capacityDesc = SnTypeDescList[2];
|
|
|
-
|
|
|
- Product chemicalSystem = new Product();
|
|
|
- chemicalSystem.setSnType("化学体系");
|
|
|
- chemicalSystem.setSnTypeCode(chemicalSystemCode);
|
|
|
- chemicalSystem.setSnTypeDesc(chemicalSystemDesc);
|
|
|
- chemicalSystem.setOperator(product.getOperator());
|
|
|
- String checkSnTypeCodeResultOnChemicalSystem = VerifyUtil.checkSnTypeCode(chemicalSystem);
|
|
|
- if(checkSnTypeCodeResultOnChemicalSystem.equals("passed")){
|
|
|
- Product tmp_1 = productService.save(chemicalSystem);
|
|
|
- productSpecification.add(tmp_1);}
|
|
|
- else{
|
|
|
- return ApiDTO.error(500,checkSnTypeCodeResultOnChemicalSystem);
|
|
|
+ String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
|
|
|
+ if(!(checkSnTypeCodeResult.equals("passed"))){
|
|
|
+ return ApiDTO.error(500,checkSnTypeCodeResult);
|
|
|
}
|
|
|
-
|
|
|
- Product batteryPlatform = new Product();
|
|
|
- batteryPlatform.setSnType("电池平台");
|
|
|
- batteryPlatform.setSnTypeCode(batteryPlatformCode);
|
|
|
- batteryPlatform.setSnTypeDesc(batteryPlatformDesc);
|
|
|
- batteryPlatform.setOperator(product.getOperator());
|
|
|
- String checkSnTypeCodeResultOnBatteryPlatform = VerifyUtil.checkSnTypeCode(batteryPlatform);
|
|
|
- if(checkSnTypeCodeResultOnBatteryPlatform.equals("passed")){
|
|
|
- Product tmp_2 = productService.save(batteryPlatform);
|
|
|
- productSpecification.add(tmp_2);}
|
|
|
- else{
|
|
|
- return ApiDTO.error(500,checkSnTypeCodeResultOnChemicalSystem);
|
|
|
+ List<Product> productSpecificationResults = ResolveUtil.resolveProductSpecification(product);
|
|
|
+ List<List<Product>> checkDuplicatedResults = new ArrayList<>();
|
|
|
+
|
|
|
+ for(Product productSpecificationResult:productSpecificationResults) {
|
|
|
+ List<Product> checkDuplicatedResult = productService.findAll(
|
|
|
+ Arrays.asList(QueryParamExp.eq("snTypeCode", productSpecificationResult.getSnTypeCode()),
|
|
|
+ QueryParamExp.eq("snType", productSpecificationResult.getSnType())));
|
|
|
+
|
|
|
+ checkDuplicatedResults.add(checkDuplicatedResult);
|
|
|
+
|
|
|
+ String checkSnTypeCodeResultForEach = VerifyUtil.checkSnTypeCode(productSpecificationResult);
|
|
|
+ if((checkSnTypeCodeResultForEach.equals("passed"))&(checkDuplicatedResult.isEmpty())){
|
|
|
+ productService.save(productSpecificationResult);
|
|
|
+ }
|
|
|
+ else if(!(checkSnTypeCodeResultForEach.equals("passed"))){
|
|
|
+ return ApiDTO.error(500,checkSnTypeCodeResultForEach);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- Product capacity = new Product();
|
|
|
- capacity.setSnType("容量");
|
|
|
- capacity.setSnTypeCode(capacityCode);
|
|
|
- capacity.setSnTypeDesc(capacityDesc);
|
|
|
- capacity.setOperator(product.getOperator());
|
|
|
- String checkSnTypeCodeResultOnCapacity = VerifyUtil.checkSnTypeCode(capacity);
|
|
|
- if(checkSnTypeCodeResultOnCapacity.equals("passed")){
|
|
|
- Product tmp_3 = productService.save(capacity);
|
|
|
- productSpecification.add(tmp_3);}
|
|
|
- else{
|
|
|
- return ApiDTO.error(500,checkSnTypeCodeResultOnChemicalSystem);
|
|
|
+ if((!(checkDuplicatedResults.get(0).isEmpty()))&(!(checkDuplicatedResults.get(1).isEmpty()))&(!(checkDuplicatedResults.get(2).isEmpty()))){
|
|
|
+ return ApiDTO.error(500,"该产品规格对应的三个规则行已存在,未进行任何保存",checkDuplicatedResults);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- return ApiDTO.ok("保存成功",productSpecification);
|
|
|
+ return ApiDTO.ok("保存成功,未保存的规则行id为null",productSpecificationResults);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 校验输入的SN类型对应的编号
|
|
|
String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
|
|
|
-
|
|
|
+ List<Product> checkDuplicatedResult = productService.findAll(
|
|
|
+ Arrays.asList(QueryParamExp.eq("snTypeCode",product.getSnTypeCode()),
|
|
|
+ QueryParamExp.eq("snType",product.getSnType())));
|
|
|
+ if(!checkDuplicatedResult.isEmpty()){
|
|
|
+ return ApiDTO.error(500,"该规则行已存在",checkDuplicatedResult);
|
|
|
+ }
|
|
|
if(checkSnTypeCodeResult.equals("passed")){
|
|
|
Product tmp = productService.save(product);
|
|
|
return ApiDTO.ok("保存成功",tmp);}
|