|
@@ -1,5 +1,6 @@
|
|
|
|
|
|
using AutoMapper;
|
|
|
+using Newtonsoft.Json;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
@@ -12,6 +13,7 @@ using OASystem.Domain.ViewModels.Groups;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.Intrinsics.X86;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
@@ -26,7 +28,8 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
public VisaDeleClientRepository(SqlSugarClient sqlSugar,IMapper mapper) :
|
|
|
base(sqlSugar)
|
|
|
{
|
|
|
- _mapper = mapper;
|
|
|
+ this._mapper = mapper;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -44,7 +47,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
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 ");
|
|
|
+ Left Join Crm_CustomerCert crmCard2 On crmCard2.SdId = 774 And cdc.Id = crmCard2.DcId where cdc.IsDel='0' order By cdc.CreateTime desc");
|
|
|
|
|
|
var clientList = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(sql).ToListAsync();
|
|
|
|
|
@@ -151,6 +154,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
try
|
|
|
{
|
|
|
+ int deleId = 0;
|
|
|
if (dto.Status==1)//添加
|
|
|
{
|
|
|
string selectSql = string.Format(@"select * from Crm_DeleClient where LastName+FirstName='{0}' and Phone='{1}' and IsDel='{2}'"
|
|
@@ -158,7 +162,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
var DeleClient = await _sqlSugar.SqlQueryable<Crm_DeleClient>(selectSql).FirstAsync();//查询是否存在
|
|
|
if (DeleClient != null)
|
|
|
{
|
|
|
- return result = new Result() { Code = -1, Msg = "该客户已存在,请勿重复添加!" };
|
|
|
+ result = new Result() { Code = -1, Msg = "该客户已存在,请勿重复添加!" };
|
|
|
|
|
|
}
|
|
|
else//不存在,可添加
|
|
@@ -167,16 +171,17 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
int id = await AddAsyncReturnId(_CountryFeeCost);
|
|
|
if (id == 0)
|
|
|
{
|
|
|
- return result = new Result() { Code = -1, Msg = "添加失败!" };
|
|
|
+ result = new Result() { Code = -1, Msg = "添加失败!" };
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
|
|
|
- //进行其他表炒作
|
|
|
+ result = new Result() { Code = 0, Msg = "添加成功!" };
|
|
|
+ deleId = id;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
else if (dto.Status == 2)//修改
|
|
|
{
|
|
|
+ deleId=dto.DeleClient.Id;
|
|
|
bool res = await UpdateAsync(a => a.Id == dto.DeleClient.Id, a => new Crm_DeleClient
|
|
|
{
|
|
|
LastName = dto.DeleClient.LastName,
|
|
@@ -272,25 +277,207 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
});
|
|
|
if (!res)
|
|
|
{
|
|
|
- return result = new Result() { Code = -1, Msg = "修改失败!" };
|
|
|
+ result = new Result() { Code = -1, Msg = "修改失败!" };
|
|
|
}
|
|
|
- foreach (var item in dto.CustomerFamily)
|
|
|
+ result = new Result() { Code = 0, Msg = "修改成功!" };
|
|
|
+
|
|
|
+ }
|
|
|
+ //进行其他表
|
|
|
+ if (result.Code == 0)
|
|
|
+ {//家庭成员信息
|
|
|
+ foreach (CustomerFamily item in dto.CustomerFamily)
|
|
|
{
|
|
|
- if (item.Id!=0)//修改
|
|
|
+ Crm_VisaCustomerFamily Crm_VisaCustomerFamily = _mapper.Map<Crm_VisaCustomerFamily>(item);
|
|
|
+ Crm_VisaCustomerFamily.DcId = deleId;
|
|
|
+ if (item.Id != 0)//修改
|
|
|
+ {
|
|
|
+ int res = await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.Id == Crm_VisaCustomerFamily.Id).SetColumns(a => new Crm_VisaCustomerFamily
|
|
|
+ {
|
|
|
+ Appellation = Crm_VisaCustomerFamily.Appellation,
|
|
|
+ Name = Crm_VisaCustomerFamily.Name,
|
|
|
+ BirthDay = Crm_VisaCustomerFamily.BirthDay,
|
|
|
+ BirthPlace = Crm_VisaCustomerFamily.BirthPlace,
|
|
|
+ Politics = Crm_VisaCustomerFamily.Politics,
|
|
|
+ Client = Crm_VisaCustomerFamily.Client,
|
|
|
+ Address = Crm_VisaCustomerFamily.Address,
|
|
|
+ IsEu = Crm_VisaCustomerFamily.IsEu,
|
|
|
+ NameSnd = Crm_VisaCustomerFamily.NameSnd,
|
|
|
+ BirthDaySnd = Crm_VisaCustomerFamily.BirthDaySnd,
|
|
|
+ Nationality = Crm_VisaCustomerFamily.Nationality,
|
|
|
+ IDCard = Crm_VisaCustomerFamily.IDCard,
|
|
|
+ Reletionship = Crm_VisaCustomerFamily.Reletionship,
|
|
|
+ IsUSA = Crm_VisaCustomerFamily.IsUSA,
|
|
|
+ Remark = Crm_VisaCustomerFamily.Remark,
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ if (res==0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.Id == 0)//添加
|
|
|
{
|
|
|
+ int sss= await _sqlSugar.Insertable(Crm_VisaCustomerFamily).ExecuteReturnIdentityAsync();
|
|
|
+ if (sss == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //证件表信息
|
|
|
+ foreach (CustomerCerts item in dto.CustomerCert)
|
|
|
+ {
|
|
|
+ Crm_CustomerCert CustomerCert = _mapper.Map<Crm_CustomerCert>(item);
|
|
|
+ CustomerCert.DcId = deleId;
|
|
|
+ if (item.Id != 0)//修改
|
|
|
+ {
|
|
|
+ int res = await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.Id == CustomerCert.Id).SetColumns(a => new Crm_CustomerCert
|
|
|
+ {
|
|
|
+ DcId=CustomerCert.DcId,
|
|
|
+ SdId = CustomerCert.DcId,
|
|
|
+ CertNo = CustomerCert.CertNo,
|
|
|
+ Country = CustomerCert.Country,
|
|
|
+ Area = CustomerCert.Area,
|
|
|
+ TargetCountry = CustomerCert.TargetCountry,
|
|
|
+ IssueDt = CustomerCert.IssueDt,
|
|
|
+ ExpiryDt = CustomerCert.ExpiryDt,
|
|
|
+ IDCardAddress = CustomerCert.IDCardAddress,
|
|
|
+ CreateUserId = CustomerCert.CreateUserId,
|
|
|
+ Remark = CustomerCert.Remark,
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ if (res == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
|
|
|
+ }
|
|
|
}
|
|
|
- else//添加
|
|
|
+ else if (item.Id == 0)//添加
|
|
|
{
|
|
|
-
|
|
|
+ int sss = await _sqlSugar.Insertable(CustomerCert).ExecuteReturnIdentityAsync();
|
|
|
+ if (sss == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return result = new Result() { Code = 0, Msg = "修改成功!" };
|
|
|
- //进行其他表操作
|
|
|
+ //客户工作经历表
|
|
|
+ foreach (VisaCustomerCompany item in dto.WorkExperience)
|
|
|
+ {
|
|
|
+ Crm_VisaCustomerCompany VisaCustomerCompany = _mapper.Map<Crm_VisaCustomerCompany>(item);
|
|
|
+ VisaCustomerCompany.DcId = deleId;
|
|
|
+ if (item.Id != 0)//修改
|
|
|
+ {
|
|
|
+ int res = await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.Id == VisaCustomerCompany.Id).SetColumns(a => new Crm_VisaCustomerCompany
|
|
|
+ {
|
|
|
+ DcId=VisaCustomerCompany.DcId,
|
|
|
+ Company = VisaCustomerCompany.Company,
|
|
|
+ CompanyAddress = VisaCustomerCompany.CompanyAddress,
|
|
|
+ Phone = VisaCustomerCompany.Phone,
|
|
|
+ Job = VisaCustomerCompany.Job,
|
|
|
+ LeaderName = VisaCustomerCompany.LeaderName,
|
|
|
+ WorkStart = VisaCustomerCompany.WorkStart,
|
|
|
+ WorkEnd = VisaCustomerCompany.WorkEnd,
|
|
|
+ WorkState = VisaCustomerCompany.WorkState,
|
|
|
+ CreateUserId = VisaCustomerCompany.CreateUserId,
|
|
|
+ Remark = VisaCustomerCompany.Remark,
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ if (res == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.Id == 0)//添加
|
|
|
+ {
|
|
|
+ int sss = await _sqlSugar.Insertable(VisaCustomerCompany).ExecuteReturnIdentityAsync();
|
|
|
+ if (sss == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //客户学历表
|
|
|
+ foreach (VisaCustomerSchool item in dto.CustomerSchool)
|
|
|
+ {
|
|
|
+ Crm_VisaCustomerSchool VisaCustomerSchool = _mapper.Map<Crm_VisaCustomerSchool>(item);
|
|
|
+ VisaCustomerSchool.DcId = deleId;
|
|
|
+ if (item.Id != 0)//修改
|
|
|
+ {
|
|
|
+ int res = await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.Id == VisaCustomerSchool.Id).SetColumns(a => new Crm_VisaCustomerSchool
|
|
|
+ {
|
|
|
+ DcId = VisaCustomerSchool.DcId,
|
|
|
+ School = VisaCustomerSchool.School,
|
|
|
+ Address = VisaCustomerSchool.Address,
|
|
|
+ Teacher = VisaCustomerSchool.Teacher,
|
|
|
+ Education = VisaCustomerSchool.Education,
|
|
|
+ Subject = VisaCustomerSchool.Subject,
|
|
|
+ StudyStart = VisaCustomerSchool.StudyStart,
|
|
|
+ StudyEnd = VisaCustomerSchool.StudyEnd,
|
|
|
+ CreateUserId = VisaCustomerSchool.CreateUserId,
|
|
|
+ Remark = VisaCustomerSchool.Remark,
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ if (res == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.Id == 0)//添加
|
|
|
+ {
|
|
|
+ int sss = await _sqlSugar.Insertable(VisaCustomerSchool).ExecuteReturnIdentityAsync();
|
|
|
+ if (sss == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return result = new Result() { Code = -2, Msg = "程序错误!" };
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<Result> DelCustomer(DeleClientDelDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bool isOk=await SoftDeleteByIdAsync<Crm_DeleClient>(dto.Id.ToString(),dto.DeleteUserId);
|
|
|
+ if (isOk)//删除其他表数据
|
|
|
+ {
|
|
|
+ //客户工作经历
|
|
|
+ await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.DcId==dto.Id).SetColumns(a => new Crm_VisaCustomerCompany()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = dto.DeleteUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ //客户学历
|
|
|
+ await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerSchool()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = dto.DeleteUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ //客户家庭成员信息
|
|
|
+ await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerFamily()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = dto.DeleteUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ //客户证件表
|
|
|
+ await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_CustomerCert()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = dto.DeleteUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ return result = new Result() { Code = 0, Msg = "删除成功!" };
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- catch (Exception)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
return result = new Result() { Code = -2, Msg = "程序错误!" };
|
|
|
throw;
|