generated from dxfeng/secondev-wugang-dxfeng
消息发送动作流
This commit is contained in:
parent
77e5d9d367
commit
2e6e862846
|
|
@ -0,0 +1,163 @@
|
|||
package com.weaver.seconddev.entry.action;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.common.hrm.dao.HrmCommonEmployeeDao;
|
||||
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
|
||||
import com.weaver.seconddev.chapanda.feishu.util.Esb2FeishuOpenIdUtil;
|
||||
import com.weaver.seconddev.chapanda.feishu.util.Esb2FeishuSendMessageUtil;
|
||||
import com.weaver.seconddev.entry.entity.MessageSendConfig;
|
||||
import com.weaver.seconddev.entry.mapper.SendMessageMapper;
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/08/26
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("SendMessageAction")
|
||||
public class SendMessageAction implements EsbServerlessRpcRemoteInterface {
|
||||
|
||||
@Autowired
|
||||
Esb2FeishuSendMessageUtil esb2FeishuSendMessageUtil;
|
||||
|
||||
@Autowired
|
||||
SendMessageMapper sendMessageMapper;
|
||||
|
||||
@Autowired
|
||||
HrmCommonEmployeeDao hrmCommonEmployeeDao;
|
||||
|
||||
@Autowired
|
||||
Esb2FeishuOpenIdUtil esb2FeishuOpenIdUtil;
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
|
||||
// ID
|
||||
String employeeId = Convert.toStr(params.get("employeeId"), "");
|
||||
//if(null==employeeId){
|
||||
// return WeaResult.fail("动作流配置[employeeId]参数获取异常",true);
|
||||
//}
|
||||
|
||||
// 当前部门ID
|
||||
String departmentId = Convert.toStr(params.get("departmentId"), "");
|
||||
String templateId = (String) params.get("templateId");
|
||||
String templateVersionName = (String) params.get("templateVersionName");
|
||||
String content = (String) params.get("content");
|
||||
|
||||
log.error("params===" + JSON.toJSONString(params));
|
||||
|
||||
BaseParam baseParam = new BaseParam();
|
||||
MessageSendConfig messageSendConfig = sendMessageMapper.getMessageSendConfig(baseParam, departmentId);
|
||||
|
||||
while (messageSendConfig == null && StringUtils.isNotBlank(departmentId)) {
|
||||
String parentDepartmentId = sendMessageMapper.getParentDepartmentId(baseParam, departmentId);
|
||||
// 防止无限循环:如果parentDepartmentId为空或与当前departmentId相同,则跳出循环
|
||||
if (StringUtils.isBlank(parentDepartmentId) || parentDepartmentId.equals(departmentId)) {
|
||||
log.error("部门上下级数据异常,departmentId==" + departmentId);
|
||||
break;
|
||||
}
|
||||
departmentId = parentDepartmentId;
|
||||
messageSendConfig = sendMessageMapper.getMessageSendConfig(baseParam, departmentId);
|
||||
}
|
||||
|
||||
if (null == messageSendConfig) {
|
||||
return WeaResult.success();
|
||||
}
|
||||
log.error("messageSendConfig===" + JSON.toJSONString(messageSendConfig));
|
||||
|
||||
Set<String> userIdList = new HashSet<>();
|
||||
|
||||
if (1 == messageSendConfig.getZjsj() && StringUtils.isNotBlank(employeeId)) {
|
||||
// 发送消息给直接上级
|
||||
String superior = sendMessageMapper.getSuperior(baseParam, employeeId);
|
||||
if (StringUtils.isBlank(superior)) {
|
||||
superior = sendMessageMapper.getSuperiorFromEntry(baseParam, employeeId);
|
||||
}
|
||||
userIdList.add(superior);
|
||||
}
|
||||
|
||||
if (1 == messageSendConfig.getJgsjzjssj() && StringUtils.isNotBlank(employeeId)) {
|
||||
// 发送消息给间接上级
|
||||
String superior = sendMessageMapper.getSuperior(baseParam, employeeId);
|
||||
if (StringUtils.isBlank(superior)) {
|
||||
superior = sendMessageMapper.getSuperiorFromEntry(baseParam, employeeId);
|
||||
if (StringUtils.isNotBlank(superior)) {
|
||||
superior = sendMessageMapper.getSuperiorFromEntry(baseParam, superior);
|
||||
}
|
||||
} else {
|
||||
superior = sendMessageMapper.getSuperior(baseParam, superior);
|
||||
}
|
||||
userIdList.add(superior);
|
||||
}
|
||||
|
||||
if (1 == messageSendConfig.getXxsj() && StringUtils.isNotBlank(employeeId)) {
|
||||
// 发送消息给虚线上级
|
||||
String otherSuperior = sendMessageMapper.getOtherSuperior(baseParam, employeeId);
|
||||
if (StringUtils.isBlank(otherSuperior)) {
|
||||
otherSuperior = sendMessageMapper.getOtherSuperiorFromEntry(baseParam, employeeId);
|
||||
}
|
||||
userIdList.add(otherSuperior);
|
||||
}
|
||||
|
||||
Map<String, Object> departmentCustomData = sendMessageMapper.getDepartmentCustomData(baseParam, departmentId);
|
||||
if (1 == messageSendConfig.getBmfzr()) {
|
||||
// 发送消息给部门负责人
|
||||
String bmfzr = Convert.toStr(departmentCustomData.get("bmfzr"), "");
|
||||
userIdList.add(bmfzr);
|
||||
}
|
||||
|
||||
if (1 == messageSendConfig.getTbmyg()) {
|
||||
// 发送消息给同部门员工
|
||||
List<String> employeeIdsByDeptId = sendMessageMapper.getEmployeeIdsByDeptId(baseParam, departmentId);
|
||||
userIdList.addAll(employeeIdsByDeptId);
|
||||
}
|
||||
|
||||
if (1 == messageSendConfig.getHrbp()) {
|
||||
// 发送消息给HRBP
|
||||
String hrbp = Convert.toStr(departmentCustomData.get("hrbp"), "");
|
||||
userIdList.add(hrbp);
|
||||
}
|
||||
|
||||
if (1 == messageSendConfig.getFgld()) {
|
||||
// 发送消息给分管领导
|
||||
String fgld = Convert.toStr(departmentCustomData.get("fgld"), "");
|
||||
userIdList.add(fgld);
|
||||
}
|
||||
|
||||
|
||||
for (String userId : userIdList) {
|
||||
if (StringUtils.isBlank(userId)) {
|
||||
continue;
|
||||
}
|
||||
// 获取飞书ID
|
||||
String openId = this.esb2FeishuOpenIdUtil.queryFeishuOpenId(userId);
|
||||
if (StringUtils.isBlank(openId)) {
|
||||
log.error("userId=={},未获取到飞书openId", userId);
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
if (0 == messageSendConfig.getXxlx()) {
|
||||
// 文本消息
|
||||
esb2FeishuSendMessageUtil.senTextMessage(content, openId);
|
||||
} else if (1 == messageSendConfig.getXxlx()) {
|
||||
// 卡片消息
|
||||
esb2FeishuSendMessageUtil.senCardMessage(templateId, templateVersionName, openId, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return WeaResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.weaver.seconddev.entry.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/08/26
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class MessageSendConfig {
|
||||
private String bm;
|
||||
private Long ry;
|
||||
private int xxlx;
|
||||
private String ms;
|
||||
private int zjsj;
|
||||
private int jgsjzjssj;
|
||||
private int xxsj;
|
||||
private int bmfzr;
|
||||
private int tbmyg;
|
||||
private int hrbp;
|
||||
private int fgld;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.weaver.seconddev.entry.mapper;
|
||||
|
||||
import com.weaver.seconddev.entry.entity.MessageSendConfig;
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/08/26
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface SendMessageMapper {
|
||||
|
||||
String getParentDepartmentId(@Param("param") BaseParam param, @Param("departmentId") String departmentId);
|
||||
|
||||
MessageSendConfig getMessageSendConfig(@Param("param") BaseParam param, @Param("departmentId") String departmentId);
|
||||
|
||||
String getSuperior(@Param("param") BaseParam param, @Param("employeeId") String employeeId);
|
||||
|
||||
String getOtherSuperior(@Param("param") BaseParam param, @Param("employeeId") String employeeId);
|
||||
|
||||
String getSuperiorFromEntry(@Param("param") BaseParam param, @Param("employeeId") String employeeId);
|
||||
|
||||
String getOtherSuperiorFromEntry(@Param("param") BaseParam param, @Param("employeeId") String employeeId);
|
||||
|
||||
Map<String, Object> getDepartmentCustomData(@Param("param") BaseParam param, @Param("departmentId") String departmentId);
|
||||
|
||||
List<String> getEmployeeIdsByDeptId(@Param("param") BaseParam param, @Param("departmentId") String departmentId);
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?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.weaver.seconddev.entry.mapper.SendMessageMapper">
|
||||
|
||||
|
||||
<select id="getParentDepartmentId" resultType="java.lang.String">
|
||||
select parent
|
||||
from ${param.eteams}.department t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and id = #{departmentId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getMessageSendConfig" resultType="com.weaver.seconddev.entry.entity.MessageSendConfig">
|
||||
select bm,ry,xxlx,ms,zjsj,jgsjzjssj,xxsj,bmfzr,tbmyg,hrbp,fgld
|
||||
from ${param.eteams}.uf_xxgzb t1 where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and FIND_IN_SET(#{departmentId}, bm) > 0
|
||||
</select>
|
||||
|
||||
<select id="getSuperior" resultType="java.lang.String">
|
||||
select t1.superior from ${param.e10_common}.uf_jcl_employee_information t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.id = #{employeeId}
|
||||
</select>
|
||||
|
||||
<select id="getOtherSuperior" resultType="java.lang.String">
|
||||
select t1.other_superior from ${param.e10_common}.uf_jcl_employee_information t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.id = #{employeeId}
|
||||
</select>
|
||||
|
||||
<select id="getSuperiorFromEntry" resultType="java.lang.String">
|
||||
select t1.superior from ${param.e10_common}.uf_jcl_rzgl t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.id = #{employeeId}
|
||||
</select>
|
||||
|
||||
<select id="getOtherSuperiorFromEntry" resultType="java.lang.String">
|
||||
select t1.other_superior from ${param.e10_common}.uf_jcl_rzgl t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.id = #{employeeId}
|
||||
</select>
|
||||
|
||||
<select id="getDepartmentCustomData" resultType="java.util.Map">
|
||||
select t2.id as departmentId,t1.* from ${param.eteams}.${param.table_dept_cus} t1
|
||||
inner join ${param.eteams}.department t2 on t1.ID =t2.formdata
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t2.tenant_key = #{param.tenantKey} and t2.delete_type = 0
|
||||
and t2.id = #{departmentId}
|
||||
</select>
|
||||
|
||||
<select id="getEmployeeIdsByDeptId" resultType="java.lang.String">
|
||||
select t1.id from ${param.e10_common}.uf_jcl_employee_information t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.department = #{employeeId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue