package com.yunfeiyun.agmp.fms.controller;

import java.util.List;

import com.yunfeiyun.agmp.fms.domain.reqvo.TmnBaseBlockReqVo;
import com.yunfeiyun.agmp.fms.domain.reqvo.TmnBlockDeviceListReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.TmnBlockDeviceListResVo;
import com.yunfeiyun.agmp.fms.service.ITmnBlockService;
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.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

/**
 * 设备地块Controller
 * 
 * @author 杨晓辉
 * @date 2023-07-12
 */
@RestController
@RequestMapping("/tmn/block")
public class TmnBlockController extends BaseController
{
    @Autowired
    private ITmnBlockService tmnBlockService;

    /**
     * 查询设备地块列表
     */
    @PreAuthorize("@ss.hasPermi('tmn:block:list')")
    @GetMapping("/list")
    public TableDataInfo list(TmnBlockDeviceListReqVo tmnBlockDeviceListReqVo)
    {
        startPage();
        List<TmnBlockDeviceListResVo> list = tmnBlockService.selectTmnBlockDeviceList(tmnBlockDeviceListReqVo);
        return getDataTable(list);
    }

    /**
     * 设备绑定基地
     */
    @PreAuthorize("@ss.hasPermi('tmn:block:bind')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping("/bind")
    public AjaxResult bind(@RequestBody TmnBaseBlockReqVo tmnBaseBlockReqVo)
    {
        return toAjax(this.tmnBlockService.insertTmnBaseBlockByBind(tmnBaseBlockReqVo));
    }

    /**
     * 设备解绑地块
     */
    @PreAuthorize("@ss.hasPermi('tmn:land:unbind')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/unbind")
    public AjaxResult unbind(@RequestBody TmnBaseBlockReqVo tmnBaseBlockReqVo)
    {
        return toAjax(this.tmnBlockService.deleteTmnBlockByTmnblockId(tmnBaseBlockReqVo));
    }
}
