public FormDataModel Process(string id) { var result = new FormDataModel() { success = true, data = new List <Dictionary <string, string> >() }; if (string.IsNullOrEmpty(id)) { return(result); } var idArr = id.Split('_'); var companyId = Convert.ToInt32(idArr[1]); var dic = new Dictionary <string, string>(); var company = _companyBll.GetCompanyByKey(companyId); dic.Add("CompanyId", company.CompanyId.ToString()); dic.Add("AreaId", company.AreaId.ToString()); dic.Add("CompanyName", company.CompanyName?.ToString()); dic.Add("ArtificialPerson", company.ArtificialPerson?.ToString()); dic.Add("SetUpTime", company.SetUpTime.GetFormatStr()); dic.Add("CompanyPhone", company.CompanyPhone?.ToString()); dic.Add("Address", company.Address?.ToString()); result.data.Add(dic); return(result); }
/// <summary> /// 业务逻辑 /// </summary> /// <param name="excelId"></param> /// <returns></returns> public Stream Process(string ids) { var excelDatas = new List <List <string> >(); excelDatas.Add(GetExcelTitel()); var idsArr = ids.Split(','); var companyList = new List <Company>(); var areas = _companyBll.GetAllArea(); foreach (var id in idsArr) { if (string.IsNullOrEmpty(id)) { continue; } var idArr = id.Split('_'); var findId = Convert.ToInt32(idArr[1]); if (idArr[0] == "1") { var companys = _companyBll.GetCompanyByAreaId(findId); if (companys != null) { companyList.AddRange(companys); } } else { var company = _companyBll.GetCompanyByKey(findId); if (company != null) { companyList.Add(company); } } } foreach (var company in companyList) { var area = areas.FirstOrDefault(x => x.AreaId == company.AreaId); var companyRecords = _companyBll.GetCompanyconnectrecordByCompanyId(company.CompanyId); if (companyRecords != null && companyRecords.Count > 0) { foreach (var record in companyRecords) { excelDatas.Add(GetOneCellData(area, company, record)); } } else { excelDatas.Add(GetOneCellData(area, company, new CompanyConnectRecord())); } } var excelBuilder = ExcelFactory.CreateBuilder(); var sheet = excelBuilder.InsertSheet("sheet1"); sheet.InsertSheetContent(ExcelExportRequest.GetInstance(excelDatas)); var stream = new MemoryStream(); excelBuilder.Save(stream, SaveFormat.Xlsx); stream.Position = 0; return(stream); }