VisaDeleClientRepository.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. 
  2. using AutoMapper;
  3. using Newtonsoft.Json;
  4. using OASystem.Domain;
  5. using OASystem.Domain.AesEncryption;
  6. using OASystem.Domain.Dtos;
  7. using OASystem.Domain.Dtos.CRM;
  8. using OASystem.Domain.Dtos.UserDto;
  9. using OASystem.Domain.Entities.Customer;
  10. using OASystem.Domain.Entities.Groups;
  11. using OASystem.Domain.Entities.Resource;
  12. using OASystem.Domain.ViewModels.CRM;
  13. using OASystem.Domain.ViewModels.Groups;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Runtime.Intrinsics.X86;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. namespace OASystem.Infrastructure.Repositories.CRM
  21. {
  22. /// <summary>
  23. /// 签证客户 仓库
  24. /// </summary>
  25. public class VisaDeleClientRepository : BaseRepository<Crm_DeleClient, VisaDeleClientView>
  26. {
  27. private readonly IMapper _mapper;
  28. public VisaDeleClientRepository(SqlSugarClient sqlSugar,IMapper mapper) :
  29. base(sqlSugar)
  30. {
  31. this._mapper = mapper;
  32. }
  33. /// <summary>
  34. /// 签证客户list
  35. /// </summary>
  36. /// <param name="loginDto"></param>
  37. /// <returns></returns>
  38. public async Task<Result> GetCrmList(DtoBase dto)
  39. {
  40. Result result = new Result() { Code = -2 };
  41. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  42. {
  43. string sql = string.Format(@"Select cdc.Id,cdc.LastName,cdc.FirstName,ccc.CompanyFullName,Sex,Marriage,
  44. Phone LandlinePhone,Tel,crmCard1.CertNo IDNo,crmCard2.CertNo PassportNo
  45. From Crm_DeleClient cdc
  46. Left Join Crm_CustomerCompany ccc On cdc.crmCompanyId = ccc.Id
  47. Left Join Crm_CustomerCert crmCard1 On crmCard1.SdId = 773 And cdc.Id = crmCard1.DcId And crmCard1.Isdel=0
  48. 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");
  49. var clientList = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(sql).ToListAsync();
  50. foreach (var item in clientList)
  51. {
  52. EncryptionProcessor.DecryptProperties(item);
  53. }
  54. if (clientList.Count > 0)
  55. {
  56. result.Code = 0;
  57. result.Msg = "成功!";
  58. result.Data = clientList;
  59. }
  60. else
  61. {
  62. result.Msg = "暂无数据!";
  63. }
  64. }
  65. return result;
  66. }
  67. /// <summary>
  68. /// 签证客户操作
  69. /// </summary>
  70. /// <param name="loginDto"></param>
  71. /// <returns></returns>
  72. public async Task<Result> CrmClinetoperation(LoginDto loginDto)
  73. {
  74. Result result = new Result() { Code = -2 };
  75. return result;
  76. }
  77. /// <summary>
  78. /// 签证客户 新增
  79. /// </summary>
  80. /// <param name="loginDto"></param>
  81. /// <returns></returns>
  82. public async Task<int> CrmClinetAdd(Crm_DeleClient client)
  83. {
  84. int addId = -1;
  85. return addId;
  86. }
  87. /// <summary>
  88. /// 根据身份证识别修改ocr添加
  89. /// </summary>
  90. /// <param name="client"></param>
  91. /// <returns></returns>
  92. public async Task<bool> SetCrmUpdPassIdCardOCR(SetCrmUpdPassIdCardOCRDto client)
  93. {
  94. string clientSql = string.Format(@"Select * From Crm_DeleClient Where LastName+FirstName='{0}' And Sex = {1}",
  95. client.ClientName, client.Sex);
  96. var clientInfo = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(clientSql).FirstAsync();
  97. if(clientInfo == null) return false;
  98. string cardSql = string.Format(@"Select * From Crm_CustomerCert Where SdId=773 And DcId={0}", clientInfo.Id);
  99. var cardInfo = await _sqlSugar.SqlQueryable<CustomerCertView>(cardSql).FirstAsync();
  100. if (cardInfo == null) //添加
  101. {
  102. int cerdAdd = await _sqlSugar.Insertable<Crm_CustomerCert>(new Crm_CustomerCert
  103. {
  104. DcId = clientInfo.Id,
  105. SdId = 773,
  106. Country = "中国",
  107. CertNo = client.CerdNo,
  108. TargetCountry = "",
  109. IssueDt = new DateTime(1990, 1, 1),
  110. ExpiryDt = new DateTime(1990, 1, 1),
  111. CreateUserId = client.UserId,
  112. CreateTime = DateTime.Now,
  113. DeleteUserId = null,
  114. DeleteTime = "1990-01-01 00:00:00.000",
  115. Remark = "",
  116. IsDel = 0
  117. }).ExecuteReturnIdentityAsync();
  118. if (cerdAdd > 0) return true;
  119. }
  120. else //修改
  121. {
  122. var cerdStatus = await _sqlSugar.Updateable<Crm_CustomerCert>()
  123. .Where(c => c.Id == cardInfo.Id)
  124. .SetColumns(c => new Crm_CustomerCert
  125. {
  126. CertNo = cardInfo.CertNo,
  127. IDCardAddress = cardInfo.IDCardAddress
  128. }).ExecuteCommandAsync();
  129. if (cerdStatus > 0) return true;
  130. }
  131. return false;
  132. }
  133. public async Task<Result> OpCustomer(DeleClientOpDto dto)
  134. {
  135. Result result = new Result() { Code = -2, Msg = "未知错误" };
  136. try
  137. {
  138. EncryptionProcessor.EncryptProperties(dto.DeleClient);
  139. BeginTran();
  140. int deleId = 0;
  141. if (dto.Status==1)//添加
  142. {
  143. string selectSql = string.Format(@"select * from Crm_DeleClient where LastName+FirstName='{0}' and Phone='{1}' and IsDel='{2}'"
  144. , dto.DeleClient.LastName+dto.DeleClient.FirstName, dto.DeleClient.Phone, 0);
  145. var DeleClient = await _sqlSugar.SqlQueryable<Crm_DeleClient>(selectSql).FirstAsync();//查询是否存在
  146. if (DeleClient != null)
  147. {
  148. result = new Result() { Code = -1, Msg = "该客户已存在,请勿重复添加!" };
  149. }
  150. else//不存在,可添加
  151. {
  152. Crm_DeleClient _CountryFeeCost = _mapper.Map<Crm_DeleClient>(dto.DeleClient);
  153. int id = await AddAsyncReturnId(_CountryFeeCost);
  154. if (id == 0)
  155. {
  156. result = new Result() { Code = -1, Msg = "添加失败!" };
  157. }
  158. result = new Result() { Code = 0, Msg = "添加成功!" };
  159. deleId = id;
  160. }
  161. }
  162. else if (dto.Status == 2)//修改
  163. {
  164. deleId=dto.DeleClient.Id;
  165. DateTime? dateTime = null;
  166. bool isDt = DateTime.TryParse(dto.DeleClient.BirthDay, out DateTime dt);
  167. if (isDt) dateTime = dt;
  168. bool res = await UpdateAsync(a => a.Id == dto.DeleClient.Id, a => new Crm_DeleClient
  169. {
  170. DiId = dto.DeleClient.DiId,
  171. LastName = dto.DeleClient.LastName,
  172. FirstName = dto.DeleClient.FirstName,
  173. OldName = dto.DeleClient.OldName,
  174. Pinyin = dto.DeleClient.Pinyin,
  175. Sex = dto.DeleClient.Sex,
  176. Marriage = dto.DeleClient.Marriage,
  177. Phone = dto.DeleClient.Phone,
  178. BirthProvince = dto.DeleClient.BirthProvince,
  179. BirthCity = dto.DeleClient.BirthCity,
  180. BirthDay = dateTime,
  181. AirType = dto.DeleClient.AirType,
  182. SeatPref = dto.DeleClient.SeatPref,
  183. AirRemark = dto.DeleClient.AirRemark,
  184. RoomType = dto.DeleClient.RoomType,
  185. RoomPref = dto.DeleClient.RoomPref,
  186. Tel = dto.DeleClient.Tel,
  187. Email = dto.DeleClient.Email,
  188. Address = dto.DeleClient.Address,
  189. HighestEducation = dto.DeleClient.HighestEducation,
  190. PostCodes = dto.DeleClient.PostCodes,
  191. CrmCompanyId = dto.DeleClient.CrmCompanyId,
  192. Job = dto.DeleClient.Job,
  193. WorkState = dto.DeleClient.WorkState,
  194. WorkDate = dto.DeleClient.WorkDate,
  195. Wage = dto.DeleClient.Wage,
  196. ClientPhone = dto.DeleClient.ClientPhone,
  197. ClientFax = dto.DeleClient.ClientFax,
  198. ClientEmail = dto.DeleClient.ClientEmail,
  199. ClientLeader = dto.DeleClient.ClientLeader,
  200. ClientLeaderJob = dto.DeleClient.ClientLeaderJob,
  201. IsGetSchengen = dto.DeleClient.IsGetSchengen,
  202. StartTime = dto.DeleClient.StartTime,
  203. EndTime = dto.DeleClient.EndTime,
  204. IsFinger = dto.DeleClient.IsFinger,
  205. FingerDate = dto.DeleClient.FingerDate,
  206. IsVisitUC = dto.DeleClient.IsVisitUC,
  207. USADate = dto.DeleClient.USADate,
  208. USADays = dto.DeleClient.USADays,
  209. CanDate = dto.DeleClient.CanDate,
  210. CanDays = dto.DeleClient.CanDays,
  211. IsUSAVia = dto.DeleClient.IsUSAVia,
  212. GetUSAVisaDate = dto.DeleClient.GetUSAVisaDate,
  213. GetUPPlace = dto.DeleClient.GetUPPlace,
  214. USAVisaCate = dto.DeleClient.USAVisaCate,
  215. USAVisaCode = dto.DeleClient.USAVisaCode,
  216. USAFinger = dto.DeleClient.USAFinger,
  217. IsRejected = dto.DeleClient.IsRejected,
  218. RejectedDate = dto.DeleClient.RejectedDate,
  219. RejectedPlace = dto.DeleClient.RejectedPlace,
  220. RejectedVisa = dto.DeleClient.RejectedVisa,
  221. IsRevoke = dto.DeleClient.IsRevoke,
  222. IsLose = dto.DeleClient.IsLose,
  223. LoseDate = dto.DeleClient.LoseDate,
  224. LoseCode = dto.DeleClient.LoseCode,
  225. IsUSAVisa = dto.DeleClient.IsUSAVisa,
  226. MateUSA = dto.DeleClient.MateUSA,
  227. MateIden = dto.DeleClient.MateIden,
  228. WHUSA = dto.DeleClient.WHUSA,
  229. WHIden = dto.DeleClient.WHIden,
  230. ParentUSA = dto.DeleClient.ParentUSA,
  231. ParentIden = dto.DeleClient.ParentIden,
  232. ChildUSA = dto.DeleClient.ChildUSA,
  233. ChildIden = dto.DeleClient.ChildIden,
  234. BroUSA = dto.DeleClient.BroUSA,
  235. BroIden = dto.DeleClient.BroIden,
  236. Social = dto.DeleClient.Social,
  237. IsArmy = dto.DeleClient.IsArmy,
  238. ArmyState = dto.DeleClient.ArmyState,
  239. CostBearers = dto.DeleClient.CostBearers,
  240. TableOpName = dto.DeleClient.TableOpName,
  241. TableOpTel = dto.DeleClient.TableOpTel,
  242. TableDate = dto.DeleClient.TableDate,
  243. Party = dto.DeleClient.Party,
  244. Nationality = dto.DeleClient.Nationality,
  245. WeddingDate = dto.DeleClient.WeddingDate,
  246. DivorceDate = dto.DeleClient.DivorceDate,
  247. MateName = dto.DeleClient.MateName,
  248. MateBirthDay = dto.DeleClient.MateBirthDay,
  249. MateBirthCity = dto.DeleClient.MateBirthCity,
  250. MateBirthCountry = dto.DeleClient.MateBirthCountry,
  251. MateAddress = dto.DeleClient.MateAddress,
  252. MateClient = dto.DeleClient.MateClient,
  253. MateClientAddress = dto.DeleClient.MateClientAddress,
  254. MateJob = dto.DeleClient.MateJob,
  255. VisitCountry = dto.DeleClient.VisitCountry,
  256. Paper = dto.DeleClient.Paper,
  257. Papent = dto.DeleClient.Papent,
  258. PhD = dto.DeleClient.PhD,
  259. CreateUserId = dto.DeleClient.CreateUserId,
  260. Remark = dto.DeleClient.Remark,
  261. });
  262. if (!res)
  263. {
  264. result = new Result() { Code = -1, Msg = "修改失败!" };
  265. }
  266. result = new Result() { Code = 0, Msg = "修改成功!" };
  267. }
  268. //进行其他表
  269. if (result.Code == 0)
  270. {//家庭成员信息
  271. foreach (CustomerFamily item in dto.CustomerFamily)
  272. {
  273. Crm_VisaCustomerFamily Crm_VisaCustomerFamily = _mapper.Map<Crm_VisaCustomerFamily>(item);
  274. Crm_VisaCustomerFamily.DcId = deleId;
  275. if (item.Id != 0)//修改
  276. {
  277. int res = await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.Id == Crm_VisaCustomerFamily.Id).SetColumns(a => new Crm_VisaCustomerFamily
  278. {
  279. Appellation = Crm_VisaCustomerFamily.Appellation,
  280. Name = Crm_VisaCustomerFamily.Name,
  281. BirthDay = Crm_VisaCustomerFamily.BirthDay,
  282. BirthPlace = Crm_VisaCustomerFamily.BirthPlace,
  283. Politics = Crm_VisaCustomerFamily.Politics,
  284. Client = Crm_VisaCustomerFamily.Client,
  285. Address = Crm_VisaCustomerFamily.Address,
  286. IsEu = Crm_VisaCustomerFamily.IsEu,
  287. NameSnd = Crm_VisaCustomerFamily.NameSnd,
  288. BirthDaySnd = Crm_VisaCustomerFamily.BirthDaySnd,
  289. Nationality = Crm_VisaCustomerFamily.Nationality,
  290. IDCard = Crm_VisaCustomerFamily.IDCard,
  291. Reletionship = Crm_VisaCustomerFamily.Reletionship,
  292. IsUSA = Crm_VisaCustomerFamily.IsUSA,
  293. Remark = Crm_VisaCustomerFamily.Remark,
  294. }).ExecuteCommandAsync();
  295. if (res==0)
  296. {
  297. result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
  298. RollbackTran();
  299. }
  300. }
  301. else if (item.Id == 0)//添加
  302. {
  303. int sss= await _sqlSugar.Insertable(Crm_VisaCustomerFamily).ExecuteReturnIdentityAsync();
  304. if (sss == 0)
  305. {
  306. result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
  307. RollbackTran();
  308. }
  309. }
  310. }
  311. //证件表信息
  312. foreach (CustomerCerts item in dto.CustomerCert)
  313. {
  314. Crm_CustomerCert CustomerCert = _mapper.Map<Crm_CustomerCert>(item);
  315. CustomerCert.DcId = deleId;
  316. if (item.Id != 0)//修改
  317. {
  318. int res = await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.Id == CustomerCert.Id).SetColumns(a => new Crm_CustomerCert
  319. {
  320. DcId=CustomerCert.DcId,
  321. SdId = CustomerCert.SdId,
  322. CertNo = CustomerCert.CertNo,
  323. Country = CustomerCert.Country,
  324. Area = CustomerCert.Area,
  325. TargetCountry = CustomerCert.TargetCountry,
  326. IssueDt = CustomerCert.IssueDt,
  327. ExpiryDt = CustomerCert.ExpiryDt,
  328. IDCardAddress = CustomerCert.IDCardAddress,
  329. CreateUserId = CustomerCert.CreateUserId,
  330. Remark = CustomerCert.Remark,
  331. }).ExecuteCommandAsync();
  332. if (res == 0)
  333. {
  334. result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
  335. RollbackTran();
  336. }
  337. }
  338. else if (item.Id == 0)//添加
  339. {
  340. int sss = await _sqlSugar.Insertable(CustomerCert).ExecuteReturnIdentityAsync();
  341. if (sss == 0)
  342. {
  343. result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
  344. RollbackTran();
  345. }
  346. }
  347. }
  348. //客户工作经历表
  349. foreach (VisaCustomerCompany item in dto.WorkExperience)
  350. {
  351. Crm_VisaCustomerCompany VisaCustomerCompany = _mapper.Map<Crm_VisaCustomerCompany>(item);
  352. VisaCustomerCompany.DcId = deleId;
  353. if (item.Id != 0)//修改
  354. {
  355. int res = await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.Id == VisaCustomerCompany.Id).SetColumns(a => new Crm_VisaCustomerCompany
  356. {
  357. DcId=VisaCustomerCompany.DcId,
  358. Company = VisaCustomerCompany.Company,
  359. CompanyAddress = VisaCustomerCompany.CompanyAddress,
  360. Phone = VisaCustomerCompany.Phone,
  361. Job = VisaCustomerCompany.Job,
  362. LeaderName = VisaCustomerCompany.LeaderName,
  363. WorkStart = VisaCustomerCompany.WorkStart,
  364. WorkEnd = VisaCustomerCompany.WorkEnd,
  365. WorkState = VisaCustomerCompany.WorkState,
  366. CreateUserId = VisaCustomerCompany.CreateUserId,
  367. Remark = VisaCustomerCompany.Remark,
  368. }).ExecuteCommandAsync();
  369. if (res == 0)
  370. {
  371. result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
  372. RollbackTran();
  373. }
  374. }
  375. else if (item.Id == 0)//添加
  376. {
  377. int sss = await _sqlSugar.Insertable(VisaCustomerCompany).ExecuteReturnIdentityAsync();
  378. if (sss == 0)
  379. {
  380. result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
  381. RollbackTran();
  382. }
  383. }
  384. }
  385. //客户学历表
  386. foreach (VisaCustomerSchool item in dto.CustomerSchool)
  387. {
  388. Crm_VisaCustomerSchool VisaCustomerSchool = _mapper.Map<Crm_VisaCustomerSchool>(item);
  389. VisaCustomerSchool.DcId = deleId;
  390. if (item.Id != 0)//修改
  391. {
  392. int res = await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.Id == VisaCustomerSchool.Id).SetColumns(a => new Crm_VisaCustomerSchool
  393. {
  394. DcId = VisaCustomerSchool.DcId,
  395. School = VisaCustomerSchool.School,
  396. Address = VisaCustomerSchool.Address,
  397. Teacher = VisaCustomerSchool.Teacher,
  398. Education = VisaCustomerSchool.Education,
  399. Subject = VisaCustomerSchool.Subject,
  400. StudyStart = VisaCustomerSchool.StudyStart,
  401. StudyEnd = VisaCustomerSchool.StudyEnd,
  402. CreateUserId = VisaCustomerSchool.CreateUserId,
  403. Remark = VisaCustomerSchool.Remark,
  404. }).ExecuteCommandAsync();
  405. if (res == 0)
  406. {
  407. result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
  408. RollbackTran();
  409. }
  410. }
  411. else if (item.Id == 0)//添加
  412. {
  413. int sss = await _sqlSugar.Insertable(VisaCustomerSchool).ExecuteReturnIdentityAsync();
  414. if (sss == 0)
  415. {
  416. result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
  417. RollbackTran();
  418. }
  419. }
  420. }
  421. CommitTran();
  422. }
  423. }
  424. catch (Exception ex)
  425. {
  426. return result = new Result() { Code = -2, Msg = "程序错误!" };
  427. throw;
  428. }
  429. return result;
  430. }
  431. public async Task<Result> DelCustomer(DeleClientDelDto dto)
  432. {
  433. Result result = new Result() { Code = -2, Msg = "未知错误" };
  434. try
  435. {
  436. bool isOk=await SoftDeleteByIdAsync<Crm_DeleClient>(dto.Id.ToString(),dto.DeleteUserId);
  437. if (isOk)//删除其他表数据
  438. {
  439. //客户工作经历
  440. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.DcId==dto.Id).SetColumns(a => new Crm_VisaCustomerCompany()
  441. {
  442. IsDel = 1,
  443. DeleteUserId = dto.DeleteUserId,
  444. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  445. }).ExecuteCommandAsync();
  446. //客户学历
  447. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerSchool()
  448. {
  449. IsDel = 1,
  450. DeleteUserId = dto.DeleteUserId,
  451. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  452. }).ExecuteCommandAsync();
  453. //客户家庭成员信息
  454. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerFamily()
  455. {
  456. IsDel = 1,
  457. DeleteUserId = dto.DeleteUserId,
  458. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  459. }).ExecuteCommandAsync();
  460. //客户证件表
  461. await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_CustomerCert()
  462. {
  463. IsDel = 1,
  464. DeleteUserId = dto.DeleteUserId,
  465. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  466. }).ExecuteCommandAsync();
  467. return result = new Result() { Code = 0, Msg = "删除成功!" };
  468. }
  469. }
  470. catch (Exception ex)
  471. {
  472. return result = new Result() { Code = -2, Msg = "程序错误!" };
  473. throw;
  474. }
  475. return result;
  476. }
  477. }
  478. }