package cn.iocoder.yudao.module.product.controller.admin.deviceoperatelog;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.deviceoperatelog.vo.DeviceOperateLogPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.deviceoperatelog.vo.DeviceOperateLogRespVO;
import cn.iocoder.yudao.module.product.convert.deviceoperatelog.DeviceOperateLogConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.deviceoperatelog.DeviceOperateLogDO;
import cn.iocoder.yudao.module.product.service.deviceoperatelog.DeviceOperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 设备操作日志")
@RestController
@RequestMapping("/product/device-operate-log")
@Validated
public class DeviceOperateLogController {

    @Resource
    private DeviceOperateLogService deviceOperateLogService;

    @GetMapping("/get")
    @ApiOperation("获得设备操作日志")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('product:device-operate-log:query')")
    public CommonResult<DeviceOperateLogRespVO> getDeviceOperateLog(@RequestParam("id") Long id) {
        DeviceOperateLogDO deviceOperateLog = deviceOperateLogService.getDeviceOperateLog(id);
        return success(DeviceOperateLogConvert.INSTANCE.convert(deviceOperateLog));
    }

    @GetMapping("/page")
    @ApiOperation("获得设备操作日志分页")
    @PreAuthorize("@ss.hasPermission('product:device-operate-log:query')")
    public CommonResult<PageResult<DeviceOperateLogRespVO>> getDeviceOperateLogPage(@Valid DeviceOperateLogPageReqVO pageVO) {
        PageResult<DeviceOperateLogDO> pageResult = deviceOperateLogService.getDeviceOperateLogPage(pageVO);
        return success(DeviceOperateLogConvert.INSTANCE.convertPage(pageResult));
    }

}
