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.

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