package com.ruoyi.web.controller.app;

import java.util.List;

import com.ruoyi.app.DTO.SlaughterBatchDTO;
import com.ruoyi.app.model.request.ReqSlaughterBatch;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.app.model.SlaughterBatch;
import com.ruoyi.app.service.ISlaughterBatchService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 屠宰批次Controller
 * 
 * @author coede
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/app/slaughterBatch")
public class SlaughterBatchController extends BaseController
{
    @Autowired
    private ISlaughterBatchService slaughterBatchService;

    /**
     * 查询屠宰批次列表
     */
    @PreAuthorize("@ss.hasPermi('app:slaughterBatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReqSlaughterBatch req)
    {
        startPage();
        List<SlaughterBatchDTO> list = slaughterBatchService.selectSlaughterBatchList(req);
        return getDataTable(list);
    }

    /**
     * 获取屠宰批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:slaughterBatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slaughterBatchService.selectSlaughterBatchById(id));
    }

    /**
     * 新增屠宰批次
     */
    @PreAuthorize("@ss.hasPermi('app:slaughterBatch:add')")
    @Log(title = "屠宰批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SlaughterBatch slaughterBatch)
    {
        slaughterBatch.setCreateBy(getUsername());
        return toAjax(slaughterBatchService.insertSlaughterBatch(slaughterBatch));
    }

    /**
     * 修改屠宰批次
     */
    @PreAuthorize("@ss.hasPermi('app:slaughterBatch:edit')")
    @Log(title = "屠宰批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated  @RequestBody SlaughterBatch slaughterBatch)
    {
        slaughterBatch.setUpdateBy(getUsername());
        return toAjax(slaughterBatchService.updateSlaughterBatch(slaughterBatch));
    }

    /**
     * 删除屠宰批次
     */
    @PreAuthorize("@ss.hasPermi('app:slaughterBatch:remove')")
    @Log(title = "屠宰批次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slaughterBatchService.deleteSlaughterBatchByIds(ids));
    }
}
