package com.sptg.gateway.controller.statistics;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.common.security.service.SecurityServiceInterface;
import com.sptg.permissions.api.entity.Account;
import com.sptg.statistics.api.constant.StatisticsSecurityToken;
import com.sptg.statistics.api.dto.SysOperationLogDto;
import com.sptg.statistics.api.entity.SysOperationLog;
import com.sptg.statistics.api.feigns.SysOperationLogFeign;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * title: VisitorController
 * package: com.sptg.gateway.controller.statistics
 * description: 系统事件日志-网关控制器
 *
 *                
 *                
 */

@RestController
@RequestMapping(value = "/statistics/sysOperationLog")
@AllArgsConstructor
public class SysOperationLogController {

    private final SysOperationLogFeign sysOperationLogFeign;
    private final SecurityServiceInterface<Account> securityServiceInterface;

    /**
     * 功能描述:系统事件日志
     * @return java.lang.String
     *                
     *                       
     */
    @RequestMapping("/index")
    @Security(token = StatisticsSecurityToken.LOG_OPERATION_MANAGE)
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("statistics/sys-operation-log");
        return modelAndView;
    }

    /**
     * 功能描述:系统事件日志详情
     * @return java.lang.String
     *
     *
     */
    @RequestMapping("/detail/{id}")
    @Security(token = StatisticsSecurityToken.LOG_OPERATION_MANAGE)
    public ModelAndView detail(@PathVariable(value = "id") Long id){
        if (id == null){
            return new ModelAndView("common/404");
        }
        ModelAndView modelAndView = new ModelAndView("statistics/sys-operation-log-detail");
        SysOperationLog sysOperationLog = this.sysOperationLogFeign.selectById(id);
        modelAndView.addObject("sysOperationLog",sysOperationLog);
        return modelAndView;
    }

    /**
     * 功能描述:展示系统日志列表
     * @param solDto
     * @param page
     * @return ResultBean<Page<SysOperationLog>>
     *                
     *                       
     */
    @RequestMapping(value="/showSysOperationLogList")
    @Security(token = StatisticsSecurityToken.LOG_OPERATION_MANAGE,format= DataFormatEnum.JSON)
    public ResultBean<Page<SysOperationLog>> showSysOperationLogList(SysOperationLogDto solDto,Page<SysOperationLog> page){
            solDto.setPage(page);
            //机构位置
            Account account=this.securityServiceInterface.getOnLineUser();
            solDto.setOrgPosition(account.getOrgPosition());
            return  sysOperationLogFeign.showSysOperationLogList(solDto);
    }
}
