package com.ruoyi.web.controller.system;

import java.security.GeneralSecurityException;
import java.security.Key;
import java.util.*;
import java.util.stream.Collectors;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.security.Md5Utils;
import com.ruoyi.system.domain.ClewPhone;
import com.ruoyi.system.domain.CompanyApp;
import com.ruoyi.system.domain.OppoCheck;
import com.ruoyi.system.service.IClewPhoneService;
import com.ruoyi.system.service.ICompanyAppService;
import com.ruoyi.system.service.IDutyConfigService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.core.config.GlobalLogHelper;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Clew;
import com.ruoyi.system.service.IClewService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

/**
 * 线索Controller
 *
 * @author ruoyi
 * @date 2023-05-15
 */
@Slf4j
@Controller
@RequestMapping("/system/clew")
public class ClewController extends BaseController
{
    private String prefix = "system/clew";

    @Autowired
    private IClewService clewService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private IClewPhoneService clewPhoneService;

    @Autowired
    private ICompanyAppService companyAppService;

    @Autowired
    private IDutyConfigService dutyConfigService;

    @RequiresPermissions("system:clew:view")
    @GetMapping()
    public String clew(ModelMap modelMap)
    {
        List<SysUser> users = sysUserService.selectUserList(new SysUser());
        modelMap.put("users", users);
        return prefix + "/clew";
    }

    @RequiresPermissions("system:clew:view")
    @GetMapping("publicClew")
    public String publicClew(ModelMap modelMap)
    {
        return prefix + "/publicClew";
    }

    @RequiresPermissions("system:clew:view")
    @GetMapping("qualityClew")
    public String qualityClew(ModelMap modelMap)
    {
        return prefix + "/qualityClew";
    }

    /**
     * 查询线索列表
     */
    @RequiresPermissions("system:clew:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Clew clew)
    {
        startPage();
        if(!"admin".equals(getSysUser().getLoginName())){
            clew.setSaleId(getSysUser().getUserId());
        }
        long isSubAdmin = getSysUser().getRoles().stream().filter(x->x.getRoleKey().equals("subAdmin")).count();
        if(isSubAdmin > 0 && !"admin".equals(getSysUser().getLoginName())){
            clew.setSaleId(null);
            clew.setRemark("baidu");
        }
        List<Clew> list = clewService.selectClewList(clew);
        list.forEach(model->{
            if(model.getSaleId() != null){
                SysUser user = sysUserService.selectUserById(model.getSaleId());
                if(user != null){
                    model.setSaleName(user.getUserName());
                }
                SysUser sourceUser = sysUserService.selectUserById(model.getSourceSaleId());
                if(sourceUser != null){
                    model.setSourceSaleName(sourceUser.getUserName());
                }
            }
            if(model.getSourceApp() != null){
                CompanyApp param = new CompanyApp();
                param.setCompanyId(model.getSourceApp());
                List<CompanyApp> result = companyAppService.selectCompanyAppList(param);
                model.setSourceAppName(result.get(0).getAppName());
            }else {
                model.setSourceAppName("黑猫APP");
            }
        });
        return getDataTable(list);
    }

    @RequiresPermissions("system:clew:list")
    @PostMapping("/listPublic")
    @ResponseBody
    public TableDataInfo listPublic(Clew clew)
    {
        startPage();
        clew.setSaleId(2L);
        clew.setPoolStatus("01"); // 只显示公海池状态的线索
        List<Clew> list = clewService.selectClewPublicList(clew);
        list.forEach(model->{
            if(model.getSaleId() != null){
                SysUser user = sysUserService.selectUserById(model.getSaleId());
                if(user != null){
                    model.setSaleName(user.getUserName());
                }
                SysUser sourceUser = sysUserService.selectUserById(model.getSourceSaleId());
                if(sourceUser != null){
                    model.setSourceSaleName(sourceUser.getUserName());
                }
            }
            if(model.getSourceApp() != null){
                CompanyApp param = new CompanyApp();
                param.setCompanyId(model.getSourceApp());
                List<CompanyApp> result = companyAppService.selectCompanyAppList(param);
                model.setSourceAppName(result.get(0).getAppName());
            }else {
                model.setSourceAppName("黑猫APP");
            }
        });
        return getDataTable(list);
    }

    @RequiresPermissions("system:clew:list")
    @PostMapping("/listQuality")
    @ResponseBody
    public TableDataInfo listQuality(Clew clew)
    {
        SysUser sysUser=getSysUser();
        startPage();
//        clew.setSaleId(2L);
        clew.setPoolStatus("02"); // 只显示优质线索池状态的线索
        if (!Objects.equals(sysUser.getLoginName(), "admin")){
             clew.setSaleId(sysUser.getUserId());
        }
        List<Clew> list = clewService.selectClewQualityList(clew);

        list.forEach(model->{
            if(model.getSaleId() != null){
                SysUser user = sysUserService.selectUserById(model.getSaleId());
                if(user != null){
                    model.setSaleName(user.getUserName());
                }
                SysUser sourceUser = sysUserService.selectUserById(model.getSourceSaleId());
                if(sourceUser != null){
                    model.setSourceSaleName(sourceUser.getUserName());
                }
            }
            if(model.getSourceApp() != null){
                CompanyApp param = new CompanyApp();
                param.setCompanyId(model.getSourceApp());
                List<CompanyApp> result = companyAppService.selectCompanyAppList(param);
                model.setSourceAppName(result.get(0).getAppName());
            }else {
                model.setSourceAppName("黑猫APP");
            }
        });
        return getDataTable(list);
    }

    /**
     * 导出线索列表
     */
    @RequiresPermissions("system:clew:export")
    @Log(title = "线索", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Clew clew)
    {
        List<Clew> list = clewService.selectClewList(clew);
        ExcelUtil<Clew> util = new ExcelUtil<Clew>(Clew.class);
        return util.exportExcel(list, "线索数据");
    }

    /**
     * 新增线索
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存线索
     */
    @RequiresPermissions("system:clew:add")
    @Log(title = "线索", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Clew clew)
    {
        return toAjax(clewService.insertClew(clew));
    }


    @PostMapping("/app/add")
    @ResponseBody
    public AjaxResult appAddSave(@RequestBody Clew clew)
    {
        Clew param = new Clew();
        param.setPhone(clew.getPhone());
        List<Clew> result = clewService.selectClewList(param);
        if (CollectionUtils.isNotEmpty(result)){
            return AjaxResult.success();
        }

        // 根据值班配置自动分配客服
        Long assignedUserId = null;
        try {
            assignedUserId = dutyConfigService.getNextDutyUserId();
            if (assignedUserId != null) {
                clew.setSaleId(assignedUserId);
                clew.setSourceSaleId(assignedUserId); // 记录初始分配的销售
                clew.setAssignTimes("01"); // 标记为首次分配
                log.info("线索自动分配给值班用户, 手机号:{}, 用户ID:{}", clew.getPhone(), assignedUserId);
            } else {
                // 如果没有值班配置，使用默认逻辑（可以设置为公海或默认用户）
                clew.setSaleId(1L); // 默认分配给默认用户-保无忧
                clew.setPoolStatus("01"); // 设置为公海池状态
                log.info("未找到值班配置, 线索分配到公海, 手机号:{}", clew.getPhone());
            }
        } catch (Exception e) {
            log.error("获取值班用户失败, 线索分配到公海, 手机号:{}, 错误:{}", clew.getPhone(), e.getMessage());
            clew.setSaleId(1L); // 异常时分配给公海
            clew.setPoolStatus("01"); // 设置为公海池状态
        }

        // 不存在手机号则入库线索
        clewService.insertClew(clew);
        
        // 如果分配给了具体客服，发送短信通知
        if (assignedUserId != null && assignedUserId != 2L) {
            sendSmsNotification(assignedUserId, clew);
        }

        // 将初始线索设置成已跟踪
        ClewPhone model = new ClewPhone();
        model.setPhone(clew.getPhone());
        List<ClewPhone> clewPhoneList =  clewPhoneService.selectClewPhoneList(model);
        clewPhoneList.forEach(x->{
            x.setStatus("1");
            x.setSourceApp(clew.getSourceApp());
            clewPhoneService.updateClewPhone(x);
        });
        // 调用oppo的统计接口
        try {
            // 回调
            if("oppo".equalsIgnoreCase(clew.getRemark())){
                OppoCheck oppoCheck = new OppoCheck();
                oppoCheck.setDataType(7);
                oppoCheck.setTimestamp(System.currentTimeMillis());
                if(StringUtils.isNotEmpty(clew.getImei())){
                    oppoCheck.setImei(encode(clew.getImei().getBytes()));
                }
                if(StringUtils.isNotEmpty(clew.getOaid())){
                    oppoCheck.setOuId(encode(clew.getOaid().getBytes()));
                }
                String content = JSONObject.toJSONString(oppoCheck) + oppoCheck.getTimestamp() + "e0u6fnlag06lc3pl";
                log.info("请求的content加密前属性{}", content);
                Map<String, String> headerMap = new HashMap<>();
                headerMap.put("signature", Md5Utils.hash(content));
                headerMap.put("timestamp", String.valueOf(oppoCheck.getTimestamp()));
                headerMap.put("Content-Type", "application/json");
                log.info("请求https://api.ads.heytapmobi.com/api/uploadActiveData的属性{}", JSONObject.toJSONString(oppoCheck));
                String s = HttpUtils.sendPost("https://api.ads.heytapmobi.com/api/uploadActiveData", JSONObject.toJSONString(oppoCheck), headerMap);
                log.info("请求https://api.ads.heytapmobi.com/api/uploadActiveData的响应{}", s);
            }else if("vivo".equalsIgnoreCase(clew.getRemark())){
                String token = "b447ca5eaa2aabac351bc798e8a826f2ad52927bb01aa0afcb8ca22397dac494";
                String timeStamp = System.currentTimeMillis() + "";
                String notice = "VIVO"+ (long)((Math.random()+1) * 10000000);
                String url = "https://marketing-api.vivo.com.cn/openapi/v1/advertiser/behavior/upload?access_token="+token+"&timestamp="+timeStamp+"&nonce="+notice;
                String content = "{\"dataList\":[{\"cvTime\":"+timeStamp+",\"cvType\":\"PAY\",\"userId\":\""+ clew.getOaid() +"\",\"userIdType\":\"OAID\"}],\"pkgName\":\"com.yinliu.loan\",\"srcId\":\"ds-202502072511\",\"srcType\":\"app\"}";
                if(clew.getSourceApp() != null && clew.getSourceApp() == 2L){
                    content = "{\"dataList\":[{\"cvTime\":"+timeStamp+",\"cvType\":\"PAY\",\"userId\":\""+ clew.getOaid() +"\",\"userIdType\":\"OAID\"}],\"pkgName\":\"com.zh.gdyq\",\"srcId\":\"ds-202404185034\",\"srcType\":\"app\"}";
                }
                Map<String, String> headerMap = new HashMap<>();
                headerMap.put("Content-Type", "application/json");
                log.info("请求{}的属性{}", url, content);
                String s = HttpUtils.sendPost(url, content, headerMap);
                log.info("请求{}的响应{}", url, s);
            }else if("xiaomi".equalsIgnoreCase(clew.getRemark())){
                log.info("oaid : {}, imei:{}", clew.getOaid(), clew.getImei());
//                String imei = clew.getImei();
                    String oaid = clew.getOaid();
//                    String ua = "Dalvik/2.1.0 (Linux; U; Android 11; M2012K11AC Build/RKQ1.200826.002)";
                    String clientIp = "58.49.150.163";
                long convTime = System.currentTimeMillis();
                String convType = "APP_PAY";
                long appId = 1545362;
                int customerId = 445972;
                String singKey = "FkqMqeKVbCaeSGBI";
                String encryptKey = "IIUWoEaMXlzctOqk";
                if(clew.getSourceApp() != null && clew.getSourceApp() == 2L){
                    customerId = 593022;
                    appId = 1585622;
                    singKey = "lNebrbVaMMubMqUr";
                    encryptKey = "hZdCGTMvrOAdVeUq";
                }
                GlobalLogHelper.UploadInfo uploadInfo = GlobalLogHelper.UploadInfo.builder()
//                        .imei(imei)
                            .oaid(oaid)
//                            .ua(ua)
                            .clientIp(clientIp)
                        .convTime(convTime).convType(convType)
                        .appId(appId).customerId(customerId).signKey(singKey).encryptKey(encryptKey).build().genInfo();
                log.info("请求xiaomi的属性{}", uploadInfo.getFinalUrl());
                String s = HttpUtils.sendGet(uploadInfo.getFinalUrl());
                log.info("请求xiaomi的响应{}", s);
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("回调oppo报错:{}", e.getMessage());
        }
        return AjaxResult.success();
    }

    //huawei-归因
    public String getHuaWeiToken(){

        return null;
    }

    public String send() throws Exception{
        JSONObject vivoJson = new JSONObject();
        vivoJson.put("srcType", "APP");
        vivoJson.put("pkgName", "");
        vivoJson.put("pageUrl", "");
        vivoJson.put("srcId", "");
        vivoJson.put("dataFrom", "0");
        String url = "https://sandbox-marketing-api.vivo.com.cn/openapi/v1/advertiser/behavior/upload";
        String advertiserId = "XX";
        String nonce = "XX";
        String accessToken = "595a46633e3f8162363a37092037a436f62e4d462102ddbf3eb503fa52017b93";
        String timestamp = String.valueOf(System.currentTimeMillis());
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("application/json");
        String jsonStr = "XX"; //使用请求参数的json串替换，格式如下方示例
        okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, jsonStr);
        Request request = new Request.Builder()
                .url(url + "?access_token=" + accessToken + "&timestamp=" + timestamp + "&nonce=" + nonce + "&advertiser_id=" + advertiserId)
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    public static String encode(byte[] data) throws GeneralSecurityException {
        final Key dataKey = new SecretKeySpec(Base64.decodeBase64("XGAXicVG5GMBsx5bueOe4w=="), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, dataKey);
        byte[] encryptData = cipher.doFinal(data);
        return Base64.encodeBase64String(encryptData).replaceAll("\r", "").replaceAll("\n", "");
    }

    /**
     * 修改线索
     */
    @RequiresPermissions("system:clew:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Clew clew = clewService.selectClewById(id);
        mmap.put("clew", clew);
        return prefix + "/edit";
    }

    /**
     * 修改保存线索
     */
    @RequiresPermissions("system:clew:edit")
    @Log(title = "线索", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Clew clew)
    {
        return toAjax(clewService.updateClew(clew));
    }

    /**
     * 删除线索
     */
    @RequiresPermissions("system:clew:remove")
    @Log(title = "线索", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clewService.deleteClewByIds(ids));
    }

    @PostMapping("/changeUser")
    @ResponseBody
    public AjaxResult changeUser(Clew clew)
    {
        Clew sourceClew = clewService.selectClewById(clew.getId());
        if(!ObjectUtil.equals(sourceClew.getSaleId(), 1L)){
            clew.setAssignTimes("02");
        }
        clew.setUpdateTime(DateUtils.getNowDate());
        // 线索短信通知
        try {
            // 查询销售手机号
            SysUser sysUser = sysUserService.selectUserById(clew.getSaleId());
            JSONObject smsContent = new JSONObject();
            smsContent.put("uid", "12347");
            smsContent.put("pwd", "wJgzaC0u");
            smsContent.put("mobile", sysUser.getLoginName());
            // 证明是普通的手机号
            boolean flag =  sysUser.getLoginName().length() > 10;
            if(sourceClew.getSourceApp() != null && sourceClew.getSourceApp() == 2L){
                smsContent.put("content", "你有一条来自大象，新线索生成，客户电话：" + sourceClew.getPhone() + "（请注意及时跟进）");
            }else {
                smsContent.put("content", "你有一条来自黑猫，新线索生成，客户电话：" + sourceClew.getPhone() + "（请注意及时跟进）");
            }
            if(!ObjectUtil.equals(sourceClew.getSourceApp(), 8L) && flag){
                log.info("请求傲众短信入参:{}", smsContent.toJSONString());
                String s = HttpUtils.sendPost("http://www.aozhongyun.com/Admin/index.php/Message/send", smsContent.toJSONString());
                log.info("请求傲众短信url:{}, 响应:{}", "http://www.aozhongyun.com/Admin/index.php/Message/send", s);
            }
        }catch (Exception e){
            log.error("请求傲众短信url:{}, 报错:{}","http://www.aozhongyun.com/Admin/index.php/Message/send", e.getMessage());
        }
        return toAjax(clewService.updateClew(clew));
    }


    @PostMapping("/getBackClew")
    @ResponseBody
    public AjaxResult getBackClew(Clew clew)
    {
        Clew sourceClew = clewService.selectClewById(clew.getId());
        if(sourceClew.getSaleId() != 2L){
            return AjaxResult.error("该线索已被人取走!");
        }
        sourceClew.setSaleId(getSysUser().getUserId());
        sourceClew.setUpdateTime(new Date());
        return toAjax(clewService.updateClew(sourceClew));
    }

    @PostMapping("/addPublicClew")
    @ResponseBody
    public AjaxResult addPublicClew(Clew clew)
    {
        Clew sourceClew = clewService.selectClewById(clew.getId());
        sourceClew.setSaleId(2L);
        clew.setUpdateTime(DateUtils.getNowDate());
        return toAjax(clewService.updateClew(sourceClew));
    }


    @GetMapping("/changeUser/{clewId}")
    public String changeUser(@PathVariable("clewId") String id, ModelMap mmap)
    {
        mmap.put("clewId", id);
        mmap.put("users", sysUserService.selectUserList(new SysUser()));
        return "system/clew/changeUser";
    }

    @PostMapping("/changeBatchUser")
    @ResponseBody
    public AjaxResult changeBatchUser(Clew clew)
    {
        if(StringUtils.isEmpty(clew.getIds())){
            return AjaxResult.error("请选择线索!");
        }
        Clew sourceClew = clewService.selectClewById(Long.parseLong(clew.getIds().split(",")[0]));
        if(!ObjectUtil.equals(sourceClew.getSaleId(), 1L)){
            clew.setAssignTimes("02");
        }
        clew.setUpdateTime(DateUtils.getNowDate());
        clew.setIdList(Arrays.stream(clew.getIds().split(",")).map(Long::parseLong).collect(Collectors.toList()));
        // 线索短信通知
        try {
            // 查询销售手机号
            SysUser sysUser = sysUserService.selectUserById(clew.getSaleId());
            JSONObject smsContent = new JSONObject();
            smsContent.put("uid", "12347");
            smsContent.put("pwd", "wJgzaC0u");
            smsContent.put("mobile", sysUser.getLoginName());
            // 证明是普通的手机号
            boolean flag =  sysUser.getLoginName().length() > 10;
            if(sourceClew.getSourceApp() != null && sourceClew.getSourceApp() == 2L){
                smsContent.put("content", "你有多条来自大象，新线索生成（请注意及时跟进）");
            }else {
                smsContent.put("content", "你有一条来自黑猫，新线索生成（请注意及时跟进）");
            }
            if(!ObjectUtil.equals(sourceClew.getSourceApp(), 8L) && flag){
                log.info("请求傲众短信入参:{}", smsContent.toJSONString());
                String s = HttpUtils.sendPost("http://www.aozhongyun.com/Admin/index.php/Message/send", smsContent.toJSONString());
                log.info("请求傲众短信url:{}, 响应:{}", "http://www.aozhongyun.com/Admin/index.php/Message/send", s);
            }
        }catch (Exception e){
            log.error("请求傲众短信url:{}, 报错:{}","http://www.aozhongyun.com/Admin/index.php/Message/send", e.getMessage());
        }
        return toAjax(clewService.updateBatchClew(clew));
    }

    @GetMapping("/changeBatchUser/{clewIds}")
    public String changeBatchUser(@PathVariable("clewIds") String ids, ModelMap mmap)
    {
        mmap.put("clewIds", ids);
        mmap.put("users", sysUserService.selectUserList(new SysUser()));
        return "system/clew/changeBatchUser";
    }

    /**
     * 捞取线索到优质线索池
     */
    @PostMapping("/catchClew")
    @ResponseBody
    public AjaxResult catchClew(Clew clew)
    {
        Clew sourceClew = clewService.selectClewById(clew.getId());
        if(!"01".equals(sourceClew.getPoolStatus())){
            return AjaxResult.error("该线索不在公海池中!");
        }
        sourceClew.setSaleId(getUserId());
        sourceClew.setPoolStatus("02");
        sourceClew.setCatchTime(new Date());
        sourceClew.setUpdateTime(new Date());
        return toAjax(clewService.catchClewToQuality(sourceClew));
    }

    /**
     * 发送短信通知给值班客服
     */
    private void sendSmsNotification(Long userId, Clew clew) {
        try {
            // 查询客服手机号
            SysUser sysUser = sysUserService.selectUserById(userId);
            if (sysUser == null || StringUtils.isEmpty(sysUser.getLoginName())) {
                log.warn("未找到用户信息或手机号为空, 用户ID:{}", userId);
                return;
            }
            
            // 检查是否是手机号（长度大于10位）
            boolean isPhone = sysUser.getLoginName().length() > 10;
            if (!isPhone) {
                log.info("用户登录名不是手机号，跳过短信通知, 用户ID:{}, 登录名:{}", userId, sysUser.getLoginName());
                return;
            }
            
            // 排除特定来源（sourceApp == 8）
            if (ObjectUtil.equals(clew.getSourceApp(), 8L)) {
                log.info("线索来源为8，跳过短信通知, 用户ID:{}", userId);
                return;
            }
            
            JSONObject smsContent = new JSONObject();
            smsContent.put("uid", "12347");
            smsContent.put("pwd", "wJgzaC0u");
            smsContent.put("mobile", sysUser.getLoginName());
            
            // 根据来源设置短信内容
            if (clew.getSourceApp() != null && clew.getSourceApp() == 2L) {
                smsContent.put("content", "【值班分配】你有一条来自大象，新线索生成，客户电话：" + clew.getPhone() + "（请注意及时跟进）");
            } else {
                smsContent.put("content", "【值班分配】你有一条来自黑猫，新线索生成，客户电话：" + clew.getPhone() + "（请注意及时跟进）");
            }
            
            log.info("值班分配短信通知, 用户ID:{}, 手机号:{}, 请求参数:{}", userId, sysUser.getLoginName(), smsContent.toJSONString());
            String response = HttpUtils.sendPost("http://www.aozhongyun.com/Admin/index.php/Message/send", smsContent.toJSONString());
            log.info("值班分配短信通知响应:{}", response);
        } catch (Exception e) {
            log.error("发送值班分配短信通知失败, 用户ID:{}, 错误:{}", userId, e.getMessage(), e);
        }
    }

}
