1.代码发送钉钉警报
1.yml配置:
alert: dingdingToken: b77968b5ac150902f2a23858ecd1ba3e822521b3f21a47f047b07ef2ea9c5a86 // 机器人生成的群code services: groupMessage: // 执行的方法别名 owners: - 13616546418 // 员工手机号 lagAfterAlert: 3h // 间隔时间发送消息
2.代码:
package cn.nascent.ecrp.sg.asset.warning; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.nascent.ecrp.sg.alert.annotation.AlertPoint; import cn.nascent.ecrp.sg.asset.entity.AssetTransferTaskDO; import cn.nascent.ecrp.sg.asset.service.AssetMemberTransferService; import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.List; import java.util.Set; import java.util.stream.Collectors; /** * 导购资产(会员、会员+好友、好友、群)类型的转移异常进行警报 * * @author liuYiBo * @since 2023/4/28 10:39 */ @Component("cn.nascent.ecrp.sg.asset.warning.GuideAssertTransferWarning") @Slf4j public class GuideAssertTransferWarning { private final AssetMemberTransferService transferService; public GuideAssertTransferWarning(AssetMemberTransferService transferService) { this.transferService = transferService; } /** * 检查sg_customer_transfer_task * 员工资产转移半个小时还没转移完成进行钉钉警报 */ @AlertPoint("sg-service-asset-transfer:unTransferGuideAssert") public void unTransferGuideAsset() { DateTime dateTime = DateUtil.offsetMinute(DateUtil.parse(DateUtil.now()), -10); long unMarkCount = transferService.findUnTransferGuideAssetCount(dateTime.toDateStr()); if (unMarkCount > 0) { List<AssetTransferTaskDO> unTransferGuideAssetData = transferService.findUnTransferGuideAssetData(dateTime.toDateStr()); Set<Long> taskIdList = unTransferGuideAssetData.stream().map(AssetTransferTaskDO::getTaskId).collect(Collectors.toSet()); String message = "[导购资产转移] 在 " + dateTime + " 之前有" + unMarkCount + " 批(会员或者会员+好友或者好友或者群)转移任务未转移完成!转移批次是:" + JSON.toJSONString(taskIdList) + ",请及时处理呀。 "; throw new BusinessWarningRuntimeException(message); } } }
3.获取钉钉群code的方式:
1 |
2 |
3 |
4 |
5 |
6 |