package com.ruoyi.web.controller.columns;

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

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.columns.YjHealthy;
import com.ruoyi.system.service.columns.IYjHealthyService;
import org.springframework.security.access.prepost.PreAuthorize;
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.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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健康饮食Controller
 * 
 * @author ruoyi
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/system/healthy")
public class YjHealthyController extends BaseController
{
    @Autowired
    private IYjHealthyService yjHealthyService;

    /**
     * 查询健康饮食列表
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjHealthy yjHealthy)
    {
        startPage();
        yjHealthy.setTenantId(SecurityUtils.getLoginUser().getNowTenantId());
        List<YjHealthy> list = yjHealthyService.selectYjHealthyList(yjHealthy);
        return getDataTable(list);
    }

    /**
     * 导出健康饮食列表
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:export')")
    @Log(title = "健康饮食", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjHealthy yjHealthy) throws IOException {
        List<YjHealthy> list = yjHealthyService.selectYjHealthyList(yjHealthy);
        ExcelUtil<YjHealthy> util = new ExcelUtil<YjHealthy>(YjHealthy.class);
        util.exportExcel(response, list, "健康饮食数据");
    }

    /**
     * 获取健康饮食详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(yjHealthyService.selectYjHealthyById(id));
    }

    /**
     * 新增健康饮食
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:add')")
    @Log(title = "健康饮食", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjHealthy yjHealthy)
    {
        yjHealthy.setId(IdWorker.get32UUID());
        return toAjax(yjHealthyService.insertYjHealthy(yjHealthy));
    }

    /**
     * 修改健康饮食
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:edit')")
    @Log(title = "健康饮食", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjHealthy yjHealthy)
    {
        return toAjax(yjHealthyService.updateYjHealthy(yjHealthy));
    }

    /**
     * 删除健康饮食
     */
    @PreAuthorize("@ss.hasPermi('system:healthy:remove')")
    @Log(title = "健康饮食", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(yjHealthyService.deleteYjHealthyByIds(ids));
    }
}
