package com.ruoyi.web.v1.controller;

import com.ruoyi.web.v1.DTO.PorkSideProduceRecordDTO;
import com.ruoyi.web.v1.model.PorkSideProduceRecord;
import com.ruoyi.web.v1.model.request.ReqGetPorkSideProduceRecord;
import com.ruoyi.web.v1.service.IPorkSideProduceRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 白条生产录入记录Controller
 * 
 * @author coede
 * @date 2025-05-09
 */
@Api("白条生产录入记录信息管理")
@RestController
@RequestMapping("/app/porkSideProduceRecord")
public class PorkSideProduceRecordController extends BaseController
{
    @Autowired
    private IPorkSideProduceRecordService PorkSideProduceRecordService;

    /**
     * 查询白条生产录入记录列表
     */
    @ApiOperation("查询白条生产录入记录列表")
    // @PreAuthorize("@ss.hasPermi('app:porkSideProduceRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReqGetPorkSideProduceRecord req)
    {
        startPage();
        List<PorkSideProduceRecordDTO> list = PorkSideProduceRecordService.selectPorkSideProduceRecordList(req);
        return getDataTable(list);
    }

    /**
     * 获取白条生产录入记录详细信息
     */
    @ApiOperation("获取白条生产录入记录详细信息")
    // @PreAuthorize("@ss.hasPermi('app:porkSideProduceRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(PorkSideProduceRecordService.selectPorkSideProduceRecordById(id));
    }

    /**
     * 新增白条生产录入记录
     */
    @ApiOperation("新增白条生产录入记录")
    // @PreAuthorize("@ss.hasPermi('app:porkSideProduceRecord:add')")
    @Log(title = "白条生产录入记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PorkSideProduceRecord req)
    {
        req.setProductName(PorkSideProduceRecord.DEFAULT_NAME);
        req.setProduceTime(DateUtils.getNowDate());
        req.setCreateBy(getUsername());
        return toAjax(PorkSideProduceRecordService.insertPorkSideProduceRecord(req));
    }

    /**
     * 修改白条生产录入记录
     */
    @ApiOperation("修改白条生产录入记录")
    // @PreAuthorize("@ss.hasPermi('app:porkSideProduceRecord:edit')")
    @Log(title = "白条生产录入记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PorkSideProduceRecord PorkSideProduceRecord)
    {
        PorkSideProduceRecord.setUpdateBy(getUsername());
        return toAjax(PorkSideProduceRecordService.updatePorkSideProduceRecord(PorkSideProduceRecord));
    }

    /**
     * 删除白条生产录入记录
     */
    @ApiOperation("删除白条生产录入记录")
    // @PreAuthorize("@ss.hasPermi('app:porkSideProduceRecord:remove')")
    @Log(title = "白条生产录入记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(PorkSideProduceRecordService.deletePorkSideProduceRecordByIds(ids));
    }
}
