package com.mirs.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.mirs.common.annotation.Log;
import com.mirs.common.core.controller.BaseController;
import com.mirs.common.core.domain.AjaxResult;
import com.mirs.common.enums.BusinessType;
import com.mirs.biz.domain.Sample;
import com.mirs.biz.service.ISampleService;
import com.mirs.common.utils.poi.ExcelUtil;
import com.mirs.common.core.page.TableDataInfo;

/**
 * 样片管理Controller
 * 
 * @author kk
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/manage/sample")
public class SampleController extends BaseController
{
    @Autowired
    private ISampleService sampleService;

    /**
     * 查询样片管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sample sample)
    {
        startPage();
        List<Sample> list = sampleService.selectSampleList(sample);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('manage:sample:list')")
    @GetMapping("/getOne")
    public Sample getOneBy(Sample sample)
    {
        return sampleService.getOne(sample);
    }

    /**
     * 导出样片管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:export')")
    @Log(title = "样片管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sample sample)
    {
        List<Sample> list = sampleService.selectSampleList(sample);
        ExcelUtil<Sample> util = new ExcelUtil<Sample>(Sample.class);
        util.exportExcel(response, list, "样片管理数据");
    }

    /**
     * 获取样片管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sampleService.selectSampleById(id));
    }

    /**
     * 新增样片管理
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:add')")
    @Log(title = "样片管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sample sample)
    {
        return toAjax(sampleService.insertSample(sample));
    }

    /**
     * 修改样片管理
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:edit')")
    @Log(title = "样片管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sample sample)
    {
        return toAjax(sampleService.updateSample(sample));
    }

    /**
     * 删除样片管理
     */
    @PreAuthorize("@ss.hasPermi('manage:sample:remove')")
    @Log(title = "样片管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sampleService.deleteSampleByIds(ids));
    }
}
