package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.InstructionInfo;
import com.phm.manage.service.IInstructionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 指令信息Controller
 *
 * @author phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/instructionInfo")
public class InstructionInfoController extends BaseController {
    @Autowired
    private IInstructionInfoService instructionInfoService;

    /**
     * 查询指令信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(InstructionInfo instructionInfo) {
        startPage();
        List<InstructionInfo> list = instructionInfoService.selectInstructionInfoList(instructionInfo);
        return getDataTable(list);
    }

    /**
     * 导出指令信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:export')")
    @Log(title = "指令信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InstructionInfo instructionInfo) {
        List<InstructionInfo> list = instructionInfoService.selectInstructionInfoList(instructionInfo);
        ExcelUtil<InstructionInfo> util = new ExcelUtil<InstructionInfo>(InstructionInfo.class);
        util.exportExcel(response, list, "指令信息数据");
    }

    /**
     * 获取指令信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(instructionInfoService.selectInstructionInfoById(id));
    }

    /**
     * 新增指令信息
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:add')")
    @Log(title = "指令信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InstructionInfo instructionInfo) {
        return toAjax(instructionInfoService.insertInstructionInfo(instructionInfo));
    }

    /**
     * 修改指令信息
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:edit')")
    @Log(title = "指令信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InstructionInfo instructionInfo) {
        return toAjax(instructionInfoService.updateInstructionInfo(instructionInfo));
    }

    /**
     * 删除指令信息
     */
    @PreAuthorize("@ss.hasPermi('manage:instructionInfo:remove')")
    @Log(title = "指令信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(instructionInfoService.deleteInstructionInfoByIds(ids));
    }
}
