package com.bonus.canteen.core.cook.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.canteen.core.cook.domain.CookMaterial;
import com.bonus.canteen.core.cook.service.ICookMaterialService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 原料信息Controller
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Api(tags = "原料信息接口")
@RestController
@RequestMapping("/cook_material")
public class CookMaterialController extends BaseController {
    @Autowired
    private ICookMaterialService cookMaterialService;

    /**
     * 查询原料信息列表
     */
    @ApiOperation(value = "查询原料信息列表")
    @GetMapping("/list")
    public TableDataInfo list(CookMaterial cookMaterial) {
        startPage();
        List<CookMaterial> list = cookMaterialService.selectCookMaterialList(cookMaterial);
        return getDataTable(list);
    }

    /**
     * 导出原料信息列表
     */
    @ApiOperation(value = "导出原料信息列表")
    @SysLog(title = "原料信息", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出原料信息")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CookMaterial cookMaterial) {
        List<CookMaterial> list = cookMaterialService.selectCookMaterialList(cookMaterial);
        ExcelUtil<CookMaterial> util = new ExcelUtil<CookMaterial>(CookMaterial.class);
        util.exportExcel(response, list, "原料信息数据");
    }

    /**
     * 获取原料信息详细信息
     */
    @ApiOperation(value = "获取原料信息详细信息")
    @GetMapping(value = "/getInfo/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId) {
        return success(cookMaterialService.selectCookMaterialByMaterialId(materialId));
    }

    /**
     * 新增原料信息
     */
    @ApiOperation(value = "新增原料信息")
    @SysLog(title = "原料信息", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增原料信息")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CookMaterial cookMaterial) {
        try {
            return toAjax(cookMaterialService.insertCookMaterial(cookMaterial));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改原料信息
     */
    @ApiOperation(value = "修改原料信息")
    @SysLog(title = "原料信息", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改原料信息")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody CookMaterial cookMaterial) {
        try {
            return toAjax(cookMaterialService.updateCookMaterial(cookMaterial));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除原料信息
     */
    @ApiOperation(value = "删除原料信息")
    @SysLog(title = "原料信息", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除原料信息")
	@PostMapping("/del/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds) {
        return toAjax(cookMaterialService.deleteCookMaterialByMaterialIds(materialIds));
    }
}
