package com.fs.store.controller;

import com.fs.common.BeanCopyUtils;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsFamousPrescribe;
import com.fs.store.service.IFsFamousPrescribeService;
import com.fs.store.vo.FsFamousPrescribeExecelVO;
import com.fs.store.vo.FsFamousPrescribeListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 经典名方Controller
 *
 * @author fs
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/his/famousPrescribe")
public class FsFamousPrescribeController extends BaseController
{
    @Autowired
    private IFsFamousPrescribeService fsFamousPrescribeService;

    /**
     * 查询经典名方列表
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsFamousPrescribe fsFamousPrescribe)
    {
        startPage();
        List<FsFamousPrescribeListVO> list = fsFamousPrescribeService.selectFsFamousPrescribeListVO(fsFamousPrescribe);
        return getDataTable(list);
    }
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsFamousPrescribeExecelVO> util = new ExcelUtil<>(FsFamousPrescribeExecelVO.class);
        return util.importTemplateExcel("导入模板");
    }


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsFamousPrescribeExecelVO> util = new ExcelUtil<>(FsFamousPrescribeExecelVO.class);
        List<FsFamousPrescribeExecelVO> list = util.importExcel(file.getInputStream());
        System.out.println(list);
        String message = fsFamousPrescribeService.importData(list);
        return AjaxResult.success(message);
    }

    /**
     * 导出经典名方列表
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:export')")
    @Log(title = "经典名方", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsFamousPrescribe fsFamousPrescribe)
    {
        List<FsFamousPrescribe> list = fsFamousPrescribeService.selectFsFamousPrescribeList(fsFamousPrescribe);
        List<FsFamousPrescribeExecelVO> fsFamousPrescribes = BeanCopyUtils.copyList(list, FsFamousPrescribeExecelVO.class);
        ExcelUtil<FsFamousPrescribeExecelVO> util = new ExcelUtil<FsFamousPrescribeExecelVO>(FsFamousPrescribeExecelVO.class);
        return util.exportExcel(fsFamousPrescribes, "经典名方数据");
    }

    /**
     * 获取经典名方详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsFamousPrescribeService.selectFsFamousPrescribeById(id));
    }

    /**
     * 新增经典名方
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:add')")
    @Log(title = "经典名方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsFamousPrescribe fsFamousPrescribe)
    {
        return toAjax(fsFamousPrescribeService.insertFsFamousPrescribe(fsFamousPrescribe));
    }

    /**
     * 修改经典名方
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:edit')")
    @Log(title = "经典名方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsFamousPrescribe fsFamousPrescribe)
    {
        return toAjax(fsFamousPrescribeService.updateFsFamousPrescribe(fsFamousPrescribe));
    }

    /**
     * 删除经典名方
     */
    @PreAuthorize("@ss.hasPermi('his:famousPrescribe:remove')")
    @Log(title = "经典名方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsFamousPrescribeService.deleteFsFamousPrescribeByIds(ids));
    }
}
