Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

192 řádky
6.5 KiB

  1. using Nancy;
  2. using Learun.Util;
  3. using System.Collections.Generic;
  4. using Learun.Application.TwoDevelopment.EducationalAdministration;
  5. using static Learun.Application.WebApi.Modules.StuInfoFreshApi;
  6. using System;
  7. using System.IO;
  8. using Learun.Application.Base.SystemModule;
  9. namespace Learun.Application.WebApi
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 力软敏捷开发框架
  13. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-08-19 17:50
  16. /// 描 述:教师注册
  17. /// </summary>
  18. public class EmpInfoApi : BaseNoLoginApi
  19. {
  20. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  21. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  22. private TeachSwitchIBLL teachSwitchIBLL = new TeachSwitchBLL();
  23. /// <summary>
  24. /// 注册接口
  25. /// <summary>
  26. public EmpInfoApi()
  27. : base("/Learun/EducationalAdministration/EmpRegister")
  28. {
  29. Get["/pagelist"] = GetPageList;
  30. Get["/list"] = GetList;
  31. Get["/form"] = GetForm;
  32. Post["/delete"] = DeleteForm;
  33. Post["/save"] = SaveForm;
  34. Post["/savePhoto"] = GetSavePhoto;
  35. Get["/registerbutton"] = RegisterButton;
  36. Post["/signon"] = Signon;
  37. }
  38. private Response Signon(dynamic _)
  39. {
  40. SignUpHelper.AddQueue("德玛西亚", "140181199110080255");
  41. return Success("成功");
  42. }
  43. #region 获取数据
  44. /// <summary>
  45. /// 获取页面显示列表分页数据
  46. /// <summary>
  47. /// <param name="_"></param>
  48. /// <returns></returns>
  49. public Response GetPageList(dynamic _)
  50. {
  51. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  52. var data = empInfoIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  53. var jsonData = new
  54. {
  55. rows = data,
  56. total = parameter.pagination.total,
  57. page = parameter.pagination.page,
  58. records = parameter.pagination.records
  59. };
  60. return Success(jsonData);
  61. }
  62. /// <summary>
  63. /// 获取页面显示列表数据
  64. /// <summary>
  65. /// <param name="_"></param>
  66. /// <returns></returns>
  67. public Response GetList(dynamic _)
  68. {
  69. string queryJson = this.GetReqData();
  70. var data = empInfoIBLL.GetList(queryJson);
  71. return Success(data);
  72. }
  73. public Response RegisterButton(dynamic _)
  74. {
  75. var result = teachSwitchIBLL.FindFirst("js").ToString();
  76. return Success(result);
  77. }
  78. /// <summary>
  79. /// 获取表单数据
  80. /// <summary>
  81. /// <param name="_"></param>
  82. /// <returns></returns>
  83. public Response GetForm(dynamic _)
  84. {
  85. string keyValue = this.GetReqData();
  86. var EmpInfoData = empInfoIBLL.GetEmpInfoEntity(keyValue);
  87. var jsonData = new
  88. {
  89. EmpInfo = EmpInfoData,
  90. };
  91. return Success(jsonData);
  92. }
  93. #endregion
  94. #region 提交数据
  95. /// <summary>
  96. /// 头像
  97. /// </summary>
  98. /// <param name="_"></param>
  99. /// <returns></returns>
  100. private Response GetSavePhoto(dynamic _)
  101. {
  102. var model = this.GetReqData<PhotoModel>();
  103. var folderId = Guid.NewGuid().ToString();
  104. string filePath = Config.GetValue("AnnexesFile");
  105. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  106. string FileEextension = ".png";
  107. string fileGuid = Guid.NewGuid().ToString();
  108. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, model.account, uploadDate, fileGuid, FileEextension);
  109. //创建文件夹
  110. string path = Path.GetDirectoryName(virtualPath);
  111. Directory.CreateDirectory(path);
  112. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  113. if (!System.IO.File.Exists(virtualPath))
  114. {
  115. //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
  116. byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
  117. FileInfo file = new FileInfo(virtualPath);
  118. FileStream fs = file.Create();
  119. fs.Write(bytes, 0, bytes.Length);
  120. fs.Close();
  121. //文件信息写入数据库
  122. fileAnnexesEntity.F_Id = fileGuid;
  123. fileAnnexesEntity.F_FileName = "userphoto.png";
  124. fileAnnexesEntity.F_FilePath = virtualPath;
  125. fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
  126. fileAnnexesEntity.F_FileExtensions = FileEextension;
  127. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  128. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  129. }
  130. var data = new
  131. {
  132. Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
  133. AnnexesFileId = fileGuid
  134. };
  135. return Success(data);
  136. }
  137. /// <summary>
  138. /// 删除实体数据
  139. /// <param name="_"></param>
  140. /// <summary>
  141. /// <returns></returns>
  142. public Response DeleteForm(dynamic _)
  143. {
  144. string keyValue = this.GetReqData();
  145. empInfoIBLL.DeleteEntity(keyValue);
  146. return Success("删除成功!");
  147. }
  148. /// <summary>
  149. /// 保存实体数据(新增、修改)
  150. /// <param name="_"></param>
  151. /// <summary>
  152. /// <returns></returns>
  153. public Response SaveForm(dynamic _)
  154. {
  155. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  156. EmpInfoEntity entity = parameter.strEntity.ToObject<EmpInfoEntity>();
  157. empInfoIBLL.SaveEntity(this.userInfo, parameter.keyValue, entity);
  158. return Success("保存成功!");
  159. }
  160. #endregion
  161. #region 私有类
  162. /// <summary>
  163. /// 表单实体类
  164. /// <summary>
  165. private class ReqFormEntity
  166. {
  167. public string keyValue { get; set; }
  168. public string strEntity { get; set; }
  169. }
  170. #endregion
  171. }
  172. }