package com.ruoyi.interfaces.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.interfaces.core.page.Page;
import com.ruoyi.interfaces.core.page.PageUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.interfaces.domain.PtModelLog;
import com.ruoyi.interfaces.mapper.PtModelLogMapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

@RestController
@RequestMapping("/pt/model/log")
public class PtModelLogController extends BaseController {

    @Autowired
    private PtModelLogMapper ptModelInfoMapper;

    @ApiOperation("/删除日志")
    @RequestMapping(value = "/del")
    public AjaxResult del(String ids) {
        String[] strs = ids.split(",");
        int deletes = 0;
        if (strs == null || strs.length == 0) {
            return ptModelInfoMapper.deleteByPrimaryKey(ids) > 0 ? AjaxResult.success() : AjaxResult.error();
        } else {
            for (String str : strs) {
                deletes += ptModelInfoMapper.deleteByPrimaryKey(str);
            }
            return strs.length == deletes ? AjaxResult.success() : AjaxResult.error();
        }
    }

    @ApiOperation("/日志列表")
    @RequestMapping(value = "/list")
    public Page list(@RequestParam(required = false, defaultValue = "1") int page,
                     @RequestParam(required = false, defaultValue = "100") int rows, String appid, String startDate, String endDate) {
        PageHelper.startPage(page, rows);

        PtModelLog log = new PtModelLog();

        List<PtModelLog> list = ptModelInfoMapper.selectAll(log);

        PageInfo<PtModelLog> pageInfo = new PageInfo<>(list);
        return PageUtils.convert(pageInfo);
    }
}
