package com.hotent.uc.controller;


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.ScanLoginManager;
import com.hotent.uc.manager.UserUniteManager;
import com.hotent.uc.model.ScanLogin;
import com.hotent.uc.model.User;
import com.hotent.uc.model.UserUnite;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * 扫码登录 接口控制器
 *
 * @company 广州宏天软件股份有限公司
 * @author pangquan
 * @since 2020-10-30
 */
@RestController
@RequestMapping("/uc/scanLogin/v1/")
@Api(tags="用户与外部通讯录关系")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class ScanLoginController extends BaseController<ScanLoginManager, ScanLogin> {
	@Autowired
	private ScanLoginManager scanLoginManager;

	/**
	 * 生成扫码登录二维码接口
	 * @param
	 * @return
	 */
	@GetMapping("/productQrCode")
	@ApiOperation(value = "生成登录二维码", httpMethod = "GET", notes = "生成登录二维码")
	public ScanLogin productQrCode(@RequestParam(value="type",required=true) String  type){
		ScanLogin res=scanLoginManager.productScanLogin(type);
		return res;
	}


	/**
	 * 钉钉扫码回调接口
	 * @param
	 * @return
	 */
	@GetMapping("/dingAuthByCode")
	@ApiOperation(value = "钉钉扫码回调接口", httpMethod = "GET", notes = "钉钉扫码回调接口")
	public User dingAuthByCode(@RequestParam(value="code",required=true) String code){
		User res=scanLoginManager.getDingUserInfo(code);
		return res;
	}

	/**
	 * 钉钉扫码回调接口
	 * @param
	 * @return
	 */
	@GetMapping("/updateScanLoginInfo")
	@ApiOperation(value = "更新扫码结果", httpMethod = "GET", notes = "更新扫码结果")
	public String updateScanLoginInfo(@RequestParam(value="scanId",required=true) String scanId,@RequestParam(value="userId",required=true) String userId){
		scanLoginManager.updateScanLoginInfo(scanId,userId);
		return "更新数据成功";
	}


	/**
	 * 钉钉扫码回调接口
	 * @param
	 * @return
	 */
	@GetMapping("/queryScanLoginInfo")
	@ApiOperation(value = "获取扫码结果", httpMethod = "GET", notes = "获取扫码结果")
	public User queryScanLoginInfo(@RequestParam(value="busId",required=true) String busId) {
		User res = scanLoginManager.queryScanLoginInfo(busId);
		return res;
	}

	/**
	 * 钉钉扫码是否扫码
	 * @param
	 * @return
	 */
	@GetMapping("/scanIng")
	@ApiOperation(value = "是否扫码", httpMethod = "GET", notes = "是否扫码")
	public CommonResult<?> scanIng(@RequestParam(value="busId",required=true) String busId) {
		return scanLoginManager.queryScanIng(busId);
	}

	/**
	 * 扫码更新结果
	 * @param
	 * @return
	 */
	@GetMapping("/putScanResult")
	@ApiOperation(value = "扫码更新结果", httpMethod = "GET", notes = "扫码更新结果")
	public CommonResult<?> putScanResult(@RequestParam(value="busId",required=true) String busId) {
		return scanLoginManager.putScanResult(busId);
	}
}
