Sfoglia il codice sorgente

商户PC端 价目表 代码优化

qinxuyang 2 mesi fa
parent
commit
da59f9a9ba

+ 88 - 3
alien-store/src/main/java/shop/alien/store/controller/StoreCuisineController.java

@@ -98,7 +98,92 @@ public class StoreCuisineController {
                 return R.fail("新增失败:数据保存异常");
             }
             
-            log.info("新增成功,返回ID: {}", savedCuisine.getId());
+            // 将状态置为"审核中"(0)
+            LambdaUpdateWrapper<StoreCuisine> auditingWrapper = new LambdaUpdateWrapper<>();
+            auditingWrapper.eq(StoreCuisine::getId, savedCuisine.getId());
+            auditingWrapper.set(StoreCuisine::getStatus, 0);
+            auditingWrapper.set(StoreCuisine::getRejectionReason, null);
+            auditingWrapper.set(StoreCuisine::getAuditTime, new Date());
+            storeCuisineMapper.update(null, auditingWrapper);
+            
+            // 组装 AI 审核文本和图片
+            StringBuilder textContent = new StringBuilder();
+            if (StringUtils.isNotEmpty(cuisineComboDto.getName())) {
+                textContent.append(cuisineComboDto.getName()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getDetailContent())) {
+                textContent.append(cuisineComboDto.getDetailContent()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getDescription())) {
+                textContent.append(cuisineComboDto.getDescription()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getDishReview())) {
+                textContent.append(cuisineComboDto.getDishReview()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getExtraNote())) {
+                textContent.append(cuisineComboDto.getExtraNote()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getReserveRule())) {
+                textContent.append(cuisineComboDto.getReserveRule()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(cuisineComboDto.getUsageRule())) {
+                textContent.append(cuisineComboDto.getUsageRule()).append(" ");
+            }
+
+            List<String> imageUrls = new ArrayList<>();
+
+            if (StringUtils.isNotEmpty(cuisineComboDto.getImages())) {
+                String[] urls = cuisineComboDto.getImages().split(",");
+                for (String url : urls) {
+                    if (StringUtils.isNotEmpty(url.trim())) {
+                        String trimmedUrl = url.trim();
+                        imageUrls.add(trimmedUrl);
+                    }
+                }
+            }
+
+            if (StringUtils.isNotEmpty(cuisineComboDto.getImageContent())) {
+                String[] urls = cuisineComboDto.getImageContent().split(",");
+                for (String url : urls) {
+                    if (StringUtils.isNotEmpty(url.trim())) {
+                        String trimmedUrl = url.trim();
+                        imageUrls.add(trimmedUrl);
+                    }
+                }
+            }
+
+            // 执行AI审核
+            if (StringUtils.isNotEmpty(textContent.toString()) || imageUrls.size() > 0) {
+                AiContentModerationUtil.AuditResult auditResult = aiContentModerationUtil.auditContent(textContent.toString(), imageUrls);
+                
+                LambdaUpdateWrapper<StoreCuisine> auditUpdateWrapper = new LambdaUpdateWrapper<>();
+                auditUpdateWrapper.eq(StoreCuisine::getId, savedCuisine.getId());
+                auditUpdateWrapper.set(StoreCuisine::getRejectionReason, null);
+                auditUpdateWrapper.set(StoreCuisine::getAuditTime, new Date());
+                
+                if (auditResult.isPassed()) {
+                    // 审核通过 审核状态为1 上架状态为1 已上架
+                    auditUpdateWrapper.set(StoreCuisine::getStatus, 1);
+                    auditUpdateWrapper.set(StoreCuisine::getShelfStatus, 1);
+                    log.info("AI审核通过,ID: {}", savedCuisine.getId());
+                } else {
+                    // 审核拒绝 审核状态为2 上架状态为0 没有上下架状态
+                    auditUpdateWrapper.set(StoreCuisine::getStatus, 2);
+                    auditUpdateWrapper.set(StoreCuisine::getShelfStatus, 0);
+                    log.info("AI审核拒绝,ID: {}", savedCuisine.getId());
+                }
+                storeCuisineMapper.update(null, auditUpdateWrapper);
+            }
+            
+            // 重新查询一次,返回最新的数据
+            StoreCuisine finalCuisine = storeCuisineService.getById(savedCuisine.getId());
+            if (finalCuisine != null) {
+                log.info("新增成功,返回ID: {}", finalCuisine.getId());
+                return R.data(finalCuisine, "新增成功");
+            }
+            
+            // 如果查询失败,返回保存后的对象(至少包含ID)
+            log.warn("新增成功但最终查询失败,返回保存后的对象,ID: {}", savedCuisine.getId());
             return R.data(savedCuisine, "新增成功");
             
         } catch (Exception e) {
@@ -347,7 +432,7 @@ public class StoreCuisineController {
             if(null==origin){
                 queryWrapper.eq(StoreCuisine::getShelfStatus, 1);
             }else if(origin == 0){
-                queryWrapper.in(StoreCuisine::getShelfStatus, 1,2);
+                queryWrapper.in(StoreCuisine::getShelfStatus, 0,1,2);
             }
             else{
                 queryWrapper.eq(StoreCuisine::getShelfStatus, origin);
@@ -399,7 +484,7 @@ public class StoreCuisineController {
             if(null==origin){
                 queryWrapper.eq(StorePrice::getShelfStatus, 1);
             }else if(origin == 0){
-                queryWrapper.in(StorePrice::getShelfStatus, 1,2);
+                queryWrapper.in(StorePrice::getShelfStatus, 0,1,2);
             }
             else{
                 queryWrapper.eq(StorePrice::getShelfStatus, origin);

+ 3 - 3
alien-store/src/main/java/shop/alien/store/controller/StorePriceController.java

@@ -188,14 +188,14 @@ public class StorePriceController {
             // 执行AI审核
             if (StringUtils.isNotEmpty(textContent.toString()) || imageUrls.size() > 0) {
                 AiContentModerationUtil.AuditResult auditResult = aiContentModerationUtil.auditContent(textContent.toString(), imageUrls);
-                boolean allPassed = (auditResult != null);
+//                boolean allPassed = (auditResult != null);
                 
                 LambdaUpdateWrapper<StorePrice> auditUpdateWrapper = new LambdaUpdateWrapper<>();
                 auditUpdateWrapper.eq(StorePrice::getId, savedPrice.getId());
                 auditUpdateWrapper.set(StorePrice::getRejectionReason, null);
                 auditUpdateWrapper.set(StorePrice::getAuditTime, new Date());
                 
-                if (allPassed) {
+                if (auditResult.isPassed()) {
                     // 审核通过 审核状态为1 上架状态为1 已上架
                     auditUpdateWrapper.set(StorePrice::getStatus, 1);
                     auditUpdateWrapper.set(StorePrice::getShelfStatus, 1);
@@ -452,7 +452,7 @@ public class StorePriceController {
         if(null==origin){
             queryWrapper.eq(StorePrice::getShelfStatus, 1);
         }else if(origin==0){
-            queryWrapper.in(StorePrice::getShelfStatus, 1,2);
+            queryWrapper.in(StorePrice::getShelfStatus, 0,1,2);
         }else{
             queryWrapper.eq(StorePrice::getShelfStatus, origin);
         }