From 7a742d73381eb879217bc76bebf6b8ebede57399 Mon Sep 17 00:00:00 2001 From: Diyu0904 <1819728964@qq.com> Date: Tue, 21 Jan 2025 17:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ModelImageServiceImpl.java | 98 ++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java index efda0b2..be341cd 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java @@ -1,6 +1,8 @@ package com.mcwl.resource.service.impl; import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -11,6 +13,7 @@ import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.page.TableDataInfo; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.StringUtils; +import com.mcwl.common.utils.baidu.BaiduCensor; import com.mcwl.resource.domain.ModelImage; import com.mcwl.resource.domain.dto.ModelImagePageRes; import com.mcwl.resource.domain.dto.ModelImageRes; @@ -22,12 +25,16 @@ import com.mcwl.system.init.DictInit; import com.mcwl.system.service.ISysDictDataService; import com.mcwl.system.service.ISysUserService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Objects; +@Slf4j @Service @RequiredArgsConstructor public class ModelImageServiceImpl extends ServiceImpl implements ModelImageService { @@ -40,6 +47,8 @@ public class ModelImageServiceImpl extends ServiceImpl { + if (modelImage != null) { + if (modelImage.getTitle() != null) { + + //审核名称 + String s = BaiduCensor.TextCensor(modelImage.getTitle() + "," + modelImage.getTags() + "," + + modelImage.getDescription()); + // 解析 JSON 字符串 + JSONObject jsonObject = JSONObject.parseObject(s); + // 获取 'conclusion' 字段的值 + String conclusion = jsonObject.getString("conclusion"); + + if (conclusion.equals("不合规")) { + + //更改状态,添加原因 -> 结束任务 + // 获取 'data' 数组 + JSONArray dataArray = jsonObject.getJSONArray("data"); + + // 存储所有的失败原因 + List failureReasons = new ArrayList<>(); + // 遍历 'data' 数组中的每个元素 + for (Object itemObj : dataArray) { + JSONObject item = (JSONObject) itemObj; + String msg = item.getString("msg"); + failureReasons.add(msg); + } + // 使用逗号拼接所有的失败原因 + String concatenatedReasons = String.join(", ", failureReasons); + modelImage.setAuditText(concatenatedReasons); + + //修改状态以及失败原因 + modelImage.setStatus(4); + log.info("执行111"); + modelImageMapper.updateById(modelImage); + log.info("图片审核未通过"); + //结束任务 + return; + } + + //修改为合格 + modelImage.setAuditText(""); + modelImage.setStatus(1); + baseMapper.updateById(modelImage); + } + } + + if (modelImage.getImagePaths() == null) { + return; + } + //审核图片 + String[] split = modelImage.getImagePaths().split(","); + for (String path : split) { + String s2 = BaiduCensor.ImageCnesor(path); + JSONObject jsonObject2 = JSONObject.parseObject(s2); + if (jsonObject2.getString("conclusion").equals("不合规")) { + + //修改状态->跳出循环 判断下一个版本 + // 获取 'data' 数组 + JSONArray dataArray2 = jsonObject2.getJSONArray("data"); + // 存储所有的失败原因 + List failureReasons = new ArrayList<>(); + // 遍历 'data' 数组中的每个元素 + for (Object itemObj : dataArray2) { + JSONObject item = (JSONObject) itemObj; + String msg = item.getString("msg"); + failureReasons.add(msg); + } + // 使用逗号拼接所有的失败原因 + String concatenatedReasons = String.join(", ", failureReasons); + modelImage.setAuditText(concatenatedReasons); + modelImage.setStatus(4); + baseMapper.updateById(modelImage); + log.info("图片审核未通过"); + return; + } + } + + //修改版本成功审核状态 + modelImage.setAuditText(""); + modelImage.setStatus(1); + baseMapper.updateById(modelImage); + log.info("全部通过审核"); + }); + + } /**