Commit c51d6549 by Neo Turing

init

parents
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/.vs
/Src/bin/Debug
/Src/bin/Release
/Src/obj
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kivii.Lims.Addons
{
internal class Configs
{
public const string RouteFileMerge = "/Lims/Report/PdfMerge";
}
}
using Kivii.Lims.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kivii.Lims.Addons
{
internal class Feature : IPlugin
{
public void Register(IAppHost appHost)
{
appHost.RegisterService<FileMergeService>();
}
}
}
using Kivii.Lims.Entities;
using Kivii.Linq;
using Kivii.Pdf;
using Kivii.Text.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Kivii.Lims.Addons
{
[Route(Configs.RouteFileMerge)]
public class FileMerge
{
public List<Guid> Kvids { get; set; }
public string FolderPath { get; set; } = "/Reports/Pdf";
public bool Download { get; set; } = true;
}
public class FileMergeService:Service
{
public object Any(FileMerge request)
{
request.Kvids.ThrowIfNullOrEmpty("请传入报告集合以合并PDF");
var conn = KiviiContext.GetOpenedDbConnection<Report>();
var queryPdfEntityFile = conn.From<EntityDbFile<Report>>();
queryPdfEntityFile.Where(o => o.OwnerKvid != Guid.Empty && o.ParentKvid == Guid.Empty && o.DbFolderPath ==request.FolderPath && o.Extension.ToLower() == ".pdf" && Sql.In(o.OwnerKvid, request.Kvids));
var pdfEntityFiles = conn.Select(queryPdfEntityFile);
pdfEntityFiles.ThrowIfNullOrEmpty("未找到指定pdf文件");
pdfEntityFiles = pdfEntityFiles.OrderBy(o => Array.IndexOf(request.Kvids.ToArray(), o.OwnerKvid)).ToList();
if (pdfEntityFiles.Count == 1)
{
var dbFile = pdfEntityFiles[0];
var physicalStorageFilePath = dbFile.GetPhysicalPath();
if (!File.Exists(physicalStorageFilePath)) throw new Exception("服务器端文件已被移除");
FileInfo localFile = new FileInfo(physicalStorageFilePath);
return new HttpResult(localFile, asAttachment: request.Download, fileName: dbFile.Name);
}
var fileName = $"{DateTime.Now:yyyyMMddHHmmss}合并PDF.pdf";
var tempPath = KiviiContext.GetTemporaryFilePath(fileName);
pdfEntityFiles.MergePDF(tempPath);
FileInfo fileInfo = new FileInfo(tempPath);
return new HttpResult(fileInfo, asAttachment: request.Download, fileName: fileName);
}
}
public static class FileMergeExtension
{
/// <summary>
/// 合并多个pdf
/// </summary>
/// <param name="pdfEntityFiles">pdf文件路径集合</param>
/// <param name="outPath">最终pdf的输出目录</param>
public static void MergePDF(this List<EntityDbFile<Report>> pdfEntityFiles, string outPath)
{
Document source = new Document();
PdfCopy pdfCopy =new PdfCopy(source,new FileStream(outPath, FileMode.Create));
source.Open();
for (int i = 0; i < pdfEntityFiles.Count; i++)
{
var dbFile = pdfEntityFiles[i];
var physicalStorageFilePath = dbFile.GetPhysicalPath();
PdfReader reader = new PdfReader(physicalStorageFilePath);
int iPageNum = reader.NumberOfPages;
for (int j = 1; j <= iPageNum; j++)
{
PdfImportedPage importedPage = pdfCopy.GetImportedPage(reader, j);
pdfCopy.AddPage(importedPage);
}
reader.Close();
}
source.Close();
}
}
}
<?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>{EA04C940-A05D-4F5B-AFB3-8F064F25FADD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Kivii.Lims.Addons</RootNamespace>
<AssemblyName>Kivii.Lims.Addons.V1.0</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>..\..\Kivii%27s Releases\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kivii.Common.V4.5, Version=5.6.2024.10240, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Kivii.Common.5.6.2024.10240\lib\net45\Kivii.Common.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Core.V4.5, Version=5.6.2024.10000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Kivii.Core.5.6.2024.10000\lib\net45\Kivii.Core.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Linq.V4.5, Version=5.6.2024.10000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Kivii.Linq.5.6.2024.10000\lib\net45\Kivii.Linq.V4.5.dll</HintPath>
</Reference>
<Reference Include="Kivii.Pdf.V4.5, Version=5.6.2024.7000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Kivii.Pdf.5.6.2024.7000\lib\net45\Kivii.Pdf.V4.5.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<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="Configs.cs" />
<Compile Include="Feature.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FileMergeService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Kivii.Biz.Lims.V1.0\Src\Kivii.Biz.Lims.V1.0.csproj">
<Project>{c2a2c9b2-e412-4267-8dad-4c37a3fe33e3}</Project>
<Name>Kivii.Biz.Lims.V1.0</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if "$(ConfigurationName)"=="Release" if exist "$(TargetDir)Reactor\dotNET_Reactor.exe" (call "$(TargetDir)Reactor\dotNET_Reactor.exe" -file "$(TargetPath)" -targetfile "$(TargetDir)Release\$(TargetFileName)" -stringencryption 0 -antitamp 1 -suppressildasm 1)</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Kivii.Lims.Addons.V1.0")]
[assembly: AssemblyDescription("Lims 1.0 扩展功能")]
[assembly: AssemblyDefaultAlias("Kivii.Lims.Addons")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Kivii.Lims.Addons.V1.0")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyLoadFeature(typeof(Kivii.Lims.Addons.Feature))]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("ea04c940-a05d-4f5b-afb3-8f064f25fadd")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2024.10100")]
[assembly: AssemblyFileVersion("5.4.2024.10100")]
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.Common" version="5.6.2024.10240" targetFramework="net45" />
<package id="Kivii.Core" version="5.6.2024.10000" targetFramework="net45" />
<package id="Kivii.Linq" version="5.6.2024.10000" targetFramework="net45" />
<package id="Kivii.Pdf" version="5.6.2024.7000" 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