package com.ruoyi.web.controller.coffee;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Machine;
import com.ruoyi.system.service.IMachineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机器Controller
 * 
 * @author ruoyi
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/system/machine")
public class MachineController extends BaseController
{
    @Autowired
    private IMachineService machineService;

    /**
     * 查询机器列表
     */
    @PreAuthorize("@ss.hasPermi('system:machine:list')")
    @GetMapping("/list")
    public TableDataInfo list(Machine machine)
    {
        startPage();
        List<Machine> list = machineService.selectMachineList(machine);
        return getDataTable(list);
    }
    /**
     * 绑定机器
     */
    @Log(title = "机器", businessType = BusinessType.INSERT)
    @GetMapping("/bindMachine")
    public AjaxResult bindMachine(String code,Long shopId)
    {
        return AjaxResult.success(machineService.bindMachine(code,shopId));
    }

    /**
     * 获取机器详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:machine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(machineService.selectMachineById(id));
    }

    /**
     * 新增机器
     */
    @PreAuthorize("@ss.hasPermi('system:machine:add')")
    @Log(title = "机器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Machine machine)
    {
        return toAjax(machineService.insertMachine(machine));
    }

    /**
     * 解绑机器
     */
    @Log(title = "机器", businessType = BusinessType.UPDATE)
    @GetMapping("/unbound")
    public AjaxResult unbound(String id)
    {
        return toAjax(machineService.unbound(id));
    }


}
