package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.entity.rest.RestCode;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.common.utils.AppTokenUtil;
import cn.hanghui.outapi.platform.tenant.entity.dto.AppLogDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.AppLogPageDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.AppLogVo;
import cn.hanghui.outapi.platform.tenant.service.AppLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.controller
 * @class AppLogController
 * @date 2023/12/19 上午10:44
 * @description
 */
@Slf4j
@Api(tags = "应用日志")
@RestController
@RequestMapping("/api/v1/app/log")
@AllArgsConstructor(onConstructor_ = @Autowired)
public class AppLogController {

    @Autowired
    private AppLogService appLogService;

    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;

    @ApiOperation(value = "日志插入", notes = "日志插入")
    @PostMapping(value = "/add")
    public RestResult taskQuery(@RequestBody AppLogDto dto) {
//        List<String> tokens = AppTokenUtil.getTokens();
//        if (dto == null || dto.getToken() == null || "".equals(dto.getToken().trim()) || !tokens.contains(dto.getToken().trim())) {
//            return RestResult.error(RestCode.FORBIDDEN.getMsg());
//        }
//
//        if (dto.getSn() == null || "".equals(dto.getSn().trim())) {
//            return RestResult.error("参数有误！");
//        }
//        threadPoolExecutor.execute(() -> {
//            appLogService.add(dto);
//        });
        return RestResult.ok();
    }

    @ApiOperation(value = "查询日志列表（分页）")
    @PostMapping("/page")
    public RestResult<IPage<AppLogVo>> page(@RequestBody AppLogPageDto dto) {
        return appLogService.page(dto);
    }


}
