Parcourir la source

产品第三方接口推送

chen il y a 1 an
Parent
commit
31b215120b

+ 39 - 0
src/main/java/org/springblade/api/utils/FileUtils.java

@@ -0,0 +1,39 @@
+package org.springblade.api.utils;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+public class FileUtils {
+
+	public static File getFileByUrl(String fileUrl, String suffix){
+		try {
+			// 从URL获取文件内容
+			URL url = new URL(fileUrl);
+			URLConnection urlConnection = url.openConnection();
+			// 创建一个临时文件
+			File tempFile = File.createTempFile("tempfile", suffix);
+			try (InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
+				 OutputStream outputStream = Files.newOutputStream(tempFile.toPath())) {
+
+				// 复制文件内容到临时文件
+				byte[] buffer = new byte[4096];
+				int bytesRead;
+				while ((bytesRead = inputStream.read(buffer)) != -1) {
+					outputStream.write(buffer, 0, bytesRead);
+				}
+				return tempFile;
+			}
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	public static void main(String[] args) {
+		System.out.println(getFileByUrl("https://ai.my-123.cn/pic/product-line/upload/20240415/b3df69006e3de829970490d181870ddf.jpg", "jpg"));
+	}
+}

+ 11 - 0
src/main/java/org/springblade/app/AppApiController.java

@@ -36,6 +36,8 @@ import org.springblade.modules.pl.product.vo.ProductImageRecordVO;
 import org.springblade.modules.pl.product.vo.ProductVO;
 import org.springblade.modules.pl.product.wrapper.ProductImageRecordWrapper;
 import org.springblade.modules.pl.product.wrapper.ProductWrapper;
+import org.springblade.modules.pl.productModel.entity.ProductModelEntity;
+import org.springblade.modules.pl.productModel.service.IProductModelService;
 import org.springblade.modules.pl.productRework.entity.ProductReworkEntity;
 import org.springblade.modules.pl.productRework.service.IProductReworkService;
 import org.springblade.modules.pl.productRework.vo.ProductReworkVO;
@@ -62,6 +64,7 @@ public class AppApiController {
 	private final IGoodsMaterialService goodsMaterialService;
 	private final IProductService productService;
 	private final IProductReworkService productReworkService;
+	private final IProductModelService productModelService;
 
 	/**
 	 * 获取设备信息 分页
@@ -213,6 +216,14 @@ public class AppApiController {
 			productReworkService.save(productReworkEntity);
 
 		}
+		ProductModelEntity productModel = productModelService.getById(productEntity.getProductModelId());
+
+		if(productEntity!=null && productModel!=null && productModel.getIsPushTripartite()==1){
+			if(productEntity.getAiStatus()==-1 || productEntity.getAiStatus()==2){
+				productService.pushTripartite(productEntity.getQrCode(),aiImg,productModel,"OK");
+			}
+		}
+
 		return R.success("操作成功");
 	}
 }

+ 6 - 0
src/main/java/org/springblade/applet/ProductApiController.java

@@ -253,6 +253,12 @@ public class ProductApiController {
 			productReworkService.save(productReworkEntity);
 
 		}
+		ProductModelEntity productModel = productModelService.getById(productEntity.getProductModelId());
+		if(productEntity!=null && productModel!=null && productModel.getIsPushTripartite()==1){
+			if(productEntity.getAiStatus()==-1 || productEntity.getAiStatus()==2){
+				productService.pushTripartite(productEntity.getQrCode(),aiImg,productModel,"OK");
+			}
+		}
 		return R.success("操作成功");
 	}
 

+ 4 - 0
src/main/java/org/springblade/modules/pl/product/service/IProductService.java

@@ -17,11 +17,14 @@
 package org.springblade.modules.pl.product.service;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import org.springblade.core.oss.model.BladeFile;
 import org.springblade.modules.pl.product.entity.ProductEntity;
 import org.springblade.modules.pl.product.vo.ProductVO;
 import org.springblade.modules.pl.product.excel.ProductExcel;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.core.mp.base.BaseService;
+import org.springblade.modules.pl.productModel.entity.ProductModelEntity;
+
 import java.util.List;
 
 /**
@@ -49,4 +52,5 @@ public interface IProductService extends BaseService<ProductEntity> {
 	 */
 	List<ProductExcel> exportProduct(Wrapper<ProductEntity> queryWrapper);
 
+    void pushTripartite(String productCode, String fileUl, ProductModelEntity productModel ,String result);
 }

+ 7 - 1
src/main/java/org/springblade/modules/pl/product/service/impl/ProductImageRecordServiceImpl.java

@@ -98,6 +98,7 @@ public class ProductImageRecordServiceImpl extends BaseServiceImpl<ProductImageR
 	@Override
 	public ProductImageRecordVO submit(String productCode, EquipmentEntity equipmentEntity, ProductImageRecordEntity productImageRecord, BladeFile bladeFile, FactoryEntity factory) {
 		ProductEntity productEntity = null;
+		ProductModelEntity productModel = null;
 		//ai识别状态 -1无需识别 0未识别 1ng 2ok 3人工ok
 		int aiStatus = -1;
 		productImageRecord.setEquipmentId(equipmentEntity.getId());
@@ -107,7 +108,7 @@ public class ProductImageRecordServiceImpl extends BaseServiceImpl<ProductImageR
 			productImageRecord.setMessage("产品码'"+productCode+"'小于18位");
 		}else{
 			String code = productCode.substring(8,12);
-			ProductModelEntity productModel = productModelService.getOne(Wrappers.<ProductModelEntity>lambdaQuery().eq(ProductModelEntity::getProductSpec,code).eq(ProductModelEntity::getFactoryId,equipmentEntity.getFactoryId()),false);
+			productModel = productModelService.getOne(Wrappers.<ProductModelEntity>lambdaQuery().eq(ProductModelEntity::getProductSpec,code).eq(ProductModelEntity::getFactoryId,equipmentEntity.getFactoryId()),false);
 			if(productModel==null){
 				productImageRecord.setStatus(2);
 				productImageRecord.setMessage("未找到型号码为'"+code+"'的数据");
@@ -313,6 +314,11 @@ public class ProductImageRecordServiceImpl extends BaseServiceImpl<ProductImageR
 				}
 			}
 		}
+		if(productEntity!=null && productModel!=null && productModel.getIsPushTripartite()==1){
+			if(productEntity.getAiStatus()==-1 || productEntity.getAiStatus()==2){
+				productService.pushTripartite(productCode,productEntity.getAiStatus()==-1?productImageRecord.getProductImage():productImageRecord.getProductAiImage(),productModel,"OK");
+			}
+		}
 		this.save(productImageRecord);
 		ProductImageRecordVO productImageRecordVO = ProductImageRecordWrapper.build().entityVO(productImageRecord);
 		productImageRecordVO.setAiStatus(aiStatus);

+ 31 - 0
src/main/java/org/springblade/modules/pl/product/service/impl/ProductServiceImpl.java

@@ -16,16 +16,26 @@
  */
 package org.springblade.modules.pl.product.service.impl;
 
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.api.utils.FileUtils;
+import org.springblade.common.utils.PostGet;
+import org.springblade.core.http.util.HttpUtil;
+import org.springblade.core.oss.model.BladeFile;
 import org.springblade.modules.pl.product.entity.ProductEntity;
 import org.springblade.modules.pl.product.vo.ProductVO;
 import org.springblade.modules.pl.product.excel.ProductExcel;
 import org.springblade.modules.pl.product.mapper.ProductMapper;
 import org.springblade.modules.pl.product.service.IProductService;
+import org.springblade.modules.pl.productModel.entity.ProductModelEntity;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.core.mp.base.BaseServiceImpl;
+
+import java.io.File;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 产品表 服务实现类
@@ -34,6 +44,7 @@ import java.util.List;
  * @since 2023-12-05
  */
 @Service
+@Slf4j
 public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEntity> implements IProductService {
 
 	@Override
@@ -51,4 +62,24 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn
 		return productList;
 	}
 
+	@Override
+	public void pushTripartite(String productCode, String fileUlr, ProductModelEntity productModel ,String result) {
+		File file = FileUtils.getFileByUrl(fileUlr,".jpg");
+		Map<String,Object> param = new HashMap<>();
+		param.put("sn",productCode);
+		param.put("result",result);
+		param.put("file",file);
+		log.info("产品-{}推送三方平台result:{},fileUrl:{}",productCode,result,fileUlr);
+		String postResult = HttpUtil.post(productModel.getTripartiteUrl(), param);
+		log.info("产品-{}推送三方平台结果:{}",productCode,postResult);
+//		HttpUtil.post()
+	}
+
+	public static void main(String[] args) {
+		Map<String,Object> param = new HashMap<>();
+		param.put("sn","test1");
+		param.put("result","OK");
+		param.put("file",new File("C:\\Users\\86180\\Desktop\\logo\\logo2.jpg"));
+		System.out.println(HttpUtil.post("http://121.36.53.58:8099/js/a/mes/mesProductMpp/add", param));
+	}
 }

+ 10 - 0
src/main/java/org/springblade/modules/pl/productModel/entity/ProductModelEntity.java

@@ -99,4 +99,14 @@ public class ProductModelEntity extends TenantEntity {
 	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private String processConfigId;
 
+	/**
+	 * 是否上传三方平台
+	 */
+	@ApiModelProperty(value = "是否上传三方平台")
+	private Integer isPushTripartite;
+	/**
+	 * 三方平台地址
+	 */
+	@ApiModelProperty(value = "三方平台地址")
+	private String tripartiteUrl;
 }