package com.zhyc.module.feed.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.module.feed.domain.SgFormulaList;
import com.zhyc.module.feed.service.ISgFormulaListService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 配方列表Controller
 * 
 * @author HashMap
 * @date 2025-08-09
 */
@RestController
@RequestMapping("/feed/FormulaList")
public class SgFormulaListController extends BaseController
{
    private final ISgFormulaListService sgFormulaListService;

    public SgFormulaListController(ISgFormulaListService sgFormulaListService) {
        this.sgFormulaListService = sgFormulaListService;
    }

    /**
     * 查询配方列表列表
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:list')")
    @GetMapping("/list")
    public TableDataInfo list(SgFormulaList sgFormulaList)
    {
        startPage();
        List<SgFormulaList> list = sgFormulaListService.selectSgFormulaListList(sgFormulaList);
        return getDataTable(list);
    }

    /**
     * 导出配方列表列表
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:export')")
    @Log(title = "配方列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SgFormulaList sgFormulaList)
    {
        List<SgFormulaList> list = sgFormulaListService.selectSgFormulaListList(sgFormulaList);
        ExcelUtil<SgFormulaList> util = new ExcelUtil<>(SgFormulaList.class);
        util.exportExcel(response, list, "配方列表数据");
    }

    /**
     * 获取配方列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") Long code)
    {
        return success(sgFormulaListService.selectSgFormulaListByCode(code));
    }

    /**
     * 新增配方列表
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:add')")
    @Log(title = "配方列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SgFormulaList sgFormulaList)
    {
        sgFormulaList.setUserId(getUserId());
        sgFormulaList.setDeptId(getDeptId());
        return toAjax(sgFormulaListService.insertSgFormulaList(sgFormulaList));
    }

    /**
     * 修改配方列表
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:edit')")
    @Log(title = "配方列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SgFormulaList sgFormulaList)
    {
        return toAjax(sgFormulaListService.updateSgFormulaList(sgFormulaList));
    }

    /**
     * 删除配方列表
     */
    @PreAuthorize("@ss.hasPermi('feed:FormulaList:remove')")
    @Log(title = "配方列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable Long[] codes)
    {
        return toAjax(sgFormulaListService.deleteSgFormulaListByCodes(codes));
    }
}
