ソースを参照

头图审核返回状态

panzhilin 3 ヶ月 前
コミット
d66d04e1d2

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

@@ -325,4 +325,8 @@ public class StoreInfo {
     @TableField("manual_review_reason")
     private String manualReviewReason;
 
+    @ApiModelProperty(value = "头图审核状态(1-审核通过, 2-审核不通过)")
+    @TableField("head_img_status")
+    private Integer headImgStatus;
+
 }

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreMainInfoVo.java

@@ -105,4 +105,7 @@ public class StoreMainInfoVo extends StoreInfo {
 //    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     private Date foodLicenceExpirationTime;
 
+    @ApiModelProperty(value = "头图审核状态(1—审核通过, 2—审核不通过)")
+    private Integer headImgStatus;
+
 }

+ 54 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreImgController.java

@@ -74,20 +74,74 @@ public class StoreImgController {
         if (storeImgInfoVo.getStoreId()==null || storeImgInfoVo.getImgType()==null) {
             return R.fail("失败");
         }
+        
+        // 判断是否是头图(20:单图模式, 21:多图模式)
+        Integer imgType = storeImgInfoVo.getImgType();
+        boolean isHeadImage = (imgType == 20 || imgType == 21);
+        
         // 清空storeid,imgType下图片
         int deleteCount = storeImgService.saveOrUpdateImg(storeImgInfoVo.getStoreId(),storeImgInfoVo.getImgType());
         log.info("StoreImgController.updateStoreImgModeInfo?deleteCount={}", deleteCount);
         int result = storeInfoService.updateStoreImgModeInfo(storeImgInfoVo);
         log.info("StoreImgController.updateStoreImgModeInfo?result={}", result);
+        
         if(!CollectionUtils.isEmpty(storeImgList)){
             Integer id = storeImgList.get(0).getId();
             if (storeImgService.saveOrUpdateBatch(storeImgList)) {
+                // 如果是头图,先设置审核状态为通过(1),然后进行AI审核
+                if (isHeadImage) {
+                    // 有头图,先设置为审核通过状态(1)
+                    try {
+                        storeInfoService.updateHeadImgStatus(storeImgInfoVo.getStoreId(), 1);
+                        log.info("头图保存成功,设置审核状态为通过,storeId={}", storeImgInfoVo.getStoreId());
+                    } catch (Exception e) {
+                        log.error("更新头图审核状态失败,storeId={}, error={}", 
+                                storeImgInfoVo.getStoreId(), e.getMessage(), e);
+                    }
+                    
+                    // 然后进行AI审核,如果审核不通过则更新为2
+                    try {
+                        boolean auditResult = storeInfoService.auditHeadImageAndUpdateStatus(storeImgInfoVo);
+                        log.info("头图AI审核完成,storeId={}, imgType={}, auditResult={}", 
+                                storeImgInfoVo.getStoreId(), imgType, auditResult);
+                    } catch (Exception e) {
+                        log.error("头图AI审核异常,storeId={}, imgType={}, error={}", 
+                                storeImgInfoVo.getStoreId(), imgType, e.getMessage(), e);
+                        // AI审核异常时,设置审核状态为不通过
+                        try {
+                            storeInfoService.updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+                        } catch (Exception ex) {
+                            log.error("更新头图审核状态失败,storeId={}, error={}", 
+                                    storeImgInfoVo.getStoreId(), ex.getMessage(), ex);
+                        }
+                    }
+                }
                 if (null != id) {
                     return R.success("修改成功");
                 }
                 return R.success("新增成功");
+            } else {
+                // 图片保存失败,如果是头图,设置审核状态为不通过
+                if (isHeadImage) {
+                    try {
+                        storeInfoService.updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+                        log.info("图片保存失败,更新头图审核状态为不通过,storeId={}", storeImgInfoVo.getStoreId());
+                    } catch (Exception e) {
+                        log.error("更新头图审核状态失败,storeId={}, error={}", 
+                                storeImgInfoVo.getStoreId(), e.getMessage(), e);
+                    }
+                }
             }
         } else {
+            // 如果是头图且没有图片,设置审核状态为不通过
+            if (isHeadImage) {
+                try {
+                    storeInfoService.updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+                } catch (Exception e) {
+                    log.error("更新头图审核状态失败,storeId={}, error={}", 
+                            storeImgInfoVo.getStoreId(), e.getMessage(), e);
+                }
+            }
             return R.success("保存成功");
         }
         return R.fail("失败");

+ 16 - 0
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -499,4 +499,20 @@ public interface StoreInfoService extends IService<StoreInfo> {
                                                   String states,
                                                   String startSubmitDate,
                                                   String endSubmitDate);
+
+    /**
+     * 头图上传后AI审核并更新审核状态
+     *
+     * @param storeImgInfoVo 图片信息VO
+     * @return 审核结果 true-审核通过,false-审核不通过
+     */
+    boolean auditHeadImageAndUpdateStatus(StoreImgInfoVo storeImgInfoVo);
+
+    /**
+     * 更新门店头图审核状态
+     *
+     * @param storeId 门店ID
+     * @param headImgStatus 审核状态 1-审核通过,2-审核不通过
+     */
+    void updateHeadImgStatus(Integer storeId, Integer headImgStatus);
 }

+ 119 - 4
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -240,10 +240,33 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         storeMainInfoVo.setStoreLabel(storeLabelMapper.selectOne(new LambdaQueryWrapper<StoreLabel>().eq(StoreLabel::getStoreId, id)));
         //营业时间
         storeMainInfoVo.setStoreBusinessInfo(storeBusinessInfoMapper.selectList(new LambdaQueryWrapper<StoreBusinessInfo>().eq(StoreBusinessInfo::getStoreId, id)));
-        //门店头像
-        LambdaQueryWrapper<StoreImg> eq = new LambdaQueryWrapper<StoreImg>().eq(StoreImg::getImgType, 10).eq(StoreImg::getStoreId, id);
-        StoreImg storeImg = storeImgMapper.selectOne(eq);
-        storeMainInfoVo.setHeadImgUrl(storeImg != null ? storeImg.getImgUrl() : "");
+        //门店头图(20:头图单图模式, 21:头图多图模式)
+        LambdaQueryWrapper<StoreImg> headImgWrapper = new LambdaQueryWrapper<StoreImg>()
+                .in(StoreImg::getImgType, 20, 21)
+                .eq(StoreImg::getStoreId, id)
+                .eq(StoreImg::getDeleteFlag, 0)
+                .orderByAsc(StoreImg::getImgSort);
+        List<StoreImg> headImgList = storeImgMapper.selectList(headImgWrapper);
+        // 设置头图URL(取第一张图片,如果是多图模式可能有多个)
+        if (headImgList != null && !headImgList.isEmpty()) {
+            StoreImg firstHeadImg = headImgList.get(0);
+            storeMainInfoVo.setHeadImgUrl(firstHeadImg.getImgUrl() != null ? firstHeadImg.getImgUrl() : "");
+        } else {
+            storeMainInfoVo.setHeadImgUrl("");
+        }
+        // 设置头图审核状态
+        // 逻辑说明:
+        // 1. 上传头图后,审核通过时,store_info.head_img_status会被设置为1
+        // 2. 查询时,如果store_info.head_img_status=1,说明头图已审核通过,返回1
+        // 从store_info表获取head_img_status字段值(通过getStoreInfo查询已包含此字段)
+        Integer headImgStatusFromDb = storeMainInfoVo.getHeadImgStatus();
+        if (headImgStatusFromDb != null && headImgStatusFromDb == 1) {
+            // 数据库head_img_status=1(审核通过),返回1
+            storeMainInfoVo.setHeadImgStatus(1); // 审核通过
+        } else {
+            // 数据库head_img_status不为1(待审核0、不通过2、拒绝3或为空),返回2
+            storeMainInfoVo.setHeadImgStatus(2); // 审核不通过
+        }
         List<StoreUser> storeUsers = storeUserMapper.selectList(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()));
         for (StoreUser storeUser : storeUsers) {
             storeMainInfoVo.setLogoutFlagUser(storeUser.getLogoutFlag());
@@ -3089,6 +3112,98 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
     }
 
     /**
+     * 头图上传后AI审核并更新审核状态
+     * 流程:上传头图 → 调用AI门头识别接口 → 根据结果更新head_img_status → 保存到store_img表
+     *
+     * @param storeImgInfoVo 图片信息VO
+     * @return 审核结果 true-审核通过,false-审核不通过
+     */
+    @Override
+    public boolean auditHeadImageAndUpdateStatus(StoreImgInfoVo storeImgInfoVo) {
+        // 判断是否是头图(20:单图模式, 21:多图模式)
+        Integer imgType = storeImgInfoVo.getImgType();
+        if (imgType == null || (imgType != GroupConstant.IMG_TYPE_SINGLE_MODE && imgType != GroupConstant.IMG_TYPE_MULTI_MODE)) {
+            // 不是头图,不需要审核,直接返回true
+            return true;
+        }
+
+        List<StoreImg> storeImgList = storeImgInfoVo.getStoreImgList();
+        if (storeImgList == null || storeImgList.isEmpty()) {
+            // 没有图片,设置审核状态为不通过
+            updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+            return false;
+        }
+
+        // 获取第一张头图的URL(头图可能有多张,取第一张进行审核)
+        StoreImg firstHeadImg = storeImgList.get(0);
+        String imageUrl = firstHeadImg.getImgUrl();
+        if (imageUrl == null || imageUrl.trim().isEmpty()) {
+            // 图片URL为空,设置审核状态为不通过
+            updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+            return false;
+        }
+
+        // 获取门店信息(需要门店名称用于AI审核)
+        StoreInfo storeInfo = storeInfoMapper.selectById(storeImgInfoVo.getStoreId());
+        if (storeInfo == null) {
+            log.error("门店不存在,storeId={}", storeImgInfoVo.getStoreId());
+            updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+            return false;
+        }
+
+        String merchantName = storeInfo.getStoreName();
+        if (merchantName == null || merchantName.trim().isEmpty()) {
+            log.error("门店名称为空,storeId={}", storeImgInfoVo.getStoreId());
+            updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+            return false;
+        }
+
+        try {
+            // 调用AI门头识别接口进行审核
+            Map<String, Object> ocrData = getStoreOcrData(imageUrl, merchantName);
+            Boolean overallMatch = (Boolean) ocrData.get("overall_match");
+
+            // 根据AI审核结果更新head_img_status
+            // overall_match = true -> 审核通过 -> head_img_status = 1(保持通过状态)
+            // overall_match = false -> 审核不通过 -> head_img_status = 2(改为不通过)
+            if (overallMatch != null && overallMatch) {
+                // AI审核通过,保持审核通过状态(1)
+                updateHeadImgStatus(storeImgInfoVo.getStoreId(), 1);
+                log.info("头图AI审核通过,storeId={}, imageUrl={}, headImgStatus=1",
+                        storeImgInfoVo.getStoreId(), imageUrl);
+                return true;
+            } else {
+                // AI审核不通过,更新为不通过状态(2)
+                updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+                log.info("头图AI审核不通过,storeId={}, imageUrl={}, overallMatch={}, headImgStatus=2",
+                        storeImgInfoVo.getStoreId(), imageUrl, overallMatch);
+                return false;
+            }
+        } catch (Exception e) {
+            log.error("头图AI审核失败,storeId={}, imageUrl={}, error={}",
+                    storeImgInfoVo.getStoreId(), imageUrl, e.getMessage(), e);
+            // AI审核失败,设置审核状态为不通过
+            updateHeadImgStatus(storeImgInfoVo.getStoreId(), 2);
+            return false;
+        }
+    }
+
+    /**
+     * 更新门店头图审核状态
+     *
+     * @param storeId 门店ID
+     * @param headImgStatus 审核状态 1-审核通过,2-审核不通过
+     */
+    @Override
+    public void updateHeadImgStatus(Integer storeId, Integer headImgStatus) {
+        LambdaUpdateWrapper<StoreInfo> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(StoreInfo::getId, storeId);
+        wrapper.set(StoreInfo::getHeadImgStatus, headImgStatus);
+        storeInfoMapper.update(null, wrapper);
+        log.info("更新门店头图审核状态,storeId={}, headImgStatus={}", storeId, headImgStatus);
+    }
+
+    /**
      * 获取活动banner图
      * 关联查询 store_img 和 store_operational_activity 表
      * 关联条件:store_operational_activity.id = store_img.business_id