Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

254 linhas
8.7 KiB

  1. using Nancy;
  2. using Learun.Util;
  3. using System.Collections.Generic;
  4. using Learun.Application.TwoDevelopment.EducationalAdministration;
  5. using System;
  6. using Learun.Application.Base.SystemModule;
  7. using System.IO;
  8. using System.Web.Mvc;
  9. using Learun.Application.WebApi.Modules;
  10. using System.Linq;
  11. namespace Learun.Application.WebApi
  12. {
  13. /// <summary>
  14. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  15. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  16. /// 创 建:超级管理员
  17. /// 日 期:2020-06-03 14:29
  18. /// 描 述:听课记录
  19. /// </summary>
  20. public class SunshineEducationApi : BaseNoLoginApi
  21. {
  22. private SunshineEducationIBLL sunshineEducationIBLL = new SunshineEducationBLL();
  23. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  24. /// <summary>
  25. /// 阳光教育
  26. /// <summary>
  27. public SunshineEducationApi()
  28. : base("/Learun/adms/SunshineEducation")
  29. {
  30. Get["/pagelist"] = GetPageList;
  31. Get["/list"] = GetList;
  32. Get["/form"] = GetForm;
  33. Get["/statistics"] = StatisticsForm;
  34. //Post["/delete"] = DeleteForm;
  35. Get["/down"] = DownAnnexesFile;
  36. Post["/upload"] = Upload;
  37. Post["/save"] = SaveForm;//提交,回复,评论
  38. Post["/clicks"] = ClicksForm;
  39. }
  40. #region 获取数据
  41. /// <summary>
  42. /// 获取页面显示列表分页数据
  43. /// <summary>
  44. /// <param name="_"></param>
  45. /// <returns></returns>
  46. public Response GetPageList(dynamic _)
  47. {
  48. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  49. var data = sunshineEducationIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  50. var jsonData = new
  51. {
  52. rows = data,
  53. total = parameter.pagination.total,
  54. page = parameter.pagination.page,
  55. records = parameter.pagination.records
  56. };
  57. return Success(jsonData);
  58. }
  59. /// <summary>
  60. /// 获取页面显示列表数据
  61. /// <summary>
  62. /// <param name="_"></param>
  63. /// <returns></returns>
  64. public Response GetList(dynamic _)
  65. {
  66. string queryJson = this.GetReqData();
  67. var data = sunshineEducationIBLL.GetList(queryJson);
  68. return Success(data);
  69. }
  70. /// <summary>
  71. /// 获取表单数据
  72. /// <summary>
  73. /// <param name="_"></param>
  74. /// <returns></returns>
  75. public Response GetForm(dynamic _)
  76. {
  77. string keyValue = this.GetReqData();
  78. var sunshineEducationData = sunshineEducationIBLL.GetEntity(keyValue);
  79. sunshineEducationData.Contents = WebHelper.HtmlDecode(sunshineEducationData.Contents);
  80. var jsonData = new
  81. {
  82. sunshineEducation = sunshineEducationData,
  83. };
  84. return Success(jsonData);
  85. }
  86. public Response StatisticsForm(dynamic _)
  87. {
  88. var data = sunshineEducationIBLL.GetAllList();
  89. var zsNum = data.Count();
  90. var yclNum = data.Count(x => x.Status == 2);
  91. var slzNum = data.Count(x => x.Status == 1);
  92. var wclNum = data.Count(x => x.Status == 0);
  93. return Success(new { zsNum, yclNum, wclNum,slzNum });
  94. }
  95. #endregion
  96. #region 提交数据
  97. ///// <summary>
  98. ///// 删除实体数据
  99. ///// <param name="_"></param>
  100. ///// <summary>
  101. ///// <returns></returns>
  102. //public Response DeleteForm(dynamic _)
  103. //{
  104. // string keyValue = this.GetReqData();
  105. // sunshineEducationIBLL.DeleteEntity(keyValue);
  106. // return Success("删除成功!");
  107. //}
  108. /// <summary>
  109. /// 保存实体数据(新增、修改)
  110. /// <param name="_"></param>
  111. /// <summary>
  112. /// <returns></returns>
  113. public Response SaveForm(dynamic _)
  114. {
  115. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  116. SunshineEducationEntity entity = parameter.strEntity.ToObject<SunshineEducationEntity>();
  117. if (!string.IsNullOrEmpty(parameter.keyValue))
  118. {
  119. var data = sunshineEducationIBLL.GetEntity(parameter.keyValue);
  120. if (data.AcceptanceCode != entity.AcceptanceCode)
  121. {
  122. return Fail("评论失败,受理单号不正确");
  123. }
  124. entity.Contents = data.Contents;
  125. }
  126. else
  127. {
  128. entity.Contents = WebHelper.HtmlEncode(entity.Contents);
  129. }
  130. sunshineEducationIBLL.SaveEntity(parameter.keyValue, entity);
  131. return Success("保存成功!");
  132. }
  133. /// <summary>
  134. /// 点击累计
  135. /// <param name="_"></param>
  136. /// <summary>
  137. /// <returns></returns>
  138. public Response ClicksForm(dynamic _)
  139. {
  140. string keyValue = this.GetReqData();
  141. sunshineEducationIBLL.ClicksEntity(keyValue);
  142. return Success("点击数据!");
  143. }
  144. #endregion
  145. #region 上传附件图片文件
  146. /// <summary>
  147. /// 上传附件图片文件
  148. /// <summary>
  149. /// <returns></returns>
  150. public Response Upload(dynamic _)
  151. {
  152. var files = (List<HttpFile>)this.Context.Request.Files;
  153. string folderId = Guid.NewGuid().ToString();
  154. string filePath = Config.GetValue("AnnexesFile");
  155. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  156. string fileEextension = Path.GetExtension(files[0].Name);
  157. string fileType = fileEextension.Replace(".", "");
  158. string fileGuid = Guid.NewGuid().ToString();
  159. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, "system", uploadDate, fileGuid, fileEextension);
  160. //创建文件夹
  161. string path = Path.GetDirectoryName(virtualPath);
  162. Directory.CreateDirectory(path);
  163. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  164. if (!System.IO.File.Exists(virtualPath))
  165. {
  166. byte[] bytes = new byte[files[0].Value.Length];
  167. files[0].Value.Read(bytes, 0, bytes.Length);
  168. FileInfo file = new FileInfo(virtualPath);
  169. FileStream fs = file.Create();
  170. fs.Write(bytes, 0, bytes.Length);
  171. fs.Close();
  172. //文件信息写入数据库
  173. fileAnnexesEntity.F_Id = fileGuid;
  174. fileAnnexesEntity.F_FileName = files[0].Name;
  175. fileAnnexesEntity.F_FilePath = virtualPath;
  176. fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
  177. fileAnnexesEntity.F_FileExtensions = fileEextension;
  178. fileAnnexesEntity.F_FileType = fileType;
  179. fileAnnexesEntity.F_CreateUserId = "system";
  180. fileAnnexesEntity.F_CreateUserName = "system";
  181. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  182. }
  183. return SuccessString(folderId);
  184. }
  185. /// <summary>
  186. /// 删除文件
  187. /// </summary>
  188. /// <param name="_"></param>
  189. /// <returns></returns>
  190. public Response DeleteFile(dynamic _)
  191. {
  192. var fileId = this.GetReqData();
  193. AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
  194. annexesFileIBLL.DeleteEntity(fileId);
  195. //删除文件
  196. if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
  197. {
  198. System.IO.File.Delete(fileInfoEntity.F_FilePath);
  199. }
  200. return Success("删除成功");
  201. }
  202. /// <summary>
  203. /// 下载文件
  204. /// </summary>
  205. /// <param name="_"></param>
  206. /// <returns></returns>
  207. public Response DownAnnexesFile(dynamic _)
  208. {
  209. string name = this.GetReqData();
  210. string fileId = name.Split('.')[0];
  211. var data = annexesFileIBLL.GetEntity(fileId);
  212. string filepath = data.F_FilePath;
  213. if (FileDownHelper.FileExists(filepath))
  214. {
  215. FileDownHelper.DownLoadnew(filepath);
  216. }
  217. return Success("");
  218. }
  219. #endregion
  220. #region 私有类
  221. /// <summary>
  222. /// 表单实体类
  223. /// <summary>
  224. private class ReqFormEntity
  225. {
  226. public string keyValue { get; set; }
  227. public string strEntity { get; set; }
  228. }
  229. #endregion
  230. }
  231. }