package org.dromara.web.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.web.domain.bo.HospitalMealRecipeBo;
import org.dromara.web.domain.vo.HospitalMealRecipeVo;
import org.dromara.web.service.IHospitalMealRecipeService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;

import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 院内膳食食谱明细
 *
 * @author Lion Li
 * @date 2025-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/patients/hospitalMealRecipe")
public class HospitalMealRecipeController extends BaseController {

    private final IHospitalMealRecipeService hospitalMealRecipeService;

    /**
     * 查询院内膳食食谱明细列表
     */
    @SaCheckPermission("patients:hospitalMealRecipe:list")
    @GetMapping("/list")
    public TableDataInfo<HospitalMealRecipeVo> list(HospitalMealRecipeBo bo, PageQuery pageQuery) {
        return hospitalMealRecipeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出院内膳食食谱明细列表
     */
    @SaCheckPermission("patients:hospitalMealRecipe:export")
    @Log(title = "院内膳食食谱明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HospitalMealRecipeBo bo, HttpServletResponse response) {
        List<HospitalMealRecipeVo> list = hospitalMealRecipeService.queryList(bo);
        ExcelUtil.exportExcel(list, "院内膳食食谱明细", HospitalMealRecipeVo.class, response);
    }

    /**
     * 获取院内膳食食谱明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("patients:hospitalMealRecipe:query")
    @GetMapping("/{id}")
    public R<HospitalMealRecipeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(hospitalMealRecipeService.queryById(id));
    }

    /**
     * 新增院内膳食食谱明细
     */
    @SaCheckPermission("patients:hospitalMealRecipe:add")
    @Log(title = "院内膳食食谱明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HospitalMealRecipeBo bo) {
        return toAjax(hospitalMealRecipeService.insertByBo(bo));
    }

    /**
     * 修改院内膳食食谱明细
     */
    @SaCheckPermission("patients:hospitalMealRecipe:edit")
    @Log(title = "院内膳食食谱明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HospitalMealRecipeBo bo) {
        return toAjax(hospitalMealRecipeService.updateByBo(bo));
    }

    /**
     * 删除院内膳食食谱明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("patients:hospitalMealRecipe:remove")
    @Log(title = "院内膳食食谱明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(hospitalMealRecipeService.deleteWithValidByIds(List.of(ids), true));
    }
}
