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.

913 lines
40 KiB

using Dapper;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Npgsql;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Shentun.Peis.PatientRegisters;
using Shentun.Peis.PersonnelTypes;
using Shentun.Peis.MedicalTypes;
using Shentun.Peis.CustomerOrgs;
using Shentun.Peis.CustomerOrgGroups;
using Shentun.Peis.CustomerReports;
using Shentun.Peis.CustomerOrgGroupDetails;
using Shentun.Peis.CustomerOrgRegisters;
using Shentun.Peis.Enums;
using Shentun.Peis.Patients;
using Shentun.Peis.PlugIns.PatientRegisters;
using Shentun.Peis.PlugIns.ImportPacsResults;
namespace Shentun.Peis.PlugIns.Extensions.PatientRegisters.Qztl
{
public class ImportPatientRegisterPlugInsQztl : ImportPatientRegisterPlugInsBase
{
private string _hospitalId;
private string _aesKEY;
private string _year;
private CustomerOrgDto _customerOrgDto;
private CustomerOrgRegisterDto _customerOrgRegisterDto;
private List<PersonnelTypeDto> _personnelTypes;
private List<CustomerOrgGroupDto> _customerOrgGroupDtos;
private string _answerWebApiUrl;
public ImportPatientRegisterPlugInsQztl(Guid thirdInterfaceId) : base(thirdInterfaceId)
{
}
public ImportPatientRegisterPlugInsQztl(string parmValue) : base(parmValue)
{
}
public override async Task<ImportPatientRegisterByCustomerOrgRegisterIdDto> ImportPatientRegisterByCustomerOrgRegisterIdAsync(Guid customerOrgRegisterId)
{
CustomerOrgRegisterId = customerOrgRegisterId;
if(CustomerOrgRegisterId == Guid.Empty)
{
throw new Exception("customerOrgRegisterId参数不能为空");
}
await LoginAsync();
await InitAsync();
var errorList = new List<string>();
var qztlPatientRegisterFromInterface = await CallInterfaceServiceAsync();
var returnDto = new ImportPatientRegisterByCustomerOrgRegisterIdDto();
if (qztlPatientRegisterFromInterface == null)
{
return returnDto;
}
//删除人员
if (qztlPatientRegisterFromInterface.delIds != null)
{
foreach (var deleteUserId in qztlPatientRegisterFromInterface.delIds)
{
var error = deleteUserId;
try
{
var patientRegister = await GetPatientRegisterByPlanUserId(deleteUserId);
if (patientRegister == null)
{
continue;
}
if (patientRegister.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration &&
patientRegister.CompleteFlag != PatientRegisterCompleteFlag.Registration)
{
//已检人员不允许删除
returnDto.DeleteErrorNum++;
returnDto.DeleteErrorMessages.Add($"姓名:{patientRegister.PatientName},身份证号:{patientRegister.IdNo},已检不能删除");
continue;
}
var patientRegisterInputDto = new PatientRegisterIdInputDto()
{
PatientRegisterId = patientRegister.PatientRegisterId
};
await CallAppServiceAsync<PatientRegisterIdInputDto, object>(
"api/app/PatientRegister/DeleteById", patientRegisterInputDto);
//发送答复通知
var succesIds = new List<string>();
var deleteIds = new List<string>();
deleteIds.Add(deleteUserId);
await AnswerOk(succesIds, deleteIds);
returnDto.DeleteSuccessNum++;
}
catch (Exception ex)
{
returnDto.DeleteErrorNum++;
returnDto.DeleteErrorMessages.Add(error + ex.Message);
continue;
}
}
}
if (qztlPatientRegisterFromInterface.plans == null)
{
return returnDto;
}
//设置导入人员信息
foreach (var patient in qztlPatientRegisterFromInterface.plans)
{
var error = $"姓名:{patient.personName},身份证:{patient.cardId}";
try
{
//婚姻状况
var maritalStatusId = ConvertMaritalStatus(patient.wedding);
//人员类别
var personnelType = ConvertPersonnelType(patient.tjJieduan);
//性别
var sexId = ConvertSex(patient.sex);
//体检类别
var medicalTypeName = patient.tjpcV;
MedicalTypeDto medicalTypeDto = null;
if (!string.IsNullOrWhiteSpace(medicalTypeName))
{
medicalTypeDto = await CallAppServiceAsync<DisplayNameInputDto, MedicalTypeDto>(
"api/app/MedicalType/GetByDisplayName", new DisplayNameInputDto() { DisplayName = medicalTypeName });
if (medicalTypeDto == null)
{
var createMedicalTypeDto = new CreateMedicalTypeDto()
{
DisplayName = medicalTypeName,
};
medicalTypeDto = await CallAppServiceAsync<CreateMedicalTypeDto, MedicalTypeDto>(
"api/app/medical-type", new CreateMedicalTypeDto() { DisplayName = medicalTypeName });
}
}
//职称
var jobTitle = ConvertJobTitle(patient.gradeZwV);
//职务
var jobPost = ConvertJobPost(patient.tjTab1);
string workTypeV = patient.workTypeV;
if (string.IsNullOrWhiteSpace(workTypeV))
{
workTypeV = "";
}
else
{
workTypeV = "," + workTypeV;
}
jobPost = jobPost + workTypeV;
if (!string.IsNullOrWhiteSpace(jobPost) && jobPost.Length >= 10)
{
jobPost = jobPost.Substring(0, 10);//只能存储10个汉字
}
//查找子单位是否存在,如存在获取子单位id,如果不存在这创建子单位
var orgName = patient.orgName;
var pos = orgName.IndexOf("_");
orgName = orgName.Substring(0, pos);
if (string.IsNullOrWhiteSpace(patient.mobile))
{
//青海省第五人民医院要强行设置为 11111111111
}
var customerOrgDtos = await CallAppServiceAsync<CustomerOrgIdInputDto, List<CustomerOrgDto>>(
"api/app/CustomerOrg/GetChildCustomerOrgsById",
new CustomerOrgIdInputDto() { CustomerOrgId = _customerOrgDto.Id });
CustomerOrgDto customerOrgDto = null;
if (customerOrgDtos != null && customerOrgDtos.Any())
{
customerOrgDto = customerOrgDtos.Where(o => o.DisplayName == orgName).FirstOrDefault();
}
if (customerOrgDto == null)
{
customerOrgDto = await CallAppServiceAsync<CreateCustomerOrgDto, CustomerOrgDto>(
"api/app/customerorg/create", new CreateCustomerOrgDto()
{
MedicalCenterId = _customerOrgDto.MedicalCenterId,
ParentId = _customerOrgDto.Id,
DisplayName = orgName,
ShortName = orgName,
IsActive = 'Y',
IsLock = 'Y'
});
}
CustomerOrgGroupDto customerOrgGroupDto;
if (patient.ifFj == 1)
{
//复检
//加载单位分组信息
_customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
"api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
, new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
customerOrgGroupDto = _customerOrgGroupDtos.Where(o => o.DisplayName == "复检").FirstOrDefault();
if (customerOrgGroupDto == null)
{
throw new Exception("没有复检这个分组");
}
}
else
{
List<string> groupNames = new List<string>();
if (patient.ifGy == 1)
{
groupNames.Add("高原");
}
else if (patient.ifJk == 1)
{
groupNames.Add("健康");
}
else
{
throw new Exception("分组名称必须是高原或健康体检二选一");
}
if (patient.ifGt == 1)
{
groupNames.Add("高铁");
}
if (patient.ifWh == 1)
{
groupNames.Add("职害");
}
if (patient.ifCw == 1)
{
groupNames.Add("普速");
}
if (patient.ifMain == 1)
{
groupNames.Add("行车");
}
if (patient.ifCy == 1)
{
groupNames.Add("从业");
}
customerOrgGroupDto = await GetCustomerOrgGroup(groupNames, sexId, maritalStatusId);
}
//没有planuserid的自动设置planuserid
var patientRegisters = await GetPatientRegisterByCustomerOrgRegisterIdWithIdNo(_customerOrgRegisterDto.Id, patient.cardId);
var succesIds = new List<string>();
var deleteIds = new List<string>();
succesIds.Add(patient.id.ToString());
bool IsNoPlanUserIdComplete = false;
foreach (var patintRegister in patientRegisters)
{
//没有planUserId的更新planUserId
if (string.IsNullOrWhiteSpace(patintRegister.Planuserid) && patintRegister.PatientName == patient.personName)
{
await UpdatePatientRegisterPlanUserId(patintRegister.PatientRegisterId, patient.id.ToString());
await AnswerOk(succesIds, deleteIds);
returnDto.ImportSuccessNum++;
IsNoPlanUserIdComplete = true;
continue;
}
//已经登记了该PlanUserId的不再登记
if (!string.IsNullOrWhiteSpace(patintRegister.Planuserid) && patintRegister.Planuserid == patient.id.ToString())
{
await AnswerOk(succesIds, deleteIds);
IsNoPlanUserIdComplete = true;
returnDto.ImportSuccessNum++;
}
}
if (IsNoPlanUserIdComplete)
{
continue;
}
//获取病人ID
var patientRegister = new CreatePatientRegisterDto()
{
MedicalCenterId = _customerOrgDto.MedicalCenterId,
//PatientRegisterId = null,
//PatientId = null,
IsMaxMedicalTimes = 'Y',
CompleteFlag = '0',
CustomerOrgId = customerOrgDto.Id,
CustomerOrgRegisterId = _customerOrgRegisterDto.Id,
CustomerOrgGroupId = customerOrgGroupDto.Id,
PatientName = patient.personName,
SexId = sexId,
Age = patient.age,
MaritalStatusId = maritalStatusId,
MobileTelephone = patient.mobile,
Planuserid = patient.id.ToString(),
IdNo = patient.cardId,
//PersonnelTypeId = personnelType.Id,
JobTitle = jobTitle,
Remark = patient.remark,
JobPost = jobPost,
Remark2 = patient.tjOpinion,
Remark3 = patient.fjOpinion,
QztlIsFj = patient.ifFj == 1 ? 'Y' : 'N',
QztlIsGt = patient.ifGt == 1 ? 'Y' : 'N',
QztlIsWh = patient.ifWh == 1 ? 'Y' : 'N',
QztlIsCw = patient.ifCw == 1 ? 'Y' : 'N',
QztlIsMain = patient.ifMain == 1 ? 'Y' : 'N',
QztlIsCy = patient.ifCy == 1 ? 'Y' : 'N',
IsQztlImport = 'Y',
IsAllowIdNoSexError = 'Y'
};
if (!string.IsNullOrWhiteSpace(patient.cardId))
{
var patientInfo = await CallAppServiceAsync<IdNoInputDto, PatientDto>(
"api/app/patient/GetByIdNo",
new IdNoInputDto()
{
IdNo = patient.cardId
});
if (patientInfo != null)
{
patientRegister.PatientId = patientInfo.Id;
}
}
if (medicalTypeDto != null)
{
patientRegister.MedicalTypeId = medicalTypeDto.Id;
}
if (personnelType != null)
{
patientRegister.PersonnelTypeId = personnelType.Id;
}
if (patient.ifGy == 1)
{
patientRegister.QztlType = '0';
}
else if (patient.ifJk == 1) { }
{
patientRegister.QztlType = '1';
}
patientRegister.RegisterCheckAsbitems = new List<CreatePatientRegisterRegisterCheckAsbitem>();
//获取分组信息
var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
"api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroupDto.Id.ToString()
, Guid.Empty, "get");
if (!customerOrgGroupDetailOrAsbitemDtos.Any() && customerOrgGroupDto.DisplayName!= "复检")
{
throw new Exception($"分组{customerOrgGroupDto.DisplayName}未包含项目");
}
foreach (var asbitem in customerOrgGroupDetailOrAsbitemDtos)
{
patientRegister.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = asbitem.AsbitemId,
StandardPrice = asbitem.Price,
ChargePrice = asbitem.CustomerOrgGroupDetailPrice,
PayTypeFlag = '1',
IsCharge = 'N',
Amount = asbitem.CustomerOrgGroupDetailAmount
});
}
await CallAppServiceAsync<CreatePatientRegisterDto, object>(
"api/PatientRegister/CreatePatientRegister",
patientRegister);
await AnswerOk(succesIds, deleteIds);
returnDto.ImportSuccessNum++;
}
catch (Exception ex)
{
returnDto.ImportErrorNum++;
returnDto.ImportErrorMessages.Add(error + ",错误信息:" + ex.Message);
continue;
//throw new Exception(error + ex.Message);
//if (ex.Message.Contains("人员信息姓名和性别和原来的信息都不一致") ||
// ex.Message.Contains("身份证号解析出的性别与填入的性别不一致"))
//{
// continue;
//}
//else
//{
// throw ex;
//}
}
}
return returnDto;
}
public async Task InitAsync()
{
if (CustomerOrgRegisterId == Guid.Empty)
{
throw new Exception("customerOrgRegisterId参数不能为空");
}
var customerOrgIdStr = InterfaceConfig.GetSection("Interface").GetSection("CustomerOrgId").Value;
_hospitalId = InterfaceConfig.GetSection("Interface").GetSection("HospitalId").Value;
_aesKEY = InterfaceConfig.GetSection("Interface").GetSection("aesKEY").Value;
_answerWebApiUrl = InterfaceConfig.GetSection("Interface").GetSection("AnswerWebApiUrl").Value;
if (string.IsNullOrWhiteSpace(customerOrgIdStr))
{
return;
}
if (string.IsNullOrWhiteSpace(_hospitalId))
{
throw new Exception("HospitalId参数不能为空");
}
if (string.IsNullOrWhiteSpace(_aesKEY))
{
throw new Exception("_aesKEY参数不能为空");
}
Guid customerOrgId;
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
sql = @"
SELECT customer_org.id as customer_org_id,
customer_org.display_name as customer_org_name,
customer_org.parent_id as parent_id,
customer_org.path_code as path_code
from customer_org ,customer_org_register
where customer_org.id = customer_org_register.customer_org_id and
customer_org_register.id = @CustomerOrgRegisterId
";
var customerOrgForPlugInss = (await conn.QueryAsync<CustomerOrgForPlugIns>(sql,
new { CustomerOrgRegisterId = CustomerOrgRegisterId })).FirstOrDefault();
if (customerOrgForPlugInss == null)
{
throw new Exception("单位登记次数不正确,找不到单位");
}
var year = customerOrgForPlugInss.CustomerOrgName.Substring(
customerOrgForPlugInss.CustomerOrgName.Length - 5
, 4);
if (!int.TryParse(year, out var yearNumber))
{
throw new Exception("单位名称必须是以2000年这样的格式结尾");
}
if (yearNumber < 2024 || yearNumber > 2050)
{
throw new Exception("单位名称年限范围必须在2024-2050之间");
}
_year = year;
customerOrgId = customerOrgForPlugInss.CustomerOrgId;
}
//加载单位信息
_customerOrgDto = await CallAppServiceAsync<CustomerOrgIdInputDto, CustomerOrgDto>(
"api/app/CustomerOrg/GetById", new CustomerOrgIdInputDto()
{
CustomerOrgId = customerOrgId,
});
//加载单位登记信息
_customerOrgRegisterDto = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, CustomerOrgRegisterDto>(
"api/app/CustomerOrgRegister/GetById", new CustomerOrgRegisterIdInputDto()
{
CustomerOrgRegisterId = CustomerOrgRegisterId,
});
//加载人员类别列表
_personnelTypes = await CallAppServiceAsync<string, List<PersonnelTypeDto>>("api/app/PersonnelType/GetAll", "");
}
public async Task<List<PatientRegisterQztl>> GetPatientRegisterByCustomerOrgRegisterIdWithIdNo(Guid customerOrgRegisterId, string idNo)
{
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
sql = @"
SELECT *
from patient_register,patient_register_exter,patient
where patient_register.id = patient_register_exter.patient_register_id and
patient_register.patient_id = patient.id and
customer_org_register_id =@CustomerOrgRegisterId and
patient.id_no =@IdNo
";
var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
new { CustomerOrgRegisterId = customerOrgRegisterId, IdNo = idNo })).ToList();
return patientRegisters;
}
}
public async Task<PatientRegisterQztl> GetPatientRegisterByPlanUserId(string planUserId)
{
if (string.IsNullOrWhiteSpace(planUserId))
{
throw new Exception("planUserId不能为空");
}
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
sql = @"
SELECT *
from patient_register,patient_register_exter
where patient_register.id = patient_register_exter.patient_register_id and
patient_register_exter.planuserid =@PlanUserId
";
var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
new { PlanUserId = planUserId })).FirstOrDefault();
return patientRegisters;
}
}
public async Task UpdatePatientRegisterPlanUserId(Guid patientRegisterId, string planUserid)
{
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
sql = @"
update patient_register_exter
set planuserid =@Planuserid
where patient_register_id=@PatientRegisterId
";
conn.Execute(sql, new { PatientRegisterId = patientRegisterId, Planuserid = planUserid });
return;
}
}
public async Task<QztlPatientRegisterFromInterface?> CallInterfaceServiceAsync()
{
string baseAddress = InterfaceWebApiUrl;
string ary = "HospitalId=" + _hospitalId + (char)38 + "year=" + _year + (char)38 + "AesKey=" + _aesKEY;
baseAddress = baseAddress + ary;
using (var httpClientHandler = new HttpClientHandler())
{
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.BaseAddress = new Uri(baseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
//httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
//var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
using (HttpContent httpContent = new StringContent(""))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
HttpResponseMessage response = await httpClient.GetAsync("");
string result;
if (!response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
}
result = await response.Content.ReadAsStringAsync();
result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
if (result.IndexOf("status") < 0)
{
throw new Exception($"调用WebApi中无status,返回值:" + result);
}
QztlPatientRegisterFromInterface? resultDto = JsonConvert.DeserializeObject<QztlPatientRegisterFromInterface>(result);
if (resultDto != null)
{
if (resultDto.status != 0)
{
throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
}
//插入数据库中备份
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
var qztlImportDataEntity = new QztlImportDataEntity()
{
Id = Guid.NewGuid(),
Data = result,
DataType = '0',
IsComplete = 'Y',
CreationTime = DateTime.Now,
};
sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
conn.Execute(sql, qztlImportDataEntity);
}
return resultDto;
}
return null;
}
}
}
}
public char ConvertMaritalStatus(int maritalStatus)
{
switch (maritalStatus)
{
case 1:
return '0';
case 2:
return '1';
case 3:
return '4';
default:
return '9';
}
}
public char ConvertSex(int sex)
{
switch (sex)
{
case 1:
return 'M';
case 2:
return 'F';
default:
return 'U';
}
}
public string ConvertJobPost(string jobPost)
{
if (string.IsNullOrWhiteSpace(jobPost))
{
return "";
}
switch (jobPost)
{
case "0":
return "普通成员";
case "1":
return "班子成员";
default:
return "";
}
}
public string ConvertJobTitle(string jobTitle)
{
if (string.IsNullOrWhiteSpace(jobTitle))
{
return "无";
}
switch (jobTitle)
{
case "0":
return "无";
case "1":
return "科员";
case "2":
return "副科";
case "3":
return "正科";
case "4":
return "副处";
case "5":
return "正处";
case "6":
return "副局";
case "7":
return "正局";
default:
return "无";
}
}
public PersonnelTypeDto ConvertPersonnelType(int personnelType)
{
string personnelTypeName;
switch (personnelType)
{
case 1:
personnelTypeName = "岗前";
break;
case 2:
personnelTypeName = "岗中";
break;
case 3:
personnelTypeName = "岗后";
break;
default:
personnelTypeName = "";
break;
}
if (string.IsNullOrWhiteSpace(personnelTypeName))
{
return null;
}
var personnelTypeDto = _personnelTypes.Where(o => o.DisplayName == personnelTypeName).FirstOrDefault();
return personnelTypeDto;
}
public async Task<CustomerOrgGroupDto> GetCustomerOrgGroup(List<string> goupNames, char sexId, char maritalStatusId)
{
string sexName = "";
if (sexId == 'M')
{
sexName = "男";
}
else if (sexId == 'F')
{
sexName = "女";
}
string groupName = "";
for (var i = 0; i < goupNames.Count; i++)
{
if (i == 0)
{
groupName = goupNames[i];
}
else
{
groupName += goupNames[i];
}
}
string maritalStatusName;
if (maritalStatusId == '0')
{
maritalStatusName = "未婚";
}
else
{
maritalStatusName = "已婚";
}
if (sexName == "女")
{
groupName += maritalStatusName + sexName;
}
else
{
groupName += sexName;
}
_customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
"api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
, new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
var customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == groupName).FirstOrDefault();
if (customerOrgGroup != null)
{
return customerOrgGroup;
}
//-------------自动创建分组
//检测有没有单个分组
string existGroupName = "";
var createCustomerOrgGroupWithDetailDto = new CreateCustomerOrgGroupWithDetailDto()
{
IsMaxMedicalTimes = 'Y',
CustomerOrgId = _customerOrgDto.Id,
DisplayName = groupName,
ForSexId = sexId,
AgeLowerLimit = 0,
AgeUpperLimit = 200,
MaritalStatusId = 'A'
};
for (var i = 0; i < goupNames.Count; i++)
{
if (i == 0)
{
if (sexName == "女")
{
existGroupName = goupNames[i] + maritalStatusName + sexName;
}
else
{
existGroupName = goupNames[i] + maritalStatusName + sexName;
}
}
else
{
existGroupName = goupNames[i];
}
_customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
"api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
, new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == existGroupName).FirstOrDefault();
if (customerOrgGroup == null)
{
throw new Exception($"分组名{existGroupName}不存在");
}
var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
"api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroup.Id.ToString()
, Guid.Empty, "get");
foreach (var customerOrgGroupDetailOrAsbitemDto in customerOrgGroupDetailOrAsbitemDtos)
{
if (!createCustomerOrgGroupWithDetailDto.Details.
Where(o => o.AsbitemId == customerOrgGroupDetailOrAsbitemDto.AsbitemId).ToList().Any())
{
createCustomerOrgGroupWithDetailDto.Details.Add(new CreateCustomerOrgGroupDetail_Detail()
{
AsbitemId = customerOrgGroupDetailOrAsbitemDto.AsbitemId,
Amount = customerOrgGroupDetailOrAsbitemDto.CustomerOrgGroupDetailAmount,
Price = customerOrgGroupDetailOrAsbitemDto.Price,
});
}
}
}
customerOrgGroup = await CallAppServiceAsync<CreateCustomerOrgGroupWithDetailDto, CustomerOrgGroupDto>(
"api/app/CustomerOrgGroup/CreateCustomerOrgGroupWithDetail", createCustomerOrgGroupWithDetailDto);
return customerOrgGroup;
}
public async Task AnswerOk(List<string> successIds, List<string> deleteIds)
{
if (successIds == null || deleteIds == null)
{
return;
}
if (successIds.Count == 0 && deleteIds.Count == 0)
{
return;
}
string successIdStr = "";
for (var i = 0; i < successIds.Count; i++)
{
if (i == 0)
{
successIdStr = successIds[i];
}
else
{
successIdStr += "," + successIds[i];
}
}
string deleteIdStr = "";
for (var i = 0; i < deleteIds.Count; i++)
{
if (i == 0)
{
deleteIdStr = deleteIds[i];
}
else
{
deleteIdStr += "," + deleteIds[i];
}
}
string baseAddress = _answerWebApiUrl;// "http://62.156.10.237:8005/health/values/SetPlanOK?";
string ary = "HospitalId=" + _hospitalId + (char)38 +
"ids=" + successIdStr + (char)38 + "delids=" + deleteIdStr + (char)38 + "AesKey=" + _aesKEY;
baseAddress = baseAddress + ary;
using (var httpClientHandler = new HttpClientHandler())
{
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.BaseAddress = new Uri(baseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
//httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
//var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
using (HttpContent httpContent = new StringContent(""))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
HttpResponseMessage response = await httpClient.GetAsync("");
string result;
if (!response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
}
result = await response.Content.ReadAsStringAsync();
result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
if (result.IndexOf("更新ok") >= 0 || result.IndexOf("更新OK") >= 0 || result.IndexOf("更新Ok") >= 0)
{
return;
}
dynamic? resultDto = JsonConvert.DeserializeObject(result);
if (resultDto != null)
{
if (resultDto.status != 0)
{
throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
}
//插入数据库中备份
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
var qztlImportDataEntity = new QztlImportDataEntity()
{
Id = Guid.NewGuid(),
Data = result,
DataType = '0',
IsComplete = 'Y',
CreationTime = DateTime.Now,
};
sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
conn.Execute(sql, qztlImportDataEntity);
}
return;
}
return;
}
}
}
}
}
}