|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+using CallCenter.Utility;
|
|
|
2
|
+using CallCenterApi.DB;
|
|
|
3
|
+using CallCenterApi.Interface.Controllers.Base;
|
|
|
4
|
+using NPOI.SS.UserModel;
|
|
|
5
|
+using NPOI.SS.Util;
|
|
|
6
|
+using System;
|
|
|
7
|
+using System.Collections.Generic;
|
|
|
8
|
+using System.Data;
|
|
|
9
|
+using System.IO;
|
|
|
10
|
+using System.Linq;
|
|
|
11
|
+using System.Web;
|
|
|
12
|
+using System.Web.Mvc;
|
|
|
13
|
+
|
|
|
14
|
+namespace CallCenterApi.Interface.Controllers.report
|
|
|
15
|
+{
|
|
|
16
|
+ public class GDLXYQController : BaseController
|
|
|
17
|
+ {
|
|
|
18
|
+ //// GET: GDLXYQ
|
|
|
19
|
+ //public ActionResult Index()
|
|
|
20
|
+ //{
|
|
|
21
|
+ // return View();
|
|
|
22
|
+ //}
|
|
|
23
|
+ /// <summary>
|
|
|
24
|
+ /// 获取报表头
|
|
|
25
|
+ /// </summary>
|
|
|
26
|
+ /// <returns></returns>
|
|
|
27
|
+ public ActionResult GetHeadList()
|
|
|
28
|
+ {
|
|
|
29
|
+ ActionResult res = NoToken("未知错误,请重新登录");
|
|
|
30
|
+ DataTable dtNew = new DataTable();
|
|
|
31
|
+ //添加第一行标题
|
|
|
32
|
+ //DataColumn dc1 = new DataColumn("");
|
|
|
33
|
+ //dtNew.Columns.Add(dc1);
|
|
|
34
|
+ var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '仪器')";
|
|
|
35
|
+ var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
|
|
|
36
|
+ int dtGDLY1rowcount = dtGDLY1.Rows.Count;
|
|
|
37
|
+ //列名
|
|
|
38
|
+ string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
|
|
|
39
|
+ dtGDLY1_name[0] = "";
|
|
|
40
|
+ //列数
|
|
|
41
|
+ int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
|
|
|
42
|
+ dtGDLY1_count[0] = 1;
|
|
|
43
|
+
|
|
|
44
|
+ for (int v = 0; v < dtGDLY1rowcount; v++)
|
|
|
45
|
+ {
|
|
|
46
|
+ string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
|
|
|
47
|
+ var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
|
|
|
48
|
+ dtGDLY1_name[v + 1] = catename;
|
|
|
49
|
+ dtGDLY1_count[v + 1] = count_sub;
|
|
|
50
|
+ }
|
|
|
51
|
+ dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
|
|
|
52
|
+ dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
|
|
|
53
|
+ res = Success("获取工单类型仪器报表表头成功", dtNew);
|
|
|
54
|
+
|
|
|
55
|
+ return res;
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ /// <summary>
|
|
|
59
|
+ /// 获取工单类型仪器报表
|
|
|
60
|
+ /// </summary>
|
|
|
61
|
+ /// <param name="stime"></param>
|
|
|
62
|
+ /// <param name="endtime"></param>
|
|
|
63
|
+ /// <returns></returns>
|
|
|
64
|
+ public ActionResult GetDataList(string stime, string endtime)
|
|
|
65
|
+ {
|
|
|
66
|
+ ActionResult res = NoToken("未知错误,请重新登录");
|
|
|
67
|
+ DataTable dtNew = new DataTable();
|
|
|
68
|
+ //添加第一行标题
|
|
|
69
|
+ //DataColumn dc1 = new DataColumn("");
|
|
|
70
|
+ //dtNew.Columns.Add(dc1);
|
|
|
71
|
+ var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '仪器')";
|
|
|
72
|
+ var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
|
|
|
73
|
+ int dtGDLY1rowcount = dtGDLY1.Rows.Count;
|
|
|
74
|
+ //列名
|
|
|
75
|
+ string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
|
|
|
76
|
+ dtGDLY1_name[0] = "";
|
|
|
77
|
+ //列数
|
|
|
78
|
+ int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
|
|
|
79
|
+ dtGDLY1_count[0] = 1;
|
|
|
80
|
+
|
|
|
81
|
+ for (int v = 0; v < dtGDLY1rowcount; v++)
|
|
|
82
|
+ {
|
|
|
83
|
+ string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
|
|
|
84
|
+ var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
|
|
|
85
|
+ dtGDLY1_name[v + 1] = catename;
|
|
|
86
|
+ dtGDLY1_count[v + 1] = count_sub;
|
|
|
87
|
+ }
|
|
|
88
|
+ dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
|
|
|
89
|
+ dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
|
|
|
90
|
+ dtNew = getData(stime, endtime);
|
|
|
91
|
+ var obj = new
|
|
|
92
|
+ {
|
|
|
93
|
+ linename = dtGDLY1_name,
|
|
|
94
|
+ linecount = dtGDLY1_count,
|
|
|
95
|
+ dtlist = dtNew
|
|
|
96
|
+ };
|
|
|
97
|
+ res = Success("获取工单来源数据成功", obj);
|
|
|
98
|
+
|
|
|
99
|
+ return res;
|
|
|
100
|
+ }
|
|
|
101
|
+
|
|
|
102
|
+ private DataTable getData(string stime, string endtime)
|
|
|
103
|
+ {
|
|
|
104
|
+ DataTable dtNew = new DataTable();
|
|
|
105
|
+ #region 添加表格标题
|
|
|
106
|
+ ////添加第一行标题
|
|
|
107
|
+ ////DataColumn dc1 = new DataColumn("");
|
|
|
108
|
+ ////dtNew.Columns.Add(dc1);
|
|
|
109
|
+ //var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '仪器'))";
|
|
|
110
|
+ //var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
|
|
|
111
|
+ //int dtGDLY1rowcount = dtGDLY1.Rows.Count;
|
|
|
112
|
+ ////列名
|
|
|
113
|
+ //string[] dtGDLY1_name = new string[dtGDLY1rowcount + 1];
|
|
|
114
|
+ //dtGDLY1_name[0] = "";
|
|
|
115
|
+ ////列数
|
|
|
116
|
+ //int[] dtGDLY1_count = new int[dtGDLY1rowcount + 1];
|
|
|
117
|
+ //dtGDLY1_count[0] = 1;
|
|
|
118
|
+
|
|
|
119
|
+ //for (int v = 0; v < dtGDLY1rowcount; v++)
|
|
|
120
|
+ //{
|
|
|
121
|
+ // string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
|
|
|
122
|
+ // var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
|
|
|
123
|
+ // dtGDLY1_name[v + 1] = catename;
|
|
|
124
|
+ // dtGDLY1_count[v + 1] = count_sub;
|
|
|
125
|
+ //}
|
|
|
126
|
+
|
|
|
127
|
+ //添加第二行标题
|
|
|
128
|
+ DataColumn dc = new DataColumn("姓名");
|
|
|
129
|
+ dtNew.Columns.Add(dc);
|
|
|
130
|
+ var sqlGDLY = " and F_CategoryType=1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '仪器'))";
|
|
|
131
|
+ var recordCount = 0;
|
|
|
132
|
+ var dtGDLY = BLL.PagerBLL.GetListPager(
|
|
|
133
|
+ "T_RepositoryCategory",
|
|
|
134
|
+ "F_CategoryId",
|
|
|
135
|
+ "*",
|
|
|
136
|
+ sqlGDLY,
|
|
|
137
|
+ "ORDER BY F_ParentId asc",
|
|
|
138
|
+ 10,
|
|
|
139
|
+ 1,
|
|
|
140
|
+ true,
|
|
|
141
|
+ out recordCount);
|
|
|
142
|
+ int[] cateid = new int[recordCount];
|
|
|
143
|
+ List<Model.T_RepositoryCategory> modelList = new BLL.T_RepositoryCategory().DataTableToList(dtGDLY);
|
|
|
144
|
+
|
|
|
145
|
+ for (int i = 0; i < modelList.Count; i++)
|
|
|
146
|
+ {
|
|
|
147
|
+ string colname = modelList[i].F_CategoryName;
|
|
|
148
|
+ if (dtNew.Columns.Contains(colname))
|
|
|
149
|
+ colname += "_1";
|
|
|
150
|
+ dtNew.Columns.Add(new DataColumn(colname));
|
|
|
151
|
+ cateid[i] = modelList[i].F_CategoryId;
|
|
|
152
|
+ }
|
|
|
153
|
+ dtNew.Columns.Add("总计");
|
|
|
154
|
+ #endregion
|
|
|
155
|
+
|
|
|
156
|
+ string sqltimeCallRecords = "";
|
|
|
157
|
+ if (stime != null && stime.Trim() != "")
|
|
|
158
|
+ {
|
|
|
159
|
+ sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)>=CONVERT(varchar , '" + stime.Trim() + " 00:00:01', 120) ";
|
|
|
160
|
+ }
|
|
|
161
|
+ if (endtime != null && endtime.Trim() != "")
|
|
|
162
|
+ {
|
|
|
163
|
+ sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
|
|
|
164
|
+ }
|
|
|
165
|
+
|
|
|
166
|
+ double day = 0;
|
|
|
167
|
+ if (stime != null && endtime != null && endtime.Trim() != "" && stime.Trim() != "")
|
|
|
168
|
+ {
|
|
|
169
|
+ TimeSpan time = Convert.ToDateTime(endtime) - Convert.ToDateTime(stime);
|
|
|
170
|
+ day = time.Days + 1;
|
|
|
171
|
+ }
|
|
|
172
|
+ //获取坐席数据
|
|
|
173
|
+ DataTable dt = new DataTable();
|
|
|
174
|
+ string sql = "SELECT * from T_Sys_UserAccount where F_DeleteFlag=0 order by F_Userid asc";
|
|
|
175
|
+ dt = DbHelperSQL.Query(sql).Tables[0];
|
|
|
176
|
+ for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
177
|
+ {
|
|
|
178
|
+ DataRow drNew = dtNew.NewRow();
|
|
|
179
|
+ drNew["姓名"] = dt.Rows[i]["F_UserName"].ToString();
|
|
|
180
|
+ //获取工单类型数据
|
|
|
181
|
+ int sum = 0;
|
|
|
182
|
+ for (int j = 0; j < cateid.Length; j++)
|
|
|
183
|
+ {
|
|
|
184
|
+ string str = "select count(*) from T_Wo_WorkOrder where IsDel=0 and typeclass=" + cateid[j] + " and CreateUserID='" + dt.Rows[i]["F_Userid"].ToString() + "'" + sqltimeCallRecords;
|
|
|
185
|
+ int ecount = int.Parse(DbHelperSQL.GetSingle(str).ToString());
|
|
|
186
|
+
|
|
|
187
|
+ sum += ecount;
|
|
|
188
|
+ drNew[j + 1] = ecount.ToString();
|
|
|
189
|
+ }
|
|
|
190
|
+ drNew["总计"] = sum;
|
|
|
191
|
+ dtNew.Rows.Add(drNew);
|
|
|
192
|
+ }
|
|
|
193
|
+ DataRow drsum = dtNew.NewRow();
|
|
|
194
|
+ drsum[0] = "总计";
|
|
|
195
|
+
|
|
|
196
|
+ for (int i = 1; i < dtNew.Columns.Count; i++)
|
|
|
197
|
+ {
|
|
|
198
|
+ int ecount = 0;
|
|
|
199
|
+ int sum = 0;
|
|
|
200
|
+ for (int j = 1; j < dtNew.Rows.Count; j++)
|
|
|
201
|
+ {
|
|
|
202
|
+ if (dtNew.Rows[j][i] != null)
|
|
|
203
|
+ {
|
|
|
204
|
+ ecount = int.Parse(dtNew.Rows[j][i].ToString());
|
|
|
205
|
+ sum += ecount;
|
|
|
206
|
+ }
|
|
|
207
|
+ }
|
|
|
208
|
+ drsum[i] = sum;
|
|
|
209
|
+ }
|
|
|
210
|
+ dtNew.Rows.Add(drsum);
|
|
|
211
|
+ return dtNew;
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ //导出数据
|
|
|
215
|
+ public ActionResult ExptList(string stime, string endtime)
|
|
|
216
|
+ {
|
|
|
217
|
+ ActionResult res = NoToken("未知错误,请重新登录");
|
|
|
218
|
+ if (Request.IsAuthenticated)
|
|
|
219
|
+ {
|
|
|
220
|
+ DataTable dtNew = new DataTable();
|
|
|
221
|
+ //添加第一行标题
|
|
|
222
|
+ //DataColumn dc1 = new DataColumn("");
|
|
|
223
|
+ //dtNew.Columns.Add(dc1);
|
|
|
224
|
+ var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '仪器')";
|
|
|
225
|
+ var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
|
|
|
226
|
+ int dtGDLY1rowcount = dtGDLY1.Rows.Count;
|
|
|
227
|
+ //每块占的列数
|
|
|
228
|
+ int[] colpos = new int[dtGDLY1rowcount + 1];
|
|
|
229
|
+ colpos[0] = 1;
|
|
|
230
|
+ //列名
|
|
|
231
|
+ string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
|
|
|
232
|
+ dtGDLY1_name[0] = "";
|
|
|
233
|
+ //列数
|
|
|
234
|
+ int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
|
|
|
235
|
+ dtGDLY1_count[0] = 1;
|
|
|
236
|
+
|
|
|
237
|
+ for (int v = 0; v < dtGDLY1rowcount; v++)
|
|
|
238
|
+ {
|
|
|
239
|
+ string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
|
|
|
240
|
+ var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
|
|
|
241
|
+ dtGDLY1_name[v + 1] = catename;
|
|
|
242
|
+ dtGDLY1_count[v + 1] = count_sub;
|
|
|
243
|
+ colpos[v + 1] = count_sub;
|
|
|
244
|
+ }
|
|
|
245
|
+ dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
|
|
|
246
|
+ dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
|
|
|
247
|
+
|
|
|
248
|
+ NPOIHelper npoi = new NPOIHelper();
|
|
|
249
|
+ DataTable dt = getData(stime, endtime);
|
|
|
250
|
+ if (npoi.ExportToExcelForGDLX("工单类型仪器报表", dt, "仪器", dtGDLY1_name, colpos) == "")
|
|
|
251
|
+ {
|
|
|
252
|
+ var obj = new
|
|
|
253
|
+ {
|
|
|
254
|
+ datatable = dt,
|
|
|
255
|
+ dtnames = dtGDLY1_name,
|
|
|
256
|
+ dtcols = colpos
|
|
|
257
|
+ };
|
|
|
258
|
+ return Success("导出成功", obj);
|
|
|
259
|
+ }
|
|
|
260
|
+ else
|
|
|
261
|
+ {
|
|
|
262
|
+ return Error("导出失败");
|
|
|
263
|
+ }
|
|
|
264
|
+ }
|
|
|
265
|
+ return res;
|
|
|
266
|
+ }
|
|
|
267
|
+
|
|
|
268
|
+ ///// <summary>
|
|
|
269
|
+ ///// 合并单元格
|
|
|
270
|
+ ///// </summary>
|
|
|
271
|
+ ///// <param name="sheet">要合并单元格所在的sheet</param>
|
|
|
272
|
+ ///// <param name="rowstart">开始行的索引</param>
|
|
|
273
|
+ ///// <param name="rowend">结束行的索引</param>
|
|
|
274
|
+ ///// <param name="colstart">开始列的索引</param>
|
|
|
275
|
+ ///// <param name="colend">结束列的索引</param>
|
|
|
276
|
+ //public static void SetCellRangeAddress(ISheet sheet, int rowstart, int rowend, int colstart, int colend)
|
|
|
277
|
+ //{
|
|
|
278
|
+ // CellRangeAddress cellRangeAddress = new CellRangeAddress(rowstart, rowend, colstart, colend);
|
|
|
279
|
+ // sheet.AddMergedRegion(cellRangeAddress);
|
|
|
280
|
+ //}
|
|
|
281
|
+ }
|
|
|
282
|
+}
|