|
@@ -1,5 +1,6 @@
|
|
|
using AutoMapper;
|
|
|
using AutoMapper.Execution;
|
|
|
+using MySqlX.XDevAPI.Relational;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
|
using OASystem.Domain.Entities.Customer;
|
|
@@ -23,7 +24,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
public NewClientDataRepository(SqlSugarClient sqlSugar, IMapper mapper) :
|
|
|
base(sqlSugar)
|
|
|
{
|
|
|
- _mapper= mapper;
|
|
|
+ _mapper = mapper;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -36,17 +37,18 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
try
|
|
|
{
|
|
|
- if (dto.PortType==1)
|
|
|
+ if (dto.PortType == 1)
|
|
|
{
|
|
|
|
|
|
- List<int> NewClientDataId1= new List<int>();
|
|
|
+ List<int> NewClientDataId1 = new List<int>();
|
|
|
List<int> NewClientDataId2 = new List<int>();
|
|
|
string NewClientDataId = "";
|
|
|
+ int state = 0;
|
|
|
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)
|
|
|
+ if (ascribedUsers.Count != 0)
|
|
|
{
|
|
|
foreach (var ascribedUser in ascribedUsers)
|
|
|
{
|
|
@@ -60,6 +62,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
result = new Result() { Code = -1, Msg = "暂无数据" };
|
|
|
}
|
|
|
+ state = -1;
|
|
|
}
|
|
|
if (dto.Business != 0)
|
|
|
{
|
|
@@ -69,7 +72,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
foreach (var item in AscribedDepartment)
|
|
|
{
|
|
|
- if (item.NewClientDataId!= 0)
|
|
|
+ if (item.NewClientDataId != 0)
|
|
|
{
|
|
|
NewClientDataId2.Add(item.NewClientDataId);
|
|
|
}
|
|
@@ -79,15 +82,21 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
result = new Result() { Code = -1, Msg = "暂无数据" };
|
|
|
}
|
|
|
+ state = -1;
|
|
|
}
|
|
|
- List<int> intStr=new List<int>();
|
|
|
- if (NewClientDataId1.Count!=0 && NewClientDataId2.Count != 0)
|
|
|
+ List<int> intStr = new List<int>();
|
|
|
+
|
|
|
+
|
|
|
+ if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
|
|
|
{
|
|
|
intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList();
|
|
|
- }else if (NewClientDataId1.Count != 0)
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (NewClientDataId1.Count != 0)
|
|
|
{
|
|
|
intStr = NewClientDataId1;
|
|
|
- }else if (NewClientDataId2.Count != 0)
|
|
|
+ }
|
|
|
+ else if (NewClientDataId2.Count != 0)
|
|
|
{
|
|
|
intStr = NewClientDataId2;
|
|
|
}
|
|
@@ -112,17 +121,18 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
|
|
|
}
|
|
|
- if (!string.IsNullOrWhiteSpace(NewClientDataId))
|
|
|
+ if (state == -1)
|
|
|
{
|
|
|
+ if (string.IsNullOrWhiteSpace(NewClientDataId))
|
|
|
+ {
|
|
|
+ NewClientDataId = "0";
|
|
|
+ }
|
|
|
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)
|
|
|
+
|
|
|
+ if (dto.Lvlid != 0)
|
|
|
{
|
|
|
- sqlWhere += string.Format(@" And s.Lvlid={0}",dto.Lvlid);
|
|
|
+ sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid);
|
|
|
}
|
|
|
|
|
|
sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
|
|
@@ -140,9 +150,9 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
foreach (var item in NewClientDataView)
|
|
|
{
|
|
|
Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category);
|
|
|
- item.CategoryStr = CategoryStr.Name;
|
|
|
+ item.CategoryStr = CategoryStr != null ? CategoryStr.Name : null;
|
|
|
Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid);
|
|
|
- item.LvlidStr = lvlStr.Name;
|
|
|
+ item.LvlidStr = lvlStr != null ? lvlStr.Name : null;
|
|
|
}
|
|
|
#region 下拉框初始化数据
|
|
|
//负责人下拉框
|
|
@@ -210,42 +220,46 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
};
|
|
|
_ServiceClass.Add(data);
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
#endregion
|
|
|
- if (NewClientDataView.Count!=0)
|
|
|
+ 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();
|
|
|
+ ("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();
|
|
|
+ ("select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + item.Id + "").ToListAsync();
|
|
|
item.AscribedDepartment = AscribedDepartment;
|
|
|
}
|
|
|
-
|
|
|
- int count = NewClientDataView[0].countPage;
|
|
|
- float totalPage = (float)count / dto.PageSize;//总页数
|
|
|
- if (totalPage == 0) totalPage = 1;
|
|
|
- else totalPage = (int)Math.Ceiling((double)totalPage);
|
|
|
|
|
|
- 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
|
|
|
- };
|
|
|
- return result = new Result()
|
|
|
- {
|
|
|
- Code = 0,
|
|
|
- Msg = "查询成功",
|
|
|
- Data = Data
|
|
|
- };
|
|
|
-
|
|
|
+ int count = NewClientDataView[0].countPage;
|
|
|
+ float totalPage = (float)count / dto.PageSize;//总页数
|
|
|
+ if (totalPage == 0) totalPage = 1;
|
|
|
+ else totalPage = (int)Math.Ceiling((double)totalPage);
|
|
|
+
|
|
|
+
|
|
|
+ var groupNumber = await QueryNumberGroups();
|
|
|
+
|
|
|
+ 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
|
|
|
{
|
|
@@ -253,14 +267,14 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- else if(dto.PortType==2)
|
|
|
+ else if (dto.PortType == 2)
|
|
|
{
|
|
|
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);
|
|
|
+ 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}) and u1.isdel = 0 and u2.isdel = 0", dto.Userid);
|
|
|
List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
|
|
|
if (ascribedUsers.Count != 0)
|
|
|
{
|
|
@@ -279,7 +293,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
}
|
|
|
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);
|
|
|
+ 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}) and d1.isdel = 0 and d2.isdel = 0", dto.Business);
|
|
|
List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
|
|
|
if (AscribedDepartment.Count != 0)
|
|
|
{
|
|
@@ -334,10 +348,6 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
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);
|
|
@@ -349,12 +359,17 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
Regex r = new Regex("And");
|
|
|
sqlWhere = r.Replace(sqlWhere, "Where", 1);
|
|
|
}
|
|
|
- int pIndex= dto.PageIndex * dto.PageSize - dto.PageSize + 1;
|
|
|
+
|
|
|
+ #region 分页查询
|
|
|
+ int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
|
|
|
int pSize = 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, pIndex, pSize);
|
|
|
List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
foreach (var item in NewClientDataView)
|
|
|
{
|
|
|
Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category);
|
|
@@ -377,7 +392,6 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
- throw;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -400,11 +414,11 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
};
|
|
|
_Users.Add(data);
|
|
|
};
|
|
|
- if (_Users.Count==0)
|
|
|
+ if (_Users.Count == 0)
|
|
|
{
|
|
|
result = new Result() { Code = -1, Msg = "暂无数据" };
|
|
|
}
|
|
|
- result = new Result() { Code = 0, Msg = "查询成功!",Data=_Users };
|
|
|
+ result = new Result() { Code = 0, Msg = "查询成功!", Data = _Users };
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
@@ -422,7 +436,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
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);
|
|
|
+ , dto.Client, dto.Contact, 0);
|
|
|
var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
|
|
|
if (NewClientData != null)
|
|
|
{
|
|
@@ -445,28 +459,28 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
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,
|
|
|
+ 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)
|
|
|
{
|
|
@@ -486,5 +500,25 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<Result> QueryNumberGroups()
|
|
|
+ {
|
|
|
+ Result result = new Result();
|
|
|
+ //preDeleAll 预计总量
|
|
|
+ //finlishedDeleAll 已出总量
|
|
|
+
|
|
|
+ DataTable preDeleAndfinlishedDeleAll = await GetDataTableAsync("select SUM(PreDele) as PreDeleAll ,SUM(FinlishedDele) as FinlishedDeleAll from Crm_NewClientData");
|
|
|
+ var preDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["PreDeleAll"].ToString();
|
|
|
+ var finlishedDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["finlishedDeleAll"].ToString();
|
|
|
+ result.Code = 0;
|
|
|
+ result.Msg = "成功!";
|
|
|
+ result.Data = new
|
|
|
+ {
|
|
|
+ preDeleAll,
|
|
|
+ finlishedDeleAll
|
|
|
+ };
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
}
|