package com.uas.platform.b2b.manage.controller;

import com.uas.platform.b2b.manage.controller.support.ResultBean;
import com.uas.platform.b2b.manage.model.Statistics;
import com.uas.platform.b2b.manage.model.UseType;
import com.uas.platform.b2b.manage.service.StatisticsService;
import com.uas.platform.b2b.manage.web.BaseController;
import com.uas.platform.core.util.AgentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据统计
 *
 * @author hejq
 * @date 2018-10-17 9:21
 */
@RequestMapping("/statistics")
@RestController
public class StatisticsController extends BaseController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 统计B2B企业注册信息
     *
     * @param groupType 分组形式
     * @param key 关键字
     * @return ResultBean
     */
    @RequestMapping(value = "/regist/enterprise", method = RequestMethod.GET)
    public ResultBean enterpriseCount(@RequestParam(value = "groupType", defaultValue = "year") String groupType, Integer... key) {
        List<Statistics> statistics = statisticsService.getEnterpriseCount(groupType, key);
        useLogService.appendLog(UseType.ENGERPRISE_REGISTER.code(), null, AgentUtils.getIp(request));
        return ResultBean.success(statistics, "B2B企业注册统计");
    }
}
