package com.ruoyi.web.controller.system;

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

import com.ruoyi.common.constant.UserConstants;
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.ruoyi.system.domain.InspectInfor;
import com.ruoyi.system.service.IInspectInforService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 送检信息Controller
 * 
 * @author boman
 * @date 2021-12-27
 */
@RestController
@RequestMapping("/system/inspectInfor")
public class InspectInforController extends BaseController
{
    @Autowired
    private IInspectInforService inspectInforService;

    /**
     * 查询送检信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectInfor inspectInfor)
    {
        startPage();
        List<InspectInfor> list = inspectInforService.selectInspectInforList(inspectInfor);
        return getDataTable(list);
    }

    /**
     * 导出送检信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:export')")
    @Log(title = "送检信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectInfor inspectInfor)
    {
        List<InspectInfor> list = inspectInforService.selectInspectInforList(inspectInfor);
        ExcelUtil<InspectInfor> util = new ExcelUtil<InspectInfor>(InspectInfor.class);
        util.exportExcel(response, list, "送检信息数据");
    }

    /**
     * 获取送检信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:query')")
    @GetMapping(value = "/{inspectId}")
    public AjaxResult getInfo(@PathVariable("inspectId") Long inspectId)
    {
        return AjaxResult.success(inspectInforService.selectInspectInforByInspectId(inspectId));
    }

    /**
     * 新增送检信息
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:add')")
    @Log(title = "送检信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectInfor inspectInfor)
    {
/*        if (UserConstants.NOT_UNIQUE.equals(inspectInforService.checkSampleNameUnique(inspectInfor)))
        {
            return AjaxResult.error("新增样品名称'" + inspectInfor.getSampleName() + "'失败，样品名称已存在");
        }*/
        return toAjax(inspectInforService.insertInspectInfor(inspectInfor));
    }

    /**
     * 修改送检信息
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:edit')")
    @Log(title = "送检信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectInfor inspectInfor)
    {
/*        if (UserConstants.NOT_UNIQUE.equals(inspectInforService.checkSampleNameUnique(inspectInfor)))
        {
            return AjaxResult.error("修改样品名称'" + inspectInfor.getSampleName() + "'失败，样品名称已存在");
        }*/
        return toAjax(inspectInforService.updateInspectInfor(inspectInfor));
    }

    /**
     * 删除送检信息
     */
    @PreAuthorize("@ss.hasPermi('system:inspectInfor:remove')")
    @Log(title = "送检信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectIds}")
    public AjaxResult remove(@PathVariable Long[] inspectIds)
    {
        return toAjax(inspectInforService.deleteInspectInforByInspectIds(inspectIds));
    }
}
