Selaa lähdekoodia

商户PC端 价目表编辑 增加AI审核

qinxuyang 2 kuukautta sitten
vanhempi
commit
d2391cb094

+ 49 - 27
alien-store/src/main/java/shop/alien/store/controller/StoreCuisineController.java

@@ -98,9 +98,51 @@ public class StoreCuisineController {
                 return R.fail("新增失败:数据保存异常");
             }
             
+            log.info("新增成功,返回ID: {}", savedCuisine.getId());
+            return R.data(savedCuisine, "新增成功");
+            
+        } catch (Exception e) {
+            log.error("新增美食套餐或单品异常", e);
+            return R.fail("新增失败:" + e.getMessage());
+        }
+    }
+
+    @ApiOperation("修改美食套餐或单品")
+    @ApiOperationSupport(order = 2)
+    @PostMapping("/updateCuisineCombo")
+    public R<String> updateCuisineCombo(@RequestBody CuisineComboDto cuisineComboDto) {
+        log.info("StoreCuisineController.updateCuisineCombo?dto={}", cuisineComboDto);
+        
+        // 参数验证
+        if (cuisineComboDto == null) {
+            log.error("修改美食套餐或单品失败:参数不能为空");
+            return R.fail("参数不能为空");
+        }
+        
+        // 校验ID不能为空
+        if (cuisineComboDto.getId() == null) {
+            log.error("修改美食套餐或单品失败:ID不能为空");
+            return R.fail("ID不能为空");
+        }
+        
+        try {
+            // 更新数据
+            boolean updateResult = storeCuisineService.updateCuisineCombo(cuisineComboDto);
+            if (!updateResult) {
+                log.error("修改美食套餐或单品失败:更新操作返回false");
+                return R.fail("修改失败");
+            }
+            
+            // 查询更新后的记录
+            StoreCuisine updatedCuisine = storeCuisineService.getById(cuisineComboDto.getId());
+            if (updatedCuisine == null) {
+                log.error("修改美食套餐或单品失败:更新后查询不到数据,ID={}", cuisineComboDto.getId());
+                return R.fail("修改失败:数据更新异常");
+            }
+            
             // 将状态置为"审核中"(0)
             LambdaUpdateWrapper<StoreCuisine> auditingWrapper = new LambdaUpdateWrapper<>();
-            auditingWrapper.eq(StoreCuisine::getId, savedCuisine.getId());
+            auditingWrapper.eq(StoreCuisine::getId, updatedCuisine.getId());
             auditingWrapper.set(StoreCuisine::getStatus, 0);
             auditingWrapper.set(StoreCuisine::getRejectionReason, null);
             auditingWrapper.set(StoreCuisine::getAuditTime, new Date());
@@ -158,7 +200,7 @@ public class StoreCuisineController {
                 boolean allPassed = (auditResult != null);
                 
                 LambdaUpdateWrapper<StoreCuisine> auditUpdateWrapper = new LambdaUpdateWrapper<>();
-                auditUpdateWrapper.eq(StoreCuisine::getId, savedCuisine.getId());
+                auditUpdateWrapper.eq(StoreCuisine::getId, updatedCuisine.getId());
                 auditUpdateWrapper.set(StoreCuisine::getRejectionReason, null);
                 auditUpdateWrapper.set(StoreCuisine::getAuditTime, new Date());
                 
@@ -166,42 +208,22 @@ public class StoreCuisineController {
                     // 审核通过 审核状态为1 上架状态为1 已上架
                     auditUpdateWrapper.set(StoreCuisine::getStatus, 1);
                     auditUpdateWrapper.set(StoreCuisine::getShelfStatus, 1);
-                    log.info("AI审核通过,ID: {}", savedCuisine.getId());
+                    log.info("AI审核通过,ID: {}", updatedCuisine.getId());
                 } else {
                     // 审核拒绝 审核状态为2 上架状态为0 没有上下架状态
                     auditUpdateWrapper.set(StoreCuisine::getStatus, 2);
                     auditUpdateWrapper.set(StoreCuisine::getShelfStatus, 0);
-                    log.info("AI审核拒绝,ID: {}", savedCuisine.getId());
+                    log.info("AI审核拒绝,ID: {}", updatedCuisine.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, "新增成功");
+            return R.success("修改成功");
             
         } catch (Exception e) {
-            log.error("新增美食套餐或单品异常", e);
-            return R.fail("新增失败:" + e.getMessage());
-        }
-    }
-
-    @ApiOperation("修改美食套餐或单品")
-    @ApiOperationSupport(order = 2)
-    @PostMapping("/updateCuisineCombo")
-    public R<String> updateCuisineCombo(@RequestBody CuisineComboDto cuisineComboDto) {
-        log.info("StoreCuisineController.updateCuisineCombo?dto={}", cuisineComboDto);
-        if (storeCuisineService.updateCuisineCombo(cuisineComboDto)) {
-            return R.success("修改成功");
+            log.error("修改美食套餐或单品异常", e);
+            return R.fail("修改失败:" + e.getMessage());
         }
-        return R.fail("修改失败");
     }
 
     @ApiOperation("获取所有美食单品名称,用于添加套餐")

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

@@ -232,27 +232,118 @@ public class StorePriceController {
     public R<String> update(@RequestBody StorePrice storePrice) {
         log.info("StorePriceController.update?storePrice={}", storePrice);
         
+        // 参数验证
+        if (storePrice == null) {
+            log.error("修改通用价目失败:参数不能为空");
+            return R.fail("参数不能为空");
+        }
+        
         // 校验ID不能为空
         if (storePrice.getId() == null) {
             log.error("修改通用价目失败:ID不能为空");
             return R.fail("ID不能为空");
         }
         
-        // 检查记录是否存在
-        StorePrice existingPrice = storePriceService.getById(storePrice.getId());
-        if (existingPrice == null) {
-            log.error("修改通用价目失败:ID={} 的记录不存在", storePrice.getId());
-            return R.fail("记录不存在,无法修改");
-        }
-        
-        // 执行更新
-        boolean result = storePriceService.updateById(storePrice);
-        if (result) {
+        try {
+            // 检查记录是否存在
+            StorePrice existingPrice = storePriceService.getById(storePrice.getId());
+            if (existingPrice == null) {
+                log.error("修改通用价目失败:ID={} 的记录不存在", storePrice.getId());
+                return R.fail("记录不存在,无法修改");
+            }
+            
+            // 执行更新
+            boolean updateResult = storePriceService.updateById(storePrice);
+            if (!updateResult) {
+                log.error("修改通用价目失败:ID={},更新操作返回false", storePrice.getId());
+                return R.fail("修改失败,请检查数据是否正确");
+            }
+            
+            // 查询更新后的记录
+            StorePrice updatedPrice = storePriceService.getById(storePrice.getId());
+            if (updatedPrice == null) {
+                log.error("修改通用价目失败:更新后查询不到数据,ID={}", storePrice.getId());
+                return R.fail("修改失败:数据更新异常");
+            }
+            
+            // 将状态置为"审核中"(0)
+            LambdaUpdateWrapper<StorePrice> auditingWrapper = new LambdaUpdateWrapper<>();
+            auditingWrapper.eq(StorePrice::getId, updatedPrice.getId());
+            auditingWrapper.set(StorePrice::getStatus, 0);
+            auditingWrapper.set(StorePrice::getRejectionReason, null);
+            auditingWrapper.set(StorePrice::getAuditTime, new Date());
+            storePriceMapper.update(null, auditingWrapper);
+            
+            // 组装 AI 审核文本和图片
+            StringBuilder textContent = new StringBuilder();
+            if (StringUtils.isNotEmpty(storePrice.getName())) {
+                textContent.append(storePrice.getName()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(storePrice.getDetailContent())) {
+                textContent.append(storePrice.getDetailContent()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(storePrice.getExtraNote())) {
+                textContent.append(storePrice.getExtraNote()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(storePrice.getReserveRule())) {
+                textContent.append(storePrice.getReserveRule()).append(" ");
+            }
+            if (StringUtils.isNotEmpty(storePrice.getUsageRule())) {
+                textContent.append(storePrice.getUsageRule()).append(" ");
+            }
+
+            List<String> imageUrls = new ArrayList<>();
+
+            if (StringUtils.isNotEmpty(storePrice.getImages())) {
+                String[] urls = storePrice.getImages().split(",");
+                for (String url : urls) {
+                    if (StringUtils.isNotEmpty(url.trim())) {
+                        String trimmedUrl = url.trim();
+                        imageUrls.add(trimmedUrl);
+                    }
+                }
+            }
+
+            if (StringUtils.isNotEmpty(storePrice.getImageContent())) {
+                String[] urls = storePrice.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);
+                boolean allPassed = (auditResult != null);
+                
+                LambdaUpdateWrapper<StorePrice> auditUpdateWrapper = new LambdaUpdateWrapper<>();
+                auditUpdateWrapper.eq(StorePrice::getId, updatedPrice.getId());
+                auditUpdateWrapper.set(StorePrice::getRejectionReason, null);
+                auditUpdateWrapper.set(StorePrice::getAuditTime, new Date());
+                
+                if (allPassed) {
+                    // 审核通过 审核状态为1 上架状态为1 已上架
+                    auditUpdateWrapper.set(StorePrice::getStatus, 1);
+                    auditUpdateWrapper.set(StorePrice::getShelfStatus, 1);
+                    log.info("AI审核通过,ID: {}", updatedPrice.getId());
+                } else {
+                    // 审核拒绝 审核状态为2 上架状态为0 没有上下架状态
+                    auditUpdateWrapper.set(StorePrice::getStatus, 2);
+                    auditUpdateWrapper.set(StorePrice::getShelfStatus, 0);
+                    log.info("AI审核拒绝,ID: {}", updatedPrice.getId());
+                }
+                storePriceMapper.update(null, auditUpdateWrapper);
+            }
+            
             return R.success("修改成功");
+            
+        } catch (Exception e) {
+            log.error("修改通用价目异常", e);
+            return R.fail("修改失败:" + e.getMessage());
         }
-        
-        log.error("修改通用价目失败:ID={},更新操作返回false", storePrice.getId());
-        return R.fail("修改失败,请检查数据是否正确");
     }
 
     @TrackEvent(