package com.xinelu.manage.controller.patientinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.patientinfo.PatientInfo;
import com.xinelu.manage.dto.patientinfo.PatientInfoDto;
import com.xinelu.manage.service.patientinfo.IPatientInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 患者信息Controller
 *
 * @author haown
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/manage/patientInfo")
@Api(tags = "患者信息控制器")
public class PatientInfoController extends BaseController {
    @Resource
    private IPatientInfoService patientInfoService;

	/**
	 * 查询患者信息列表
	 */
	@ApiOperation("患者档案列表")
	@PreAuthorize("@ss.hasPermi('manage:patientInfo:list')")
	@GetMapping("/list")
    public TableDataInfo list(PatientInfoDto patientInfo) {
		// 根据用户权限判断查询数据权限
        startPage();
        List<PatientInfo> list = patientInfoService.selectPatientInfoList(patientInfo);
        return getDataTable(list);
    }

    /**
     * 导出患者信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:patientInfo:export')")
    @Log(title = "患者信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientInfoDto patientInfo) {
        List<PatientInfo> list = patientInfoService.selectPatientInfoList(patientInfo);
        ExcelUtil<PatientInfo> util = new ExcelUtil<PatientInfo>(PatientInfo. class);
        util.exportExcel(response, list, "患者信息数据");
    }

    /**
     * 获取患者信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:patientInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(patientInfoService.selectPatientInfoById(id));
    }

    /**
     * 新增患者信息
     */
    @PreAuthorize("@ss.hasPermi('manage:patientInfo:add')")
    @Log(title = "患者信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<PatientInfo> add(@RequestBody PatientInfo patientInfo) {
        return R.ok(patientInfoService.insertPatientInfo(patientInfo));
    }

    /**
     * 修改患者信息
     */
    @ApiOperation("修改患者信息")
    @PreAuthorize("@ss.hasPermi('manage:patientInfo:edit')")
    @Log(title = "患者信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<PatientInfo> edit(@RequestBody PatientInfo patientInfo) {
        return R.ok(patientInfoService.updatePatientInfo(patientInfo));
    }

    /**
     * 删除患者信息
     */
    @PreAuthorize("@ss.hasPermi('manage:patientInfo:remove')")
    @Log(title = "患者信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(patientInfoService.deletePatientInfoByIds(ids));
    }
}
