Commit 7a4865d5 by 陶然

初始化

parents
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/.vs
/Src/bin/Debug
/Src/obj/Debug
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2AD133E7-98F9-4FA3-AA16-A802F1682474}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Kivii.Finances.Addons</RootNamespace>
<AssemblyName>Kivii.Finances.Addons.V4.5</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kivii.Common.V4.5, Version=5.6.2023.6000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\local.K5\packages\Kivii.Common.5.6.2023.6000\lib\net45\Kivii.Common.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Core.V4.5, Version=5.6.2023.6000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\local.K5\packages\Kivii.Core.5.6.2023.6000\lib\net45\Kivii.Core.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Linq.V4.5, Version=5.6.2023.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\local.K5\packages\Kivii.Linq.5.6.2023.4200\lib\net45\Kivii.Linq.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Office.OpenXml.V4.5, Version=5.6.2023.3000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\local.K5\packages\Kivii.Office.OpenXml.5.6.2023.3000\lib\net45\Kivii.Office.OpenXml.V4.5.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RestfulPayment.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Kivii.Biz.Finances\Src\Kivii.Biz.Finances.V4.5.csproj">
<Project>{79937f8c-d32e-4bde-aa72-e7c58ee2e375}</Project>
<Name>Kivii.Biz.Finances.V4.5</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Content\Templates\Finances.Payment.Receipt.xlsx" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Kivii.Finances.Addons")]
[assembly: AssemblyDescription("财务管理扩展功能")]
[assembly: AssemblyDefaultAlias("Kivii.Finances.Addons")]
#if DEBUG
[assembly: AssemblyCompany("Kivii.Org")]
#else
[assembly: AssemblyCompany("Kivii.Com")]
#endif
[assembly: AssemblyProduct("Kivii Dev Platform")]
[assembly: AssemblyCopyright("Copyright (c) Kivii 2015-2023")]
[assembly: AssemblyTrademark("Kivii,K5")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyVersion("5.4.2023.8050")]
[assembly: AssemblyFileVersion("5.4.2023.8050")]
using Kivii.Finances.Entities;
using Kivii.Office.OpenXml.Excel;
using Kivii.Web;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kivii.Finances.Addons
{
public class ReadExcelResponse<T>:RestfulQueryResponse<T>
{
public bool success { get; set; }
}
[Api(Description = "读取Excel收款流水")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class PaymentReadReceiptExcel : RestfulExecution<Payment>
{
public override object OnExecution(IRequest req, IResponse res)
{
(Request.Files.Count() < 1 || Request.Files == null).ThrowIfTrue("未找到excel文件!");
var httpFile = Request.Files[0];
ExcelPackage package = new ExcelPackage(Request.Files[0].InputStream);
(package.Workbook.Worksheets.Count == 0).ThrowIfTrue("未找到Sheet!");
var rtns = new ReadExcelResponse<Payment>();
rtns.Results = new List<Payment>();
try
{
var sheet = package.Workbook.Worksheets[1];
var end = sheet.Dimension.End.Row;
for (int i = 2; i <= end; i++)
{
#region 格式化Excel中每行数据,必填项若不符合验证条件就抛出异常
var eSerialNumber = sheet.Cells[i, 2].Value;
if(eSerialNumber==null)
{
throw new Exception($"Excel第{i}行第2列不可为空,请传入不重复的流水号!");
}
var serialNumber = eSerialNumber.ToString();
var ePayerName = sheet.Cells[i, 3].Value;
if (ePayerName == null)
{
throw new Exception($"Excel第{i}行第3列不可为空,请传入付款单位!");
}
var payerName = ePayerName.ToString();
var eType = sheet.Cells[i, 4].Value;
if (eType == null)
{
throw new Exception($"Excel第{i}行第4列不可为空,请选择指定类型!");
}
if(!Enum.TryParse(eType.ToString(), true, out PaymentType type))
{
throw new Exception($"Excel第{i}行第4列类型不正确,请选择指定类型!");
}
if (type != PaymentType.Bank && type != PaymentType.Cash && type != PaymentType.Pos && type != PaymentType.AliPay && type != PaymentType.WeChat)
{
throw new Exception($"Excel第{i}行第4列类型不正确,请选择指定类型!");
}
var eAmount = sheet.Cells[i, 5].Value;
if (eAmount == null)
{
throw new Exception($"Excel第{i}行第5列不可为空,请传入发生金额!");
}
if (!Decimal.TryParse(eAmount.ToString(),out var amount))
{
throw new Exception($"Excel第{i}行第5列金额格式不正确!");
}
if(amount <= 0)
{
throw new Exception($"Excel第{i}行第5列金额不能小于等于零!");
}
var eCurrency = sheet.Cells[i, 6].Value;
if (eCurrency == null)
{
throw new Exception($"Excel第{i}行第6列不可为空,请传入货币单位!");
}
if (!Enum.TryParse(eCurrency.ToString(),true, out CurrencyUnit currency))
{
throw new Exception($"Excel第{i}行第6列货币单位格式不正确!");
}
if (currency != CurrencyUnit.CNY)
{
throw new Exception($"Excel第{i}行第6列货币单位格式不正确,请选择指定货币单位!");
}
var eOperateTime = sheet.Cells[i, 7].Value;
if (eOperateTime == null)
{
throw new Exception($"Excel第{i}行第7列不可为空,请传入发生日期!");
}
if (!DateTime.TryParse(eOperateTime.ToString(), out DateTime operateTime))
{
throw new Exception($"Excel第{i}行第7列发生日期格式不正确!");
}
var eBank = sheet.Cells[i, 8].Value;
var bank = eBank == null ? string.Empty : eBank.ToString();
var eBankNumber = sheet.Cells[i, 9].Value;
var bankNumber = eBankNumber == null ? string.Empty : eBankNumber.ToString();
var eSummary = sheet.Cells[i, 10].Value;
var summary = eSummary == null ? string.Empty : eSummary.ToString();
var eRemark = sheet.Cells[i, 11].Value;
var remark = eRemark == null ? string.Empty : eRemark.ToString();
#endregion
var payment = new Payment();
payment.Metadata = new Dictionary<string, string>();
payment.SerialNumber = serialNumber;
payment.Type = type;
payment.Currency = currency;
payment.OperateTime = operateTime;
payment.Amount = amount;
payment.PayerName = payerName;
payment.PayerAccountName = bank;
payment.PayerAccountSerialNumber = bankNumber;
payment.Summary = summary;
payment.Remark = remark;
rtns.Results.Add(payment);
}
}
catch (Exception ex)
{
throw ex;
}
rtns.Total = rtns.Results.Count;
rtns.success = true;
return rtns;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.Common" version="5.6.2023.6000" targetFramework="net45" />
<package id="Kivii.Core" version="5.6.2023.6000" targetFramework="net45" />
<package id="Kivii.Linq" version="5.6.2023.4200" targetFramework="net45" />
<package id="Kivii.Office.OpenXml" version="5.6.2023.3000" targetFramework="net45" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment