package com.yanzhu.jh.video.controller;

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

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.system.service.ISysDeptService;
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.yanzhu.jh.video.domain.DevAiProjectData;
import com.yanzhu.jh.video.service.IDevAiProjectDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备数据Controller
 * 
 * @author JiangYuQi
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/project/aiBoxProjectData")
public class DevAiProjectDataController extends BaseController
{
    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private IDevAiProjectDataService devAiProjectDataService;

    /**
     * 查询设备数据列表
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevAiProjectData devAiProjectData)
    {
        startPage();
        devAiProjectData.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(devAiProjectData.getNowRole())){
            devAiProjectData.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            devAiProjectData.setNowDept(Convert.toStr(getDeptId()));
        }
        devAiProjectData.setNowUser(Convert.toStr(getUserId()));
        devAiProjectData.setNowUserName(getUsername());
        List<DevAiProjectData> list = devAiProjectDataService.selectDevAiProjectDataList(devAiProjectData);
        return getDataTable(list);
    }

    /**
     * 导出设备数据列表
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:export')")
    @Log(title = "设备数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevAiProjectData devAiProjectData)
    {
        List<DevAiProjectData> list = devAiProjectDataService.selectDevAiProjectDataList(devAiProjectData);
        ExcelUtil<DevAiProjectData> util = new ExcelUtil<DevAiProjectData>(DevAiProjectData.class);
        util.exportExcel(response, list, "设备数据数据");
    }

    /**
     * 获取设备数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devAiProjectDataService.selectDevAiProjectDataById(id));
    }

    /**
     * 新增设备数据
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:add')")
    @Log(title = "设备数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevAiProjectData devAiProjectData)
    {
        return toAjax(devAiProjectDataService.insertDevAiProjectData(devAiProjectData));
    }

    /**
     * 修改设备数据
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:edit')")
    @Log(title = "设备数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevAiProjectData devAiProjectData)
    {
        return toAjax(devAiProjectDataService.updateDevAiProjectData(devAiProjectData));
    }

    /**
     * 删除设备数据
     */
    @PreAuthorize("@ss.hasPermi('project:aiBoxProjectData:remove')")
    @Log(title = "设备数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devAiProjectDataService.deleteDevAiProjectDataByIds(ids));
    }
}
