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 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.HospitalMemberRecharge;
import com.fs.hospital.service.IHospitalMemberRechargeService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 用户充值Controller
 *
 * @author fs
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/hospital/hospitalMemberRecharge")
public class HospitalMemberRechargeController extends BaseController
{
    @Autowired
    private IHospitalMemberRechargeService hospitalMemberRechargeService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询用户充值列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalMemberRecharge hospitalMemberRecharge)
    {
        startPage();
        List<HospitalMemberRecharge> list = hospitalMemberRechargeService.selectHospitalMemberRechargeList(hospitalMemberRecharge);
        return getDataTable(list);
    }

    /**
     * 导出用户充值列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:export')")
    @Log(title = "用户充值", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalMemberRecharge hospitalMemberRecharge)
    {
        List<HospitalMemberRecharge> list = hospitalMemberRechargeService.selectHospitalMemberRechargeList(hospitalMemberRecharge);
        ExcelUtil<HospitalMemberRecharge> util = new ExcelUtil<HospitalMemberRecharge>(HospitalMemberRecharge.class);
        return util.exportExcel(list, "用户充值数据");
    }

    /**
     * 获取用户充值详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:query')")
    @GetMapping(value = "/{rechargeId}")
    public AjaxResult getInfo(@PathVariable("rechargeId") Long rechargeId)
    {

        return AjaxResult.success(hospitalMemberRechargeService.selectHospitalMemberRechargeByRechargeId(rechargeId));
    }

    /**
     * 新增用户充值
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:add')")
    @Log(title = "用户充值", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody HospitalMemberRecharge hospitalMemberRecharge)
    {
        System.out.println(hospitalMemberRecharge);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalMemberRecharge.setHospitalId(loginUser.getHospital().getHospitalId());
        return hospitalMemberRechargeService.insertHospitalMemberRecharge(hospitalMemberRecharge);
    }

    /**
     * 修改用户充值
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:edit')")
    @Log(title = "用户充值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalMemberRecharge hospitalMemberRecharge)
    {
        return toAjax(hospitalMemberRechargeService.updateHospitalMemberRecharge(hospitalMemberRecharge));
    }

    /**
     * 删除用户充值
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberRecharge:remove')")
    @Log(title = "用户充值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rechargeIds}")
    public AjaxResult remove(@PathVariable Long[] rechargeIds)
    {
        return toAjax(hospitalMemberRechargeService.deleteHospitalMemberRechargeByRechargeIds(rechargeIds));
    }
}
