package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.hospital.domain.HospitalPatient;
import com.fs.hospital.service.IHospitalPatientService;
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.hospital.domain.HospitalMember;
import com.fs.hospital.service.IHospitalMemberService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 诊所会员Controller
 *
 * @author fs
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/hospital/hospitalMember")
public class HospitalMemberController extends BaseController
{
    @Autowired
    private IHospitalMemberService hospitalMemberService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private IHospitalPatientService patientService;

    /**
     * 查询诊所会员列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalMember hospitalMember)
    {
        startPage();
        List<HospitalMember> list = hospitalMemberService.selectHospitalMemberList(hospitalMember);
        return getDataTable(list);
    }

    /**
     * 导出诊所会员列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:export')")
    @Log(title = "诊所会员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalMember hospitalMember)
    {
        List<HospitalMember> list = hospitalMemberService.selectHospitalMemberList(hospitalMember);
        ExcelUtil<HospitalMember> util = new ExcelUtil<HospitalMember>(HospitalMember.class);
        return util.exportExcel(list, "诊所会员数据");
    }

    /**
     * 获取诊所会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return AjaxResult.success(hospitalMemberService.selectHospitalMemberByMemberId(memberId));
    }

    /**
     * 新增诊所会员
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:add')")
    @Log(title = "诊所会员", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody HospitalMember hospitalMember)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalMember.setHospitalId(loginUser.getHospital().getHospitalId());
        return hospitalMemberService.insertHospitalMember(hospitalMember);
    }

    /**
     * 修改诊所会员
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:edit')")
    @Log(title = "诊所会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalMember hospitalMember)
    {
        return toAjax(hospitalMemberService.updateHospitalMember(hospitalMember));
    }

    /**
     * 删除诊所会员
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMember:remove')")
    @Log(title = "诊所会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(hospitalMemberService.deleteHospitalMemberByMemberIds(memberIds));
    }
}
