|
|
@@ -10,6 +10,9 @@ using Custom;
|
|
|
using Tasks;
|
|
|
using Infrastructure;
|
|
|
using Dto.Admin;
|
|
|
+using Feign;
|
|
|
+using Util;
|
|
|
+using LitJson;
|
|
|
|
|
|
|
|
|
namespace Services
|
|
|
@@ -87,9 +90,122 @@ namespace Services
|
|
|
/// 同步api到管理平台
|
|
|
/// </summary>
|
|
|
/// <param name="serviceId">服务id</param>
|
|
|
- public void sycnApiToSystem(int serviceId)
|
|
|
+ public string sycnApiToSystem(int projectId, int serviceId, string env)
|
|
|
{
|
|
|
-
|
|
|
+ var apiGroupService = App.GetService<IApiGroupService>();
|
|
|
+ var apiInfoService = App.GetService<IApiInfoService>();
|
|
|
+ var tableService = App.GetService<IDatabaseTableService>();
|
|
|
+ var project = IProject.getProject(projectId);
|
|
|
+ string ApiListHost = "";
|
|
|
+ string Hosts = "";
|
|
|
+ if(env == "test")
|
|
|
+ {
|
|
|
+ ApiListHost = project.apiListNoticeHostDev ?? "";
|
|
|
+ Hosts = project.gatewayHostDev ?? "";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ApiListHost = project.apiListNoticeHost ?? "";
|
|
|
+ Hosts = project.gatewayHost ?? "";
|
|
|
+ }
|
|
|
+ var projectService = IProject.getProjectService(serviceId);
|
|
|
+ List<string> checkStrs = new List<string>();
|
|
|
+ List<Dictionary<string, object>> dic = new List<Dictionary<string, object>>();
|
|
|
+ string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ int Id = 0;
|
|
|
+ var projectServiceList = IProject.getProjectServiceList(projectId);
|
|
|
+ foreach(var proService in projectServiceList)
|
|
|
+ {
|
|
|
+ Id += 1;
|
|
|
+ int serId = proService.id;
|
|
|
+ string serviceTitle = proService.serviceTitle ?? "";
|
|
|
+ string serviceName = proService.serviceName ?? "";
|
|
|
+ string Language = proService.devLanguage ?? "";
|
|
|
+ string[] HostList = Hosts.Split(':');
|
|
|
+ string Host = HostList[0];
|
|
|
+ string Port = "80";
|
|
|
+ if(HostList.Length > 1)
|
|
|
+ {
|
|
|
+ Port = HostList[1];
|
|
|
+ }
|
|
|
+ List<Dictionary<string, object>> child = new List<Dictionary<string, object>>();
|
|
|
+ var apiInfos = apiInfoService.GetList(m => m.serviceId == serId);
|
|
|
+ foreach(var apiInfo in apiInfos)
|
|
|
+ {
|
|
|
+ var linkTable = tableService.GetFirst(m => m.id == apiInfo.linkTableId) ?? new DatabaseTable();
|
|
|
+ string Gategory = apiInfo.controllerName ?? "";
|
|
|
+ string Router = "";
|
|
|
+ var group = apiGroupService.GetList(m => m.id == apiInfo.groupId);
|
|
|
+ if (group.Count > 0)
|
|
|
+ {
|
|
|
+ Router = group[0].groupName ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ string MethodName = apiInfo.methodName ?? "";
|
|
|
+ string TabName = apiInfo.tabName ?? "";
|
|
|
+ string Title = apiInfo.apiName ?? "";
|
|
|
+ string ApiType = apiInfo.apiKind.ToString();
|
|
|
+ string Method = "get";
|
|
|
+ string ApiKey = "";
|
|
|
+ if(string.IsNullOrEmpty(ApiKey))
|
|
|
+ {
|
|
|
+ ApiKey = Gategory + MethodName;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ApiType == "3") Method = "post";
|
|
|
+ if(ApiType == "4") Method = "put";
|
|
|
+ if(ApiType == "5") Method = "delete";
|
|
|
+ Dictionary<string, object> subItem = new Dictionary<string, object>();
|
|
|
+ string ApiRouter = "/v1/" + Router + "/" + Gategory + "/" + MethodName;
|
|
|
+ subItem.Add("api_router", ApiRouter);
|
|
|
+ subItem.Add("api_port", Port);
|
|
|
+ if(Port == "443")
|
|
|
+ {
|
|
|
+ subItem.Add("api_host", "https://" + Host);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ subItem.Add("api_host", "http://" + Host);
|
|
|
+ }
|
|
|
+ subItem.Add("api_key", ApiKey);
|
|
|
+ subItem.Add("api_name", TabName + "-" + Title);
|
|
|
+ subItem.Add("api_method", Method);
|
|
|
+ subItem.Add("api_path", "/" + Gategory + "/" + linkTable.tableNameUpper + "/index");
|
|
|
+ subItem.Add("api_en_name", linkTable.tableNameUpper ?? "");
|
|
|
+ child.Add(subItem);
|
|
|
+ }
|
|
|
+ Dictionary<string, object> item = new Dictionary<string, object>();
|
|
|
+ item.Add("id", Id);
|
|
|
+ item.Add("group_project", projectId);
|
|
|
+ item.Add("group_kind", 1);
|
|
|
+ item.Add("group_remark", proService.serviceTitle ?? "");
|
|
|
+ item.Add("group_name", PublicFunction.transferName(proService.serviceName ?? "", 2));
|
|
|
+ item.Add("child", child);
|
|
|
+ dic.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
|
|
|
+ string result = "";
|
|
|
+ if(project.encryptKind == 1)
|
|
|
+ {
|
|
|
+ JsonData encryptParam = JsonMapper.ToObject(project.encryptParams ?? "{}");
|
|
|
+ string reqData = CryptHelper.AesEncrypt(req, encryptParam["encrypt_key"].ToString(), encryptParam["encrypt_iv"].ToString(), encryptParam["encrypt_model"].ToString(), encryptParam["encrypt_padding"].ToString());
|
|
|
+ result = Function.PostWebRequest(ApiListHost, reqData, "application/json");
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(result);
|
|
|
+ if(jsonObj["status"].ToString() == "1")
|
|
|
+ {
|
|
|
+ return "同步成功";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = Function.PostWebRequest(ApiListHost, "value=" + req);
|
|
|
+ if(result == "success")
|
|
|
+ {
|
|
|
+ return "同步成功";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "同步失败";
|
|
|
}
|
|
|
}
|
|
|
}
|