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.
 
 
 
 
 
 

208 line
7.0 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/adms/EducationalAdministration/EmpRegister")
  28. {
  29. Get["/pagelist"] = GetPageList;
  30. Get["/list"] = GetList;
  31. Get["/form"] = GetForm;
  32. Get["/formForNo"] = GetFormForNo;
  33. Post["/delete"] = DeleteForm;
  34. Post["/save"] = SaveForm;
  35. Post["/savePhoto"] = GetSavePhoto;
  36. Get["/registerbutton"] = RegisterButton;
  37. Post["/signon"] = Signon;
  38. }
  39. private Response Signon(dynamic _)
  40. {
  41. SignUpHelper.AddQueue("德玛西亚", "140181199110080255");
  42. return Success("成功");
  43. }
  44. #region 获取数据
  45. /// <summary>
  46. /// 获取页面显示列表分页数据
  47. /// <summary>
  48. /// <param name="_"></param>
  49. /// <returns></returns>
  50. public Response GetPageList(dynamic _)
  51. {
  52. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  53. var data = empInfoIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  54. var jsonData = new
  55. {
  56. rows = data,
  57. total = parameter.pagination.total,
  58. page = parameter.pagination.page,
  59. records = parameter.pagination.records
  60. };
  61. return Success(jsonData);
  62. }
  63. /// <summary>
  64. /// 获取页面显示列表数据
  65. /// <summary>
  66. /// <param name="_"></param>
  67. /// <returns></returns>
  68. public Response GetList(dynamic _)
  69. {
  70. string queryJson = this.GetReqData();
  71. var data = empInfoIBLL.GetList(queryJson);
  72. return Success(data);
  73. }
  74. public Response RegisterButton(dynamic _)
  75. {
  76. var result = teachSwitchIBLL.FindFirst("js").ToString();
  77. return Success(result);
  78. }
  79. /// <summary>
  80. /// 获取表单数据
  81. /// <summary>
  82. /// <param name="_"></param>
  83. /// <returns></returns>
  84. public Response GetForm(dynamic _)
  85. {
  86. string keyValue = this.GetReqData();
  87. var EmpInfoData = empInfoIBLL.GetEmpInfoEntity(keyValue);
  88. var jsonData = new
  89. {
  90. EmpInfo = EmpInfoData,
  91. };
  92. return Success(jsonData);
  93. }
  94. /// <summary>
  95. /// 获取表单数据
  96. /// <summary>
  97. /// <param name="_"></param>
  98. /// <returns></returns>
  99. public Response GetFormForNo(dynamic _)
  100. {
  101. string keyValue = this.GetReqData();
  102. var EmpInfoData = empInfoIBLL.GetEmpInfoEntityByEmpNo(keyValue);
  103. var jsonData = new
  104. {
  105. EmpInfo = EmpInfoData,
  106. };
  107. return Success(jsonData);
  108. }
  109. #endregion
  110. #region 提交数据
  111. /// <summary>
  112. /// 头像
  113. /// </summary>
  114. /// <param name="_"></param>
  115. /// <returns></returns>
  116. private Response GetSavePhoto(dynamic _)
  117. {
  118. var model = this.GetReqData<PhotoModel>();
  119. var folderId = Guid.NewGuid().ToString();
  120. string filePath = Config.GetValue("AnnexesFile");
  121. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  122. string FileEextension = ".png";
  123. string fileGuid = Guid.NewGuid().ToString();
  124. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, model.account, uploadDate, fileGuid, FileEextension);
  125. //创建文件夹
  126. string path = Path.GetDirectoryName(virtualPath);
  127. Directory.CreateDirectory(path);
  128. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  129. if (!System.IO.File.Exists(virtualPath))
  130. {
  131. //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
  132. byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
  133. FileInfo file = new FileInfo(virtualPath);
  134. FileStream fs = file.Create();
  135. fs.Write(bytes, 0, bytes.Length);
  136. fs.Close();
  137. //文件信息写入数据库
  138. fileAnnexesEntity.F_Id = fileGuid;
  139. fileAnnexesEntity.F_FileName = "userphoto.png";
  140. fileAnnexesEntity.F_FilePath = virtualPath;
  141. fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
  142. fileAnnexesEntity.F_FileExtensions = FileEextension;
  143. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  144. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  145. }
  146. var data = new
  147. {
  148. Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
  149. AnnexesFileId = fileGuid
  150. };
  151. return Success(data);
  152. }
  153. /// <summary>
  154. /// 删除实体数据
  155. /// <param name="_"></param>
  156. /// <summary>
  157. /// <returns></returns>
  158. public Response DeleteForm(dynamic _)
  159. {
  160. string keyValue = this.GetReqData();
  161. empInfoIBLL.DeleteEntity(keyValue);
  162. return Success("删除成功!");
  163. }
  164. /// <summary>
  165. /// 保存实体数据(新增、修改)
  166. /// <param name="_"></param>
  167. /// <summary>
  168. /// <returns></returns>
  169. public Response SaveForm(dynamic _)
  170. {
  171. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  172. EmpInfoEntity entity = parameter.strEntity.ToObject<EmpInfoEntity>();
  173. empInfoIBLL.SaveEntity(this.userInfo, parameter.keyValue, entity);
  174. return Success("保存成功!");
  175. }
  176. #endregion
  177. #region 私有类
  178. /// <summary>
  179. /// 表单实体类
  180. /// <summary>
  181. private class ReqFormEntity
  182. {
  183. public string keyValue { get; set; }
  184. public string strEntity { get; set; }
  185. }
  186. #endregion
  187. }
  188. }