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.

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