浏览代码

feat:添加入驻营业执照相关信息存入

penghao 6 天之前
父节点
当前提交
424ea59b9b

+ 30 - 4
alien-entity/src/main/java/shop/alien/entity/store/StoreInfo.java

@@ -221,12 +221,12 @@ public class StoreInfo {
     @TableField("food_licence_reason")
     private String foodLicenceReason;
 
-    @ApiModelProperty(value = "经营许可证到期时间")
+    @ApiModelProperty(value = "食品经营许可证到期时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @TableField("food_licence_expiration_time")
     private Date  foodLicenceExpirationTime;
 
-    @ApiModelProperty(value = "变更经营许可证提交时间")
+    @ApiModelProperty(value = "变更食品经营许可证提交时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @TableField("update_food_licence_time")
     private Date  updateFoodLicenceTime;
@@ -244,8 +244,6 @@ public class StoreInfo {
     @TableField("business_classify_name")
     private String businessClassifyName;
 
-
-
     @ApiModelProperty(value = "是否提供餐食")
     @TableField("meals_flag")
     private Integer  mealsFlag;
@@ -267,4 +265,32 @@ public class StoreInfo {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @TableField("update_entertainment_licence_time")
     private Date updateEntertainmentLicenceTime;
+
+    @ApiModelProperty(value = "续签合同到期时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField("renew_contract_expiration_time")
+    private Date renewContractExpirationTime;
+
+    @ApiModelProperty(value = "营业执照状态 字典 foodLicenceStatus")
+    @TableField("business_license_status")
+    private Integer businessLicenseStatus;
+
+    @ApiModelProperty(value = "营业执照失败原因")
+    @TableField("business_license_reason")
+    private String businessLicenseReason;
+
+    @ApiModelProperty(value = "营业执照到期时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField("business_license_expiration_time")
+    private Date businessLicenseExpirationTime;
+
+    @ApiModelProperty(value = "变更营业执照提交时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField("update_business_license_time")
+    private Date updateBusinessLicenseTime;
+
+    @ApiModelProperty(value = "审核时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField("review_date")
+    private Date reviewDate;
 }

+ 14 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/StoreInfoDto.java

@@ -209,4 +209,18 @@ public class StoreInfoDto {
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
     private Date entertainmentLicenceExpirationTime;
+
+    @ApiModelProperty(value = "营业执照图片URL")
+    private String businessLicenseUrl;
+
+    @ApiModelProperty(value = "营业执照状态 字典 foodLicenceStatus")
+    private Integer businessLicenseStatus;
+
+    @ApiModelProperty(value = "营业执照失败原因")
+    private String businessLicenseReason;
+
+    @ApiModelProperty(value = "营业执照到期时间")
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private Date businessLicenseExpirationTime;
 }

+ 116 - 10
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -910,10 +910,13 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                 storeInfo.setFoodLicenceStatus(2);
                 storeInfo.setUpdateFoodLicenceTime(new Date());
             }
-        } else if (storeInfoDto.getFoodLicenceExpirationTime() != null) {
-            // 没有食品经营许可证URL,但有传入到期时间时直接使用
-            storeInfo.setFoodLicenceExpirationTime(storeInfoDto.getFoodLicenceExpirationTime());
-            log.info("无食品经营许可证URL,使用DTO中的到期时间:{}", storeInfoDto.getFoodLicenceExpirationTime());
+        } else {
+            // 没有食品经营许可证URL,初始化状态为"未提交"(字典值0)
+            storeInfo.setFoodLicenceStatus(0);
+            if (storeInfoDto.getFoodLicenceExpirationTime() != null) {
+                storeInfo.setFoodLicenceExpirationTime(storeInfoDto.getFoodLicenceExpirationTime());
+                log.info("无食品经营许可证URL,使用DTO中的到期时间:{}", storeInfoDto.getFoodLicenceExpirationTime());
+            }
         }
         
         // 处理娱乐经营许可证OCR数据(复用营业执照OCR类型,数据库中ocr_type存的是BUSINESS_LICENSE)
@@ -961,13 +964,78 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                 storeInfo.setEntertainmentLicenceStatus(2);
                 storeInfo.setUpdateEntertainmentLicenceTime(new Date());
             }
-        } else if (storeInfoDto.getEntertainmentLicenceExpirationTime() != null) {
-            // 没有娱乐经营许可证URL,但有传入到期时间时直接使用
-            storeInfo.setEntertainmentLicenceExpirationTime(storeInfoDto.getEntertainmentLicenceExpirationTime());
-            log.info("无娱乐经营许可证URL,使用DTO中的到期时间:{}", storeInfoDto.getEntertainmentLicenceExpirationTime());
+        } else {
+            // 没有娱乐经营许可证URL,初始化状态为"未提交"(字典值0)
+            storeInfo.setEntertainmentLicenceStatus(0);
+            if (storeInfoDto.getEntertainmentLicenceExpirationTime() != null) {
+                storeInfo.setEntertainmentLicenceExpirationTime(storeInfoDto.getEntertainmentLicenceExpirationTime());
+                log.info("无娱乐经营许可证URL,使用DTO中的到期时间:{}", storeInfoDto.getEntertainmentLicenceExpirationTime());
+            }
+        }
+
+        // 处理营业执照OCR数据(复用营业执照OCR类型,数据库中ocr_type存的是BUSINESS_LICENSE)
+        // 营业执照使用 businessLicenseAddress 列表中的第一个URL查询OCR
+        String businessLicenseOcrUrl = null;
+        if (!CollectionUtils.isEmpty(storeInfoDto.getBusinessLicenseAddress())) {
+            businessLicenseOcrUrl = storeInfoDto.getBusinessLicenseAddress().get(0);
+        } else if (StringUtils.isNotEmpty(storeInfoDto.getBusinessLicenseUrl())) {
+            businessLicenseOcrUrl = storeInfoDto.getBusinessLicenseUrl();
+        }
+        
+        if (StringUtils.isNotEmpty(businessLicenseOcrUrl)) {
+            // 查询营业执照OCR识别记录
+            OcrImageUpload businessLicenseOcr = ocrImageUploadMapper.selectOne(
+                    new LambdaQueryWrapper<OcrImageUpload>()
+                            .eq(OcrImageUpload::getImageUrl, businessLicenseOcrUrl)
+                            .eq(OcrImageUpload::getOcrType, OcrTypeEnum.BUSINESS_LICENSE.getCode())
+                            .orderByDesc(OcrImageUpload::getCreateTime)
+                            .last("limit 1")
+            );
+            if (businessLicenseOcr != null && StringUtils.isNotEmpty(businessLicenseOcr.getOcrResult())) {
+                try {
+                    com.alibaba.fastjson2.JSONObject ocrResult = com.alibaba.fastjson2.JSONObject.parseObject(businessLicenseOcr.getOcrResult());
+                    // 营业执照OCR字段:validToDate(优先,格式"20241217")、validPeriod(格式"2020年09月04日至2022年09月03日")
+                    Date expirationTime = parseBusinessLicenseExpirationDate(ocrResult);
+                    if (expirationTime != null) {
+                        storeInfo.setBusinessLicenseExpirationTime(expirationTime);
+                    } else if (storeInfoDto.getBusinessLicenseExpirationTime() != null) {
+                        // OCR解析结果为空时,使用DTO中传入的值
+                        storeInfo.setBusinessLicenseExpirationTime(storeInfoDto.getBusinessLicenseExpirationTime());
+                        log.info("使用DTO中的营业执照到期时间:{}", storeInfoDto.getBusinessLicenseExpirationTime());
+                    }
+                    // 设置营业执照状态为"待审核"(字典值2)
+                    storeInfo.setBusinessLicenseStatus(2);
+                    storeInfo.setUpdateBusinessLicenseTime(new Date());
+                    log.info("营业执照OCR数据解析成功,到期时间:{}", storeInfo.getBusinessLicenseExpirationTime());
+                } catch (Exception e) {
+                    log.error("解析营业执照OCR数据失败", e);
+                    // 解析失败时使用DTO中传入的值
+                    if (storeInfoDto.getBusinessLicenseExpirationTime() != null) {
+                        storeInfo.setBusinessLicenseExpirationTime(storeInfoDto.getBusinessLicenseExpirationTime());
+                        log.info("OCR解析失败,使用DTO中的营业执照到期时间:{}", storeInfoDto.getBusinessLicenseExpirationTime());
+                    }
+                    storeInfo.setBusinessLicenseStatus(2);
+                    storeInfo.setUpdateBusinessLicenseTime(new Date());
+                }
+            } else {
+                // 没有OCR记录时,使用DTO中传入的值
+                if (storeInfoDto.getBusinessLicenseExpirationTime() != null) {
+                    storeInfo.setBusinessLicenseExpirationTime(storeInfoDto.getBusinessLicenseExpirationTime());
+                    log.info("无OCR记录,使用DTO中的营业执照到期时间:{}", storeInfoDto.getBusinessLicenseExpirationTime());
+                }
+                storeInfo.setBusinessLicenseStatus(2);
+                storeInfo.setUpdateBusinessLicenseTime(new Date());
+            }
+        } else {
+            // 没有营业执照URL,初始化状态为"未提交"(字典值0)
+            storeInfo.setBusinessLicenseStatus(0);
+            if (storeInfoDto.getBusinessLicenseExpirationTime() != null) {
+                storeInfo.setBusinessLicenseExpirationTime(storeInfoDto.getBusinessLicenseExpirationTime());
+                log.info("无营业执照URL,使用DTO中的到期时间:{}", storeInfoDto.getBusinessLicenseExpirationTime());
+            }
         }
 
-        // 计算并设置到期时间为三个过期时间的最小值
+        // 计算并设置到期时间为个过期时间的最小值
         List<Date> expirationTimeList = new ArrayList<>();
         // 收集所有非空的过期时间
         if (storeInfoDto.getExpirationTime() != null) {
@@ -979,11 +1047,14 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         if (storeInfo.getEntertainmentLicenceExpirationTime() != null) {
             expirationTimeList.add(storeInfo.getEntertainmentLicenceExpirationTime());
         }
+        if (storeInfo.getBusinessLicenseExpirationTime() != null) {
+            expirationTimeList.add(storeInfo.getBusinessLicenseExpirationTime());
+        }
         // 取最小值设置为门店到期时间
         if (!expirationTimeList.isEmpty()) {
             Date minExpirationTime = Collections.min(expirationTimeList);
             storeInfo.setExpirationTime(minExpirationTime);
-            log.info("设置门店到期时间为个过期时间的最小值:{}", minExpirationTime);
+            log.info("设置门店到期时间为个过期时间的最小值:{}", minExpirationTime);
         }
         
         storeInfoMapper.insert(storeInfo);
@@ -5285,6 +5356,41 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         log.warn("娱乐经营许可证OCR结果中未找到有效的到期时间,validToDate={},validPeriod={}", validToDate, validPeriod);
         return null;
     }
+
+    /**
+     * 解析营业执照OCR结果中的到期时间(复用营业执照OCR类型)
+     * 营业执照OCR返回字段:validToDate(格式"20241217"或空)、validPeriod(可能为空)
+     * 注意:营业执照的validToDate可能为空,表示长期有效
+     *
+     * @param ocrResult OCR识别结果JSON对象
+     * @return 到期日期,如果解析失败或为长期有效则返回null
+     */
+    private Date parseBusinessLicenseExpirationDate(com.alibaba.fastjson2.JSONObject ocrResult) {
+        if (ocrResult == null) {
+            return null;
+        }
+        
+        // 优先使用validToDate字段(格式为yyyyMMdd,如"20241217",可能为空表示长期有效)
+        String validToDate = ocrResult.getString("validToDate");
+        if (StringUtils.isNotEmpty(validToDate)) {
+            Date date = parseDateString(validToDate);
+            if (date != null) {
+                return date;
+            }
+        }
+        
+        // 其次使用validPeriod字段(格式为"2020年09月04日至2022年09月03日",可能为空)
+        String validPeriod = ocrResult.getString("validPeriod");
+        if (StringUtils.isNotEmpty(validPeriod)) {
+            Date date = parseValidPeriodEndDate(validPeriod);
+            if (date != null) {
+                return date;
+            }
+        }
+        
+        log.info("营业执照OCR结果中未找到有效的到期时间,validToDate={},validPeriod={},可能为长期有效", validToDate, validPeriod);
+        return null;
+    }
     
     /**
      * 解析日期字符串