package com.zksy.data.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.common.domain.Result;
import com.zksy.common.domain.dto.PageDTO;
import com.zksy.common.utils.SearchUtil;
import com.zksy.data.domain.po.XhDataLog;
import com.zksy.data.service.XhDataLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/log")
@Api(tags = "数据采集日志", description = "数据采集日志")
public class LogController {
    @Autowired
    private XhDataLogService xhDataLogService;

    @SneakyThrows
    @GetMapping("/list")
    @ApiOperation("分页获取日志数据")
    public Result list(@RequestParam Optional<Long> pageNum, @RequestParam Optional<Long> pageSize, @RequestParam Optional<String> conditionJson) {
        long defaultPageNum = 1L;
        long defaultPageSize = 10L;
        String defaultCondition = "";
        Page<XhDataLog> page = xhDataLogService.page(
                new Page<>(pageNum.orElse(defaultPageNum), pageSize.orElse(defaultPageSize)),
                SearchUtil.parseWhereSql(conditionJson.orElse(defaultCondition))
        );
        PageDTO<XhDataLog> dto = PageDTO.of(page, XhDataLog.class);
        return Result.ok(dto);
    }
}
