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

PostGroupListByCTableAndUserId 增加条件参数
三公费用 Bug 修改

leiy преди 11 месеца
родител
ревизия
b8dc82e228

+ 5 - 0
OASystem/OASystem.Api/Controllers/BusinessController.cs

@@ -197,6 +197,11 @@ namespace OASystem.API.Controllers
 									         Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
 									         And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
 
+                if (!string.IsNullOrEmpty(dto.TeamName))
+                {
+                    sql = string.Format($"{sql} And di.TeamName Like '%{dto.TeamName}%'");
+                }
+
                 RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
                 var data = await _groupRep._sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
                 foreach (var item in data)

+ 254 - 0
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -35,6 +35,12 @@ using System.Security.Cryptography;
 using NPOI.POIFS.Crypt.Dsig;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
 using Org.BouncyCastle.Asn1.Ocsp;
+using FluentValidation;
+using AutoMapper;
+using NetTaste;
+using EyeSoft.Runtime.InteropServices;
+using NPOI.HPSF;
+using System.Data.OleDb;
 
 namespace OASystem.API.Controllers
 {
@@ -3604,6 +3610,254 @@ Group by PriceType ", dto.diId);
         }
 
 
+        #endregion
+
+        #region 信用卡对账
+
+        /// <summary>
+        /// 信用卡对账
+        /// </summary>
+        /// <param name="file"></param>
+        /// <param name="cardType"></param>
+        /// <param name="beginDt"></param>
+        /// <param name="endDt"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostCreditCardBill([FromForm] IFormFile file, int cardType, string beginDt, string endDt)
+        {
+            if (file == null  || file.Length < 1)
+            {
+                return Ok(JsonView(false, "请上传文件!"));
+            }
+            string fileName = file.FileName;
+            if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
+            {
+                return Ok(JsonView(false, "请上传Excel文件!"));
+            }
+
+            if (cardType < 1) return Ok(JsonView(false, "请传入有效的卡类型!"));
+
+
+            if (string.IsNullOrEmpty(beginDt) || string.IsNullOrEmpty(endDt )) return Ok(JsonView(false, "请输入开始/结束日期!"));
+
+            var beginValid = DateTime.TryParse(beginDt, out _);
+            var endValid = DateTime.TryParse(endDt, out _);
+            if (beginValid || endValid) return Ok(JsonView(false, "请输入正确的日期格式"));
+
+
+            //保存文件
+            string filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}/CreditCardBill";
+            if (!Directory.Exists(filePath))
+            {
+                Directory.CreateDirectory(filePath);
+            }
+            filePath = $"{filePath}/{file.FileName}";
+            using (var stream = new FileStream(filePath, FileMode.Create))
+            { 
+                await stream.CopyToAsync(stream);
+            }
+
+            //信用卡信息
+            string sql = string.Format($"Select * From Grp_CreditCardPayment Where Isdel = 0 And CTDId = {cardType} And ConsumptionDate between '{beginDt}' and '{endDt}' ");
+            var List_ccp = await _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql).ToListAsync();
+
+            if (List_ccp.Count < 1)
+            {
+                return Ok(JsonView(false, $"未查询到 {beginDt} 至 {endDt} 信用卡账单信息!!!!"));
+            }
+
+            //资源信息
+            var delegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
+            var users = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
+            string cardTempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}/Template";
+            string url = string.Empty;
+            try
+            {
+                /*
+                 * 卡类型
+                 * 74	美元卡 1
+                 * 75	欧元卡 1
+                 * 86	招行卡 1
+                 * 346	中信卡 1
+                 * 363	交行卡 1
+                 * 
+                 */
+                switch (cardType)
+                {
+                    case 74:
+                        cardTempPath = $"{cardTempPath}/信用卡对账模板-美元卡.xls";
+                        var AirGroupReuslt = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
+                        if (AirGroupReuslt != null && AirGroupReuslt.Count > 0)
+                        {
+                            foreach (var item in AirGroupReuslt)
+                            {
+                                if (item.Count() > 1)
+                                {
+                                    var obj = item.FirstOrDefault();
+                                    obj.RMBPrice = item.Sum(x => x.PayMoney);//合计币种金额
+                                    obj.Remark = "团组机票总价(虚拟)";
+                                    List_ccp.Add(obj);
+                                }
+                            }
+                        }
+
+                        if (Directory.Exists(filePath))
+                        {
+                            Workbook wb = new Workbook(filePath);
+                            WorksheetCollection collection = wb.Worksheets;
+                            DataTable dt = new DataTable();
+                            if (collection.Count == 1) dt = ExcelToDataTable(filePath, collection[0].Name);
+                            else return Ok(JsonView(false, "请检查工作簿页数,请保留一页工作簿页数!!!"));
+
+                            if (dt == null) return Ok(JsonView(false, "您上传的Excel工作表没有内容,请检查!!!"));
+
+                            dt.AcceptChanges(); //提交
+
+                            dt.Columns.Add("TeamRemark", Type.GetType("System.String"));  //团组备注描述
+                            dt.Columns.Add("Handlers", Type.GetType("System.String"));  //经手人
+                            dt.Columns.Add("State", Type.GetType("System.String"));       //状态
+
+                            //修改table列名
+                            dt.Columns[0].ColumnName = "accountType";       // 账户类型
+                            dt.Columns[1].ColumnName = "tradeDate";         //交易日期
+                            dt.Columns[2].ColumnName = "BillingDate";   // 记账日期
+                            dt.Columns[3].ColumnName = "CardNo";           // 卡号
+                            dt.Columns[4].ColumnName = "deposit";           // 存入金额
+                            dt.Columns[5].ColumnName = "SpendingAmount";   // 支出金额
+                            dt.Columns[6].ColumnName = "TransactionDescription";   // 交易描述
+
+                            foreach (DataRow item in dt.Rows)
+                            {
+                                #region 匹配的金额
+                                decimal ExcelAmount = 0.00M;
+                                decimal deposit = 0.00M;
+                                if (!string.IsNullOrEmpty(item["SpendingAmount"].ToString()))
+                                {
+                                    var isParase = decimal.TryParse(item["SpendingAmount"].ToString(), out ExcelAmount);
+                                    if (isParase)
+                                    {
+                                        var CList = List_ccp.FindAll(x => x.PayMoney == ExcelAmount);
+                                        if (CList != null && CList.Count > 0)
+                                        {
+                                            item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
+                                            item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
+                                            item["State"] = 1;
+                                        }
+                                    }
+                                }
+                                if (!string.IsNullOrEmpty(item["deposit"].ToString()))
+                                {
+                                    var isParse = decimal.TryParse(item["deposit"].ToString(), out deposit);
+                                    if (isParse)
+                                    {
+                                        var CList = List_ccp.FindAll(x => x.PayMoney == deposit);
+                                        if (CList != null && CList.Count > 0)
+                                        {
+                                            item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
+                                            item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
+                                            item["State"] = 1;
+                                        }
+                                    }
+                                }
+                                #endregion
+
+
+                                //交易描述
+                                if (!string.IsNullOrEmpty(item["TransactionDescription"].ToString()))
+                                {
+                                    string TransactionDescription = item["TransactionDescription"].ToString();
+                                    var startIndex = TransactionDescription.LastIndexOf("[");
+                                    var endIndex = TransactionDescription.LastIndexOf("]");
+                                    if (startIndex != -1 && endIndex != -1)
+                                    {
+                                        var moenyList = TransactionDescription.Substring(startIndex + 1, endIndex - startIndex - 1).Split(' ').
+                                            Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                        decimal money = 0.00M;
+                                        foreach (var itemMoeny in moenyList)
+                                        {
+                                            if (itemMoeny.Contains('.'))
+                                            {
+                                                string itemMoenyStr = itemMoeny.Replace(",", string.Empty);
+                                                bool istrue = decimal.TryParse(itemMoenyStr, out money);
+                                                if (istrue)
+                                                {
+                                                    var CList = List_ccp.FindAll(x => x.PayMoney == money);
+                                                    if (CList != null && CList.Count > 0)
+                                                    {
+                                                        item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
+                                                        item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
+                                                        item["State"] = 1;
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+
+                            string fileName1 = $"信用卡账单(美元卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
+                            Dictionary<string, object> pairs = new Dictionary<string, object>();
+                            List<DataTable> datas = new List<DataTable>();
+                            datas.Add(dt);
+                            url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-美元卡.xls", "TB", fileName1, pairs, datas);
+                            return Ok(JsonView(true, "操作成功", new { url = "url" }));
+                        }
+
+                        break;
+
+                    default:
+                        return Ok(JsonView(false, "该卡类型对账开发中..."));
+                        break;
+                }
+            }
+            catch (Exception ex)
+            {
+                return Ok(JsonView(false, ex.Message));
+            }
+
+            return Ok(JsonView(true, "操作成功"));
+        }
+
+
+        /// <summary>
+        /// 把数据从Excel装载到DataTable
+        /// </summary>
+        /// <param name="pathName">带路径的Excel文件名</param>
+        /// <param name="sheetName">工作表名</param>
+        /// <param name="tbContainer">将数据存入的DataTable</param>
+        /// <returns></returns>
+        public static DataTable ExcelToDataTable(string pathName, string sheetName)
+        {
+            DataTable tbContainer = new DataTable();
+            string strConn = string.Empty;
+            if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet1"; }
+            FileInfo file = new FileInfo(pathName);
+            if (!file.Exists) { throw new Exception("文件不存在"); }
+            string extension = file.Extension;
+            switch (extension)
+            {
+                case ".xls":
+                    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
+                    break;
+                case ".xlsx":
+                    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
+                    break;
+                default:
+                    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
+                    break;
+            }
+            //链接Excel
+            OleDbConnection cnnxls = new OleDbConnection(strConn);
+            //读取Excel里面有 表Sheet1
+            System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
+            DataSet ds = new DataSet();
+            //将Excel里面有表内容装载到内存表中!
+            oda.Fill(tbContainer);
+            return tbContainer;
+        }
+
+
         #endregion
     }
 }

+ 10 - 4
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -4833,8 +4833,15 @@ namespace OASystem.API.Controllers
                         dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
                         //dic.Add("TellPhone", _DelegationInfo.TellPhone);
 
-                        string missionLeaderName = DeleClientList[0].Name,
-                               missionLeaderJob = DeleClientList[0].Job;
+                        string missionLeaderName = "",
+                               missionLeaderJob = "";
+
+                        if (DeleClientList.Count > 0)
+                        {
+                            missionLeaderName = DeleClientList[0].Name;
+                            missionLeaderJob = DeleClientList[0].Job;
+                        }
+
                         dic.Add("MissionLeaderName", missionLeaderName);
                         dic.Add("MissionLeaderJob", missionLeaderJob);
 
@@ -10582,8 +10589,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// <param name="file"></param>
         /// <param name="columnIndex"></param>
-        /// <param name="totalColumns"></param>
-        /// <param name="sheetName"></param>
+        /// <param name="isDel"></param>
         private void DeleteColumn(string file, int columnIndex,bool isDel)
         {
 

+ 1 - 0
OASystem/OASystem.Api/OASystem.API.csproj

@@ -39,6 +39,7 @@
     <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
     <PackageReference Include="SqlSugarCore" Version="5.1.3.35" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
+    <PackageReference Include="System.Data.OleDb" Version="8.0.0" />
     <PackageReference Include="TencentCloudSDK.Common" Version="3.0.734" />
     <PackageReference Include="TencentCloudSDK.Ocr" Version="3.0.734" />
     <PackageReference Include="TinyPinyin.Net" Version="1.0.2" />

+ 2 - 0
OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

@@ -267,6 +267,8 @@ namespace OASystem.Domain.Dtos.Groups
         /// 用户Id
         /// </summary>
         public int UserId { get; set; }
+
+        public string TeamName { get; set; } = "";
     }
 
 

+ 78 - 0
OASystem/OASystem.Domain/ViewModels/Financial/CreditCardBillDTO.cs

@@ -0,0 +1,78 @@
+using FluentValidation;
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.Financial
+{
+    /// <summary>
+    /// 信用卡账单对账 DTO
+    /// </summary>
+    public class CreditCardBillDTO
+    {
+        ///// <summary>
+        ///// 文件名称
+        ///// </summary>
+        //public IFormFile file { get; set; }
+
+        /// <summary>
+        /// 卡类型
+        /// </summary>
+        public int cardType { get; set; }
+
+        public string beginDt { get; set; }
+
+        public string endDt { get; set; }
+    }
+
+    public class CreditCardBillDTOFoaValidator : AbstractValidator<CreditCardBillDTO>
+    {
+        public CreditCardBillDTOFoaValidator() 
+        {
+            //RuleFor(it => it.file)
+            //    .NotNull()
+            //    .NotEmpty()
+            //    .WithMessage("请上传文件!")
+            //    .Must(it => IsExcelFile(it.FileName))
+            //    .WithMessage("请上传Excel文件");
+
+            RuleFor(it => it.cardType)
+                .GreaterThan(0)
+                .WithMessage("请传入有效的卡类型!");
+
+            RuleFor(it => it.beginDt)
+                .NotNull()
+                .NotEmpty()
+                .WithMessage("请输入开始日期!")
+                .Must(IsValidDate)
+                .WithMessage("请输入正确的日期格式!");
+
+            RuleFor(it => it.endDt)
+                .NotNull()
+                .NotEmpty()
+                .WithMessage("请输入结束日期!")
+                .Must(IsValidDate)
+                .WithMessage("请输入正确的日期格式!");
+        }
+
+        private bool IsValidDate(string dateString)
+        {
+            return DateTime.TryParse(dateString, out _);
+        }
+
+        private bool IsExcelFile(string fileName)
+        {
+            if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
+            {
+                return false;
+            }
+            return true;
+        }
+    }
+
+    
+
+}