Преглед на файлове

添加“案件绩效点数清单”报表导出功能

luocaiyang преди 10 месеца
родител
ревизия
6edbc802cf

+ 166 - 0
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -8,6 +8,8 @@ using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Caching.Memory;
 using Microsoft.Extensions.Hosting;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
@@ -823,6 +825,170 @@ namespace wispro.sp.api.Controllers
             return null;
         }
 
+        [Authorize]
+        public FileProcessTask GetStaticsPointReport(int Year, int Month)
+        {
+            CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
+            if (calMonth != null)
+            {
+                var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}代理人案件绩效点数清单.xlsx";
+                var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
+                var filePath = Path.Combine(attachfileSavePath, filename);
+
+                var fileTask = new FileProcessTask()
+                {
+                    Id = Guid.NewGuid().ToString(),
+                    FileName = filename,
+                    FilePath = filePath,
+                    Processed = 0
+                };
+
+                fileTaskService.Add(fileTask);
+
+                ExportDataResult result = new ExportDataResult()
+                {
+                    fileTask = fileTask,
+                    calMonth = calMonth
+                };
+
+                System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportStaticPointReport));
+                t.Start(result);
+
+                return fileTask;
+            }
+
+            return null;
+        }
+        private void ExportStaticPointReport(object exportDataResult)
+        {
+            ExportDataResult result = (ExportDataResult)exportDataResult;
+            FileProcessTask file = result.fileTask;
+            CalMonth calMonth = result.calMonth;
+
+            //var StatisticsResults = _CalMyStatistics(calMonth);
+            string strSQL = @" SELECT Staff.Name as 姓名,PerformanceItem.CaseNo as 案号,
+                  StaffStatistics.jxType as 点数类型,
+                  StaffStatistics.totalBasePoint as 基础点数,
+                  StaffStatistics.totalActuallyPoint as 调整后点数 
+                  ,StaffStatistics.FinianlPoint as 最终点数,
+                  StaffStatistics.nanduXS as 难度系数,
+                  StaffStatistics.S as S案件数,
+                  StaffStatistics.A as A案件数,
+                  StaffStatistics.B as B案件数,
+                  StaffStatistics.C as C案件数,
+                  StaffStatistics.D as D案件数
+                FROM StaffStatistics,Staff,PerformanceItem 
+                WHERE  StaffStatistics.ItemId =PerformanceItem.Id
+                  and StaffStatistics.StaffId = staff.Id
+                  and PerformanceItem.CalMonthId =@CalMonthId
+                  order by Staff.Name ";
+
+            DataTable dt = new DataTable();
+            spDbContext spDb = new spDbContext();
+            using (var conn = spDb.Database.GetDbConnection())
+            {
+                conn.Open();
+                var cmd = conn.CreateCommand();
+                cmd.CommandText = strSQL;
+                cmd.CommandType = CommandType.Text;
+
+                cmd.Parameters.Add(new SqlParameter("CalMonthId", calMonth.Id));
+                using (var reader = cmd.ExecuteReader())
+                {
+                    dt.Load(reader);
+                }
+            }
+
+            NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
+
+            #region 添加月度的难度系数和各等级案件数量
+            /*
+            // 检查文件是否是只读的
+            if ((System.IO.File.GetAttributes(result.fileTask.FilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
+            {
+                // 取消只读属性
+                System.IO.File.SetAttributes(result.fileTask.FilePath, System.IO.File.GetAttributes(result.fileTask.FilePath) & ~FileAttributes.ReadOnly);
+            }
+
+            using (FileStream f = new FileStream(result.fileTask.FilePath, FileMode.Open, FileAccess.ReadWrite))
+            {
+                XSSFWorkbook workbook = new XSSFWorkbook(f);
+                
+                ISheet sheet = workbook.GetSheetAt(0);
+
+                ICellStyle style = workbook.CreateCellStyle();
+
+                // 设置边框
+                style.BorderTop = BorderStyle.Thin;
+                style.BorderBottom = BorderStyle.Thin;
+                style.BorderLeft = BorderStyle.Thin;
+                style.BorderRight = BorderStyle.Thin;
+
+                sheet.ShiftRows(0, sheet.LastRowNum, 1);
+                sheet.ShiftRows(0, sheet.LastRowNum, 1);
+
+                IRow newRow = sheet.CreateRow(0);
+                ICell cell = newRow.CreateCell(0);
+                cell.SetCellValue((calMonth.NanduXS != null) ? calMonth.NanduXS.Value : 0.0);
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(1);
+                cell.SetCellValue((calMonth.S != null) ? calMonth.S.Value : 0.0);
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(2);
+                cell.SetCellValue((calMonth.A != null) ? calMonth.A.Value : 0.0);
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(3);
+                cell.SetCellValue((calMonth.B != null) ? calMonth.B.Value : 0.0);
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(4);
+                cell.SetCellValue((calMonth.C != null) ? calMonth.C.Value : 0.0);
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(5);
+                cell.SetCellValue((calMonth.D != null) ? calMonth.D.Value : 0.0);
+                cell.CellStyle = style;
+
+
+                sheet.ShiftRows(0, sheet.LastRowNum, 1);
+                newRow = sheet.CreateRow(0);
+                cell = newRow.CreateCell(0);
+                cell.SetCellValue("难度系数");
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(1);
+                cell.SetCellValue("S");
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(2);
+                cell.SetCellValue("A");
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(3);
+                cell.SetCellValue("B");
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(4);
+                cell.SetCellValue("C");
+                cell.CellStyle = style;
+
+                cell = newRow.CreateCell(5);
+                cell.SetCellValue("D");
+                cell.CellStyle = style;
+                
+                workbook.Write(f);
+
+            }
+            */
+            
+            #endregion
+
+            result.fileTask.Finished = true;
+        }
+
 
         private void ExportStaticReport(object exportDataResult)
         {

+ 1 - 0
wispro.sp.utility/NPOIExcle.cs

@@ -269,6 +269,7 @@ namespace wispro.sp.utility
                     {
                         workbook.Write(fs);//向打开的这个xls文件中写入数据
                         result = true;
+                        fs.Close();
                     }
 
                     #region 设定列宽

+ 79 - 38
wispro.sp.web/Pages/AppCase/CaseManager.razor

@@ -91,21 +91,83 @@ RenderFragment gdIcon =
             <Card Title="@($"{HandlingCalMonth.Year}年{HandlingCalMonth.Month}月绩效清单")">
 
                 <Extra>
-                    @if (HandlingCalMonth.Status != 4)
-                    {
-                        if(isGuiDang)
-                        {
-                            <Button Icon="download" Type="@ButtonType.Text" Loading>数据归档中</Button>
-                        }
-                        else{
-                        
-                            <a @onclick="()=>GuidangCalMonth(HandlingCalMonth)">
-                                <Icon Component="gdIcon" Style="font-size:28px;"></Icon>
-                                完成本期绩效计算,归档数据
-                            </a>
-                        }
-                    }
+                    <Space>
+                        <SpaceItem>
+                            @if (HandlingCalMonth.Status != 4)
+                            {
+                                if(isGuiDang)
+                                {
+                                    <Button Type="@ButtonType.Default" Shape="@ButtonShape.Round" Disabled Loading>数据归档中</Button>
+                                }
+                                else{
+                                    <Button Icon="gdIcon" Type="@ButtonType.Default"  Shape="@ButtonShape.Round">
+                                        <a @onclick="()=>GuidangCalMonth(HandlingCalMonth)">
+                                            完成本期绩效计算,归档数据
+                                        </a>
+                                    </Button>
+                                }
+                            }
+                        </SpaceItem>
+                        <SpaceItem>
+                            <DropdownButton>
+                                <Overlay>
+                                    <Menu>
+                                        <MenuItem>
+                                    
+                                        </MenuItem>
+                                        <MenuItem>
+                                            @if (isDownloading)
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" Loading>导出最终绩效报表</Button>
+                                            }
+                                            else
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportJXDataAsync(HandlingCalMonth)">导出最终绩效报表</Button>
+                                            }
+                                         </MenuItem>
+                                         <MenuItem>
+                                            @if (isDownloading)
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" Loading>导出案件绩效点数报表</Button>
+                                            }
+                                            else
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportJXPointAsync(HandlingCalMonth)">导出案件绩效点数报表</Button>
+                                            }
+                                         </MenuItem>
+                                        <MenuItem>
+                                            @if (isDownloading)
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" Loading>导出案件数据</Button>
+                                            }
+                                            else
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportDataAsync(HandlingCalMonth)">导出</Button>
+                                            }
+                                        </MenuItem>
+                                        <MenuItem>
+                                            @if (isDownloading)
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" Loading>导出客户案件统计</Button>
+                                            }
+                                            else
+                                            {
+                                                <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportCCSDataAsync(HandlingCalMonth)">导出客户案件统计</Button>
+                                            }
+                                        </MenuItem>
+                                    </Menu>
+                                </Overlay>
+                                <ChildContent>
+                                    <a class="ant-dropdown-link" @onclick:preventDefault>
+                                        数据导出
+                                    </a>
+                            </ChildContent>
+                        </DropdownButton>
 
+                        </SpaceItem>
+                    </Space>
+                    
+                    
                     @*@if(isDownloading)
                     {
                         <Button Icon="download" Type="@ButtonType.Text" Loading>导出线下绩效计算报表</Button>
@@ -115,32 +177,11 @@ RenderFragment gdIcon =
                         <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportCurrentMonthJXList()">导出线下绩效计算报表</Button>
                     }*@
 
-                    @if (isDownloading)
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" Loading>导出最终绩效报表</Button>
-                    }
-                    else
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportJXDataAsync(HandlingCalMonth)">导出最终绩效报表</Button>
-                    }
+                    
 
-                    @if (isDownloading)
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" Loading>导出</Button>
-                    }
-                    else
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportDataAsync(HandlingCalMonth)">导出</Button>
-                    }
+                    
 
-                    @if (isDownloading)
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" Loading>导出客户案件统计</Button>
-                    }
-                    else
-                    {
-                        <Button Icon="download" Type="@ButtonType.Text" OnClick="() => ExportCCSDataAsync(HandlingCalMonth)">导出客户案件统计</Button>
-                    }
+                    
                     
                     </Extra>
 

+ 21 - 0
wispro.sp.web/Pages/AppCase/CaseManager.razor.cs

@@ -179,6 +179,27 @@ namespace wispro.sp.web.Pages.AppCase
 
         }
 
+        private async Task ExportJXPointAsync(CalMonth calMonth)
+        {
+            isDownloading = true;
+            var fileData = await _ItemService.ExportJXPointReport(calMonth.Year, calMonth.Month);
+
+            while (!fileData.Finished)
+            {
+                fileData = await _ItemService.getExportDataProcessing(fileData.Id);
+                await Task.Delay(20);
+            }
+
+            NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
+
+            isDownloading = false;
+
+
+
+        }
+
+        
+
         private async Task ExportCCSDataAsync(CalMonth calMonth)
         {
             isDownloading = true;

+ 6 - 0
wispro.sp.web/Services/PerformanceItemServices.cs

@@ -73,6 +73,12 @@ namespace wispro.sp.web.Services
             var fileData = await _httpClient.Get<FileProcessTask>($"PerformanceItem/GetStaticsReport?Year={Year}&Month={month}");
             return fileData;
         }
+        
+        public async Task<FileProcessTask> ExportJXPointReport(int Year, int month)
+        {
+            var fileData = await _httpClient.Get<FileProcessTask>($"PerformanceItem/GetStaticsPointReport?Year={Year}&Month={month}");
+            return fileData;
+        }
 
         public async Task<FileProcessTask> CurrentData2Excel(CalMonth calMonth)
         {