Commit 050a939f by zhouhaibao

[+]新增java节点处理

1 parent 435a2ab8
Showing 25 changed files with 752 additions and 15 deletions
package cn.com.glsx.process.modules.mapper; package cn.com.glsx.process.modules.mapper;
import cn.com.glsx.process.modules.model.task.SopTaskDTO;
import com.github.pagehelper.PageInfo;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -14,4 +16,6 @@ public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> { ...@@ -14,4 +16,6 @@ public interface SopInstNodeMapper extends CommonBaseMapper<SopInstNode> {
List<SopInstNode> findByInstId(@Param("instId") String instId); List<SopInstNode> findByInstId(@Param("instId") String instId);
int resetInstNodeDailyCount(@Param("instId") String instId); int resetInstNodeDailyCount(@Param("instId") String instId);
PageInfo<SopTaskDTO> findPageListByInstId(@Param("instId")String instId);
} }
\ No newline at end of file \ No newline at end of file
...@@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Param; ...@@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@Mapper @Mapper
public interface UserMapper extends CommonBaseMapper<User> { public interface UserServiceMapper extends CommonBaseMapper<User> {
List<User> selectList(UserSearch search); List<User> selectList(UserSearch search);
......
package cn.com.glsx.process.modules.model.task;
import lombok.Data;
@Data
public class SopTaskDTO {
/**
* 实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态
*/
private String instId;
/**
* 节点id
*/
private Integer nodeId;
private String nodeParam;
/**
* 营销计划
*/
private String plan;
/**
* 触达方式
*/
private Integer taskType;
/**
* 今日营销客户总数
*/
private int todayCusCount;
/**
* 累计营销客户数
*/
private int totalCusCount;
/**
* 今日下发任务总数
*/
private int todayTaskCount;
/**
* 累计下发任务总数
*/
private int totalTaskCount;
}
package cn.com.glsx.process.modules.model.task;
import cn.hutool.db.Page;
import lombok.Data;
@Data
public class SopTaskSearch extends Page {
/**
* 实例id
*/
private String instId;
}
...@@ -90,6 +90,11 @@ ...@@ -90,6 +90,11 @@
<version>2.4.0</version> <version>2.4.0</version>
</dependency> </dependency>
<dependency>
<groupId>cn.com.glsx</groupId>
<artifactId>platform-execute-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker --> <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency> <dependency>
......
package cn.com.glsx.process.modules.controller; package cn.com.glsx.process.modules.controller;
import cn.com.glsx.process.modules.model.task.SopTaskDTO;
import cn.com.glsx.process.modules.model.task.SopTaskSearch;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -106,4 +109,9 @@ public class SopInstController extends BaseController { ...@@ -106,4 +109,9 @@ public class SopInstController extends BaseController {
return "success"; return "success";
} }
@Operation(summary = "查询任务详情", description = "查询任务详情")
@GetMapping("/getTaskList")
public PageInfo<SopTaskDTO> getTaskList(@RequestParam SopTaskSearch search) {
return sopInstService.getTaskList(search);
}
} }
...@@ -5,6 +5,9 @@ import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDTO; ...@@ -5,6 +5,9 @@ import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDTO;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDetailDTO; import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneyDetailDTO;
import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneySearch; import cn.com.glsx.cdp.modules.model.customer.CustomerSopJourneySearch;
import cn.com.glsx.cdp.modules.model.customer.ModifySopJourneyStageRequest; import cn.com.glsx.cdp.modules.model.customer.ModifySopJourneyStageRequest;
import cn.com.glsx.execute.api.SopInstNodeTaskApiClient;
import cn.com.glsx.execute.modules.model.task.SopNodeTaskSearch;
import cn.com.glsx.execute.modules.model.task.SopNodeTaskStaticModel;
import cn.com.glsx.process.common.sysenum.ResultEnum; import cn.com.glsx.process.common.sysenum.ResultEnum;
import cn.com.glsx.process.exception.AdminException; import cn.com.glsx.process.exception.AdminException;
import cn.com.glsx.process.modules.converter.SopInstConverter; import cn.com.glsx.process.modules.converter.SopInstConverter;
...@@ -15,8 +18,11 @@ import cn.com.glsx.process.modules.entity.*; ...@@ -15,8 +18,11 @@ import cn.com.glsx.process.modules.entity.*;
import cn.com.glsx.process.modules.mapper.*; import cn.com.glsx.process.modules.mapper.*;
import cn.com.glsx.process.modules.model.*; import cn.com.glsx.process.modules.model.*;
import cn.com.glsx.process.modules.model.enums.*; import cn.com.glsx.process.modules.model.enums.*;
import cn.com.glsx.process.modules.model.task.SopTaskDTO;
import cn.com.glsx.process.modules.model.task.SopTaskSearch;
import cn.com.glsx.process.modules.rabbitmq.MsgProducer; import cn.com.glsx.process.modules.rabbitmq.MsgProducer;
import cn.com.glsx.process.modules.rabbitmq.RabbitMQConstants; import cn.com.glsx.process.modules.rabbitmq.RabbitMQConstants;
import cn.com.glsx.process.modules.sop.SopHelper;
import cn.com.glsx.process.util.FileUploadServerData; import cn.com.glsx.process.util.FileUploadServerData;
import cn.com.glsx.process.util.FileUploadUtil; import cn.com.glsx.process.util.FileUploadUtil;
import cn.com.glsx.process.util.SopTplParamHandler; import cn.com.glsx.process.util.SopTplParamHandler;
...@@ -71,6 +77,9 @@ public class SopInstService { ...@@ -71,6 +77,9 @@ public class SopInstService {
@Autowired @Autowired
private MsgProducer msgProducer; private MsgProducer msgProducer;
@Autowired
private SopInstNodeTaskApiClient sopInstNodeTaskApiClient;
/** /**
* 根据id查询 * 根据id查询
* *
...@@ -517,4 +526,40 @@ public class SopInstService { ...@@ -517,4 +526,40 @@ public class SopInstService {
getCustomersForExcel(search, customerSopJourneyDTOList); getCustomersForExcel(search, customerSopJourneyDTOList);
} }
} }
public PageInfo<SopTaskDTO> getTaskList(SopTaskSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize());
PageInfo<SopTaskDTO> sopInstNodeList=sopInstNodeMapper.findPageListByInstId(search.getInstId());
List<SopTaskDTO> sopTaskDTOList = sopInstNodeList.getList();
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(sopTaskDTOList)){
List<Integer> collect = sopTaskDTOList.stream().map(SopTaskDTO::getNodeId)
.collect(Collectors.toList());
SopNodeTaskSearch sopNodeTaskSearch=new SopNodeTaskSearch();
sopNodeTaskSearch.setInstId(search.getInstId());
sopNodeTaskSearch.setNodeIds(collect);
List<SopNodeTaskStaticModel> list = sopInstNodeTaskApiClient.findList(sopNodeTaskSearch);
sopTaskDTOList.forEach(index->{
String nodeParam = index.getNodeParam();
String day = SopHelper.getValueFromJsonString(nodeParam, "day");
String time = SopHelper.getValueFromJsonString(nodeParam, "time");
String taskType = SopHelper.getValueFromJsonString(nodeParam, "taskType");
index.setPlan(day+"天后 "+time);
index.setTaskType(Integer.parseInt(taskType));
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(list)){
List<SopNodeTaskStaticModel> sopNodeTaskStaticModelList = list.stream()
.filter(ind -> ind.getNodeId().equals(index.getInstId())).collect(
Collectors.toList());
if(org.apache.commons.collections4.CollectionUtils.isNotEmpty(sopNodeTaskStaticModelList)){
SopNodeTaskStaticModel sopNodeTaskStaticModel = sopNodeTaskStaticModelList.get(
0);
index.setTodayCusCount(sopNodeTaskStaticModel.getTodayCusCount());
index.setTodayTaskCount(sopNodeTaskStaticModel.getTodayTaskCount());
index.setTotalCusCount(sopNodeTaskStaticModel.getTotalCusCount());
index.setTotalTaskCount(sopNodeTaskStaticModel.getTodayTaskCount());
}
}
});
}
return sopInstNodeList;
}
} }
...@@ -27,7 +27,7 @@ import com.glsx.plat.jwt.util.JwtUtils; ...@@ -27,7 +27,7 @@ import com.glsx.plat.jwt.util.JwtUtils;
import cn.com.glsx.process.job.xxljob.core.ExecutorRouteStrategyEnum; import cn.com.glsx.process.job.xxljob.core.ExecutorRouteStrategyEnum;
import cn.com.glsx.process.modules.converter.UserConverter; import cn.com.glsx.process.modules.converter.UserConverter;
import cn.com.glsx.process.modules.entity.User; import cn.com.glsx.process.modules.entity.User;
import cn.com.glsx.process.modules.mapper.UserMapper; import cn.com.glsx.process.modules.mapper.UserServiceMapper;
import cn.com.glsx.process.modules.model.UserDTO; import cn.com.glsx.process.modules.model.UserDTO;
import cn.com.glsx.process.modules.model.UserSearch; import cn.com.glsx.process.modules.model.UserSearch;
import cn.com.glsx.process.modules.sop.execute.plugin.java.DynamicEngine; import cn.com.glsx.process.modules.sop.execute.plugin.java.DynamicEngine;
...@@ -50,14 +50,14 @@ public class UserDemoService { ...@@ -50,14 +50,14 @@ public class UserDemoService {
private JwtUtils jwtUtils; private JwtUtils jwtUtils;
@Resource @Resource
private UserMapper userMapper; private UserServiceMapper UserServiceMapper;
public User getById(Long id) { public User getById(Long id) {
return userMapper.selectById(id); return UserServiceMapper.selectById(id);
} }
public PageInfo<UserDTO> search(UserSearch search) { public PageInfo<UserDTO> search(UserSearch search) {
List<User> userList = userMapper.selectList(search); List<User> userList = UserServiceMapper.selectList(search);
List<UserDTO> list = new ArrayList<>(userList.size()); List<UserDTO> list = new ArrayList<>(userList.size());
userList.forEach(u -> list.add(UserConverter.INSTANCE.do2dto(u))); userList.forEach(u -> list.add(UserConverter.INSTANCE.do2dto(u)));
return new PageInfo<>(list); return new PageInfo<>(list);
...@@ -89,7 +89,7 @@ public class UserDemoService { ...@@ -89,7 +89,7 @@ public class UserDemoService {
//user.setEnableStatus(SysConstants.EnableStatus.enable.getCode()); //user.setEnableStatus(SysConstants.EnableStatus.enable.getCode());
user.setCreatedDate(new Date()); user.setCreatedDate(new Date());
userMapper.insertUseGeneratedKeys(user); UserServiceMapper.insertUseGeneratedKeys(user);
return user; return user;
} }
......
package cn.com.glsx.process.modules.sop;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ConfigUtils {
private static Properties props = new Properties();
private static final String CONFIG_FILE_PATTERN = "config-%s.properties";
static {
String environment = System.getenv("ENVIRONMENT"); // 或者 System.getProperty("ENVIRONMENT")
String configFile = String.format(CONFIG_FILE_PATTERN, environment != null ? environment : "default");
try (InputStream input = ConfigUtils.class.getClassLoader().getResourceAsStream(configFile)) {
if (input == null) {
throw new FileNotFoundException("Unable to find config file: " + configFile);
}
props.load(input);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static String getProperty(String key) {
return props.getProperty(key);
}
}
\ No newline at end of file \ No newline at end of file
...@@ -86,4 +86,9 @@ public class CustomerInfo { ...@@ -86,4 +86,9 @@ public class CustomerInfo {
* 跟进人userId * 跟进人userId
*/ */
private String userId; private String userId;
/**
* scrm的oneid
*/
private String scrmOneId;
} }
package cn.com.glsx.process.modules.sop; package cn.com.glsx.process.modules.sop;
import cn.com.glsx.entmicro.model.request.mass.LabelRequest;
import cn.com.glsx.process.modules.sop.java.model.CustOneIdModel;
import cn.com.glsx.process.modules.sop.java.model.LabelModel;
import cn.com.glsx.scrm.proxy.dto.RopResponse;
import com.github.pagehelper.Page;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.DateFormat; import java.text.DateFormat;
...@@ -15,6 +22,7 @@ import java.util.List; ...@@ -15,6 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
...@@ -36,6 +44,7 @@ import cn.com.glsx.process.redis.DistributedLockUtils; ...@@ -36,6 +44,7 @@ import cn.com.glsx.process.redis.DistributedLockUtils;
* @author kome * @author kome
* @date 2023年9月19日 下午4:35:12 * @date 2023年9月19日 下午4:35:12
*/ */
@Slf4j
public class SopHelper { public class SopHelper {
private static final String SOP_INST_LOCK_NAMESPACE = "lock.sop.inst."; private static final String SOP_INST_LOCK_NAMESPACE = "lock.sop.inst.";
...@@ -44,6 +53,10 @@ public class SopHelper { ...@@ -44,6 +53,10 @@ public class SopHelper {
private final static String secret = "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"; private final static String secret = "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b";
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-stoassistant/router";
private final static String getOneIdsByTagMethod = "scrm.api.sop.marketing.task.customer";
public static boolean lockInst(SopInst inst) { public static boolean lockInst(SopInst inst) {
String key = SOP_INST_LOCK_NAMESPACE + inst.getInstId(); String key = SOP_INST_LOCK_NAMESPACE + inst.getInstId();
return DistributedLockUtils.lock(key, 10 * 1000L, 3, 3 * 1000L); return DistributedLockUtils.lock(key, 10 * 1000L, 3, 3 * 1000L);
...@@ -108,17 +121,95 @@ public class SopHelper { ...@@ -108,17 +121,95 @@ public class SopHelper {
// 拿到过滤出阶段的客户 // 拿到过滤出阶段的客户
List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(key)), CustomerInfo.class); List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(key)), CustomerInfo.class);
String diffday = SopHelper.getValueFromJsonString(nodeParam, "day"); String diffday = SopHelper.getValueFromJsonString(nodeParam, "day");
String label = SopHelper.getValueFromJsonString(nodeParam, "day");
if (org.apache.commons.lang3.StringUtils.isEmpty(diffday)) { if (org.apache.commons.lang3.StringUtils.isEmpty(diffday)) {
return null; return null;
} }
if (CollectionUtils.isNotEmpty(customerInfoList)) { if (CollectionUtils.isNotEmpty(customerInfoList)) {
// 距离旅程相差天数过滤 // 距离旅程相差天数过滤
return customerInfoList.stream().filter(index -> SopHelper.diffDay(index.getSopJourneyStageEnterTime(), Integer.parseInt(diffday))) List<CustomerInfo> collect = customerInfoList.stream().filter(
index -> SopHelper.diffDay(index.getSopJourneyStageEnterTime(),
Integer.parseInt(diffday)))
.collect(Collectors.toList()); .collect(Collectors.toList());
if(StringUtils.isNotEmpty(label)){
// 过滤标签
if(CollectionUtils.isNotEmpty(collect)){
String orgId = collect.get(0).getOrgId();
List<String> customerOneIdByTag = findCustomerByTag(label, orgId);
collect=collect.stream().filter(index->customerOneIdByTag.contains(index.getScrmOneId())).collect(
Collectors.toList());
}
}
return collect;
} }
return null; return null;
} }
/**
* 查询标签客户
*
* @param label 标签集合
* @param merchantId 商户号
* @return 客户oneIds
*/
public static List<String> findCustomerByTag(String label,String merchantId){
List<LabelModel> labelModels = JSONObject.parseArray(label, LabelModel.class);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(5);
params.add("req.pageSize", Integer.MAX_VALUE + "");
params.add("req.pageNum", "1");
addParam("req.merchantId", merchantId, params, false);
if (CollectionUtils.isNotEmpty(labelModels)) {
for (int j = labelModels.size() - 1; j >= 0; j--) {
LabelModel labelModel = labelModels.get(j);
addParam("req.labelInfoList" + "[" + j + "]"+".groupId", labelModel.getGroupId(), params, false);
addParam("req.labelInfoList" + "[" + j + "]"+".groupName", labelModel.getGroupName(), params, false);
addParam("req.labelInfoList" + "[" + j + "]"+".groupType", labelModel.getGroupType(), params, false);
addParam("req.labelInfoList" + "[" + j + "]"+".labelId", labelModel.getLabelId(), params, false);
addParam("req.labelInfoList" + "[" + j + "]"+".labelName", labelModel.getLabelName(), params, false);
}
}
try {
RopResponse ropResponse = post(params, RopResponse.class, baseurl, getOneIdsByTagMethod);
if (("0").equals(ropResponse.getCode())) {
Page<String> getOneIdsByGroupIdList = new Page<String>();
getOneIdsByGroupIdList = converRopPage(ropResponse);
return new ArrayList<>(getOneIdsByGroupIdList.getResult());
}
} catch (Exception e) {
e.printStackTrace();
log.info("根据标签过滤用户oneId列表异常:{}", e);
}
return null;
}
private static void addParam(String name, Object val, MultiValueMap<String, String> params,
boolean needEncode) {
if (null != val) {
try {
String en_val = String.valueOf(val);
if (needEncode) {
en_val = URLEncoder.encode(String.valueOf(val), "UTF-8");
}
params.add(name, en_val);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
log.info("addParam==name;{},val:{},encode异常msg:{}", name, val, e.getMessage());
}
}
}
public static Page<String> converRopPage(RopResponse ropResponse) {
Page<String> converPage = new Page<String>();
Map<String, Object> page = (Map<String, Object>) ropResponse.getData();
CustOneIdModel parse = JSON.parseObject(JSONObject.toJSONString(page), CustOneIdModel.class);
converPage.setPageSize(parse.getPageSize());
converPage.setPageNum(parse.getPageNum());
converPage.setTotal(parse.getTotal());
converPage.addAll(
com.alibaba.nacos.client.naming.utils.CollectionUtils.isEmpty(parse.getOneIdList()) ? new ArrayList<>() : parse.getOneIdList());
return converPage;
}
public static Map<String, Object> objectToMap(Object obj) { public static Map<String, Object> objectToMap(Object obj) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Class<?> clazz = obj.getClass(); Class<?> clazz = obj.getClass();
......
package cn.com.glsx.process.modules.sop.java.example; package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.sop.ConfigUtils;
import cn.com.glsx.process.modules.sop.java.model.SopNodeTaskInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -15,6 +19,7 @@ import cn.com.glsx.process.modules.entity.SopInstNode; ...@@ -15,6 +19,7 @@ import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.CustomerInfo; import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult; import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper; import cn.com.glsx.process.modules.sop.SopHelper;
import org.springframework.web.client.RestTemplate;
/** /**
...@@ -23,12 +28,15 @@ import cn.com.glsx.process.modules.sop.SopHelper; ...@@ -23,12 +28,15 @@ import cn.com.glsx.process.modules.sop.SopHelper;
*/ */
public class ControllerDisTasksDemo { public class ControllerDisTasksDemo {
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-stoassistant/router"; private final static String baseurl = "/rop-scrm-stoassistant/router";
private final static String method = "scrm.api.sop.marketing.task.customer"; private final static String method = "scrm.api.sop.marketing.task.customer";
public static JSON execute(JSON param) { // 下发任务url
private final static String taskUrl = "/api/soptask/add";
public static JSON execute(JSON param) {
Map<String,Object> map=new HashMap<>();
// 将JSON字符串转换为Map // 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中 // 将Map中的数据放入MultiValueMap中
Object post = null; Object post = null;
...@@ -42,7 +50,7 @@ public class ControllerDisTasksDemo { ...@@ -42,7 +50,7 @@ public class ControllerDisTasksDemo {
// 营销的客户存在执行任务下发 // 营销的客户存在执行任务下发
if (CollectionUtils.isNotEmpty(customerInfoList)) { if (CollectionUtils.isNotEmpty(customerInfoList)) {
List<SopNodeTaskInfo> sopNodeTaskInfoList=new ArrayList<>();
String instSnapshot = sopInst.getInstSnapshot(); String instSnapshot = sopInst.getInstSnapshot();
multiValueMap.add("requestList[0].activityId", SopHelper.getValueFromJsonString(instSnapshot, "initMap", "customData","activityId")); multiValueMap.add("requestList[0].activityId", SopHelper.getValueFromJsonString(instSnapshot, "initMap", "customData","activityId"));
multiValueMap.add("requestList[0].nodeId", sopInstNode.getNodeId() + ""); multiValueMap.add("requestList[0].nodeId", sopInstNode.getNodeId() + "");
...@@ -66,12 +74,26 @@ public class ControllerDisTasksDemo { ...@@ -66,12 +74,26 @@ public class ControllerDisTasksDemo {
if(customerInfo.getTalkId()!=null) { if(customerInfo.getTalkId()!=null) {
multiValueMap.add("requestList[0].customerList[" + i + "].talkId", customerInfo.getTalkId()); multiValueMap.add("requestList[0].customerList[" + i + "].talkId", customerInfo.getTalkId());
} }
SopNodeTaskInfo sopNodeTaskInfo=new SopNodeTaskInfo();
sopNodeTaskInfo.setInstId(sopInst.getInstId());
sopNodeTaskInfo.setNodeId(sopInstNode.getNodeId());
sopNodeTaskInfo.setCustomerPhone(customerInfo.getCustomerPhone());
sopNodeTaskInfo.setStaffPhone(customerInfo.getFollowStaffPhone());
sopNodeTaskInfoList.add(sopNodeTaskInfo);
} }
try { try {
// 推送门店助手消息
System.out.println("入参" + JSONObject.toJSONString(multiValueMap)); System.out.println("入参" + JSONObject.toJSONString(multiValueMap));
post = SopHelper.post(multiValueMap, Object.class, baseurl, method); post = SopHelper.post(multiValueMap, Object.class, ConfigUtils.getProperty("scrm.baseurl")+baseurl, method);
System.out.println("返回" + JSONObject.toJSONString(post)); System.out.println("返回" + JSONObject.toJSONString(post));
map.put("sendTask",post);
// 新增任务记录
RestTemplate restTemplate = new RestTemplate();
Object o = restTemplate.postForObject(ConfigUtils.getProperty("scrm.sopurl")+taskUrl, sopNodeTaskInfoList, Object.class);
map.put("sendTask",post);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
package cn.com.glsx.process.modules.sop.java.example; package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.ConfigUtils;
import cn.com.glsx.process.modules.sop.CustomerInfo; import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult; import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper; import cn.com.glsx.process.modules.sop.SopHelper;
...@@ -25,7 +26,7 @@ import java.util.stream.Collectors; ...@@ -25,7 +26,7 @@ import java.util.stream.Collectors;
*/ */
public class ControllerFoundInsDemo { public class ControllerFoundInsDemo {
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-marketing/router"; private final static String baseurl = "/rop-scrm-marketing/router";
private final static String method = "marketing.api.supermarket.renewal.queryByVins"; private final static String method = "marketing.api.supermarket.renewal.queryByVins";
...@@ -43,7 +44,7 @@ public class ControllerFoundInsDemo { ...@@ -43,7 +44,7 @@ public class ControllerFoundInsDemo {
List<String> collect = customerInfoList.stream().filter(index -> StringUtils.isNotEmpty(index.getVin())).map(CustomerInfo::getVin).collect(Collectors.toList()); List<String> collect = customerInfoList.stream().filter(index -> StringUtils.isNotEmpty(index.getVin())).map(CustomerInfo::getVin).collect(Collectors.toList());
try { try {
multiValueMap.put("vins", collect); multiValueMap.put("vins", collect);
Object post = SopHelper.post(multiValueMap, Object.class, baseurl, method); Object post = SopHelper.post(multiValueMap, Object.class, ConfigUtils.getProperty("scrm.baseurl")+baseurl, method);
JSONObject json = (JSONObject) JSONObject.toJSON(post); JSONObject json = (JSONObject) JSONObject.toJSON(post);
Object data = json.get("data"); Object data = json.get("data");
Map<String, Object> stringObjectMap = (Map<String, Object>) (data); Map<String, Object> stringObjectMap = (Map<String, Object>) (data);
......
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.ConfigUtils;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchModel;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchSourceModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute 获取门店的企微客户
*/
public class ControllerGetEntCusDemo {
private final static String baseurl = "/rop-scrm-entmicro/router";
private final static String method = "entmicro.api.customer.sendCustomerToSop";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
SopInst sopInst = excustorParam.getSopInst();
String instParam = sopInst.getInstParam();
try {
String instDefalutName = SopHelper.getValueFromJsonString(instParam, "stages", "stage1",
"value");
multiValueMap.add("merchantId",sopInst.getGrantId()+"");
multiValueMap.add("instId",sopInst.getInstId());
multiValueMap.add("instDefalutName",instDefalutName);
System.out.println("入参" + JSONObject.toJSONString(multiValueMap));
post = SopHelper.post(multiValueMap, Object.class, ConfigUtils.getProperty("scrm.baseurl")+ baseurl, method);
System.out.println("返回" + JSONObject.toJSONString(post));
} catch (Exception e) {
throw new RuntimeException(e);
}
return (JSONObject) JSONObject.toJSON(post);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.ConfigUtils;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchModel;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchSourceModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute 1.短信发送 2.企微群发 3.企微朋友圈
*/
public class ControllerSendMessageDemo {
private final static String sendCustomerUrl = "/sop/api/execute/sendCustomer";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
Map<String, Object> resultData = excustorParam.getResultData();
SopInst sopInst = excustorParam.getSopInst();
SopInstNode sopInstNode = excustorParam.getSopInstNode();
String nodeParam = sopInstNode.getNodeParam();
List<CustomerInfo> customerInfoList = SopHelper.getMeetWithCustomer(sopInstNode, resultData);
// 营销的客户存在
if (CollectionUtils.isNotEmpty(customerInfoList)) {
// 获取营销类型 1.短信发送 2.企微群发 3.企微朋友圈
String sendType = SopHelper.getValueFromJsonString(nodeParam, "sendType");
if (StringUtils.isNotEmpty(sendType)) {
List<CustomerTouchModel> customerTouchModels = new ArrayList<>();
Map<String, List<CustomerInfo>> collect = customerInfoList.stream()
.collect(Collectors.groupingBy(CustomerInfo::getUserId));
Iterator<Entry<String, List<CustomerInfo>>> iterator = collect.entrySet().iterator();
while (iterator.hasNext()) {
CustomerTouchModel customerTouchModel = new CustomerTouchModel();
customerTouchModel.setSendType(Integer.parseInt(sendType));
Entry<String, List<CustomerInfo>> next = iterator.next();
String key = next.getKey();
List<CustomerInfo> value = next.getValue();
switch (sendType) {
case "1":
buildMessageParam(customerTouchModel, value, nodeParam, sopInst, sopInstNode);
break;
case "2":
case "3":
buildMassParam(customerTouchModel, key, value, nodeParam, sopInst, sopInstNode);
break;
default:
break;
}
customerTouchModels.add(customerTouchModel);
}
RestTemplate restTemplate = new RestTemplate();
post = restTemplate.postForObject(ConfigUtils.getProperty("scrm.sopurl")+sendCustomerUrl, customerTouchModels, Object.class);
}
return (JSONObject) JSONObject.toJSON(post);
}
return null;
}
private static void buildMonmentParam(CustomerTouchModel customerTouchModel, String key,
List<CustomerInfo> value, String nodeParam, SopInst sopInst, SopInstNode sopInstNode) {
}
/**
* 构建短信参数
*
* @param customerTouchModel 参数
* @param key 员工id
* @param value 客户信息
* @param nodeParam 节点入参信息
* @param sopInst 实例信息
* @param sopInstNode 实例节点信息
*/
private static void buildMassParam(CustomerTouchModel customerTouchModel, String key,
List<CustomerInfo> value, String nodeParam, SopInst sopInst, SopInstNode sopInstNode) {
buildDefaultParam(customerTouchModel, sopInst, sopInstNode, nodeParam);
List<String> collect = value.stream()
.filter(index -> StringUtils.isNotEmpty(index.getCustomerPhone()))
.map(CustomerInfo::getExternalUserId).collect(
Collectors.toList());
customerTouchModel.setSendExternalUserId(collect);
customerTouchModel.setSendUserId(key);
}
private static void buildDefaultParam(CustomerTouchModel customerTouchModel, SopInst sopInst,
SopInstNode sopInstNode, String nodeParam) {
String contentlists = SopHelper.getValueFromJsonString(nodeParam, "contentlists");
customerTouchModel.setInstId(sopInst.getInstId());
customerTouchModel.setMerchantNo(sopInst.getGrantId());
customerTouchModel.setNodeId(sopInstNode.getNodeId());
customerTouchModel.setContentlists(JSONObject.parseArray(contentlists,
CustomerTouchSourceModel.class));
String valueFromJsonString = SopHelper.getValueFromJsonString(sopInst.getInstSnapshot(),
"initMap", "supMerchantNo");
customerTouchModel.setSupMerchantNo(Integer.parseInt(valueFromJsonString));
}
/**
* 构建短信参数
*
* @param customerTouchModel 参数
* @param key 员工id
* @param value
* @param nodeParam 节点入参信息
* @param sopInst 实例信息
* @param sopInstNode 实例节点信息
*/
private static void buildMessageParam(CustomerTouchModel customerTouchModel,
List<CustomerInfo> value, String nodeParam, SopInst sopInst, SopInstNode sopInstNode) {
buildDefaultParam(customerTouchModel, sopInst, sopInstNode, nodeParam);
List<String> phones = value.stream()
.filter(index -> StringUtils.isNotEmpty(index.getCustomerPhone()))
.map(CustomerInfo::getCustomerPhone).collect(
Collectors.toList());
customerTouchModel.setSendPhone(phones);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.ConfigUtils;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchModel;
import cn.com.glsx.process.modules.sop.java.model.CustomerTouchSourceModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute 发送提醒
*/
public class ControllerSendRemindDemo {
private final static String sendStaffUrl = "/sop/api/execute/sendStaff";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
Map<String, Object> resultData = excustorParam.getResultData();
SopInst sopInst = excustorParam.getSopInst();
SopInstNode sopInstNode = excustorParam.getSopInstNode();
String nodeParam = sopInstNode.getNodeParam();
List<CustomerInfo> customerInfoList = SopHelper.getMeetWithCustomer(sopInstNode, resultData);
// 营销的客户存在
if (CollectionUtils.isNotEmpty(customerInfoList)) {
List<String> filterUserList = null;
// 获取营销类型 发送提醒
String sendType = SopHelper.getValueFromJsonString(nodeParam, "sendType");
String userIds = SopHelper.getValueFromJsonString(nodeParam, "userIds");
if (StringUtils.isNotEmpty(userIds)) {
filterUserList = Arrays.asList(userIds.split(","));
}
if (StringUtils.isNotEmpty(sendType)) {
List<CustomerTouchModel> customerTouchModels = new ArrayList<>();
Map<String, List<CustomerInfo>> collect = customerInfoList.stream()
.collect(Collectors.groupingBy(CustomerInfo::getUserId));
Iterator<Entry<String, List<CustomerInfo>>> iterator = collect.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, List<CustomerInfo>> next = iterator.next();
String key = next.getKey();
List<CustomerInfo> value = next.getValue();
// 过滤条件为空,或者过滤条件存在
if (CollectionUtils.isEmpty(filterUserList) || (CollectionUtils.isNotEmpty(filterUserList)
&& filterUserList.contains(key))) {
CustomerTouchModel customerTouchModel = new CustomerTouchModel();
buildDefaultParam(customerTouchModel, sopInst, sopInstNode, nodeParam);
customerTouchModel.setSendType(Integer.parseInt(sendType));
customerTouchModel.setSendUserId(key);
List<String> externalUserList = value.stream()
.filter(index -> StringUtils.isNotEmpty(index.getExternalUserId()))
.map(CustomerInfo::getExternalUserId).collect(
Collectors.toList());
customerTouchModel.setSendExternalUserId(externalUserList);
customerTouchModels.add(customerTouchModel);
}
}
RestTemplate restTemplate = new RestTemplate();
post = restTemplate.postForObject(ConfigUtils.getProperty("scrm.sopurl")+sendStaffUrl, customerTouchModels, Object.class);
}
return (JSONObject) JSONObject.toJSON(post);
}
return null;
}
private static void buildDefaultParam(CustomerTouchModel customerTouchModel, SopInst sopInst,
SopInstNode sopInstNode, String nodeParam) {
String notice = SopHelper.getValueFromJsonString(nodeParam, "notice");
String msgtype = SopHelper.getValueFromJsonString(nodeParam, "msgtype");
customerTouchModel.setInstId(sopInst.getInstId());
customerTouchModel.setNotice(notice);
customerTouchModel.setMsgtype(msgtype);
customerTouchModel.setMerchantNo(sopInst.getGrantId());
customerTouchModel.setNodeId(sopInstNode.getNodeId());
String valueFromJsonString = SopHelper.getValueFromJsonString(sopInst.getInstSnapshot(),
"initMap", "supMerchantNo");
customerTouchModel.setSupMerchantNo(Integer.parseInt(valueFromJsonString));
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.sop.java.model;
import java.util.List;
import lombok.Data;
/**
* @author zhouhaibao
* @version 1.0
* @description: TODO
* @date 2022/2/18 13:48
*/
@Data
public class CustOneIdModel {
private List<String> oneIdList;
private int pageSize;
private int pageNum;
private int totalSize;
private int total;
}
package cn.com.glsx.process.modules.sop.java.model;
import java.util.List;
import lombok.Data;
/**
* 客户触达model
*/
@Data
public class CustomerTouchModel {
/**
* 发送类型
*/
private Integer sendType;
/**
* 发送手机号
*/
private List<String> sendPhone;
/**
* 发送员工
*/
private String sendUserId;
/**
* 发送外部联系人
*/
private List<String> sendExternalUserId;
/**
* 商户号
*/
private Integer merchantNo;
/**
* 实例id
*/
private String instId;
/**
* 节点id
*/
private Integer nodeId;
/**
* 授权商户号
*/
private Integer supMerchantNo;
/**
* 素材
*/
private List<CustomerTouchSourceModel> contentlists;
/**
* 通知的素材
*/
private String notice;
/**
* 通知类型
*/
private String msgtype;
}
package cn.com.glsx.process.modules.sop.java.model;
import lombok.Data;
/**
* 客户触达model
*/
@Data
public class CustomerTouchSourceModel {
private Integer attType;
private String attContent;
}
package cn.com.glsx.process.modules.sop.java.model;
import lombok.Data;
@Data
public class LabelModel {
private Integer groupId;
private String groupName;
private String groupType;
private Integer labelId;
private String labelName;
}
package cn.com.glsx.process.modules.sop.java.model;
import java.io.Serializable;
import lombok.Data;
@Data
public class SopNodeTaskInfo implements Serializable {
/**
* 实例id
*/
private String instId;
/**
* 节点id
*/
private Integer nodeId;
/**
* 外部联系人id
*/
private String externalUserid;
/**
* 手机号码
*/
private String customerPhone;
/**
* 员工userid
*/
private String userId;
/**
* 员工手机号
*/
private String staffPhone;
}
\ No newline at end of file \ No newline at end of file
scrm.baseurl=http://scrm.dev.glsx.com.cn
sop.baseurl=
\ No newline at end of file \ No newline at end of file
scrm.baseurl=http://scrm.test.glsx.com.cn
sop.baseurl=
\ No newline at end of file \ No newline at end of file
...@@ -34,7 +34,12 @@ ...@@ -34,7 +34,12 @@
node_id, node_name,node_type node_id, node_name,node_type
FROM sop_inst_node WHERE inst_id=#{instId} FROM sop_inst_node WHERE inst_id=#{instId}
</select> </select>
<select id="findPageListByInstId"
resultType="cn.com.glsx.process.modules.model.task.SopTaskDTO">
select inst_id as instId, node_id as nodeId,node_param as nodeParam from sop_inst_node where inst_id=#{instId} and node_param->'$.taskType' is not null
</select>
<update id="resetInstNodeDailyCount"> <update id="resetInstNodeDailyCount">
update sop_inst_node set daily_count=0 where inst_id=#{instId} update sop_inst_node set daily_count=0 where inst_id=#{instId}
</update> </update>
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.process.modules.mapper.UserMapper"> <mapper namespace="cn.com.glsx.process.modules.mapper.UserServiceMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.User"> <resultMap id="BaseResultMap" type="cn.com.glsx.process.modules.entity.User">
<id column="id" jdbcType="INTEGER" property="id"/> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="account" jdbcType="VARCHAR" property="account"/> <result column="account" jdbcType="VARCHAR" property="account"/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!