package io.renren.modules.admin.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.admin.entity.OrganizationEntity;
import io.renren.modules.admin.service.AttendersService;
import io.renren.modules.admin.service.OrganizationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * VIEW
 *
 * @author huwhois
 * @email huwhois@gmail.com
 * @date 2020-07-08 09:32:07
 */
@RestController
@RequestMapping("admin/organization")
public class OrganizationController {
    @Autowired
    private OrganizationService organizationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:organization:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = organizationService.queryPage(params);

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

    /**
     * 单位历届参会统计
     */
    @GetMapping("/prelist")
    @RequiresPermissions("admin:organization:list")
    public R previousList(@RequestParam Map<String, Object> params){
        if (!params.containsKey("organization")) {
            return R.error("单位名称不可为空");
        }

        String organization = (String) params.get("organization");

        List<OrganizationEntity>  list= organizationService.previousList(organization);

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

    /**
     * 单位历届参会统计
     */
    @GetMapping("/attendlist")
    @RequiresPermissions("admin:organization:list")
    public R attendlist(@RequestParam Map<String, Object> params){
        if (!params.containsKey("organization")) {
            return R.error("单位名称不可为空");
        }

        PageUtils page= organizationService.attendList(params);

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