|
|
@@ -5,7 +5,6 @@ import com.fs.common.constant.Constants;
|
|
|
import com.fs.common.core.redis.RedisCacheT;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
-import com.fs.common.utils.http.HttpUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.*;
|
|
|
@@ -20,10 +19,10 @@ import com.fs.crm.service.impl.CrmCustomerServiceImpl;
|
|
|
import com.fs.enums.ExecutionStatusEnum;
|
|
|
import com.fs.enums.NodeTypeEnum;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
-import com.fs.wxcid.domain.CidIpadServer;
|
|
|
import com.fs.wxcid.domain.WxContact;
|
|
|
import com.fs.wxcid.mapper.CidIpadServerMapper;
|
|
|
import com.fs.wxcid.mapper.WxContactMapper;
|
|
|
+import com.fs.wxwork.service.WxIpadService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.util.Date;
|
|
|
@@ -50,7 +49,8 @@ public class AiAddWxTaskNewNode extends AbstractWorkflowNode {
|
|
|
private static final ObjectPlaceholderResolver objectPlaceholderResolver = SpringUtils.getBean(ObjectPlaceholderResolver.class);
|
|
|
private static final ISysConfigService sysConfigService = SpringUtils.getBean(ISysConfigService.class);
|
|
|
private static final CidIpadServerMapper cidIpadServerMapper = SpringUtils.getBean(CidIpadServerMapper.class);
|
|
|
- private static final String ADDWX_POST_URL = "/app/common/addWxAction";
|
|
|
+ private static final WxIpadService wxService = SpringUtils.getBean(WxIpadService.class);
|
|
|
+// private static final String ADDWX_POST_URL = "/app/common/addWxAction";
|
|
|
/**
|
|
|
* 默认加微超时时间(分钟)
|
|
|
*/
|
|
|
@@ -104,8 +104,12 @@ public class AiAddWxTaskNewNode extends AbstractWorkflowNode {
|
|
|
update.setId(roboticBusiness.getWxClientId());
|
|
|
companyWxClientMapper.updateCompanyWxClient(update);
|
|
|
super.asyncWorkflowForBlockingNode(context.getWorkflowInstanceId(), context.getCurrentNodeKey(), context, ExecutionStatusEnum.PAUSED);
|
|
|
- pendingAddWx(wxQuery.getAccountId(),wxQuery.getRemark(),wxQuery.getPhone(),addWxConfig.getDialogId(),wxQuery.getCrmUserId());
|
|
|
- doneAddwx(context.getWorkflowInstanceId());
|
|
|
+ pendingAddWx(wxQuery.getAccountId(), wxQuery.getRemark(),
|
|
|
+ wxQuery.getPhone(),
|
|
|
+ addWxConfig.getDialogId(),
|
|
|
+ wxQuery.getCrmUserId(),
|
|
|
+ context.getWorkflowInstanceId(),
|
|
|
+ context.getCurrentNodeKey());
|
|
|
return ExecutionResult.paused()
|
|
|
.outputData(context.getVariables())
|
|
|
.nextNodeKey("").build();
|
|
|
@@ -262,48 +266,53 @@ public class AiAddWxTaskNewNode extends AbstractWorkflowNode {
|
|
|
|
|
|
/**
|
|
|
* 发起加微请求
|
|
|
- * @param accountId 微信账号ID
|
|
|
- * @param remark 备注
|
|
|
- * @param phone 手机号
|
|
|
- * @param dialogId 话术ID
|
|
|
- * @param crmUserId CRM用户ID
|
|
|
+ * @param accountId
|
|
|
+ * @param remark
|
|
|
+ * @param phone
|
|
|
+ * @param dialogId
|
|
|
+ * @param crmUserId
|
|
|
+ * @param instanceId
|
|
|
+ * @param nodeKey
|
|
|
*/
|
|
|
- private void pendingAddWx(Long accountId, String remark, String phone, Long dialogId, Long crmUserId) {
|
|
|
- // 1. 获取基础数据
|
|
|
- CompanyWxAccount companyWxAccount = companyWxAccountMapper.selectCompanyWxAccountById(accountId);
|
|
|
- if (companyWxAccount == null) {
|
|
|
- throw new CustomException("未找到对应的微信账号配置, accountId: " + accountId);
|
|
|
- }
|
|
|
+ private void pendingAddWx(Long accountId, String remark, String phone, Long dialogId, Long crmUserId,String instanceId,String nodeKey) {
|
|
|
+ try {
|
|
|
+ // 1. 获取基础数据
|
|
|
+ CompanyWxAccount companyWxAccount = companyWxAccountMapper.selectCompanyWxAccountById(accountId);
|
|
|
+ if (companyWxAccount == null) {
|
|
|
+ throw new CustomException("未找到对应的微信账号配置, accountId: " + accountId);
|
|
|
+ }
|
|
|
|
|
|
- CompanyWxDialog dialog = companyWxDialogMapper.selectCompanyWxDialogById(dialogId);
|
|
|
- if (dialog == null) {
|
|
|
- throw new CustomException("未找到对应的对话模板, dialogId: " + dialogId);
|
|
|
- }
|
|
|
+ CompanyWxDialog dialog = companyWxDialogMapper.selectCompanyWxDialogById(dialogId);
|
|
|
+ if (dialog == null) {
|
|
|
+ throw new CustomException("未找到对应的对话模板, dialogId: " + dialogId);
|
|
|
+ }
|
|
|
|
|
|
- CrmCustomer crmCustomer = crmCustomerService.selectCrmCustomerById(crmUserId);
|
|
|
+ CrmCustomer crmCustomer = crmCustomerService.selectCrmCustomerById(crmUserId);
|
|
|
|
|
|
- // 2. 解析话术模板
|
|
|
- String newTxt = objectPlaceholderResolver.resolvePlaceholders(crmCustomer, dialog.getTemplateDetails());
|
|
|
+ // 2. 解析话术模板
|
|
|
+ String newTxt = objectPlaceholderResolver.resolvePlaceholders(crmCustomer, dialog.getTemplateDetails());
|
|
|
|
|
|
- // 3. 构建请求参数
|
|
|
- AddWxActionParam param = new AddWxActionParam();
|
|
|
- param.setWxId(companyWxAccount.getWxNo());
|
|
|
- param.setRemark(remark);
|
|
|
- param.setPhone(phone);
|
|
|
- param.setApplyMsg(newTxt);
|
|
|
- CidIpadServer cidIpadServer = cidIpadServerMapper.selectCidIpadServerById(companyWxAccount.getServerId());
|
|
|
- if (null == cidIpadServer || StringUtils.isBlank(cidIpadServer.getUrl())) {
|
|
|
- throw new CustomException("加微接口地址未配置");
|
|
|
+ // 3. 构建请求参数
|
|
|
+ AddWxActionParam param = new AddWxActionParam();
|
|
|
+ param.setWxId(companyWxAccount.getWxNo());
|
|
|
+ param.setRemark(remark);
|
|
|
+ param.setPhone(phone);
|
|
|
+ param.setApplyMsg(newTxt);
|
|
|
+ param.setServerId(companyWxAccount.getServerId());
|
|
|
+ JSONObject bizJson = new JSONObject()
|
|
|
+ .fluentPut("instanceId",instanceId)
|
|
|
+ .fluentPut("nodeKey",nodeKey)
|
|
|
+ .fluentPut("accountId",companyWxAccount.getId());
|
|
|
+ param.setBizJson(bizJson.toJSONString());
|
|
|
+ wxService.addWx(param);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new CustomException("发起加微请求异常, phone: " + phone + ", error: " + ex.getMessage());
|
|
|
}
|
|
|
- // 4. 从系统配置获取加微接口地址
|
|
|
- String addWxUrl = cidIpadServer.getUrl() + ADDWX_POST_URL;
|
|
|
+ }
|
|
|
|
|
|
- // 5. 发送 HTTP 请求
|
|
|
- try {
|
|
|
- String result = HttpUtils.sendPost(addWxUrl, JSONObject.toJSONString(param));
|
|
|
- log.info("pendingAddWx: 加微任务提交成功, phone: {}, result: {}", phone, result);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CustomException("发起加微请求异常, phone: " + phone + ", error: " + e.getMessage());
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected void postExecute(ExecutionContext context, ExecutionResult result) {
|
|
|
+ super.postExecute(context, result);
|
|
|
+ doneAddwx(context.getWorkflowInstanceId());
|
|
|
}
|
|
|
}
|