Bläddra i källkod

公司客户资料 --> list、info 加密/解密

LEIYI 3 månader sedan
förälder
incheckning
d48bae7209

+ 32 - 0
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -1,6 +1,9 @@
 using OASystem.API.OAMethodLib;
+using OASystem.Domain.AesEncryption;
 using OASystem.Domain.Dtos.CRM;
+using OASystem.Domain.Entities.Customer;
 using OASystem.Infrastructure.Repositories.CRM;
+using System.Diagnostics;
 
 namespace OASystem.API.Controllers
 {
@@ -19,6 +22,35 @@ namespace OASystem.API.Controllers
             this._clientDataRepository = clientDataRepository;
         }
 
+
+        /// <summary>
+        /// 客户资料数据
+        /// 批量加密
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> MarketCustomerBatchEncryption()
+        {
+            JsonView jw = new JsonView();
+         
+            
+            var infos = await _clientDataRepository._sqlSugar.Queryable< Crm_NewClientData >().ToListAsync();
+
+            Stopwatch stopwatch = Stopwatch.StartNew();
+
+            foreach (var info in infos) EncryptionProcessor.EncryptProperties(info);
+
+            var updCount = await _clientDataRepository._sqlSugar.Updateable(infos).ExecuteCommandAsync();
+            stopwatch.Stop();
+
+            jw.Count = 200;
+            jw.Msg = $"AES加密耗时: {stopwatch.ElapsedMilliseconds} 毫秒";
+            jw.Count = updCount;
+
+            return Ok(jw);
+        }
+
         /// <summary>
         /// 客户资料数据
         /// 基础数据

+ 28 - 13
OASystem/OASystem.Domain/Entities/Customer/Crm_NewClientData.cs

@@ -1,4 +1,5 @@
-using Org.BouncyCastle.Asn1.Ocsp;
+using OASystem.Domain.Attributes;
+using Org.BouncyCastle.Asn1.Ocsp;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -51,25 +52,29 @@ namespace OASystem.Domain.Entities.Customer
         /// <summary>
         /// 客户单位
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Client { get => client; set => client = value; }
 
         /// <summary>
         /// 权重
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(20)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(100)")]
         public string Weight { get => weight; set => weight = value; }
 
         /// <summary>
         /// 客户单位简写
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string ClientShort { get => clientshort; set => clientshort = value; }
 
         /// <summary>
         /// 联系人
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Contact { get => contact; set => contact = value; }
 
         /// <summary>
@@ -81,7 +86,8 @@ namespace OASystem.Domain.Entities.Customer
         /// <summary>
         /// 护照
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Passport { get => passport; set => passport = value; }
 
         /// <summary>
@@ -93,55 +99,64 @@ namespace OASystem.Domain.Entities.Customer
         /// <summary>
         /// 职位
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Job { get => job; set => job = value; }
 
         /// <summary>
         /// 联系手机号
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Telephone { get => telephone; set => telephone = value; }
 
         /// <summary>
         /// 联系座机号
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Phone { get => phone; set => phone = value; }
 
         /// <summary>
         /// 邮件
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Email { get => email; set => email = value; }
 
         /// <summary>
         /// 所属区域(所在城市)
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(MAX)")]
         public string Location { get => location; set => location = value; }
 
         /// <summary>
         /// 地址
         /// </summary>
+        [Encrypted]
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(80)")]
         public string Address { get => address; set => address = value; }
 
         /// <summary>
         /// 生日
         /// </summary>
+        [Encrypted]
         [SugarColumn(IsNullable = true, ColumnDataType = "string")]
         public string Birthday { get => birthday; set => birthday = value; }
 
         /// <summary>
         /// 其他信息
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(100)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(MAX)")]
         public string OtherInfo { get => otherinfo; set => otherinfo = value; }
 
         /// <summary>
         /// 微信
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
+        [Encrypted]
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(200)")]
         public string Wechat { get => wechat; set => wechat = value; }
 
         /// <summary>

+ 336 - 0
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -6,6 +6,7 @@ using NPOI.OpenXmlFormats.Dml.Diagram;
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.UserModel;
 using OASystem.Domain;
+using OASystem.Domain.AesEncryption;
 using OASystem.Domain.Dtos;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Entities.Customer;
@@ -19,6 +20,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.Design;
 using System.Linq;
+using System.Runtime.Intrinsics.Arm;
 using System.Text;
 using System.Threading.Tasks;
 using System.Xml.Linq;
@@ -197,6 +199,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
             return result;
         }
 
+
         /// <summary>
         /// 客户资料初识初始化
         /// </summary>
@@ -206,6 +209,338 @@ namespace OASystem.Infrastructure.Repositories.CRM
         {
             Result result = new Result() { Code = -2, Msg = "未知错误" };
 
+            try
+            {
+                #region 交集
+                List<int> NewClientDataId1 = new List<int>();
+                List<int> NewClientDataId2 = new List<int>();
+                string NewClientDataId = "";
+                int state = 0;
+
+                #region 负责人
+                if (dto.OperationUserId != 21)
+                {
+                    if (string.IsNullOrWhiteSpace(dto.Userid))
+                    {
+                        dto.Userid = dto.OperationUserId.ToString();
+                    }
+                }
+
+                if (!string.IsNullOrWhiteSpace(dto.Userid))
+                {
+                    string sql = string.Format(@"select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0})  and u1.IsDel = 0", dto.Userid);
+                    List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
+                    if (ascribedUsers.Count != 0)
+                    {
+                        foreach (var ascribedUser in ascribedUsers)
+                        {
+                            if (ascribedUser.NewClientDataId != 0)
+                            {
+                                NewClientDataId1.Add(ascribedUser.NewClientDataId);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        result = new Result() { Code = -1, Msg = "暂无数据" };
+                    }
+                    state = -1;
+                }
+                #endregion
+
+                #region 业务归属
+                if (!string.IsNullOrWhiteSpace(dto.Business))
+                {
+                    string sql = string.Format(@"select   d2.Id,d2.Name,d1.NewClientDataId   from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0}) and d1.isdel = 0", dto.Business);
+                    List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
+                    if (AscribedDepartment.Count != 0)
+                    {
+                        foreach (var item in AscribedDepartment)
+                        {
+                            if (item.NewClientDataId != 0)
+                            {
+                                NewClientDataId2.Add(item.NewClientDataId);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        result = new Result() { Code = -1, Msg = "暂无数据" };
+                    }
+                    state = -1;
+                }
+                #endregion
+
+                List<int> intList = new List<int>();
+
+                if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
+                {
+                    intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
+
+                }
+                else if (NewClientDataId1.Count != 0)
+                {
+                    intList = NewClientDataId1;
+                }
+                else if (NewClientDataId2.Count != 0)
+                {
+                    intList = NewClientDataId2;
+                }
+                #endregion
+
+                foreach (var item in intList)
+                {
+                    NewClientDataId += item + ",";
+                }
+                if (!string.IsNullOrWhiteSpace(NewClientDataId))
+                {
+                    NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
+                }
+
+                var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToListAsync();
+
+                string contact = dto.Contact,location = dto.Location,clientDto = dto.Client;
+                //aes 解密
+                foreach (var client in clientDatas)
+                {
+                    if (!string.IsNullOrEmpty(contact)) AesEncryptionHelper.Decrypt(client.Contact);
+                    if (!string.IsNullOrEmpty(location)) AesEncryptionHelper.Decrypt(client.Location);
+                    if (!string.IsNullOrEmpty(clientDto)) AesEncryptionHelper.Decrypt(client.Client);
+                }
+                
+                string sqlWhere = string.Empty;
+
+                if (dto.PortType == 1)
+                {
+                    clientDatas = clientDatas
+                        .WhereIF(!string.IsNullOrEmpty(contact), x => x.Contact.Contains(contact))    //联系人条件
+                        .WhereIF(!string.IsNullOrEmpty(location), x => x.Location.Contains(location)) //地区条件
+                        .WhereIF(!string.IsNullOrEmpty(clientDto), x => x.Client.Contains(clientDto)) //单位条件
+                        .ToList();
+
+                }
+                else if (dto.PortType == 2 || dto.PortType == 3)
+                {
+                    clientDatas = clientDatas.Where(x => x.Contact.Contains(clientDto) || x.Location.Contains(clientDto) || x.Client.Contains(clientDto)).ToList();
+                }
+
+                if (state == -1)
+                {
+                    //intList
+
+                    clientDatas = clientDatas.WhereIF(intList.Count > 0, x => intList.Contains(x.Id)).ToList();
+                }
+
+                #region 地市州条件
+                if (dto.Lvlid != 0)
+                {
+                    clientDatas = clientDatas.Where(x => x.Lvlid == dto.Lvlid).ToList();
+                }
+                #endregion
+
+                #region 省域条件
+                if (dto.Range != 0)
+                {
+                    string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0  ";
+                    switch (dto.Range)
+                    {
+                        case 419:
+                            setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
+                            break;
+                        case 421:
+                            setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
+                            break;
+                        case 420:
+                            setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
+                            break;
+                        case 423:
+                            setDataSql += " and (Name like '%重庆%')";
+                            break;
+                        case 422:
+                            setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
+                            break;
+                        case 578:
+                            setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
+                            break;
+                        case 605:
+                            setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
+                            break;
+                        case 606:
+                            setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
+                            break;
+                        case 625:
+                            setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
+                            break;
+                        case 634:
+                            setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
+                            break;
+                    }
+
+                    var RangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
+
+                    clientDatas = clientDatas.WhereIF(RangeSetDataList.Count > 0, x => RangeSetDataList.Contains(x.Lvlid)).ToList();
+
+                }
+                #endregion
+
+                #region 客户类别
+                clientDatas = clientDatas.WhereIF(dto.Category > 0, x => x.Category == dto.Category).ToList();
+                #endregion
+
+                int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
+                int pSize = dto.PageIndex * dto.PageSize;
+                int skip = (dto.PageIndex - 1) * dto.PageSize;
+
+                var pageData = clientDatas.OrderByDescending(x => x.CreateTime).Skip(skip).Take(dto.PageSize).ToList();
+
+                var NewClientDataView = _mapper.Map<List<NewClientDataView>>(pageData);
+                var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
+                int index = 1;
+                foreach (var item in NewClientDataView)
+                {
+                    item.RowNumber = index;
+                    item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
+                    item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
+                    item.Weight = AesEncryptionHelper.Decrypt(item.Weight);
+                    item.Client = AesEncryptionHelper.Decrypt(item.Client);
+                    item.Contact = AesEncryptionHelper.Decrypt(item.Contact);
+                    item.Job = AesEncryptionHelper.Decrypt(item.Job);
+                    item.Telephone = AesEncryptionHelper.Decrypt(item.Telephone);
+                    item.Phone = AesEncryptionHelper.Decrypt(item.Phone);
+                    item.Location = AesEncryptionHelper.Decrypt(item.Location);
+                    item.Remark = AesEncryptionHelper.Decrypt(item.Remark);
+
+                    index++;
+                }
+
+                #region 下拉框初始化数据
+                //负责人下拉框
+                var _Users = GetNewExistClient(dto.OperationUserId).Select(x => new { x.Id, Name = x.CnName }).ToList();
+
+                //省域数据
+                var _Province = setDatas.Where(u => u.STid == 42).Select(x => new { x.Id, x.Name }).ToList();
+
+                //客户级别数据
+                var _level = setDatas.Where(u => u.STid == 33).Select(x => new { x.Id, x.Name }).ToList();
+
+                //客户类别
+                var _CustomerClass = setDatas.Where(u => u.STid == 37).Select(x => new { x.Id, x.Name }).ToList();
+
+                //业务分类 
+                var _ServiceClass = setDatas.Where(u => u.STid == 36).Select(x => new { x.Id, x.Name }).ToList();
+
+                #endregion
+                var groupNumber = await QueryNumberGroups();
+
+                if (NewClientDataView.Count > 0)
+                {
+                    int count = clientDatas.Count;
+                    float totalPage = (float)count / dto.PageSize;//总页数
+                    if (totalPage == 0) totalPage = 1;
+                    else totalPage = (int)Math.Ceiling((double)totalPage);
+
+                    if (dto.PortType == 1)
+                    {
+                        foreach (var item in NewClientDataView)
+                        {
+                            List<AscribedUser> 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 NewClientDataId=" + item.Id + "   AND u1.ISDEL = 0").ToListAsync();
+                            item.AscribedUser = AscribedUser;
+
+                            List<AscribedDepartment> 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 NewClientDataId=" + item.Id + "  AND d1.ISDEL = 0").ToListAsync();
+                            item.AscribedDepartment = AscribedDepartment;
+                        }
+
+                        var Data = new
+                        {
+                            ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
+                            Users = _Users,
+                            Province = _Province,
+                            level = _level,
+                            CustomerClass = _CustomerClass,
+                            ServiceClass = _ServiceClass,
+                            groupNumber = groupNumber.Data,
+                        };
+                        return result = new Result()
+                        {
+                            Code = 0,
+                            Msg = "查询成功",
+                            Data = Data
+                        };
+
+                    }
+                    else if (dto.PortType == 2 || dto.PortType == 3)
+                    {
+
+                        List<NewClientDataAndroidIOSView> newClientDataIOSViews = new List<NewClientDataAndroidIOSView>();
+                        foreach (var item in NewClientDataView)
+                        {
+
+                            newClientDataIOSViews.Add(new NewClientDataAndroidIOSView()
+                            {
+                                RowNumber = item.RowNumber,
+                                Id = item.Id,
+                                Client = item.Client,
+                                Contact = item.Contact,
+                                Job = item.Job,
+                                Telephone = item.Telephone,
+                                Location = item.Location,
+                            });
+                        }
+
+                        result = new Result()
+                        {
+                            Code = 0,
+                            Msg = "查询成功",
+                            Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = newClientDataIOSViews },
+                        };
+                    }
+
+                }
+                else
+                {
+                    if (dto.PortType == 2 || dto.PortType == 3)
+                    {
+                        var Data = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView };
+                        result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
+                    }
+                    else
+                    {
+                        var Data = new
+                        {
+
+                            ClientTableData = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
+                            Users = _Users,
+                            Province = _Province,
+                            level = _level,
+                            CustomerClass = _CustomerClass,
+                            ServiceClass = _ServiceClass,
+                            groupNumber = groupNumber.Data,
+                        };
+                        result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
+                    }
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+                result = new Result() { Code = -2, Msg = "未知错误" };
+            }
+            return result;
+        }
+
+
+        /// <summary>
+        /// 客户资料初识初始化
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<Result> QueryNewClientData1(NewClientDataQueryDto dto)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+
             try
             {
                 #region 交集
@@ -806,6 +1141,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
             NewClientDataView MapQueryData = null;
             if (QueryData != null)
             {
+                EncryptionProcessor.DecryptProperties(QueryData);
                 MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
                 MapQueryData.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 NewClientDataId=" + dto.Id + " and u1.isdel = 0").ToListAsync();