diff --git a/src/Shentun.Peis.Application.Contracts/DataMigrations/CreateFieldComparisonDto.cs b/src/Shentun.Peis.Application.Contracts/DataMigrations/CreateFieldComparisonDto.cs new file mode 100644 index 0000000..3526456 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/DataMigrations/CreateFieldComparisonDto.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Shentun.Peis.DataMigrations +{ + public class CreateFieldComparisonDto + { + /// + /// 表名 新系统表名 + /// + public string TableName { get; set; } + + + /// + /// 老系统主键值 + /// + public string OldKeyValue { get; set; } + + + /// + /// 新系统主键值 + /// + public string NewKeyValue { get; set; } + } +} diff --git a/src/Shentun.Peis.Application/DataMigrations/BaseDataHandleAppService.cs b/src/Shentun.Peis.Application/DataMigrations/BaseDataHandleAppService.cs index c4d2e2e..da7dbd4 100644 --- a/src/Shentun.Peis.Application/DataMigrations/BaseDataHandleAppService.cs +++ b/src/Shentun.Peis.Application/DataMigrations/BaseDataHandleAppService.cs @@ -1,9 +1,12 @@ using log4net.Plugin; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.Options; using NPOI.DDF; +using Shentun.Peis.CustomerOrgs; using Shentun.Peis.Enums; using Shentun.Peis.ItemTypes; using Shentun.Peis.Models; @@ -32,8 +35,8 @@ namespace Shentun.Peis.DataMigrations /// /// 基础数据处理 /// - [Authorize] - [RemoteService(false)] + //[Authorize] + //[RemoteService(false)] public class BaseDataHandleAppService : ApplicationService { @@ -53,9 +56,11 @@ namespace Shentun.Peis.DataMigrations //默认指引类别ID - private readonly char defaultGuidTypeId = '0'; + private readonly Guid defaultGuidTypeId = Guid.Parse("3a120284-df18-7b36-4b12-0423a7d5c1c6"); //默认体检报告类别ID - private readonly char defaultMedicalReportTypeId = '0'; + private readonly Guid defaultMedicalReportTypeId = Guid.Parse("3a120285-65dd-e7da-c923-6b503ab9e1d9"); + //默认体检中心 + private readonly Guid defaultMedicalCenterId = Guid.Parse("0de5b78a-731d-4f80-b262-655ebbf04581"); private readonly IRepository _deviceTypeRepository; @@ -79,6 +84,9 @@ namespace Shentun.Peis.DataMigrations private readonly IRepository _ItemResultMatchRepository; private readonly MyUserAppService _myUserAppService; private readonly IRepository _menuInfoRepository; + private readonly IRepository _customerOrgRepository; + private readonly CustomerOrgManager _customerOrgManager; + private readonly IRepository _customerOrgRegisterRepository; public BaseDataHandleAppService( IRepository deviceTypeRepository, @@ -101,7 +109,10 @@ namespace Shentun.Peis.DataMigrations IRepository diagnosisRepository, IRepository suggestionRepository, MyUserAppService myUserAppService, - IRepository menuInfoRepository) + IRepository menuInfoRepository, + IRepository customerOrgRepository, + CustomerOrgManager customerOrgManager, + IRepository customerOrgRegisterRepository) { _deviceTypeRepository = deviceTypeRepository; _itemTypeRepository = itemTypeRepository; @@ -124,12 +135,38 @@ namespace Shentun.Peis.DataMigrations _suggestionRepository = suggestionRepository; _myUserAppService = myUserAppService; _menuInfoRepository = menuInfoRepository; + _customerOrgRepository = customerOrgRepository; + _customerOrgManager = customerOrgManager; + _customerOrgRegisterRepository = customerOrgRegisterRepository; } + + + /// + /// 手动添加字段对照 + /// + /// + /// + [HttpPost] + public async Task CreateFieldComparisonAsync(CreateFieldComparisonDto input) + { + FieldComparison fieldComparison = new FieldComparison + { + FieldName = "id", + NewKeyValue = input.NewKeyValue, + OldKeyValue = input.OldKeyValue, + TableName = input.TableName + }; + + await _fieldComparisonRepository.InsertAsync(fieldComparison); + } + + /// /// 迁移仪器类别数据 /// /// + [RemoteService(false)] public async Task TransferDeviceTypeData() { var count = await _deviceTypeRepository.GetCountAsync(); @@ -172,6 +209,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移数值单位数据 /// /// + [RemoteService(false)] public async Task TransferUnitData() { var count = await _unitRepository.GetCountAsync(); @@ -213,6 +251,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移体检类别数据 /// /// + [RemoteService(false)] public async Task TransferMedicalTypeData() { var count = await _medicalTypeRepository.GetCountAsync(); @@ -254,6 +293,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移人员类别数据 /// /// + [RemoteService(false)] public async Task TransferPersonnelTypeData() { var count = await _personnelTypeRepository.GetCountAsync(); @@ -296,6 +336,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移发票项目类别数据 /// /// + [RemoteService(false)] public async Task TransferInvoiceItemTypeData() { var count = await _invoiceItemTypeRepository.GetCountAsync(); @@ -336,6 +377,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移项目类别-科室数据 /// /// + [RemoteService(false)] public async Task TransferItemTypeData() { var count = await _itemTypeRepository.GetCountAsync(); @@ -386,6 +428,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移标本类型数据 /// /// + [RemoteService(false)] public async Task TransferSampleTypeData() { var count = await _sampleTypeRepository.GetCountAsync(); @@ -426,6 +469,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移项目数据 /// /// + [RemoteService(false)] public async Task TransferItemData() { var count = await _itemRepository.GetCountAsync(); @@ -563,6 +607,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移组合项目数据 /// /// + [RemoteService(false)] public async Task TransferAsbitemData() { var count = await _asbitemRepository.GetCountAsync(); @@ -672,6 +717,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移组合项目明细数据 /// /// + [RemoteService(false)] public async Task TransferAsbitemDetailData() { var count = await _asbitemDetailRepository.GetCountAsync(); @@ -748,6 +794,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移体检套餐数据 /// /// + [RemoteService(false)] public async Task TransferMedicalPackageData() { var count = await _medicalPackageRepository.GetCountAsync(); @@ -799,6 +846,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移体检套餐明细数据 /// /// + [RemoteService(false)] public async Task TransferMedicalPackageDetailData() { var count = await _medicalPackageDetailRepository.GetCountAsync(); @@ -843,6 +891,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移诊断设置数据 /// /// + [RemoteService(false)] public async Task TransferDiagnosisData() { var count = await _diagnosisRepository.GetCountAsync(); @@ -942,6 +991,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移诊断建议数据 /// /// + [RemoteService(false)] public async Task TransferSuggestionData() { var count = await _suggestionRepository.GetCountAsync(); @@ -990,6 +1040,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移项目结果模板数据 /// /// + [RemoteService(false)] public async Task TransferItemResultTemplateData() { var count = await _itemResultTemplateRepository.GetCountAsync(); @@ -1052,6 +1103,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移项目结果匹配数据 /// /// + [RemoteService(false)] public async Task TransferItemResultMatchData() { var count = await _ItemResultMatchRepository.GetCountAsync(); @@ -1108,6 +1160,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移项目参考范围数据 /// /// + [RemoteService(false)] public async Task TransferReferenceRangeData() { var count = (await _referenceRangeRepository.GetQueryableAsync()).Where(m => m.ReferenceRangeTypeFlag != ItemReferenceRangeTypeFlag.Character).Count(); @@ -1168,6 +1221,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移后台用户数据 /// /// + [RemoteService(false)] public async Task TransferUserData() { @@ -1202,6 +1256,7 @@ namespace Shentun.Peis.DataMigrations /// 迁移菜单 /// /// + [RemoteService(false)] public async Task TransferMenuInfoData() { var oldMenuInfoList = await PgDb.Ado.GetDataTableAsync("select * from menu_info"); @@ -1239,6 +1294,292 @@ namespace Shentun.Peis.DataMigrations } + + /// + /// 迁移体检单位数据 一级 + /// + /// + public async Task TransferTopCustomerOrgData() + { + var count = await _customerOrgRepository.GetCountAsync(); + if (count == 0) + { + List dataList = new List(); + List fieldComparisons = new List(); + var oldCustomerOrgList = await Db.Ado.GetDataTableAsync("select * from org where len(org_id)=5 order by display_order asc"); + if (oldCustomerOrgList.Rows.Count > 0) + { + foreach (DataRow row in oldCustomerOrgList.Rows) + { + + Guid customerOrgId = GuidGenerator.Create(); + + var data = new CustomerOrg(customerOrgId) + { + Accounts = row["accounts"].ToString(), + Address = row["address"].ToString(), + Bank = row["bank"].ToString(), + DisplayName = row["org_name"].ToString(), + DisplayOrder = oldCustomerOrgList.Rows.IndexOf(row) + 1, + Fax = row["fax"].ToString(), + InvoiceName = row["org_name"].ToString(), + IsActive = 'Y', + IsLock = Convert.ToChar(row["lock_flag"].ToString()), + MedicalCenterId = defaultMedicalCenterId, + OrgTypeId = Guid.Parse("3a11fe4e-7dd3-b379-43b9-5be586097abe"), //默认为私营 + ParentId = null, + PathCode = (oldCustomerOrgList.Rows.IndexOf(row) + 1).ToString().PadLeft(5, '0'), + PostalCode = row["postalcode"].ToString(), + Remark = row["linkman"].ToString() + "|" + "telephone", + ShortName = row["short_name"].ToString(), + SimpleCode = LanguageConverter.GetPYSimpleCode(row["org_name"].ToString()), + Telephone = row["telephone"].ToString(), + }; + + dataList.Add(data); + + fieldComparisons.Add(new FieldComparison + { + FieldName = "id", + NewKeyValue = customerOrgId.ToString(), + OldKeyValue = row["org_id"].ToString(), + TableName = "customer_org" + }); + + } + + if (dataList.Any()) + await _customerOrgRepository.InsertManyAsync(dataList); + if (fieldComparisons.Any()) + await _fieldComparisonRepository.InsertManyAsync(fieldComparisons); + } + } + } + + + /// + /// 迁移体检单位数据 二级 + /// + /// + public async Task TransferTwoCustomerOrgData() + { + var count = (await _customerOrgRepository.GetQueryableAsync()).Where(m => m.PathCode.Length > 5).Count(); + if (count == 0) + { + List dataList = new List(); + List fieldComparisons = new List(); + var oldCustomerOrgList = await Db.Ado.GetDataTableAsync("select * from [dbo].[org] where len(org_id)=8 order by org_id asc"); + if (oldCustomerOrgList.Rows.Count > 0) + { + List customerOrgList = await _customerOrgRepository.GetListAsync(m => m.ParentId == null); + List fieldComparisonList = await _fieldComparisonRepository.GetListAsync(m => m.TableName == "customer_org"); + + foreach (DataRow row in oldCustomerOrgList.Rows) + { + #region 查找上级ID + string oldId = row["org_id"].ToString(); + string oldParentId = oldId.Substring(0, 5); + Guid parentId = Guid.Parse(fieldComparisonList.Where(m => m.OldKeyValue == oldParentId).FirstOrDefault().NewKeyValue); + #endregion + + + Guid customerOrgId = GuidGenerator.Create(); + + #region 备注 导入联系人姓名、电话 + string remark = ""; + if (!string.IsNullOrWhiteSpace(row["linkman"].ToString())) + { + remark = row["linkman"].ToString(); + } + if (!string.IsNullOrWhiteSpace(row["telephone"].ToString())) + { + if (!string.IsNullOrWhiteSpace(remark)) + { + remark += "|" + row["telephone"].ToString(); + } + else + { + remark = row["telephone"].ToString(); + } + } + #endregion + + var data = new CustomerOrg(customerOrgId) + { + Accounts = row["accounts"].ToString(), + Address = row["address"].ToString(), + Bank = row["bank"].ToString(), + DisplayName = row["org_name"].ToString(), + DisplayOrder = oldCustomerOrgList.Rows.IndexOf(row) + 1, + Fax = row["fax"].ToString(), + InvoiceName = row["org_name"].ToString(), + IsActive = 'Y', + IsLock = Convert.ToChar(row["lock_flag"].ToString()), + MedicalCenterId = defaultMedicalCenterId, + OrgTypeId = Guid.Parse("3a11fe4e-7dd3-b379-43b9-5be586097abe"), //默认为私营 + ParentId = parentId, + PathCode = _customerOrgManager.CreatePathCode(parentId).Result, + PostalCode = row["postalcode"].ToString(), + Remark = remark, + ShortName = row["short_name"].ToString(), + SimpleCode = LanguageConverter.GetPYSimpleCode(row["org_name"].ToString()), + Telephone = row["telephone"].ToString(), + }; + + await _customerOrgRepository.InsertAsync(data, true); + + fieldComparisons.Add(new FieldComparison + { + FieldName = "id", + NewKeyValue = customerOrgId.ToString(), + OldKeyValue = row["org_id"].ToString(), + TableName = "customer_org" + }); + + } + + + if (fieldComparisons.Any()) + await _fieldComparisonRepository.InsertManyAsync(fieldComparisons); + } + } + } + + /// + /// 迁移体检单位数据 三级 + /// + /// + public async Task TransferThreeCustomerOrgData() + { + var count = (await _customerOrgRepository.GetQueryableAsync()).Where(m => m.PathCode.Length > 11).Count(); + if (count == 0) + { + List dataList = new List(); + List fieldComparisons = new List(); + var oldCustomerOrgList = await Db.Ado.GetDataTableAsync("select * from [dbo].[org] where len(org_id)=11 order by org_id asc"); + if (oldCustomerOrgList.Rows.Count > 0) + { + List customerOrgList = await _customerOrgRepository.GetListAsync(m => m.ParentId == null); + List fieldComparisonList = await _fieldComparisonRepository.GetListAsync(m => m.TableName == "customer_org"); + + foreach (DataRow row in oldCustomerOrgList.Rows) + { + #region 查找上级ID + string oldId = row["org_id"].ToString(); + string oldParentId = oldId.Substring(0, 8); + Guid parentId = Guid.Parse(fieldComparisonList.Where(m => m.OldKeyValue == oldParentId).FirstOrDefault().NewKeyValue); + #endregion + + + Guid customerOrgId = GuidGenerator.Create(); + + #region 备注 导入联系人姓名、电话 + string remark = ""; + if (!string.IsNullOrWhiteSpace(row["linkman"].ToString())) + { + remark = row["linkman"].ToString(); + } + if (!string.IsNullOrWhiteSpace(row["telephone"].ToString())) + { + if (!string.IsNullOrWhiteSpace(remark)) + { + remark += "|" + row["telephone"].ToString(); + } + else + { + remark = row["telephone"].ToString(); + } + } + #endregion + + var data = new CustomerOrg(customerOrgId) + { + Accounts = row["accounts"].ToString(), + Address = row["address"].ToString(), + Bank = row["bank"].ToString(), + DisplayName = row["org_name"].ToString(), + DisplayOrder = oldCustomerOrgList.Rows.IndexOf(row) + 1, + Fax = row["fax"].ToString(), + InvoiceName = row["org_name"].ToString(), + IsActive = 'Y', + IsLock = Convert.ToChar(row["lock_flag"].ToString()), + MedicalCenterId = defaultMedicalCenterId, + OrgTypeId = Guid.Parse("3a11fe4e-7dd3-b379-43b9-5be586097abe"), //默认为私营 + ParentId = parentId, + PathCode = _customerOrgManager.CreatePathCode(parentId).Result, + PostalCode = row["postalcode"].ToString(), + Remark = remark, + ShortName = row["short_name"].ToString(), + SimpleCode = LanguageConverter.GetPYSimpleCode(row["org_name"].ToString()), + Telephone = row["telephone"].ToString(), + }; + + await _customerOrgRepository.InsertAsync(data, true); + + fieldComparisons.Add(new FieldComparison + { + FieldName = "id", + NewKeyValue = customerOrgId.ToString(), + OldKeyValue = row["org_id"].ToString(), + TableName = "customer_org" + }); + + } + + + if (fieldComparisons.Any()) + await _fieldComparisonRepository.InsertManyAsync(fieldComparisons); + } + } + } + + + /// + /// 迁移单位体检次数数据 + /// + /// + public async Task TransferCustomerOrgRegisterData() + { + var count = await _customerOrgRegisterRepository.GetCountAsync(); + if (count == 0) + { + List dataList = new List(); + + var oldCustomerOrgRegisterList = await Db.Ado.GetDataTableAsync("select * from org_medical_register"); + if (oldCustomerOrgRegisterList.Rows.Count > 0) + { + List fieldComparisonList = await _fieldComparisonRepository.GetListAsync(m => m.TableName == "customer_org"); + + foreach (DataRow row in oldCustomerOrgRegisterList.Rows) + { + Guid customerOrgId = Guid.Parse(fieldComparisonList.Where(m => m.OldKeyValue == row["org_id"].ToString()).FirstOrDefault().NewKeyValue); + Guid customerOrgRegisterId = GuidGenerator.Create(); + + if (customerOrgId == GuidFlag.PersonCustomerOrgId) + customerOrgRegisterId = GuidFlag.PersonCustomerOrgRegisterId; + var data = new CustomerOrgRegister(customerOrgRegisterId) + { + BeginTime = Convert.ToDateTime(row["start_time"].ToString()), + CustomerOrgId = customerOrgId, + EndTime = !string.IsNullOrWhiteSpace(row["end_time"].ToString()) ? Convert.ToDateTime(row["end_time"].ToString()) : null, + IsComplete = Convert.ToChar(row["complete_flag"].ToString()), + MedicalTimes = (short)Convert.ToInt32(row["org_medical_times"].ToString()), + RegisterName = "", + RegisterNo = "" + }; + + dataList.Add(data); + + + } + + if (dataList.Any()) + await _customerOrgRegisterRepository.InsertManyAsync(dataList); + + } + } + } + private void LoadDLL() { // 定义dll文件夹路径 diff --git a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs index 23777b1..20a007c 100644 --- a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs +++ b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs @@ -208,6 +208,10 @@ namespace Shentun.Peis.PeisReports { sumquery = sumquery.Where(m => m.a.CompleteFlag == input.CompleteFlag); } + else + { + sumquery = sumquery.Where(m => m.a.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration); + } if (input.IsAudit != null) { @@ -450,7 +454,7 @@ namespace Shentun.Peis.PeisReports [HttpPost("api/app/peisreport/getregisterasbitemchargestatus")] public async Task> GetRegisterAsbitemChargeStatusAsync(GetRegisterAsbitemChargeStatusRequestDto input) { - + var query = from j in await _registerAsbitemRepository.GetQueryableAsync() join k in await _registerCheckRepository.GetQueryableAsync() on j.RegisterCheckId equals k.Id into kk from jk in kk.DefaultIfEmpty() diff --git a/src/Shentun.Peis.Domain/CustomerOrgRegisters/CustomerOrgRegister.cs b/src/Shentun.Peis.Domain/CustomerOrgRegisters/CustomerOrgRegister.cs index 9747aa9..8b26788 100644 --- a/src/Shentun.Peis.Domain/CustomerOrgRegisters/CustomerOrgRegister.cs +++ b/src/Shentun.Peis.Domain/CustomerOrgRegisters/CustomerOrgRegister.cs @@ -14,6 +14,10 @@ namespace Shentun.Peis.Models [Table("customer_org_register")] public class CustomerOrgRegister : AuditedEntity, IHasConcurrencyStamp { + public CustomerOrgRegister(Guid id):base(id) { + + } + public CustomerOrgRegister() { CustomerOrgCharges = new HashSet(); diff --git a/src/Shentun.Peis.Domain/CustomerOrgs/CustomerOrgManager.cs b/src/Shentun.Peis.Domain/CustomerOrgs/CustomerOrgManager.cs index 40b8a80..829cfff 100644 --- a/src/Shentun.Peis.Domain/CustomerOrgs/CustomerOrgManager.cs +++ b/src/Shentun.Peis.Domain/CustomerOrgs/CustomerOrgManager.cs @@ -221,7 +221,7 @@ namespace Shentun.Peis.CustomerOrgs /// /// /// - private async Task CreatePathCode(Guid? parentId) + public async Task CreatePathCode(Guid? parentId) { string PathCode = "00001"; //一级 diff --git a/src/Shentun.Peis.Domain/Data/DefaultDataSeederContributor.cs b/src/Shentun.Peis.Domain/Data/DefaultDataSeederContributor.cs index 5882ee0..b4eb7d1 100644 --- a/src/Shentun.Peis.Domain/Data/DefaultDataSeederContributor.cs +++ b/src/Shentun.Peis.Domain/Data/DefaultDataSeederContributor.cs @@ -94,22 +94,22 @@ namespace Shentun.Peis.Data await CreateMaritalStatusAsync(); //结果状态 - await CreateResultStatusAsync(); + //await CreateResultStatusAsync(); //支付方式 await CreatePayModeAsync(); //体检结论类别 - await CreateMedicalConclusionTypeAsync(); + //await CreateMedicalConclusionTypeAsync(); //生成客户单位类别数据 - await CreateCustomerOrgTypeAsync(); + //await CreateCustomerOrgTypeAsync(); //生成民族数据 await CreateNationAsync(); - //生成性激素期限数据 - await CreateSexHormoneTermAsync(); + ////生成性激素期限数据 + //await CreateSexHormoneTermAsync(); await CreateDiagnosisLevelAsync(); }