Commit 04bc0663 by 陶然

init

parents
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/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>{6F67E759-00BA-449C-AA6D-161495364B40}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Njhg.Finances.Addons</RootNamespace>
<AssemblyName>Njhg.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.10280, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Kivii.K5\local.K5\packages\Kivii.Common.5.6.2023.10280\lib\net45\Kivii.Common.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Core.V4.5, Version=5.6.2023.9000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Kivii.K5\local.K5\packages\Kivii.Core.5.6.2023.9000\lib\net45\Kivii.Core.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Linq.V4.5, Version=5.6.2023.10000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Kivii.K5\local.K5\packages\Kivii.Linq.5.6.2023.10000\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>..\..\Kivii.K5\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="RestfulReadExcel.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Content\Templates\Njhg.Finances.Payment.Receipt.xlsx" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Kivii.K5\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>
<ProjectReference Include="..\..\Kivii.K5\Kivii.Finances.Addons\Src\Kivii.Finances.Addons.V4.5.csproj">
<Project>{2ad133e7-98f9-4fa3-aa16-a802f1682474}</Project>
<Name>Kivii.Finances.Addons.V4.5</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Njhg.Finances.Addons.V4.5")]
[assembly: AssemblyDescription("南京海关财务管理扩展功能")]
[assembly: AssemblyDefaultAlias("Njhg.Finances.Addons")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Njhg.Finances.Addons.V4.5")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("6f67e759-00ba-449c-aa6d-161495364b40")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2023.11100")]
[assembly: AssemblyFileVersion("5.4.2023.11100")]
using Kivii.Finances.Addons;
using Kivii.Finances.Entities;
using Kivii.Office.OpenXml.Excel;
using Kivii.Web;
using Kivii;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Njhg.Finances.Addons
{
[Api(Description = "南京海关网银流水读取")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class PaymentReadExcelNjhgReceipt : 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 ePayeeName = sheet.Cells[1, 4].Value;
var payeeName = "南京海关工业产品检测中心";
if (ePayeeName != null)
{
payeeName = ePayeeName.ToString();
}
var payeeAccount = "4132200001819900011640";
var ePayeeAccount = sheet.Cells[1, 2].Value;
if (ePayeeAccount != null)
{
payeeAccount = ePayeeAccount.ToString();
}
var end = sheet.Dimension.End.Row;
for (int i = 8; i <= end; i++)
{
#region 格式化Excel中每行数据,必填项若不符合验证条件就抛出异常
var eOperateDate = sheet.Cells[i, 2].Value;
if (eOperateDate == null)
{
throw new Exception($"Excel第{i}行第2列不可为空,请传入交易日期!");
}
string operate = string.Empty;
var eOperateTime = sheet.Cells[i, 3].Value;
if (eOperateTime == null)
{
operate = eOperateDate.ToString();
//throw new Exception($"Excel第{i}行第8列不可为空,请传入交易时间!");
}
else
{
operate = $"{eOperateDate} {eOperateTime}";
}
if (!DateTime.TryParse(operate, out DateTime operateTime))
{
throw new Exception($"Excel第{i}行第2列交易日期格式不正确!");
}
var eAmount = sheet.Cells[i, 5].Value;
if (eAmount == null) continue;
if (!Decimal.TryParse(eAmount.ToString(), out var amount)) continue;
//{
// throw new Exception($"Excel第{i}行第5列金额格式不正确!");
//}
if (amount <= 0)
{
throw new Exception($"Excel第{i}行第5列金额不能小于等于零!");
}
var eSerialNumber = sheet.Cells[i, 9].Value;
if (eSerialNumber == null)
{
throw new Exception($"Excel第{i}行第9列不可为空,请传入不重复的流水号!");
}
var serialNumber = $"{operateTime:yyyyMMddHHmmss}{eSerialNumber}";
var ePayerName = sheet.Cells[i, 7].Value;
if (ePayerName == null)
{
throw new Exception($"Excel第{i}行第7列不可为空,请传入付款单位!");
}
var payerName = ePayerName.ToString();
var type = PaymentType.Bank;
var currency = CurrencyUnit.CNY;
var eBank = sheet.Cells[i, 8].Value;
var bank = eBank == null ? string.Empty : eBank.ToString();
var eBankNumber = sheet.Cells[i, 6].Value;
var bankNumber = eBankNumber == null ? string.Empty : eBankNumber.ToString();
var eSummary = sheet.Cells[i, 11].Value;
var summary = eSummary == null ? string.Empty : eSummary.ToString();
var eRemark = sheet.Cells[i, 10].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.PayeeName= payerName;
payment.PayeeAccountSerialNumber = payeeAccount;
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.10280" targetFramework="net45" />
<package id="Kivii.Core" version="5.6.2023.9000" targetFramework="net45" />
<package id="Kivii.Linq" version="5.6.2023.10000" 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