ocr识别修改
This commit is contained in:
@@ -46,4 +46,8 @@ public class MkOcr implements Serializable {
|
||||
|
||||
private Long shopId;
|
||||
|
||||
private String md5;
|
||||
private String status;
|
||||
private String err;
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ public class AliOcrUtil {
|
||||
|
||||
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(fileName)
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.exception.CzgException;
|
||||
@@ -267,12 +268,17 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
@Override
|
||||
public Integer ocr(String originalFilename, InputStream inputStream) {
|
||||
Long shopId = StpKit.USER.getShopId();
|
||||
String md5 = DigestUtil.md5Hex(inputStream);
|
||||
MkOcr ocr = ocrService.getOne(new QueryWrapper().eq(MkOcr::getShopId, shopId).eq(MkOcr::getMd5, md5));
|
||||
if (ocr != null) {
|
||||
return ocr.getId();
|
||||
}
|
||||
MkOcr mkOcr = new MkOcr();
|
||||
mkOcr.setShopId(shopId);
|
||||
mkOcr.setMd5(md5);
|
||||
ocrService.save(mkOcr);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
|
||||
String infoStr = AliOcrUtil.appCall(inputStream, originalFilename);
|
||||
SaleOrderDTO saleOrderDTO = JSONObject.parseObject(infoStr, SaleOrderDTO.class);
|
||||
|
||||
@@ -308,10 +314,14 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
|
||||
.setOcrSaleOrder(saleOrderDTO);
|
||||
|
||||
|
||||
mkOcr.setStatus("SUCCESS");
|
||||
mkOcr.setResp(JSON.toJSONString(headParam));
|
||||
ocrService.updateById(mkOcr);
|
||||
}catch (Exception e) {
|
||||
mkOcr.setErr(e.getMessage());
|
||||
mkOcr.setStatus("FAILED");
|
||||
log.warn("ocr失败: {}", e.getMessage());
|
||||
}finally {
|
||||
ocrService.updateById(mkOcr);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user