|
@@ -3106,26 +3106,13 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
|
|
|
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 cellVal2 = worksheet.Cells[row, 1].Value; //单位名称
|
|
|
+ var cellVal3 = worksheet.Cells[row, 2].Value; //出访次数
|
|
|
+
|
|
|
+ int count = !string.IsNullOrEmpty(cellVal3?.ToString()) ? int.Parse(cellVal3?.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, //创建人
|
|
|
+ Number = count,
|
|
|
+ Client = cellVal2?.ToString().Trim(),//单位名称
|
|
|
};
|
|
|
|
|
|
clients.Add(rowData); // 将当前行数据添加到集合中
|
|
@@ -3134,47 +3121,52 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
|
|
|
|
|
|
if (clients.Any())
|
|
|
{
|
|
|
- _sqlSugar.BeginTran();
|
|
|
- try
|
|
|
- {
|
|
|
- int total = 0;
|
|
|
- foreach (var item in clients)
|
|
|
- {
|
|
|
+ var clientArr = clients.Select(x => x.Client).ToList();
|
|
|
+ var clientDatas = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0)
|
|
|
+ .ToList()
|
|
|
+ .Select(x => new { id = x.Id, client = AesEncryptionHelper.Decrypt(x.Client), remark = AesEncryptionHelper.Decrypt(x.Remark) });
|
|
|
|
|
|
- var userId = item.Number;
|
|
|
- item.Number = 0;
|
|
|
+ var clientDatas1 = clientDatas.Where(x => clientArr.Contains(x.client)).ToList();
|
|
|
|
|
|
- var insertId = _sqlSugar.Insertable(item).ExecuteReturnIdentity();
|
|
|
- if (insertId < 1)
|
|
|
- {
|
|
|
- _sqlSugar.RollbackTran();
|
|
|
- return Ok(JsonView(false));
|
|
|
- }
|
|
|
+ var updates = new List<Crm_NewClientData>();
|
|
|
|
|
|
- var linkUser = new Crm_ClientDataAndUser() {
|
|
|
- usersId = userId,
|
|
|
- NewClientDataId = insertId,
|
|
|
- CreateUserId = 4
|
|
|
- };
|
|
|
+ foreach (var item in clientDatas1)
|
|
|
+ {
|
|
|
|
|
|
- var insertSub = _sqlSugar.Insertable(linkUser).ExecuteReturnIdentity();
|
|
|
- if (insertSub < 1)
|
|
|
- {
|
|
|
- _sqlSugar.RollbackTran();
|
|
|
- return Ok(JsonView(false));
|
|
|
- }
|
|
|
- total++;
|
|
|
+ string newRemark = item.remark;
|
|
|
+ var str = clients.FirstOrDefault(x => x.Client.Equals(item.client))?.Number ?? 0;
|
|
|
+ if (str > 0)
|
|
|
+ {
|
|
|
+ newRemark += $"\r\n2025年拟出访次数{str}次";
|
|
|
}
|
|
|
|
|
|
- _sqlSugar.CommitTran();
|
|
|
- return Ok(JsonView(true,$"操作成功!成功条数:{total}"));
|
|
|
+ updates.Add(new Crm_NewClientData() {
|
|
|
+ Id = item.id,
|
|
|
+
|
|
|
+ Remark = AesEncryptionHelper.Encrypt(newRemark)
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
- catch (Exception)
|
|
|
+
|
|
|
+ if (updates.Any())
|
|
|
{
|
|
|
- _sqlSugar.RollbackTran();
|
|
|
- return Ok(JsonView(false));
|
|
|
+ //加密后更改
|
|
|
+ var update = _sqlSugar.Updateable(updates).UpdateColumns(it => new {
|
|
|
+ //it.Client,
|
|
|
+ it.Remark,
|
|
|
+ //it.Phone,
|
|
|
+ //it.Address,
|
|
|
+ // it.Location,
|
|
|
+ }).ExecuteCommand();
|
|
|
+
|
|
|
+
|
|
|
+ if (update > 0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(true, $"数据加密成功!加密条数:{update}"));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
return Ok(JsonView(false));
|
|
|
}
|
|
@@ -3222,6 +3214,28 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
|
|
|
return Ok(JsonView(false));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 数库事务异常测试
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> TransactionExTest()
|
|
|
+ {
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+
|
|
|
+
|
|
|
+ var a1 = new List<dynamic>();
|
|
|
+
|
|
|
+ var a2 = a1[0].ToString();
|
|
|
+
|
|
|
+
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+
|
|
|
+ return Ok(JsonView(false));
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
}
|