package com.hotent.uc.controller;


import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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.PostMapping;
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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.base.util.BeanUtils;
import com.hotent.uc.manager.UserUniteManager;
import com.hotent.uc.model.UserUnite;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户与外部通讯录关系表 前端控制器
 *
 * @company 广州宏天软件股份有限公司
 * @author pangquan
 * @since 2020-10-30
 */
@RestController
@RequestMapping("/uc/userUnite/v1/")
@Api(tags="用户与外部通讯录关系")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class UserUniteController extends BaseController<UserUniteManager, UserUnite> {
	@Autowired
	private UserUniteManager userUniteManager;

	@PostMapping("updateUserUnite")
	@ApiOperation(value = "更新", httpMethod = "POST", notes = "更新")
	public CommonResult<String> updateUserUnite(@RequestBody UserUnite userUnite){
		this.baseService.updateUserUnite(userUnite);
		return new CommonResult<String>("更新成功");
	}
	@PostMapping("save")
	@ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
	public CommonResult<String> save(@RequestBody UserUnite userUnite){
		if(BeanUtils.isNotEmpty(userUnite.getId())){
			this.baseService.update(userUnite);
			return new CommonResult<String>("更新成功");

		}else{
			this.baseService.create(userUnite);
			return new CommonResult<String>("新增成功");
		}
		
	}
	/**
	 * 根据企业微信通讯录userid获取数据
	 * @param wxWorkId
	 * @return
	 */
	@GetMapping("getUserUniteByWxWorkId")
	@ApiOperation(value = "根据企业微信通讯录userid获取数据", httpMethod = "POST", notes = "根据企业微信通讯录userid获取数据")
	public Object getUserUniteByWxWorkId(@RequestParam(value="wxWorkId",required=true) String wxWorkId){
		QueryWrapper<UserUnite> queryWrapper = new QueryWrapper<UserUnite>().eq("WX_WORK_ID_", wxWorkId);
		UserUnite exist = this.baseService.getOne(queryWrapper);
		return exist;
	}
	/**
	 * 根据用户id获取数据
	 * @param userId
	 * @return
	 */
	@GetMapping("/getByUserId/{userId}")
	@ApiOperation(value = "根据用户id获取数据", httpMethod = "GET", notes = "根据用户id获取数据")
	public UserUnite getByUserId(@PathVariable String userId){
		QueryWrapper<UserUnite> queryWrapper = new QueryWrapper<UserUnite>().eq("USER_ID_", userId);
		UserUnite exist = this.baseService.getOne(queryWrapper);
		return exist;
	}
	/**
	 * 根据userIds获取钉钉ids
	 * @param userId
	 * @return
	 */
	@GetMapping("/getDingtalkIdsByUserIds")
	@ApiOperation(value = "根据userIds获取钉钉ids", httpMethod = "GET", notes = "根据userIds获取钉钉ids")
	public String getDingtalkIdsByUserIds(@RequestParam(value="userIds",required=true) String userIds){
		String res=userUniteManager.getDingtalkIdsByUserIds(userIds);
		return res;
	}
	/**
	 * 根据userIds获取企业微信ids
	 * @param userId
	 * @return
	 */
	@GetMapping("/getWxWorkIdsByUserIds")
	@ApiOperation(value = "根据userIds获取企业微信ids", httpMethod = "GET", notes = "根据userIds获取企业微信ids")
	public String getWxWorkIdsByUserIds(@RequestParam(value="userIds",required=true) String userIds){
		String res=userUniteManager.getWxWorkIdsByUserIds(userIds);
		return res;
	}
	
	/**
	 * 根据userIds获取公众号openids
	 * @param userId
	 * @return
	 */
	@GetMapping("/getOpenIdsByUserIds")
	@ApiOperation(value = "根据userIds获取公众号openids", httpMethod = "GET", notes = "根据userIds获取公众号openids")
	public String getOpenIdsByUserIds(@RequestParam(value="userIds",required=true) String userIds){
		String res=userUniteManager.getOpenIdsByUserIds(userIds);
		return res;
	}
}
