package com.fs.his.controller;

import java.util.List;

import com.fs.common.utils.SecurityUtils;
import com.fs.his.param.FsHealthRecordListParam;
import com.fs.his.param.FsHealthRecordParam;
import com.fs.his.vo.FsHealthRecordListPVO;
import com.fs.his.vo.FsHealthRecordListVO;
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.FsHealthRecord;
import com.fs.his.service.IFsHealthRecordService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 健康档案Controller
 *
 * @author fs
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/his/healthRecord")
public class FsHealthRecordController extends BaseController
{
    @Autowired
    private IFsHealthRecordService fsHealthRecordService;

    /**
     * 查询健康档案列表
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsHealthRecordListParam fsHealthRecord)
    {
        startPage();
        List<FsHealthRecordListPVO> list = fsHealthRecordService.selectFsHealthRecordListVO(fsHealthRecord);
        return getDataTable(list);
    }

    /**
     * 导出健康档案列表
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:export')")
    @Log(title = "健康档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsHealthRecord fsHealthRecord)
    {
        logger.info("tc>\n【健康档案】：{}", SecurityUtils.getUserId());
        List<FsHealthRecord> list = fsHealthRecordService.selectFsHealthRecordList(fsHealthRecord);
        ExcelUtil<FsHealthRecord> util = new ExcelUtil<FsHealthRecord>(FsHealthRecord.class);
        return util.exportExcel(list, "健康档案数据");
    }

    /**
     * 获取健康档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsHealthRecordService.selectFsHealthRecordById(id));
    }

    /**
     * 新增健康档案
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:add')")
    @Log(title = "健康档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsHealthRecord fsHealthRecord)
    {
        return toAjax(fsHealthRecordService.insertFsHealthRecord(fsHealthRecord));
    }

    /**
     * 修改健康档案
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:edit')")
    @Log(title = "健康档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsHealthRecord fsHealthRecord)
    {
        return toAjax(fsHealthRecordService.updateFsHealthRecord(fsHealthRecord));
    }

    /**
     * 删除健康档案
     */
    @PreAuthorize("@ss.hasPermi('his:healthRecord:remove')")
    @Log(title = "健康档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsHealthRecordService.deleteFsHealthRecordByIds(ids));
    }
}
