chen 2 年 前
コミット
6f67ce2ad0

+ 4 - 0
src/main/java/org/springblade/applet/ProductReworkApiController.java

@@ -164,6 +164,10 @@ public class ProductReworkApiController {
 		}
 		if(StringUtil.isNotBlank(productRework.getQrCode())){
 			if(!productRework.getQrCode().equals(detail.getQrCode())){
+				long count = productService.count(Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getFactoryId,detail.getFactoryId()).eq(ProductEntity::getQrCode,productRework.getQrCode()));
+				if(count>0){
+					return R.fail("产品二维码已存在");
+				}
 				ProductEntity product = new ProductEntity();
 				product.setId(detail.getProductId());
 				product.setQrCode(productRework.getQrCode());

+ 9 - 6
src/main/java/org/springblade/modules/pl/productRework/service/impl/ProductReworkServiceImpl.java

@@ -86,10 +86,6 @@ public class ProductReworkServiceImpl extends BaseServiceImpl<ProductReworkMappe
 		String productCode = productRework.getQrCode();
 
 		BladeUser user = AuthUtil.getUser();
-		long count = productService.count(Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getQrCode,productRework.getQrCode()).eq(ProductEntity::getFactoryId,user.getFactoryId()));
-		if(count>0){
-			return R.fail("产品已下线,无法维修");
-		}
 		// 获取可重入锁, 指定锁的名称
 		RLock lock = redissonLock.getLock("lock:cameraUploadImg:"+productRework.getQrCode());
 		// 尝试获取锁
@@ -102,12 +98,19 @@ public class ProductReworkServiceImpl extends BaseServiceImpl<ProductReworkMappe
 				if(productCode.length()<25){
 					return R.fail("产品码'"+productCode+"'小于25位");
 				}
+				ProductEntity productEntity = productService.getOne(Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getQrCode,productRework.getQrCode()).eq(ProductEntity::getFactoryId,user.getFactoryId()),false);
+				if(productEntity!=null && productEntity.getStatus()!=3){
+					return R.fail("产品已下线或在维修中,无法发起维修");
+				}
+
 				String code = productCode.substring(8,12);
 				ProductModelEntity productModel = productModelService.getOne(Wrappers.<ProductModelEntity>lambdaQuery().eq(ProductModelEntity::getProductSpec,code).eq(ProductModelEntity::getFactoryId,user.getFactoryId()),false);
 				if(productModel==null){
 					return R.fail("未找到型号码为'"+code+"'的数据");
 				}else{
-					ProductEntity productEntity = new ProductEntity();
+					if(productEntity==null){
+						productEntity = new ProductEntity();
+					}
 					productEntity.setTenantId(productModel.getTenantId());
 					productEntity.setFactoryId(productModel.getFactoryId());
 //					productEntity.setClientId(productModel.getClientId());
@@ -116,7 +119,7 @@ public class ProductReworkServiceImpl extends BaseServiceImpl<ProductReworkMappe
 					productEntity.setProductModel(productModel.getProductModel());
 					productEntity.setQrCode(productCode);
 					productEntity.setStatus(1);
-					productService.save(productEntity);
+					productService.saveOrUpdate(productEntity);
 					ProductReworkEntity productReworkEntity = new ProductReworkEntity();
 					productReworkEntity.setFactoryId(productEntity.getFactoryId());
 					productReworkEntity.setProductId(productEntity.getId());