ocr入库
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.czg.market.vo;
|
||||
|
||||
import com.czg.market.entity.MemberOrder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class MmberOrderVO extends MemberOrder {
|
||||
private String nickname;
|
||||
private String phone;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.czg.product.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 销售单实体
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SaleOrderDTO {
|
||||
|
||||
/** 单据类型 */
|
||||
private String documentType;
|
||||
|
||||
/** 销售单号 */
|
||||
private String orderNumber;
|
||||
|
||||
/** 日期 */
|
||||
private String date;
|
||||
|
||||
/** 客户名称 */
|
||||
private String customerName;
|
||||
|
||||
/** 操作员 */
|
||||
private String operator;
|
||||
|
||||
/** 商品明细列表 */
|
||||
private List<Item> items;
|
||||
|
||||
/** 总金额 */
|
||||
private String totalAmount;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 销售单商品明细
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Item {
|
||||
|
||||
/** 商品名称 */
|
||||
private String conName;
|
||||
|
||||
/** 规格 */
|
||||
private String spec;
|
||||
|
||||
/** 单位 */
|
||||
private String unitName;
|
||||
|
||||
/** 数量 */
|
||||
private String inOutNumber;
|
||||
|
||||
/** 单价 */
|
||||
private String purchasePrice;
|
||||
|
||||
/** 金额 */
|
||||
private String subTotal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -17,6 +18,7 @@ import java.math.BigDecimal;
|
||||
* @since 1.0 2025-02-20
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ConsInOutStockBodyParam implements Serializable {
|
||||
|
||||
@Serial
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.czg.product.param;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.czg.product.dto.SaleOrderDTO;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -18,6 +20,7 @@ import java.util.List;
|
||||
* @since 1.0 2025-02-20
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ConsInOutStockHeadParam implements Serializable {
|
||||
|
||||
@Serial
|
||||
@@ -57,4 +60,13 @@ public class ConsInOutStockHeadParam implements Serializable {
|
||||
* 耗材明细列表
|
||||
*/
|
||||
List<ConsInOutStockBodyParam> bodyList;
|
||||
|
||||
/**
|
||||
* 原始识别信息
|
||||
*/
|
||||
private SaleOrderDTO ocrSaleOrder;
|
||||
/**
|
||||
* 未入库信息
|
||||
*/
|
||||
private List<SaleOrderDTO.Item> unInCons;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.czg.product.vo.ConsCheckStockRecordVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -76,4 +77,6 @@ public interface ConsStockFlowService extends IService<ConsStockFlow> {
|
||||
* @param entity 库存变动记录实体
|
||||
*/
|
||||
void saveFlow(ConsStockFlow entity);
|
||||
}
|
||||
|
||||
ConsInOutStockHeadParam ocr(String originalFilename, InputStream inputStream);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.czg.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
@@ -8,8 +7,6 @@ import com.alibaba.dashscope.app.Application;
|
||||
import com.alibaba.dashscope.app.ApplicationParam;
|
||||
import com.alibaba.dashscope.app.ApplicationResult;
|
||||
import com.alibaba.dashscope.app.RagOptions;
|
||||
import com.alibaba.dashscope.exception.InputRequiredException;
|
||||
import com.alibaba.dashscope.exception.NoApiKeyException;
|
||||
import com.aliyun.bailian20231229.Client;
|
||||
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponse;
|
||||
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponseBody;
|
||||
@@ -17,7 +14,7 @@ import com.czg.exception.CzgException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -56,12 +53,12 @@ public class AliOcrUtil {
|
||||
|
||||
|
||||
|
||||
public static ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData applyFileUpload(File file) {
|
||||
String md5 = DigestUtil.md5Hex(file);
|
||||
public static ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData applyFileUpload(InputStream stream, String fileName) {
|
||||
String md5 = DigestUtil.md5Hex(stream);
|
||||
System.out.println(md5);
|
||||
com.aliyun.bailian20231229.Client client = createClient();
|
||||
com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = new com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest()
|
||||
.setFileName(file.getName())
|
||||
.setFileName(fileName)
|
||||
.setMd5(md5)
|
||||
.setSizeInBytes("100000")
|
||||
.setCategoryType("SESSION_FILE")
|
||||
@@ -80,9 +77,9 @@ public class AliOcrUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String uploadFile(File file) {
|
||||
public static String uploadFile(InputStream stream, String fileName) throws Exception {
|
||||
|
||||
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData applyInfo = applyFileUpload(file);
|
||||
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData applyInfo = applyFileUpload(stream, fileName);
|
||||
|
||||
// 获取预签名要求的所有头
|
||||
Map<String, String> headers = (Map<String, String>) applyInfo.getParam().getHeaders();
|
||||
@@ -95,7 +92,7 @@ public class AliOcrUtil {
|
||||
}
|
||||
|
||||
// 设置文件内容
|
||||
request.body(FileUtil.readBytes(file));
|
||||
request.body(stream.readAllBytes());
|
||||
|
||||
HttpResponse resp = request.execute();
|
||||
log.info(resp.body());
|
||||
@@ -103,8 +100,13 @@ public class AliOcrUtil {
|
||||
}
|
||||
|
||||
|
||||
public static void appCall(File file) {
|
||||
String id = uploadFile(file);
|
||||
public static String appCall(InputStream stream, String fileName) {
|
||||
String id = null;
|
||||
try {
|
||||
id = uploadFile(stream, fileName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ApplicationParam param = ApplicationParam.builder()
|
||||
.apiKey("sk-2343af4413834ad1ab43b036e3a903de")
|
||||
.appId("3493340ef5e146c487364395fbca7bf3")
|
||||
@@ -121,13 +123,16 @@ public class AliOcrUtil {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.printf("%s\n",
|
||||
log.info("{}",
|
||||
result.getOutput().getText());
|
||||
return result.getOutput().getText();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
static void main() throws Exception {
|
||||
appCall(new File("C:\\Users\\Administrator\\Downloads\\微信图片_20251121101326_2015_354.jpg"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user