// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 // // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinExpressIntracityQueryFlowResponse.Types; namespace Admin.NET.Plugin.DingTalk.Service; /// /// 钉钉服务 🧩 /// [ApiDescriptionSettings(DingTalkConst.GroupName, Order = 100)] public class DingTalkService : IDynamicApiController, IScoped { private readonly IDingTalkApi _dingTalkApi; private readonly DingTalkOptions _dingTalkOptions; private readonly SqlSugarRepository 钉钉审批记录; public DingTalkService( IDingTalkApi dingTalkApi, IOptions dingTalkOptions, SqlSugarRepository _钉钉审批记录 ) { _dingTalkApi = dingTalkApi; _dingTalkOptions = dingTalkOptions.Value; 钉钉审批记录 = _钉钉审批记录; } /// /// 获取企业内部应用的access_token /// /// [DisplayName("获取企业内部应用的access_token")] public async Task GetDingTalkToken() { var tokenRes = await _dingTalkApi.GetDingTalkToken( _dingTalkOptions.ClientId, _dingTalkOptions.ClientSecret ); if (tokenRes.ErrCode != 0) { throw Oops.Oh(tokenRes.ErrMsg); } return tokenRes; } /// /// 获取在职员工列表 🔖 /// /// /// /// [HttpPost, DisplayName("获取在职员工列表")] public async Task< DingTalkBaseResponse > GetDingTalkCurrentEmployeesList( string access_token, [Required] GetDingTalkCurrentEmployeesListInput input ) { return await _dingTalkApi.GetDingTalkCurrentEmployeesList(access_token, input); } /// /// 获取员工花名册字段信息 🔖 /// /// /// /// [HttpPost, DisplayName("获取员工花名册字段信息")] public async Task< DingTalkBaseResponse> > GetDingTalkCurrentEmployeesRosterList( string access_token, [Required] GetDingTalkCurrentEmployeesRosterListInput input ) { return await _dingTalkApi.GetDingTalkCurrentEmployeesRosterList(access_token, input); } /// /// 发送钉钉互动卡片 🔖 /// /// /// /// [DisplayName("给指定用户发送钉钉互动卡片")] public async Task DingTalkSendInteractiveCards( string token, DingTalkSendInteractiveCardsInput input ) { return await _dingTalkApi.DingTalkSendInteractiveCards(token, input); } /// /// 创建并投放钉钉消息卡片 🔖 /// /// /// /// [DisplayName("给指定用户发送钉钉消息卡片")] public async Task DingTalkCreateAndDeliver( string token, DingTalkCreateAndDeliverInput input ) { return await _dingTalkApi.DingTalkCreateAndDeliver(token, input); } [DisplayName("用于发起OA审批实例")] public async Task DingTalkWorkflowProcessInstances( string token, DingTalkWorkflowProcessInstancesInput input ) { var temp = await _dingTalkApi.DingTalkWorkflowProcessInstances(token, input); return temp; } [DisplayName("查询审批实例")] public async Task DingTalkWorkflowProcessInstances( string token, string input ) { var temp = await _dingTalkApi.GetProcessInstances(token, input); DingTalkWokerflowLog flow = await 钉钉审批记录.GetFirstAsync(t => t.Status == "RUNNING" && t.instanceId == input ); if ((flow != null) && (temp.Result.Status != flow.Status)) { flow.Status = temp.Result.Status; flow.UpdateTime = DateTime.Now; flow.WorkflowId = temp.Result.BusinessId; flow.Result = temp.Result.Result; flow.taskId = temp.Result.Tasks.FirstOrDefault(t => t.Status == "RUNNING")?.TaskId; 钉钉审批记录.UpdateAsync(flow); } return temp; } }