package com.ruoyi.web.controller.conference;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.conference.SysUserConference;
import com.ruoyi.system.service.conference.ISysUserConferenceService;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参会人员Controller
 *
 * @author boman
 * @date 2024-05-06
 */
@RestController
@RequestMapping("/conference")
public class SysUserConferenceController extends BaseController {
    @Autowired
    private ISysUserConferenceService sysUserConferenceService;

    /**
     * 查询参会人员列表
     */
    @PreAuthorize("@ss.hasPermi('c:conference:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserConference sysUserConference) {
        startPage();
        List<SysUserConference> list = sysUserConferenceService.selectSysUserConferenceList(sysUserConference);
        return getDataTable(list);
    }

    /**
     * 按照时间分组
     */
    @PreAuthorize("@ss.hasPermi('c:conference:list:time')")
    @GetMapping("/app/time/list")
    public AjaxResult timeTist(SysUserConference sysUserConference) {
        return sysUserConferenceService.timeTist(sysUserConference);
    }

    /**
     * 按照时间分组
     */
    @PreAuthorize("@ss.hasPermi('c:conference:list:time')")
    @GetMapping("/pc/time/list")
    public AjaxResult pcTimeTist(SysUserConference sysUserConference) {
        return sysUserConferenceService.pcTimeTist(sysUserConference);
    }


    /**
     * 导出参会人员列表
     */
    @PreAuthorize("@ss.hasPermi('c:conference:export')")
    @Log(title = "参会人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserConference sysUserConference) {
        List<SysUserConference> list = sysUserConferenceService.selectSysUserConferenceList(sysUserConference);
        ExcelUtil<SysUserConference> util = new ExcelUtil<SysUserConference>(SysUserConference.class);
        util.exportExcel(response, list, "参会人员数据");
    }

    /**
     * 获取参会人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('c:conference:query')")
    @GetMapping(value = "/{conferenceId}")
    public AjaxResult getInfo(@PathVariable("conferenceId") Long conferenceId) {
        return success(sysUserConferenceService.selectSysUserConferenceByConferenceId(conferenceId));
    }

    /**
     * 新增参会人员
     */
    @PreAuthorize("@ss.hasPermi('c:conference:add')")
    @Log(title = "参会人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserConference sysUserConference) {
        return toAjax(sysUserConferenceService.insertSysUserConference(sysUserConference));
    }

    /**
     * 随机生成参会人员
     * loanApplicationId 贷款id
     */
    @PreAuthorize("@ss.hasPermi('c:conference:randomAdd')")
    @Log(title = "参会人员", businessType = BusinessType.INSERT)
    @PostMapping(value = "/random/five")
    public AjaxResult randomAdd(@RequestBody SysUserConference sysUserConference) {
        return sysUserConferenceService.randomAdd(sysUserConference);
    }

    /**
     * 修改参会人员
     */
    @PreAuthorize("@ss.hasPermi('c:conference:edit')")
    @Log(title = "参会人员", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody SysUserConference sysUserConference) {
        return toAjax(sysUserConferenceService.updateSysUserConference(sysUserConference));
    }

    /**
     * 投票
     */
    @PreAuthorize("@ss.hasPermi('c:conference:vote')")
    @Log(title = "参会人员", businessType = BusinessType.UPDATE)
    @PostMapping("/vote")
    public AjaxResult vote(@RequestBody SysUserConference sysUserConference) {
        return sysUserConferenceService.vote(sysUserConference);
    }

    /**
     * 管理员发起重新投票（最新一次的投票人员不变）
     */
    @PreAuthorize("@ss.hasPermi('c:conference:again')")
    @Log(title = "参会人员", businessType = BusinessType.UPDATE)
    @PostMapping("/again")
    public AjaxResult again(@RequestBody SysUserConference sysUserConference) {
        return sysUserConferenceService.again(sysUserConference);
    }

    /**
     * 董事长一票否决
     */
    @PreAuthorize("@ss.hasPermi('c:conference:finish')")
    @Log(title = "参会人员", businessType = BusinessType.UPDATE)
    @PostMapping("/finish")
    public AjaxResult finish(@RequestBody SysUserConference sysUserConference) {
        return sysUserConferenceService.finish(sysUserConference);
    }

    /**
     * 删除参会人员
     */
    @PreAuthorize("@ss.hasPermi('c:conference:remove')")
    @Log(title = "参会人员", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{conferenceIds}")
    public AjaxResult remove(@PathVariable Long[] conferenceIds) {
        return toAjax(sysUserConferenceService.deleteSysUserConferenceByConferenceIds(conferenceIds));
    }
}
