增加批量推送

This commit is contained in:
wulin 2020-11-04 11:33:23 +08:00
parent d76be4273e
commit ebed4d36dd
4 changed files with 80 additions and 1 deletions

View File

@ -267,7 +267,8 @@ public class DingTalkUtil {
}
public String sendSingleActionCardMSG(String appid, StaffEntity staff, String title, String marDown, String singleTitle, String singleUrl, String token) {
public String sendSingleActionCardMSG(String appid, StaffEntity staff, String title, String marDown,
String singleTitle, String singleUrl, String token) {
String msg = "OK";
ThirdMsgSendRecord thirdMsgSendRecord = new ThirdMsgSendRecord();

View File

@ -46,6 +46,10 @@ public class StaffSimpleInfo implements Serializable {
private String employeeId;
//头像
private String avatar;
//本次发起任务的id
private Long startId;
//本次发起绩效的id
private Long recordId;
}

View File

@ -3,6 +3,7 @@ package com.lz.modules.flow.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.emun.ChartOptType;
import com.lz.common.emun.CheckStaffType;
import com.lz.common.emun.WorkMsgTypeEnum;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.app.entity.StaffEntity;
@ -13,6 +14,7 @@ import com.lz.modules.flow.dao.FlowStartMapper;
import com.lz.modules.flow.entity.*;
import com.lz.modules.flow.model.*;
import com.lz.modules.flow.service.*;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.performance.service.ResultTagetLibService;
import com.lz.modules.sys.entity.app.ResultDetail;
import com.lz.modules.sys.entity.app.ResultRecord;
@ -81,6 +83,9 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
@Autowired
private FlowChartRoleService flowChartRoleService;
@Autowired
private DingtalkBusiness dingtalkBusiness;
@ -152,6 +157,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
case 5:
return R.error(groupStaffs.getEvaluationGroup().getName() + "——初始化考核流程失败");
}
dingtalkBusiness.sendWorkMSGWithThread(staffSimpleInfos, WorkMsgTypeEnum.START_WORK.getType());
}
return R.ok("发起成功").put("data", flowStart);
@ -243,6 +249,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
case 5:
return R.error(evaluationGroup.getName() + "——初始化考核流程失败");
}
dingtalkBusiness.sendWorkMSGWithThread(staffIds, WorkMsgTypeEnum.START_WORK.getType());
}
return R.ok("发起成功").put("data", flowStart);
}
@ -461,6 +468,8 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
//下面初始化参与人员
for (StaffSimpleInfo staffInfo:staffIds
) {
staffInfo.setStartId(flowStart.getId());
EvaluationStartStaff evaluationStartStaff = new EvaluationStartStaff();
evaluationStartStaff.setEvaluationId(evaluationGroup.getId());
evaluationStartStaff.setEvaluationName(evaluationGroup.getName());
@ -563,6 +572,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
roleJSON = roleJSON.replace(",]", "]");
resultRecord.setFlowStaffIdRole(roleJSON);
resultRecordService.insertResultRecord(resultRecord);
staffInfo.setRecordId(resultRecord.getId());
//下面生成实际的考核流程
resultRecordService.initFlowRecord(resultRecord.getId());
//下面生成ResultDetail对象

View File

@ -8,6 +8,7 @@ import com.lz.common.utils.R;
import com.lz.modules.app.dao.StaffDao;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.entity.StaffOccupationEntity;
import com.lz.modules.app.entity.StaffSimpleInfo;
import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.app.service.StaffOccupationService;
@ -20,6 +21,7 @@ import com.lz.modules.third.entity.ThirdAppConfig;
import com.lz.modules.third.service.ThirdAppConfigService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -62,6 +64,8 @@ public class DingtalkBusiness {
@Resource
StaffDao staffDao;
@Value("${dingtalk.appid}")
private String appid;
/**
* 获取组织架构信息并录入到数据库
@ -187,6 +191,22 @@ public class DingtalkBusiness {
return sendWorkMSGByEntity(appid, fromStaffEntity, toStaffEntity, workMsgTypeEnum, "https://www.baidu.com");
}
public String sendWorkMSGWithAsyn(List<Long> toStaffids, int type) {
List<StaffSimpleInfo> staffSimpleInfos = staffService.selectStaffSimpleInfos(toStaffids);
return sendWorkMSGWithThread(staffSimpleInfos, type);
}
public String sendWorkMSGWithThread(List<StaffSimpleInfo> toStaffids, int type) {
WorkMsgTypeEnum workMsgTypeEnum = WorkMsgTypeEnum.findRoleTypeByCode(type);
ThreadSendMessage threadSendMessage = new ThreadSendMessage(toStaffids, workMsgTypeEnum, appid);
Thread thread = new Thread(threadSendMessage);
thread.start();
return "OK";
}
public String sendWorkMSGByEntity(String appid, StaffEntity fromStaffEntity, StaffEntity toStaffEntity,
WorkMsgTypeEnum workMsgTypeEnum, String url){
if(toStaffEntity != null && fromStaffEntity != null){
@ -250,4 +270,48 @@ public class DingtalkBusiness {
logger.info("token的token_code不存在");
return R.error("未授权登录");
}
public class ThreadSendMessage implements Runnable{
List<StaffSimpleInfo> toStaffids;
WorkMsgTypeEnum workMsgTypeEnum;
String appid;
String url = "";
public ThreadSendMessage(List<StaffSimpleInfo> toStaffids, WorkMsgTypeEnum typeEnum, String appid){
this.toStaffids = toStaffids;
workMsgTypeEnum = typeEnum;
this.appid = appid;
}
@Override
public void run() {
logger.info("开始批量推送消息,数量{}, appid", toStaffids.size(), appid);
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig);
for (StaffSimpleInfo info:toStaffids
) {
if(token != null && token.length() > 0){
//下面防止第二次发送消息时钉钉不推送
if(url.contains("?")){
url += "&halokit=" + System.currentTimeMillis();
}else{
url += "?halokit=" + System.currentTimeMillis();
}
url = URLEncoder.encode(url);
/* url = "dingtalk://dingtalkclient/action/openapp?corpid=" + thirdAppConfig.getCorpId() +
"&container_type=work_platform&app_id=0_" + appid + "&redirect_type=jump&redirect_url=" + url;*/
url = "dingtalk://dingtalkclient/page/link?pc_slide=true&url=" + url;
String content = workMsgTypeEnum.getContent().replace("@", info.getName());
StaffEntity entity = new StaffEntity();
entity.setId(info.getId());
entity.setEmployeeId(info.getEmployeeId());
dingTalkUtil.sendSingleActionCardMSG(appid, entity, workMsgTypeEnum.getTitle(),
content, workMsgTypeEnum.getBtnText(), url, token);
}else{
logger.info("ThreadSendMessage token无效"); ;
}
}
}
}
}