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.

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