From a1ae71bcdae46ece7957dba1113b720f413344ca Mon Sep 17 00:00:00 2001
From: wxd <123@qq.com>
Date: Tue, 25 Jun 2024 23:53:40 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=BD=8D=E7=99=BB=E8=AE=B0=E4=BA=BA?=
 =?UTF-8?q?=E6=95=B0=E9=87=91=E9=A2=9D=E6=8A=A5=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
 ...omerOrgPhysicalExaminationStatisticsDto.cs | 77 ++++++++++++++++
 ...rgPhysicalExaminationStatisticsInputDto.cs | 31 +++++++
 .../CustomerReportAppService.cs               | 87 +++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsDto.cs
 create mode 100644 src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsInputDto.cs
diff --git a/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsDto.cs b/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsDto.cs
new file mode 100644
index 0000000..3b6ec0f
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsDto.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.CustomerReports
+{
+    public class GetCustomerOrgPhysicalExaminationStatisticsDto
+    {
+        /// 
+        /// 单位名称
+        /// 
+        public string CustomerOrgName { get; set; }
+
+        /// 
+        /// 单位Id
+        /// 
+        public Guid CustomerOrgId { get; set; }
+
+        /// 
+        /// 人次  登记人数
+        /// 
+        public int RegisterCount { get; set; }
+
+        /// 
+        /// 已检人次  总检
+        /// 
+        public int CheckCount { get; set; }
+
+        /// 
+        /// 标准均价
+        /// 
+        public decimal AvgStandardPrice { get; set; }
+        /// 
+        /// 实收均价
+        /// 
+        public decimal AvgChargePrice { get; set; }
+
+
+        /// 
+        /// 标准价格总金额
+        /// 
+        public decimal SumStandardPrice { get; set; }
+        /// 
+        /// 实收价格总金额
+        /// 
+        public decimal SumChargePrice { get; set; }
+    }
+
+    public class GetCustomerOrgPhysicalExaminationStatisticsPatientRegisterGroupDto
+    {
+        public Guid PatientRegisterId { get; set; }
+
+        public char CompleteFlag { get; set; }
+
+        /// 
+        /// 单位名称
+        /// 
+        public string CustomerOrgName { get; set; }
+
+        /// 
+        /// 单位Id
+        /// 
+        public Guid CustomerOrgId { get; set; }
+
+        /// 
+        /// 标准
+        /// 
+        public decimal StandardPrice { get; set; }
+        /// 
+        /// 实收
+        /// 
+        public decimal ChargePrice { get; set; }
+
+
+
+    }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsInputDto.cs b/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsInputDto.cs
new file mode 100644
index 0000000..547476a
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/CustomerReports/GetCustomerOrgPhysicalExaminationStatisticsInputDto.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+
+namespace Shentun.Peis.CustomerReports
+{
+    public class GetCustomerOrgPhysicalExaminationStatisticsInputDto
+    {
+        public List CustomerOrgIds { get; set; }
+
+        /// 
+        /// 日期类型(1、登记日期   2、体检日期  3、总检日期)
+        /// 
+        [Required(ErrorMessage = "日期类型不能为空")]
+        public char DateType { get; set; }
+
+        /// 
+        /// 开始日期
+        /// 
+        [Required(ErrorMessage = "开始日期不能为空")]
+        public string StartDate { get; set; }
+
+
+        /// 
+        /// 结束日期
+        /// 
+        [Required(ErrorMessage = "结束日期不能为空")]
+        public string EndDate { get; set; }
+    }
+}
diff --git a/src/Shentun.Peis.Application/CustomerReports/CustomerReportAppService.cs b/src/Shentun.Peis.Application/CustomerReports/CustomerReportAppService.cs
index b22ddc6..85c418b 100644
--- a/src/Shentun.Peis.Application/CustomerReports/CustomerReportAppService.cs
+++ b/src/Shentun.Peis.Application/CustomerReports/CustomerReportAppService.cs
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Routing;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using NPOI.HPSF;
+using NPOI.POIFS.Properties;
 using NPOI.POIFS.Storage;
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.UserModel;
@@ -11,6 +12,7 @@ using NPOI.XSSF.UserModel.Extensions;
 using Org.BouncyCastle.Crypto.Tls;
 using Shentun.Peis.CustomerOrgs;
 using Shentun.Peis.Enums;
+using Shentun.Peis.InternalReports;
 using Shentun.Peis.Models;
 using Shentun.Peis.PeisReports;
 using Shentun.Peis.ReportTemplates;
@@ -2292,6 +2294,91 @@ namespace Shentun.Peis.CustomerReports
         }
 
 
+        /// 
+        /// 单位体检数据统计
+        /// 
+        /// 
+        [HttpPost("api/app/CustomerReport/GetCustomerOrgPhysicalExaminationStatistics")]
+        public async Task> GetCustomerOrgPhysicalExaminationStatisticsAsync(GetCustomerOrgPhysicalExaminationStatisticsInputDto input)
+        {
+
+            var qeruy = from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
+                        join registerCheck in await _registerCheckRepository.GetQueryableAsync() on patientRegister.Id equals registerCheck.PatientRegisterId
+                        join registerCheckAsbitem in await _registerAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckAsbitem.RegisterCheckId
+                        join customerOrg in await _customerOrgRepository.GetQueryableAsync() on patientRegister.CustomerOrgId equals customerOrg.Id
+                        join customerOrgParent in await _customerOrgRepository.GetQueryableAsync()
+                        on customerOrg.PathCode.Substring(0, 5) equals customerOrgParent.PathCode
+                        select new
+                        {
+                            patientRegister,
+                            registerCheckAsbitem,
+                            customerOrgParent
+                        };
+
+
+
+            if (input.CustomerOrgIds.Any())
+            {
+                List CustomerOrgIds = new List();
+
+                foreach (var item in input.CustomerOrgIds)
+                {
+                    CustomerOrgIds.AddRange(await _customerOrgManager.GetCustomerOrgChildrenId(item));
+                }
+
+                qeruy = qeruy.Where(m => CustomerOrgIds.Contains(m.patientRegister.CustomerOrgId));
+            }
+
+            if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
+            {
+                if (input.DateType == '1')
+                {
+                    qeruy = qeruy.Where(m => m.patientRegister.CreationTime >= Convert.ToDateTime(input.StartDate) &&
+                 m.patientRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
+                }
+                else if (input.DateType == '2')
+                {
+                    qeruy = qeruy.Where(m => m.patientRegister.MedicalStartDate != null && m.patientRegister.MedicalStartDate >= Convert.ToDateTime(input.StartDate) &&
+                 m.patientRegister.MedicalStartDate < Convert.ToDateTime(input.EndDate).AddDays(1));
+                }
+                else if (input.DateType == '3')
+                {
+                    qeruy = qeruy.Where(m => m.patientRegister.SummaryDate != null && m.patientRegister.SummaryDate >= Convert.ToDateTime(input.StartDate) &&
+              m.patientRegister.SummaryDate < Convert.ToDateTime(input.EndDate).AddDays(1));
+                }
+            }
+
+ 
+            var patientRegisterGroup = qeruy.ToList().GroupBy(g => g.patientRegister.Id);
+            var patientRegisterGroupList = patientRegisterGroup.Select(s => new GetCustomerOrgPhysicalExaminationStatisticsPatientRegisterGroupDto
+            {
+                PatientRegisterId = s.First().patientRegister.Id,
+                CompleteFlag = s.First().patientRegister.CompleteFlag,
+                StandardPrice = s.Sum(ss => ss.registerCheckAsbitem.StandardPrice * ss.registerCheckAsbitem.Amount),
+                ChargePrice = s.Sum(ss => ss.registerCheckAsbitem.ChargePrice * ss.registerCheckAsbitem.Amount),
+                CustomerOrgId = s.First().customerOrgParent.Id,
+                CustomerOrgName = s.First().customerOrgParent.DisplayName,
+            }).ToList();
+
+
+
+            var customerOrgGroup = patientRegisterGroupList.GroupBy(g => g.CustomerOrgId);
+
+            var customerOrgGrouplist = customerOrgGroup.Select(s => new GetCustomerOrgPhysicalExaminationStatisticsDto
+            {
+                CustomerOrgName = s.First().CustomerOrgName,
+                CustomerOrgId = s.First().CustomerOrgId,
+                CheckCount = s.Where(m => m.CompleteFlag == PatientRegisterCompleteFlag.SumCheck).Count(),
+                RegisterCount = s.Count(),
+                AvgChargePrice = Math.Round(s.Average(v => v.ChargePrice), 2),
+                AvgStandardPrice = Math.Round(s.Average(v => v.StandardPrice), 2),
+                SumChargePrice = Math.Round(s.Sum(v => v.ChargePrice), 2),
+                SumStandardPrice = Math.Round(s.Sum(v => v.StandardPrice), 2)
+            }).OrderByDescending(o => o.RegisterCount).ToList();
+
+            return customerOrgGrouplist;
+
+        }