package com.ruoyi.web.controller.baseinfo;

import java.util.List;

import com.ruoyi.baseinfo.domain.BaseWorkingprocedureInfo;
import com.ruoyi.baseinfo.service.IBaseWorkingprocedureInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baseinfo.domain.BaseDeviceInfo;
import com.ruoyi.baseinfo.service.IBaseDeviceInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备基础信息Controller
 * 
 * @author CaesarBao
 * @date 2020-10-22
 */
@Controller
@RequestMapping("/baseinfo/deviceinfo")
public class BaseDeviceInfoController extends BaseController
{
    private String prefix = "baseinfo/deviceinfo";

    @Autowired
    private IBaseDeviceInfoService baseDeviceInfoService;
    @Autowired
    private IBaseWorkingprocedureInfoService baseWorkingprocedureInfoService;

    @RequiresPermissions("baseinfo:deviceinfo:view")
    @GetMapping()
    public String deviceinfo()
    {
        return prefix + "/deviceinfo";
    }

    /**
     * 查询设备基础信息列表
     */
    @RequiresPermissions("baseinfo:deviceinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseDeviceInfo baseDeviceInfo)
    {
        startPage();
        List<BaseDeviceInfo> list = baseDeviceInfoService.selectBaseDeviceInfoList(baseDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备基础信息列表
     */
    @RequiresPermissions("baseinfo:deviceinfo:export")
    @Log(title = "设备基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseDeviceInfo baseDeviceInfo)
    {
        List<BaseDeviceInfo> list = baseDeviceInfoService.selectBaseDeviceInfoList(baseDeviceInfo);
        ExcelUtil<BaseDeviceInfo> util = new ExcelUtil<BaseDeviceInfo>(BaseDeviceInfo.class);
        return util.exportExcel(list, "deviceinfo");
    }

    /**
     * 新增设备基础信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        BaseWorkingprocedureInfo baseWorkingprocedureInfo = new BaseWorkingprocedureInfo();
        mmap.put("cbWorkingprocedureInfo",baseWorkingprocedureInfoService.selectBaseWorkingprocedureInfoList(baseWorkingprocedureInfo));
        return prefix + "/add";
    }

    /**
     * 新增保存设备基础信息
     */
    @RequiresPermissions("baseinfo:deviceinfo:add")
    @Log(title = "设备基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseDeviceInfo baseDeviceInfo)
    {
        return toAjax(baseDeviceInfoService.insertBaseDeviceInfo(baseDeviceInfo));
    }

    /**
     * 修改设备基础信息
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BaseDeviceInfo baseDeviceInfo = baseDeviceInfoService.selectBaseDeviceInfoById(objid);
        mmap.put("cbEditWorkingProcedureInfo",baseWorkingprocedureInfoService.selectEditBaseWorkingprocedureInfoList(baseDeviceInfo.getWorkingProcedureId()));
        mmap.put("baseDeviceInfo", baseDeviceInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备基础信息
     */
    @RequiresPermissions("baseinfo:deviceinfo:edit")
    @Log(title = "设备基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseDeviceInfo baseDeviceInfo)
    {
        return toAjax(baseDeviceInfoService.updateBaseDeviceInfo(baseDeviceInfo));
    }

    /**
     * 删除设备基础信息
     */
    @RequiresPermissions("baseinfo:deviceinfo:remove")
    @Log(title = "设备基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseDeviceInfoService.deleteBaseDeviceInfoByIds(ids));
    }
}
