package com.willalp.web.controller.system;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.enums.BusinessType;
import com.willalp.system.domain.SysDevice;
import com.willalp.system.service.ISysDeviceService;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.common.core.page.TableDataInfo;

/**
 * 设备账户Controller
 *
 * @author willalp
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/system/device")
public class SysDeviceController extends BaseController
{
    @Autowired
    private ISysDeviceService sysDeviceService;

    /**
     * 查询设备账户列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDevice sysDevice)
    {
        startPage();
        List<SysDevice> list = sysDeviceService.selectSysDeviceList(sysDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备账户列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "设备账户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysDevice sysDevice)
    {
        List<SysDevice> list = sysDeviceService.selectSysDeviceList(sysDevice);
        ExcelUtil<SysDevice> util = new ExcelUtil<SysDevice>(SysDevice.class);
        return util.exportExcel(list, "设备账户数据");
    }

    /**
     * 获取设备账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysDeviceService.getById(id));
    }

    /**
     * 新增设备账户
     */
    @PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "设备账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDevice sysDevice) {
        sysDeviceService.saveInfo(sysDevice);
        return AjaxResult.success();
    }

    /**
     * 修改设备账户
     */
    @PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "设备账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDevice sysDevice) {
        sysDeviceService.updateInfoById(sysDevice);
        return AjaxResult.success();
    }

    /**
     * 删除设备账户
     */
    @PreAuthorize("@ss.hasPermi('system:device:remove')")
    @Log(title = "设备账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysDeviceService.removeByIds(Arrays.asList(ids)));
    }
}
