package com.cyksj.web.controller.landing;

import cn.hutool.core.util.StrUtil;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
import com.cyksj.service.user.UserService;
import com.cyksj.web.util.StpUserUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 项目名: yhlxj
 * 文件名: CorpFollowActiveCodeController
 * 创建者: JavaZou
 * 创建时间:2023/10/10 14:31
 */
@RestController
@RequestMapping("/applets/landing")
@RequiredArgsConstructor
public class CorpFollowActiveCodeController {
	private final CorpFollowActiveCodeFrontService corpFollowActiveCodeFrontService;

	private final UserService userService;

	private final EquipmentDistributeService equipDistributeService;

	/**
	 * 活动活码落地页 获取对应客服二维码
	 */
	@GetMapping("/get/corp/active/qrCode/{id}")
	public Result<String> getCorpActiveQrCode(@PathVariable Long id, String dsCode) throws Exception {
		String qrCode = corpFollowActiveCodeFrontService.getCorpActiveQrCode(id);
		Long userId = StpUserUtil.getUserIdAfterLogin();
		if (userId != null && StrUtil.isNotBlank(dsCode)) {
			//绑定关系
			userService.bindUserDistributeShared(userId, dsCode);
		}
		return GatewayResponse.SUCCESS.newBuilder().toResult(qrCode);
	}
}
