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

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bonus.canteen.core.cook.vo.NutritionTypeVO;
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.CookNutritionType;
import com.bonus.canteen.core.cook.service.ICookNutritionTypeService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;

/**
 * 食材营养基础类型Controller
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Api(tags = "食材营养基础类型接口")
@RestController
@RequestMapping("/cook_nutrition_type")
public class CookNutritionTypeController extends BaseController {
    @Autowired
    private ICookNutritionTypeService cookNutritionTypeService;

    /**
     * 查询食材营养基础类型列表
     */
    @ApiOperation(value = "查询食材营养基础类型列表")
    @GetMapping("/list")
    public AjaxResult list(CookNutritionType cookNutritionType) {
        List<CookNutritionType> list = cookNutritionTypeService.selectCookNutritionTypeList(cookNutritionType);
        return AjaxResult.success(list);
    }

    /**
     * 导出食材营养基础类型列表
     */
    @ApiOperation(value = "导出食材营养基础类型列表")
    @SysLog(title = "食材营养基础类型", businessType = OperaType.EXPORT, logType = 1,module = "营养->导出食材营养基础类型")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CookNutritionType cookNutritionType) {
        List<CookNutritionType> list = cookNutritionTypeService.selectCookNutritionTypeList(cookNutritionType);
        ExcelUtil<CookNutritionType> util = new ExcelUtil<CookNutritionType>(CookNutritionType.class);
        util.exportExcel(response, list, "食材营养基础类型数据");
    }

    /**
     * 获取食材营养基础类型详细信息
     */
    @ApiOperation(value = "获取食材营养基础类型详细信息")
    @GetMapping(value = "/getInfo/{nutritionTypeId}")
    public AjaxResult getInfo(@PathVariable("nutritionTypeId") Long nutritionTypeId) {
        return success(cookNutritionTypeService.selectCookNutritionTypeByNutritionTypeId(nutritionTypeId));
    }

    /**
     * 新增食材营养基础类型
     */
    @ApiOperation(value = "新增食材营养基础类型")
    @SysLog(title = "食材营养基础类型", businessType = OperaType.INSERT, logType = 1,module = "营养->新增食材营养基础类型")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CookNutritionType cookNutritionType) {
        try {
            return toAjax(cookNutritionTypeService.insertCookNutritionType(cookNutritionType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改食材营养基础类型
     */
    @ApiOperation(value = "修改食材营养基础类型")
    @SysLog(title = "食材营养基础类型", businessType = OperaType.UPDATE, logType = 1,module = "营养->修改食材营养基础类型")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody CookNutritionType cookNutritionType) {
        try {
            return toAjax(cookNutritionTypeService.updateCookNutritionType(cookNutritionType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除食材营养基础类型
     */
    @ApiOperation(value = "删除食材营养基础类型")
    @SysLog(title = "食材营养基础类型", businessType = OperaType.DELETE, logType = 1,module = "营养->删除食材营养基础类型")
	@PostMapping("/del/{nutritionTypeIds}")
    public AjaxResult remove(@PathVariable Long[] nutritionTypeIds) {
        return toAjax(cookNutritionTypeService.deleteCookNutritionTypeByNutritionTypeIds(nutritionTypeIds));
    }


    @PostMapping({"/nutritionTypeList"})
    @ApiOperation("获取所有食材类别")
    @SysLog(title = "营养基础类型", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除营养基础类型")
    public AjaxResult getNutritionTypeList() {
        List<NutritionTypeVO> nutritionTypeList = this.cookNutritionTypeService.getNutritionTypeList();
        return AjaxResult.success(nutritionTypeList);
    }

}
