package io.renren.modules.app.controller;

import io.renren.common.utils.R;
import io.renren.modules.admin.entity.MeetingEntity;
import io.renren.modules.admin.entity.MoneyAccountEntity;
import io.renren.modules.admin.service.EmployeeService;
import io.renren.modules.admin.service.MeetingService;
import io.renren.modules.admin.service.MoneyAccountService;
import io.renren.modules.admin.entity.PaperRequireEntity;
import io.renren.modules.admin.service.PaperRequireService;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * APP测试接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/app/meeting")
public class AppMeetingController {
    @Autowired
    private MeetingService meetingService;

    @Autowired
    private MoneyAccountService moneyAccountService;
    @Autowired
    private PaperRequireService paperRequireService;
    @Autowired
    private EmployeeService employeeService;

    /**
     * 获取会议信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MeetingEntity meeting = meetingService.getById(id);

        return R.ok().put("meeting", meeting);
    }

    /**
     * 获取会议联系方式
     */
    @GetMapping("/contact/{id}")
    public R contact(@PathVariable("id") Long id) {
        MeetingEntity meeting = meetingService.getById(id);
        String contactIds = meeting.getContactIds();
        if(contactIds == null) {
            return R.ok().put("list", null);
        }

        List<Map<String, Object>> list = employeeService.getContact(contactIds);
        return R.ok().put("list", list);
    }


    /**
     * 会议提示
     */
    @GetMapping("/tips/{id}")
    public R tips(@PathVariable("id") Long id) {
        MeetingEntity meeting = meetingService.getById(id);
        // 线上报名截止时间
        Date onlineRegDeadline = meeting.getOnlineRegDeadline();
       
        // 现场报名截止时间
        Date onsiteRegDeadline = meeting.getOnsiteRegDeadline();
        
        PaperRequireEntity paperRequir = paperRequireService.getOneByMeetingId(id);
        // 征文截止时间
        Date paperDealine = paperRequir.getDeadline();

        return R.ok().put("onlineRegDeadline", onlineRegDeadline)
            .put("onsiteRegDeadline", onsiteRegDeadline).put("paperDealine", paperDealine);
    }

    /**
     * 根据meetingId信息获取对公账号
     * @param mid
     * @return
     */
    @GetMapping("/accountinfo/{mid}")
    public R infoByMid(@PathVariable("mid") Long mid){
		MoneyAccountEntity moneyAccount = moneyAccountService.getOneByMeetingId(mid);
        
        return R.ok().put("moneyAccount", moneyAccount);
    }

     /**
     * 根据meetingId信息获取投稿要求
     */
    @GetMapping("/paperrequireinfo/{mid}")
    public R paperrequireInfoByMid(@PathVariable("mid") Long mid) {
        PaperRequireEntity paperRequir = paperRequireService.getOneByMeetingId(mid);
        
        return R.ok().put("paperRequir", paperRequir);
    }
}
