package com.fs.his.controller;

import java.util.List;

import com.fs.his.vo.FsChineseMedicineListVO;
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.FsChineseMedicine;
import com.fs.his.service.IFsChineseMedicineService;
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/chineseMedicine")
public class FsChineseMedicineController extends BaseController
{
    @Autowired
    private IFsChineseMedicineService fsChineseMedicineService;

    /**
     * 查询中药科普管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsChineseMedicine fsChineseMedicine)
    {
        startPage();
        List<FsChineseMedicineListVO> list = fsChineseMedicineService.selectFsChineseMedicineListVO(fsChineseMedicine);
        return getDataTable(list);
    }
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsChineseMedicine> util = new ExcelUtil<>(FsChineseMedicine.class);
        return util.importTemplateExcel("导入模板");
    }


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsChineseMedicine> util = new ExcelUtil<>(FsChineseMedicine.class);
        List<FsChineseMedicine> list = util.importExcel(file.getInputStream());
        String message = fsChineseMedicineService.importData(list);
        return AjaxResult.success(message);
    }
    /**
     * 导出中药科普管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:export')")
    @Log(title = "中药科普管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsChineseMedicine fsChineseMedicine)
    {
        List<FsChineseMedicine> list = fsChineseMedicineService.selectFsChineseMedicineList(fsChineseMedicine);
        ExcelUtil<FsChineseMedicine> util = new ExcelUtil<FsChineseMedicine>(FsChineseMedicine.class);
        return util.exportExcel(list, "中药科普管理数据");
    }

    /**
     * 获取中药科普管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsChineseMedicineService.selectFsChineseMedicineById(id));
    }

    /**
     * 新增中药科普管理
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:add')")
    @Log(title = "中药科普管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsChineseMedicine fsChineseMedicine)
    {
        return toAjax(fsChineseMedicineService.insertFsChineseMedicine(fsChineseMedicine));
    }

    /**
     * 修改中药科普管理
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:edit')")
    @Log(title = "中药科普管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsChineseMedicine fsChineseMedicine)
    {
        return toAjax(fsChineseMedicineService.updateFsChineseMedicine(fsChineseMedicine));
    }

    /**
     * 删除中药科普管理
     */
    @PreAuthorize("@ss.hasPermi('his:chineseMedicine:remove')")
    @Log(title = "中药科普管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsChineseMedicineService.deleteFsChineseMedicineByIds(ids));
    }
}
