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.
 
 
 
 
 
 

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