You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

432 line
15 KiB

  1. using Learun.Application.Excel;
  2. using System.Collections.Generic;
  3. using System.Web.Mvc;
  4. using Learun.Util;
  5. using System.Data;
  6. using Learun.Application.Base.SystemModule;
  7. using System;
  8. using System.Drawing;
  9. using Learun.Application.TwoDevelopment.EducationalAdministration;
  10. namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
  11. {
  12. /// <summary>
  13. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  14. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  15. /// 创建人:陈彬彬
  16. /// 日 期:2017.04.01
  17. /// 描 述:Excel导入管理
  18. /// </summary>
  19. public class ExcelImportController : MvcControllerBase
  20. {
  21. private ExcelImportIBLL excelImportIBLL = new ExcelImportBLL();
  22. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  23. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  24. private WageScheduleIBLL wageScheduleIBLL = new WageScheduleBLL();
  25. private JobPerformanceIBLL jobPerformanceIBLL = new JobPerformanceBLL();
  26. #region 视图功能
  27. /// <summary>
  28. /// 导入模板管理页面
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpGet]
  32. public ActionResult Index()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 导入模板管理表单
  38. /// </summary>
  39. /// <returns></returns>
  40. [HttpGet]
  41. public ActionResult Form()
  42. {
  43. return View();
  44. }
  45. /// <summary>
  46. /// 设置字段属性
  47. /// </summary>
  48. /// <returns></returns>
  49. [HttpGet]
  50. public ActionResult SetFieldForm()
  51. {
  52. return View();
  53. }
  54. /// <summary>
  55. /// 导入页面
  56. /// </summary>
  57. /// <returns></returns>
  58. [HttpGet]
  59. public ActionResult ImportForm()
  60. {
  61. return View();
  62. }
  63. #endregion
  64. #region 获取数据
  65. /// <summary>
  66. /// 获取分页数据
  67. /// </summary>
  68. /// <param name="pagination">分页参数</param>
  69. /// <param name="queryJson">查询参数</param>
  70. /// <returns></returns>
  71. [HttpGet]
  72. [AjaxOnly]
  73. public ActionResult GetPageList(string pagination, string queryJson)
  74. {
  75. Pagination paginationobj = pagination.ToObject<Pagination>();
  76. var data = excelImportIBLL.GetPageList(paginationobj, queryJson);
  77. var jsonData = new
  78. {
  79. rows = data,
  80. total = paginationobj.total,
  81. page = paginationobj.page,
  82. records = paginationobj.records,
  83. };
  84. return JsonResult(jsonData);
  85. }
  86. /// <summary>
  87. /// 获取分页数据
  88. /// </summary>
  89. /// <param name="moduleId">功能模块主键</param>
  90. /// <returns></returns>
  91. [HttpGet]
  92. [AjaxOnly]
  93. public ActionResult GetList(string moduleId)
  94. {
  95. var data = excelImportIBLL.GetList(moduleId);
  96. return JsonResult(data);
  97. }
  98. /// <summary>
  99. /// 获取表单数据
  100. /// <param name="keyValue">主键</param>
  101. /// <summary>
  102. /// <returns></returns>
  103. [HttpGet]
  104. [AjaxOnly]
  105. public ActionResult GetFormData(string keyValue)
  106. {
  107. ExcelImportEntity entity = excelImportIBLL.GetEntity(keyValue);
  108. IEnumerable<ExcelImportFieldEntity> list = excelImportIBLL.GetFieldList(keyValue);
  109. var data = new
  110. {
  111. entity = entity,
  112. list = list
  113. };
  114. return JsonResult(data);
  115. }
  116. #endregion
  117. #region 提交数据
  118. /// <summary>
  119. /// 保存表单数据
  120. /// </summary>
  121. /// <param name="keyValue">主键</param>
  122. /// <param name="entity">实体</param>
  123. /// <returns></returns>
  124. [HttpPost]
  125. [ValidateAntiForgeryToken]
  126. [AjaxOnly]
  127. public ActionResult SaveForm(string keyValue, string strEntity, string strList)
  128. {
  129. ExcelImportEntity entity = strEntity.ToObject<ExcelImportEntity>();
  130. List<ExcelImportFieldEntity> filedList = strList.ToObject<List<ExcelImportFieldEntity>>();
  131. excelImportIBLL.SaveEntity(keyValue, entity, filedList);
  132. return Success("保存成功!");
  133. }
  134. /// <summary>
  135. /// 删除表单数据
  136. /// </summary>
  137. /// <param name="keyValue">主键</param>
  138. /// <returns></returns>
  139. [HttpPost]
  140. [AjaxOnly]
  141. public ActionResult DeleteForm(string keyValue)
  142. {
  143. excelImportIBLL.DeleteEntity(keyValue);
  144. return Success("删除成功!");
  145. }
  146. /// <summary>
  147. /// 更新表单数据
  148. /// </summary>
  149. /// <param name="keyValue">主键</param>
  150. /// <param name="entity">实体数据</param>
  151. /// <returns></returns>
  152. [HttpPost]
  153. [AjaxOnly]
  154. public ActionResult UpdateForm(string keyValue, ExcelImportEntity entity)
  155. {
  156. excelImportIBLL.UpdateEntity(keyValue, entity);
  157. return Success("操作成功!");
  158. }
  159. #endregion
  160. #region 扩展方法
  161. /// <summary>
  162. /// 下载文件
  163. /// </summary>
  164. /// <param name="fileId">文件id</param>
  165. /// <returns></returns>
  166. [HttpPost]
  167. [ValidateAntiForgeryToken]
  168. public void DownSchemeFile(string keyValue)
  169. {
  170. ExcelImportEntity templateInfo = excelImportIBLL.GetEntity(keyValue);
  171. IEnumerable<ExcelImportFieldEntity> fileds = excelImportIBLL.GetFieldList(keyValue);
  172. //设置导出格式
  173. ExcelConfig excelconfig = new ExcelConfig();
  174. excelconfig.FileName = Server.UrlDecode(templateInfo.F_Name) + ".xls";
  175. excelconfig.IsAllSizeColumn = true;
  176. excelconfig.ColumnEntity = new List<ColumnModel>();
  177. //表头
  178. DataTable dt = new DataTable();
  179. foreach (var col in fileds)
  180. {
  181. if (col.F_RelationType != 1 && col.F_RelationType != 4 && col.F_RelationType != 5 && col.F_RelationType != 6 && col.F_RelationType != 7)
  182. {
  183. excelconfig.ColumnEntity.Add(new ColumnModel()
  184. {
  185. Column = col.F_Name,
  186. ExcelColumn = col.F_ColName,
  187. Alignment = "center",
  188. Background = col.F_IsMandatory == true ? Color.Red : new Color()
  189. });
  190. dt.Columns.Add(col.F_Name, typeof(string));
  191. }
  192. }
  193. ExcelHelper.ExcelDownload(dt, excelconfig);
  194. }
  195. /// <summary>
  196. /// excel文件导入(通用)
  197. /// </summary>
  198. /// <param name="templateId">模板Id</param>
  199. /// <param name="fileId">文件主键</param>
  200. /// <param name="chunks">分片数</param>
  201. /// <param name="ext">文件扩展名</param>
  202. /// <returns></returns>
  203. [HttpPost]
  204. [ValidateAntiForgeryToken]
  205. public ActionResult ExecuteImportExcel(string templateId, string fileId, int chunks, string ext)
  206. {
  207. UserInfo userInfo = LoginUserInfo.Get();
  208. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  209. if (!string.IsNullOrEmpty(path))
  210. {
  211. DataTable dt = ExcelHelper.ExcelImport(path);
  212. string res = excelImportIBLL.ImportTable(templateId, fileId, dt);
  213. var data = new
  214. {
  215. Success = res.Split('|')[0],
  216. Fail = res.Split('|')[1]
  217. };
  218. return JsonResult(data);
  219. }
  220. else
  221. {
  222. return Fail("导入数据失败!");
  223. }
  224. }
  225. /// <summary>
  226. /// 工资导入
  227. /// </summary>
  228. /// <param name="templateId">模板Id</param>
  229. /// <param name="fileId">文件主键</param>
  230. /// <param name="chunks">分片数</param>
  231. /// <param name="ext">文件扩展名</param>
  232. /// <returns></returns>
  233. [HttpPost]
  234. [ValidateAntiForgeryToken]
  235. public ActionResult ExecuteImportSaralExcel(string fileId, int chunks, string ext)
  236. {
  237. UserInfo userInfo = LoginUserInfo.Get();
  238. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  239. if (!string.IsNullOrEmpty(path))
  240. {
  241. DataTable dt = ExcelHelper.ExcelImport(path);
  242. string res = excelImportIBLL.ImportSalaryInfo(dt, fileId);
  243. var data = new
  244. {
  245. Success = res.Split('|')[0],
  246. Fail = res.Split('|')[1]
  247. };
  248. return JsonResult(data);
  249. }
  250. else
  251. {
  252. return Fail("导入数据失败!");
  253. }
  254. }
  255. /// <summary>
  256. /// 金隅教师信息导入
  257. /// </summary>
  258. /// <param name="templateId">模板Id</param>
  259. /// <param name="fileId">文件主键</param>
  260. /// <param name="chunks">分片数</param>
  261. /// <param name="ext">文件扩展名</param>
  262. /// <returns></returns>
  263. [HttpPost]
  264. [ValidateAntiForgeryToken]
  265. public ActionResult EmpInfoImport(string fileId, int chunks, string ext)
  266. {
  267. UserInfo userInfo = LoginUserInfo.Get();
  268. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  269. if (!string.IsNullOrEmpty(path))
  270. {
  271. DataTable dt = ExcelHelper.ExcelImport(path);
  272. string res = excelImportIBLL.EmpInfoImport(dt, fileId);
  273. var data = new
  274. {
  275. Success = res.Split('|')[0],
  276. Fail = res.Split('|')[1]
  277. };
  278. return JsonResult(data);
  279. }
  280. else
  281. {
  282. return Fail("导入数据失败!");
  283. }
  284. }
  285. /// <summary>
  286. /// 学生学籍信息批量修改
  287. /// </summary>
  288. /// <param name="templateId">模板Id</param>
  289. /// <param name="fileId">文件主键</param>
  290. /// <param name="chunks">分片数</param>
  291. /// <param name="ext">文件扩展名</param>
  292. /// <returns></returns>
  293. [HttpPost]
  294. [ValidateAntiForgeryToken]
  295. public ActionResult StuInfoBasicImport(string fileId, int chunks, string ext)
  296. {
  297. UserInfo userInfo = LoginUserInfo.Get();
  298. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  299. if (!string.IsNullOrEmpty(path))
  300. {
  301. DataTable dt = ExcelHelper.ExcelImport(path);
  302. string res = stuInfoBasicIBLL.StuInfoBasicImport(dt, fileId);
  303. var data = new
  304. {
  305. Success = res.Split('|')[0],
  306. Fail = res.Split('|')[1]
  307. };
  308. return JsonResult(data);
  309. }
  310. else
  311. {
  312. return Fail("导入数据失败!");
  313. }
  314. }
  315. /// <summary>
  316. /// 工资条导入
  317. /// </summary>
  318. /// <param name="templateId">模板Id</param>
  319. /// <param name="fileId">文件主键</param>
  320. /// <param name="chunks">分片数</param>
  321. /// <param name="ext">文件扩展名</param>
  322. /// <returns></returns>
  323. [HttpPost]
  324. [ValidateAntiForgeryToken]
  325. public ActionResult SalarySheetImport(string fileId, int chunks, string ext)
  326. {
  327. UserInfo userInfo = LoginUserInfo.Get();
  328. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  329. if (!string.IsNullOrEmpty(path))
  330. {
  331. DataTable dt = ExcelHelper.ExcelImport(path);
  332. string res = wageScheduleIBLL.SalarySheelImport(dt, fileId);
  333. var data = new
  334. {
  335. Success = res.Split('|')[0],
  336. Fail = res.Split('|')[1]
  337. };
  338. return JsonResult(data);
  339. }
  340. else
  341. {
  342. return Fail("导入数据失败!");
  343. }
  344. }
  345. /// <summary>
  346. /// 工作绩效导入
  347. /// </summary>
  348. /// <param name="templateId">模板Id</param>
  349. /// <param name="fileId">文件主键</param>
  350. /// <param name="chunks">分片数</param>
  351. /// <param name="ext">文件扩展名</param>
  352. /// <returns></returns>
  353. [HttpPost]
  354. [ValidateAntiForgeryToken]
  355. public ActionResult JobPerformanceImport(string fileId, int chunks, string ext)
  356. {
  357. UserInfo userInfo = LoginUserInfo.Get();
  358. string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo);
  359. if (!string.IsNullOrEmpty(path))
  360. {
  361. DataTable dt = ExcelHelper.ExcelImport(path);
  362. string res = jobPerformanceIBLL.JobPerformanceImport(dt, fileId);
  363. var data = new
  364. {
  365. Success = res.Split('|')[0],
  366. Fail = res.Split('|')[1]
  367. };
  368. return JsonResult(data);
  369. }
  370. else
  371. {
  372. return Fail("导入数据失败!");
  373. }
  374. }
  375. /// <summary>
  376. /// 下载文件(导入文件未被导入的数据)
  377. /// </summary>
  378. /// <param name="fileId">文件id</param>
  379. /// <returns></returns>
  380. [HttpPost]
  381. [ValidateAntiForgeryToken]
  382. public void DownImportErrorFile(string fileId, string fileName)
  383. {
  384. //设置导出格式
  385. ExcelConfig excelconfig = new ExcelConfig();
  386. excelconfig.FileName = Server.UrlDecode("未导入错误数据【" + fileName + "】") + ".xls";
  387. excelconfig.IsAllSizeColumn = true;
  388. excelconfig.ColumnEntity = new List<ColumnModel>();
  389. //表头
  390. DataTable dt = excelImportIBLL.GetImportError(fileId);
  391. foreach (DataColumn col in dt.Columns)
  392. {
  393. if (col.ColumnName == "导入错误")
  394. {
  395. excelconfig.ColumnEntity.Add(new ColumnModel()
  396. {
  397. Column = col.ColumnName,
  398. ExcelColumn = col.ColumnName,
  399. Alignment = "center",
  400. Background = Color.Red
  401. });
  402. }
  403. else
  404. {
  405. excelconfig.ColumnEntity.Add(new ColumnModel()
  406. {
  407. Column = col.ColumnName,
  408. ExcelColumn = col.ColumnName,
  409. Alignment = "center",
  410. });
  411. }
  412. }
  413. ExcelHelper.ExcelDownload(dt, excelconfig);
  414. }
  415. #endregion
  416. }
  417. }