FaultReportServices.cs
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Hh.Mes.Common.config;
using Hh.Mes.Common.Exel;
using Hh.Mes.Common.log;
using Hh.Mes.Service.QiYeWeiXin;
using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace Hh.Mes.Service
{
public class FaultReportService
{
private readonly QiYiWeiXinGlobalContext qiYiWeiXinGlobalContext;
public FaultReportService(QiYiWeiXinGlobalContext qiYiWeiXinGlobalContext)
{
this.qiYiWeiXinGlobalContext = qiYiWeiXinGlobalContext;
}
private static string FilePath { get; set; }
/// <summary>
/// 将Excel作为企业微信附件发送
/// </summary>
public async Task SendToWeChatWorkAsync()
{
var tempPath = FilePath;
try
{
// 2. 上传到企业微信获取media_id
string mediaId = qiYiWeiXinGlobalContext.UploadFileToWeChatWorkAsync(tempPath);
if (!string.IsNullOrEmpty(mediaId))
{
// 3. 发送文件消息
await qiYiWeiXinGlobalContext.SendFileMessage(mediaId);
}
}
catch (Exception ex)
{
Log4NetHelper.Instance.Error($"项目故障报告信息发送企业微信异常:{ex.Message}");
}
finally
{
// 4. 清理临时文件
if (File.Exists(tempPath))
{
File.Delete(tempPath);
}
}
}
public async Task Export(DataTable dt, string fileName)
{
try
{
string fileurl = ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend8;
FilePath = $"{fileurl}/{fileName}.xlsx";
//获取当年周数
int week = ISOWeek.GetWeekOfYear(DateTime.Now);
await NPOIHelper.ExportDTtoExcelAsync(dt, $"IOT项目故障报告", FilePath, fileurl);
}
catch (Exception ex)
{
Log4NetHelper.Instance.Error($"项目故障报告信息导出Excel异常:{ex.Message}");
}
}
}
}