using OASystem.Domain;
using OASystem.Domain.Dtos;
using OASystem.Domain.Dtos.CRM;
using OASystem.Domain.Dtos.UserDto;
using OASystem.Domain.Entities.Customer;
using OASystem.Domain.Entities.Groups;
using OASystem.Domain.ViewModels.CRM;
using OASystem.Domain.ViewModels.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OASystem.Infrastructure.Repositories.CRM
{
///
/// 签证客户 仓库
///
public class VisaDeleClientRepository : BaseRepository
{
public VisaDeleClientRepository(SqlSugarClient sqlSugar) :
base(sqlSugar)
{ }
///
/// 签证客户list
///
///
///
public async Task GetCrmList(DtoBase dto)
{
Result result = new Result() { Code = -2 };
if (dto.PortType == 1 || dto.PortType == 2)
{
string sql = string.Format(@"Select cdc.Id,LastName+FirstName ClientName,ccc.CompanyName,Sex,Marriage,
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 ");
var clientList = await _sqlSugar.SqlQueryable(sql).ToListAsync();
if (clientList.Count > 0)
{
result.Code = 0;
result.Msg = "成功!";
result.Data = clientList;
}
else
{
result.Msg = "暂无数据!";
}
}
return result;
}
///
/// 签证客户操作
///
///
///
public async Task CrmClinetoperation(LoginDto loginDto)
{
Result result = new Result() { Code = -2 };
return result;
}
///
/// 签证客户 新增
///
///
///
public async Task CrmClinetAdd(Crm_DeleClient client)
{
int addId = -1;
return addId;
}
///
/// 根据身份证识别修改ocr添加
///
///
///
public async Task SetCrmUpdPassIdCardOCR(SetCrmUpdPassIdCardOCRDto client)
{
string clientSql = string.Format(@"Select * From Crm_DeleClient Where LastName+FirstName='{0}' And Sex = {1}",
client.ClientName, client.Sex);
var clientInfo = await _sqlSugar.SqlQueryable(clientSql).FirstAsync();
if(clientInfo == null) return false;
string cardSql = string.Format(@"Select * From Crm_CustomerCert Where SdId=773 And DcId={0}", clientInfo.Id);
var cardInfo = await _sqlSugar.SqlQueryable(cardSql).FirstAsync();
if (cardInfo == null) //添加
{
int cerdAdd = await _sqlSugar.Insertable(new Crm_CustomerCert
{
DcId = clientInfo.Id,
SdId = "773",
Country = "中国",
CertNo = client.CerdNo,
TargetCountry = "",
IssueDt = new DateTime(1990, 1, 1),
ExpiryDt = "1990-01-01 00:00:00.000",
CreateUserId = client.UserId,
CreateTime = DateTime.Now,
DeleteUserId = null,
DeleteTime = "1990-01-01 00:00:00.000",
Remark = "",
IsDel = 0
}).ExecuteReturnIdentityAsync();
if (cerdAdd > 0) return true;
}
else //修改
{
var cerdStatus = await _sqlSugar.Updateable()
.Where(c => c.Id == cardInfo.Id)
.SetColumns(c => new Crm_CustomerCert
{
CertNo = cardInfo.CertNo,
IDCardAddress = cardInfo.IDCardAddress
}).ExecuteCommandAsync();
if (cerdStatus > 0) return true;
}
return false;
}
}
}