package com.sooka.sponest.monitor.aidevicedept.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.sooka.sponest.monitor.aidevicedept.domain.CenterdataTAidevicedept;
import com.sooka.sponest.monitor.aidevicedept.service.ICenterdataTAidevicedeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * AI对应部门Controller
 *
 * @author yy
 * @date 2022-09-01
 */
@Api(tags = "AI对应部门控制器")
@RestController
@RequestMapping("/aidevicedept")
public class CenterdataTAidevicedeptController extends BaseController
{
    private final ICenterdataTAidevicedeptService centerdataTAidevicedeptService;

    public CenterdataTAidevicedeptController(ICenterdataTAidevicedeptService centerdataTAidevicedeptService) {
        this.centerdataTAidevicedeptService = centerdataTAidevicedeptService;
    }

    /**
     * 查询AI对应部门列表
     */
    @Log(title = "AI对应部门", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询AI对应部门列表", notes = "查询AI对应部门列表")
    @RequiresPermissions("aidevicedept:aidevicedept:list")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "String"),
            @ApiImplicitParam(name = "deviceCode", value = "设备code", dataType = "String")
    })
    public TableDataInfo list(CenterdataTAidevicedept centerdataTAidevicedept)
    {
        startPage();
        List<CenterdataTAidevicedept> list = centerdataTAidevicedeptService.selectCenterdataTAidevicedeptList(centerdataTAidevicedept);
        return getDataTable(list);
    }

    /**
     * 查询设备对应部门列表
     */
    @Log(title = "AI对应部门", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询设备对应部门列表", notes = "查询设备对应部门列表")
    @GetMapping("/listForCommandCenter")
    public AjaxResult listForCommandCenter(CenterdataTAidevicedept centerdataTAidevicedept)
    {
        List<CenterdataTAidevicedept> list;
        try{
            list = centerdataTAidevicedeptService.selectCenterdataTAidevicedeptList(centerdataTAidevicedept);
            return AjaxResult.success(list);
        }catch (Exception e){
            e.printStackTrace();
        }
        return AjaxResult.error("数据查询失败！");
    }

    /**
     * 导出AI对应部门列表
     */
    @ApiOperation(value = "导出AI对应部门列表", notes = "导出AI对应部门列表")
    @RequiresPermissions("aidevicedept:aidevicedept:export")
    @Log(title = "AI对应部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CenterdataTAidevicedept centerdataTAidevicedept)
    {
        List<CenterdataTAidevicedept> list = centerdataTAidevicedeptService.selectCenterdataTAidevicedeptList(centerdataTAidevicedept);
        ExcelUtil<CenterdataTAidevicedept> util = new ExcelUtil<>(CenterdataTAidevicedept.class);
        util.exportExcel(response, list, "AI对应部门数据");
    }

    /**
     * 获取AI对应部门详细信息
     */
    @Log(title = "AI对应部门", businessType = BusinessType.OTHER)
    @ApiOperation(value = "获取AI对应部门详细信息", notes = "获取AI对应部门详细信息")
    @RequiresPermissions("aidevicedept:aidevicedept:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(centerdataTAidevicedeptService.selectCenterdataTAidevicedeptById(id));
    }

    /**
     * 新增AI对应部门
     */
    @ApiOperation(value = "新增AI对应部门", notes = "新增AI对应部门")
    @RequiresPermissions("aidevicedept:aidevicedept:add")
    @Log(title = "AI对应部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CenterdataTAidevicedept centerdataTAidevicedept)
    {
        return toAjax(centerdataTAidevicedeptService.insertCenterdataTAidevicedept(centerdataTAidevicedept));
    }

    /**
     * 修改AI对应部门
     */
    @ApiOperation(value = "修改AI对应部门", notes = "修改AI对应部门")
    @RequiresPermissions("aidevicedept:aidevicedept:edit")
    @Log(title = "AI对应部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CenterdataTAidevicedept centerdataTAidevicedept)
    {
        return toAjax(centerdataTAidevicedeptService.updateCenterdataTAidevicedept(centerdataTAidevicedept));
    }

    /**
     * 删除AI对应部门
     */
    @ApiOperation(value = "删除AI对应部门", notes = "删除AI对应部门")
    @RequiresPermissions("aidevicedept:aidevicedept:remove")
    @Log(title = "AI对应部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(centerdataTAidevicedeptService.deleteCenterdataTAidevicedeptByIds(ids));
    }
}
