소스 검색

Merge remote-tracking branch 'origin/ScrmStores' into ScrmStores

yjwang 2 주 전
부모
커밋
dcbefd22fa

+ 66 - 2
fs-common/src/main/java/com/fs/common/utils/txocr/TxOcrClient.java

@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * @description:
@@ -22,12 +24,74 @@ public class TxOcrClient  {
 
     private static final String YPLS = "药品零售";
 
+
+    /**
+     * 营业执照识别
+     * @param imageUrl
+     * @return
+     */
+    public static String bizLicenseOCR(String imageUrl){
+        try{
+            Credential cred = new Credential("AKIDviPyMZbRp24udCcpqjQxHOK4cx88ze6N", "97tVwEJE81sY0StDPPGukQ2ZvkU3QceY");
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+            OcrClient client = new OcrClient(cred, "", clientProfile);
+            BizLicenseOCRRequest req = new BizLicenseOCRRequest();
+            req.setImageUrl(imageUrl);
+            BizLicenseOCRResponse resp = client.BizLicenseOCR(req);
+            String business = resp.getBusiness();
+            return business;
+        } catch (TencentCloudSDKException e) {
+            log.info("营业执照OCR请求发生异常!异常信息是:{}",e.toString());
+        }
+        return null;
+    }
+
+
+    /**
+     * 药品经营许可证识别
+     * @param imageUrl
+     * @return
+     */
+    public static String enterpriseLicenseOCR(String imageUrl){
+        try{
+            Credential cred = new Credential("AKIDviPyMZbRp24udCcpqjQxHOK4cx88ze6N", "97tVwEJE81sY0StDPPGukQ2ZvkU3QceY");
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+            OcrClient client = new OcrClient(cred, "", clientProfile);
+            EnterpriseLicenseOCRRequest req = new EnterpriseLicenseOCRRequest();
+            req.setImageUrl(imageUrl);
+            EnterpriseLicenseOCRResponse resp = client.EnterpriseLicenseOCR(req);
+            Optional<EnterpriseLicenseInfo> jyfw = Arrays.stream(resp.getEnterpriseLicenseInfos())
+                    .filter(enterpriseLicenseInfo -> enterpriseLicenseInfo.getName().equals("经营范围")).findAny();
+            if(!jyfw.isPresent()){
+                return null;
+            }
+            AtomicReference<String> value = new AtomicReference<>();
+                    Arrays.stream(resp.getEnterpriseLicenseInfos()).forEach(enterpriseLicenseInfo -> {
+                String name = enterpriseLicenseInfo.getName();
+                if(name.equals("经营范围")){
+                    value.set(enterpriseLicenseInfo.getValue());
+                }
+            });
+            log.info("许可证书OCR请求识别成功!结果是:{}",AbstractModel.toJsonString(resp));
+            return value.get();
+        } catch (TencentCloudSDKException e) {
+            log.info("证书识别失败!异常信息是:{}",e.toString());
+        }
+        return null;
+    }
+
     /**
      * BizLicenseOCR
      * 本接口支持快速精准识别营业执照上的字段,包括统一社会信用代码、公司名称、主体类型、法定代表人、注册资本、组成形式、成立日期、营业期限和经营范围等字段。
      * 默认接口请求频率限制:10次/秒。
-     * @param imageUrl
-     * @param keywords
+     * @param imageUrl 图片url
+     * @param keywords 需要对比的关键字
      * @return ContainsResult
      */
     public static ContainsResult isContains(String imageUrl, String keywords) {

+ 62 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreScrmOcr.java

@@ -0,0 +1,62 @@
+package com.fs.hisStore.domain;
+
+import java.time.LocalDateTime;
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+import org.springframework.data.annotation.Id;
+
+/**
+ * @description: 店铺OCR识别信息实体类
+ * @author: Guos
+ * @time: 2025/11/21 上午9:35
+ */
+@Data
+public class FsStoreScrmOcr {
+
+    /**
+     * 店铺ID
+     */
+    @Id
+    private Long storeId;
+
+    /**
+     * 营业执照文件url
+     */
+    private String businessLicense;
+
+    /**
+     * 营业执照文件经营范围描述
+     */
+    private String businessLicenseTxt;
+
+    /**
+     * 药品经营许可证文件
+     */
+    private String drugLicense;
+
+    /**
+     * 药品经营许可证文件经营范围描述
+     */
+    private String drugLicenseTxt;
+
+    /**
+     * 营业执照返回的全部结果
+     */
+    private String businessLicenseOcrResult;
+
+    /**
+     * 药品经营许可证返回的全部结果
+     */
+    private String drugLicenseOcrResult;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 修改时间
+     */
+    private LocalDateTime updateTime;
+
+}

+ 87 - 0
fs-service/src/main/java/com/fs/hisStore/listener/FsStoreScrmListener.java

@@ -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");
+    }
+
+}

+ 10 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreScrmMapper.java

@@ -210,4 +210,14 @@ public interface FsStoreScrmMapper
      * @return
      * **/
     List<FsStoreProductScrmInfoDTO> getStoreInfo(@Param("storeIds") Long[] storeIds);
+
+    /**
+     * 查询店铺管理
+     *
+     * @param storeSeq 店铺管理主键
+     * @return 店铺管理
+     */
+    FsStoreScrm selectFsStoreByStoreSeq(@Param("storeSeq") String storeSeq);
+
+
 }

+ 32 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreScrmOcrMapper.java

@@ -0,0 +1,32 @@
+package com.fs.hisStore.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fs.hisStore.domain.FsStoreScrmOcr;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @description:
+ * @author: Guos
+ * @time: 2025/11/21 上午9:37
+ */
+public interface FsStoreScrmOcrMapper {
+
+
+    FsStoreScrmOcr selectById(@Param("storeId") Long storeId);
+
+    /**
+     * 插入店铺OCR信息记录
+     * @param fsStoreScrmOcr 店铺OCR信息实体对象
+     * @return 影响的记录数
+     */
+    int insert(FsStoreScrmOcr fsStoreScrmOcr);
+
+    /**
+     * 根据店铺ID更新OCR信息记录
+     * @param fsStoreScrmOcr 店铺OCR信息实体对象
+     * @return 影响的记录数
+     */
+    int updateById(FsStoreScrmOcr fsStoreScrmOcr);
+
+
+}

+ 14 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreScrmServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanWrapper;
 import org.springframework.beans.BeanWrapperImpl;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -49,6 +50,7 @@ import java.util.stream.Collectors;
 @Service
 @Slf4j
 public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
+
     @Autowired
     private FsStoreScrmMapper fsStoreMapper;
 
@@ -57,11 +59,16 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
 
     @Autowired
     private FsStoreProductScrmMapper fsStoreProduct;
+
     @Autowired
     private ConfigUtil configUtil;
 
     private static final String MERCHANT_PREFIX = "YJB";
 
+    @Autowired
+    private ApplicationEventPublisher applicationEventPublisher;
+
+
     /**
      * 查询店铺管理
      *
@@ -97,6 +104,7 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
      */
     @Override
     public Long insertFsStore(FsStoreScrm fsStore) {
+        //检查商家填写的账号是否重复
         if (fsStore.getAccount() != null) {
             FsStoreScrm fs = fsStoreMapper.selectFsStoreByAccount(fsStore.getAccount());
             if (fs != null) {
@@ -127,6 +135,8 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
         fsStore.setStoreSeq(sequence);
         fsStore.setQualificationUpdateTime(LocalDate.now());
         fsStoreMapper.insertFsStore(fsStore);
+        //信息发布
+        applicationEventPublisher.publishEvent(fsStore);
         return fsStore.getStoreId();
     }
 
@@ -230,7 +240,10 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
             log.error("获取diff出错", e);
         }
         fsStore.setQualificationUpdateTime(LocalDate.now());
-        return fsStoreMapper.updateFsStore(fsStore);
+        int updateRowNum = fsStoreMapper.updateFsStore(fsStore);
+        //信息发布
+        applicationEventPublisher.publishEvent(fsStore);
+        return updateRowNum;
     }
 
     @Override

+ 9 - 0
fs-service/src/main/resources/mapper/hisStore/FsStoreScrmMapper.xml

@@ -963,4 +963,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{item}
         </foreach>
     </select>
+
+    <select id="selectFsStoreByStoreSeq" resultType="com.fs.hisStore.domain.FsStoreScrm">
+        select
+            store_id,
+            business_license,
+            drug_license
+        from fs_store_scrm
+        where store_seq= #{storeSeq}
+    </select>
 </mapper>

+ 77 - 0
fs-service/src/main/resources/mapper/hisStore/FsStoreScrmOcrMapper.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.hisStore.mapper.FsStoreScrmOcrMapper">
+
+    <!-- 插入店铺OCR信息记录 -->
+    <insert id="insert" parameterType="com.fs.hisStore.domain.FsStoreScrmOcr">
+        INSERT INTO fs_store_scrm_ocr (
+            store_id,
+            business_license,
+            business_license_txt,
+            drug_license,
+            drug_license_txt,
+            business_license_ocr_result,
+            drug_license_ocr_result,
+            create_time,
+            update_time
+        ) VALUES (
+            #{storeId},
+            #{businessLicense},
+            #{businessLicenseTxt},
+            #{drugLicense},
+            #{drugLicenseTxt},
+            #{businessLicenseOcrResult},
+            #{drugLicenseOcrResult},
+            #{createTime},
+            #{updateTime}
+        )
+    </insert>
+
+        <!-- 根据店铺ID更新OCR信息记录 -->
+        <update id="updateById" parameterType="com.fs.hisStore.domain.FsStoreScrmOcr">
+            UPDATE fs_store_scrm_ocr
+            <set>
+                <if test="businessLicense != null and businessLicense != ''">
+                    business_license = #{businessLicense},
+                </if>
+                <if test="businessLicenseTxt != null and businessLicenseTxt != ''">
+                    business_license_txt = #{businessLicenseTxt},
+                </if>
+                <if test="drugLicense != null and drugLicense != ''">
+                    drug_license = #{drugLicense},
+                </if>
+                <if test="drugLicenseTxt != null and drugLicenseTxt != ''">
+                    drug_license_txt = #{drugLicenseTxt},
+                </if>
+                <if test="businessLicenseOcrResult != null">
+                    business_license_ocr_result = #{businessLicenseOcrResult},
+                </if>
+                <if test="drugLicenseOcrResult != null">
+                    drug_license_ocr_result = #{drugLicenseOcrResult},
+                </if>
+                update_time = #{updateTime}
+            </set>
+            WHERE store_id = #{storeId}
+        </update>
+
+    <!-- 根据店铺ID查询OCR信息 -->
+    <select id="selectById" resultType="com.fs.hisStore.domain.FsStoreScrmOcr">
+        select
+            store_id,
+            business_license,
+            drug_license,
+            business_license_txt,
+            drug_license_txt,
+            business_license_ocr_result,
+            drug_license_ocr_result,
+            create_time,
+            update_time
+        from fs_store_scrm_ocr
+        where store_id= #{storeId}
+    </select>
+
+
+
+</mapper>