|
@@ -1,9 +1,13 @@
|
|
|
|
+using Aspose.Cells;
|
|
|
|
+using NPOI.POIFS.Crypt;
|
|
using OASystem.Domain.AesEncryption;
|
|
using OASystem.Domain.AesEncryption;
|
|
using OASystem.Domain.Entities.Customer;
|
|
using OASystem.Domain.Entities.Customer;
|
|
using OASystem.Domain.Entities.Financial;
|
|
using OASystem.Domain.Entities.Financial;
|
|
using OASystem.Domain.Entities.Groups;
|
|
using OASystem.Domain.Entities.Groups;
|
|
using System.Collections;
|
|
using System.Collections;
|
|
using System.Data;
|
|
using System.Data;
|
|
|
|
+using System.Dynamic;
|
|
|
|
+using System.Linq;
|
|
using static OASystem.API.OAMethodLib.GeneralMethod;
|
|
using static OASystem.API.OAMethodLib.GeneralMethod;
|
|
using static OASystem.API.OAMethodLib.JWTHelper;
|
|
using static OASystem.API.OAMethodLib.JWTHelper;
|
|
|
|
|
|
@@ -3053,5 +3057,172 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
+ #region 动态读取excel并去重
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 客户名单excel导入
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [HttpPost]
|
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
|
+ public async Task<IActionResult> DynamicReadExcel(IFormFile file )
|
|
|
|
+ {
|
|
|
|
+ // 检查文件是否为空
|
|
|
|
+ if (file == null || file.Length == 0)
|
|
|
|
+ {
|
|
|
|
+ return BadRequest("No file uploaded.");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存文件到服务器
|
|
|
|
+ var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "File");
|
|
|
|
+ if (!Directory.Exists(uploadsFolder))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(uploadsFolder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var filePath = Path.Combine(uploadsFolder, file.FileName);
|
|
|
|
+ using (var stream = new FileStream(filePath, FileMode.Create))
|
|
|
|
+ {
|
|
|
|
+ await file.CopyToAsync(stream);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Workbook workbook = new Workbook(filePath);
|
|
|
|
+
|
|
|
|
+ // 获取第一个工作表
|
|
|
|
+ Worksheet worksheet = workbook.Worksheets[0];
|
|
|
|
+
|
|
|
|
+ // 获取表头(第一行作为列名)
|
|
|
|
+ int headerRowIndex = 0; // 假设第一行是表头
|
|
|
|
+ Row headerRow = worksheet.Cells.Rows[headerRowIndex];
|
|
|
|
+ int colCount = worksheet.Cells.MaxDataColumn + 1;
|
|
|
|
+
|
|
|
|
+ // 动态存储列名
|
|
|
|
+ var clients = new List<Crm_NewClientData>();
|
|
|
|
+
|
|
|
|
+ var lvData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 33).ToList();
|
|
|
|
+
|
|
|
|
+ // 遍历数据行(从第二行开始)
|
|
|
|
+ int rowCount = worksheet.Cells.MaxDataRow + 1;
|
|
|
|
+ for (int row = headerRowIndex + 1; row < rowCount; row++)
|
|
|
|
+ {
|
|
|
|
+ var cellVal1 = worksheet.Cells[row, 0].Value; //序号
|
|
|
|
+ var cellVal2 = worksheet.Cells[row, 1].Value; //区域分类
|
|
|
|
+ var cellVal3 = worksheet.Cells[row, 2].Value; //省级分类
|
|
|
|
+ var cellVal4 = worksheet.Cells[row, 3].Value; //单位名称
|
|
|
|
+ var cellVal5 = worksheet.Cells[row, 4].Value; //单位详细地址
|
|
|
|
+ var cellVal6 = worksheet.Cells[row, 5].Value; //座机号
|
|
|
|
+ var cellVal7 = worksheet.Cells[row, 6].Value; //所在城市
|
|
|
|
+ var cellVal8 = worksheet.Cells[row, 7].Value; //分配人Id
|
|
|
|
+
|
|
|
|
+ int userId = !string.IsNullOrEmpty(cellVal8?.ToString()) ? int.Parse(cellVal8?.ToString()) : 0;
|
|
|
|
+ var rowData = new Crm_NewClientData() {
|
|
|
|
+ Number = userId,
|
|
|
|
+ Lvlid = lvData.FirstOrDefault(x => x.Name.Equals(cellVal2?.ToString()))?.Id ?? 0,//区域分类
|
|
|
|
+ Client = cellVal4?.ToString().Trim(),//单位名称
|
|
|
|
+ Weight = "C",//客户权重
|
|
|
|
+ Phone = cellVal6?.ToString(), //座机号
|
|
|
|
+ Location = cellVal7?.ToString(),//所在城市
|
|
|
|
+ Address = cellVal5?.ToString(),//单位详细地址
|
|
|
|
+ LastUpdateUserId = 4, //最后更新人
|
|
|
|
+ LastUpdateTime = DateTime.Now, //最后更新时间
|
|
|
|
+ CreateUserId = 4, //创建人
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ clients.Add(rowData); // 将当前行数据添加到集合中
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (clients.Any())
|
|
|
|
+ {
|
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ int total = 0;
|
|
|
|
+ foreach (var item in clients)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ var userId = item.Number;
|
|
|
|
+ item.Number = 0;
|
|
|
|
+
|
|
|
|
+ var insertId = _sqlSugar.Insertable(item).ExecuteReturnIdentity();
|
|
|
|
+ if (insertId < 1)
|
|
|
|
+ {
|
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
|
+ return Ok(JsonView(false));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var linkUser = new Crm_ClientDataAndUser() {
|
|
|
|
+ usersId = userId,
|
|
|
|
+ NewClientDataId = insertId,
|
|
|
|
+ CreateUserId = 4
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var insertSub = _sqlSugar.Insertable(linkUser).ExecuteReturnIdentity();
|
|
|
|
+ if (insertSub < 1)
|
|
|
|
+ {
|
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
|
+ return Ok(JsonView(false));
|
|
|
|
+ }
|
|
|
|
+ total++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
|
+ return Ok(JsonView(true,$"操作成功!成功条数:{total}"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (Exception)
|
|
|
|
+ {
|
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
|
+ return Ok(JsonView(false));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return Ok(JsonView(false));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 客户数据加密
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [HttpGet]
|
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
|
+ public async Task<IActionResult> DynamicReadExcel1()
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ // 动态存储列名
|
|
|
|
+ var clients = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && x.Id > 6789).ToListAsync();
|
|
|
|
+
|
|
|
|
+ if (clients.Any())
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in clients)
|
|
|
|
+ {
|
|
|
|
+ item.Weight = AesEncryptionHelper.Encrypt("391");
|
|
|
|
+ //Encrypted
|
|
|
|
+ //EncryptionProcessor.EncryptProperties(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //加密后更改
|
|
|
|
+ var update = _sqlSugar.Updateable(clients).UpdateColumns(it => new {
|
|
|
|
+ //it.Client,
|
|
|
|
+ it.Weight,
|
|
|
|
+ //it.Phone,
|
|
|
|
+ //it.Address,
|
|
|
|
+ // it.Location,
|
|
|
|
+ }).ExecuteCommand();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (update > 0)
|
|
|
|
+ {
|
|
|
|
+ return Ok(JsonView(true,$"数据加密成功!加密条数:{update}"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(JsonView(false));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|