package com.chinaweal.aiccs.aiccs.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aiccs.system.entity.LogVO;
import com.chinaweal.aiccs.aiccs.system.service.LogService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.exception.custom.BusinessException;
import com.chinaweal.youfool.framework.springboot.log.service.IRestLogService;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.page.PageRequestDto;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("log")
public class LogController extends BaseController {
    @Autowired
    private IRestLogService iRestLogService;
    @Autowired
    private LogService logService;

    @RequestMapping("query")
    public RestResult<?> queryLog(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request){
        AICUser loginUser = getLoginUser(request);
        if (loginUser == null) throw new BusinessException("登录超时，请重新登录");
        Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
        IPage<LogVO> rs = logService.queryAll(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), customParamMap);
        return RestResult.ok(rs);
    }
}
