using Nancy; using Learun.Util; using System.Collections.Generic; using Learun.Application.TwoDevelopment.EducationalAdministration; using System; using Learun.Application.Base.SystemModule; using System.IO; using System.Web.Mvc; using Learun.Application.WebApi.Modules; using System.Linq; namespace Learun.Application.WebApi { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创 建:超级管理员 /// 日 期:2020-06-03 14:29 /// 描 述:听课记录 /// public class SunshineEducationApi : BaseNoLoginApi { private SunshineEducationIBLL sunshineEducationIBLL = new SunshineEducationBLL(); private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); /// /// 阳光教育 /// public SunshineEducationApi() : base("/Learun/adms/SunshineEducation") { Get["/pagelist"] = GetPageList; Get["/list"] = GetList; Get["/form"] = GetForm; Get["/statistics"] = StatisticsForm; //Post["/delete"] = DeleteForm; Get["/down"] = DownAnnexesFile; Post["/upload"] = Upload; Post["/save"] = SaveForm;//提交,回复,评论 Post["/clicks"] = ClicksForm; } #region 获取数据 /// /// 获取页面显示列表分页数据 /// /// /// public Response GetPageList(dynamic _) { ReqPageParam parameter = this.GetReqData(); var data = sunshineEducationIBLL.GetPageList(parameter.pagination, parameter.queryJson); var jsonData = new { rows = data, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records }; return Success(jsonData); } /// /// 获取页面显示列表数据 /// /// /// public Response GetList(dynamic _) { string queryJson = this.GetReqData(); var data = sunshineEducationIBLL.GetList(queryJson); return Success(data); } /// /// 获取表单数据 /// /// /// public Response GetForm(dynamic _) { string keyValue = this.GetReqData(); var sunshineEducationData = sunshineEducationIBLL.GetEntity(keyValue); sunshineEducationData.Contents = WebHelper.HtmlDecode(sunshineEducationData.Contents); var jsonData = new { sunshineEducation = sunshineEducationData, }; return Success(jsonData); } public Response StatisticsForm(dynamic _) { var data = sunshineEducationIBLL.GetAllList(); var zsNum = data.Count(); var yclNum = data.Count(x => x.Status == 2); var slzNum = data.Count(x => x.Status == 1); var wclNum = data.Count(x => x.Status == 0); return Success(new { zsNum, yclNum, wclNum,slzNum }); } #endregion #region 提交数据 ///// ///// 删除实体数据 ///// ///// ///// //public Response DeleteForm(dynamic _) //{ // string keyValue = this.GetReqData(); // sunshineEducationIBLL.DeleteEntity(keyValue); // return Success("删除成功!"); //} /// /// 保存实体数据(新增、修改) /// /// /// public Response SaveForm(dynamic _) { ReqFormEntity parameter = this.GetReqData(); SunshineEducationEntity entity = parameter.strEntity.ToObject(); if (!string.IsNullOrEmpty(parameter.keyValue)) { var data = sunshineEducationIBLL.GetEntity(parameter.keyValue); if (data.AcceptanceCode != entity.AcceptanceCode) { return Fail("评论失败,受理单号不正确"); } entity.Contents = data.Contents; } else { entity.Contents = WebHelper.HtmlEncode(entity.Contents); } sunshineEducationIBLL.SaveEntity(parameter.keyValue, entity); return Success("保存成功!"); } /// /// 点击累计 /// /// /// public Response ClicksForm(dynamic _) { string keyValue = this.GetReqData(); sunshineEducationIBLL.ClicksEntity(keyValue); return Success("点击数据!"); } #endregion #region 上传附件图片文件 /// /// 上传附件图片文件 /// /// public Response Upload(dynamic _) { var files = (List)this.Context.Request.Files; string folderId = Guid.NewGuid().ToString(); string filePath = Config.GetValue("AnnexesFile"); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string fileEextension = Path.GetExtension(files[0].Name); string fileType = fileEextension.Replace(".", ""); string fileGuid = Guid.NewGuid().ToString(); string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, "system", uploadDate, fileGuid, fileEextension); //创建文件夹 string path = Path.GetDirectoryName(virtualPath); Directory.CreateDirectory(path); AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity(); if (!System.IO.File.Exists(virtualPath)) { byte[] bytes = new byte[files[0].Value.Length]; files[0].Value.Read(bytes, 0, bytes.Length); FileInfo file = new FileInfo(virtualPath); FileStream fs = file.Create(); fs.Write(bytes, 0, bytes.Length); fs.Close(); //文件信息写入数据库 fileAnnexesEntity.F_Id = fileGuid; fileAnnexesEntity.F_FileName = files[0].Name; fileAnnexesEntity.F_FilePath = virtualPath; fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString(); fileAnnexesEntity.F_FileExtensions = fileEextension; fileAnnexesEntity.F_FileType = fileType; fileAnnexesEntity.F_CreateUserId = "system"; fileAnnexesEntity.F_CreateUserName = "system"; annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity); } return SuccessString(folderId); } /// /// 删除文件 /// /// /// public Response DeleteFile(dynamic _) { var fileId = this.GetReqData(); AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId); annexesFileIBLL.DeleteEntity(fileId); //删除文件 if (System.IO.File.Exists(fileInfoEntity.F_FilePath)) { System.IO.File.Delete(fileInfoEntity.F_FilePath); } return Success("删除成功"); } /// /// 下载文件 /// /// /// public Response DownAnnexesFile(dynamic _) { string name = this.GetReqData(); string fileId = name.Split('.')[0]; var data = annexesFileIBLL.GetEntity(fileId); string filepath = data.F_FilePath; if (FileDownHelper.FileExists(filepath)) { FileDownHelper.DownLoadnew(filepath); } return Success(""); } #endregion #region 私有类 /// /// 表单实体类 /// private class ReqFormEntity { public string keyValue { get; set; } public string strEntity { get; set; } } #endregion } }