lmx 1 месяц назад
Родитель
Сommit
4246477fa5

+ 58 - 14
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallLog.java

@@ -1,38 +1,82 @@
 package com.fs.company.domain;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
+import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
-import com.fs.company.vo.RoboticWxVo;
+import com.fs.common.constant.Constants;
 import lombok.Data;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.EqualsAndHashCode;
 
-import java.time.LocalDateTime;
-import java.util.List;
-import java.util.Map;
-
+/**
+ * 调用日志对象 company_voice_robotic_call_log
+ *
+ * @author fs
+ * @date 2026-01-13
+ */
 @Data
-public class CompanyVoiceRoboticCallLog {
-    private static final long serialVersionUID = 1L;
+@EqualsAndHashCode(callSuper = true)
+public class CompanyVoiceRoboticCallLog extends BaseEntity{
 
-    /** ID */
-    @TableId(type = IdType.AUTO)
+    /** $column.columnComment */
     private Long logId;
 
+    /** 任务id */
+    @Excel(name = "任务id")
     private Long roboticId;
 
+    /**
+     * caller_id  打电话&发短信
+     * */
+    @Excel(name = "caller_id")
     private Long callerId;
 
+    /**
+     * wx_client_id 加微
+     */
+    @Excel(name = "wx_client_id")
+    private Long wxClientId;
+
+    /** 调用方法 */
+    @Excel(name = "调用方法")
     private String runFunction;
 
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime runTime;
+    /** 记录调用时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "记录调用时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date runTime;
 
+    /** 调用参数 */
+    @Excel(name = "调用参数")
     private String runParam;
 
+    /** 执行结果 */
+    @Excel(name = "执行结果")
     private String result;
 
+    /** 执行状态:1、执行中,2、执行成功,3、执行失败 */
+    @Excel(name = "执行状态:1、执行中,2、执行成功,3、执行失败")
     private Integer status;
 
+
+    public static CompanyVoiceRoboticCallLog initCallLogByType(String type, String runParam, Long keyId, Long taskId) {
+        CompanyVoiceRoboticCallLog log = new CompanyVoiceRoboticCallLog();
+
+        switch (type) {
+            case Constants.SEND_MSG:
+            case Constants.CELL_PHONE:
+                log.callerId = keyId;
+                break;
+            case Constants.ADD_WX:
+                log.wxClientId = keyId;
+                break;
+        }
+        log.runParam = runParam;
+        log.roboticId = taskId;
+        log.runFunction = type;
+        log.runTime = new Date();
+        return log;
+    }
+
 }

+ 70 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyVoiceRoboticCallLogMapper.java

@@ -0,0 +1,70 @@
+package com.fs.company.mapper;
+
+import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fs.company.domain.CompanyVoiceRoboticCallLog;
+import com.fs.company.domain.CompanyVoiceRoboticCallees;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * 调用日志Mapper接口
+ * 
+ * @author fs
+ * @date 2026-01-13
+ */
+public interface CompanyVoiceRoboticCallLogMapper extends BaseMapper<CompanyVoiceRoboticCallLog>{
+    /**
+     * 查询调用日志
+     * 
+     * @param logId 调用日志主键
+     * @return 调用日志
+     */
+    CompanyVoiceRoboticCallLog selectCompanyVoiceRoboticCallLogByLogId(Long logId);
+
+    /**
+     * 查询调用日志列表
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 调用日志集合
+     */
+    List<CompanyVoiceRoboticCallLog> selectCompanyVoiceRoboticCallLogList(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 新增调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    int insertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 修改调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    int updateCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 删除调用日志
+     * 
+     * @param logId 调用日志主键
+     * @return 结果
+     */
+    int deleteCompanyVoiceRoboticCallLogByLogId(Long logId);
+
+    /**
+     * 批量删除调用日志
+     * 
+     * @param logIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    int deleteCompanyVoiceRoboticCallLogByLogIds(Long[] logIds);
+
+    /**
+     * 查询待回调写入日志数据
+     * @param callees
+     * @return
+     */
+    CompanyVoiceRoboticCallLog selectNoResultLogByCallees(@Param("callees") CompanyVoiceRoboticCallees callees);
+}

+ 73 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyVoiceRoboticCallLogService.java

@@ -0,0 +1,73 @@
+package com.fs.company.service;
+
+import java.util.List;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.aicall.domain.apiresult.PushIIntentionResult;
+import com.fs.company.domain.CompanyVoiceRoboticCallLog;
+import com.fs.company.domain.CompanyVoiceRoboticCallees;
+
+/**
+ * 调用日志Service接口
+ * 
+ * @author fs
+ * @date 2026-01-13
+ */
+public interface ICompanyVoiceRoboticCallLogService extends IService<CompanyVoiceRoboticCallLog>{
+    /**
+     * 查询调用日志
+     * 
+     * @param logId 调用日志主键
+     * @return 调用日志
+     */
+    CompanyVoiceRoboticCallLog selectCompanyVoiceRoboticCallLogByLogId(Long logId);
+
+    /**
+     * 查询调用日志列表
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 调用日志集合
+     */
+    List<CompanyVoiceRoboticCallLog> selectCompanyVoiceRoboticCallLogList(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 新增调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    int insertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 修改调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    int updateCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    /**
+     * 批量删除调用日志
+     * 
+     * @param logIds 需要删除的调用日志主键集合
+     * @return 结果
+     */
+    int deleteCompanyVoiceRoboticCallLogByLogIds(Long[] logIds);
+
+    /**
+     * 删除调用日志信息
+     * 
+     * @param logId 调用日志主键
+     * @return 结果
+     */
+    int deleteCompanyVoiceRoboticCallLogByLogId(Long logId);
+
+    /**
+     * 异步写入日志
+     * @param companyVoiceRoboticCallLog
+     */
+    void asyncInsertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog);
+
+    void asyncInsertCompanyVoiceRoboticCallLogBatch(List<CompanyVoiceRoboticCallLog> list);
+
+    void asyncHandleCalleeCallBackResult(PushIIntentionResult result, CompanyVoiceRoboticCallees callees);
+}

+ 141 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticCallLogServiceImpl.java

@@ -0,0 +1,141 @@
+package com.fs.company.service.impl;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.aicall.domain.apiresult.PushIIntentionResult;
+import com.fs.company.domain.CompanyVoiceRoboticCallees;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import com.fs.company.mapper.CompanyVoiceRoboticCallLogMapper;
+import com.fs.company.domain.CompanyVoiceRoboticCallLog;
+import com.fs.company.service.ICompanyVoiceRoboticCallLogService;
+
+/**
+ * 调用日志Service业务层处理
+ * 
+ * @author fs
+ * @date 2026-01-13
+ */
+@Service
+@Slf4j
+public class CompanyVoiceRoboticCallLogServiceImpl extends ServiceImpl<CompanyVoiceRoboticCallLogMapper, CompanyVoiceRoboticCallLog> implements ICompanyVoiceRoboticCallLogService {
+
+
+    @Autowired
+    CompanyVoiceRoboticCallLogMapper companyVoiceRoboticCallLogMapper;
+
+    /**
+     * 查询调用日志
+     * 
+     * @param logId 调用日志主键
+     * @return 调用日志
+     */
+    @Override
+    public CompanyVoiceRoboticCallLog selectCompanyVoiceRoboticCallLogByLogId(Long logId)
+    {
+        return baseMapper.selectCompanyVoiceRoboticCallLogByLogId(logId);
+    }
+
+    /**
+     * 查询调用日志列表
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 调用日志
+     */
+    @Override
+    public List<CompanyVoiceRoboticCallLog> selectCompanyVoiceRoboticCallLogList(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog)
+    {
+        return baseMapper.selectCompanyVoiceRoboticCallLogList(companyVoiceRoboticCallLog);
+    }
+
+    /**
+     * 新增调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    @Override
+    public int insertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog)
+    {
+        return baseMapper.insertCompanyVoiceRoboticCallLog(companyVoiceRoboticCallLog);
+    }
+
+    /**
+     * 修改调用日志
+     * 
+     * @param companyVoiceRoboticCallLog 调用日志
+     * @return 结果
+     */
+    @Override
+    public int updateCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog)
+    {
+        return baseMapper.updateCompanyVoiceRoboticCallLog(companyVoiceRoboticCallLog);
+    }
+
+    /**
+     * 批量删除调用日志
+     * 
+     * @param logIds 需要删除的调用日志主键
+     * @return 结果
+     */
+    @Override
+    public int deleteCompanyVoiceRoboticCallLogByLogIds(Long[] logIds)
+    {
+        return baseMapper.deleteCompanyVoiceRoboticCallLogByLogIds(logIds);
+    }
+
+    /**
+     * 删除调用日志信息
+     * 
+     * @param logId 调用日志主键
+     * @return 结果
+     */
+    @Override
+    public int deleteCompanyVoiceRoboticCallLogByLogId(Long logId)
+    {
+        return baseMapper.deleteCompanyVoiceRoboticCallLogByLogId(logId);
+    }
+
+    @Async("callLogExcutor")
+    public void asyncInsertCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog) {
+        try{
+            companyVoiceRoboticCallLog.setCreateTime(new Date());
+            baseMapper.insertCompanyVoiceRoboticCallLog(companyVoiceRoboticCallLog);
+        } catch (Exception e) {
+            log.error("记录任务执行日志失败:失败数据:{}",companyVoiceRoboticCallLog, e);
+        }
+    }
+    @Async("callLogExcutor")
+    public void asyncInsertCompanyVoiceRoboticCallLogBatch(List<CompanyVoiceRoboticCallLog> list) {
+        try{
+            list.stream().forEach(i->i.setCreateTime(new Date()));
+            this.saveBatch(list);
+        } catch (Exception e) {
+            log.error("批量记录任务执行日志失败:失败数据:{}",list, e);
+        }
+    }
+
+
+    @Async("callLogExcutor")
+    public void asyncHandleCalleeCallBackResult(PushIIntentionResult result, CompanyVoiceRoboticCallees callees) {
+        try {
+            CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog = companyVoiceRoboticCallLogMapper.selectNoResultLogByCallees(callees);
+            companyVoiceRoboticCallLog.setStatus(2);
+            companyVoiceRoboticCallLog.setResult(JSON.toJSONString(result));
+            baseMapper.updateCompanyVoiceRoboticCallLog(companyVoiceRoboticCallLog);
+        } catch (Exception ex) {
+            log.error("处理回调结果异常:{}", result, ex);
+        }
+    }
+
+}

+ 35 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyVoiceRoboticServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.company.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.aicall.domain.apiresult.Notify;
@@ -22,6 +23,7 @@ import com.fs.company.mapper.CompanyVoiceRoboticMapper;
 import com.fs.company.mapper.CompanyVoiceRoboticWxMapper;
 import com.fs.company.mapper.CompanyWxClientMapper;
 import com.fs.company.service.ICompanySmsService;
+import com.fs.company.service.ICompanyVoiceRoboticCallLogService;
 import com.fs.company.service.ICompanyVoiceRoboticService;
 import com.fs.company.service.ICompanyWxAccountService;
 import com.fs.company.vo.AddWxClientVo;
@@ -79,6 +81,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
     private final CompanySmsTempServiceImpl smsTempService;
     private final ICompanySmsService companySmsService;
     private final CompanyWxClientMapper companyWxClientMapper;
+    private final ICompanyVoiceRoboticCallLogService companyVoiceRoboticCallLogService;
     /**
      * 查询机器人外呼任务
      *
@@ -162,6 +165,7 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         if(customerList.isEmpty()){
             throw new BaseException("拨打电话不能为空");
         }
+        List<CompanyVoiceRoboticCallLog>  addLogs = new ArrayList<>();
         // 构建三方接口请求数据
         CalltaskcreateaiCustomizeDomain param = new CalltaskcreateaiCustomizeDomain();
         param.setRobot(companyVoiceRobotic.getRobot());
@@ -197,6 +201,16 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         }
         // 请求外呼接口
         CalltaskcreateaiCustomizeResult result = aiCallService.calltaskcreateaiCustomize(param, companyVoiceRobotic.getCompanyId());
+        JSONObject runParam = (JSONObject) JSON.toJSON(param);
+        runParam.put("companyId", companyVoiceRobotic.getCompanyId());
+        String runPString = runParam.toJSONString();
+        calleesList.forEach(call -> {
+            CompanyVoiceRoboticCallLog addLog = CompanyVoiceRoboticCallLog.initCallLogByType(Constants.CELL_PHONE,
+                    runPString, call.getId(), companyVoiceRobotic.getId());
+            addLog.setStatus(1);
+            addLogs.add(addLog);
+        });
+        companyVoiceRoboticCallLogService.asyncInsertCompanyVoiceRoboticCallLogBatch(addLogs);
         // 设置返回数据
         companyVoiceRobotic.setTaskId(result.getTaskID());
         companyVoiceRobotic.setTaskName(result.getTaskName());
@@ -232,8 +246,14 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
             if(StringUtils.isNotEmpty(robotic.getEndTime1())){
                 param.setEndTime1(robotic.getEndTime1() + ":00");
             }
+            JSONObject runParam = (JSONObject) JSON.toJSON(param);
+            runParam.put("companyId",robotic.getCompanyId());
+            CompanyVoiceRoboticCallLog addLog = CompanyVoiceRoboticCallLog.initCallLogByType(Constants.CELL_PHONE,
+                    runParam.toJSONString(), callerId, roboticId);
             // 请求外呼接口
             CalltaskcreateaiCustomizeResult result = aiCallService.calltaskcreateaiCustomize(param, robotic.getCompanyId());
+            addLog.setStatus(1);
+            companyVoiceRoboticCallLogService.asyncInsertCompanyVoiceRoboticCallLog(addLog);
             // 设置返回数据
 //            robotic.setTaskId(result.getTaskID());
 //            robotic.setTaskName(result.getTaskName());
@@ -286,7 +306,19 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
                         smsSendBatchParam.setCustomerIds(ids);
                         smsSendBatchParam.setContent(temp.getContent());
                         smsSendBatchParam.setSenderName(wxAccount.getWxNickName());
-                        sendMsgBatch(temp,smsSendBatchParam);
+                        JSONObject runParam = (JSONObject) JSON.toJSON(smsSendBatchParam);
+                        runParam.put("temp",temp);
+                        CompanyVoiceRoboticCallLog addLog = CompanyVoiceRoboticCallLog.initCallLogByType(Constants.SEND_MSG,
+                                runParam.toJSONString(), callerId, roboticId);
+                        addLog.setStatus(2);
+                        try{
+                            sendMsgBatch(temp,smsSendBatchParam);
+                        }catch(Exception ex){
+                            addLog.setStatus(3);
+                            addLog.setResult(ex.getMessage());
+                            log.error("sendMsgOne异常:",ex);
+                        }
+                        companyVoiceRoboticCallLogService.asyncInsertCompanyVoiceRoboticCallLog(addLog);
                         //如果选择的是名片短链接模版  update by qxj 2023年05月26日10:45:28
 //                        if(StringUtils.isNotEmpty(param.getCardUrl())){
 //                            smsSendBatchParam.setCardUrl(param.getCardUrl());
@@ -395,6 +427,8 @@ public class CompanyVoiceRoboticServiceImpl extends ServiceImpl<CompanyVoiceRobo
         if("billing".equals(notify.getType())) pushBilling(result);
 //        // 是否全部回调完毕
         CompanyVoiceRoboticCallees callee = getResultCalleeInfo(notify);
+        //更新调用日志
+        companyVoiceRoboticCallLogService.asyncHandleCalleeCallBackResult(result,callee);
         long count = companyVoiceRoboticCalleesMapper.countByRoboticIdNotUuid(callee.getRoboticId());
         if(count == 0){
 //            new Thread(() -> dispenseWx(callee.getRoboticId())).start();

+ 27 - 0
fs-service/src/main/java/com/fs/wxcid/threadExecutor/callLogTaskExecutor.java

@@ -0,0 +1,27 @@
+package com.fs.wxcid.threadExecutor;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+@EnableAsync
+public class callLogTaskExecutor {
+
+    @Bean("callLogExcutor")
+    public Executor callLogExcutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(4);
+        executor.setMaxPoolSize(8);
+        executor.setQueueCapacity(1000);
+        executor.setThreadNamePrefix("CallLog-");
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        executor.setKeepAliveSeconds(60);
+        executor.initialize();
+        return executor;
+    }
+}

+ 98 - 0
fs-service/src/main/resources/mapper/company/CompanyVoiceRoboticCallLogMapper.xml

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.company.mapper.CompanyVoiceRoboticCallLogMapper">
+    
+    <resultMap type="CompanyVoiceRoboticCallLog" id="CompanyVoiceRoboticCallLogResult">
+        <result property="logId"    column="log_id"    />
+        <result property="roboticId"    column="robotic_id"    />
+        <result property="callerId"    column="caller_id"    />
+        <result property="runFunction"    column="run_function"    />
+        <result property="runTime"    column="run_time"    />
+        <result property="runParam"    column="run_param"    />
+        <result property="result"    column="result"    />
+        <result property="status"    column="status"    />
+        <result property="createTime"    column="create_time"    />
+    </resultMap>
+
+    <sql id="selectCompanyVoiceRoboticCallLogVo">
+        select log_id, robotic_id, caller_id, wx_client_id, run_function, run_time, run_param, result, status,create_time from company_voice_robotic_call_log
+    </sql>
+
+    <select id="selectCompanyVoiceRoboticCallLogList" parameterType="CompanyVoiceRoboticCallLog" resultMap="CompanyVoiceRoboticCallLogResult">
+        <include refid="selectCompanyVoiceRoboticCallLogVo"/>
+        <where>  
+            <if test="roboticId != null "> and robotic_id = #{roboticId}</if>
+            <if test="callerId != null "> and caller_id = #{callerId}</if>
+            <if test="wxClientId != null "> and wx_client_id = #{wxClientId}</if>
+            <if test="runFunction != null  and runFunction != ''"> and run_function = #{runFunction}</if>
+            <if test="runTime != null "> and run_time = #{runTime}</if>
+            <if test="runParam != null  and runParam != ''"> and run_param = #{runParam}</if>
+            <if test="result != null  and result != ''"> and result = #{result}</if>
+            <if test="status != null "> and status = #{status}</if>
+            <if test="createTime != null "> and create_time = #{createTime}</if>
+        </where>
+    </select>
+    
+    <select id="selectCompanyVoiceRoboticCallLogByLogId" parameterType="Long" resultMap="CompanyVoiceRoboticCallLogResult">
+        <include refid="selectCompanyVoiceRoboticCallLogVo"/>
+        where log_id = #{logId}
+    </select>
+        
+    <insert id="insertCompanyVoiceRoboticCallLog" parameterType="CompanyVoiceRoboticCallLog" useGeneratedKeys="true" keyProperty="logId">
+        insert into company_voice_robotic_call_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="roboticId != null">robotic_id,</if>
+            <if test="callerId != null">caller_id,</if>
+            <if test="wxClientId != null">wx_client_id,</if>
+            <if test="runFunction != null">run_function,</if>
+            <if test="runTime != null">run_time,</if>
+            <if test="runParam != null">run_param,</if>
+            <if test="result != null">result,</if>
+            <if test="status != null">status,</if>
+            <if test="createTime != null">create_time,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="roboticId != null">#{roboticId},</if>
+            <if test="callerId != null">#{callerId},</if>
+            <if test="wxClientId != null">#{wxClientId},</if>
+            <if test="runFunction != null">#{runFunction},</if>
+            <if test="runTime != null">#{runTime},</if>
+            <if test="runParam != null">#{runParam},</if>
+            <if test="result != null">#{result},</if>
+            <if test="status != null">#{status},</if>
+            <if test="createTime != null">#{createTime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateCompanyVoiceRoboticCallLog" parameterType="CompanyVoiceRoboticCallLog">
+        update company_voice_robotic_call_log
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="roboticId != null">robotic_id = #{roboticId},</if>
+            <if test="callerId != null">caller_id = #{callerId},</if>
+            <if test="wxClientId != null">wx_client_id = #{wxClientId},</if>
+            <if test="runFunction != null">run_function = #{runFunction},</if>
+            <if test="runTime != null">run_time = #{runTime},</if>
+            <if test="runParam != null">run_param = #{runParam},</if>
+            <if test="result != null">result = #{result},</if>
+            <if test="status != null">status = #{status},</if>
+        </trim>
+        where log_id = #{logId}
+    </update>
+
+    <delete id="deleteCompanyVoiceRoboticCallLogByLogId" parameterType="Long">
+        delete from company_voice_robotic_call_log where log_id = #{logId}
+    </delete>
+
+    <delete id="deleteCompanyVoiceRoboticCallLogByLogIds" parameterType="String">
+        delete from company_voice_robotic_call_log where log_id in 
+        <foreach item="logId" collection="array" open="(" separator="," close=")">
+            #{logId}
+        </foreach>
+    </delete>
+
+    <select id="selectNoResultLogByCallees" parameterType="com.fs.company.domain.CompanyVoiceRoboticCallees"  resultType="CompanyVoiceRoboticCallLog">
+        select * from company_voice_robotic_call_log where robotic_id = #{callees.roboticId} And caller_id = #{callees.id} And status = 1
+    </select>
+</mapper>

+ 36 - 0
fs-wx-task/src/main/java/com/fs/app/service/WxTaskService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fs.common.constant.Constants;
 import com.fs.common.constant.FsConstants;
@@ -16,6 +17,7 @@ import com.fs.company.service.ICompanyVoiceRoboticService;
 import com.fs.company.service.ICompanyWxAccountService;
 import com.fs.company.service.ICompanyWxClientService;
 import com.fs.company.service.ICompanyWxDialogService;
+import com.fs.company.service.impl.CompanyVoiceRoboticCallLogServiceImpl;
 import com.fs.company.service.impl.CompanyVoiceRoboticCalleesServiceImpl;
 import com.fs.company.service.impl.CompanyVoiceRoboticWxServiceImpl;
 import com.fs.company.util.ObjectPlaceholderResolver;
@@ -30,6 +32,8 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -104,6 +108,7 @@ public class WxTaskService {
         addAccountList.forEach(e -> {
             CompanyWxClient client = clientMap.get(e.getId());
             if(client != null){
+
                 String task = redisCache.getCacheObject(Constants.TASK_ID + client.getRoboticId());
                 log.info("ROBOTIC-ID:{},CLIENT-ID:{},当前任务执行状态:{}", client.getRoboticId(), client.getId(), task);
                 if(StringUtils.isNotEmpty(task) && Constants.ADD_WX.equals(task)){
@@ -111,6 +116,13 @@ public class WxTaskService {
                     CrmCustomer crmCustomer = crmCustomerService.selectCrmCustomerById(client.getCustomerId());
                     String newTxt = objectPlaceholderResolver.resolvePlaceholders(crmCustomer, dialog.getTemplateDetails());
                     AddContactVo vo = friendService.addContact(e.getId(), crmCustomer.getMobile(), newTxt, client.getId());
+                    JSONObject runParam = new JSONObject();
+                    runParam.put("id",e.getId());
+                    runParam.put("mobile",crmCustomer.getMobile());
+                    runParam.put("txt",newTxt);
+                    runParam.put("clientId",client.getId());
+                    CompanyVoiceRoboticCallLog addLog = CompanyVoiceRoboticCallLog.initCallLogByType(Constants.ADD_WX,
+                            runParam.toJSONString(),client.getId(),client.getRoboticId());
                     log.info("ROBOTIC-ID:{},CLIENT-ID:{},执行加微:{},客户:{}-{},使用话术:{}", client.getRoboticId(), client.getId(), e.getId(), client.getCustomerId(), crmCustomer.getCustomerName(), dialog.getName());
                     if(vo.isSuccess()){
                         e.setLastAddWxTime(LocalDateTime.now());
@@ -120,9 +132,14 @@ public class WxTaskService {
                         client.setWxV3(vo.getV3());
                         client.setWxV4(vo.getV4());
                         addList.add(client);
+                        addLog.setStatus(2);
+                        addLog.setResult(JSON.toJSONString(vo));
                     }else{
                         log.error("ROBOTIC-ID:{},加微失败:{}", client.getRoboticId(), vo);
+                        addLog.setStatus(3);
+                        addLog.setResult(JSON.toJSONString(vo));
                     }
+                    asyncSaveCompanyVoiceRoboticCallLog(addLog);
                 }else{
                     log.error("ROBOTIC-ID:{},当前任务没有执行加微任务", client.getRoboticId());
                 }
@@ -477,6 +494,10 @@ public class WxTaskService {
                         log.error("单项任务执行或删除失败,taskId: {},callerId:{}", taskId, callerId,throwable);
                         return null;
                     });
+                }else{
+                    // todo 加入新逻辑 没有到执行时间的待执行任务 检查上一个任务的执行状态
+                    // 如果是已经完成的状态 修改待执行时间为现在 下次进入任务会直接执行对应的下个任务
+
                 }
             });
 
@@ -488,4 +509,19 @@ public class WxTaskService {
             }
         }
     }
+
+    @Autowired
+    CompanyVoiceRoboticCallLogServiceImpl companyVoiceRoboticCallLogService;
+    /**
+     * 记录任务执行日志
+     * @param companyVoiceRoboticCallLog
+     */
+
+    public void asyncSaveCompanyVoiceRoboticCallLog(CompanyVoiceRoboticCallLog companyVoiceRoboticCallLog){
+        try{
+            companyVoiceRoboticCallLogService.asyncInsertCompanyVoiceRoboticCallLog(companyVoiceRoboticCallLog);
+        }catch (Exception ex){
+            log.error("记录任务执行日志失败:失败数据:{}",companyVoiceRoboticCallLog, ex);
+        }
+    }
 }