package com.fs.his.controller;

import java.util.List;

import com.fs.his.vo.FsMedicatedFoodExcelVO;
import com.fs.his.vo.FsMedicatedFoodLListVO;
import com.fs.his.vo.FsStoreProductExcelVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.his.domain.FsMedicatedFood;
import com.fs.his.service.IFsMedicatedFoodService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 药膳食疗Controller
 *
 * @author fs
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/his/medicatedFood")
public class FsMedicatedFoodController extends BaseController
{
    @Autowired
    private IFsMedicatedFoodService fsMedicatedFoodService;


    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsMedicatedFood> util = new ExcelUtil<>(FsMedicatedFood.class);
        return util.importTemplateExcel("导入模板");
    }


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsMedicatedFood> util = new ExcelUtil<>(FsMedicatedFood.class);
        List<FsMedicatedFood> list = util.importExcel(file.getInputStream());
        String message = fsMedicatedFoodService.importDataMedicatedFoodExcel(list, updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 查询药膳食疗列表
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsMedicatedFood fsMedicatedFood)
    {
        startPage();
        List<FsMedicatedFoodLListVO> list = fsMedicatedFoodService.selectFsMedicatedFoodListVO(fsMedicatedFood);
        return getDataTable(list);
    }

    /**
     * 导出药膳食疗列表
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:export')")
    @Log(title = "药膳食疗", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsMedicatedFood fsMedicatedFood)
    {
        List<FsMedicatedFood> list = fsMedicatedFoodService.selectFsMedicatedFoodList(fsMedicatedFood);
        ExcelUtil<FsMedicatedFood> util = new ExcelUtil<FsMedicatedFood>(FsMedicatedFood.class);
        return util.exportExcel(list, "药膳食疗数据");
    }

    /**
     * 获取药膳食疗详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsMedicatedFoodService.selectFsMedicatedFoodById(id));
    }

    /**
     * 新增药膳食疗
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:add')")
    @Log(title = "药膳食疗", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMedicatedFood fsMedicatedFood)
    {
        return toAjax(fsMedicatedFoodService.insertFsMedicatedFood(fsMedicatedFood));
    }

    /**
     * 修改药膳食疗
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:edit')")
    @Log(title = "药膳食疗", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsMedicatedFood fsMedicatedFood)
    {
        return toAjax(fsMedicatedFoodService.updateFsMedicatedFood(fsMedicatedFood));
    }

    /**
     * 删除药膳食疗
     */
    @PreAuthorize("@ss.hasPermi('his:medicatedFood:remove')")
    @Log(title = "药膳食疗", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsMedicatedFoodService.deleteFsMedicatedFoodByIds(ids));
    }
}
