package com.fs.qw.service.impl;

import com.fs.common.utils.PubFun;
import com.fs.course.domain.FsUserCourse;
import com.fs.course.service.impl.FsUserCourseServiceImpl;
import com.fs.qw.domain.QwCompany;
import com.fs.qw.domain.QwUser;
import com.fs.qw.mapper.QwExternalContactMapper;
import com.fs.qw.result.QwFilterSopCustomersResult;
import com.fs.qw.service.IQwCompanyService;
import com.fs.qw.vo.QwSopRuleTimeVO;
import com.fs.sop.domain.*;
import com.fs.sop.mapper.QwSopLogsMapper;
import com.fs.sop.mapper.QwSopMapper;
import com.fs.sop.mapper.QwSopTempMapper;
import com.fs.sop.mapper.SopUserLogsInfoMapper;
import com.fs.sop.params.DeleteQwSopParam;
import com.fs.sop.params.QwSopTagsParam;
import com.fs.sop.params.SopUserLogsArray;
import com.fs.sop.params.SopUserLogsList;
import com.fs.sop.service.IQwSopTempVoiceService;
import com.fs.sop.service.ISopUserLogsService;
import com.fs.voice.utils.StringUtil;
import com.fs.wxUser.domain.CompanyWxUser;
import com.fs.wxUser.mapper.CompanyWxUserMapper;
import com.fs.wxUser.param.CompanyWxUserSopParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
@AllArgsConstructor
public class AsyncUploadQwCourseImageService {


    @Autowired
    private IQwCompanyService iQwCompanyService;

    @Autowired
    private FsUserCourseServiceImpl fsUserCourseService;

    /**
     * 异步处理销售删除客户
     */
    @Async("scheduledExecutorService")
    public void uploadQwCourseImage(FsUserCourse fsUserCourse) {

        // 获取所有企业微信配置
        List<QwCompany> companies = iQwCompanyService.selectQwCompanyList(new QwCompany());

        // 遍历每个企业微信配置
        for (QwCompany company : companies) {
            String corpId = company.getCorpId();
            if (corpId == null) {
                continue;
            }

            //上传图片到对应企业的素材库
            try {
                fsUserCourseService.uploadCourseImage(fsUserCourse, corpId);
            } catch (Exception e) {
                log.error("处理课程图片失败: courseId={}, corpId={}, error={}", fsUserCourse.getCourseId(), corpId, e.getMessage());
            }

        }

    }
}
