package com.ruoyi.web.controller.app;

import java.util.List;

import com.ruoyi.app.DTO.HookBindDetailDTO;
import com.ruoyi.app.DTO.PorkSideProduceDTO;
import com.ruoyi.app.model.request.AddPorkSideProduce;
import com.ruoyi.app.model.request.ReqGetPorkSideProduce;
import com.ruoyi.app.service.IHookBindService;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.PorkSideProduce;
import com.ruoyi.app.service.IPorkSideProduceService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 白条生产记录Controller
 * 
 * @author coede
 * @date 2025-03-19
 */
@Api("白条生产记录信息管理")
@RestController
@RequestMapping("/app/porkSideProduce")
public class PorkSideProduceController extends BaseController
{
    @Autowired
    private IPorkSideProduceService porkSideProduceService;

    @Autowired
    private IHookBindService hookBindService;

    /**
     * 查询白条生产记录列表
     */
    @ApiOperation("查询白条生产记录列表")
    @PreAuthorize("@ss.hasPermi('app:porkSideProduce:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReqGetPorkSideProduce req)
    {
        startPage();
        List<PorkSideProduceDTO> list = porkSideProduceService.selectPorkSideProduceList(req);
        return getDataTable(list);
    }

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

    /**
     * 新增白条生产记录
     */
    @ApiOperation("新增白条生产记录")
    @PreAuthorize("@ss.hasPermi('app:porkSideProduce:add')")
    @Log(title = "白条生产记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AddPorkSideProduce req)
    {
        HookBindDetailDTO hookBind = hookBindService.selectHookBindDetail(req.getHookNo());

        PorkSideProduce porkSideProduce = new PorkSideProduce();
        porkSideProduce.setProductName(PorkSideProduce.DEFAULT_NAME);
        porkSideProduce.setProduceTime(DateUtils.getNowDate());
        porkSideProduce.setHookNo(req.getHookNo());
        porkSideProduce.setSlaughterCode(hookBind.getSlaughterCode());
        porkSideProduce.setDistributeBatchId(hookBind.getDistributeBatchId());
        porkSideProduce.setEntranceBatchId(hookBind.getEntranceBatchId());
        porkSideProduce.setCreateBy(getUsername());
        return toAjax(porkSideProduceService.insertPorkSideProduce(porkSideProduce));
    }

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

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