VisaDeleClientRepository.cs 25 KB

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