using AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models;
using DS.Module.SqlSugar;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Sys.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tea;
namespace DS.WMS.Core.Fee.Method
{
public class DingDing
{
///
/// 获取token
///
public static string GetDingToken(string Key, string Secret)
{
AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client client = CreateClient1();
AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest getAccessTokenRequest = new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest
{
AppKey = Key, //"dingplilbecwnldzcdwc",
AppSecret = Secret //"V1jtywZwJNtcTw9PfY5am2nsqacgserqNVOx-_yHsv-5YIypKKG2R0Qm19lpnHCj",
};
try
{
var p = client.GetAccessToken(getAccessTokenRequest);
return p.Body.AccessToken;
}
catch (TeaException err)
{
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
catch (Exception _err)
{
TeaException err = new TeaException(new Dictionary
{
{ "message", _err.Message }
});
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
return "";
}
///
/// 更新表单
///
/// 钉钉token
/// 审批模板Id
/// 租户Id
public static void UpDingOAForm(string token, string ProcessCode, List inInvoicesData)
{
AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient();
FormCreateHeaders formCreateHeaders = new FormCreateHeaders();
formCreateHeaders.XAcsDingtalkAccessToken = token;
#region 费用类别
FormComponent fylx = new FormComponent
{
ComponentType = "DDSelectField",
Props = new FormComponentProps
{
ComponentId = "DDSelectField-fylx", // 控件id,表单内唯一,与bizAlias二选一
Required = true, // 控件是否必填
Label = "费用类别", // 控件标题
Placeholder = "请选择", // 输入提示
Print = "1",//是否参与打印
Disabled = false, //是否可编辑
Options = new List {
new SelectOption{Value = "项目费用",Key = "1"},
new SelectOption { Value = "部门费用", Key = "2" },
new SelectOption { Value = "差旅费用", Key = "3" },
new SelectOption { Value = "其他", Key = "4" }
}
}
};
#endregion
#region 项目名称
FormComponent xmmc = new FormComponent
{
ComponentType = "TextField",
Props = new FormComponentProps
{
ComponentId = "TextField-abcd", // 控件id,表单内唯一,与bizAlias二选一
Required = true, // 控件是否必填
Label = "项目名称", // 控件标题
Placeholder = "请输入",// 输入提示
Print = "1",//是否参与打印
Disabled = false, //是否可编辑
}
};
#endregion
#region 费用明细
var taxinfo = inInvoicesData;
List selectOptions = new List();
foreach (var item in taxinfo)
{
SelectOption st = new SelectOption();
st.Value = ($"金额:{item.Amount};销方名称:{item.SellerName};发票号码:{item.InvoiceNumber}");
st.Key = item.InvoiceNumber;
selectOptions.Add(st);
}
FormComponent fymx = new FormComponent
{
ComponentType = "DDSelectField",
Props = new FormComponentProps
{
ComponentId = "DDSelectField-fymx", // 控件id,表单内唯一,与bizAlias二选一
Required = false, // 控件是否必填
Label = "费用明细", // 控件标题
Placeholder = "请选择", // 输入提示
Print = "1",//是否参与打印
Disabled = false, //是否可编辑
Options = selectOptions
}
};
#endregion
#region 金额
FormComponent xmmcA = new FormComponent
{
ComponentType = "MoneyField",
Props = new FormComponentProps
{
ComponentId = "MoneyField_1JZJIQ", // 控件id,表单内唯一,与bizAlias二选一
Required = true, // 控件是否必填
Label = "金额(元)", // 控件标题
Placeholder = "请输入金额",// 输入提示
Print = "1",//是否参与打印
Disabled = false, //是否可编辑
}
};
#endregion
#region 收款账户
FormComponent skzh = new FormComponent
{
ComponentType = "RecipientAccountField",
Props = new FormComponentProps
{
ComponentId = "RecipientAccountField_7KZ7T", // 控件id,表单内唯一,与bizAlias二选一
Required = true, // 控件是否必填
Label = "收款账户", // 控件标题
Placeholder = "请选择",// 输入提示
Disabled = false,
}
};
#endregion
#region 关联审批单
FormComponent glspd = new FormComponent
{
ComponentType = "RelateField",
Props = new FormComponentProps
{
ComponentId = "RelateField_7KZ7T", // 控件id,表单内唯一,与bizAlias二选一
Required = false, // 控件是否必填
Label = "关联审批单", // 控件标题
Placeholder = "请选择",// 输入提示
Disabled = false,
}
};
#endregion
FormCreateRequest formCreateRequest = new FormCreateRequest
{
ProcessCode = ProcessCode,// "PROC-528BFFFF-00D1-4AF0-AB5F-7BFB89787994",
Name = "测试费用报销(电子发票)",
Description = "测试费用报销使用",
FormComponents = new List
{
fylx,//费用类别
xmmc,//项目名称
fymx,//费用明细
xmmcA,//金额
skzh,//收款账户
glspd //关联审批单
},
};
try
{
client.FormCreateWithOptions(formCreateRequest, formCreateHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
}
catch (TeaException err)
{
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
catch (Exception _err)
{
TeaException err = new TeaException(new Dictionary
{
{ "message", _err.Message }
});
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
}
/**
* 使用 Token 初始化账号Client
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client CreateClient1()
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
config.Protocol = "https";
config.RegionId = "central";
return new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client(config);
}
public static AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client CreateClient()
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
config.Protocol = "https";
config.RegionId = "central";
return new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client(config);
}
///
/// 获取审批实例详情
///
/// 审批实例Id
/// 钉钉token
///
public static GetProcessInstanceResponse GetProcessInstanceWithOptions(string ProcessInstanceId, string Token)
{
AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient();
AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceHeaders getProcessInstanceHeaders = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceHeaders();
getProcessInstanceHeaders.XAcsDingtalkAccessToken = Token;
AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceRequest getProcessInstanceRequest = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceRequest
{
ProcessInstanceId = ProcessInstanceId,
};
try
{
return client.GetProcessInstanceWithOptions(getProcessInstanceRequest, getProcessInstanceHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
}
catch (TeaException err)
{
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
catch (Exception _err)
{
TeaException err = new TeaException(new Dictionary
{
{ "message", _err.Message }
});
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
return new GetProcessInstanceResponse();
}
///
/// 获取钉钉报销审批列表
///
/// 钉钉token
/// 钉钉模板Id
/// 开始时间
/// 结束时间
/// 获取到的数据集
/// 分页游标
///
public static List GetProcessList(string token, string ProcessCode, long StartTime, long EndTime, List Data, int NextToken = 0)
{
AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient();
ListProcessInstanceIdsHeaders listProcessInstanceIdsHeaders = new ListProcessInstanceIdsHeaders();
listProcessInstanceIdsHeaders.XAcsDingtalkAccessToken = token;
ListProcessInstanceIdsRequest listProcessInstanceIdsRequest = new ListProcessInstanceIdsRequest
{
ProcessCode = ProcessCode,
StartTime = StartTime,
EndTime = EndTime,
NextToken = NextToken,
MaxResults = 20
};
try
{
var data = client.ListProcessInstanceIdsWithOptions(listProcessInstanceIdsRequest, listProcessInstanceIdsHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
foreach (var item in data.Body.Result.List)
{
Data.Add(item);
}
if (data.Body.Result.NextToken != null)
{
GetProcessList(token, ProcessCode, StartTime, EndTime, Data, Convert.ToInt32(data.Body.Result.NextToken));
}
return Data;
}
catch (TeaException err)
{
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
catch (Exception _err)
{
TeaException err = new TeaException(new Dictionary
{
{ "message", _err.Message }
});
if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
{
// err 中含有 code 和 message 属性,可帮助开发定位问题
}
}
return new List();
}
}
}