You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

762 lines
32 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Dapper;
  2. using Newtonsoft.Json.Converters;
  3. using Newtonsoft.Json;
  4. using Npgsql;
  5. using NPOI.SS.Formula.Functions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data.Common;
  9. using System.Linq;
  10. using System.Net.Http.Headers;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Text.RegularExpressions;
  14. using Shentun.Peis.PatientRegisters;
  15. using Shentun.Peis.PersonnelTypes;
  16. using Shentun.Peis.MedicalTypes;
  17. using Shentun.Peis.CustomerOrgs;
  18. using Shentun.Peis.CustomerOrgGroups;
  19. using Shentun.Peis.CustomerReports;
  20. using Shentun.Peis.CustomerOrgGroupDetails;
  21. using Shentun.Peis.CustomerOrgRegisters;
  22. using Shentun.Peis.Enums;
  23. using Shentun.Peis.Patients;
  24. using Shentun.Peis.PlugIns.PatientRegisters;
  25. namespace Shentun.Peis.PlugIns.Extensions.PatientRegisters.Qztl
  26. {
  27. public class ImportPatientRegisterPlugInsQztl : ImportPatientRegisterPlugInsBase
  28. {
  29. private Guid _importCustomerOrgId;
  30. private string _hospitalId;
  31. private string _aesKEY;
  32. private string _year;
  33. private CustomerOrgDto _customerOrgDto;
  34. private CustomerOrgRegisterDto _customerOrgRegisterDto;
  35. private List<PersonnelTypeDto> _personnelTypes;
  36. private List<CustomerOrgGroupDto> _customerOrgGroupDtos;
  37. private string _answerWebApiUrl;
  38. public ImportPatientRegisterPlugInsQztl(Guid thirdInterfaceId) : base(thirdInterfaceId)
  39. {
  40. }
  41. public ImportPatientRegisterPlugInsQztl(string parmValue) : base(parmValue)
  42. {
  43. }
  44. public override async Task ImportAsync()
  45. {
  46. await LoginAsync();
  47. await InitAsync();
  48. var qztlPatientRegisterFromInterface = await CallInterfaceServiceAsync();
  49. if (qztlPatientRegisterFromInterface == null || !qztlPatientRegisterFromInterface.plans.Any())
  50. {
  51. return;
  52. }
  53. //设置导入人员信息
  54. foreach (var patient in qztlPatientRegisterFromInterface.plans)
  55. {
  56. try
  57. {
  58. //婚姻状况
  59. var maritalStatusId = ConvertMaritalStatus(patient.wedding);
  60. //人员类别
  61. var personnelType = ConvertPersonnelType(patient.tjJieduan);
  62. //性别
  63. var sexId = ConvertSex(patient.sex);
  64. //体检类别
  65. var medicalTypeName = patient.tjpcV;
  66. MedicalTypeDto medicalTypeDto = null;
  67. if (!string.IsNullOrWhiteSpace(medicalTypeName))
  68. {
  69. medicalTypeDto = await CallAppServiceAsync<DisplayNameInputDto, MedicalTypeDto>(
  70. "api/app/MedicalType/GetByDisplayName", new DisplayNameInputDto() { DisplayName = medicalTypeName });
  71. if (medicalTypeDto == null)
  72. {
  73. var createMedicalTypeDto = new CreateMedicalTypeDto()
  74. {
  75. DisplayName = medicalTypeName,
  76. };
  77. medicalTypeDto = await CallAppServiceAsync<CreateMedicalTypeDto, MedicalTypeDto>(
  78. "api/app/medical-type", new CreateMedicalTypeDto() { DisplayName = medicalTypeName });
  79. }
  80. }
  81. //职称
  82. var jobTitle = ConvertJobTitle(patient.gradeZwV);
  83. //职务
  84. var jobPost = ConvertJobPost(patient.tjTab1);
  85. string workTypeV = patient.workTypeV;
  86. if (string.IsNullOrWhiteSpace(workTypeV))
  87. {
  88. workTypeV = "";
  89. }
  90. else
  91. {
  92. workTypeV = "," + workTypeV;
  93. }
  94. jobPost = jobPost + workTypeV;
  95. if (!string.IsNullOrWhiteSpace(jobPost) && jobPost.Length >= 10)
  96. {
  97. jobPost = jobPost.Substring(0, 10);//只能存储10个汉字
  98. }
  99. //查找子单位是否存在,如存在获取子单位id,如果不存在这创建子单位
  100. var orgName = patient.orgName;
  101. var pos = orgName.IndexOf("_");
  102. orgName = orgName.Substring(0, pos);
  103. if (string.IsNullOrWhiteSpace(patient.mobile))
  104. {
  105. //青海省第五人民医院要强行设置为 11111111111
  106. }
  107. var customerOrgDtos = await CallAppServiceAsync<CustomerOrgIdInputDto, List<CustomerOrgDto>>(
  108. "api/app/CustomerOrg/GetChildCustomerOrgsById",
  109. new CustomerOrgIdInputDto() { CustomerOrgId = _importCustomerOrgId });
  110. CustomerOrgDto customerOrgDto = null;
  111. if (customerOrgDtos != null && customerOrgDtos.Any())
  112. {
  113. customerOrgDto = customerOrgDtos.Where(o => o.DisplayName == orgName).FirstOrDefault();
  114. }
  115. if (customerOrgDto == null)
  116. {
  117. customerOrgDto = await CallAppServiceAsync<CreateCustomerOrgDto, CustomerOrgDto>(
  118. "api/app/customerorg/create", new CreateCustomerOrgDto()
  119. {
  120. MedicalCenterId = _customerOrgDto.MedicalCenterId,
  121. ParentId = _importCustomerOrgId,
  122. DisplayName = orgName,
  123. ShortName = orgName,
  124. IsActive = 'Y',
  125. IsLock = 'Y'
  126. });
  127. }
  128. CustomerOrgGroupDto customerOrgGroupDto;
  129. if (patient.ifFj == 1)
  130. {
  131. //复检
  132. //加载单位分组信息
  133. _customerOrgGroupDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDto>>(
  134. "api/app/customer-org-group/in-customer-org-id/" + _importCustomerOrgId.ToString()
  135. , Guid.Empty, "get");
  136. customerOrgGroupDto = _customerOrgGroupDtos.Where(o => o.DisplayName == "复检").FirstOrDefault();
  137. if (customerOrgGroupDto == null)
  138. {
  139. throw new Exception("没有复检这个分组");
  140. }
  141. }
  142. else
  143. {
  144. List<string> groupNames = new List<string>();
  145. if (patient.ifGy == 1)
  146. {
  147. groupNames.Add("高原");
  148. }
  149. else if (patient.ifJk == 1)
  150. {
  151. groupNames.Add("健康");
  152. }
  153. else
  154. {
  155. throw new Exception("分组名称必须是高原或健康体检二选一");
  156. }
  157. if (patient.ifGt == 1)
  158. {
  159. groupNames.Add("高铁");
  160. }
  161. if (patient.ifWh == 1)
  162. {
  163. groupNames.Add("职害");
  164. }
  165. if (patient.ifCw == 1)
  166. {
  167. groupNames.Add("普速");
  168. }
  169. if (patient.ifMain == 1)
  170. {
  171. groupNames.Add("行车");
  172. }
  173. if (patient.ifCy == 1)
  174. {
  175. groupNames.Add("从业");
  176. }
  177. customerOrgGroupDto = await GetCustomerOrgGroup(groupNames, sexId, maritalStatusId);
  178. }
  179. //获取病人ID
  180. var patientRegister = new CreatePatientRegisterDto()
  181. {
  182. MedicalCenterId = _customerOrgDto.MedicalCenterId,
  183. //PatientRegisterId = null,
  184. //PatientId = null,
  185. IsMaxMedicalTimes = 'Y',
  186. CompleteFlag = '0',
  187. CustomerOrgId = customerOrgDto.Id,
  188. CustomerOrgRegisterId = _customerOrgRegisterDto.Id,
  189. CustomerOrgGroupId = customerOrgGroupDto.Id,
  190. PatientName = patient.personName,
  191. SexId = sexId,
  192. Age = patient.age,
  193. MaritalStatusId = maritalStatusId,
  194. MobileTelephone = patient.mobile,
  195. Planuserid = patient.id.ToString(),
  196. IdNo = patient.cardId,
  197. //PersonnelTypeId = personnelType.Id,
  198. JobTitle = jobTitle,
  199. Remark = patient.remark,
  200. JobPost = jobPost,
  201. Remark2 = patient.tjOpinion,
  202. Remark3 = patient.fjOpinion,
  203. QztlIsFj = patient.ifFj == 1 ? 'Y' : 'N',
  204. QztlIsGt = patient.ifGt == 1 ? 'Y' : 'N',
  205. QztlIsWh = patient.ifWh == 1 ? 'Y' : 'N',
  206. QztlIsCw = patient.ifCw == 1 ? 'Y' : 'N',
  207. QztlIsMain = patient.ifMain == 1 ? 'Y' : 'N',
  208. QztlIsCy = patient.ifCy == 1 ? 'Y' : 'N',
  209. IsQztlImport = 'Y'
  210. };
  211. if (!string.IsNullOrWhiteSpace(patient.cardId))
  212. {
  213. var patientInfo = await CallAppServiceAsync<IdNoInputDto, PatientDto>(
  214. "api/app/patient/GetByIdNo",
  215. new IdNoInputDto()
  216. {
  217. IdNo = patient.cardId
  218. });
  219. if (patientInfo != null)
  220. {
  221. patientRegister.PatientId = patientInfo.Id;
  222. }
  223. }
  224. if (medicalTypeDto != null)
  225. {
  226. patientRegister.MedicalTypeId = medicalTypeDto.Id;
  227. }
  228. if (personnelType != null)
  229. {
  230. patientRegister.PersonnelTypeId = personnelType.Id;
  231. }
  232. if (patient.ifGy == 1)
  233. {
  234. patientRegister.QztlType = '0';
  235. }
  236. else if (patient.ifJk == 1) { }
  237. {
  238. patientRegister.QztlType = '1';
  239. }
  240. patientRegister.RegisterCheckAsbitems = new List<CreatePatientRegisterRegisterCheckAsbitem>();
  241. //获取分组信息
  242. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  243. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroupDto.Id.ToString()
  244. , Guid.Empty, "get");
  245. if (!customerOrgGroupDetailOrAsbitemDtos.Any())
  246. {
  247. throw new Exception("分组未包含项目");
  248. }
  249. foreach (var asbitem in customerOrgGroupDetailOrAsbitemDtos)
  250. {
  251. patientRegister.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
  252. {
  253. AsbitemId = asbitem.AsbitemId,
  254. StandardPrice = asbitem.Price,
  255. ChargePrice = asbitem.CustomerOrgGroupDetailPrice,
  256. PayTypeFlag = '1',
  257. IsCharge = 'N',
  258. Amount = asbitem.CustomerOrgGroupDetailAmount
  259. });
  260. }
  261. await CallAppServiceAsync<CreatePatientRegisterDto, object>(
  262. "api/PatientRegister/CreatePatientRegister",
  263. patientRegister);
  264. var succesIds = new List<string>();
  265. var deleteIds = new List<string>();
  266. succesIds.Add(patientRegister.Planuserid);
  267. await AnswerOk(succesIds, deleteIds);
  268. }
  269. catch (Exception ex)
  270. {
  271. if (ex.Message.Contains("人员信息姓名和性别和原来的信息都不一致") ||
  272. ex.Message.Contains("身份证号解析出的性别与填入的性别不一致"))
  273. {
  274. continue;
  275. }
  276. else
  277. {
  278. throw ex;
  279. }
  280. }
  281. }
  282. }
  283. public async Task InitAsync()
  284. {
  285. var customerOrgIdStr = InterfaceConfig.GetSection("Interface").GetSection("单位编号").Value;
  286. _hospitalId = InterfaceConfig.GetSection("Interface").GetSection("HospitalId").Value;
  287. _aesKEY = InterfaceConfig.GetSection("Interface").GetSection("aesKEY").Value;
  288. _answerWebApiUrl = InterfaceConfig.GetSection("Interface").GetSection("AnswerWebApiUrl").Value;
  289. if (string.IsNullOrWhiteSpace(customerOrgIdStr))
  290. {
  291. return;
  292. }
  293. if (!Guid.TryParse(customerOrgIdStr, out _importCustomerOrgId))
  294. {
  295. throw new Exception("单位编号不正确");
  296. }
  297. if (string.IsNullOrWhiteSpace(_hospitalId))
  298. {
  299. throw new Exception("HospitalId参数不能为空");
  300. }
  301. if (string.IsNullOrWhiteSpace(_aesKEY))
  302. {
  303. throw new Exception("_aesKEY参数不能为空");
  304. }
  305. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  306. {
  307. string sql;
  308. sql = @"
  309. SELECT id as customer_org_id,
  310. display_name as customer_org_name,
  311. parent_id ,
  312. path_code
  313. from
  314. customer_org
  315. where id = @CustomerOrgId
  316. ";
  317. var customerOrgForPlugInss = (await conn.QueryAsync<CustomerOrgForPlugIns>(sql,
  318. new { CustomerOrgId = _importCustomerOrgId })).FirstOrDefault();
  319. if (customerOrgForPlugInss == null)
  320. {
  321. throw new Exception("单位编号不正确,找不到单位");
  322. }
  323. var year = customerOrgForPlugInss.CustomerOrgName.Substring(
  324. customerOrgForPlugInss.CustomerOrgName.Length - 5
  325. , 4);
  326. if (!int.TryParse(year, out var yearNumber))
  327. {
  328. throw new Exception("单位名称必须是以2000年这样的格式结尾");
  329. }
  330. if (yearNumber < 2024 || yearNumber > 2050)
  331. {
  332. throw new Exception("单位名称年限范围必须在2024-2050之间");
  333. }
  334. _year = year;
  335. }
  336. //加载单位信息
  337. _customerOrgDto = await CallAppServiceAsync<CustomerOrgIdInputDto, CustomerOrgDto>(
  338. "api/app/CustomerOrg/GetById", new CustomerOrgIdInputDto()
  339. {
  340. CustomerOrgId = _importCustomerOrgId,
  341. });
  342. //加载单位登记信息
  343. _customerOrgRegisterDto = await CallAppServiceAsync<CustomerOrgIdInputDto, CustomerOrgRegisterDto>(
  344. "api/app/CustomerOrgRegister/GetLastCustomerOrgRegisterByCustomerOrgId", new CustomerOrgIdInputDto()
  345. {
  346. CustomerOrgId = _importCustomerOrgId,
  347. });
  348. //加载人员类别列表
  349. _personnelTypes = await CallAppServiceAsync<string, List<PersonnelTypeDto>>("api/app/PersonnelType/GetAll", "");
  350. }
  351. //public
  352. public async Task<QztlPatientRegisterFromInterface?> CallInterfaceServiceAsync()
  353. {
  354. string baseAddress = InterfaceWebApiUrl;
  355. string ary = "HospitalId=" + _hospitalId + (char)38 + "year=" + _year + (char)38 + "AesKey=" + _aesKEY;
  356. baseAddress = baseAddress + ary;
  357. using (var httpClientHandler = new HttpClientHandler())
  358. {
  359. using (var httpClient = new HttpClient(httpClientHandler))
  360. {
  361. httpClient.BaseAddress = new Uri(baseAddress);
  362. httpClient.DefaultRequestHeaders.Accept.Add(
  363. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  364. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  365. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  366. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  367. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  368. using (HttpContent httpContent = new StringContent(""))
  369. {
  370. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  371. HttpResponseMessage response = await httpClient.GetAsync("");
  372. string result;
  373. if (!response.IsSuccessStatusCode)
  374. {
  375. result = response.Content.ReadAsStringAsync().Result;
  376. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  377. }
  378. result = await response.Content.ReadAsStringAsync();
  379. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  380. if (result.IndexOf("status") < 0)
  381. {
  382. throw new Exception($"调用WebApi中无status,返回值:" + result);
  383. }
  384. QztlPatientRegisterFromInterface? resultDto = JsonConvert.DeserializeObject<QztlPatientRegisterFromInterface>(result);
  385. if (resultDto != null)
  386. {
  387. if (resultDto.status != 0)
  388. {
  389. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  390. }
  391. //插入数据库中备份
  392. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  393. {
  394. string sql;
  395. var qztlImportDataEntity = new QztlImportDataEntity()
  396. {
  397. Id = Guid.NewGuid(),
  398. Data = result,
  399. DataType = '0',
  400. IsComplete = 'Y',
  401. CreationTime = DateTime.Now,
  402. };
  403. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  404. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  405. conn.Execute(sql, qztlImportDataEntity);
  406. }
  407. return resultDto;
  408. }
  409. return null;
  410. }
  411. }
  412. }
  413. }
  414. public char ConvertMaritalStatus(int maritalStatus)
  415. {
  416. switch (maritalStatus)
  417. {
  418. case 1:
  419. return '0';
  420. case 2:
  421. return '1';
  422. case 3:
  423. return '4';
  424. default:
  425. return '9';
  426. }
  427. }
  428. public char ConvertSex(int sex)
  429. {
  430. switch (sex)
  431. {
  432. case 1:
  433. return 'M';
  434. case 2:
  435. return 'F';
  436. default:
  437. return 'U';
  438. }
  439. }
  440. public string ConvertJobPost(string jobPost)
  441. {
  442. if (string.IsNullOrWhiteSpace(jobPost))
  443. {
  444. return "";
  445. }
  446. switch (jobPost)
  447. {
  448. case "0":
  449. return "普通成员";
  450. case "1":
  451. return "班子成员";
  452. default:
  453. return "";
  454. }
  455. }
  456. public string ConvertJobTitle(string jobTitle)
  457. {
  458. if (string.IsNullOrWhiteSpace(jobTitle))
  459. {
  460. return "无";
  461. }
  462. switch (jobTitle)
  463. {
  464. case "0":
  465. return "无";
  466. case "1":
  467. return "科员";
  468. case "2":
  469. return "副科";
  470. case "3":
  471. return "正科";
  472. case "4":
  473. return "副处";
  474. case "5":
  475. return "正处";
  476. case "6":
  477. return "副局";
  478. case "7":
  479. return "正局";
  480. default:
  481. return "无";
  482. }
  483. }
  484. public PersonnelTypeDto ConvertPersonnelType(int personnelType)
  485. {
  486. string personnelTypeName;
  487. switch (personnelType)
  488. {
  489. case 1:
  490. personnelTypeName = "岗前";
  491. break;
  492. case 2:
  493. personnelTypeName = "岗中";
  494. break;
  495. case 3:
  496. personnelTypeName = "岗后";
  497. break;
  498. default:
  499. personnelTypeName = "";
  500. break;
  501. }
  502. if (string.IsNullOrWhiteSpace(personnelTypeName))
  503. {
  504. return null;
  505. }
  506. var personnelTypeDto = _personnelTypes.Where(o => o.DisplayName == personnelTypeName).FirstOrDefault();
  507. return personnelTypeDto;
  508. }
  509. public async Task<CustomerOrgGroupDto> GetCustomerOrgGroup(List<string> goupNames, char sexId, char maritalStatusId)
  510. {
  511. string sexName = "";
  512. if (sexId == 'M')
  513. {
  514. sexName = "男";
  515. }
  516. else if (sexId == 'F')
  517. {
  518. sexName = "女";
  519. }
  520. string groupName = "";
  521. for (var i = 0; i < goupNames.Count; i++)
  522. {
  523. if (i == 0)
  524. {
  525. groupName = goupNames[i];
  526. }
  527. else
  528. {
  529. groupName += goupNames[i];
  530. }
  531. }
  532. string maritalStatusName;
  533. if (maritalStatusId == '0')
  534. {
  535. maritalStatusName = "未婚";
  536. }
  537. else
  538. {
  539. maritalStatusName = "已婚";
  540. }
  541. if (sexName == "女")
  542. {
  543. groupName += maritalStatusName + sexName;
  544. }
  545. else
  546. {
  547. groupName += sexName;
  548. }
  549. _customerOrgGroupDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDto>>(
  550. "api/app/customer-org-group/in-customer-org-id/" + _importCustomerOrgId.ToString()
  551. , Guid.Empty, "get");
  552. var customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == groupName).FirstOrDefault();
  553. if (customerOrgGroup != null)
  554. {
  555. return customerOrgGroup;
  556. }
  557. //-------------自动创建分组
  558. //检测有没有单个分组
  559. string existGroupName = "";
  560. var createCustomerOrgGroupWithDetailDto = new CreateCustomerOrgGroupWithDetailDto()
  561. {
  562. IsMaxMedicalTimes = 'Y',
  563. CustomerOrgId = _importCustomerOrgId,
  564. DisplayName = groupName,
  565. ForSexId = sexId,
  566. AgeLowerLimit = 0,
  567. AgeUpperLimit = 200,
  568. MaritalStatusId = 'A'
  569. };
  570. for (var i = 0; i < goupNames.Count; i++)
  571. {
  572. if (i == 0)
  573. {
  574. if (sexName == "女")
  575. {
  576. existGroupName = goupNames[i] + maritalStatusName + sexName;
  577. }
  578. else
  579. {
  580. existGroupName = goupNames[i] + maritalStatusName + sexName;
  581. }
  582. }
  583. else
  584. {
  585. existGroupName = goupNames[i];
  586. }
  587. _customerOrgGroupDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDto>>(
  588. "api/app/customerorgregister/getlistincustomerorgid?CustomerOrgId=" + _importCustomerOrgId.ToString()
  589. , Guid.Empty, "get");
  590. customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == existGroupName).FirstOrDefault();
  591. if (customerOrgGroup == null)
  592. {
  593. throw new Exception($"分组名{existGroupName}不存在");
  594. }
  595. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  596. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroup.Id.ToString()
  597. , Guid.Empty, "get");
  598. foreach (var customerOrgGroupDetailOrAsbitemDto in customerOrgGroupDetailOrAsbitemDtos)
  599. {
  600. if (!createCustomerOrgGroupWithDetailDto.Details.
  601. Where(o => o.AsbitemId == customerOrgGroupDetailOrAsbitemDto.AsbitemId).ToList().Any())
  602. {
  603. createCustomerOrgGroupWithDetailDto.Details.Add(new CreateCustomerOrgGroupDetail_Detail()
  604. {
  605. AsbitemId = customerOrgGroupDetailOrAsbitemDto.AsbitemId,
  606. Amount = customerOrgGroupDetailOrAsbitemDto.CustomerOrgGroupDetailAmount,
  607. Price = customerOrgGroupDetailOrAsbitemDto.Price,
  608. });
  609. }
  610. }
  611. }
  612. customerOrgGroup = await CallAppServiceAsync<CreateCustomerOrgGroupWithDetailDto, CustomerOrgGroupDto>(
  613. "api/app/CustomerOrgGroup/CreateCustomerOrgGroupWithDetail", createCustomerOrgGroupWithDetailDto);
  614. return customerOrgGroup;
  615. }
  616. public async Task AnswerOk(List<string> successIds, List<string> deleteIds)
  617. {
  618. if (successIds == null || deleteIds == null)
  619. {
  620. return;
  621. }
  622. if (successIds.Count == 0 && deleteIds.Count == 0)
  623. {
  624. return;
  625. }
  626. string successIdStr = "";
  627. for (var i = 0; i < successIds.Count; i++)
  628. {
  629. if (i == 0)
  630. {
  631. successIdStr = successIds[i];
  632. }
  633. else
  634. {
  635. successIdStr += "," + successIds[i];
  636. }
  637. }
  638. string deleteIdStr = "";
  639. for (var i = 0; i < deleteIds.Count; i++)
  640. {
  641. if (i == 0)
  642. {
  643. deleteIdStr = deleteIds[i];
  644. }
  645. else
  646. {
  647. deleteIdStr += "," + deleteIds[i];
  648. }
  649. }
  650. string baseAddress = _answerWebApiUrl;// "http://62.156.10.237:8005/health/values/SetPlanOK?";
  651. string ary = "HospitalId=" + _hospitalId + (char)38 +
  652. "ids=" + successIdStr + (char)38 + "delids=" + deleteIdStr + (char)38 + "AesKey=" + _aesKEY;
  653. baseAddress = baseAddress + ary;
  654. using (var httpClientHandler = new HttpClientHandler())
  655. {
  656. using (var httpClient = new HttpClient(httpClientHandler))
  657. {
  658. httpClient.BaseAddress = new Uri(baseAddress);
  659. httpClient.DefaultRequestHeaders.Accept.Add(
  660. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  661. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  662. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  663. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  664. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  665. using (HttpContent httpContent = new StringContent(""))
  666. {
  667. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  668. HttpResponseMessage response = await httpClient.GetAsync("");
  669. string result;
  670. if (!response.IsSuccessStatusCode)
  671. {
  672. result = response.Content.ReadAsStringAsync().Result;
  673. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  674. }
  675. result = await response.Content.ReadAsStringAsync();
  676. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  677. if (result.IndexOf("更新ok") >= 0 || result.IndexOf("更新OK") >= 0 || result.IndexOf("更新Ok") >= 0)
  678. {
  679. return;
  680. }
  681. dynamic? resultDto = JsonConvert.DeserializeObject(result);
  682. if (resultDto != null)
  683. {
  684. if (resultDto.status != 0)
  685. {
  686. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  687. }
  688. //插入数据库中备份
  689. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  690. {
  691. string sql;
  692. var qztlImportDataEntity = new QztlImportDataEntity()
  693. {
  694. Id = Guid.NewGuid(),
  695. Data = result,
  696. DataType = '0',
  697. IsComplete = 'Y',
  698. CreationTime = DateTime.Now,
  699. };
  700. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  701. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  702. conn.Execute(sql, qztlImportDataEntity);
  703. }
  704. return;
  705. }
  706. return;
  707. }
  708. }
  709. }
  710. }
  711. }
  712. }