浏览代码

添加项目文件。

wup 1 年之前
父节点
当前提交
efa3ad7388

+ 4 - 0
.editorconfig

@@ -0,0 +1,4 @@
+[*.cs]
+
+# IDE0059: 不需要赋值
+dotnet_diagnostic.IDE0059.severity = silent

+ 55 - 0
Controllers/ValuesController.cs

@@ -0,0 +1,55 @@
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using System.Collections.Generic;
+using WebApplication.model;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace WebApplication.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class ValuesController : ControllerBase
+    {
+
+        // GET api/<ValuesController>/5
+        [HttpGet("{id}")]
+        public string Get(string id)
+        {
+            dingApi dingApi = new dingApi();
+            dingApi.DingToken();
+            //dingApi.processInstances();
+            //printInfo printInfo = new printInfo();
+            //List<printInfo.Person> peopledata = new List<printInfo.Person>();
+            //printInfo.WriteDataToExcelTemplate("E:/jsjPrintTemplate/XBPrintTemplate.xlsx", "E:/jsjPrintTemplate/XBPrintTemplate"+DateTime.Now+".xlsx", peopledata.ToString(), "采购申请");
+            return "value";
+        }
+
+        // GET api/<ValuesController>/5
+        /// <summary>
+        /// OA审批单
+        /// </summary>
+        /// <param name="processInstanceId">OA审批单号</param>
+        /// <param name="name">OA单据名称</param>
+        /// <returns></returns>
+        [HttpGet("{processInstanceId},{name}")]
+        public string Get(string processInstanceId,string name)
+        { 
+            dingApi dingApi = new dingApi();
+            personOA oA = new personOA();
+            string token = dingApi.DingToken();
+            string process = dingApi.processInstances(processInstanceId);
+            switch (name)
+            {
+                case "内部工作流转":
+                    List<personOA.Person> listIWG = new List<personOA.Person>();
+                    listIWG.Add(oA.Roleioat(process, "内部工作流转"));
+                    new cyAPI().commonMethod(token, JsonConvert.SerializeObject(listIWG[0]).ToString(),listIWG[0].F0000005, "F0000005");
+                    break;
+            }
+            return "true";
+        }
+
+        
+    }
+}

+ 38 - 0
Controllers/WeatherForecastController.cs

@@ -0,0 +1,38 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace WebApplication.Controllers
+{
+    [ApiController]
+    [Route("[controller]")]
+    public class WeatherForecastController : ControllerBase
+    {
+        private static readonly string[] Summaries = new[]
+        {
+            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+        };
+
+        private readonly ILogger<WeatherForecastController> _logger;
+
+        public WeatherForecastController(ILogger<WeatherForecastController> logger)
+        {
+            _logger = logger;
+        }
+
+        [HttpGet]
+        public IEnumerable<WeatherForecast> Get()
+        {
+            var rng = new Random();
+            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+            {
+                Date = DateTime.Now.AddDays(index),
+                TemperatureC = rng.Next(-20, 55),
+                Summary = Summaries[rng.Next(Summaries.Length)]
+            })
+            .ToArray();
+        }
+    }
+}

+ 156 - 0
Controllers/WebApi.cs

@@ -0,0 +1,156 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebApplication.Controllers
+{
+    public class WebApi
+    {
+        /// <summary>
+        /// Get方式提交数据
+        /// </summary>
+        /// <param name="methodname"></param>
+        /// <returns></returns>
+        public object retObject(string methodname)
+        {
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(methodname);
+            request.Method = "GET";
+            request.ContentType = "text/html;charset=UTF-8";
+            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+            Stream myResponseStream = response.GetResponseStream();
+            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
+            string retString = myStreamReader.ReadToEnd();
+
+            var retObject = (JObject)JsonConvert.DeserializeObject(retString);
+            return retObject;
+        }
+
+
+        /// <summary>
+        /// Post方式提交数据
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="body"></param>
+        /// <returns></returns>
+        public string HttpPost(string url, string body, string accessToken)
+        {
+            Encoding encoding = Encoding.UTF8;
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.Method = "POST";
+            //request.Accept = "text/html, application/xhtml+xml, */*";
+            request.ContentType = "application/json; charset=utf-8";
+            byte[] buffer = encoding.GetBytes(body);
+            request.ContentLength = buffer.Length;
+            request.GetRequestStream().Write(buffer, 0, buffer.Length);
+            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
+            {
+                return reader.ReadToEnd();
+            }
+        }
+
+        /// <summary>
+        /// http Post请求 发送Json数据
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headht"></param>
+        /// <returns></returns>
+        public string PostJson(string url, string postData, Hashtable headht = null)
+        {
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.Method = "POST";
+            request.ContentType = "application/json;charset=UTF-8";
+            request.UserAgent = "www.qq.cc/WebRequest";
+            request.Accept = "application/json";
+
+            #region headers设置
+            if (headht != null)
+            {
+                foreach (DictionaryEntry item in headht)
+                {
+                    request.Headers.Add(item.Key.ToString(), item.Value.ToString());
+                }
+            }
+            #endregion
+
+            byte[] paramJsonBytes;
+            paramJsonBytes = System.Text.Encoding.UTF8.GetBytes(postData);
+            request.ContentLength = paramJsonBytes.Length;
+            Stream writer;
+            try
+            {
+                writer = request.GetRequestStream();
+            }
+            catch (Exception e)
+            {
+                writer = null;
+                Console.Write("连接服务器失败!");
+            }
+            writer.Write(paramJsonBytes, 0, paramJsonBytes.Length);
+            writer.Close();
+            HttpWebResponse response;
+            try
+            {
+                response = (HttpWebResponse)request.GetResponse();
+            }
+            catch (WebException ex)
+            {
+                response = ex.Response as HttpWebResponse;
+            }
+            Stream resStream = response.GetResponseStream();
+            StreamReader reader = new StreamReader(resStream);
+            string text = reader.ReadToEnd();
+            return text;
+        }
+
+        /// <summary>
+        /// Get 方法
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="accessToken">Headers 中的秘钥</param>
+        /// <returns></returns>
+        public string HttpGet(string url ,string accessToken)
+        {
+            string result = string.Empty;
+            HttpWebRequest reqS = (HttpWebRequest)WebRequest.Create(url);
+            reqS.Method = "GET";
+
+            //添加请求头
+            reqS.Headers.Add("x-acs-dingtalk-access-token",accessToken);
+            reqS.ContentType = "application/json; charset=utf-8";
+
+            HttpWebResponse resS = (HttpWebResponse)reqS.GetResponse();
+            Stream myResponseStream = resS.GetResponseStream();
+            StreamReader streamReader = new StreamReader(myResponseStream);
+            result = streamReader.ReadToEnd();
+            streamReader.Close();
+            myResponseStream.Close();
+
+            // 解析返回的json数据(使用 jobject)
+            JObject theResult = (JObject)JsonConvert.DeserializeObject(result);
+
+            return theResult.ToString();
+        }
+
+
+        /// <summary>
+        /// Json解析
+        /// </summary>
+        /// <param name="result"></param>
+        /// <returns></returns>
+        public string[] jsons(string result)
+        {
+            JObject jo = JObject.Parse(result);
+            string[] values1 = jo.Properties().Select(item => item.Value.ToString()).ToArray();
+            return values1;
+        }
+    }
+}

+ 189 - 0
Controllers/cyAPI.cs

@@ -0,0 +1,189 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Text;
+using System.Threading.Tasks;
+using WebApplication.controller;
+
+namespace WebApplication.Controllers
+{
+    /// <summary>
+    /// 氚云API
+    /// </summary>
+    public class cyAPI
+    {
+        WebApi webApi = new WebApi();
+        printInfo printInfo = new printInfo();
+        static HttpClient client = new HttpClient();
+
+        /// <summary>
+        /// 公用方法
+        /// </summary>
+        /// <param name="peopledata"></param>
+        /// <returns></returns>
+        public string commonMethod(string token, string peopledata,string ufname,string FilePropertyName)
+        {
+            string result = instances(token,"e02b79c9-ec99-4982-bcb7-2811457b98c8", peopledata);      //e02b79c9-ec99-4982-bcb7-2811457b98c8
+            JObject toArr = JsonConvert.DeserializeObject<JObject>(result);
+            if (toArr["code"].ToString() == "success")
+            {
+                string dtnow = DateTimeToLongTimeStamp(DateTime.Now).ToString();
+                printInfo.WriteDataToExcelTemplate("E:/jsjPrintTemplate/XBPrintTemplateOA.xlsx", "E:/jsjPrintTemplate/XBPrintTemplateOA" + dtnow + ".xlsx", JsonConvert.SerializeObject(peopledata[0]).ToString(), "OA审批");
+                printInfo.excelToPdf("E:/jsjPrintTemplate/XBPrintTemplateOA" + dtnow + ".xlsx", "E:/jsjPrintTemplate/XBPrintTemplateOA" + dtnow + ".PDF");
+                string bizObjectId = toArr["data"]["bizObjectId"].ToString();
+                string schemaCode = toArr["data"]["schemaCode"].ToString();
+                UploadAttachment(schemaCode, bizObjectId, "E:\\jsjPrintTemplate\\XBPrintTemplateOA" + dtnow + ".PDF", ufname, FilePropertyName);
+            }
+            return "true";
+        }
+
+        /// <summary>
+        /// Post 方式调用表单创建
+        /// </summary>
+        /// <returns></returns>
+        public string instances(string token,string opUserId,string bizJson)
+        {
+            string url = "https://api.dingtalk.com/v1.0/h3yun/forms/instances";
+            Dictionary<string, string> dic = new Dictionary<string, string>();
+            dic.Add("schemaCode", "D1463788fabdbfcf89b4080b91d58b1dbc7f856");
+            dic.Add("opUserId", opUserId);
+            dic.Add("bizObjectJson", bizJson);
+            dic.Add("isDraft", "false");
+            Hashtable headht = new Hashtable();
+            headht.Add("x-acs-dingtalk-access-token", token);
+            string toredate = webApi.PostJson(url, JsonConvert.SerializeObject(dic).ToString(), headht);
+            //string toredate = webApi.HttpPosts(url, JsonConvert.SerializeObject(dic).ToString(), token);
+            return toredate;
+        }
+
+        /// <summary>
+        /// Get 方法调用文件上传接口地址
+        /// </summary>
+        /// <returns></returns>
+        public string uploadUrls(string token,string schemaCode, string bizObjectId,string fieldName)
+        {
+            //GET / v1.0 / h3yun / attachments / uploadUrls ? schemaCode = String & bizObjectId = String & fieldName = String & isOverwrite = Boolean HTTP / 1.1
+            //Host: api.dingtalk.com
+            //x - acs - dingtalk - access - token:String
+            //Content - Type:application / json
+            //schemaCode  表单编码。       bizObjectId 业务数据实例ID。  fieldName  文件上传至目标控件的字段名。 isOverwrite 是否覆盖,取值:false:添加
+            string url = "https://api.dingtalk.com/v1.0/h3yun/attachments/uploadUrls?schemaCode="+ schemaCode + "&bizObjectId="+ bizObjectId + "&fieldName="+ fieldName + "&isOverwrite=false";
+            var errUf = webApi.HttpGet(url, token);
+            return errUf.ToString() ;
+        }
+
+        /// <summary>
+        /// 附件上传接口 Post
+        /// </summary>
+        /// <param name="SchemaCode">表单编码</param>
+        /// <param name="BizObjectId">表单控件编码</param>
+        /// <param name="fileurl">表单ObjectId值</param>
+        /// <param name="name">名称</param>
+        /// <returns></returns>
+        public string UploadAttachment(string SchemaCode,string BizObjectId,string fileurl,string name,string FilePropertyName)
+        {
+            WebHeaderCollection head = new WebHeaderCollection();
+            head.Add("EngineCode", "mdhf9vbowovdb2xastdoua0f0");
+            head.Add("EngineSecret", "jMr8Hdq+RmPcGHfP8OPBQ/23a+dsNkvE3NH+6KFu5OfNvhUJ07cSmg==");
+            //请求的URL
+            string url = "https://www.h3yun.com/OpenApi/UploadAttachment?SchemaCode="+ SchemaCode + "&FilePropertyName="+ FilePropertyName + "&BizObjectId="+ BizObjectId;
+            string directory = Path.GetDirectoryName(fileurl);
+            if (!Directory.Exists(directory))
+            {
+                Directory.CreateDirectory(directory);
+            }
+            //读取本地文件
+            FileStream file = new FileStream(fileurl, FileMode.Open);
+            var fd = file.Length;
+            byte[] bytes = new byte[fd];
+            file.Read(bytes, 0, Convert.ToInt32(fd));
+            file.Close();
+            //调用上传方法
+            string filename = name+".PDF"; //氚云显示的文件名,必须带后缀(例:file.jpg)      
+            string contentType = "application/pdf";//文件ContentType,不清楚可以打开网址(https://www.w3school.com.cn/media/media_mimeref.asp)参考(例:image/jpg)
+            string result = _UploadFile(url, bytes, filename, head, contentType);
+            return result;
+        }
+
+        /// <summary>
+        /// 上传方法
+        /// </summary>
+        /// <param name="url">上传接口Url</param>
+        /// <param name="bytes">文件Byte</param>
+        /// <param name="fileName">文件名</param>
+        /// <param name="headers">请求Headers</param>
+        /// <param name="contentType">文件ContentType</param>
+        /// <returns></returns>
+        private static string _UploadFile(string url, byte[] bytes, string fileName, WebHeaderCollection headers, string contentType)
+        {
+            Uri oUri = new Uri(url);
+            string strBoundary = "----------" + DateTime.Now.Ticks.ToString("x");
+
+            // The trailing boundary string
+            byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + strBoundary + "--\r\n");
+
+            // The post message header
+            StringBuilder sb = new StringBuilder();
+            sb.Append("--");
+            sb.Append(strBoundary);
+            sb.Append("\r\n");
+            sb.Append("Content-Disposition:   form-data; name=\"media\";");
+            sb.Append(" filename=\"");
+            sb.Append(fileName);
+            sb.Append("\"");
+            sb.Append("\r\n");
+            sb.Append("Content-Type: ");
+            sb.Append(contentType + "\r\n\r\n");
+            string strPostHeader = sb.ToString();
+            byte[] postHeaderBytes = Encoding.UTF8.GetBytes(strPostHeader);
+            // The WebRequest
+            HttpWebRequest oWebrequest = (HttpWebRequest)WebRequest.Create(oUri);
+            oWebrequest.ContentType = "multipart/form-data; boundary=" + strBoundary;
+            oWebrequest.Method = "POST";
+            if (headers != null)
+            {
+                foreach (string key in headers.Keys)
+                {
+                    oWebrequest.Headers.Add(key, headers[key]);
+                }
+            }
+            // This is important, otherwise   the whole file will be read to memory anyway...
+            oWebrequest.AllowWriteStreamBuffering = false;
+            long length = postHeaderBytes.Length + bytes.Length + boundaryBytes.Length;
+            oWebrequest.ContentLength = length;
+            using (Stream oRequestStream = oWebrequest.GetRequestStream())
+            {
+                // Write the post header
+                oRequestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
+                oRequestStream.Write(bytes, 0, bytes.Length);
+                // Add the trailing boundary
+                oRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
+                WebResponse oWResponse = oWebrequest.GetResponse();
+                using (Stream s = oWResponse.GetResponseStream())
+                {
+                    using (StreamReader sr = new StreamReader(s))
+                    {
+                        string sReturnString = sr.ReadToEnd();
+                        return sReturnString;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// DateTime转换为13位时间戳(单位:毫秒)
+        /// </summary>
+        /// <param name="dateTime"> DateTime</param>
+        /// <returns>13位时间戳(单位:毫秒)</returns>
+        public static long DateTimeToLongTimeStamp(DateTime dateTime)
+        {
+            return (long)(dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
+        }
+    }
+}

+ 47 - 0
Controllers/dingApi.cs

@@ -0,0 +1,47 @@
+using DingTalk.Api;
+using DingTalk.Api.Request;
+using DingTalk.Api.Response;
+using System.Net.Http;
+
+namespace WebApplication.Controllers
+{
+    /// <summary>
+    /// 钉钉API接口
+    /// </summary>
+    public class dingApi
+    {
+        WebApi webApi = new WebApi();
+        static HttpClient client = new HttpClient();
+        private string access_token = "";
+        /// <summary>
+        /// 获取钉钉Token
+        /// </summary>
+        /// <returns></returns>
+        public string DingToken()
+        {
+            //string appKey = "dingidtiffltdio8sv7g";
+            //string appSecret = "LtWTmFAEdJ0Sf9TgoBbUlMZFB274sOCcc1etRn2aEkvuiDacly8cEx37LKgOoAqX";
+            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
+            OapiGettokenRequest req = new OapiGettokenRequest();
+            req.Appkey = "dingtcdktugu7zegcobs";
+            req.Appsecret = "QV2itumaTYw0_0meLfDyOUtzL9_e-b1pwczldkZYjHDgzYTi8GMBCLIg4eHfUnod";
+            req.SetHttpMethod("GET");
+            OapiGettokenResponse rsp = client.Execute(req, access_token);
+            access_token = rsp.AccessToken;
+            return access_token;
+        }
+
+        /// <summary>
+        /// 获取单个审批实例详情
+        /// </summary>
+        /// <param name="processInstanceId"></param>
+        /// <returns></returns>
+        public string processInstances(string processInstanceId = "8fJzVf7JQKytuEgX-vIArA09771690787501")
+        {
+            string url = "https://api.dingtalk.com/v1.0/workflow/processInstances?processInstanceId=" + processInstanceId;
+            string resultlist = webApi.HttpGet(url, access_token);
+            return resultlist;
+        }
+
+    }
+}

+ 26 - 0
Program.cs

@@ -0,0 +1,26 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace WebApplication
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            CreateHostBuilder(args).Build().Run();
+        }
+
+        public static IHostBuilder CreateHostBuilder(string[] args) =>
+            Host.CreateDefaultBuilder(args)
+                .ConfigureWebHostDefaults(webBuilder =>
+                {
+                    webBuilder.UseStartup<Startup>();
+                });
+    }
+}

+ 31 - 0
Properties/launchSettings.json

@@ -0,0 +1,31 @@
+{
+  "$schema": "http://json.schemastore.org/launchsettings.json",
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:38381",
+      "sslPort": 44357
+    }
+  },
+  "profiles": {
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "launchUrl": "swagger",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "WebApplication": {
+      "commandName": "Project",
+      "dotnetRunMessages": "true",
+      "launchBrowser": true,
+      "launchUrl": "swagger",
+      "applicationUrl": "https://localhost:5001;http://localhost:5000",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}

+ 58 - 0
Startup.cs

@@ -0,0 +1,58 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.HttpsPolicy;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.OpenApi.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace WebApplication
+{
+    public class Startup
+    {
+        public Startup(IConfiguration configuration)
+        {
+            Configuration = configuration;
+        }
+
+        public IConfiguration Configuration { get; }
+
+        // This method gets called by the runtime. Use this method to add services to the container.
+        public void ConfigureServices(IServiceCollection services)
+        {
+
+            services.AddControllers();
+            services.AddSwaggerGen(c =>
+            {
+                c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication", Version = "v1" });
+            });
+        }
+
+        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+            
+            app.UseDeveloperExceptionPage();
+            app.UseSwagger();
+            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication v1"));
+          
+
+            app.UseHttpsRedirection();
+
+            app.UseRouting();
+
+            app.UseAuthorization();
+
+            app.UseEndpoints(endpoints =>
+            {
+                endpoints.MapControllers();
+            });
+        }
+    }
+}

+ 15 - 0
WeatherForecast.cs

@@ -0,0 +1,15 @@
+using System;
+
+namespace WebApplication
+{
+    public class WeatherForecast
+    {
+        public DateTime Date { get; set; }
+
+        public int TemperatureC { get; set; }
+
+        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+        public string Summary { get; set; }
+    }
+}

+ 17 - 0
WebApplication.csproj

@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>net5.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="AlibabaCloud.SDK.Dingtalk" Version="2.0.28" />
+    <PackageReference Include="EPPlus" Version="6.2.7" />
+    <PackageReference Include="FreeSpire.XLS" Version="12.7.0" />
+    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
+    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
+    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
+    <PackageReference Include="TopSDK.DingTalk" Version="1.0.0" />
+  </ItemGroup>
+
+</Project>

+ 25 - 0
WebApplication.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.32630.194
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication", "WebApplication.csproj", "{48355564-7E6A-4EA5-9E75-42F03A73211E}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{48355564-7E6A-4EA5-9E75-42F03A73211E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{48355564-7E6A-4EA5-9E75-42F03A73211E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{48355564-7E6A-4EA5-9E75-42F03A73211E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{48355564-7E6A-4EA5-9E75-42F03A73211E}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {A7FC198E-A515-4464-9EDC-23A3BB3C4776}
+	EndGlobalSection
+EndGlobal

+ 9 - 0
appsettings.Development.json

@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  }
+}

+ 10 - 0
appsettings.json

@@ -0,0 +1,10 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  },
+  "AllowedHosts": "*"
+}

+ 91 - 0
controller/printInfo.cs

@@ -0,0 +1,91 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using OfficeOpenXml;
+using Spire.Xls;
+using System.IO;
+
+namespace WebApplication.controller
+{
+    public class printInfo
+    {
+        public void WriteDataToExcelTemplate(string templatePath, string outputPath, string data,string name)
+        {
+
+            //WriteDataToExcelTemplate(templatePath, outputPath, data);
+            // 加载 Excel 模板文件
+            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
+            using (ExcelPackage package = new ExcelPackage(new FileInfo(templatePath)))
+            {
+                    switch (name)
+                    {
+                        case "采购申请":
+                        ExcelWorksheet worksheetCG = package.Workbook.Worksheets[0];
+                        string nameCG = worksheetCG.ToString();
+                        if (nameCG == "采购申请")
+                        {
+                            //int colCount = worksheet.Dimension.End.Column;  //get Column Count
+                            //int rowCount = worksheet.Dimension.End.Row;     //get row count
+
+                            // 遍历数据,逐行写入到工作表中
+                            int i = 10; // 第一行是标题,从第二行开始写入数据
+
+                            worksheetCG.Cells["B2"].Value = "合同编号";
+                            worksheetCG.Cells["F2"].Value = "创建时间";
+                            worksheetCG.Cells["B3"].Value = "拥有者";
+                            worksheetCG.Cells["F4"].Value = "所属部门";
+                            worksheetCG.Cells["B4"].Value = "主题";
+                            worksheetCG.Cells["B5"].Value = "合同名称";
+                            worksheetCG.Cells["B6"].Value = "供应商";
+                            worksheetCG.Cells["B7"].Value = "联系人";
+                            worksheetCG.Cells["F7"].Value = "联系方式";
+                            worksheetCG.Cells["B8"].Value = "采购内容类型";
+                            worksheetCG.Cells["F8"].Value = "合同金额";
+                            //for (int row = 10; row <= data.Count; row++)
+                            //{
+
+                            //}
+                            worksheetCG.Cells["B11"].Value = "合同事由";
+                            worksheetCG.Cells["B12"].Value = "备注";
+                        }
+                        break;
+                        case "OA审批":
+                        JObject arrdata = JsonConvert.DeserializeObject<JObject>(data);
+                        ExcelWorksheet worksheetOA = package.Workbook.Worksheets[0];
+                        string nameOA = worksheetOA.ToString();
+                        if (nameOA == "OA审批")
+                        {
+                            worksheetOA.Cells["B2"].Value = arrdata["F0000001"].ToString();         //标题
+                            worksheetOA.Cells["F2"].Value = arrdata["F0000006"].ToString();         //创建人
+                            worksheetOA.Cells["B3"].Value = arrdata["F0000004"].ToString();         //审批单号
+                            worksheetOA.Cells["B4"].Value = arrdata["F0000007"].ToString();         //结束时间
+                            worksheetOA.Cells["F4"].Value = arrdata["F0000002"].ToString();         //发起时间
+                            worksheetOA.Cells["B5"].Value = arrdata["F0000009"].ToString();         //时长
+                            worksheetOA.Cells["B6"].Value = arrdata["F0000010"].ToString();         //同行人
+                            worksheetOA.Cells["B7"].Value = arrdata["F0000011"].ToString();         //事由
+                            worksheetOA.Cells["B8"].Value = arrdata["F0000012"].ToString();         //费用出处
+                            worksheetOA.Cells["B9"].Value = arrdata["F0000005"].ToString();         //附件
+                            worksheetOA.Cells["B10"].Value = arrdata["F0000013"].ToString();        //说明
+                            worksheetOA.Cells["B11"].Value = arrdata["F0000014"].ToString();        //审批流程
+                        }
+                        break;
+                    }
+                //excelToPdf(new FileInfo(outputPath), outputPath)
+                // 保存 Excel 文件
+                package.SaveAs(new FileInfo(outputPath));
+            }
+        }
+
+        /// <summary>
+        /// Excel转PDF
+        /// </summary>
+        /// <param name="LoadFromFile">文件地址</param>
+        /// <param name="SaveToPdf">输出文件地址</param>
+        public void excelToPdf(string LoadFromFile, string SaveToPdf)
+        {
+            Workbook workbook = new Workbook();
+            workbook.LoadFromFile(LoadFromFile);
+            Worksheet sheet = workbook.Worksheets[0];
+            sheet.SaveToPdf(SaveToPdf);
+        }
+    }
+}

+ 100 - 0
model/personOA.cs

@@ -0,0 +1,100 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace WebApplication.model
+{
+    public class personOA
+    {
+        /// <summary>
+        /// OA审批
+        /// </summary>
+        public class Person
+        {
+            /// <summary>
+            /// 单据类型
+            /// </summary>
+            public string F0000015 { get; set; }
+            /// <summary>
+            /// 标题
+            /// </summary>
+            public string F0000001 { get; set; }
+            /// <summary>
+            /// 审批单号
+            /// </summary>
+            public string F0000004 { get; set; }
+            /// <summary>
+            /// 发起人
+            /// </summary>
+            public string F0000006 { get; set; }
+            /// <summary>
+            /// 开始时间
+            /// </summary>
+            public string F0000007 { get; set; }
+            /// <summary>
+            /// 结束时间
+            /// </summary>
+            public string F0000002 { get; set; }
+            /// <summary>
+            /// 时长
+            /// </summary>
+            public string F0000009 { get; set; }
+            /// <summary>
+            /// 事由
+            /// </summary>
+            public string F0000011 { get; set; }
+            /// <summary>
+            /// 附件
+            /// </summary>
+            public string F0000005 { get; set; }
+            /// <summary>
+            /// 说明
+            /// </summary>
+            public string F0000013 { get; set; }
+            
+        }
+
+
+        public Person Roleioat(string process,string DocumentType)
+        {
+            JObject array = JsonConvert.DeserializeObject<JObject>(process);
+            Person person = new Person()
+            {
+                F0000001 = string.IsNullOrEmpty(array["result"]["title"].ToString())?"": array["result"]["title"].ToString(),
+                F0000002 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "结束时间"))?"": rolename(array["result"].ToString(), "结束时间"),
+                F0000004 = string.IsNullOrEmpty(array["result"]["businessId"].ToString())?"": array["result"]["businessId"].ToString(),
+                F0000005 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "附件"))?"": rolename(array["result"].ToString(), "附件"),
+                F0000006 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "发起人"))?"": rolename(array["result"].ToString(), "发起人"),
+                F0000007 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "开始时间"))?"": rolename(array["result"].ToString(), "开始时间"),
+                F0000009 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "时长"))?"": rolename(array["result"].ToString(), "时长"),
+                F0000011 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "事由"))?"": rolename(array["result"].ToString(), "事由"),
+                F0000013 = string.IsNullOrEmpty(rolename(array["result"].ToString(), "说明"))?"": rolename(array["result"].ToString(), "说明"),
+                F0000015 = DocumentType
+            };
+            return person;
+        }
+
+        /// <summary>
+        /// 查询Json字段
+        /// </summary>
+        /// <param name="json">jsons数据</param>
+        /// <param name="name">查询字段名称</param>
+        /// <returns></returns>
+        public string rolename(string json,string name)
+        {
+            //JArray array = JArray.Parse(json);
+            JObject array = JsonConvert.DeserializeObject<JObject>(json);
+            foreach (JObject item in array["formComponentValues"][0])
+            {
+                if (name == item["name"].ToString())
+                {
+                    return item["value"].ToString();
+                }
+            }
+            return "";
+        }
+    }
+}