package com.fs.his.controller;

import java.util.List;

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.FsIcd;
import com.fs.his.service.IFsIcdService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * icd编码库Controller
 *
 * @author fs
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/his/icd")
public class FsIcdController extends BaseController
{
    @Autowired
    private IFsIcdService fsIcdService;

    /**
     * 查询icd编码库列表
     */
    @PreAuthorize("@ss.hasPermi('his:icd:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsIcd fsIcd)
    {
        startPage();
        List<FsIcd> list = fsIcdService.selectFsIcdList(fsIcd);
        return getDataTable(list);
    }

    /**
     * 导出icd编码库列表
     */
    @PreAuthorize("@ss.hasPermi('his:icd:export')")
    @Log(title = "icd编码库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsIcd fsIcd)
    {
        List<FsIcd> list = fsIcdService.selectFsIcdList(fsIcd);
        ExcelUtil<FsIcd> util = new ExcelUtil<FsIcd>(FsIcd.class);
        return util.exportExcel(list, "icd编码库数据");
    }

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


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


    /**
     * 获取icd编码库详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:icd:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsIcdService.selectFsIcdById(id));
    }


    @GetMapping(value = "/allIcd/{name}")
    public AjaxResult allIcd(@PathVariable("name") String name)
    {
        return AjaxResult.success(fsIcdService.selectFsIcdByName(name));
    }

    /**
     * 新增icd编码库
     */
    @PreAuthorize("@ss.hasPermi('his:icd:add')")
    @Log(title = "icd编码库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsIcd fsIcd)
    {
        return toAjax(fsIcdService.insertFsIcd(fsIcd));
    }

    /**
     * 修改icd编码库
     */
    @PreAuthorize("@ss.hasPermi('his:icd:edit')")
    @Log(title = "icd编码库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsIcd fsIcd)
    {
        return toAjax(fsIcdService.updateFsIcd(fsIcd));
    }

    /**
     * 删除icd编码库
     */
    @PreAuthorize("@ss.hasPermi('his:icd:remove')")
    @Log(title = "icd编码库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsIcdService.deleteFsIcdByIds(ids));
    }
}
