从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
using FluentFTP;
|
||||
using SocialExplorer.IO.FastDBF;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YLErp.Modules.TradeMsgOutputModule.Dto;
|
||||
|
||||
namespace YLErp.Modules.TradeMsgOutputModule.Company
|
||||
{
|
||||
public abstract class BaseDongWanFileGenerateService
|
||||
{
|
||||
//protected string DBFFileSavePath = OtcAppContext.MapPath("~/App_Docs/Temp/DbfFile");
|
||||
protected string DBFFileSavePath = "D:\\测试文件";
|
||||
|
||||
|
||||
private string FtpServer = Environment.GetEnvironmentVariable("AppSettings:FtpServer");
|
||||
|
||||
private string FtpPort = Environment.GetEnvironmentVariable("AppSettings:FtpPort");
|
||||
|
||||
private string FtpFilePath = Environment.GetEnvironmentVariable("AppSettings:FtpFilePath");
|
||||
|
||||
private string FtpUserName = Environment.GetEnvironmentVariable("AppSettings:FtpUserName");
|
||||
|
||||
private string FtpPassword = Environment.GetEnvironmentVariable("AppSettings:FtpPassword");
|
||||
|
||||
/// <summary>
|
||||
/// 组装文件名称
|
||||
/// </summary>
|
||||
/// <param name="namePrefix"></param>
|
||||
/// <param name="valueDate"></param>
|
||||
/// <returns></returns>
|
||||
protected string GetFileName(string namePrefix,DateTime valueDate)
|
||||
{
|
||||
return namePrefix + "_" + valueDate.ToString("yyyyMMdd") + ".dbf";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetFilePath()
|
||||
{
|
||||
if (!Directory.Exists(DBFFileSavePath))
|
||||
{
|
||||
Directory.CreateDirectory(DBFFileSavePath);
|
||||
}
|
||||
return DBFFileSavePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件
|
||||
/// </summary>
|
||||
/// <param name="namePrefix"></param>
|
||||
/// <param name="valueDate"></param>
|
||||
/// <returns></returns>
|
||||
protected DbfFile CreateFile(string namePrefix, DateTime valueDate, out string fullFilePath)
|
||||
{
|
||||
return CreateDbfFile(GetFileName(namePrefix, valueDate), GetDbfFileColumns(),out fullFilePath);
|
||||
}
|
||||
|
||||
private DbfFile CreateDbfFile(string dbfName, List<DbfColumn> columns,out string fullFilePath)
|
||||
{
|
||||
var dbfPath = GetFilePath();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
fullFilePath = Path.Combine(dbfPath, dbfName);
|
||||
if (File.Exists(fullFilePath))
|
||||
{
|
||||
File.Delete(fullFilePath);
|
||||
}
|
||||
var odbf = new DbfFile(Encoding.UTF8);
|
||||
odbf.Open(fullFilePath, FileMode.Create);
|
||||
if (columns == null || columns.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("columns 不能为空");
|
||||
}
|
||||
columns.ForEach(p =>
|
||||
{
|
||||
odbf.Header.AddColumn(p);
|
||||
});
|
||||
return odbf;
|
||||
}
|
||||
|
||||
|
||||
protected abstract List<DbfColumn> GetDbfFileColumns();
|
||||
|
||||
|
||||
public abstract GenerateDbfFileResult GenerateDbfFile(DateTime valueDate);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取部门代码
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <returns></returns>
|
||||
protected string GetBmdmByAssetGroupName(string groupName)
|
||||
{
|
||||
switch (groupName)
|
||||
{
|
||||
case "投资管理部":
|
||||
return "1003";
|
||||
case "固定收益部":
|
||||
return "1004";
|
||||
case "做市业务部":
|
||||
return "1006";
|
||||
case "柜台市场业务部":
|
||||
return "1007";
|
||||
case "量化投资部":
|
||||
return "1009";
|
||||
case "基金期权做市部":
|
||||
return "1011";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取业务类别
|
||||
/// </summary>
|
||||
/// <param name="tradeType"></param>
|
||||
/// <returns></returns>
|
||||
protected string GetYWLBByTradeType(string tradeType)
|
||||
{
|
||||
if (ConsGlobal.TradeType.PayoffSwap.Equals(tradeType))
|
||||
{
|
||||
return "QYHH";
|
||||
}
|
||||
return "CWQQ";
|
||||
}
|
||||
|
||||
|
||||
protected string UploadFile(string filePath,string fileName)
|
||||
{
|
||||
using (var ftp = new FtpClient(FtpServer, FtpUserName, FtpPassword,int.Parse(FtpPort)))
|
||||
{
|
||||
ftp.Connect();
|
||||
if (ftp.DirectoryExists(FtpFilePath))
|
||||
{
|
||||
ftp.CreateDirectory(FtpFilePath);
|
||||
}
|
||||
// upload a file to an existing FTP directory
|
||||
ftp.UploadFile(filePath, FtpFilePath+"/"+fileName, FtpRemoteExists.Overwrite, true, FtpVerify.Retry);
|
||||
}
|
||||
|
||||
File.Delete(filePath);
|
||||
return FtpServer + ":" + FtpPort + FtpFilePath + "/" + fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user