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.

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