Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SunshineEducationApi.cs 14 KiB

2 лет назад
1 год назад
2 лет назад
1 год назад
2 лет назад
1 год назад
2 лет назад
1 год назад
1 год назад
1 год назад
1 год назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
1 год назад
2 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. using System.Net;
  12. using Learun.Cache.Base;
  13. using Learun.Cache.Factory;
  14. using Nancy.Responses;
  15. using Quanjiang.DigitalScholl.SendSms;
  16. namespace Learun.Application.WebApi
  17. {
  18. /// <summary>
  19. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  20. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  21. /// 创 建:超级管理员
  22. /// 日 期:2020-06-03 14:29
  23. /// 描 述:听课记录
  24. /// </summary>
  25. public class SunshineEducationApi : BaseNoLoginApi
  26. {
  27. private SunshineEducationIBLL sunshineEducationIBLL = new SunshineEducationBLL();
  28. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  29. private ICache redisCache = CacheFactory.CaChe();
  30. private readonly ISms yixintongSms = new YixintongSms();
  31. /// <summary>
  32. /// 阳光教育
  33. /// <summary>
  34. public SunshineEducationApi()
  35. : base("/Learun/adms/SunshineEducation")
  36. {
  37. Get["/pagelist"] = GetPageList;
  38. Get["/list"] = GetList;
  39. Get["/form"] = GetForm;
  40. Get["/statistics"] = StatisticsForm;
  41. //Post["/delete"] = DeleteForm;
  42. Get["/down"] = DownAnnexesFile;
  43. Post["/upload"] = Upload;
  44. Post["/save"] = SaveForm;//提交,回复,评论
  45. Post["/clicks"] = ClicksForm;
  46. Get["/getverifycode"] = GetVerifyCode;
  47. Post["/checkverifycode"] = CheckVerifyCode;
  48. }
  49. #region 获取数据
  50. /// <summary>
  51. /// 检查图形验证码并发送短信验证码
  52. /// </summary>
  53. /// <param name="_"></param>
  54. /// <returns></returns>
  55. public Response CheckVerifyCode(dynamic _)
  56. {
  57. MobileVerify mobileVerify = this.GetReqData<MobileVerify>();
  58. var code = redisCache.Read<string>("sunshineimgvcode_" + mobileVerify.pagecode);
  59. LogEntity logEntity = null;
  60. if (!string.IsNullOrEmpty(code) && code.ToLower() == mobileVerify.verifycode.ToLower())
  61. {
  62. //发送短信
  63. try
  64. {
  65. //学生增加短信发送验证
  66. string raRndNum = Learun.Util.CommonHelper.RndNum(6);
  67. var listStr = new List<string>();
  68. var str1 = $"您本次提交的验证码是" + raRndNum + "。";
  69. listStr.Add(str1);
  70. var result = yixintongSms.SendSmsToSingle(mobileVerify.mobile, SmsType.LoginBind, listStr);
  71. if (result.Result.code == "0")
  72. {
  73. redisCache.Write<string>("sunshinesmscode_"+mobileVerify.pagecode +"_"+ mobileVerify.mobile, raRndNum, new TimeSpan(0, 5, 0));
  74. //日志
  75. logEntity = new LogEntity();
  76. logEntity.F_CategoryId = 3;
  77. logEntity.F_OperateTypeId = "sms";
  78. logEntity.F_OperateType = "sms";
  79. logEntity.F_OperateAccount = "system";
  80. logEntity.F_ExecuteResult = 200;
  81. logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
  82. logEntity.F_Description = "短信发送:" + mobileVerify.mobile;
  83. logEntity.WriteLog();
  84. }
  85. else
  86. {
  87. logEntity = new LogEntity();
  88. logEntity.F_CategoryId = 4;
  89. logEntity.F_OperateTypeId = "sms";
  90. logEntity.F_OperateType = "sms";
  91. logEntity.F_OperateAccount = "system";
  92. logEntity.F_ExecuteResult = 400;
  93. logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
  94. logEntity.F_Description = "短信发送:" + mobileVerify.mobile;
  95. logEntity.WriteLog();
  96. }
  97. }
  98. catch (Exception e)
  99. {
  100. logEntity = new LogEntity();
  101. logEntity.F_CategoryId = 4;
  102. logEntity.F_OperateTypeId = "sms";
  103. logEntity.F_OperateType = "sms";
  104. logEntity.F_OperateAccount = "system";
  105. logEntity.F_ExecuteResult = 400;
  106. logEntity.F_ExecuteResultJson = "短信发送失败:" + e.Message;
  107. logEntity.F_Description = "短信发送:" + mobileVerify.mobile;
  108. logEntity.WriteLog();
  109. }
  110. return Success("短信验证码已成功发送。");
  111. }
  112. else
  113. {
  114. return Fail("验证失败,验证码错误或已失效。");
  115. }
  116. }
  117. /// <summary>
  118. /// 获取图形验证码
  119. /// </summary>
  120. /// <param name="_">页面编号</param>
  121. /// <returns></returns>
  122. public Response GetVerifyCode(dynamic _)
  123. {
  124. string pagecode = this.GetReqData();
  125. return new StreamResponse(() => GetImgVerifyCode(pagecode), "image/Gif");
  126. }
  127. public Stream GetImgVerifyCode(string pagecode)
  128. {
  129. MemoryStream ms = null;
  130. try
  131. {
  132. (byte[] buffer,string code) = new VerifyCode().GetVerifyCodeForMobileApi();
  133. redisCache.Write<string>("sunshineimgvcode_" + pagecode, code, new TimeSpan(0, 30, 0));
  134. ms = new MemoryStream(buffer);
  135. return ms;
  136. }
  137. catch (Exception e)
  138. {
  139. return null;
  140. }
  141. //finally
  142. //{
  143. // if (ms != null)
  144. // {
  145. // ms.Close();
  146. // ms.Dispose();
  147. // }
  148. //}
  149. }
  150. /// <summary>
  151. /// 获取页面显示列表分页数据
  152. /// <summary>
  153. /// <param name="_"></param>
  154. /// <returns></returns>
  155. public Response GetPageList(dynamic _)
  156. {
  157. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  158. var data = sunshineEducationIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  159. var jsonData = new
  160. {
  161. rows = data,
  162. total = parameter.pagination.total,
  163. page = parameter.pagination.page,
  164. records = parameter.pagination.records
  165. };
  166. return Success(jsonData);
  167. }
  168. /// <summary>
  169. /// 获取页面显示列表数据
  170. /// <summary>
  171. /// <param name="_"></param>
  172. /// <returns></returns>
  173. public Response GetList(dynamic _)
  174. {
  175. string queryJson = this.GetReqData();
  176. var data = sunshineEducationIBLL.GetList(queryJson);
  177. return Success(data);
  178. }
  179. /// <summary>
  180. /// 获取表单数据
  181. /// <summary>
  182. /// <param name="_"></param>
  183. /// <returns></returns>
  184. public Response GetForm(dynamic _)
  185. {
  186. string keyValue = this.GetReqData();
  187. var sunshineEducationData = sunshineEducationIBLL.GetEntity(keyValue);
  188. sunshineEducationData.Contents = WebHelper.HtmlDecode(sunshineEducationData.Contents);
  189. var jsonData = new
  190. {
  191. sunshineEducation = sunshineEducationData,
  192. };
  193. return Success(jsonData);
  194. }
  195. public Response StatisticsForm(dynamic _)
  196. {
  197. var data = sunshineEducationIBLL.GetAllList();
  198. var zsNum = data.Count();
  199. var yclNum = data.Count(x => x.Status == 2);
  200. var slzNum = data.Count(x => x.Status == 1);
  201. var wclNum = data.Count(x => x.Status == 0);
  202. return Success(new { zsNum, yclNum, wclNum,slzNum });
  203. }
  204. #endregion
  205. #region 提交数据
  206. ///// <summary>
  207. ///// 删除实体数据
  208. ///// <param name="_"></param>
  209. ///// <summary>
  210. ///// <returns></returns>
  211. //public Response DeleteForm(dynamic _)
  212. //{
  213. // string keyValue = this.GetReqData();
  214. // sunshineEducationIBLL.DeleteEntity(keyValue);
  215. // return Success("删除成功!");
  216. //}
  217. /// <summary>
  218. /// 保存实体数据(新增、修改)
  219. /// <param name="_"></param>
  220. /// <summary>
  221. /// <returns></returns>
  222. public Response SaveForm(dynamic _)
  223. {
  224. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  225. SunshineEducationEntity entity = parameter.strEntity.ToObject<SunshineEducationEntity>();
  226. if (!string.IsNullOrEmpty(parameter.keyValue))
  227. {
  228. var data = sunshineEducationIBLL.GetEntity(parameter.keyValue);
  229. if (data.AcceptanceCode != entity.AcceptanceCode)
  230. {
  231. return Fail("评论失败,受理单号不正确");
  232. }
  233. entity.Contents = data.Contents;
  234. sunshineEducationIBLL.SaveEntity(parameter.keyValue, entity);
  235. return Success("提交成功!");
  236. }
  237. else
  238. {
  239. entity.Contents = WebHelper.HtmlEncode(entity.Contents);
  240. var code = redisCache.Read<string>("sunshinesmscode_" +entity.pagecode+"_" + entity.mobile);
  241. if (entity.smscode== code)
  242. {
  243. sunshineEducationIBLL.SaveEntity(parameter.keyValue, entity);
  244. return Success("提交成功!");
  245. }
  246. else
  247. {
  248. return Fail("验证失败,验证码错误或已失效。");
  249. }
  250. }
  251. }
  252. /// <summary>
  253. /// 点击累计
  254. /// <param name="_"></param>
  255. /// <summary>
  256. /// <returns></returns>
  257. public Response ClicksForm(dynamic _)
  258. {
  259. string keyValue = this.GetReqData();
  260. sunshineEducationIBLL.ClicksEntity(keyValue);
  261. return Success("点击数据!");
  262. }
  263. #endregion
  264. #region 上传附件图片文件
  265. /// <summary>
  266. /// 上传附件图片文件
  267. /// <summary>
  268. /// <returns></returns>
  269. public Response Upload(dynamic _)
  270. {
  271. var files = (List<HttpFile>)this.Context.Request.Files;
  272. string folderId = Guid.NewGuid().ToString();
  273. string filePath = Config.GetValue("AnnexesFile");
  274. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  275. string fileEextension = Path.GetExtension(files[0].Name);
  276. string fileType = fileEextension.Replace(".", "");
  277. string fileGuid = Guid.NewGuid().ToString();
  278. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, "system", uploadDate, fileGuid, fileEextension);
  279. //创建文件夹
  280. string path = Path.GetDirectoryName(virtualPath);
  281. Directory.CreateDirectory(path);
  282. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  283. if (!System.IO.File.Exists(virtualPath))
  284. {
  285. byte[] bytes = new byte[files[0].Value.Length];
  286. files[0].Value.Read(bytes, 0, bytes.Length);
  287. FileInfo file = new FileInfo(virtualPath);
  288. FileStream fs = file.Create();
  289. fs.Write(bytes, 0, bytes.Length);
  290. fs.Close();
  291. //文件信息写入数据库
  292. fileAnnexesEntity.F_Id = fileGuid;
  293. fileAnnexesEntity.F_FileName = files[0].Name;
  294. fileAnnexesEntity.F_FilePath = virtualPath;
  295. fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
  296. fileAnnexesEntity.F_FileExtensions = fileEextension;
  297. fileAnnexesEntity.F_FileType = fileType;
  298. fileAnnexesEntity.F_CreateUserId = "system";
  299. fileAnnexesEntity.F_CreateUserName = "system";
  300. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  301. }
  302. return SuccessString(folderId);
  303. }
  304. /// <summary>
  305. /// 删除文件
  306. /// </summary>
  307. /// <param name="_"></param>
  308. /// <returns></returns>
  309. public Response DeleteFile(dynamic _)
  310. {
  311. var fileId = this.GetReqData();
  312. AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
  313. annexesFileIBLL.DeleteEntity(fileId);
  314. //删除文件
  315. if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
  316. {
  317. System.IO.File.Delete(fileInfoEntity.F_FilePath);
  318. }
  319. return Success("删除成功");
  320. }
  321. /// <summary>
  322. /// 下载文件
  323. /// </summary>
  324. /// <param name="_"></param>
  325. /// <returns></returns>
  326. public Response DownAnnexesFile(dynamic _)
  327. {
  328. string name = this.GetReqData();
  329. string fileId = name.Split('.')[0];
  330. var data = annexesFileIBLL.GetEntity(fileId);
  331. string filepath = data.F_FilePath;
  332. if (FileDownHelper.FileExists(filepath))
  333. {
  334. FileDownHelper.DownLoadnew(filepath);
  335. }
  336. return Success("");
  337. }
  338. #endregion
  339. #region 私有类
  340. /// <summary>
  341. /// 表单实体类
  342. /// <summary>
  343. private class ReqFormEntity
  344. {
  345. public string keyValue { get; set; }
  346. public string strEntity { get; set; }
  347. }
  348. public class MobileVerify
  349. {
  350. public string mobile { get; set; }
  351. public string verifycode { get; set; }
  352. public string pagecode { get;set; }
  353. }
  354. #endregion
  355. }
  356. }