package com.huiju.estateagents.controller;

import com.alibaba.fastjson.JSONObject;
import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.service.impl.ActivityManageServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 活动管理
 *
 * @author gusy
 * @date 2020/4/26 10:42
 */
@Controller
@RequestMapping("/api")
public class ActivityManageController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(ActivityManageController.class);

    @Autowired
    private ActivityManageServiceImpl activityManageService;

    /**
     * 根据类型获取统计数据
     *
     * @param type 报名活动:activity、
     *             H5:h5、
     *             助力:help、
     *             拼团:group、
     *             直播:live
     * @return
     */
    @RequestMapping(value = "/admin/activityManage/getStatisticData", method = RequestMethod.GET)
    @ResponseBody
    public ResponseBean getStatisticDataByType(String type, String id, HttpServletRequest request) {
        logger.info("getStatisticDataByType 接收参数：type：{}，id：{}", type, id);

        ResponseBean responseBean = new ResponseBean();

        // 校验参数
        if (StringUtils.isBlank(type) || StringUtils.isBlank(id)) {
            responseBean.addError("参数错误");
            return responseBean;
        }

        try {
            responseBean = activityManageService.getStatisticDataByType(type, id,getOrgId(request));
            logger.info("getStatisticDataByType 返回结果：{}", JSONObject.toJSONString(responseBean));
        } catch (Exception e) {
            logger.error("异常：", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }
}
