|
@@ -14,9 +14,11 @@ using OASystem.Domain.ViewModels.Groups;
|
|
|
using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
using OASystem.Infrastructure.Repositories.Groups;
|
|
|
+using Org.BouncyCastle.Asn1.X509;
|
|
|
using Org.BouncyCastle.Utilities.Encoders;
|
|
|
using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
using static OASystem.API.OAMethodLib.JWTHelper;
|
|
|
using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
|
|
|
using static QRCoder.PayloadGenerator.SwissQrCode;
|
|
@@ -1734,6 +1736,273 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
|
|
|
}
|
|
|
return Ok(JsonView(true, "删除成功!"));
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 商邀资料 ExcelExport
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> InvitationOfficialActivityExcelExport(QueryInvitationOfficialActivityDataDto dto)
|
|
|
+ {
|
|
|
+ var ExcludedKeyStr = new string[] { "快递费" };
|
|
|
+ var ClientKeyStr = new string[] { "邀请函翻译" };
|
|
|
+ var columns = "Id,UnitName,Contact";
|
|
|
+
|
|
|
+ #region 参数验证
|
|
|
+
|
|
|
+ if (dto.PageIndex < 1) return Ok(JsonView(false, "请传入有效的PageIndex参数!"));
|
|
|
+
|
|
|
+ if (dto.PageSize < 1) return Ok(JsonView(false, "请传入有效的PageSize参数!"));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.Country)) { columns += ",Country"; }
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.Delegation)) { columns += ",Delegation"; }
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.Field)) { columns += ",Field"; }
|
|
|
+
|
|
|
+ DateTime endTime = new DateTime();
|
|
|
+ var InvitationOfficialActivityDataList = _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
|
|
|
+ .Where(x => x.IsDel == 0)
|
|
|
+ .WhereIF(dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString()), x => x.CreateUserId == dto.CreateUserId)
|
|
|
+ .WhereIF(DateTime.TryParse(dto.StartCreateTime, out DateTime startTime) && DateTime.TryParse(dto.EndCreateTime, out endTime), x => x.CreateTime >= startTime && x.CreateTime <= endTime)
|
|
|
+ .Select(columns)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var item in InvitationOfficialActivityDataList)
|
|
|
+ {
|
|
|
+ EncryptionProcessor.DecryptProperties(item);
|
|
|
+ }
|
|
|
+ InvitationOfficialActivityDataList = InvitationOfficialActivityDataList
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(dto.Country), x => !string.IsNullOrWhiteSpace(x.Country) && x.Country.Contains(dto.Country))
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(dto.UnitName), x => !string.IsNullOrWhiteSpace(x.UnitName) && x.UnitName.Contains(dto.UnitName))
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(dto.Contact), x => !string.IsNullOrWhiteSpace(x.Contact) && x.Contact.Contains(dto.Contact))
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(dto.Delegation), x => !string.IsNullOrWhiteSpace(x.Delegation) && x.Delegation.Contains(dto.Delegation))
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(dto.Field), x => !string.IsNullOrWhiteSpace(x.Field) && x.Field.Contains(dto.Field))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var item in ExcludedKeyStr)
|
|
|
+ {
|
|
|
+ InvitationOfficialActivityDataList = InvitationOfficialActivityDataList.Where(x => string.IsNullOrWhiteSpace(x.UnitName) || !x.UnitName.Contains(item)).ToList();
|
|
|
+ //sqlWhere += $" And i.UnitName not like '%{item}%' ";
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var item in ClientKeyStr)
|
|
|
+ {
|
|
|
+ InvitationOfficialActivityDataList = InvitationOfficialActivityDataList.Where(x => string.IsNullOrWhiteSpace(x.Contact) || !x.Contact.Contains(item)).ToList();
|
|
|
+ //sqlWhere += $" And i.Contact not like '%{item}%' ";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var ids = InvitationOfficialActivityDataList.Select(x => x.Id);
|
|
|
+
|
|
|
+ var _ivitiesViews = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
|
|
|
+ .LeftJoin<Sys_Users>((a, b) => b.IsDel == 0 && a.CreateUserId == b.Id)
|
|
|
+ .Where((a, b) => ids.Contains(a.Id))
|
|
|
+ .OrderByDescending((a, b) => a.CreateTime)
|
|
|
+ .Select((a, b) => new IOAInfoView
|
|
|
+ {
|
|
|
+ FaceBook = a.FaceBook,
|
|
|
+ Id = a.Id,
|
|
|
+ Address = a.Address,
|
|
|
+ Background = a.Background,
|
|
|
+ City = a.City,
|
|
|
+ Contact = a.Contact,
|
|
|
+ Country = a.Country,
|
|
|
+ Delegation = a.Delegation,
|
|
|
+ Email = a.Email,
|
|
|
+ Fax = a.Fax,
|
|
|
+ Field = a.Field,
|
|
|
+ Ins = a.Ins,
|
|
|
+ WeChat = a.WeChat,
|
|
|
+ UnitWeb = a.UnitWeb,
|
|
|
+ UnitName = a.UnitName,
|
|
|
+ UnitInfo = a.UnitInfo,
|
|
|
+ Tel = a.Tel,
|
|
|
+ SndFileName = a.SndFileName,
|
|
|
+ Remark = a.Remark,
|
|
|
+ OtherInfo = a.OtherInfo,
|
|
|
+ Job = a.Job
|
|
|
+ })
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ if (!_ivitiesViews.Any()) return Ok(JsonView(false, $"您查询的数据暂无内容,不可导出!"));
|
|
|
+
|
|
|
+ var allGroupIds = new HashSet<int>();
|
|
|
+ foreach (var item in _ivitiesViews)
|
|
|
+ {
|
|
|
+ EncryptionProcessor.DecryptProperties(item);
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(item.Delegation))
|
|
|
+ {
|
|
|
+ allGroupIds.UnionWith(
|
|
|
+ item.Delegation.Split(',')
|
|
|
+ .Select(x =>
|
|
|
+ {
|
|
|
+ int id;
|
|
|
+ if (int.TryParse(x, out id)) return id;
|
|
|
+ return 0;
|
|
|
+ })
|
|
|
+ .Where(id => id != 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>()
|
|
|
+ .Where(x => allGroupIds.Contains(x.Id) && x.IsDel == 0)
|
|
|
+ .ToList()
|
|
|
+ .GroupBy(x => x.Id)
|
|
|
+ .ToDictionary(group => group.Key, group => group.Select(g => g.TeamName));
|
|
|
+
|
|
|
+ foreach (var item in _ivitiesViews)
|
|
|
+ {
|
|
|
+ string groupNameStr = "";
|
|
|
+ if (!string.IsNullOrEmpty(item.Delegation))
|
|
|
+ {
|
|
|
+ var groupIds = item.Delegation.Split(',').Select(x =>
|
|
|
+ {
|
|
|
+ int id;
|
|
|
+ if (int.TryParse(x, out id)) return id;
|
|
|
+ return 0;
|
|
|
+ })
|
|
|
+ .Where(id => id != 0)
|
|
|
+ .ToArray();
|
|
|
+
|
|
|
+ foreach (var id in groupIds)
|
|
|
+ {
|
|
|
+ if (_DelegationInfos.ContainsKey(id))
|
|
|
+ {
|
|
|
+ groupNameStr += string.Join("", _DelegationInfos[id]) + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (groupNameStr.Length > 1)
|
|
|
+ {
|
|
|
+ groupNameStr = groupNameStr.Substring(0, groupNameStr.Length - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ item.DelegationStr = groupNameStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取模板
|
|
|
+ string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/商邀资料模板.xls");
|
|
|
+ var designer = new WorkbookDesigner();
|
|
|
+ designer.Workbook = new Workbook(tempPath);
|
|
|
+
|
|
|
+ var dt = CommonFun.ToDataTableArray(_ivitiesViews);
|
|
|
+ dt.TableName = $"OADataView";
|
|
|
+
|
|
|
+ designer.SetDataSource(dt);
|
|
|
+ designer.Process();
|
|
|
+
|
|
|
+ //文件名
|
|
|
+ string fileName = $"商邀资料{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
|
|
|
+ designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "InvitationOfficialActivityExport/" + fileName);
|
|
|
+ string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/InvitationOfficialActivityExport/" + fileName;
|
|
|
+ return Ok(JsonView(true, "成功", url));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 商邀资料 导入文件(Excel)模板下载
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> InvitationOfficialActivityExcelTemplateExport()
|
|
|
+ {
|
|
|
+ //获取模板
|
|
|
+ string fileName = $"商邀资料上传文件模板.xls";
|
|
|
+ string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/Template/" + fileName;
|
|
|
+ return Ok(JsonView(true, "成功", url));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 商邀资料 导入文件(Excel)模板下载
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="file"></param>
|
|
|
+ /// <param name="currUserId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> InvitationOfficialActivityExcelUpload(IFormFile file,int currUserId)
|
|
|
+ {
|
|
|
+ var fileName = file.FileName;
|
|
|
+ var filePostfix = fileName.Split(".")[1].ToUpper();
|
|
|
+ if (!filePostfix.Contains("XLS")) return Ok(JsonView(false, $"请传入Excel文件"));
|
|
|
+ if (file.Length < 1) return Ok(JsonView(false, $"请传入有效的文件"));
|
|
|
+ if (currUserId < 1) return Ok(JsonView(false, $"请传入有效的UserId"));
|
|
|
+
|
|
|
+ //保存文件
|
|
|
+ string fileDirPath = string.Format(@"{0}InvitationOfficialActivityExcelUpload/", AppSettingsHelper.Get("ExcelBasePath"));
|
|
|
+ if (!Directory.Exists(fileDirPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(fileDirPath);
|
|
|
+ }
|
|
|
+ var filePath = Path.Combine(fileDirPath, fileName);
|
|
|
+ await using var stream = new FileStream(filePath, FileMode.Create);
|
|
|
+ await file.CopyToAsync(stream);
|
|
|
+
|
|
|
+ //读取保存的文件
|
|
|
+ Workbook workbook = new Workbook(filePath);
|
|
|
+ if (workbook == null) return Ok(JsonView(false, $"Excel文件不存在!"));
|
|
|
+ Worksheet worksheet = workbook.Worksheets[0];
|
|
|
+ if (worksheet == null) return Ok(JsonView(false, $"Excel文件工作簿不存在!"));
|
|
|
+
|
|
|
+ var infos = new List<Res_InvitationOfficialActivityData>();
|
|
|
+ var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName)).Select(x => new { x.Id, x.TeamName }).ToListAsync();
|
|
|
+ for (int row = 1; row < worksheet.Cells.MaxDataRow + 1; row++)
|
|
|
+ {
|
|
|
+ var groupIdsLabel = string.Empty;
|
|
|
+ var groupNames1 = worksheet.Cells[row, 14].StringValue ?? "-";
|
|
|
+ if (!string.IsNullOrEmpty(groupNames1))
|
|
|
+ {
|
|
|
+ if (groupNames1.Contains(";"))
|
|
|
+ {
|
|
|
+ var groupNameArray = groupNames1.Split(";").Where(x => !string.IsNullOrEmpty(x)).ToList();
|
|
|
+
|
|
|
+ var groupIds = groupNames.Where(x => groupNameArray.Contains(x.TeamName)).Select(x => x.Id).ToList();
|
|
|
+ if (groupIds.Any()) groupIdsLabel = string.Join(',', groupIds);
|
|
|
+ }
|
|
|
+ else groupIdsLabel = groupNames.Where(x => groupNames1.Equals(x.TeamName)).FirstOrDefault()?.Id.ToString() ?? string.Empty;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ infos.Add(new Res_InvitationOfficialActivityData() {
|
|
|
+ Country = worksheet.Cells[row, 0].StringValue ?? "-",
|
|
|
+ City = worksheet.Cells[row, 1].StringValue ?? "-",
|
|
|
+ UnitName = worksheet.Cells[row, 2].StringValue ?? "-",
|
|
|
+ Field = worksheet.Cells[row, 3].StringValue ?? "-",
|
|
|
+ Address = worksheet.Cells[row, 4].StringValue ?? "-",
|
|
|
+ UnitInfo = worksheet.Cells[row, 5].StringValue ?? "-",
|
|
|
+ Contact = worksheet.Cells[row, 6].StringValue ?? "-",
|
|
|
+ Job = worksheet.Cells[row, 7].StringValue ?? "-",
|
|
|
+ Tel = worksheet.Cells[row, 8].StringValue ?? "-",
|
|
|
+ Email = worksheet.Cells[row, 9].StringValue ?? "-",
|
|
|
+ WeChat = worksheet.Cells[row, 10].StringValue ?? "-",
|
|
|
+ FaceBook = worksheet.Cells[row, 11].StringValue ?? "-",
|
|
|
+ Ins = worksheet.Cells[row, 12].StringValue ?? "-",
|
|
|
+ Fax = worksheet.Cells[row, 13].StringValue ?? "-",
|
|
|
+ Delegation = groupIdsLabel,
|
|
|
+ SndFilePath = worksheet.Cells[row, 15].StringValue ?? "-",
|
|
|
+ OtherInfo = worksheet.Cells[row, 16].StringValue ?? "-",
|
|
|
+ Remark = $"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] Excel上传文件添加! 文件存储地址[{filePath}]",
|
|
|
+ CreateUserId = currUserId,
|
|
|
+ IsDel = 0
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //加密
|
|
|
+ foreach (var item in infos) EncryptionProcessor.EncryptProperties(item);
|
|
|
+
|
|
|
+ var addCount = await _sqlSugar.Insertable(infos).ExecuteCommandAsync();
|
|
|
+ if (addCount < 1) return Ok(JsonView(false, "文件上传添加失败!"));
|
|
|
+
|
|
|
+ return Ok(JsonView(true, $"上传文件添加成功!共添加{addCount}条!"));
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 公务出访
|