From 8ebdbf6cee0bde3ea986eab22460bde5cc28943b Mon Sep 17 00:00:00 2001 From: hello-hao <923453645@qq.com> Date: Fri, 17 Mar 2023 17:41:10 +0800 Subject: [PATCH] =?UTF-8?q?update:=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=88=A0=E9=99=A4=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20feat:sout=E5=9C=A8log=E6=96=87=E4=BB=B6=E4=B8=AD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/hellohao/config/LogSystemProxy.java | 44 +++++++ .../java/cn/hellohao/config/PoolConfig.java | 52 ++++++++ .../hellohao/controller/AdminController.java | 6 +- .../hellohao/controller/IndexController.java | 6 +- src/main/java/cn/hellohao/dao/ImgMapper.java | 11 +- src/main/java/cn/hellohao/pojo/Images.java | 8 +- .../java/cn/hellohao/service/ImgService.java | 14 +-- .../hellohao/service/impl/ClientService.java | 85 +------------ .../hellohao/service/impl/ImgServiceImpl.java | 6 +- .../impl/ImgViolationJudgeServiceImpl.java | 116 ++++++++++++++++++ .../service/impl/InitializationStorage.java | 3 + .../hellohao/service/impl/UploadServicel.java | 81 ++---------- .../cn/hellohao/service/impl/deleImages.java | 53 +++++++- src/main/java/cn/hellohao/utils/FirstRun.java | 12 +- .../hellohao/utils/progress/MyProgress.java | 8 +- src/main/resources/application.properties | 2 +- src/main/resources/logback-spring.xml | 20 +-- src/main/resources/mapper/ImgMapper.xml | 10 +- 18 files changed, 326 insertions(+), 211 deletions(-) create mode 100644 src/main/java/cn/hellohao/config/LogSystemProxy.java create mode 100644 src/main/java/cn/hellohao/config/PoolConfig.java create mode 100644 src/main/java/cn/hellohao/service/impl/ImgViolationJudgeServiceImpl.java diff --git a/src/main/java/cn/hellohao/config/LogSystemProxy.java b/src/main/java/cn/hellohao/config/LogSystemProxy.java new file mode 100644 index 0000000..db95e6b --- /dev/null +++ b/src/main/java/cn/hellohao/config/LogSystemProxy.java @@ -0,0 +1,44 @@ +package cn.hellohao.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; +import java.io.PrintStream; +import java.util.function.Consumer; + +@Configuration +public class LogSystemProxy { + + private final static Logger log = LoggerFactory.getLogger("proxy.system.log"); + + @PostConstruct + public void initProxy(){ + log.debug("LogSystemProxy init ....."); + System.setOut(getLoggerProxy(StdType.OUT)); + System.setErr(getLoggerProxy(StdType.ERR)); + } + + + private enum StdType{ + OUT(System.out, log::info), + ERR(System.err, log::error), + ; + PrintStream stream; + Consumer consumer; + StdType(PrintStream stream,Consumer consumer){ + this.stream = stream; + this.consumer = consumer; + } + } + + private PrintStream getLoggerProxy(StdType stdType){ + return new PrintStream(stdType.stream){ + @Override + public void print(String s) { + stdType.stream.print(s); + stdType.consumer.accept(s); + } + }; + } +} \ No newline at end of file diff --git a/src/main/java/cn/hellohao/config/PoolConfig.java b/src/main/java/cn/hellohao/config/PoolConfig.java new file mode 100644 index 0000000..ec48552 --- /dev/null +++ b/src/main/java/cn/hellohao/config/PoolConfig.java @@ -0,0 +1,52 @@ +package cn.hellohao.config; + +import lombok.Data; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ThreadPoolExecutor; + +//线程池 +@Configuration +@EnableAsync +public class PoolConfig { + ThreadPoolProperties properties = new ThreadPoolProperties(); + @Bean(name = "taskExecutor") + public ThreadPoolTaskExecutor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(properties.getCorePoolSize()); + executor.setMaxPoolSize(properties.getMaxPoolSize()); + executor.setQueueCapacity(properties.getQueueCapacity()); + executor.setThreadNamePrefix(properties.getThreadNamePrefix()); + executor.setKeepAliveSeconds(properties.getKeepAliveTime()); + executor.setWaitForTasksToCompleteOnShutdown(properties.isWaitForTasksToCompleteOnShutdown()); + executor.setAwaitTerminationSeconds(properties.getAwaitTerminationSeconds()); + // 设置任务拒绝策略 + /** + * 4种 + * ThreadPoolExecutor类有几个内部实现类来处理这类情况: + - AbortPolicy 丢弃任务,抛RejectedExecutionException + - CallerRunsPolicy 由该线程调用线程运行。直接调用Runnable的run方法运行。 + - DiscardPolicy 抛弃策略,直接丢弃这个新提交的任务 + - DiscardOldestPolicy 抛弃旧任务策略,从队列中踢出最先进入队列(最后一个执行)的任务 + * 实现RejectedExecutionHandler接口,可自定义处理器 + */ + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } + + @Data + class ThreadPoolProperties { + private int corePoolSize = 5; + private int maxPoolSize = 50; + private int keepAliveTime = 15; + private int queueCapacity = 6; + private String threadNamePrefix = "Tbed-Thread"; + private boolean allowCoreThreadTimeout = false; + private boolean waitForTasksToCompleteOnShutdown = false; + private int awaitTerminationSeconds; + + } +} \ No newline at end of file diff --git a/src/main/java/cn/hellohao/controller/AdminController.java b/src/main/java/cn/hellohao/controller/AdminController.java index d3c6342..dac18c4 100644 --- a/src/main/java/cn/hellohao/controller/AdminController.java +++ b/src/main/java/cn/hellohao/controller/AdminController.java @@ -472,9 +472,9 @@ public class AdminController { msg.setInfo("为获取到图像信息"); return msg; } - List imgIds = new ArrayList(); + List imgIds = new ArrayList(); for (int i = 0; i < split.length; i++) { - Integer imgid = Integer.valueOf(split[i]); + Long imgid = Long.valueOf(split[i]); Images image = imgService.selectByPrimaryKey(imgid); if (!subject.hasRole("admin")) { if (!image.getUserid().equals(user.getId())) { @@ -486,7 +486,7 @@ public class AdminController { if (imgIds.size() == 0) { msg.setCode("110404"); } else { - deleimages.dele(uuid, imgIds.stream().toArray(Integer[]::new)); + deleimages.dele(uuid, imgIds.stream().toArray(Long[]::new)); msg.setCode("200"); } return msg; diff --git a/src/main/java/cn/hellohao/controller/IndexController.java b/src/main/java/cn/hellohao/controller/IndexController.java index 5a85bf0..4c5f517 100644 --- a/src/main/java/cn/hellohao/controller/IndexController.java +++ b/src/main/java/cn/hellohao/controller/IndexController.java @@ -42,10 +42,10 @@ public class IndexController { @RequestMapping(value = "/") public String Welcome(Model model, HttpServletRequest httpServletRequest) { - model.addAttribute("name", "服务端程序"); - model.addAttribute("version", "20230316"); + model.addAttribute("name", "服务端程序(开源版)"); + model.addAttribute("version", "20230318"); model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest)); - model.addAttribute("links", "www.hellohao.cn"); + model.addAttribute("links", "https://github.com/Hello-hao/tbed"); return "welcome"; } diff --git a/src/main/java/cn/hellohao/dao/ImgMapper.java b/src/main/java/cn/hellohao/dao/ImgMapper.java index 2a0b188..c4417ff 100644 --- a/src/main/java/cn/hellohao/dao/ImgMapper.java +++ b/src/main/java/cn/hellohao/dao/ImgMapper.java @@ -1,12 +1,11 @@ package cn.hellohao.dao; -import java.util.List; - +import cn.hellohao.pojo.Images; import cn.hellohao.pojo.User; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import cn.hellohao.pojo.Images; +import java.util.List; @Mapper public interface ImgMapper { @@ -17,18 +16,18 @@ public interface ImgMapper { Integer countimg(@Param("userid") Integer userid); - Integer deleimg(@Param("id") Integer id); + Integer deleimg(@Param("id") Long id); Integer deleimgForImgUid(@Param("imguid") String imguid); - Images selectByPrimaryKey(@Param("id") Integer id); + Images selectByPrimaryKey(@Param("id") Long id); Integer counts(@Param("userid") Integer userid); Integer setImg(Images images); Integer deleimgname(@Param("imgname") String imgname); - Integer deleall(@Param("id") Integer id); + Integer deleall(@Param("id") Long id); List gettimeimg(@Param("time") String time); diff --git a/src/main/java/cn/hellohao/pojo/Images.java b/src/main/java/cn/hellohao/pojo/Images.java index 2bddfdb..1752e42 100644 --- a/src/main/java/cn/hellohao/pojo/Images.java +++ b/src/main/java/cn/hellohao/pojo/Images.java @@ -4,7 +4,7 @@ public class Images { // 默认的时间字符串格式 //id, imgname, imgurl, userid - private Integer id; + private Long id; private String imgname; private String imgurl; private Integer userid; @@ -52,7 +52,7 @@ public class Images { this.imguid = imguid; } - public Images(Integer id, String imgname, String imgurl, Integer userid, String sizes, String abnormal, Integer source, + public Images(Long id, String imgname, String imgurl, Integer userid, String sizes, String abnormal, Integer source, Integer imgtype, String updatetime, String username, Integer storageType, String starttime, String stoptime, String explains, String md5key, String notes, String useridlist, String imguid, String albumtitle, String password, Integer selecttype,Long countNum,Integer monthNum,String yyyy, @@ -93,11 +93,11 @@ public class Images { } - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } diff --git a/src/main/java/cn/hellohao/service/ImgService.java b/src/main/java/cn/hellohao/service/ImgService.java index 7735782..330a635 100644 --- a/src/main/java/cn/hellohao/service/ImgService.java +++ b/src/main/java/cn/hellohao/service/ImgService.java @@ -1,27 +1,25 @@ package cn.hellohao.service; -import java.util.List; - -import cn.hellohao.pojo.User; -import org.apache.ibatis.annotations.Param; - import cn.hellohao.pojo.Images; +import cn.hellohao.pojo.User; import org.springframework.stereotype.Service; +import java.util.List; + @Service public interface ImgService { List selectimg(Images images); Integer insertImgData(Images images); - Integer deleimg(Integer id); + Integer deleimg(Long id); Integer deleimgForImgUid(String imguid); Integer countimg(Integer userid); - Images selectByPrimaryKey(Integer id); + Images selectByPrimaryKey(Long id); Integer counts(Integer userid); @@ -29,7 +27,7 @@ public interface ImgService { Integer deleimgname(String imgname); - Integer deleall(Integer id); + Integer deleall(Long id); List gettimeimg(String time); diff --git a/src/main/java/cn/hellohao/service/impl/ClientService.java b/src/main/java/cn/hellohao/service/impl/ClientService.java index 537ea14..d955dad 100644 --- a/src/main/java/cn/hellohao/service/impl/ClientService.java +++ b/src/main/java/cn/hellohao/service/impl/ClientService.java @@ -3,12 +3,8 @@ package cn.hellohao.service.impl; import cn.hellohao.dao.*; import cn.hellohao.pojo.*; import cn.hellohao.service.ImgTempService; -import cn.hellohao.service.SysConfigService; import cn.hellohao.utils.*; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baidu.aip.contentcensor.AipContentCensor; -import com.baidu.aip.contentcensor.EImgType; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -28,7 +24,6 @@ import java.util.*; @Service public class ClientService { - @Autowired private SysConfigService sysConfigService; @Autowired private UserMapper userMapper; @Autowired private KeysMapper keysMapper; @Autowired private UploadConfigMapper uploadConfigMapper; @@ -36,6 +31,7 @@ public class ClientService { @Autowired private ImgreviewMapper imgreviewMapper; @Autowired private ImgTempService imgTempService; @Autowired private GetSource getSource; + @Autowired private ImgViolationJudgeServiceImpl imgViolationJudgeService; public Msg uploadImg( HttpServletRequest request, MultipartFile multipartFile, String email, String pass,Integer setday) { @@ -164,16 +160,6 @@ public class ClientService { List images = imgMapper.selectImgUrlByMD5(md5key); if (images.size() > 0) { jsonObject.put("url", images.get(0).getImgurl()); -// Keys imgFromKey = keysService.selectKeys(images.get(0).getSource()); -// if (imgFromKey.getStorageType().equals(5)) { -// jsonObject.put( -// "url", -// imgFromKey.getRequestAddress() -// + "/ota/" -// + images.get(0).getImgname()); -// } else { -// jsonObject.put("url", images.get(0).getImgurl()); -// } jsonObject.put("name", file.getName()); jsonObject.put("size", images.get(0).getSizes()); msg.setData(jsonObject); @@ -192,11 +178,7 @@ public class ClientService { jsonObject.put("url", imgObj.getImgurl()); jsonObject.put("name", imgObj.getImgname()); jsonObject.put("size", imgObj.getSizes()); - new Thread( - () -> { - LegalImageCheck(imgObj); - }) - .start(); + imgViolationJudgeService.LegalImageCheck(imgObj,key); } else { imgMapper.deleimgForImgUid(imgObj.getImguid()); msg.setCode("5001"); @@ -266,67 +248,4 @@ public class ClientService { return msg; } - // 图片鉴黄 - private synchronized void LegalImageCheck(Images images) { - Imgreview imgreview = null; - try { - imgreview = imgreviewMapper.selectByusing(1); - } catch (Exception e) { - Print.warning("获取鉴别程序的时候发生错误"); - e.printStackTrace(); - } - if(imgreview==null){ - System.out.println("没有找到可用的图像鉴别进程"); - }else{ - LegalImageCheckForBaiDu(imgreview, images); - } - - } - - private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) { - if (imgreview.getUsing() == 1) { - try { - AipContentCensor client = - new AipContentCensor( - imgreview.getAppId(), - imgreview.getApiKey(), - imgreview.getSecretKey()); - client.setConnectionTimeoutInMillis(5000); - client.setSocketTimeoutInMillis(30000); -// org.json.JSONObject res = client.antiPorn(images.getImgurl()); - org.json.JSONObject res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null); - com.alibaba.fastjson.JSONArray jsonArray = - JSON.parseArray("[" + res.toString() + "]"); - for (Object o : jsonArray) { - JSONObject jsonObject = (JSONObject) o; - com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data"); - Integer conclusionType = jsonObject.getInteger("conclusionType"); - if (conclusionType != null) { - if (conclusionType == 2) { - for (Object datum : data) { - JSONObject imgdata = (JSONObject) datum; - if (imgdata.getInteger("type") == 1) { - Images img = new Images(); - img.setImgname(images.getImgname()); - img.setViolation("1[1]"); - imgMapper.setImg(img); - Imgreview imgv = new Imgreview(); - imgv.setId(1); - Integer count = imgreview.getCount(); - System.out.println("违法图片总数:" + count); - imgv.setCount(count + 1); - imgreviewMapper.updateByPrimaryKeySelective(imgv); - System.err.println("存在非法图片,进行处理操作"); - } - } - } - } - } - - } catch (Exception e) { - System.out.println("图像鉴黄线程执行过程中出现异常"); - e.printStackTrace(); - } - } - } } diff --git a/src/main/java/cn/hellohao/service/impl/ImgServiceImpl.java b/src/main/java/cn/hellohao/service/impl/ImgServiceImpl.java index c3344c3..565f2ea 100644 --- a/src/main/java/cn/hellohao/service/impl/ImgServiceImpl.java +++ b/src/main/java/cn/hellohao/service/impl/ImgServiceImpl.java @@ -26,7 +26,7 @@ public class ImgServiceImpl implements ImgService { } @Override - public Integer deleimg(Integer id) { + public Integer deleimg(Long id) { // TODO Auto-generated method stub return imgMapper.deleimg(id); } @@ -36,7 +36,7 @@ public class ImgServiceImpl implements ImgService { return imgMapper.deleimgForImgUid(imguid); } - public Images selectByPrimaryKey(Integer id) { + public Images selectByPrimaryKey(Long id) { return imgMapper.selectByPrimaryKey(id); } @@ -63,7 +63,7 @@ public class ImgServiceImpl implements ImgService { } @Override - public Integer deleall(Integer id) { + public Integer deleall(Long id) { return imgMapper.deleall(id); } diff --git a/src/main/java/cn/hellohao/service/impl/ImgViolationJudgeServiceImpl.java b/src/main/java/cn/hellohao/service/impl/ImgViolationJudgeServiceImpl.java new file mode 100644 index 0000000..243c699 --- /dev/null +++ b/src/main/java/cn/hellohao/service/impl/ImgViolationJudgeServiceImpl.java @@ -0,0 +1,116 @@ +package cn.hellohao.service.impl; + +import cn.hellohao.dao.ImgMapper; +import cn.hellohao.dao.ImgreviewMapper; +import cn.hellohao.pojo.Images; +import cn.hellohao.pojo.Imgreview; +import cn.hellohao.pojo.Keys; +import cn.hellohao.pojo.Msg; +import cn.hellohao.utils.FirstRun; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baidu.aip.contentcensor.AipContentCensor; +import com.baidu.aip.contentcensor.EImgType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ImgViolationJudgeServiceImpl { + + private static Logger logger = LoggerFactory.getLogger(FirstRun.class); + @Autowired + ImgreviewServiceImpl imgreviewService; + @Autowired ImgMapper imgMapper; + @Autowired deleImages deleimages; + @Autowired private ImgreviewMapper imgreviewMapper; + + + //synchronized + @Async("taskExecutor") + public void LegalImageCheck(Images images, Keys keys) { + Imgreview imgreview = null; + try { + imgreview = imgreviewService.selectByusing(1); + } catch (Exception e) { + logger.error("获取鉴别程序的时候发生错误"); + e.printStackTrace(); + } + // 判断哪个鉴别平台 + if (null != imgreview) { + LegalImageCheckForBaiDu(imgreview, images, keys); + } + } + + private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images, Keys keys) { + // Imgreview imgreview = imgreviewService.selectByPrimaryKey(1); + if (imgreview.getUsing() == 1) { + logger.info("非法图像鉴别进程启动-BaiDu"); + try { + AipContentCensor client = + new AipContentCensor( + imgreview.getAppId(), + imgreview.getApiKey(), + imgreview.getSecretKey()); + client.setConnectionTimeoutInMillis(5000); + client.setSocketTimeoutInMillis(30000); +// res = client.antiPorn(images.getImgurl()); + org.json.JSONObject res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null); + logger.info("返回的鉴黄json:" + res.toString()); + com.alibaba.fastjson.JSONArray jsonArray = + JSON.parseArray("[" + res.toString() + "]"); + + for (Object o : jsonArray) { + JSONObject jsonObject = + (JSONObject) o; + com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data"); + Integer conclusionType = jsonObject.getInteger("conclusionType"); + if (conclusionType != null) { + if (conclusionType == 2) { + // 1:合规,2:不合规,3:疑似,4:审核失败 + for (Object datum : data) { + JSONObject imgdata = + (JSONObject) datum; + if (imgdata.getInteger("type") == 1) { + logger.info("存在非法图片,进行处理操作"); + // type参数 + // 0:百度官方违禁图库、1:色情识别、2:暴恐识别、3:恶心图识别、4:广告检测、5:政治敏感识别、6:图像质量检测、7:用户图像黑名单、8:用户图像白名单、10:用户头像审核、11:百度官方违禁词库、12:图文审核、13:自定义文本黑名单、14:自定义文本白名单、15:EasyDL自定义模型、16:敏感旗帜标志识别、21:不良场景识别、24:直播场景审核 + // 存在非法图片,进行处理操作 + Images img = new Images(); + img.setImgname(images.getImgname()); + img.setViolation("1[1]"); // 数字是鉴别平台的主键ID,括号是非法的类型,参考上面的注释 + imgMapper.setImg(img); + // 计入总数 + Imgreview imgv = new Imgreview(); + imgv.setId(1); + Integer count = imgreview.getCount(); + imgv.setCount(count + 1); + imgreviewMapper.updateByPrimaryKeySelective(imgv); + Images imgObj = + imgMapper.selectImgUrlByImgUID(images.getImguid()); + Msg dele = deleimages.dele2(Long.toString(imgObj.getId())); + List ids = (List) dele.getData(); + if (!ids.contains(imgObj.getId())) { + logger.error("检测到违规图像,但是数据库删除失败"); + } + + } + } + } + } + } + + } catch (Exception e) { + logger.error("图像鉴黄线程执行过程中出现异常"); + e.printStackTrace(); + } + } + } + + + +} diff --git a/src/main/java/cn/hellohao/service/impl/InitializationStorage.java b/src/main/java/cn/hellohao/service/impl/InitializationStorage.java index 506c703..eb8eb42 100644 --- a/src/main/java/cn/hellohao/service/impl/InitializationStorage.java +++ b/src/main/java/cn/hellohao/service/impl/InitializationStorage.java @@ -4,6 +4,8 @@ import cn.hellohao.auth.filter.SubjectFilter; import cn.hellohao.dao.KeysMapper; import cn.hellohao.pojo.Keys; import cn.hellohao.utils.Print; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; @@ -23,6 +25,7 @@ import java.util.List; @Order(2) public class InitializationStorage implements CommandLineRunner { + private static Logger logger = LoggerFactory.getLogger(InitializationStorage.class); @Value("${CROS_ALLOWED_ORIGINS}") private String allowedOrigins; diff --git a/src/main/java/cn/hellohao/service/impl/UploadServicel.java b/src/main/java/cn/hellohao/service/impl/UploadServicel.java index 5005c1e..579c08c 100644 --- a/src/main/java/cn/hellohao/service/impl/UploadServicel.java +++ b/src/main/java/cn/hellohao/service/impl/UploadServicel.java @@ -4,10 +4,7 @@ import cn.hellohao.dao.*; import cn.hellohao.pojo.*; import cn.hellohao.service.ImgTempService; import cn.hellohao.utils.*; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baidu.aip.contentcensor.AipContentCensor; -import com.baidu.aip.contentcensor.EImgType; import org.apache.commons.codec.digest.DigestUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; @@ -36,9 +33,10 @@ public class UploadServicel { @Autowired private KeysMapper keysMapper; @Autowired private ImgMapper imgMapper; @Autowired private UserMapper userMapper; - @Autowired private ImgreviewMapper imgreviewMapper; @Autowired private ImgTempService imgTempService; @Autowired private GetSource getSource; + @Autowired deleImages deleimages; + @Autowired ImgViolationJudgeServiceImpl imgViolationJudgeService; public Msg uploadForLoc( HttpServletRequest request, @@ -198,11 +196,12 @@ public class UploadServicel { jsonObject.put("url", imgObj.getImgurl()); jsonObject.put("name", imgObj.getImgname()); jsonObject.put("imguid", imgObj.getImguid()); - new Thread( - () -> { - LegalImageCheck(imgObj); - }) - .start(); + imgViolationJudgeService.LegalImageCheck(imgObj,key); +// new Thread( +// () -> { +// LegalImageCheck(imgObj); +// }) +// .start(); } else { imgMapper.deleimgForImgUid(imgObj.getImguid()); msg.setCode("5001"); @@ -313,70 +312,6 @@ public class UploadServicel { return msg; } - private synchronized void LegalImageCheck(Images images) { - System.out.println("非法图像鉴别进程启动"); - Imgreview imgreview = null; - try { - imgreview = imgreviewMapper.selectByusing(1); - } catch (Exception e) { - Print.warning("获取鉴别程序的时候发生错误"); - e.printStackTrace(); - } - if (null != imgreview) { - LegalImageCheckForBaiDu(imgreview, images); - } - } - - private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) { - System.out.println("非法图像鉴别进程启动-BaiDu"); - if (imgreview.getUsing() == 1) { - try { - AipContentCensor client = - new AipContentCensor( - imgreview.getAppId(), - imgreview.getApiKey(), - imgreview.getSecretKey()); - client.setConnectionTimeoutInMillis(5000); - client.setSocketTimeoutInMillis(30000); -// org.json.JSONObject res = client.antiPorn(images.getImgurl()); - org.json.JSONObject res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null); - logger.info("百度图像审核返回的JSON:"+res.toString()); - com.alibaba.fastjson.JSONArray jsonArray = - JSON.parseArray("[" + res.toString() + "]"); - for (Object o : jsonArray) { - com.alibaba.fastjson.JSONObject jsonObject = - (com.alibaba.fastjson.JSONObject) o; - com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data"); - Integer conclusionType = jsonObject.getInteger("conclusionType"); - if (conclusionType != null) { - if (conclusionType == 2) { - for (Object datum : data) { - com.alibaba.fastjson.JSONObject imgdata = - (com.alibaba.fastjson.JSONObject) datum; - if (imgdata.getInteger("type") == 1) { - Images img = new Images(); - img.setImgname(images.getImgname()); - img.setViolation("1[1]"); - imgMapper.setImg(img); - Imgreview imgv = new Imgreview(); - imgv.setId(1); - Integer count = imgreview.getCount(); - System.out.println("违法图片总数:" + count); - imgv.setCount(count + 1); - imgreviewMapper.updateByPrimaryKeySelective(imgv); - System.err.println("存在非法图片,进行处理操作"); - } - } - } - } - } - - } catch (Exception e) { - System.out.println("图像鉴黄线程执行过程中出现异常"); - e.printStackTrace(); - } - } - } // 计算时间 public static String plusDay(int setday) { diff --git a/src/main/java/cn/hellohao/service/impl/deleImages.java b/src/main/java/cn/hellohao/service/impl/deleImages.java index 8c1c444..d4b8da7 100644 --- a/src/main/java/cn/hellohao/service/impl/deleImages.java +++ b/src/main/java/cn/hellohao/service/impl/deleImages.java @@ -32,11 +32,11 @@ public class deleImages { @Autowired private KeysServiceImpl keysService; @Autowired private IRedisService iRedisService; - public Msg dele(String uuid, Integer... imgIds) { + public Msg dele(String uuid, Long... imgIds) { Msg msg = new Msg(); MyProgress myProgress = new MyProgress(); myProgress.InitializeDelImg(); - List ids = new ArrayList<>(); + List ids = new ArrayList<>(); int successCount = 0; List errorIds = new ArrayList<>(); for (int i = 0; i < imgIds.length; i++) { @@ -111,9 +111,50 @@ public class deleImages { return msg; } - public static void main(String[] args) { - MyProgress myProgress = new MyProgress(); - myProgress.InitializeDelImg(); - System.out.println(JSONObject.toJSONString(myProgress)); + public Msg dele2(String... imgIds) { + Msg msg = new Msg(); + List ids = new ArrayList<>(); + for (int i = 0; i < imgIds.length; i++) { + try { + Images image = imgService.selectByPrimaryKey(Long.valueOf(imgIds[i])); + Keys key = keysService.selectKeys(image.getSource()); + if (key.getStorageType() == 1) { + nosImageupload.delNOS(key.getId(), image); + } else if (key.getStorageType() == 2) { + ossImageupload.delOSS(key.getId(), image); + } else if (key.getStorageType() == 3) { + ussImageupload.delUSS(key.getId(), image); + } else if (key.getStorageType() == 4) { + kodoImageupload.delKODO(key.getId(), image); + } else if (key.getStorageType() == 5) { + LocUpdateImg.deleteLOCImg(image); + } else if (key.getStorageType() == 6) { + cosImageupload.delCOS(key.getId(), image); + } else if (key.getStorageType() == 7) { + ftpService.delFTP(key.getId(), image); + } else if (key.getStorageType() == 8) { + s3Imageupload.deleS3(key.getId(), image); + } else { + System.err.println("未获取到对象存储参数,删除失败。"); + } + try { + imgAndAlbumService.deleteImgAndAlbum(image.getImgurl()); + imgTempService.delImgAndExp(image.getImguid()); + imgService.deleimg(image.getId()); + ids.add(image.getId()); + } catch (Exception e) { + e.printStackTrace(); + System.err.println(image.getImgname() + ":图片数据库记录时发生错误"); + } + } catch (Exception e) { + System.err.println("删除的时候发生了一些异常"); +// ids.add(Long.valueOf(imgIds[i])); + e.printStackTrace(); + } + } + msg.setData(ids); + return msg; } + + } diff --git a/src/main/java/cn/hellohao/utils/FirstRun.java b/src/main/java/cn/hellohao/utils/FirstRun.java index b64f9a0..c0e1f40 100644 --- a/src/main/java/cn/hellohao/utils/FirstRun.java +++ b/src/main/java/cn/hellohao/utils/FirstRun.java @@ -1,11 +1,15 @@ package cn.hellohao.utils; import cn.hellohao.config.GlobalConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; import java.util.Properties; import java.util.UUID; @@ -16,7 +20,7 @@ import java.util.UUID; */ @Configuration public class FirstRun implements InitializingBean { - + private static Logger logger = LoggerFactory.getLogger(FirstRun.class); @Value("${spring.datasource.username}") private String jdbcusername; @@ -34,13 +38,12 @@ public class FirstRun implements InitializingBean { public void afterPropertiesSet() { if(!DockerWebHost.contains("null")){ contentToTxt("/hellohaotbed/webapps/hellohao/config.json", "{\"serverHost\": \""+DockerWebHost+"\"}"); - System.out.println("====>"+DockerWebHost); } isWindows(); RunSqlScript.USERNAME = jdbcusername; RunSqlScript.PASSWORD = jdbcpass; RunSqlScript.DBURL = jdbcurl; - Print.Normal("正在校验数据库参数..."); + logger.info("正在校验数据库参数..."); RunSqlScript.RunInsert(dynamic); RunSqlScript.RunInsert(compressed); @@ -109,7 +112,6 @@ public class FirstRun implements InitializingBean { Print.Normal("Add table.confdata"); } // RunSqlScript.RunInsert(inddx_md5key); - RunSqlScript.RunInsert("UPDATE tbed.`keys` SET `Endpoint` = '0' WHERE `id` = 8"); RunSqlScript.RunInsert("ALTER TABLE tbed.`user` MODIFY id int auto_increment;"); Print.Normal("Stage success"); diff --git a/src/main/java/cn/hellohao/utils/progress/MyProgress.java b/src/main/java/cn/hellohao/utils/progress/MyProgress.java index 561a39c..95b069c 100644 --- a/src/main/java/cn/hellohao/utils/progress/MyProgress.java +++ b/src/main/java/cn/hellohao/utils/progress/MyProgress.java @@ -7,7 +7,7 @@ public class MyProgress { private int delSuccessCount=0;//已经成功的个数 private List delErrorImgListt = new ArrayList<>();//已经失败的图片 private int delOCT=0; //控制开关 - private List delSuccessImgList = new ArrayList<>(); //删除成功的图片 + private List delSuccessImgList = new ArrayList<>(); //删除成功的图片 public void InitializeDelImg(){ this.delSuccessCount=0;//已经成功的个数 @@ -19,7 +19,7 @@ public class MyProgress { public MyProgress() { } - public MyProgress(int delSuccessCount, List delErrorImgListt, int delOCT, List delSuccessImgList) { + public MyProgress(int delSuccessCount, List delErrorImgListt, int delOCT, List delSuccessImgList) { this.delSuccessCount = delSuccessCount; this.delErrorImgListt = delErrorImgListt; this.delOCT = delOCT; @@ -50,11 +50,11 @@ public class MyProgress { this.delOCT = delOCT; } - public List getDelSuccessImgList() { + public List getDelSuccessImgList() { return delSuccessImgList; } - public void setDelSuccessImgList(List delSuccessImgList) { + public void setDelSuccessImgList(List delSuccessImgList) { this.delSuccessImgList = delSuccessImgList; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 62d749d..de7de56 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -49,5 +49,5 @@ spring.datasource.druid.stat-view-servlet.login-username=hellohao@dealer spring.datasource.druid.stat-view-servlet.login-password=52BNmXPJL0rQQ3CU spring.datasource.druid.stat-view-servlet.allow=127.0.0.1 spring.datasource.druid.web-stat-filter.exclusions=false -log4j.logger.cn.hellohao.dao=DEBUG +#log4j.logger.cn.hellohao.dao=DEBUG log4j2.formatMsgNoLookups=True \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 3248a7f..b873407 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -125,18 +125,20 @@ - + - + + + + + + + + - - - - - - - + + \ No newline at end of file diff --git a/src/main/resources/mapper/ImgMapper.xml b/src/main/resources/mapper/ImgMapper.xml index a0947d0..c953242 100644 --- a/src/main/resources/mapper/ImgMapper.xml +++ b/src/main/resources/mapper/ImgMapper.xml @@ -121,7 +121,7 @@ select count(*) from imgdata where userid = #{userid} - + DELETE FROM imgdata WHERE id=#{id} @@ -129,7 +129,7 @@ DELETE FROM imgdata WHERE imguid = #{imguid} - select * from imgdata where id = #{id} @@ -154,6 +154,10 @@ idname=#{idname} + + violation=#{violation} + + where imgname=#{imgname} @@ -163,7 +167,7 @@ - + DELETE FROM imgdata WHERE id = #{id}