package io.loli.box.green;

import io.loli.box.dao.ImgFileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * Created by chocotan on 2016/8/6.
 */
@Configuration
@ConditionalOnProperty(name = "admin.green.enabled", havingValue = "aliyun")
public class AliGreenConfiguration {

    @Bean
    public GreenService greenService() {
        return new AliGreenService();
    }

    @Autowired
    ImgFileRepository imgFileRepository;

    @Bean
    public Object aliGreenJob(GreenService greenService) {
        return new Object() {
            @Scheduled(fixedRate = 60000)
            public void submitTask() {
                imgFileRepository.findByGreenStatus(0).forEach(img -> {
                    String taskId = greenService.asyncDetect("/images/" + img.getShortName());
                    imgFileRepository.updateTaskIdById(taskId, img.getId());
                    imgFileRepository.updateGreenStatusById(1, img.getId());
                });
            }

            @Scheduled(fixedRate = 120000)
            public void getResult() {
                imgFileRepository.findByGreenStatus(1).forEach(img -> {
                    float checkResult = greenService.getCheckResult(img.getGreenTaskId());
                    boolean porn = checkResult > 90;
                    imgFileRepository.updateGreenStatusById(porn ? 3 : 4, img.getId());
                    imgFileRepository.updateGreenPointById(checkResult, img.getId());
                });
            }
        };
    }
}

@@ -1426,32 +1426,63 @@
 rEach(img -%3E %7B%0D%0A
+                    try %7B%0D%0A    
                 
@@ -1577,16 +1577,20 @@
         
+    
 boolean 
@@ -1627,32 +1627,36 @@
                 
+  
+  
 imgFileRepositor
@@ -1694,9 +1694,9 @@
 3 : 
-4
+5
 , im
@@ -1700,32 +1700,36 @@
  img.getId());%0D%0A
+    
                 
@@ -1791,32 +1791,182 @@
  img.getId());%0D%0A
+                    %7D catch (Exception e) %7B%0D%0A                        imgFileRepository.updateGreenStatusById(4, img.getId());%0D%0A                    %7D%0D%0A
                 

Fix porn check error