package com.fs.app.controller;

import java.util.List;

import com.fs.app.annotation.Login;
import com.fs.common.utils.StringUtils;
import com.fs.his.domain.FsUserInvited;
import com.fs.his.service.IFsUserInvitedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fs.common.annotation.Log;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 用户填写邀请码记录Controller
 *
 * @author fs
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/app/invited")
public class UserInvitedController extends AppBaseController {
    @Autowired
    private IFsUserInvitedService fsUserInvitedService;

    /**
     * 查询用户填写邀请码记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsUserInvited fsUserInvited)
    {
        startPage();
        List<FsUserInvited> list = fsUserInvitedService.selectFsUserInvitedList(fsUserInvited);
        return getDataTable(list);
    }

    /**
     * 导出用户填写邀请码记录列表
     */
    @Log(title = "用户填写邀请码记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserInvited fsUserInvited)
    {
        List<FsUserInvited> list = fsUserInvitedService.selectFsUserInvitedList(fsUserInvited);
        ExcelUtil<FsUserInvited> util = new ExcelUtil<FsUserInvited>(FsUserInvited.class);
        return util.exportExcel(list, "用户填写邀请码记录数据");
    }

    /**
     * 获取用户填写邀请码记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserInvitedService.selectFsUserInvitedById(id));
    }

    /**
     * 用户填写邀请码记录
     */
    @Login
    @PostMapping
    public AjaxResult fillInvCode(@RequestBody FsUserInvited fsUserInvited)
    {
        //邀请码不能为空
        if (fsUserInvited.getUserId() == null){
            return AjaxResult.error("邀请码不能为空");
        }
        //添加被邀请人id
        String userId = getUserId();
        if (StringUtils.isBlank(userId)){
            return AjaxResult.error("请先登录");
        }
        fsUserInvited.setInvitedUserId(Long.valueOf(userId));
        return fsUserInvitedService.fillInvCode(fsUserInvited);
    }

    /**
     * 生成下载海报 返回海报地址
     */
    @GetMapping("/getDownloadPoster")
    public AjaxResult getDownloadPoster()
    {
        return AjaxResult.success(fsUserInvitedService.getDownloadPoster());
    }
}
