package com.mx.cneeds.server.device.web;

import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.validator.ValidatorUtils;
import com.mx.cneeds.server.entity.DeviceLogEntity;
import com.mx.cneeds.server.device.service.DeviceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 测试上传的日志表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-01-09 15:09:01
 */
@RestController
@RequestMapping("device/devicelog")
public class DeviceLogController {
    @Autowired
    private DeviceLogService deviceLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deviceLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{logId}")
    public R info(@PathVariable("logId") Long logId){
        DeviceLogEntity deviceLog = deviceLogService.getById(logId);

        return R.ok().put("deviceLog", deviceLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DeviceLogEntity deviceLog){
        deviceLogService.save(deviceLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DeviceLogEntity deviceLog){
        ValidatorUtils.validateEntity(deviceLog);
        deviceLogService.updateById(deviceLog);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] logIds){
        deviceLogService.removeByIds(Arrays.asList(logIds));

        return R.ok();
    }

}
