package com.hw.qms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.qms.domain.QmsCheckProject;
import com.hw.qms.service.IQmsCheckProjectService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 检验项目Controller
 * 
 * @author xins
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/checkproject")
public class QmsCheckProjectController extends BaseController
{
    @Autowired
    private IQmsCheckProjectService qmsCheckProjectService;

    /**
     * 查询检验项目列表
     */
    @RequiresPermissions("qms:checkproject:list")
    @GetMapping("/list")
    public TableDataInfo list(QmsCheckProject qmsCheckProject)
    {
        startPage();
        List<QmsCheckProject> list = qmsCheckProjectService.selectQmsCheckProjectList(qmsCheckProject);
        return getDataTable(list);
    }

    /**
     * 导出检验项目列表
     */
    @RequiresPermissions("qms:checkproject:export")
    @Log(title = "检验项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QmsCheckProject qmsCheckProject)
    {
        List<QmsCheckProject> list = qmsCheckProjectService.selectQmsCheckProjectList(qmsCheckProject);
        ExcelUtil<QmsCheckProject> util = new ExcelUtil<QmsCheckProject>(QmsCheckProject.class);
        util.exportExcel(response, list, "检验项目数据");
    }

    /**
     * 获取检验项目详细信息
     */
    @RequiresPermissions("qms:checkproject:query")
    @GetMapping(value = "/{checkProjectId}")
    public AjaxResult getInfo(@PathVariable("checkProjectId") Long checkProjectId)
    {
        return success(qmsCheckProjectService.selectQmsCheckProjectByCheckProjectId(checkProjectId));
    }

    /**
     * 新增检验项目
     */
    @RequiresPermissions("qms:checkproject:add")
    @Log(title = "检验项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QmsCheckProject qmsCheckProject)
    {
        return toAjax(qmsCheckProjectService.insertQmsCheckProject(qmsCheckProject));
    }

    /**
     * 修改检验项目
     */
    @RequiresPermissions("qms:checkproject:edit")
    @Log(title = "检验项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QmsCheckProject qmsCheckProject)
    {
        return toAjax(qmsCheckProjectService.updateQmsCheckProject(qmsCheckProject));
    }

    /**
     * 删除检验项目
     */
    @RequiresPermissions("qms:checkproject:remove")
    @Log(title = "检验项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkProjectIds}")
    public AjaxResult remove(@PathVariable Long[] checkProjectIds)
    {
        return toAjax(qmsCheckProjectService.deleteQmsCheckProjectByCheckProjectIds(checkProjectIds));
    }
}
