package com.cyksj.web.controller.manage.corp;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyksj.common.constant.Constant;
import com.cyksj.common.exception.BusinessRuntimeException;
import com.cyksj.common.snowflake.Sequence;
import com.cyksj.common.util.Codec;
import com.cyksj.common.util.IoKit;
import com.cyksj.common.util.Jsons;
import com.cyksj.common.util.StringUtil;
import com.cyksj.config.corp.YHLXWxCorpConfig;
import com.cyksj.dto.CorpJsSdkTicket;
import com.cyksj.dto.CorpOauth2UserInfo;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
import com.cyksj.mapper.OrderDonMapper;
import com.cyksj.mapper.corp.CorpFollowMapper;
import com.cyksj.mapper.corp.CorpUserAuthMapper;
import com.cyksj.mapper.corp.CorpUserTagMapper;
import com.cyksj.model.dto.AuthRedirect;
import com.cyksj.model.entity.*;
import com.cyksj.model.manage.views.CorpQyMsgAuditChatView;
import com.cyksj.model.manage.views.CorpWxOrderDonView;
import com.cyksj.model.request.OrderRefundReq;
import com.cyksj.model.request.corp.CorpCommonReq;
import com.cyksj.model.views.*;
import com.cyksj.redis.RedisService;
import com.cyksj.service.chatgpt.ChatGptAccountService;
import com.cyksj.service.claude.ClaudeService;
import com.cyksj.service.corp.CorpService;
import com.cyksj.service.corp.CorpUserService;
import com.cyksj.service.mange.CmsOrderDonService;
import com.cyksj.service.user.UserBindRelationService;
import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.SearchResult;
import com.ejlchina.searcher.param.Operator;
import com.ejlchina.searcher.util.MapBuilder;
import com.ejlchina.searcher.util.MapUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/*
 *项目名: netflix
 *文件名: WxCorpController
 *创建者: JavaZou
 *创建时间:2022/10/13 14:19
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/corp")
public class WxCorpController {
	private final HttpServletRequest request;

	private final CorpService corpService;

	private final CorpUserService corpUserService;

	private final YHLXWxCorpConfig yhlxWxCorpConfig;

	private final static Sequence SEQUENCE = new Sequence(0);

	private final RedisService redisService;

	private final BeanSearcher beanSearcher;

	private final GroupsRelationExpiryRecordMapper groupsRelationExpiryRecordMapper;

	private final CorpUserTagMapper corpUserTagMapper;

	private final CorpUserAuthMapper corpUserAuthMapper;

	private final UserBindRelationService userBindRelationService;

	private final CmsOrderDonService cmsOrderDonService;

	private final CorpFollowMapper corpFollowMapper;

	private final ChatGptAccountService chatGptAccountService;

	private final ClaudeService claudeService;

	private final OrderDonMapper orderDonMapper;

	private final static String CORP_UUID = "corp-uuid";

	/**
	 * 企业微信 消息推送url
	 */
	@RequestMapping(value = "/msg/notify", method = {RequestMethod.GET, RequestMethod.POST})
	public String msgNotify(@RequestParam(value = "msg_signature") String msgSignature, String timestamp, String nonce, @RequestParam(value = "echostr", required = false) String echoStr) throws Exception {
		if (StrUtil.hasEmpty(msgSignature, timestamp, nonce)) {
			return StringUtil.EMPTY;
		}
		if (StrUtil.endWithIgnoreCase(request.getMethod(), RequestMethod.GET.name())) {
			if (StrUtil.isBlank(echoStr)) {
				return StrUtil.EMPTY;
			}
			//验证消息推送URL是否正确
			return corpService.VerifyURL(msgSignature, timestamp, nonce, echoStr);
		}

		String content = IoKit.toString(request.getInputStream(), IoKit.Charsets.UTF_8);
		log.info("企业微信操作通知: \n{}", content);

		if (StringUtils.isBlank(content)) {
			return StringUtil.EMPTY;
		}
		return corpService.corpMsg(msgSignature, timestamp,
				nonce, content);
	}

	/**
	 * 企业微信授权
	 */
	@GetMapping(value = "/auth")
	public void auth(String corpId, String url, HttpServletResponse response) throws Exception {

		log.info("企业微信授权转跳. url: {}", url);
		Map<String, String> paramMap = HttpUtil.decodeParamMap(url, IoKit.Charsets.UTF_8.getCharset());
		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
		Long mappingId = SEQUENCE.nextId();
		redisService.set(RedisService.key.CORP_AUTH_MAPPING_KEY.getName() + mappingId.toString(), url, RedisService.key.CORP_AUTH_MAPPING_KEY.getTimeout());
		AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setCorpId(corpId);

		String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();

		response.sendRedirect(corpService.createUrl(corpId, state));

	}

	/**
	 * 跳转授权
	 *
	 * @author chan
	 * @date 2022-03-17 下午4:37
	 */
	@GetMapping(value = "/redirect")
	public void redirect(String code, String state, HttpServletResponse response) throws Exception {

		// 转跳参数
		String json = Codec.DoBase64.custom().setData(state).decodeAsText();
		AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);

		CorpOauth2UserInfo corpOauth2UserInfo = corpService.getUserInfo(re.getCorpId(), code);

		log.info("企业微信客服授权信息:{}", Jsons.toJson(corpOauth2UserInfo));

		CorpFollow corpFollow = corpService.saveFollowUser(re.getCorpId(), corpOauth2UserInfo);

		String url = redisService.getStr(RedisService.key.CORP_AUTH_MAPPING_KEY.getName() + re.getMappingId().toString());

		Cookie cookie = new Cookie(CORP_UUID, corpFollow.getUserid());
		cookie.setMaxAge(31536000);
		cookie.setPath("/");
		response.addCookie(cookie);

		log.info("企业微信授权转跳.,url: {}", url);
		response.sendRedirect(url);
	}


	/**
	 * 企业微信获取js_ticket
	 *
	 * @author chan
	 * @date 2022-03-17 上午11:34
	 */
	@GetMapping("/get/jsTicket")
	public Result<CorpJsSdkTicket> getJsTicket(String corpId, String agentId, String url) throws Exception {
		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
		agentId = Optional.ofNullable(agentId).orElse("1000004");

		// 获取js-ticket
		String ticket = corpService.getJsTicket(corpId);

		// 生成js-sdk权限验证 签名
		CorpJsSdkTicket jsSdkTicket = new CorpJsSdkTicket();
		jsSdkTicket.setCorpId(corpId);
		jsSdkTicket.setAgentId(agentId);
		jsSdkTicket.setNonceStr("yhlx");
		jsSdkTicket.setTimestamp(System.currentTimeMillis());

		String str = "jsapi_ticket=" + ticket +
				"&noncestr=" + jsSdkTicket.getNonceStr() +
				"&timestamp=" + jsSdkTicket.getTimestamp() +
				"&url=" + url;

		String sha1Hex = Codec.DoDigest.custom()
				.setAlgorithm(Codec.DoDigest.Algorithm.SHA1).setStringData(str).toHexString();
		jsSdkTicket.setSignature(sha1Hex);
		return GatewayResponse.SUCCESS.newBuilder().toResult(jsSdkTicket);
	}

	/**
	 * 企业微信获取应用js_ticket
	 *
	 * @author chan
	 * @date 2022-03-17 上午11:34
	 */
	@GetMapping("/get/agentJsTicket")
	public Result<CorpJsSdkTicket> getagentJsTicket(String corpId, String agentId, String url) throws Exception {
		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
		agentId = Optional.ofNullable(agentId).orElse("1000004");

		// 获取js-ticket
		String ticket = corpService.getAgentJsTicket(corpId, agentId);

		// 生成js-sdk权限验证 签名
		CorpJsSdkTicket jsSdkTicket = new CorpJsSdkTicket();
		jsSdkTicket.setCorpId(corpId);
		jsSdkTicket.setAgentId(agentId);
		jsSdkTicket.setNonceStr("yhlx");
		jsSdkTicket.setTimestamp(System.currentTimeMillis());

		String str = "jsapi_ticket=" + ticket +
				"&noncestr=" + jsSdkTicket.getNonceStr() +
				"&timestamp=" + jsSdkTicket.getTimestamp() +
				"&url=" + url;

		String sha1Hex = Codec.DoDigest.custom()
				.setAlgorithm(Codec.DoDigest.Algorithm.SHA1).setStringData(str).toHexString();
		jsSdkTicket.setSignature(sha1Hex);
		return GatewayResponse.SUCCESS.newBuilder().toResult(jsSdkTicket);
	}

	public String getCorpUuid() {
		Cookie[] cookies = this.request.getCookies();
		if (cookies != null) {
			Cookie[] var3 = cookies;
			int var4 = cookies.length;

			for(int var5 = 0; var5 < var4; ++var5) {
				Cookie cookie = var3[var5];
				if (cookie != null && CORP_UUID.equals(cookie.getName())) {
					return cookie.getValue();
				}
			}
		}
		return StrUtil.EMPTY;
	}


	/**
	 * 初始化企业微信入库信息
	 */
	@GetMapping("/dataInit")
	public Result<String> dataInitByCorpId(String corpId) throws Exception {
		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
		return GatewayResponse.SUCCESS.newBuilder().toResult(corpService.dataInitByCorpId(corpId));
	}

	/**
	 * 企业微信客户银河录像详情
	 */
	@GetMapping("/user/detail")
	public Result<YHLXUserDetailView> getYHLXUserDetailView(String externalUserid, String corpId) throws Exception {
		YHLXUserDetailView detailView = corpUserService.getUserDetailView(externalUserid, corpId);
		return GatewayResponse.SUCCESS.newBuilder().toResult(detailView);
	}

	/**
	 * 企微 续费跟进头部数据
	 */
	@GetMapping("/get/corpRenewFollow/head/data")
	public Result<Map<String, Integer>> getCorpRenewFollowHeadView(String startTime, String endTime) {
		String followId = getCorpUuid();
		if (startTime == null) {
			startTime = DateUtil.beginOfDay(DateTime.now()).toString();
		}
		if (endTime == null) {
			endTime = DateUtil.endOfDay(DateTime.now()).toString();
		}
		Map<String, Integer> map = groupsRelationExpiryRecordMapper.selectRenewOrderData(followId, startTime, endTime);
		return GatewayResponse.SUCCESS.newBuilder().toResult(map);
	}

	/**
	 * 企业微信用户 通过订单号绑定其他用户
	 */
	@PostMapping("/bind/others/users")
	public Result<String> bindOtherUsersByOrderNo(@RequestBody @Validated CorpCommonReq corpCommonReq) throws Exception {
		corpUserService.bindOtherUsersByOrderNo(corpCommonReq);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 给企业微信用户 标记
	 */
	@PostMapping("/mark/user")
	public Result<String> markCorpUser(@RequestBody @Validated CorpCommonReq corpCommonReq) throws Exception {
		corpUserService.markCorpUser(corpCommonReq);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}


	/**
	 * 企微会话列表
	 *
	 * @param externalUserid 用户 externalUserid
	 */
	@GetMapping("/getMsgAuditChat")
	public Result<List<CorpQyMsgAuditChatView>> getMsgAuditChat(String externalUserid) {
		String followId = getCorpUuid();
		List<CorpMsgFollowAssociation> corpMsgFollowAssociations = beanSearcher.searchAll(CorpMsgFollowAssociation.class, MapUtils.builder().field(CorpMsgFollowAssociation::getFollowId, followId).build());
		List<String> followIds = corpMsgFollowAssociations.stream().map(CorpMsgFollowAssociation::getAssociationFollowId).collect(Collectors.toList());
		followIds.add(followId);
		if (StringUtils.isBlank(externalUserid)) {
			throw BusinessRuntimeException.getInstance("缺少必填参数.");
		}
		List<CorpQyMsgAuditChatView> search = beanSearcher.searchAll(CorpQyMsgAuditChatView.class, MapUtils.flatBuilder(request.getParameterMap())
				.field("followId", followIds.stream()
						.map(String::valueOf)
						.collect(Collectors.toList())).op(Operator.InList)
				.build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
	}


	/**
	 * 获取聊天记录
	 */
	@GetMapping("/getMsgByFollowIdAndUserId")
	public Result<SearchResult<QyMsgContent>> getMsgByFollowIdAndUserId() {
		Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
		log.info("获取聊天记录 param:{}", JSONUtil.toJsonStr(build));
		if (!build.containsKey("followId") || !build.containsKey("externalUserid")){
			throw BusinessRuntimeException.getInstance("缺少必填参数.");
		}
		SearchResult<QyMsgContent> search = beanSearcher.search(QyMsgContent.class, build);
		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
	}

	/**
	 * 获取主动回传 回传数据
	 *
	 * @Param unionId 用户unionId
	 */
	@GetMapping("/acquistionLinkCallback")
	public Result<CorpCustomerAcquistionCallback> getAcquistionLinkCallback(String externalUserId) {
		if (StrUtil.isEmpty(externalUserId)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		String unionId = corpUserAuthMapper.getUnionIdByExternalUserId(externalUserId);
		if (StrUtil.isEmpty(unionId)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()).field(CorpCustomerAcquistionCallback::getUnionId, unionId);
		CorpCustomerAcquistionCallback corpCustomerAcquistionCallback = beanSearcher.searchFirst(CorpCustomerAcquistionCallback.class, builder.build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(corpCustomerAcquistionCallback);
	}

	/**
	 * 查询用户 购买意愿
	 */
	@GetMapping("/get/user/intention")
	public Result<CorpUserPayIntention> getUserIntention(String externalUserId) {
		if (StrUtil.isEmpty(externalUserId)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		String unionId = corpUserAuthMapper.getUnionIdByExternalUserId(externalUserId);
		if (StrUtil.isEmpty(unionId)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()).field(CorpUserPayIntention::getUnionId, unionId);
		CorpUserPayIntention corpUserPayIntention = Optional.ofNullable(beanSearcher.searchFirst(CorpUserPayIntention.class, builder.build()))
				.orElseGet(() -> {
					CorpUserPayIntention corpUserPayIntention1 = new CorpUserPayIntention();
					corpUserPayIntention1.setUnionId(unionId);
					corpUserPayIntention1.setIntention(0);
					return corpUserPayIntention1;
				});
		return GatewayResponse.SUCCESS.newBuilder().toResult(corpUserPayIntention);
	}

	/**
	 * 修改意向
	 */
	@PutMapping("/update/user/intention")
	public Result<CorpUserPayIntention> updateUserIntention(@RequestBody CorpUserPayIntention corpUserPayIntention) {
		if (corpUserPayIntention.getUnionId() == null || corpUserPayIntention.getIntention() == null) {
			throw BusinessRuntimeException.getInstance("缺少必填参数.");
		}
		String followId = getCorpUuid();
		corpUserPayIntention.setFollowId(followId);
		corpService.updateUserIntention(corpUserPayIntention);
		return GatewayResponse.SUCCESS.newBuilder().toResult(corpUserPayIntention);
	}

	/**
	 * 主动回传
	 *
	 * @param id 记录id
	 */
	@GetMapping("/acquistionLinkCallback/{id}")
	public Result<String> postAcquistionLinkCallback(@PathVariable Long id) {
		corpService.postAcquistionLinkCallback(id);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 修改 意向
	 */
	@PutMapping("/upCallbackIntention")
	@Deprecated
	public Result<String> upCallbackIntention(@RequestBody CorpCustomerAcquistionCallback corpCustomerAcquistionCallback) {
		log.info("修改意向:{}", corpCustomerAcquistionCallback);
		if (corpCustomerAcquistionCallback.getId() == null || corpCustomerAcquistionCallback.getId() == 0 || corpCustomerAcquistionCallback.getIntention() == null) {
			throw BusinessRuntimeException.getInstance("缺少必填参数.");
		}
		corpService.upCallbackIntention(corpCustomerAcquistionCallback);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 用户意愿饼图
	 */
	@GetMapping("/get/user/intention/pie")
	public Result<List<UserIntentionPieView>> getUserIntentionPie(String tagId, String date) {
		List<UserIntentionPieView> userIntentionPieViews = corpUserTagMapper.getUserIntentionPie(tagId, date);
		return GatewayResponse.SUCCESS.newBuilder().toResult(userIntentionPieViews);
	}

	/**
	 * 标签用户列表
	 */
	@GetMapping("/get/tag/user/list")
	public Result<Page<CorpUserIntentionView>> getCorpUserIntentionView(Long userId, String nickname, String tagId, String date, Integer intention, @RequestParam(defaultValue = "1") Integer start, @RequestParam(defaultValue = "10") Integer limit) {
		Page<CorpUserIntentionView> page = corpUserTagMapper.getCorpUserIntentionView(new Page<>(start, limit), userId, nickname, tagId, date, intention);
		return GatewayResponse.SUCCESS.newBuilder().toResult(page);
	}

	/**
	 * 用户车票详情列表
	 */
	@GetMapping("/get/ticket")
	public Result<SearchResult<TicketView>> getTicketView(Long userId) {
		String corpUuid = getCorpUuid();
		if (StrUtil.isEmpty(corpUuid)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		if (userId == null) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		//关联关系
		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
		if (userIdList.isEmpty()) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		SearchResult<TicketView> ticketViews = beanSearcher.search(TicketView.class, MapUtils.flatBuilder(request.getParameterMap())
				.field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
				.field(TicketView::getUserId, userIdList).op(Operator.InList)
				.put("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", DateTime.now()))
				.field(TicketView::getGrStatus, List.of("validity", "outside")).op(Operator.InList)
				.orderBy(TicketView::getExpiryTime).asc()
				.build());
		ticketViews.getDataList().forEach(ticket->{
			OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
					.eq(OrderDon::getRelationId, ticket.getRelationId())
					.eq(OrderDon::getUserId, ticket.getUserId())
					.eq(OrderDon::getOrderType, 1)
					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
					.orderByDesc(OrderDon::getId)
					.last("limit 1"));
			if (orderDon != null) {
				ticket.setOrderNo(orderDon.getOrderNo());
				ticket.setOrderId(orderDon.getId());
				ticket.setTransactionId(orderDon.getTransactionId());
				if (ticket.getSecondType() != null && ticket.getSecondType() == 1) {
					//是否完成邀请 根据订单状态
					ticket.setIsComplete(orderDon.getStatus() == OrderDon.Status.complete ? true : false);
				}
			}
		});
		return GatewayResponse.SUCCESS.newBuilder().toResult(ticketViews);
	}


	/**
	 * 用户订单详情列表
	 */
	@GetMapping("/get/orders")
	public Result<SearchResult<CorpWxOrderDonView>> getOrders(Long userId) {
		String corpUuid = getCorpUuid();
		if (StrUtil.isEmpty(corpUuid)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		if (userId == null) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
		if (userIdList.isEmpty()) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		SearchResult<CorpWxOrderDonView> orderDonViews = beanSearcher.search(CorpWxOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
				.field(CorpWxOrderDonView::getUserId, userIdList).op(Operator.InList)
				.orderBy(CorpWxOrderDonView::getId).desc()
				.build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonViews);
	}

	/**
	 * 企业微信订单统一退款
	 */
	@PostMapping("/unified/refund")
	public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
		String followId = getCorpUuid();
		if (StrUtil.isEmpty(followId)) {
			throw BusinessRuntimeException.getInstance("请先授权登录");
		}
		CorpFollow corpFollow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class)
				.eq(CorpFollow::getUserid, followId)
				.eq(CorpFollow::getWxCorpId, 2)
				.last("limit 1"));
		if (corpFollow == null) {
			corpFollow = new CorpFollow();
			corpFollow.setName("企业客服");
		}
		refundReq.setOperator(corpFollow.getName());
		cmsOrderDonService.unifiedRefund(refundReq);
		return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
	}

	/**
	 * 开启spotify用户自助
	 */
	@PostMapping("/spotify/self/service/{orderId}")
	public Result<String> spotifySelfService(@PathVariable Long orderId) {
		corpUserService.spotifySelfService(orderId);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 清除gpt次数
	 */
	@PutMapping("/clear/gpt/num")
	public Result<String> clearGptNum(Long relationId) throws Exception {
		chatGptAccountService.clearGptNum(relationId);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 清除claude次数
	 */
	@PutMapping("/clear/claude/num")
	public Result<String> clearClaudeNum(Long relationId) throws Exception {
		claudeService.clearNumByRelationId(relationId);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 获取手机临时验证码
	 */
	@GetMapping("/get/tmp/code")
	public Result<String> getPhoneTmpCode(String phone) throws Exception {
		String corpUuid = getCorpUuid();
		if (StrUtil.isEmpty(corpUuid)) {
			return GatewayResponse.SUCCESS.newBuilder().toResult();
		}
		if (StrUtil.isEmpty(phone)) {
			throw BusinessRuntimeException.getInstance("请输入手机号");
		}
		String code = corpUserService.getPhoneTmpCode(phone);
		return GatewayResponse.SUCCESS.newBuilder().toResult(code);
	}
}
