package com.tiesheng.core.controller.log;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiesheng.core.pojos.dao.CoreLogOperation;
import com.tiesheng.core.pojos.dto.PageDTO;
import com.tiesheng.core.service.CoreLogService;
import com.tiesheng.util.pojos.ApiResp;
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.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author hao
 */
@RestController
@RequestMapping("/manager/log")
public class ManagerLogController {

    @Autowired
    CoreLogService coreLogService;


    /**
     * 操作日志列表
     *
     * @return
     */
    @GetMapping("/operation/page")
    public ApiResp<List<CoreLogOperation>> operationList(@Valid PageDTO dto) {

        QueryWrapper<CoreLogOperation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0);
        dto.likeColumns(queryWrapper, "user_name", "title", "subject", "params");
        queryWrapper.orderByDesc("create_time");

        Page<CoreLogOperation> page = dto.pageObj();
        coreLogService.page(page, queryWrapper);

        return ApiResp.respOK(page.getRecords(), page.getTotal());
    }

}
