package com.fs.app.controller;

import com.fs.common.core.domain.AjaxResult;
import com.fs.qw.service.IQwAcquisitionLinkInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 获客链接+微信
 */
@Slf4j
@RestController
@RequestMapping(value="/app/friendLinkWeChat")
public class CustomerLinkWeChatController extends AppBaseController {

    @Autowired
    private IQwAcquisitionLinkInfoService acquisitionLinkInfoService;

    @GetMapping("/goToLink/{pageParam}")
    @CrossOrigin
    public AjaxResult goToLink(@PathVariable String pageParam) {
        // 参数校验
        if (StringUtils.isBlank(pageParam)) {
            return AjaxResult.error("参数错误：页面参数不能为空");
        }

        // 获取完整链接URL
        String url = acquisitionLinkInfoService.selectQwAcquisitionUrlByRandomStr(pageParam);

        // 判断URL是否有效
        if (StringUtils.isBlank(url)) {
            log.info("无效的pageParam: {}", pageParam);
            return AjaxResult.error("链接无效或已过期");
        }

        // 返回成功结果，包含URL
        return AjaxResult.success("获取成功", url);
    }
}