Explorar el Código

商户PC端价目表 封装AI审核数据

qinxuyang hace 2 meses
padre
commit
51debe6520

+ 6 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreCuisine.java

@@ -132,6 +132,12 @@ public class StoreCuisine {
     @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date updatedTime;
+
+    @ApiModelProperty(value = "AI审核时间")
+    @TableField(value = "audit_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date auditTime;
+
 }
 
 

+ 5 - 0
alien-entity/src/main/java/shop/alien/entity/store/StorePrice.java

@@ -121,6 +121,11 @@ public class StorePrice {
     @ApiModelProperty("门店名称")
     @TableField(exist = false)
     private String storeName;
+
+    @ApiModelProperty(value = "AI审核时间")
+    @TableField(value = "audit_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date auditTime;
 }
 
 

+ 135 - 4
alien-store/src/main/java/shop/alien/store/controller/StoreCuisineController.java

@@ -2,7 +2,9 @@ package shop.alien.store.controller;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
@@ -17,10 +19,12 @@ import shop.alien.entity.store.dto.CuisineComboDto;
 import shop.alien.entity.store.dto.CuisineTypeResponseDto;
 import shop.alien.entity.store.dto.TablewareFeeDto;
 import shop.alien.entity.store.vo.PriceListVo;
+import shop.alien.mapper.StoreCuisineMapper;
 import shop.alien.store.annotation.TrackEvent;
 import shop.alien.store.service.StoreCuisineService;
 import shop.alien.store.service.StoreInfoService;
 import shop.alien.store.service.StorePriceService;
+import shop.alien.store.util.ai.AiContentModerationUtil;
 import shop.alien.store.util.ai.AiGetPriceUtil;
 
 import java.text.SimpleDateFormat;
@@ -51,15 +55,142 @@ public class StoreCuisineController {
 
     private final StoreInfoService storeInfoService;
 
+    private final AiContentModerationUtil aiContentModerationUtil;
+
+    private final StoreCuisineMapper storeCuisineMapper;
+
     @ApiOperation("新增美食套餐或单品")
     @ApiOperationSupport(order = 1)
     @PostMapping("/addCuisineCombo")
     public R<StoreCuisine> addCuisineCombo(@RequestBody CuisineComboDto cuisineComboDto) {
-        log.info("StoreCuisineController.save?storeCuisine={}", cuisineComboDto);
-        if (storeCuisineService.addCuisineCombo(cuisineComboDto)) {
-            return R.success("新增成功");
+        log.info("StoreCuisineController.addCuisineCombo?cuisineComboDto={}", cuisineComboDto);
+        
+        // 参数验证
+        if (cuisineComboDto == null) {
+            log.error("新增美食套餐或单品失败:参数不能为空");
+            return R.fail("参数不能为空");
+        }
+        
+        try {
+            // 保存数据
+            boolean saveResult = storeCuisineService.addCuisineCombo(cuisineComboDto);
+            if (!saveResult) {
+                log.error("新增美食套餐或单品失败:保存操作返回false");
+                return R.fail("新增失败");
+            }
+            
+            // 由于 addCuisineCombo 方法返回的是 boolean,我们需要通过查询获取保存后的记录
+            // 通过 storeId + name + cuisineType + 最新的创建时间 来查询,确保获取到刚保存的记录
+            StoreCuisine savedCuisine = null;
+            if (cuisineComboDto.getStoreId() != null && StringUtils.isNotEmpty(cuisineComboDto.getName()) 
+                    && cuisineComboDto.getCuisineType() != null) {
+                LambdaQueryWrapper<StoreCuisine> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(StoreCuisine::getStoreId, cuisineComboDto.getStoreId())
+                        .eq(StoreCuisine::getName, cuisineComboDto.getName())
+                        .eq(StoreCuisine::getCuisineType, cuisineComboDto.getCuisineType())
+                        .orderByDesc(StoreCuisine::getCreatedTime)
+                        .last("LIMIT 1");
+                savedCuisine = storeCuisineService.getOne(queryWrapper);
+            }
+            
+            if (savedCuisine == null) {
+                log.error("新增美食套餐或单品失败:保存后查询不到数据");
+                return R.fail("新增失败:数据保存异常");
+            }
+            
+            // 将状态置为"审核中"(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);
+                boolean allPassed = (auditResult != null);
+                
+                LambdaUpdateWrapper<StoreCuisine> auditUpdateWrapper = new LambdaUpdateWrapper<>();
+                auditUpdateWrapper.eq(StoreCuisine::getId, savedCuisine.getId());
+                auditUpdateWrapper.set(StoreCuisine::getRejectionReason, null);
+                auditUpdateWrapper.set(StoreCuisine::getAuditTime, new Date());
+                
+                if (allPassed) {
+                    // 审核通过 审核状态为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) {
+            log.error("新增美食套餐或单品异常", e);
+            return R.fail("新增失败:" + e.getMessage());
         }
-        return R.fail("新增失败");
     }
 
     @ApiOperation("修改美食套餐或单品")

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

@@ -1,7 +1,9 @@
 package shop.alien.store.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
@@ -12,8 +14,10 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreInfo;
 import shop.alien.entity.store.StorePrice;
 import shop.alien.mapper.StoreInfoMapper;
+import shop.alien.mapper.StorePriceMapper;
 import shop.alien.store.annotation.TrackEvent;
 import shop.alien.store.service.StorePriceService;
+import shop.alien.store.util.ai.AiContentModerationUtil;
 import shop.alien.util.encryption.Decrypt;
 import shop.alien.util.encryption.Encrypt;
 import shop.alien.util.encryption.JasyptEncryptorUtil;
@@ -21,10 +25,7 @@ import shop.alien.util.encryption.StandardAesUtil;
 import shop.alien.util.encryption.properties.EncryptProperties;
 
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 通用价目表
@@ -47,6 +48,10 @@ public class StorePriceController {
 
     private final EncryptProperties encryptProperties;
 
+    private final AiContentModerationUtil aiContentModerationUtil;
+
+    private final StorePriceMapper storePriceMapper;
+
     @Value("${test1}")
     private String dbPassword;
 
@@ -103,10 +108,122 @@ public class StorePriceController {
     @PostMapping("/save")
     public R<StorePrice> save(@RequestBody StorePrice storePrice) {
         log.info("StorePriceController.save?storePrice={}", storePrice);
-        if (storePriceService.save(storePrice)) {
-            return R.data(storePrice, "新增成功");
+        
+        // 参数验证
+        if (storePrice == null) {
+            log.error("新增通用价目失败:参数不能为空");
+            return R.fail("参数不能为空");
+        }
+        
+        try {
+            // 保存数据
+            boolean saveResult = storePriceService.save(storePrice);
+            if (!saveResult) {
+                log.error("新增通用价目失败:保存操作返回false");
+                return R.fail("新增失败");
+            }
+            
+            // MyBatis-Plus 的 save 方法会自动将生成的主键ID填充到对象中
+            Integer savedId = storePrice.getId();
+            if (savedId == null) {
+                log.error("新增通用价目失败:保存后ID为空");
+                return R.fail("新增失败:ID生成失败");
+            }
+            
+            // 重新查询一次,确保返回包含完整数据(包括ID和所有数据库字段)的对象
+            StorePrice savedPrice = storePriceService.getById(savedId);
+            if (savedPrice == null) {
+                log.error("新增通用价目失败:保存后查询不到数据,ID={}", savedId);
+                return R.fail("新增失败:数据保存异常");
+            }
+            
+            // 将状态置为"审核中"(0)
+            LambdaUpdateWrapper<StorePrice> auditingWrapper = new LambdaUpdateWrapper<>();
+            auditingWrapper.eq(StorePrice::getId, savedPrice.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, savedPrice.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: {}", savedPrice.getId());
+                } else {
+                    // 审核拒绝 审核状态为2 上架状态为0 没有上下架状态
+                    auditUpdateWrapper.set(StorePrice::getStatus, 2);
+                    auditUpdateWrapper.set(StorePrice::getShelfStatus, 0);
+                    log.info("AI审核拒绝,ID: {}", savedPrice.getId());
+                }
+                storePriceMapper.update(null, auditUpdateWrapper);
+            }
+            
+            // 重新查询一次,返回最新的数据
+            StorePrice finalPrice = storePriceService.getById(savedPrice.getId());
+            if (finalPrice != null) {
+                log.info("新增成功,返回ID: {}", finalPrice.getId());
+                return R.data(finalPrice, "新增成功");
+            }
+            
+            // 如果查询失败,返回保存后的对象(至少包含ID)
+            log.warn("新增成功但最终查询失败,返回保存后的对象,ID: {}", savedId);
+            return R.data(savedPrice, "新增成功");
+            
+        } catch (Exception e) {
+            log.error("新增通用价目异常", e);
+            return R.fail("新增失败:" + e.getMessage());
         }
-        return R.fail("新增失败");
     }
 
     @ApiOperation("修改通用价目")