|
@@ -2,6 +2,7 @@ package com.pavis.ai.kwp.ioc.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import com.pavis.ai.kwp.ioc.common.event.OcrEvent;
|
|
|
import com.pavis.ai.kwp.ioc.common.utils.DateTimeUtils;
|
|
|
import com.pavis.ai.kwp.ioc.dto.meta.IrRes;
|
|
|
import com.pavis.ai.kwp.ioc.dto.meta.IrRet;
|
|
@@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationEventPublisher;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -24,6 +26,8 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
|
|
|
+ private ApplicationEventPublisher applicationEventPublisher;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CtrService ctrService;
|
|
|
@Autowired
|
|
@@ -42,6 +46,7 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
// @Async("recAndSaveExecutor")
|
|
|
@Override
|
|
|
public void recAndSave(OcrGoods ocrGoods) {
|
|
|
+ log.info("start rec and save");
|
|
|
QueryWrapper<UpGoods> ugw = new QueryWrapper<>();
|
|
|
ugw.lambda().eq(UpGoods::getUploadId, ocrGoods.getUploadId());
|
|
|
List<UpGoods> upGoods = upGoodsMapper.selectList(ugw);
|
|
@@ -62,6 +67,8 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
} else {
|
|
|
goodsLog.setGError(false);
|
|
|
goodsLog.setGDone(true);
|
|
|
+ // 通知监听器
|
|
|
+ applicationEventPublisher.publishEvent(new OcrEvent(this, "G", ocrGoods.getUploadId()));
|
|
|
}
|
|
|
goodsLog.setGFinishTime(DateTimeUtils.dateTimeNow());
|
|
|
goodsLog.setGTimeConsume(DateTimeUtils.calculateTimeConsume(goodsLog.getGStartTime(), goodsLog.getGFinishTime()));
|
|
@@ -105,11 +112,15 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
} else {
|
|
|
goodsLog.setGError(false);
|
|
|
goodsLog.setGDone(true);
|
|
|
+ // 通知监听器
|
|
|
+ applicationEventPublisher.publishEvent(new OcrEvent(this, "G", goodsLog.getUploadId()));
|
|
|
}
|
|
|
goodsLog.setTimes(goodsLog.getTimes() + 1);
|
|
|
} else {
|
|
|
goodsLog.setGError(true);
|
|
|
goodsLog.setGDone(true);
|
|
|
+ // 通知监听器
|
|
|
+ applicationEventPublisher.publishEvent(new OcrEvent(this, "G", goodsLog.getUploadId()));
|
|
|
}
|
|
|
goodsLogMapper.updateById(goodsLog);
|
|
|
}
|
|
@@ -120,7 +131,6 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
// 检查是否已有识别结果
|
|
|
List<SubImg> subImgList = subImgMapper.selectList(wrapper);
|
|
|
if (CollectionUtils.isEmpty(subImgList)) {
|
|
|
- GoodsLog goodsLog = goodsLogMapper.selectById(uploadId);
|
|
|
IrRes res = null;
|
|
|
try {
|
|
|
res = ctrService.startRequest(uploadId, ug.getGoodsImg());
|
|
@@ -133,7 +143,6 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
.build();
|
|
|
errGoodsMapper.insert(err);
|
|
|
log.error("商品图片:{},识别出错:{}", ug.getGoodsImg(), e.getMessage());
|
|
|
- goodsLog.setGError(true);
|
|
|
}
|
|
|
if (res != null) {
|
|
|
if (StringUtils.isBlank(res.getErrorCode())) {
|
|
@@ -147,7 +156,6 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
.createTime(DateTimeUtils.dateTimeNow())
|
|
|
.build();
|
|
|
errGoodsMapper.insert(err);
|
|
|
- goodsLog.setGError(true);
|
|
|
}
|
|
|
} else {
|
|
|
ErrGoods err = ErrGoods.builder()
|
|
@@ -157,9 +165,7 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
.createTime(DateTimeUtils.dateTimeNow())
|
|
|
.build();
|
|
|
errGoodsMapper.insert(err);
|
|
|
- goodsLog.setGError(true);
|
|
|
}
|
|
|
- goodsLogMapper.updateById(goodsLog);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -194,4 +200,9 @@ public class OcrGoodsServiceImpl implements OcrGoodsService {
|
|
|
errGoodsMapper.insert(err);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
+ this.applicationEventPublisher = applicationEventPublisher;
|
|
|
+ }
|
|
|
}
|