|
@@ -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)
|