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.

779 lines
33 KiB

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