VisaDeleClientRepository.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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)
  41. {
  42. string sql = string.Format(@"Select cdc.Id,LastName+FirstName ClientName,ccc.CompanyName,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. bool res = await UpdateAsync(a => a.Id == dto.DeleClient.Id, a => new Crm_DeleClient
  160. {
  161. DiId = dto.DeleClient.DiId,
  162. LastName = dto.DeleClient.LastName,
  163. FirstName = dto.DeleClient.FirstName,
  164. OldName = dto.DeleClient.OldName,
  165. Pinyin = dto.DeleClient.Pinyin,
  166. Sex = dto.DeleClient.Sex,
  167. Marriage = dto.DeleClient.Marriage,
  168. Phone = dto.DeleClient.Phone,
  169. BirthProvince = dto.DeleClient.BirthProvince,
  170. BirthCity = dto.DeleClient.BirthCity,
  171. BirthDay = dto.DeleClient.BirthDay,
  172. AirType = dto.DeleClient.AirType,
  173. SeatPref = dto.DeleClient.SeatPref,
  174. AirRemark = dto.DeleClient.AirRemark,
  175. RoomType = dto.DeleClient.RoomType,
  176. RoomPref = dto.DeleClient.RoomPref,
  177. Tel = dto.DeleClient.Tel,
  178. Email = dto.DeleClient.Email,
  179. Address = dto.DeleClient.Address,
  180. HighestEducation = dto.DeleClient.HighestEducation,
  181. PostCodes = dto.DeleClient.PostCodes,
  182. CrmCompanyId = dto.DeleClient.CrmCompanyId,
  183. Job = dto.DeleClient.Job,
  184. WorkState = dto.DeleClient.WorkState,
  185. WorkDate = dto.DeleClient.WorkDate,
  186. Wage = dto.DeleClient.Wage,
  187. ClientPhone = dto.DeleClient.ClientPhone,
  188. ClientFax = dto.DeleClient.ClientFax,
  189. ClientEmail = dto.DeleClient.ClientEmail,
  190. ClientLeader = dto.DeleClient.ClientLeader,
  191. ClientLeaderJob = dto.DeleClient.ClientLeaderJob,
  192. IsGetSchengen = dto.DeleClient.IsGetSchengen,
  193. StartTime = dto.DeleClient.StartTime,
  194. EndTime = dto.DeleClient.EndTime,
  195. IsFinger = dto.DeleClient.IsFinger,
  196. FingerDate = dto.DeleClient.FingerDate,
  197. IsVisitUC = dto.DeleClient.IsVisitUC,
  198. USADate = dto.DeleClient.USADate,
  199. USADays = dto.DeleClient.USADays,
  200. CanDate = dto.DeleClient.CanDate,
  201. CanDays = dto.DeleClient.CanDays,
  202. IsUSAVia = dto.DeleClient.IsUSAVia,
  203. GetUSAVisaDate = dto.DeleClient.GetUSAVisaDate,
  204. GetUPPlace = dto.DeleClient.GetUPPlace,
  205. USAVisaCate = dto.DeleClient.USAVisaCate,
  206. USAVisaCode = dto.DeleClient.USAVisaCode,
  207. USAFinger = dto.DeleClient.USAFinger,
  208. IsRejected = dto.DeleClient.IsRejected,
  209. RejectedDate = dto.DeleClient.RejectedDate,
  210. RejectedPlace = dto.DeleClient.RejectedPlace,
  211. RejectedVisa = dto.DeleClient.RejectedVisa,
  212. IsRevoke = dto.DeleClient.IsRevoke,
  213. IsLose = dto.DeleClient.IsLose,
  214. LoseDate = dto.DeleClient.LoseDate,
  215. LoseCode = dto.DeleClient.LoseCode,
  216. IsUSAVisa = dto.DeleClient.IsUSAVisa,
  217. MateUSA = dto.DeleClient.MateUSA,
  218. MateIden = dto.DeleClient.MateIden,
  219. WHUSA = dto.DeleClient.WHUSA,
  220. WHIden = dto.DeleClient.WHIden,
  221. ParentUSA = dto.DeleClient.ParentUSA,
  222. ParentIden = dto.DeleClient.ParentIden,
  223. ChildUSA = dto.DeleClient.ChildUSA,
  224. ChildIden = dto.DeleClient.ChildIden,
  225. BroUSA = dto.DeleClient.BroUSA,
  226. BroIden = dto.DeleClient.BroIden,
  227. Social = dto.DeleClient.Social,
  228. IsArmy = dto.DeleClient.IsArmy,
  229. ArmyState = dto.DeleClient.ArmyState,
  230. CostBearers = dto.DeleClient.CostBearers,
  231. TableOpName = dto.DeleClient.TableOpName,
  232. TableOpTel = dto.DeleClient.TableOpTel,
  233. TableDate = dto.DeleClient.TableDate,
  234. Party = dto.DeleClient.Party,
  235. Nationality = dto.DeleClient.Nationality,
  236. WeddingDate = dto.DeleClient.WeddingDate,
  237. DivorceDate = dto.DeleClient.DivorceDate,
  238. MateName = dto.DeleClient.MateName,
  239. MateBirthDay = dto.DeleClient.MateBirthDay,
  240. MateBirthCity = dto.DeleClient.MateBirthCity,
  241. MateBirthCountry = dto.DeleClient.MateBirthCountry,
  242. MateAddress = dto.DeleClient.MateAddress,
  243. MateClient = dto.DeleClient.MateClient,
  244. MateClientAddress = dto.DeleClient.MateClientAddress,
  245. MateJob = dto.DeleClient.MateJob,
  246. VisitCountry = dto.DeleClient.VisitCountry,
  247. Paper = dto.DeleClient.Paper,
  248. Papent = dto.DeleClient.Papent,
  249. PhD = dto.DeleClient.PhD,
  250. CreateUserId = dto.DeleClient.CreateUserId,
  251. Remark = dto.DeleClient.Remark,
  252. });
  253. if (!res)
  254. {
  255. result = new Result() { Code = -1, Msg = "修改失败!" };
  256. }
  257. result = new Result() { Code = 0, Msg = "修改成功!" };
  258. }
  259. //进行其他表
  260. if (result.Code == 0)
  261. {//家庭成员信息
  262. foreach (CustomerFamily item in dto.CustomerFamily)
  263. {
  264. Crm_VisaCustomerFamily Crm_VisaCustomerFamily = _mapper.Map<Crm_VisaCustomerFamily>(item);
  265. Crm_VisaCustomerFamily.DcId = deleId;
  266. if (item.Id != 0)//修改
  267. {
  268. int res = await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.Id == Crm_VisaCustomerFamily.Id).SetColumns(a => new Crm_VisaCustomerFamily
  269. {
  270. Appellation = Crm_VisaCustomerFamily.Appellation,
  271. Name = Crm_VisaCustomerFamily.Name,
  272. BirthDay = Crm_VisaCustomerFamily.BirthDay,
  273. BirthPlace = Crm_VisaCustomerFamily.BirthPlace,
  274. Politics = Crm_VisaCustomerFamily.Politics,
  275. Client = Crm_VisaCustomerFamily.Client,
  276. Address = Crm_VisaCustomerFamily.Address,
  277. IsEu = Crm_VisaCustomerFamily.IsEu,
  278. NameSnd = Crm_VisaCustomerFamily.NameSnd,
  279. BirthDaySnd = Crm_VisaCustomerFamily.BirthDaySnd,
  280. Nationality = Crm_VisaCustomerFamily.Nationality,
  281. IDCard = Crm_VisaCustomerFamily.IDCard,
  282. Reletionship = Crm_VisaCustomerFamily.Reletionship,
  283. IsUSA = Crm_VisaCustomerFamily.IsUSA,
  284. Remark = Crm_VisaCustomerFamily.Remark,
  285. }).ExecuteCommandAsync();
  286. if (res==0)
  287. {
  288. result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
  289. RollbackTran();
  290. }
  291. }
  292. else if (item.Id == 0)//添加
  293. {
  294. int sss= await _sqlSugar.Insertable(Crm_VisaCustomerFamily).ExecuteReturnIdentityAsync();
  295. if (sss == 0)
  296. {
  297. result = new Result() { Code = -1, Msg = "家庭成员信息保存失败!" };
  298. RollbackTran();
  299. }
  300. }
  301. }
  302. //证件表信息
  303. foreach (CustomerCerts item in dto.CustomerCert)
  304. {
  305. Crm_CustomerCert CustomerCert = _mapper.Map<Crm_CustomerCert>(item);
  306. CustomerCert.DcId = deleId;
  307. if (item.Id != 0)//修改
  308. {
  309. int res = await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.Id == CustomerCert.Id).SetColumns(a => new Crm_CustomerCert
  310. {
  311. DcId=CustomerCert.DcId,
  312. SdId = CustomerCert.SdId,
  313. CertNo = CustomerCert.CertNo,
  314. Country = CustomerCert.Country,
  315. Area = CustomerCert.Area,
  316. TargetCountry = CustomerCert.TargetCountry,
  317. IssueDt = CustomerCert.IssueDt,
  318. ExpiryDt = CustomerCert.ExpiryDt,
  319. IDCardAddress = CustomerCert.IDCardAddress,
  320. CreateUserId = CustomerCert.CreateUserId,
  321. Remark = CustomerCert.Remark,
  322. }).ExecuteCommandAsync();
  323. if (res == 0)
  324. {
  325. result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
  326. RollbackTran();
  327. }
  328. }
  329. else if (item.Id == 0)//添加
  330. {
  331. int sss = await _sqlSugar.Insertable(CustomerCert).ExecuteReturnIdentityAsync();
  332. if (sss == 0)
  333. {
  334. result = new Result() { Code = -1, Msg = "证件信息保存失败!" };
  335. RollbackTran();
  336. }
  337. }
  338. }
  339. //客户工作经历表
  340. foreach (VisaCustomerCompany item in dto.WorkExperience)
  341. {
  342. Crm_VisaCustomerCompany VisaCustomerCompany = _mapper.Map<Crm_VisaCustomerCompany>(item);
  343. VisaCustomerCompany.DcId = deleId;
  344. if (item.Id != 0)//修改
  345. {
  346. int res = await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.Id == VisaCustomerCompany.Id).SetColumns(a => new Crm_VisaCustomerCompany
  347. {
  348. DcId=VisaCustomerCompany.DcId,
  349. Company = VisaCustomerCompany.Company,
  350. CompanyAddress = VisaCustomerCompany.CompanyAddress,
  351. Phone = VisaCustomerCompany.Phone,
  352. Job = VisaCustomerCompany.Job,
  353. LeaderName = VisaCustomerCompany.LeaderName,
  354. WorkStart = VisaCustomerCompany.WorkStart,
  355. WorkEnd = VisaCustomerCompany.WorkEnd,
  356. WorkState = VisaCustomerCompany.WorkState,
  357. CreateUserId = VisaCustomerCompany.CreateUserId,
  358. Remark = VisaCustomerCompany.Remark,
  359. }).ExecuteCommandAsync();
  360. if (res == 0)
  361. {
  362. result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
  363. RollbackTran();
  364. }
  365. }
  366. else if (item.Id == 0)//添加
  367. {
  368. int sss = await _sqlSugar.Insertable(VisaCustomerCompany).ExecuteReturnIdentityAsync();
  369. if (sss == 0)
  370. {
  371. result = new Result() { Code = -1, Msg = "客户工作经历保存失败!" };
  372. RollbackTran();
  373. }
  374. }
  375. }
  376. //客户学历表
  377. foreach (VisaCustomerSchool item in dto.CustomerSchool)
  378. {
  379. Crm_VisaCustomerSchool VisaCustomerSchool = _mapper.Map<Crm_VisaCustomerSchool>(item);
  380. VisaCustomerSchool.DcId = deleId;
  381. if (item.Id != 0)//修改
  382. {
  383. int res = await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.Id == VisaCustomerSchool.Id).SetColumns(a => new Crm_VisaCustomerSchool
  384. {
  385. DcId = VisaCustomerSchool.DcId,
  386. School = VisaCustomerSchool.School,
  387. Address = VisaCustomerSchool.Address,
  388. Teacher = VisaCustomerSchool.Teacher,
  389. Education = VisaCustomerSchool.Education,
  390. Subject = VisaCustomerSchool.Subject,
  391. StudyStart = VisaCustomerSchool.StudyStart,
  392. StudyEnd = VisaCustomerSchool.StudyEnd,
  393. CreateUserId = VisaCustomerSchool.CreateUserId,
  394. Remark = VisaCustomerSchool.Remark,
  395. }).ExecuteCommandAsync();
  396. if (res == 0)
  397. {
  398. result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
  399. RollbackTran();
  400. }
  401. }
  402. else if (item.Id == 0)//添加
  403. {
  404. int sss = await _sqlSugar.Insertable(VisaCustomerSchool).ExecuteReturnIdentityAsync();
  405. if (sss == 0)
  406. {
  407. result = new Result() { Code = -1, Msg = "客户学历信息保存失败!" };
  408. RollbackTran();
  409. }
  410. }
  411. }
  412. CommitTran();
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. return result = new Result() { Code = -2, Msg = "程序错误!" };
  418. throw;
  419. }
  420. return result;
  421. }
  422. public async Task<Result> DelCustomer(DeleClientDelDto dto)
  423. {
  424. Result result = new Result() { Code = -2, Msg = "未知错误" };
  425. try
  426. {
  427. bool isOk=await SoftDeleteByIdAsync<Crm_DeleClient>(dto.Id.ToString(),dto.DeleteUserId);
  428. if (isOk)//删除其他表数据
  429. {
  430. //客户工作经历
  431. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>().Where(a => a.DcId==dto.Id).SetColumns(a => new Crm_VisaCustomerCompany()
  432. {
  433. IsDel = 1,
  434. DeleteUserId = dto.DeleteUserId,
  435. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  436. }).ExecuteCommandAsync();
  437. //客户学历
  438. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerSchool()
  439. {
  440. IsDel = 1,
  441. DeleteUserId = dto.DeleteUserId,
  442. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  443. }).ExecuteCommandAsync();
  444. //客户家庭成员信息
  445. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_VisaCustomerFamily()
  446. {
  447. IsDel = 1,
  448. DeleteUserId = dto.DeleteUserId,
  449. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  450. }).ExecuteCommandAsync();
  451. //客户证件表
  452. await _sqlSugar.Updateable<Crm_CustomerCert>().Where(a => a.DcId == dto.Id).SetColumns(a => new Crm_CustomerCert()
  453. {
  454. IsDel = 1,
  455. DeleteUserId = dto.DeleteUserId,
  456. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  457. }).ExecuteCommandAsync();
  458. return result = new Result() { Code = 0, Msg = "删除成功!" };
  459. }
  460. }
  461. catch (Exception ex)
  462. {
  463. return result = new Result() { Code = -2, Msg = "程序错误!" };
  464. throw;
  465. }
  466. return result;
  467. }
  468. }
  469. }