package com.sptg.statistics.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.statistics.api.dto.SysOperationLogDto;
import com.sptg.statistics.api.entity.SysOperationLog;
import com.sptg.statistics.api.feigns.SysOperationLogFeign;
import com.sptg.statistics.biz.service.SysOperationServiceInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * title: SysOperationLogController
 * package: com.sptg.statistics.biz.controller
 * description: 系统操作日志-控制器
 *
 *                
 *                
 */
@RestController
@Slf4j
public class SysOperationLogController implements SysOperationLogFeign {
    private final SysOperationServiceInterface sysOperationServiceInterface;

    @Autowired
    public SysOperationLogController(SysOperationServiceInterface sysOperationServiceInterface) {
        this.sysOperationServiceInterface = sysOperationServiceInterface;
    }

    @Override
    @PostMapping("/statistics/showSysOperationLogList")
    public ResultBean<Page<SysOperationLog>> showSysOperationLogList(@RequestBody(required = false) SysOperationLogDto solDto) {
        Page<SysOperationLog> page=sysOperationServiceInterface.getSysOperationLogList(solDto);
        return new ResultBean<>(ResultEnum.SUCCESS,page);
    }

    @Override
    @PostMapping("/statistics/selectById")
    public SysOperationLog selectById(@RequestBody Long id) {
        return this.sysOperationServiceInterface.selectById(id);
    }

    @Override
    @PostMapping("/statistics/addSysOperationLog")
    public ResultBean<Boolean> addSysOperationLog(@RequestBody SysOperationLog sysOperationLog) {
        boolean result=sysOperationServiceInterface.insert(sysOperationLog);
        return  new ResultBean<Boolean>(ResultEnum.SUCCESS,result);
    }

    @Override
    @PostMapping("/statistics/sysOperationLogsInfo")
    public ResultBean<Boolean> info(@RequestBody List<SysOperationLog> sysOperationLogs){
        boolean result= false;
        try {
            sysOperationServiceInterface.info(sysOperationLogs);
            result = true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return  new ResultBean<Boolean>(ResultEnum.SUCCESS,result);
    }

    @Override
    @PostMapping("/statistics/sysOperationLogInfo")
    public ResultBean<Boolean> info(@RequestBody SysOperationLog sysOperationLog){
        boolean result= false;
        try {
            sysOperationServiceInterface.info(sysOperationLog);
            result=true;
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return new ResultBean<Boolean>(ResultEnum.SUCCESS,result);
    }
}
