package com.ruoyi.os.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.os.domain.PatientInsuranceInfo;
import com.ruoyi.os.service.IPatientInsuranceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 患者医保信息Controller
 * 
 * @author 陈冠元
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/os/insurance")
public class PatientInsuranceInfoController extends BaseController
{
    @Autowired
    private IPatientInsuranceInfoService patientInsuranceInfoService;

    /**
     * 查询患者医保信息列表
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatientInsuranceInfo patientInsuranceInfo)
    {
        startPage();
        List<PatientInsuranceInfo> list = patientInsuranceInfoService.selectPatientInsuranceInfoList(patientInsuranceInfo);
        return getDataTable(list);
    }

    /**
     * 导出患者医保信息列表
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:export')")
    @Log(title = "患者医保信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientInsuranceInfo patientInsuranceInfo)
    {
        List<PatientInsuranceInfo> list = patientInsuranceInfoService.selectPatientInsuranceInfoList(patientInsuranceInfo);
        ExcelUtil<PatientInsuranceInfo> util = new ExcelUtil<PatientInsuranceInfo>(PatientInsuranceInfo.class);
        util.exportExcel(response, list, "患者医保信息数据");
    }

    /**
     * Excel表批量导入患者医保信息列表
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:add')")
    @Log(title = "患者医保信息", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult excelImport(MultipartFile file) throws Exception
    {
        ExcelUtil<PatientInsuranceInfo> util = new ExcelUtil<PatientInsuranceInfo>(PatientInsuranceInfo.class);
        List<PatientInsuranceInfo> insurancelist = util.importExcel(file.getInputStream());
        return toAjax(patientInsuranceInfoService.insertPatientInsuranceInfos(insurancelist));
    }


    /**
     * 获取患者医保信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patientInsuranceInfoService.selectPatientInsuranceInfoById(id));
    }

    /**
     * 新增患者医保信息
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:add')")
    @Log(title = "患者医保信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatientInsuranceInfo patientInsuranceInfo)
    {
        return toAjax(patientInsuranceInfoService.insertPatientInsuranceInfo(patientInsuranceInfo));
    }

    /**
     * 修改患者医保信息
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:edit')")
    @Log(title = "患者医保信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatientInsuranceInfo patientInsuranceInfo)
    {
        return toAjax(patientInsuranceInfoService.updatePatientInsuranceInfo(patientInsuranceInfo));
    }

    /**
     * 删除患者医保信息
     */
    @PreAuthorize("@ss.hasPermi('os:insurance:remove')")
    @Log(title = "患者医保信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patientInsuranceInfoService.deletePatientInsuranceInfoByIds(ids));
    }
}
