package cn.com.oa.controller;

import cn.com.v2.common.base.BaseController;
import cn.com.oa.common.constant.DataService;
import cn.com.v2.common.domain.AjaxResult;
import cn.com.oa.model.Company;
import cn.com.oa.model.Group;
import cn.com.oa.service.IGroupService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/group")
public class GroupController extends BaseController {
    @Autowired
    private IGroupService groupService;

    @ApiOperation(value = "获取公司根部门数据", notes = "获取公司根部门数据")
    @GetMapping("/getDefaultGroup")
    @ResponseBody
    public AjaxResult getDefaultGroup()
    {
        Group group = groupService.getDefaultGroup();
        if(group!=null) {
            return AjaxResult.successData(200,group).put("msg","获取成功");
        }
        return AjaxResult.successData(200, null).put("msg","无数据");

    }

    @ApiOperation(value = "获取预设数据", notes = "获取预设数据")
    @GetMapping("/getDefaultData")
    @ResponseBody
    public AjaxResult getDefaultData()
    {
        Map constantData = DataService.getConstantData();
        //Company company = (Company)constantData.get("company");
        if(constantData!=null) {
            return AjaxResult.successData(200,constantData).put("msg","获取成功");
        }
        return AjaxResult.successData(200, null).put("msg","无数据");
    }

    @ApiOperation(value = "获取组织架构数据", notes = "获取组织架构数据")
    @GetMapping("/getOrgGroup")
    @ResponseBody
    public AjaxResult getOrgGroup()
    {
        Map constantData = DataService.getConstantData();
        //Company company = (Company)constantData.get("company");
        Group group = (Group)constantData.get("defaultGroup");
        Group orgGroup = groupService.buildOrgStructure(group.getUNIVERSALID());
        if(orgGroup!=null) {
            return AjaxResult.successData(200,orgGroup).put("msg","获取成功");
        }
        return AjaxResult.successData(200, null).put("msg","无数据");

    }
}
