|
@@ -5,6 +5,7 @@ using OASystem.Domain.AesEncryption;
|
|
|
using OASystem.Domain.Attributes;
|
|
using OASystem.Domain.Attributes;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
using OASystem.Domain.Dtos.CRM;
|
|
|
using OASystem.Domain.Entities.Customer;
|
|
using OASystem.Domain.Entities.Customer;
|
|
|
|
|
+using OASystem.Domain.ViewModels.CRM;
|
|
|
using OASystem.Infrastructure.Repositories.CRM;
|
|
using OASystem.Infrastructure.Repositories.CRM;
|
|
|
using OASystem.RedisRepository;
|
|
using OASystem.RedisRepository;
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
@@ -1720,6 +1721,141 @@ namespace OASystem.API.Controllers
|
|
|
return count > 0 ? Ok(JsonView(true, "分配成功!", count)) : Ok(JsonView(false, "分配失败!"));
|
|
return count > 0 ? Ok(JsonView(true, "分配成功!", count)) : Ok(JsonView(false, "分配失败!"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 根据提供的数据id导出对应的excel
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="ids">数据id</param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ [HttpPost]
|
|
|
|
|
+ public async Task<IActionResult> ExportExcelByIds(List<int> ids)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ids == null || ids.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Ok(JsonView(false, "请提供要导出的客户数据ID"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询客户数据
|
|
|
|
|
+ var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
|
|
|
|
|
+ .Where(x => ids.Contains(x.Id) && x.IsDel == 0)
|
|
|
|
|
+ .OrderByDescending(x => x.CreateTime)
|
|
|
|
|
+ .ToListAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (clientDatas == null || clientDatas.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Ok(JsonView(false, "未找到要导出的客户数据"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var newClientDataView = new List<NewClientDataExcelDownloadView>();
|
|
|
|
|
+ foreach (var client in clientDatas)
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = new NewClientDataExcelDownloadView
|
|
|
|
|
+ {
|
|
|
|
|
+ Id = client.Id,
|
|
|
|
|
+ Number = client.Number,
|
|
|
|
|
+ Lvlid = client.Lvlid,
|
|
|
|
|
+ Client = client.Client,
|
|
|
|
|
+ Weight = client.Weight,
|
|
|
|
|
+ ClientShort = client.ClientShort,
|
|
|
|
|
+ Contact = client.Contact,
|
|
|
|
|
+ Gender = client.Gender,
|
|
|
|
|
+ Passport = client.Passport,
|
|
|
|
|
+ PassportDate = client.PassportDate,
|
|
|
|
|
+ Job = client.Job,
|
|
|
|
|
+ Telephone = client.Telephone,
|
|
|
|
|
+ Phone = client.Phone,
|
|
|
|
|
+ Email = client.Email,
|
|
|
|
|
+ Location = client.Location,
|
|
|
|
|
+ Address = client.Address,
|
|
|
|
|
+ Birthday = client.Birthday,
|
|
|
|
|
+ OtherInfo = client.OtherInfo,
|
|
|
|
|
+ Wechat = client.Wechat,
|
|
|
|
|
+ Category = client.Category,
|
|
|
|
|
+ PreDele = client.PreDele,
|
|
|
|
|
+ FinlishedDele = client.FinlishedDele,
|
|
|
|
|
+ LastUpdateUserId = client.LastUpdateUserId,
|
|
|
|
|
+ LastUpdateTime = client.LastUpdateTime,
|
|
|
|
|
+ CreateTime = client.CreateTime,
|
|
|
|
|
+ CreateUserId = client.CreateUserId,
|
|
|
|
|
+ IsDel = client.IsDel
|
|
|
|
|
+ };
|
|
|
|
|
+ newClientDataView.Add(view);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询关联数据
|
|
|
|
|
+ var userDatas = await _sqlSugar.Queryable<Sys_Users>().ToListAsync();
|
|
|
|
|
+ var setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
|
|
+ var clientIds = clientDatas.Select(x => x.Id).ToList();
|
|
|
|
|
+
|
|
|
|
|
+ List<AscribedUser> ascribedUser = new List<AscribedUser>();
|
|
|
|
|
+ List<AscribedDepartment> ascribedDepartment = new List<AscribedDepartment>();
|
|
|
|
|
+
|
|
|
|
|
+ if (clientIds.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ascribedUser = await _sqlSugar.SqlQueryable<AscribedUser>(
|
|
|
|
|
+ $"select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id AND u1.ISDEL = 0 AND u1.NewClientDataId IN ({string.Join(",", clientIds)})")
|
|
|
|
|
+ .ToListAsync();
|
|
|
|
|
+
|
|
|
|
|
+ ascribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(
|
|
|
|
|
+ $"select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id AND d1.ISDEL = 0 AND d1.NewClientDataId IN ({string.Join(",", clientIds)})")
|
|
|
|
|
+ .ToListAsync();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 填充额外字段
|
|
|
|
|
+ int index = 1;
|
|
|
|
|
+ foreach (var item in newClientDataView)
|
|
|
|
|
+ {
|
|
|
|
|
+ EncryptionProcessor.DecryptProperties(item); // 解密
|
|
|
|
|
+
|
|
|
|
|
+ item.RowNumber = index;
|
|
|
|
|
+ item.CreateUserName = userDatas.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
|
|
|
|
|
+ item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
|
|
|
|
|
+ item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
|
|
|
|
|
+
|
|
|
|
|
+ var currAscribedUser = ascribedUser.Where(x => x.NewClientDataId == item.Id).ToList();
|
|
|
|
|
+ if (currAscribedUser.Any())
|
|
|
|
|
+ {
|
|
|
|
|
+ item.AscribedUserLable = string.Join("、", currAscribedUser.Select(x => x.CnName).ToList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var currAscribedDepartment = ascribedDepartment.Where(x => x.NewClientDataId == item.Id).ToList();
|
|
|
|
|
+ if (currAscribedDepartment.Any())
|
|
|
|
|
+ {
|
|
|
|
|
+ item.AscribedDepartmentLable = string.Join("、", currAscribedDepartment.Select(x => x.Name).ToList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 使用模板生成Excel
|
|
|
|
|
+ string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料导出模板.xlsx";
|
|
|
|
|
+ var designer = new WorkbookDesigner();
|
|
|
|
|
+ designer.Workbook = new Workbook(tempPath);
|
|
|
|
|
+ designer.SetDataSource("NCDDT", newClientDataView);
|
|
|
|
|
+ designer.Process();
|
|
|
|
|
+
|
|
|
|
|
+ // 文件名
|
|
|
|
|
+ string fileName = $"公司客户资料(按ID导出){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
|
|
|
|
|
+
|
|
|
|
|
+ // 确保目录存在
|
|
|
|
|
+ string savePath = AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/";
|
|
|
|
|
+ if (!Directory.Exists(savePath))
|
|
|
|
|
+ {
|
|
|
|
|
+ Directory.CreateDirectory(savePath);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ designer.Workbook.Save(savePath + fileName);
|
|
|
|
|
+ string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
|
|
|
|
|
+
|
|
|
|
|
+ return Ok(JsonView(true, "导出成功", url));
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Ok(JsonView(false, $"导出失败:{ex.Message}"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 获取IP信息
|
|
/// 获取IP信息
|
|
|
/// </summary>
|
|
/// </summary>
|