package com.mingzuozhibi.modules.admin;

import com.mingzuozhibi.commons.base.BaseController;
import com.mingzuozhibi.commons.mylog.JmsBind;
import com.mingzuozhibi.commons.mylog.JmsEnums.Name;
import com.mingzuozhibi.modules.disc.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

import static com.mingzuozhibi.commons.mylog.JmsEnums.NEED_UPDATE_ASINS;
import static com.mingzuozhibi.commons.utils.ThreadUtils.runWithDaemon;

@RestController
@JmsBind(Name.SERVER_CORE)
public class AdminController extends BaseController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private GroupService groupService;

    @Scheduled(cron = "0 0 * * * ?")
    @GetMapping(value = "/admin/runAutomaticTasks", produces = MEDIA_TYPE)
    public void runAutomaticTasks() {
        runWithDaemon(bind, "自动任务", () -> {
            bind.info("每小时自动任务：开始");
            adminService.deleteExpiredRemembers();
            adminService.moveExpiredHourRecords();
            adminService.recordRankAndComputePt();
            adminService.cleanupModulesMessages();
            bind.info("每小时自动任务：完成");
        });
    }

    @Transactional
    @Scheduled(cron = "0 59 * * * ?")
    @GetMapping(value = "/admin/sendNeedUpdateAsins", produces = MEDIA_TYPE)
    public void sendNeedUpdateAsins() {
        Set<String> asins = groupService.findNeedUpdateAsinsSorted();
        jmsSender.send(NEED_UPDATE_ASINS, gson.toJson(asins));
        bind.debug("JMS -> %s size=%d", NEED_UPDATE_ASINS, asins.size());
    }

}

@@ -1105,16 +1105,20 @@
 (bind, %22
+%E6%AF%8F1%E5%B0%8F%E6%97%B6
 %E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%22, (
@@ -1144,24 +1144,25 @@
 bind.info(%22%E6%AF%8F
+1
 %E5%B0%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%EF%BC%9A%E5%BC%80%E5%A7%8B%22);
@@ -1191,21 +1191,19 @@
 ice.
-delet
+mov
 eExpired
 Reme
@@ -1202,16 +1202,18 @@
 ired
-Remember
+HourRecord
 s();
@@ -1238,39 +1238,337 @@
 Service.
-moveExpiredHourRecords(
+recordRankAndComputePt();%0A            bind.info(%22%E6%AF%8F1%E5%B0%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%EF%BC%9A%E5%AE%8C%E6%88%90%22);%0A        %7D);%0A    %7D%0A%0A    @Scheduled(cron = %220 55 1/4 * * ?%22)%0A    @GetMapping(value = %22/admin/runAutomaticTasks2%22, produces = MEDIA_TYPE)%0A    public void runAutomaticTasks2() %7B%0A        runWithDaemon(bind, %22%E6%AF%8F4%E5%B0%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%22, () -%3E %7B%0A            bind.info(%22%E6%AF%8F4%E5%B0%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%EF%BC%9A%E5%BC%80%E5%A7%8B%22
 );%0A     
@@ -1587,38 +1587,38 @@
 Service.
-recordRankAndComputePt
+deleteExpiredRemembers
 ();%0A    
@@ -1688,16 +1688,17 @@
 .info(%22%E6%AF%8F
+4
 %E5%B0%8F%E6%97%B6%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%EF%BC%9A%E5%AE%8C

Add auto tasks every 4 hours