Procházet zdrojové kódy

完善提成excel导出

yuanrf před 9 měsíci
rodič
revize
60bcc4db99

+ 57 - 7
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -1,8 +1,12 @@
 using Aspose.Cells;
 using Aspose.Words;
+using Aspose.Words.Drawing;
 using EyeSoft.Extensions;
+using EyeSoft.Runtime.InteropServices;
 using FluentValidation;
 using Microsoft.EntityFrameworkCore.Query.Internal;
+using NPOI.HPSF;
+using NPOI.SS.Formula.PTG;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.File;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
@@ -4623,7 +4627,7 @@ Group by PriceType ", dto.diId);
                 foreach (var airArr in groupByid)
                 {
                     var groupAirCount = 0; //团组航段数量
-                    var infos = new ArrayList();
+                    var infos = new List<string>();
                     foreach (var air in airArr)
                     {
                         var airCount = 0; // 单条航段数量
@@ -4759,7 +4763,7 @@ Group by PriceType ", dto.diId);
 
                 foreach (var group in groupByid)
                 {
-                    var infos = new ArrayList();
+                    var infos = new List<string>();
                     var totalPrice = 0.00M;
 
                     foreach (var item in group)
@@ -4816,11 +4820,15 @@ Group by PriceType ", dto.diId);
                 {
                     var price = LvArr.Find(x => x.Id == groupinfo.OpRoyaltyLv)?.Name.ObjToInt() ?? 0;
                     string temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} 提成金额为{price} {(string.IsNullOrWhiteSpace(groupinfo.OpRoyaltyRemark) ? "" : "提成说明:" + groupinfo.OpRoyaltyRemark )}";
+                    if (price == 0)
+                    {
+                        temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} op提成选项未选择!" ;
+                    }
                     resultArr.Add(new ComputeRoyaltiesView
                     {
                         TeamName = groupinfo.TeamName,
                         Id = groupinfo.Id,
-                        chiArr = new ArrayList (){ temp },
+                        chiArr = new List<string>() { temp },
                         teamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
                         VisitDate = groupinfo.VisitDate,
                         temp = temp,
@@ -4876,7 +4884,7 @@ Group by PriceType ", dto.diId);
                     bool isBasics = operUserMax == userId;
                     var money = 0;
 
-                    var infos = new ArrayList();
+                    var infos = new List<string>();
                     foreach (var item in group)
                     {
                         if (item.CreateUserId != user.Id)
@@ -4961,7 +4969,7 @@ Group by PriceType ", dto.diId);
                     var groupinfo = listVisa.First(x => x.Id == visaArr.Key);
                     var singlePrice = existsCountry.Where(x => groupinfo.VisitCountry.Contains(x)).Count() > 0 ? 50 : 30;
                     int count = 0, money = 0;
-                    var arr = new ArrayList();
+                    var arr = new List<string>();
                     foreach (var visa in visaArr)
                     {
                         if (visa.VisaPrice > 0)
@@ -5044,23 +5052,65 @@ Group by PriceType ", dto.diId);
             {
                 var apiArr = (parseApiResult.Data?.GetType().GetProperty("resultArr")?.GetValue(parseApiResult.Data)) as List<ComputeRoyaltiesView>;
 
+                var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == dto.UserId);
+
                 if (apiArr != null && apiArr.Count > 0)
                 {
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    //dic.Add("Name", "人员:" + user.CnName);
+                    dic.Add("startTime", dto.StartDate);
+                    dic.Add("endTime", dto.EndDate);
+                    dic.Add("operName", user.CnName);
+                    dic.Add("timeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
+                    //dic.Add("DowntimeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
+                    dic.Add("totalPrice",( "总金额:" +  parseApiResult.Data?.GetType().GetProperty("totalPrice")?.GetValue(parseApiResult.Data).ObjToDecimal().ToString() ?? "0") +" 元");
+
+                    ArrayList ToTableArr = new ArrayList();
+                    int No = 1;
                     //打开excel模板
                     foreach (var item in apiArr)
                     {
                         //载入数据
+                        ToTableArr.Add(new
+                        {
+                            No,
+                            item.TeamName,
+                            item.VisitDate,
+                            item.teamLvStr,
+                            item.temp,
+                            infos =  string.Join("\r\n",item.chiArr),
+                            price = item.price + "元",
+                        });
+
+                        No++;
+                    }
+
+                    DataTable TbData =CommonFun.ToDataTableArray(ToTableArr);
+                    TbData.TableName = "TbData";
+
+                    WorkbookDesigner designer = new WorkbookDesigner();
+                    designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/提成结算template.xlsx");
+
+                    foreach (var key in dic.Keys)
+                    {
+                        designer.SetDataSource(key, dic[key]);
                     }
 
+                    //数据源 
+                    designer.SetDataSource(TbData);
+                    designer.Process();
+
+                    designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx" );
+
                     jw = JsonView(true, "success!", new
                     {
-                        Url = "",
+                        Url = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath")+ "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx",
                     });
                 }
             }
             else
             {
-                jw.Msg = "获取提成信息error";
+                jw.Msg = "获取提成信息error " + jw.Msg;
             }
 
             return Ok(jw);

+ 1 - 1
OASystem/OASystem.Domain/Dtos/Financial/ComputeRoyaltiesDto.cs

@@ -26,7 +26,7 @@ namespace OASystem.Domain.Dtos.Financial
         public decimal price { get; set; }
         public string TeamName { get; set; }
         public int Id { get; set; }
-        public ArrayList chiArr { get; set; }
+        public List<string> chiArr { get; set; }
         public string? teamLvStr { get; set; }
         public DateTime VisitDate { get; set; }
         public string temp { get; set; }

+ 29 - 0
OASystem/OASystem.Infrastructure/Tools/CommonFun.cs

@@ -1,6 +1,7 @@
 using NPOI.SS.Formula.Functions;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Groups;
+using System.Collections;
 using System.Globalization;
 using System.Reflection;
 using System.Reflection.Metadata;
@@ -522,5 +523,33 @@ public static class CommonFun
 
     }
 
+    /// <summary>
+    /// List to DataTable
+    /// 集合转换成datatable
+    /// </summary>
+    public static DataTable ToDataTableArray(IList list)
+    {
+        DataTable result = new DataTable();
+        if (list.Count > 0)
+        {
+            PropertyInfo[] propertys = list[0].GetType().GetProperties();
+            foreach (PropertyInfo pi in propertys)
+            {
+                result.Columns.Add(pi.Name, pi.PropertyType);
+            }
+            for (int i = 0; i < list.Count; i++)
+            {
+                ArrayList tempList = new ArrayList();
+                foreach (PropertyInfo pi in propertys)
+                {
+                    object obj = pi.GetValue(list[i], null);
+                    tempList.Add(obj);
+                }
+                object[] array = tempList.ToArray();
+                result.LoadDataRow(array, true);
+            }
+        }
+        return result;
+    }
 
 }