|
|
@@ -0,0 +1,87 @@
|
|
|
+package com.fs.hisStore.listener;
|
|
|
+
|
|
|
+import com.fs.common.utils.txocr.TxOcrClient;
|
|
|
+import com.fs.hisStore.domain.FsStoreScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreScrmOcr;
|
|
|
+import com.fs.hisStore.mapper.FsStoreScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreScrmOcrMapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:
|
|
|
+ * @author: Guos
|
|
|
+ * @time: 2025/11/21 上午9:44
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class FsStoreScrmListener {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FsStoreScrmOcrMapper fsStoreScrmOcrMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreScrmMapper fsStoreMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @EventListener
|
|
|
+ public void StoreScrmOcrListener(FsStoreScrm fsStore){
|
|
|
+ log.info("StoreScrmOcrListener start");
|
|
|
+ //先查ocr的表中是否存在,
|
|
|
+ // 1.店铺存在,url不一致 调用识别并更新
|
|
|
+ // 2.店铺存在,url一致,不重新调用识别
|
|
|
+ // 3.店铺不存在,说明是新增,新增直接识别别插入
|
|
|
+ FsStoreScrmOcr fsStoreScrmOcr = new FsStoreScrmOcr();
|
|
|
+ Boolean oldBusinessLicenseFlag = false;
|
|
|
+ Boolean oldDrugLicenseFlag = false;
|
|
|
+ FsStoreScrmOcr OldFsStoreScrmOcr = null;
|
|
|
+ if(null == fsStore.getStoreId()){
|
|
|
+ log.info("新增店铺id为空!");
|
|
|
+ //如果是新增id是自增的,这时候可以先用StoreSeq,或者account以及storeName这种具有唯一性的字段进行反查StoreId
|
|
|
+ String storeSeq = fsStore.getStoreSeq();//这个是必须会生成的,所以我们这直接去查询
|
|
|
+ FsStoreScrm fsStoreScrm = fsStoreMapper.selectFsStoreByStoreSeq(storeSeq);
|
|
|
+ fsStoreScrmOcr.setStoreId(fsStoreScrm.getStoreId());
|
|
|
+ }else{
|
|
|
+ fsStoreScrmOcr.setStoreId(fsStore.getStoreId());
|
|
|
+ OldFsStoreScrmOcr = fsStoreScrmOcrMapper.selectById(fsStore.getStoreId());
|
|
|
+ if(!ObjectUtils.isEmpty(OldFsStoreScrmOcr)){
|
|
|
+ fsStoreScrmOcr.setStoreId(OldFsStoreScrmOcr.getStoreId());
|
|
|
+ String OldBusinessLicense = OldFsStoreScrmOcr.getBusinessLicense();
|
|
|
+ String OldDrugLicense = OldFsStoreScrmOcr.getDrugLicense();
|
|
|
+ oldDrugLicenseFlag = OldDrugLicense.equals(fsStore.getDrugLicense());
|
|
|
+ oldBusinessLicenseFlag = OldBusinessLicense.equals(fsStore.getBusinessLicense());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不一致才会去更新
|
|
|
+ if(!oldBusinessLicenseFlag){
|
|
|
+ fsStoreScrmOcr.setBusinessLicense(fsStore.getBusinessLicense());
|
|
|
+ String result = TxOcrClient.bizLicenseOCR(fsStoreScrmOcr.getBusinessLicense());
|
|
|
+ if(!result.isEmpty()){
|
|
|
+ fsStoreScrmOcr.setBusinessLicenseTxt(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!oldDrugLicenseFlag){
|
|
|
+ fsStoreScrmOcr.setDrugLicense(fsStore.getDrugLicense());
|
|
|
+ String result = TxOcrClient.enterpriseLicenseOCR(fsStore.getDrugLicense());
|
|
|
+ if(!result.isEmpty()){
|
|
|
+ fsStoreScrmOcr.setDrugLicenseTxt(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fsStoreScrmOcr.setUpdateTime(LocalDateTime.now());
|
|
|
+ if(ObjectUtils.isEmpty(OldFsStoreScrmOcr)){
|
|
|
+ fsStoreScrmOcr.setCreateTime(LocalDateTime.now());
|
|
|
+ fsStoreScrmOcrMapper.insert(fsStoreScrmOcr);
|
|
|
+ }else{
|
|
|
+ fsStoreScrmOcrMapper.updateById(fsStoreScrmOcr);
|
|
|
+ }
|
|
|
+ log.info("StoreScrmOcrListener end");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|