package com.hotent.uc.controller;


import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.model.CommonResult;
import com.hotent.uc.manager.DingApiManager;
import com.hotent.uc.manager.DingUserManager;
import com.hotent.uc.model.OrgExternalDept;
import com.hotent.uc.model.OrgExternalUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 调用钉钉组织机构接口 接口控制器
 *
 * @company 广州宏天软件股份有限公司
 * @author pangquan
 * @since 2020-10-30
 */
@RestController
@RequestMapping("/uc/orgExtUser/v1/")
@Api(tags="组织外部系统参数配置")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class OrgExternalUserController extends BaseController<DingUserManager, OrgExternalUser> {
	@Autowired
	private DingUserManager dingUserManager;


	@RequestMapping(value = "dingApi/queryUserComplex", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据组织id获取组织", httpMethod = "GET", notes = "根据组织id获取组织")
	public CommonResult<IPage<List<Map<String, Object>>>>  queryUserComplex(@ApiParam(name = "pageSize", value = "每页条数") @RequestParam(value="pageSize",required = true) Long pageSize,
																			@ApiParam(name = "pageNo", value = "当前页", required = true) @RequestParam(value="pageNo",required = true) Long pageNo,
																			@ApiParam(name = "type", value = "匹配与未匹配", required = true) @RequestParam(value="type",required = true) String type,
																			@ApiParam(name = "userName", value = "用户姓名", required = false) @RequestParam String userName,
																			@ApiParam(name = "mobile", value = "手机号", required = false) @RequestParam String mobile,
																			@ApiParam(name = "orgId", value = "组织id", required = true) @RequestParam(value="orgId",required = true)  String orgId,
																			@ApiParam(name = "extDeptId", value = "钉钉部门id", required = true) @RequestParam(value="extDeptId",required = true)  String extDeptId) {
		Page page = new Page(pageNo, pageSize);
		IPage<List<Map<String, Object>>>  list=dingUserManager.queryUserComplex(page,type,userName,mobile,orgId,extDeptId);
		return new CommonResult<IPage<List<Map<String, Object>>>>(true, "查询成功！", list);
	}


	@RequestMapping(value = "dingApi/queryExtUserInfo", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据组织id获取组织", httpMethod = "GET", notes = "根据组织id获取组织")
	public CommonResult<Map<String,Object>>  queryExtUserInfo(@ApiParam(name = "extUserId", value = "钉钉userid") @RequestParam(value="extUserId",required = true) String extUserId,
																			@ApiParam(name = "orgId", value = "部门") @RequestParam(value="orgId",required = false) String orgId) {

		return new CommonResult<Map<String,Object>>(true, "查询成功！", dingUserManager.queryExtUserInfo(extUserId,orgId));
	}

	@RequestMapping(value = "dingApi/queryExtUserInfoByUserId", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据组织id获取组织", httpMethod = "GET", notes = "根据userid获取钉钉userId")
	public OrgExternalUser queryExtUserInfoByUserId(@ApiParam(name = "userId", value = "钉钉userid") @RequestParam(value="userId",required = true) String userId) {

		return  dingUserManager.queryExtUserInfoById(userId);
	}

}
