using APT.BaseData.Domain.ApiModel; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.AE; using APT.BaseData.Domain.IServices.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.HM; using APT.MS.Domain.Entities.OH; using APT.MS.Domain.Entities.PF; using APT.MS.Domain.Entities.SC; using APT.MS.Domain.Entities.TI; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Linq.Expressions; //namespace APT.BS.WebApi.Controllers.Api namespace APT.SC.WebApi.Controllers.Api.OH { [Route("api/PF/OHHealthExamResult")] public class PFHealthExamResultController : AuthorizeApiController { IFMFlowPermitService MFlowPermitService { get; set; } IPFApproveCallBackService ApproveCallBackService { get; set; } IAEAccidentEventReportService AccidentEventReportService { get; set; } IFMNotificationTaskService NotificationTaskService { get; set; } IFMUserService UserService { get; set; } IFMDepartmentService DepartmentService { get; set; } public PFHealthExamResultController(IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IAEAccidentEventReportService accidentEventReportService, IFMNotificationTaskService notificationTaskService, IFMUserService userService, IFMDepartmentService departmentService) { MFlowPermitService = mFlowPermitService; ApproveCallBackService = approveCallBackService; AccidentEventReportService = accidentEventReportService; NotificationTaskService = notificationTaskService; UserService = userService; DepartmentService = departmentService; } /// /// 显示批量导入数据 /// /// /// [HttpPost, Route("ImportShow")] public PagedActionResult ImportShow(IFormCollection filer) { //[FromBody] KeywordPageFilter pageFilter //return WitOrderPaged(null, pageFilter); return SafeGetPagedData(delegate (PagedActionResult result) { var httpRequest = this.HttpContext.Request; string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 Guid? orgId = null; if (!string.IsNullOrEmpty(orgIdStr)) orgId = new Guid(orgIdStr); else { result.Data = null;//dataTables.Tables[0] result.TotalCount = 0; } var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); if (!Directory.Exists(dic)) Directory.CreateDirectory(dic); foreach (var key in httpRequest.Form.Files) // 文件键 { var postedFile = key; // 获取文件键对应的文件对象 string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); Byte[] fileData = new Byte[postedFile.Length]; Stream sr = postedFile.OpenReadStream();//创建数据流对象 sr.Read(fileData, 0, (int)postedFile.Length); using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(fileData, 0, fileData.Length); fs.Flush(); fs.Close(); } //获取数据 Dictionary startRowIndexs = new Dictionary(); startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); //bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, ref Msg); //try //{ // System.IO.File.Delete(filePath); //} //catch { } //result.Data = orderPageEntities.Data;//dataTables.Tables[0] result.TotalCount = dataTables.Tables[0].Rows.Count; } //return result; }); } ///// ///// 显示批量导入数据 ///// ///// ///// //[HttpPost, Route("ImportShow")] //public PagedActionResult ImportShow([FromBody] KeywordPageFilter pageFilter) //{ // //return WitOrderPaged(null, pageFilter); // return SafeGetPagedData(delegate (PagedActionResult result) // { // var httpRequest = this.HttpContext.Request; // string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 // Guid? orgId = null; // if (!string.IsNullOrEmpty(orgIdStr)) // orgId = new Guid(orgIdStr); // else // { // result.Data = null;//dataTables.Tables[0] // result.TotalCount = 0; // } // var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); // if (!Directory.Exists(dic)) // Directory.CreateDirectory(dic); // foreach (var key in httpRequest.Form.Files) // 文件键 // { // var postedFile = key; // 获取文件键对应的文件对象 // string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); // Byte[] fileData = new Byte[postedFile.Length]; // Stream sr = postedFile.OpenReadStream();//创建数据流对象 // sr.Read(fileData, 0, (int)postedFile.Length); // using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) // { // fs.Write(fileData, 0, fileData.Length); // fs.Flush(); // fs.Close(); // } // //获取数据 // Dictionary startRowIndexs = new Dictionary(); // startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 // var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); // //bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, ref Msg); // //try // //{ // // System.IO.File.Delete(filePath); // //} // //catch { } // //result.Data = orderPageEntities.Data;//dataTables.Tables[0] // result.TotalCount = dataTables.Tables[0].Rows.Count; // } // //return result; // }); //} } }