|
|
@@ -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(
|