package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.framework.service.TokenService;
import com.fs.hospital.domain.HospitalUser;
import com.fs.hospital.vo.HospitalMemberIntegralLogsListHVO;
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.HospitalMemberIntegralLogs;
import com.fs.hospital.service.IHospitalMemberIntegralLogsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 积分记录Controller
 *
 * @author fs
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/hospital/hospitalMemberIntegralLogs")
public class HospitalMemberIntegralLogsController extends BaseController
{
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IHospitalMemberIntegralLogsService hospitalMemberIntegralLogsService;

    /**
     * 查询积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        startPage();
        List<HospitalMemberIntegralLogsListHVO> list = hospitalMemberIntegralLogsService.selectHospitalMemberIntegralLogsListPVO(hospitalMemberIntegralLogs);
        return getDataTable(list);
    }

    /**
     * 导出积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:export')")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        List<HospitalMemberIntegralLogs> list = hospitalMemberIntegralLogsService.selectHospitalMemberIntegralLogsList(hospitalMemberIntegralLogs);
        ExcelUtil<HospitalMemberIntegralLogs> util = new ExcelUtil<HospitalMemberIntegralLogs>(HospitalMemberIntegralLogs.class);
        return util.exportExcel(list, "积分记录数据");
    }

    /**
     * 获取积分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hospitalMemberIntegralLogsService.selectHospitalMemberIntegralLogsById(id));
    }

    /**
     * 新增积分记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        return toAjax(hospitalMemberIntegralLogsService.insertHospitalMemberIntegralLogs(hospitalMemberIntegralLogs));
    }

    /**
     * 修改积分记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        return toAjax(hospitalMemberIntegralLogsService.updateHospitalMemberIntegralLogs(hospitalMemberIntegralLogs));
    }


    @Log(title = "积分", businessType = BusinessType.UPDATE)
    @PutMapping("/add")
    public AjaxResult addIntegral(@RequestBody HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        HospitalUser user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        hospitalMemberIntegralLogs.setHospitalUserId(user.getUserId());
        hospitalMemberIntegralLogs.setHospitalId(user.getHospitalId());
        return toAjax(hospitalMemberIntegralLogsService.addHospitalMemberIntegral(hospitalMemberIntegralLogs));
    }

    @Log(title = "积分", businessType = BusinessType.UPDATE)
    @PutMapping("/sub")
    public AjaxResult subIntegral(@RequestBody HospitalMemberIntegralLogs hospitalMemberIntegralLogs)
    {
        HospitalUser user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        hospitalMemberIntegralLogs.setHospitalUserId(user.getUserId());
        hospitalMemberIntegralLogs.setHospitalId(user.getHospitalId());
        return toAjax(hospitalMemberIntegralLogsService.subHospitalMemberIntegral(hospitalMemberIntegralLogs));
    }


    /**
     * 删除积分记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalMemberIntegralLogs:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(hospitalMemberIntegralLogsService.deleteHospitalMemberIntegralLogsByIds(ids));
    }
}
