package com.rwk.web.controller.ability;

import java.util.List;
import com.rwk.common.utils.DateUtils;
import com.rwk.system.domain.RwkStaffInformation;
import com.rwk.system.service.IRwkStaffInformationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rwk.common.annotation.Log;
import com.rwk.common.enums.BusinessType;
import com.rwk.system.domain.RwkMeeting;
import com.rwk.system.service.IRwkMeetingService;
import com.rwk.common.core.controller.BaseController;
import com.rwk.common.core.domain.AjaxResult;
import com.rwk.common.utils.poi.ExcelUtil;
import com.rwk.common.core.page.TableDataInfo;

/**
 * 教育培训Controller
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@Controller
@RequestMapping("/system/meeting")
public class RwkMeetingController extends BaseController
{
    private String prefix = "system/meeting";

    @Autowired
    private IRwkMeetingService rwkMeetingService;

    @Autowired
    private IRwkStaffInformationService rwkStaffInformationService;

    @RequiresPermissions("system:meeting:view")
    @GetMapping()
    public String meeting()
    {
        return prefix + "/meeting";
    }

    /**
     * 查询教育培训列表
     */
    @RequiresPermissions("system:meeting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RwkMeeting rwkMeeting)
    {
        startPage();
        List<RwkMeeting> list = rwkMeetingService.selectRwkMeetingList(rwkMeeting);
        return getDataTable(list);
    }

    /**
     * 查看培训活动详情
     */
    @GetMapping("/meetingView/{id}")
    public String receiveView(@PathVariable("id") Long id, ModelMap mmap)
    {
        RwkMeeting rwkMeeting = rwkMeetingService.selectRwkMeetingById(id);
        mmap.put("rwkMeeting", rwkMeeting);
        return prefix + "/meetingView";
    }

    /**
     * 人员选择
     */
    @GetMapping("/userSelect")
    public String userSelect(ModelMap mmap)
    {
        getJoinPeople(mmap);
        return prefix + "/userSelect";
    }

    /**
     * 新增教育培训
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教育培训
     */
    @RequiresPermissions("system:meeting:add")
    @Log(title = "教育培训", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RwkMeeting rwkMeeting)
    {
        rwkMeeting.setCreateTime(DateUtils.getNowDate());
        rwkMeeting.setCreateBy(getSysUser().getLoginName());
        return toAjax(rwkMeetingService.insertRwkMeeting(rwkMeeting));
    }

    /**
     * 修改教育培训
     */
    @RequiresPermissions("system:meeting:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RwkMeeting rwkMeeting = rwkMeetingService.selectRwkMeetingById(id);
        mmap.put("rwkMeeting", rwkMeeting);
        return prefix + "/edit";
    }

    /**
     * 修改保存教育培训
     */
    @RequiresPermissions("system:meeting:edit")
    @Log(title = "教育培训", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RwkMeeting rwkMeeting)
    {
        return toAjax(rwkMeetingService.updateRwkMeeting(rwkMeeting));
    }

    /**
     * 删除教育培训
     */
    @RequiresPermissions("system:meeting:remove")
    @Log(title = "教育培训", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rwkMeetingService.deleteRwkMeetingByIds(ids));
    }

    /**
     * 导出教育培训列表
     */
    @RequiresPermissions("system:meeting:export")
    @Log(title = "教育培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RwkMeeting rwkMeeting)
    {
        List<RwkMeeting> list = rwkMeetingService.selectRwkMeetingList(rwkMeeting);
        ExcelUtil<RwkMeeting> util = new ExcelUtil<RwkMeeting>(RwkMeeting.class);
        return util.exportExcel(list, "教育培训数据");
    }

    //获取参与人员方法
    private void getJoinPeople(ModelMap mmap){
        //获取参与人员
        List<RwkStaffInformation> list = rwkStaffInformationService.selectRwkStaffInformationList(new RwkStaffInformation());
        mmap.put("userList", list);
    }
}
