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.

760 lines
33 KiB

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