Browse Source

新客户的添加修改方法

wangh 1 year ago
parent
commit
c17d1519ec

+ 0 - 1
OASystem/OASystem.Api/Controllers/CRMController.cs

@@ -197,7 +197,6 @@ namespace OASystem.API.Controllers
                 return Ok(JsonView(false, "程序错误!"));
                 throw;
             }
-            return Ok(JsonView(false, "程序错误!"));
         }
 
         /// <summary>

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

@@ -1,6 +1,7 @@
 using Microsoft.AspNetCore.Mvc;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Infrastructure.Repositories.CRM;
+using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
 
 namespace OASystem.API.Controllers
 {
@@ -36,5 +37,46 @@ namespace OASystem.API.Controllers
                 throw;
             }
         }
+        /// <summary>
+        /// 客户资料操作(Status:1.新增,2.修改)
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
+        {
+            try
+            {
+                Domain.Result result = await _clientDataRepository.NewClientOp(dto);
+                if (result.Code != 0)
+                {
+                    return Ok(JsonView(false, result.Msg));
+                }
+                return Ok(JsonView(true, result.Msg));
+            }
+            catch (Exception)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+        }
+
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> QueryUserSelect()
+        {
+            try
+            {
+                Result resTable = await _clientDataRepository.QueryUserSelect();
+                return Ok(JsonView(true, resTable.Msg, resTable));
+            }
+            catch (Exception)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+        }
+
     }
 }

+ 4 - 0
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -13,6 +13,7 @@ using OASystem.Domain.ViewModels;
 using OASystem.Domain.ViewModels.Business;
 using OASystem.Domain.ViewModels.Resource;
 using OASystem.Domain.ViewModels.System;
+using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
 
 namespace OASystem.Domain.AutoMappers
 {
@@ -127,6 +128,9 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<VisaCustomerCompany, Crm_VisaCustomerCompany>();
             CreateMap<VisaCustomerSchool,Crm_VisaCustomerSchool>();
             #endregion
+            #region 新客户资料
+            CreateMap<NewClientOpDto, Crm_NewClientData>();
+            #endregion
             #endregion
 
             #region Business

+ 132 - 1
OASystem/OASystem.Domain/Dtos/CRM/NewClientDataQueryDto.cs

@@ -1,8 +1,12 @@
-using System;
+using AutoMapper.Execution;
+using Org.BouncyCastle.Asn1.Ocsp;
+using Org.BouncyCastle.Asn1.X9;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
 
 namespace OASystem.Domain.Dtos.CRM
 {
@@ -47,5 +51,132 @@ namespace OASystem.Domain.Dtos.CRM
         /// 业务分类
         /// </summary>
         public int Business { get; set; }
+
+        public class NewClientOpDto
+        {
+            /// <summary>
+            /// 操作状态
+            /// 1 添加 
+            /// 2 修改 
+            /// </summary>
+            public int Status { get; set; }
+            /// <summary>
+            /// 编号
+            /// </summary>
+            public int Id { get; set; }
+            /// <summary>
+            /// 序号
+            /// </summary>
+            public int Number { get; set; }
+
+            /// <summary>
+            /// 地市州Id
+            /// </summary>
+            public int Lvlid { get; set; }
+
+            /// <summary>
+            /// 客户单位
+            /// </summary>
+            public string Client { get; set; }
+
+            /// <summary>
+            /// 权重
+            /// </summary>
+            public string Weight { get; set; }
+
+            /// <summary>
+            /// 客户单位简写
+            /// </summary>
+            public string Clientshort { get; set; }
+
+            /// <summary>
+            /// 联系人
+            /// </summary>
+            public string Contact { get; set; }
+
+            /// <summary>
+            /// 联系人性别
+            /// </summary>
+            public int Gender { get; set; }
+
+            /// <summary>
+            /// 护照
+            /// </summary>
+            public string Passport { get; set; }
+
+            /// <summary>
+            /// 护照日期
+            /// </summary>
+            public DateTime? PassportDate { get; set; }
+
+            /// <summary>
+            /// 职位
+            /// </summary>
+            public string Job { get; set; }
+
+            /// <summary>
+            /// 联系手机号
+            /// </summary>
+            public string Telephone { get; set; }
+
+            /// <summary>
+            /// 联系座机号
+            /// </summary>
+            public string Phone { get; set; }
+
+            /// <summary>
+            /// 邮件
+            /// </summary>
+            public string Email { get; set; }
+
+            /// <summary>
+            /// 所属区域(所在城市)
+            /// </summary>
+            public string Location { get; set; }
+
+            /// <summary>
+            /// 地址
+            /// </summary>
+            public string Address { get; set; }
+
+            /// <summary>
+            /// 生日
+            /// </summary>
+            public string Birthday { get; set; }
+
+            /// <summary>
+            /// 其他信息
+            /// </summary>
+            public string Otherinfo { get; set; }
+
+            /// <summary>
+            /// 微信
+            /// </summary>
+            public string Wechat { get; set; }
+
+            /// <summary>
+            /// 分类
+            /// </summary>
+            public int Category { get; set; }
+
+            /// <summary>
+            /// 预计出团
+            /// </summary>
+            public int Predele { get; set; }
+
+            /// <summary>
+            /// 已出团
+            /// </summary>
+            public int FinlishedDele { get; set; }
+            /// <summary>
+            /// 创建者Id
+            /// </summary>
+            public int CreateUserId { get; set; }
+            /// <summary>
+            /// 备注
+            /// </summary>
+            public string Remark { get; set; }
+           
+        }
     }
 }

+ 3 - 3
OASystem/OASystem.Domain/Entities/Customer/Crm_NewClientData.cs

@@ -64,7 +64,7 @@ namespace OASystem.Domain.Entities.Customer
         /// 客户单位简写
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
-        public string Clientshort { get => clientshort; set => clientshort = value; }
+        public string ClientShort { get => clientshort; set => clientshort = value; }
 
         /// <summary>
         /// 联系人
@@ -136,7 +136,7 @@ namespace OASystem.Domain.Entities.Customer
         /// 其他信息
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(100)")]
-        public string Otherinfo { get => otherinfo; set => otherinfo = value; }
+        public string OtherInfo { get => otherinfo; set => otherinfo = value; }
 
         /// <summary>
         /// 微信
@@ -154,7 +154,7 @@ namespace OASystem.Domain.Entities.Customer
         /// 预计出团
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
-        public int Predele { get => predele; set => predele = value; }
+        public int PreDele { get => predele; set => predele = value; }
 
         /// <summary>
         /// 已出团

+ 427 - 171
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -1,8 +1,11 @@
-using OASystem.Domain;
+using AutoMapper;
+using AutoMapper.Execution;
+using OASystem.Domain;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Entities.Customer;
 using OASystem.Domain.Entities.Resource;
 using OASystem.Domain.ViewModels.CRM;
+using SqlSugar;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -10,14 +13,18 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Xml.Linq;
+using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
 
 namespace OASystem.Infrastructure.Repositories.CRM
 {
     public class NewClientDataRepository : BaseRepository<Crm_NewClientData, Crm_NewClientData>
     {
-        public NewClientDataRepository(SqlSugarClient sqlSugar) :
+        private readonly IMapper _mapper;
+        public NewClientDataRepository(SqlSugarClient sqlSugar, IMapper mapper) :
          base(sqlSugar)
-        { }
+        {
+            _mapper= mapper;
+        }
 
         /// <summary>
         /// 客户资料初识初始化
@@ -29,200 +36,357 @@ namespace OASystem.Infrastructure.Repositories.CRM
             Result result = new Result() { Code = -2, Msg = "未知错误" };
             try
             {
-                List<int> NewClientDataId1= new List<int>();
-                List<int> NewClientDataId2 = new List<int>();
-                string NewClientDataId = "";
-                if (dto.Userid != 0)
+                if (dto.PortType==1)
                 {
-                    string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId={0}", dto.Userid);
-                    List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
-                    if (ascribedUsers.Count!=0)
+
+                    List<int> NewClientDataId1= new List<int>();
+                    List<int> NewClientDataId2 = new List<int>();
+                    string NewClientDataId = "";
+                    if (dto.Userid != 0)
                     {
-                        foreach (var ascribedUser in ascribedUsers)
+                        string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0})", dto.Userid);
+                        List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
+                        if (ascribedUsers.Count!=0)
                         {
-                            if (ascribedUser.NewClientDataId != 0)
+                            foreach (var ascribedUser in ascribedUsers)
                             {
-                                NewClientDataId1.Add(ascribedUser.NewClientDataId);
+                                if (ascribedUser.NewClientDataId != 0)
+                                {
+                                    NewClientDataId1.Add(ascribedUser.NewClientDataId);
+                                }
                             }
                         }
+                        else
+                        {
+                            result = new Result() { Code = -1, Msg = "暂无数据" };
+                        }
                     }
-                    else
-                    {
-                        result = new Result() { Code = -1, Msg = "暂无数据" };
-                    }
-                }
-                if (dto.Business != 0)
-                {
-                    string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId={0}", dto.Business);
-                    List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
-                    if (AscribedDepartment.Count != 0)
+                    if (dto.Business != 0)
                     {
-                        foreach (var item in AscribedDepartment)
+                        string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0})", dto.Business);
+                        List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
+                        if (AscribedDepartment.Count != 0)
                         {
-                            if (item.NewClientDataId!= 0)
+                            foreach (var item in AscribedDepartment)
                             {
-                                NewClientDataId2.Add(item.NewClientDataId);
+                                if (item.NewClientDataId!= 0)
+                                {
+                                    NewClientDataId2.Add(item.NewClientDataId);
+                                }
                             }
                         }
+                        else
+                        {
+                            result = new Result() { Code = -1, Msg = "暂无数据" };
+                        }
                     }
-                    else
+                    List<int> intStr=new List<int>();
+                    if (NewClientDataId1.Count!=0 && NewClientDataId2.Count != 0)
                     {
-                        result = new Result() { Code = -1, Msg = "暂无数据" };
+                        intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList();
+                    }else if (NewClientDataId1.Count != 0)
+                    {
+                        intStr = NewClientDataId1;
+                    }else if (NewClientDataId2.Count != 0)
+                    {
+                        intStr = NewClientDataId2;
+                    }
+                    foreach (var item in intStr)
+                    {
+                        NewClientDataId += item + ",";
+                    }
+                    if (!string.IsNullOrWhiteSpace(NewClientDataId))
+                    {
+                        NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
+                    }
+                    string sqlWhere = string.Empty;
+                    if (!string.IsNullOrWhiteSpace(dto.Contact))
+                    {
+                        sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact);
+                    }
+                    if (!string.IsNullOrWhiteSpace(dto.Location))
+                    {
+                        sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location);
+                    }
+                    if (!string.IsNullOrWhiteSpace(dto.Client))
+                    {
+                        sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
+                    }
+                    if (!string.IsNullOrWhiteSpace(NewClientDataId))
+                    {
+                        sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId);
+                    }
+                    //if (!string.IsNullOrWhiteSpace(dto.Weight.ToString()))
+                    //{
+                    //    sqlWhere += string.Format(@" And Weight )", dto.Weight);
+                    //}
+                    if (dto.Lvlid!=0)
+                    {
+                        sqlWhere += string.Format(@" And s.Lvlid={0}",dto.Lvlid);
                     }
-                }
-                List<int> intStr=new List<int>();
-                if (NewClientDataId1.Count!=0 && NewClientDataId2.Count != 0)
-                {
-                    intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList();
-                }else if (NewClientDataId1.Count != 0)
-                {
-                    intStr = NewClientDataId1;
-                }else if (NewClientDataId2.Count != 0)
-                {
-                    intStr = NewClientDataId2;
-                }
-                foreach (var item in intStr)
-                {
-                    NewClientDataId += item + ",";
-                }
-                if (!string.IsNullOrWhiteSpace(NewClientDataId))
-                {
-                    NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
-                }
-                string sqlWhere = string.Empty;
-                if (!string.IsNullOrWhiteSpace(dto.Contact))
-                {
-                    sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact);
-                }
-                if (!string.IsNullOrWhiteSpace(dto.Location))
-                {
-                    sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location);
-                }
-                if (!string.IsNullOrWhiteSpace(dto.Client))
-                {
-                    sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
-                }
-                if (!string.IsNullOrWhiteSpace(NewClientDataId))
-                {
-                    sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId);
-                }
-                //if (!string.IsNullOrWhiteSpace(dto.Weight.ToString()))
-                //{
-                //    sqlWhere += string.Format(@" And Weight )", dto.Weight);
-                //}
-                if (dto.Lvlid!=0)
-                {
-                    sqlWhere += string.Format(@" And s.Lvlid={0}",dto.Lvlid);
-                }
 
-                sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
-                if (!string.IsNullOrEmpty(sqlWhere.Trim()))
-                {
-                    Regex r = new Regex("And");
-                    sqlWhere = r.Replace(sqlWhere, "Where", 1);
-                }
-                dto.PageIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
-                dto.PageSize = dto.PageIndex * dto.PageSize;
-                string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER() 
-                                                over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) as co where    
-                                                RowNumber between {1} and {2} ", sqlWhere,dto.PageIndex,dto.PageSize);
-                List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
-                #region 下拉框初始化数据
-                //负责人下拉框
-                List<dynamic> _Users = new List<dynamic>();
-                List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
-                .Where(u => u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛" && u.IsDel == 0).ToList();
-                foreach (Sys_Users user in users)
-                {
-                    var data = new
+                    sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
+                    if (!string.IsNullOrEmpty(sqlWhere.Trim()))
                     {
-                        Id = user.Id,
-                        Name = user.CnName
+                        Regex r = new Regex("And");
+                        sqlWhere = r.Replace(sqlWhere, "Where", 1);
+                    }
+                    dto.PageIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
+                    dto.PageSize = dto.PageIndex * dto.PageSize;
+                    string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER() 
+                                                    over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) as co where    
+                                                    RowNumber between {1} and {2} ", sqlWhere,dto.PageIndex,dto.PageSize);
+                    List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
+                    #region 下拉框初始化数据
+                    //负责人下拉框
+                    List<dynamic> _Users = new List<dynamic>();
+                    List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
+                    .Where(u => u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛" && u.IsDel == 0).ToList();
+                    foreach (Sys_Users user in users)
+                    {
+                        var data = new
+                        {
+                            Id = user.Id,
+                            Name = user.CnName
+                        };
+                        _Users.Add(data);
                     };
-                    _Users.Add(data);
-                };
-                //省域数据
-                List<dynamic> _Province = new List<dynamic>();
-                List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 42 && u.IsDel == 0).ToList();
-                foreach (Sys_SetData item in province)
-                {
-                    var data = new
+                    //省域数据
+                    List<dynamic> _Province = new List<dynamic>();
+                    List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>()
+                    .Where(u => u.STid == 42 && u.IsDel == 0).ToList();
+                    foreach (Sys_SetData item in province)
                     {
-                        Id = item.Id,
-                        Name = item.Name
+                        var data = new
+                        {
+                            Id = item.Id,
+                            Name = item.Name
+                        };
+                        _Province.Add(data);
                     };
-                    _Province.Add(data);
-                };
-                //客户级别数据
-                List<dynamic> _level = new List<dynamic>();
-                List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
-                foreach (Sys_SetData item in level)
-                {
-                    var data = new
+                    //客户级别数据
+                    List<dynamic> _level = new List<dynamic>();
+                    List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
+                    .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
+                    foreach (Sys_SetData item in level)
                     {
-                        Id = item.Id,
-                        Name = item.Name
+                        var data = new
+                        {
+                            Id = item.Id,
+                            Name = item.Name
+                        };
+                        _level.Add(data);
                     };
-                    _level.Add(data);
-                };
-                //客户类别
-                List<dynamic> _CustomerClass = new List<dynamic>();
-                List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
-                foreach (Sys_SetData item in CustomerClass)
-                {
-                    var data = new
+                    //客户类别
+                    List<dynamic> _CustomerClass = new List<dynamic>();
+                    List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
+                    .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                    foreach (Sys_SetData item in CustomerClass)
                     {
-                        Id = item.Id,
-                        Name = item.Name
+                        var data = new
+                        {
+                            Id = item.Id,
+                            Name = item.Name
+                        };
+                        _CustomerClass.Add(data);
                     };
-                    _CustomerClass.Add(data);
-                };
-                //业务分类 
-                List<dynamic> _ServiceClass = new List<dynamic>();
-                List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
-                foreach (Sys_SetData item in province)
-                {
-                    var data = new
+                    //业务分类 
+                    List<dynamic> _ServiceClass = new List<dynamic>();
+                    List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
+                    .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
+                    foreach (Sys_SetData item in province)
                     {
-                        Id = item.Id,
-                        Name = item.Name
+                        var data = new
+                        {
+                            Id = item.Id,
+                            Name = item.Name
+                        };
+                        _ServiceClass.Add(data);
                     };
-                    _ServiceClass.Add(data);
-                };
                
-                #endregion
-                if (NewClientDataView.Count!=0)
+                    #endregion
+                    if (NewClientDataView.Count!=0)
+                    {
+                        foreach (var item in NewClientDataView)
+                        {
+                            List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
+                           ("select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId="+ item .Id+ "").ToListAsync();
+                            item.AscribedUser = AscribedUser;
+
+                            List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
+                          ("select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId="+item.Id+"").ToListAsync();
+                            item.AscribedDepartment = AscribedDepartment;
+                        }
+                        if (dto.PageSize == 0 && dto.PageIndex == 0)
+                        {
+                            var Data = new
+                            {
+                                ClientTableData= NewClientDataView,
+                                Users = _Users,
+                                Province = _Province,
+                                level = _level,
+                                CustomerClass = _CustomerClass,
+                                ServiceClass = _ServiceClass
+                            };
+                            return result = new Result()
+                            {
+                                Code = 0,
+                                Msg = "查询成功",
+                                Data = Data,
+                            };
+                        }
+                        else
+                        {
+                            int count = NewClientDataView[0].countPage;
+                            float totalPage = (float)count / dto.PageSize;//总页数
+                            if (totalPage == 0) totalPage = 1;
+                            else totalPage = (int)Math.Ceiling((double)totalPage);
+
+                            List<NewClientDataView> NewClientView = new List<NewClientDataView>();
+                            for (int i = 0; i < dto.PageSize; i++)
+                            {
+                                var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
+                                if (RowIndex < NewClientDataView.Count)
+                                {
+                                    NewClientView.Add(NewClientDataView[RowIndex]);
+                                }
+                                else
+                                {
+                                    break;
+                                }
+                            }
+                            var Data = new
+                            {
+                                ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientView },
+                                Users = _Users,
+                                Province = _Province,
+                                level = _level,
+                                CustomerClass = _CustomerClass,
+                                ServiceClass = _ServiceClass
+                            };
+                            return result = new Result()
+                            {
+                                Code = 0,
+                                Msg = "查询成功",
+                                Data = Data
+                            };
+                        }
+                    }
+                    else
+                    {
+                        result = new Result() { Code = -1, Msg = "暂无数据!" };
+                    }
+
+                }
+                else if(dto.PortType==2)
                 {
-                    foreach (var item in NewClientDataView)
+                    List<int> NewClientDataId1 = new List<int>();
+                    List<int> NewClientDataId2 = new List<int>();
+                    string NewClientDataId = "";
+                    if (dto.Userid != 0)
+                    {
+                        string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({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 = "暂无数据" };
+                        }
+                    }
+                    if (dto.Business != 0)
+                    {
+                        string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in({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 = "暂无数据" };
+                        }
+                    }
+                    List<int> intStr = new List<int>();
+                    if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
+                    {
+                        intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList();
+                    }
+                    else if (NewClientDataId1.Count != 0)
+                    {
+                        intStr = NewClientDataId1;
+                    }
+                    else if (NewClientDataId2.Count != 0)
                     {
-                        List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
-                       ("select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId="+ item .Id+ "").ToListAsync();
-                        item.AscribedUser = AscribedUser;
+                        intStr = NewClientDataId2;
+                    }
+                    foreach (var item in intStr)
+                    {
+                        NewClientDataId += item + ",";
+                    }
+                    if (!string.IsNullOrWhiteSpace(NewClientDataId))
+                    {
+                        NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
+                    }
+                    string sqlWhere = string.Empty;
+                    if (!string.IsNullOrWhiteSpace(dto.Contact))
+                    {
+                        sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact);
+                    }
+                    if (!string.IsNullOrWhiteSpace(dto.Location))
+                    {
+                        sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location);
+                    }
+                    if (!string.IsNullOrWhiteSpace(dto.Client))
+                    {
+                        sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
+                    }
+                    if (!string.IsNullOrWhiteSpace(NewClientDataId))
+                    {
+                        sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId);
+                    }
+                    //if (!string.IsNullOrWhiteSpace(dto.Weight.ToString()))
+                    //{
+                    //    sqlWhere += string.Format(@" And Weight )", dto.Weight);
+                    //}
+                    if (dto.Lvlid != 0)
+                    {
+                        sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid);
+                    }
 
-                        List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
-                      ("select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId="+item.Id+"").ToListAsync();
-                        item.AscribedDepartment = AscribedDepartment;
+                    sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
+                    if (!string.IsNullOrEmpty(sqlWhere.Trim()))
+                    {
+                        Regex r = new Regex("And");
+                        sqlWhere = r.Replace(sqlWhere, "Where", 1);
                     }
+                    dto.PageIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
+                    dto.PageSize = dto.PageIndex * dto.PageSize;
+                    string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER() 
+                                                    over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) as co where    
+                                                    RowNumber between {1} and {2} ", sqlWhere, dto.PageIndex, dto.PageSize);
+                    List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
                     if (dto.PageSize == 0 && dto.PageIndex == 0)
                     {
-                        var Data = new
-                        {
-                            ClientTableData= NewClientDataView,
-                            Users = _Users,
-                            Province = _Province,
-                            level = _level,
-                            CustomerClass = _CustomerClass,
-                            ServiceClass = _ServiceClass
-                        };
                         return result = new Result()
                         {
                             Code = 0,
                             Msg = "查询成功",
-                            Data = Data,
+                            Data = NewClientDataView,
                         };
                     }
                     else
@@ -245,26 +409,118 @@ namespace OASystem.Infrastructure.Repositories.CRM
                                 break;
                             }
                         }
-                        var Data = new
-                        {
-                            ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientView },
-                            Users = _Users,
-                            Province = _Province,
-                            level = _level,
-                            CustomerClass = _CustomerClass,
-                            ServiceClass = _ServiceClass
-                        };
                         return result = new Result()
                         {
                             Code = 0,
                             Msg = "查询成功",
-                            Data = Data
+                            Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientView },
                         };
                     }
                 }
+            }
+            catch (Exception ex)
+            {
+                result = new Result() { Code = -2, Msg = "未知错误" };
+                throw;
+            }
+            return result;
+        }
+
+        public async Task<Result> QueryUserSelect()
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                //负责人下拉框
+                List<dynamic> _Users = new List<dynamic>();
+                List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
+                .Where(u => u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛" && u.IsDel == 0).ToList();
+                foreach (Sys_Users user in users)
+                {
+                    var data = new
+                    {
+                        Id = user.Id,
+                        Name = user.CnName
+                    };
+                    _Users.Add(data);
+                };
+                if (_Users.Count==0)
+                {
+                    result = new Result() { Code = -1, Msg = "暂无数据" };
+                }
+                result = new Result() { Code = 0, Msg = "查询成功!",Data=_Users };
+            }
+            catch (Exception)
+            {
+                result = new Result() { Code = -2, Msg = "未知错误" };
+                throw;
+            }
+            return result;
+        }
+
+        public async Task<Result> NewClientOp(NewClientOpDto dto)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                if (dto.Status == 1)//添加
+                {
+                    string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' Contact='{1}' And IsDel={2}"
+                                                       , dto.Client,dto.Contact,0);
+                    var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
+                    if (NewClientData != null)
+                    {
+                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+
+                    }
+                    else//不存在,可添加
+                    {
+                        Crm_NewClientData _NewClientData = _mapper.Map<Crm_NewClientData>(dto);
+                        int id = await AddAsyncReturnId(_NewClientData);
+                        if (id == 0)
+                        {
+                            return result = new Result() { Code = -1, Msg = "添加失败!" };
+
+                        }
+                        return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
+                    }
+                }
+                else if (dto.Status == 2)//修改
+                {
+                    bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_NewClientData
+                    {
+                        Number=dto.Number,
+                        Lvlid= dto.Lvlid,
+                        Client= dto.Client,
+                        Weight= dto.Weight,
+                        ClientShort= dto.Clientshort,
+                        Contact= dto.Contact,
+                        Gender= dto.Gender,
+                        Passport= dto.Passport,
+                        PassportDate= dto.PassportDate,
+                        Job= dto.Job,
+                        Telephone= dto.Telephone,
+                        Phone= dto.Phone,
+                        Email= dto.Email,
+                        Location= dto.Location,
+                        Address= dto.Address,
+                        Birthday= dto.Birthday,
+                        OtherInfo= dto.Otherinfo,
+                        Wechat= dto.Wechat,
+                        Category= dto.Category,
+                        PreDele= dto.Predele,
+                        FinlishedDele= dto.FinlishedDele,
+                        Remark= dto.Remark,
+                    });
+                    if (!res)
+                    {
+                        return result = new Result() { Code = -1, Msg = "修改失败!" };
+                    }
+                    return result = new Result() { Code = 0, Msg = "修改成功!" };
+                }
                 else
                 {
-                    result = new Result() { Code = -1, Msg = "暂无数据!" };
+                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
                 }
             }
             catch (Exception)

+ 2 - 2
OASystem/OASystem.Infrastructure/Repositories/CRM/VisaDeleClientRepository.cs

@@ -46,8 +46,8 @@ namespace OASystem.Infrastructure.Repositories.CRM
                                              	    Phone LandlinePhone,Tel,crmCard1.CertNo IDNo,crmCard2.CertNo PassportNo
                                              From Crm_DeleClient cdc
                                              Left Join Crm_CustomerCompany ccc On cdc.crmCompanyId = ccc.Id
-                                             Left Join Crm_CustomerCert crmCard1 On crmCard1.SdId = 773 And  cdc.Id = crmCard1.DcId 
-                                             Left Join Crm_CustomerCert crmCard2 On crmCard2.SdId = 774 And  cdc.Id = crmCard2.DcId  where cdc.IsDel='0' order By cdc.CreateTime desc");
+                                             Left Join Crm_CustomerCert crmCard1 On crmCard1.SdId = 773 And  cdc.Id = crmCard1.DcId  And crmCard1.Isdel=0
+                                             Left Join Crm_CustomerCert crmCard2 On crmCard2.SdId = 774 And  cdc.Id = crmCard2.DcId And  crmCard2.IsDel=0 where cdc.IsDel='0' order By cdc.CreateTime desc");
 
                 var clientList = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(sql).ToListAsync();