package cn.common.api;

import cn.common.common.anon.ApiLog;
import cn.common.interaction.req.log.PlatformApiLogReq;
import cn.common.interaction.resp.base.ApiResponse;
import cn.common.interaction.resp.log.ApiLogStatisticsResp;
import cn.common.interaction.resp.log.PlatformApiLogResp;
import cn.common.interaction.resp.page.Pagination;
import cn.common.service.PlatformApiLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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 javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Singer create by singer email:singer-coder@qq.com
 * @projectName health-platform-api
 * @Description: 日志前端控制器
 * @date 2020-01-13
 */
@RestController
@RequestMapping(value = "api/v1/platformApiLog")
@Slf4j
public class PlatformApiLogController extends BaseApiController {

    @Resource
    private PlatformApiLogService platformApiLogService;

    /**
     * 分页查询系统日志
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2020-01-10
     * @param platformApiLogReq 系统API日志查询请求Req
     * @return ApiResponse
     */
    @PostMapping("/queryByPage")
    @RequiresPermissions("platformApiLog:queryByPage")
    @ApiLog(value = "分页查询系统日志")
    public ApiResponse<Pagination<PlatformApiLogResp>> queryPlatformApiLogByPage(@RequestBody @Valid
                                                                                         PlatformApiLogReq platformApiLogReq){
        return apiResponse(platformApiLogService.queryByPage(platformApiLogReq));
    }


    /**
     * 根据参数统计访问量
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2022/4/11
     * @param req 查询参数
     * @return
     */
    @PostMapping("/statisticsVisitCount")
    @ApiLog(value = "分页统计查询系统日志")
    public ApiResponse<List<ApiLogStatisticsResp>> statisticsVisitCount(@RequestBody @Valid PlatformApiLogReq req){
        return apiResponse(platformApiLogService.statisticsVisitCount(req));
    }
}
