package com.pdaaphm.biz.controller;

import com.pdaaphm.biz.service.IRedisLogService;
import com.pdaaphm.common.annotation.Log;
import com.pdaaphm.common.core.domain.AjaxResult;
import com.pdaaphm.common.core.redis.RedisCache;
import com.pdaaphm.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static com.pdaaphm.common.core.domain.AjaxResult.success;

/**
 * @Description LogController
 * @Author WGK
 * @Date 2023/10/18 18:32
 */

@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private IRedisLogService redisLogService;

    @Autowired
    private RedisCache redisCache;

    @GetMapping(value = "/info/{taskId}")
    public AjaxResult getLogInfo(@PathVariable("taskId") String taskId) throws IOException {
        return success("成功", redisLogService.getLogInfo(taskId));
    }

    @GetMapping(value = "/setInfo/{taskId}")
    public AjaxResult setLogInfo(@PathVariable("taskId") String taskId) throws IOException {
        redisCache.deleteObject(taskId);
        redisCache.expire(taskId, 300, TimeUnit.SECONDS);
        redisLogService.info(taskId,"开始1。。。。。。");
        redisLogService.info(taskId,"开始2。。。。。。");
        redisLogService.info(taskId,"开始3。。。。。。");
        redisLogService.info(taskId,"开始4。。。。。。");
        redisLogService.error(taskId,"对方同意更换即可。。。。。。");
        redisLogService.error(taskId,"任务执行完成。。。。");
        return success();
    }

}
