package com.cirle.scientific.controller.live;

import com.alibaba.fastjson.JSONObject;
import com.cirle.scientific.dao.QkjLiveDao;
import com.cirle.scientific.dto.QkjRecommendDTO;
import com.cirle.scientific.po.QkjLive;
import com.cirle.scientific.pojo.BizCodeEnum;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.LiveService;
import com.cirle.scientific.utils.DeviceUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/livecounter")
@Api("直播统计")
public class CounterController {


    @Autowired
    LiveService liveService;

    @Autowired
    private QkjLiveDao qkjLiveDao;

    @GetMapping("/getcounter")
    @ResponseBody
    @ApiOperation("获取当前学习人总数")
    public Result getcounter(String liveId) {

        JSONObject data = new JSONObject();
        //
        QkjLive live = liveService.getLiveInfo(Long.parseLong(liveId));
        if(live.getLiveType()==2){
            List<QkjLive> lives = qkjLiveDao.findSonList(live.getId().intValue(), 0, 100);
            List<Map> listmap = new ArrayList();
            for(QkjLive son : lives){
                Map map = new HashMap();
                map.put("liveId",son.getId());
                map.put("count",son.getPurchasedMembers());
                listmap.add(map);
            }
            data.put("children",listmap);
        }else{
            data.put("children",new ArrayList());
        }
        data.put("liveid", liveId);
        data.put("count", live.getPurchasedMembers());
        return Result.success(data);
    }


}
