package com.bonus.sgzb.base.controller;

import com.bonus.sgzb.base.service.IMaLabelBindService;
import com.bonus.sgzb.base.vo.MaLabelBindVO;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机具设备标签ma_label_bindController
 *
 * @author bonus
 * @date 2023-12-13
 */
@Api
@RestController
@RequestMapping("/base/maLabelBind")
public class MaLabelBindController extends BaseController
{
    @Autowired
    private IMaLabelBindService maLabelBindService;

    /**
     * 查询机具设备标签ma_label_bind列表
     */
    @ApiOperation(value = "查询标签绑定管理列表")
    @GetMapping("/list")
    public TableDataInfo list(MaLabelBindVO maLabelBindVO)
    {
        startPage();
        List<MaLabelBindVO> list = maLabelBindService.selectMaLabelBindList(maLabelBindVO);
        return getDataTable(list);
    }
    /**
     * 查询机具设备标签ma_label_bind列表
     */
    @ApiOperation(value = "查询标签绑定历史列表")
    @GetMapping("/historyList")
    public TableDataInfo historyList(MaLabelBindVO maLabelBindVO)
    {
        startPage();
        List<MaLabelBindVO> list = maLabelBindService.selecthistoryList(maLabelBindVO);
        return getDataTable(list);
    }

    /**
     * 导出机具设备标签ma_label_bind列表
     */
    @ApiOperation(value = "查询标签绑定管理列表")
    @Log(title = "机具设备标签ma_label_bind", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaLabelBindVO maLabelBindVO)
    {
        List<MaLabelBindVO> list = maLabelBindService.selectMaLabelBindList(maLabelBindVO);
        ExcelUtil<MaLabelBindVO> util = new ExcelUtil<MaLabelBindVO>(MaLabelBindVO.class);
        util.exportExcel(response, list, "机具设备标签ma_label_bind数据");
    }

    /**
     * 获取机具设备标签ma_label_bind详细信息
     */
    @ApiOperation(value = "查询标签绑定管理列表")
    @GetMapping(value = "/{maId}")
    public AjaxResult getInfo(@PathVariable("maId") Long maId)
    {
        return success(maLabelBindService.selectMaLabelBindByMaId(maId));
    }

    /**
     * 新增机具设备标签ma_label_bind
     */
    @ApiOperation(value = "新增机具标签绑定管理列表")
    @PreventRepeatSubmit
    @Log(title = "机具设备标签二维码绑定", businessType = BusinessType.MATERIAL)
    @PostMapping
    public AjaxResult add(@RequestBody MaLabelBindVO maLabelBindVO)
    {

        return maLabelBindService.insertMaLabelBind(maLabelBindVO);
    }

    /**
     * 修改机具设备标签ma_label_bind
     */
    @ApiOperation(value = "查询标签绑定管理列表")
    @Log(title = "机具设备标签ma_label_bind", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaLabelBindVO maLabelBindVO)
    {
        return toAjax(maLabelBindService.updateMaLabelBind(maLabelBindVO));
    }

    /**
     * 删除机具设备标签ma_label_bind
     */
    @ApiOperation(value = "查询标签绑定管理列表")
    @Log(title = "机具设备标签ma_label_bind", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(maLabelBindService.updateMaLabelBindByMaIds(id));
    }
}
