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

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

import com.bonus.canteen.core.menu.domain.MenuNutritionType;
import com.bonus.canteen.core.menu.dto.IntegerIds;
import com.bonus.canteen.core.menu.service.IMenuNutritionTypeService;
import com.bonus.canteen.core.menu.vo.NutritionTypeV2VO;
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.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-04-03
 */
@Api(tags = "营养基础类型接口")
@RestController
@RequestMapping("/menu_nutrition_type")
public class MenuNutritionTypeController extends BaseController {
    @Autowired
    private IMenuNutritionTypeService menuNutritionTypeService;

    /**
     * 查询营养基础类型列表
     */
    @ApiOperation(value = "查询营养基础类型列表")
    //@RequiresPermissions("menu:type:list")
    @GetMapping("/list")
    public TableDataInfo list(MenuNutritionType menuNutritionType) {
        startPage();
        List<MenuNutritionType> list = menuNutritionTypeService.selectMenuNutritionTypeList(menuNutritionType);
        return getDataTable(list);
    }

    /**
     * 导出营养基础类型列表
     */
    @ApiOperation(value = "导出营养基础类型列表")
    //@PreventRepeatSubmit
    //@RequiresPermissions("menu:type:export")
    @SysLog(title = "营养基础类型", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出营养基础类型")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuNutritionType menuNutritionType) {
        List<MenuNutritionType> list = menuNutritionTypeService.selectMenuNutritionTypeList(menuNutritionType);
        ExcelUtil<MenuNutritionType> util = new ExcelUtil<MenuNutritionType>(MenuNutritionType.class);
        util.exportExcel(response, list, "营养基础类型数据");
    }

    /**
     * 获取营养基础类型详细信息
     */
    @ApiOperation(value = "获取营养基础类型详细信息")
    //@RequiresPermissions("menu:type:query")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(menuNutritionTypeService.selectMenuNutritionTypeById(id));
    }

    /**
     * 新增营养基础类型
     */
    @ApiOperation(value = "新增营养基础类型")
    //@PreventRepeatSubmit
    //@RequiresPermissions("menu:type:add")
    @SysLog(title = "营养基础类型", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增营养基础类型")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MenuNutritionType menuNutritionType) {
        try {
            return toAjax(menuNutritionTypeService.insertMenuNutritionType(menuNutritionType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改营养基础类型
     */
    @ApiOperation(value = "修改营养基础类型")
    //@PreventRepeatSubmit
    //@RequiresPermissions("menu:type:edit")
    @SysLog(title = "营养基础类型", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改营养基础类型")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MenuNutritionType menuNutritionType) {
        try {
            return toAjax(menuNutritionTypeService.updateMenuNutritionType(menuNutritionType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除营养基础类型
     */
    @ApiOperation(value = "删除营养基础类型")
    //@PreventRepeatSubmit
    //@RequiresPermissions("menu:type:remove")
    @SysLog(title = "营养基础类型", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除营养基础类型")
	@PostMapping("/del")
    public AjaxResult remove(@RequestBody IntegerIds menuNutritionTypeDTO) {
        return toAjax(menuNutritionTypeService.deleteMenuNutritionTypeByIds(menuNutritionTypeDTO.getIds()));
    }

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




}
