package com.fs.his.controller;

import java.util.List;

import com.fs.common.core.domain.model.LoginUser;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.web.service.TokenService;
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.FsPhysicalReportTemplate;
import com.fs.his.service.IFsPhysicalReportTemplateService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 体检报告模板Controller
 * 
 * @author fs
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/his/physicalReportTemplate")
public class FsPhysicalReportTemplateController extends BaseController
{
    @Autowired
    private IFsPhysicalReportTemplateService fsPhysicalReportTemplateService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询体检报告模板列表
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPhysicalReportTemplate fsPhysicalReportTemplate)
    {
        startPage();
        List<FsPhysicalReportTemplate> list = fsPhysicalReportTemplateService.selectFsPhysicalReportTemplateList(fsPhysicalReportTemplate);
        return getDataTable(list);
    }

    /**
     * 导出体检报告模板列表
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:export')")
    @Log(title = "体检报告模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPhysicalReportTemplate fsPhysicalReportTemplate)
    {
        List<FsPhysicalReportTemplate> list = fsPhysicalReportTemplateService.selectFsPhysicalReportTemplateList(fsPhysicalReportTemplate);
        ExcelUtil<FsPhysicalReportTemplate> util = new ExcelUtil<FsPhysicalReportTemplate>(FsPhysicalReportTemplate.class);
        return util.exportExcel(list, "体检报告模板数据");
    }

    /**
     * 获取体检报告模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(fsPhysicalReportTemplateService.selectFsPhysicalReportTemplateById(id));
    }

    /**
     * 新增体检报告模板
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:add')")
    @Log(title = "体检报告模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPhysicalReportTemplate fsPhysicalReportTemplate)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsPhysicalReportTemplate.setCreateBy(String.valueOf(loginUser.getUserId()));
        return toAjax(fsPhysicalReportTemplateService.insertFsPhysicalReportTemplate(fsPhysicalReportTemplate));
    }

    /**
     * 修改体检报告模板
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:edit')")
    @Log(title = "体检报告模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPhysicalReportTemplate fsPhysicalReportTemplate)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsPhysicalReportTemplate.setUpdateBy(String.valueOf(loginUser.getUserId()));
        return toAjax(fsPhysicalReportTemplateService.updateFsPhysicalReportTemplate(fsPhysicalReportTemplate));
    }

    /**
     * 删除体检报告模板
     */
    @PreAuthorize("@ss.hasPermi('his:physicalReportTemplate:remove')")
    @Log(title = "体检报告模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(fsPhysicalReportTemplateService.deleteFsPhysicalReportTemplateByIds(ids));
    }
}
