package com.xinelu.manage.controller.basedietinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.basedietinfo.BaseDietInfo;
import com.xinelu.manage.service.basedietinfo.IBaseDietInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 饮食知识库Controller
 *
 * @author xinelu
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/system/baseDiet")
public class BaseDietInfoController extends BaseController {
    @Resource
    private IBaseDietInfoService baseDietInfoService;

    /**
     * 查询饮食知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseDietInfo baseDietInfo) {
        startPage();
        List<BaseDietInfo> list = baseDietInfoService.selectBaseDietInfoList(baseDietInfo);
        return getDataTable(list);
    }

    /**
     * 导出饮食知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:export')")
    @Log(title = "饮食知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDietInfo baseDietInfo) {
        List<BaseDietInfo> list = baseDietInfoService.selectBaseDietInfoList(baseDietInfo);
        ExcelUtil<BaseDietInfo> util = new ExcelUtil<>(BaseDietInfo.class);
        util.exportExcel(response, list, "饮食知识库数据");
    }

    /**
     * 获取饮食知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(baseDietInfoService.selectBaseDietInfoById(id));
    }

    /**
     * 新增饮食知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:add')")
    @Log(title = "饮食知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseDietInfo baseDietInfo) {
        return toAjax(baseDietInfoService.insertBaseDietInfo(baseDietInfo));
    }

    /**
     * 修改饮食知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:edit')")
    @Log(title = "饮食知识库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BaseDietInfo baseDietInfo) {
        return toAjax(baseDietInfoService.updateBaseDietInfo(baseDietInfo));
    }

    /**
     * 删除饮食知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseDiet:remove')")
    @Log(title = "饮食知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseDietInfoService.deleteBaseDietInfoByIds(ids));
    }
}
