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.SysDeviceLogDto;
import com.sptg.statistics.api.entity.SysDeviceLog;
import com.sptg.statistics.api.feigns.SysDeviceLogFeign;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * title: SysDeviceLogController
 * package: com.sptg.gateway.controller.statistics
 * description: 设备事件日志-网关控制器
 *
 *                
 *                 
 */
@RestController
@RequestMapping("/statistics/sysDeviceLog")
@AllArgsConstructor
public class SysDeviceLogController {

    private final SysDeviceLogFeign sysDeviceLogFeign;
    private final SecurityServiceInterface<Account> securityServiceInterface;

    /**
     * 功能描述: 设备事件日志页面
     * @return java.lang.String
     *                
     *                       
     */
    @RequestMapping("/index")
    @Security(token = StatisticsSecurityToken.LOG_DEVICE_MANAGE)
    public ModelAndView sysDeviceLog() {
        ModelAndView modelAndView = new ModelAndView("statistics/sys-device-log");
        return modelAndView;
    }

    /**
     * 功能描述:展示设备事件日志列表
     * @param sdlDto
     * @return ResultBean<Page<SysDeviceLog>>
     *                
     *                       
     */
    @RequestMapping("/showSysDeviceLogList")
    @Security(token = StatisticsSecurityToken.LOG_DEVICE_MANAGE,format = DataFormatEnum.JSON)
    public ResultBean<Page<SysDeviceLog>> showSysDeviceLogList(SysDeviceLogDto sdlDto,Page<SysDeviceLog> page) {
        sdlDto.setPage(page);
        //机构位置
        Account account=this.securityServiceInterface.getOnLineUser();
        sdlDto.setOrgPosition(account.getOrgPosition());
        return sysDeviceLogFeign.showSysDeviceLogList(sdlDto);
    }

    /**
     * 功能描述:统计设备故障
     * @param sdlDto
     * @return ResultBean<List<Map<String,Object>>>
     *                
     *                      
     */
    @RequestMapping("/statisticsDeviceMalfunction")
    @Security(token = StatisticsSecurityToken.STATISTICS_DEVICE_MANAGE)
    public ResultBean<List<Map<String,Object>>> statisticsDeviceMalfunction(SysDeviceLogDto sdlDto){
        //统计每月新增设备/设备总数
        ResultBean maps=sysDeviceLogFeign.statisticsDeviceMalfunction(sdlDto);
        return maps;
    }
}
