524 lines
19 KiB
C#
524 lines
19 KiB
C#
using YLErp.BLL.EodSettlement;
|
|
using YLErp.Commons;
|
|
using YLErp.Modules.ClientModule;
|
|
using YLErp.Modules.SuperviseReportModule.CFMMC2022.Model;
|
|
using YLErp.Modules.SuperviseReportModule.CFMMC2022.Service;
|
|
using YLErp.Office;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 监管报告
|
|
/// </summary>
|
|
public class supervise_report2022Controller : BaseController
|
|
{
|
|
readonly YLContext db = new YLContext();
|
|
|
|
#region 成交报送
|
|
|
|
[MyAuthorize("监管报告-成交报送报表")]
|
|
public ActionResult supervise_today_report()
|
|
{
|
|
ViewBag.valueDate = BLL.Eod.EodOperationBase.GetLastSettlementDate(valuedateBLL.ValueDate).ToString("yyyy-MM-dd");
|
|
//ViewBag.valueDate = "2022-06-29";
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新成交报送报表数据查询
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public JsonResult superviseTodayReportQuery(SuperviseReportReq req)
|
|
{
|
|
var sList = new SuperviseReportTodayService(req, CurUser).NewSearchReportList();
|
|
return Json(sList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新成交报送报表数据查询导出
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public JsonResult SendSuperviseTodayReport(SuperviseReportReq req)
|
|
{
|
|
req.page = 1;
|
|
req.rows = 100000;
|
|
SearchListResult<NewSuperviseReportTodayModel> sList = null;
|
|
try
|
|
{
|
|
sList = new SuperviseReportTodayService(req, CurUser).NewSearchReportList();
|
|
var datas = sList.rows.ToList();
|
|
var sourcePath = Server.MapPath("~/App_Docs");
|
|
|
|
var sourceFileName = Path.Combine(sourcePath, "导出模板", "监管成交报告2022.xlsm");
|
|
var sourceFileName_Template = Path.Combine(sourcePath, "导出模板", $"监管成交报告2022-{req.DataSource}.xlsm");
|
|
if (System.IO.File.Exists(sourceFileName_Template))
|
|
{
|
|
sourceFileName = sourceFileName_Template;
|
|
}
|
|
var targetPath = Path.Combine(sourcePath, req.ValueDate.ToString("yyyyMMdd"));
|
|
if (!Directory.Exists(targetPath))
|
|
{
|
|
Directory.CreateDirectory(targetPath);
|
|
}
|
|
|
|
var targetFileName = Path.Combine(targetPath, $"otctrddata{req.ValueDate.ToString("yyyyMMdd")}.xlsm");
|
|
|
|
var modelDict = new Dictionary<string, object>
|
|
{
|
|
{"成交报送模板", datas}
|
|
};
|
|
var path = ExcelTemplate.GeneratePDFFromExeclTemplate(sourcePath, sourceFileName, modelDict, targetPath, targetFileName, null, null, null, false, callback: (sheet) =>
|
|
{
|
|
if (!datas.Any())
|
|
{
|
|
sheet.First().InsertRow(4, 1, 3);//此模板无数据则插入空行,注意样式
|
|
}
|
|
});
|
|
//补丁,返回一个相对地址
|
|
var relativePath = path.Substring(path.IndexOf("App_Docs") - 1);
|
|
|
|
return JsonSuccess("生成成功", relativePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return JsonError("生成失败", ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 持仓报送
|
|
|
|
[MyAuthorize("监管报告-持仓报送报表")]
|
|
public ActionResult supervise_position_report()
|
|
{
|
|
ViewBag.valueDate = BLL.Eod.EodOperationBase.GetLastSettlementDate(valuedateBLL.ValueDate).ToString("yyyy-MM-dd");
|
|
return View();
|
|
}
|
|
|
|
public JsonResult supervisePositionReportQuery(SuperviseReportReq req)
|
|
{
|
|
var sList = new SuperviseReportPositionService(req, CurUser).NewSearchReportList();
|
|
return Json(sList);
|
|
}
|
|
|
|
public JsonResult SendSupervisePositionReport(SuperviseReportReq req)
|
|
{
|
|
req.page = 1;
|
|
req.rows = 100000;
|
|
SearchListResult<NewSuperviseReportPositionModel> sList = null;
|
|
try
|
|
{
|
|
sList = new SuperviseReportPositionService(req, CurUser).NewSearchReportList();
|
|
var datas = sList.rows.ToList();
|
|
//sList.ForEach(O => { if (O.IsMoneynessOption == "是") { O.Strike = (O.InitialSpotPrice * O.Strike); O.IsMoneynessOption = "否"; } });
|
|
//获取盯市报告模板信息
|
|
var sourcePath = Server.MapPath("~/App_Docs");
|
|
var sourceFileName = Path.Combine(sourcePath, "导出模板", "监管持仓报告2022.xlsm");
|
|
var sourceFileName_Template = Path.Combine(sourcePath, "导出模板", $"监管持仓报告2022-{req.DataSource}.xlsm");
|
|
if (System.IO.File.Exists(sourceFileName_Template))
|
|
{
|
|
sourceFileName = sourceFileName_Template;
|
|
}
|
|
var targetPath = Path.Combine(sourcePath, req.ValueDate.ToString("yyyyMMdd"));
|
|
if (!Directory.Exists(targetPath))
|
|
{
|
|
Directory.CreateDirectory(targetPath);
|
|
}
|
|
|
|
var targetFileName = Path.Combine(targetPath, $"otcposdata{req.ValueDate:yyyyMMdd}.xlsm");
|
|
|
|
var modelDict = new Dictionary<string, object>
|
|
{
|
|
{"持仓报送模板", datas}
|
|
};
|
|
var path = ExcelTemplate.GeneratePDFFromExeclTemplate(sourcePath, sourceFileName, modelDict, targetPath, targetFileName, null, null, null, false,
|
|
callback: (sheet) =>
|
|
{
|
|
if (!datas.Any())
|
|
{
|
|
sheet.First().InsertRow(4, 1, 3);//此模板无数据则插入空行,注意样式
|
|
}
|
|
});
|
|
|
|
//补丁,返回一个相对地址
|
|
var relativePath = path.Substring(path.IndexOf("App_Docs") - 1);
|
|
|
|
return JsonSuccess("生成成功", relativePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return JsonError("生成失败", ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 客户资金报送-试点
|
|
|
|
[MyAuthorize("监管报告-客户资金报表")]
|
|
public ActionResult supervise_ClientCash_Report()
|
|
{
|
|
ViewBag.valueDate = BLL.Eod.EodOperationBase.GetLastSettlementDate(valuedateBLL.ValueDate).ToString("yyyy-MM-dd");
|
|
return View();
|
|
}
|
|
|
|
public JsonResult superviseClientCashReportQuery(SuperviseReportReq req)
|
|
{
|
|
IEnumerable<int> clienIds = null;
|
|
if (!string.IsNullOrWhiteSpace(req.clientName))
|
|
{
|
|
clienIds = DataCacheProvider.GetClientDataSource().AsQueryable().Where(O => O.Name.ToUpper().Contains(req.clientName.ToUpper())).Select(O => O.id).ToList();
|
|
if (!clienIds.Any() && clienIds != null)
|
|
{
|
|
return Json(new SearchListResult<NewSuperviseReportClientCashModel>());
|
|
}
|
|
}
|
|
var sList = new SuperviseReportClientCashService(CurUser).NewSearchSuperviseReportList(req, clienIds);
|
|
return Json(sList);
|
|
}
|
|
|
|
public JsonResult SendSuperviseClientCashReport(SuperviseReportReq req)
|
|
{
|
|
req.page = 1;
|
|
req.rows = 100000;
|
|
SearchListResult<NewSuperviseReportClientCashModel> sList = null;
|
|
try
|
|
{
|
|
IEnumerable<int> clienIds = null;
|
|
if (!string.IsNullOrWhiteSpace(req.clientName))
|
|
{
|
|
clienIds = DataCacheProvider.GetClientDataSource().AsQueryable().Where(O => O.Name.Contains(req.clientName)).Select(O => O.id).ToList();
|
|
}
|
|
sList = new SuperviseReportClientCashService(CurUser).NewSearchSuperviseReportList(req, clienIds);
|
|
|
|
var datas = sList.rows.ToList();
|
|
|
|
var sourcePath = Server.MapPath("~/App_Docs");
|
|
var sourceFileName = Path.Combine(sourcePath, "导出模板", "客户资金报告模板2022.xlsm");
|
|
var sourceFileName_Template = Path.Combine(sourcePath, "导出模板", $"客户资金报告模板2022-{req.DataSource}.xlsm");
|
|
|
|
if (System.IO.File.Exists(sourceFileName_Template))
|
|
{
|
|
sourceFileName = sourceFileName_Template;
|
|
}
|
|
var targetPath = Path.Combine(sourcePath, req.ValueDate.ToString("yyyyMMdd"));
|
|
if (!Directory.Exists(targetPath))
|
|
{
|
|
Directory.CreateDirectory(targetPath);
|
|
}
|
|
|
|
var targetFileName = Path.Combine(targetPath, $"funddata{req.ValueDate:yyyyMMdd}.xlsm");
|
|
|
|
var modelDict = new Dictionary<string, object>
|
|
{
|
|
{"客户资金报告模板", datas}
|
|
};
|
|
var path = ExcelTemplate.GeneratePDFFromExeclTemplate(sourcePath, sourceFileName, modelDict, targetPath, targetFileName, null, null, null, false,
|
|
callback: (sheet) =>
|
|
{
|
|
if (!datas.Any())
|
|
{
|
|
sheet.First().InsertRow(3, 1, 2);//此模板无数据则插入空行,注意样式
|
|
}
|
|
});
|
|
|
|
//补丁,返回一个相对地址
|
|
var relativePath = path.Substring(path.IndexOf("App_Docs") - 1);
|
|
|
|
return JsonSuccess("生成成功", relativePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return JsonError("生成失败", ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 子公司资金记录
|
|
[MyAuthorize("监管报告-客户资金报表")]
|
|
public ActionResult supervise_capital_allocation()
|
|
{
|
|
ViewBag.SystemDate = valuedateBLL.ValueDate;
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品列表页面
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[MyAuthorize("监管报告-客户资金报表")]
|
|
public ActionResult company_collateralList()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取子公司抵押品数据
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public JsonResult company_collateralQuery(company_collateralReq req)
|
|
{
|
|
var bll = new company_collateralBLL();
|
|
var sList = bll.SearchList(req, out _);
|
|
return Json(sList);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品显示页面
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult company_collateralView(string enid)
|
|
{
|
|
var intid = DecryptInt(enid);
|
|
var r = db.company_collateral.Find(intid);
|
|
var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(r.UnderlyingId ?? 0);
|
|
if (underlying != null)
|
|
{
|
|
r.UnderlyingCode = underlying.UnderlyingCode;
|
|
r.SpotPrice = underlying.Price;
|
|
r.ProductTotalPrice = r.SpotPrice * r.ProductAmount * r.Rate;
|
|
}
|
|
|
|
var variety = db.variety.Find(r.VarietyId);
|
|
r.VarietyShortName = variety == null ? "" : variety.ShortName;
|
|
|
|
return View(r);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品修改页面
|
|
/// </summary>
|
|
/// <param name="enid"></param>
|
|
/// <returns></returns>
|
|
public ActionResult company_collateralEdit(string enid)
|
|
{
|
|
company_collateral r;
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
r = new company_collateral { HappenDate = valuedateBLL.ValueDate.Add(DateTime.Now.TimeOfDay) };
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DecryptInt(enid);
|
|
r = db.company_collateral.Find(intid);
|
|
|
|
return View(r);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品赎回
|
|
/// </summary>
|
|
/// <param name="enid"></param>
|
|
/// <returns></returns>
|
|
public ActionResult company_collateralBackOperation(string enid)
|
|
{
|
|
var r = new company_collateral();
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DecryptInt(enid);
|
|
r = db.company_collateral.Find(intid);
|
|
return View(r);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品修改方法
|
|
/// </summary>
|
|
/// <param name="collection"></param>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public JsonResult company_collateralEditJson(company_collateral req)
|
|
{
|
|
var id = 0;
|
|
if (!string.IsNullOrEmpty(req.EncryptId))
|
|
{
|
|
id = DecryptInt(req.EncryptId);
|
|
}
|
|
|
|
if (req.HappenDate > DateTime.Now)
|
|
{
|
|
return JsonError("抵押时间不能大于当前时间");
|
|
}
|
|
|
|
var r = savecompany_collateral(id, req);
|
|
|
|
if (string.IsNullOrWhiteSpace(r.ErrorMsg))
|
|
{
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
else
|
|
{
|
|
return JsonError(r.ErrorMsg, r);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除抵押品
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public JsonResult delcompany_collateral(string id)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(id);
|
|
var r = db.company_collateral.Find(intid);
|
|
if (r == null)
|
|
{
|
|
return JsonError("找不到授信");
|
|
}
|
|
new ClientCreditService(CurUser).CreditLog(r.id, "删除");
|
|
db.company_collateral.Remove(r);
|
|
db.SaveChanges();
|
|
return JsonSuccess("删除成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保持子公司抵押品
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="collection"></param>
|
|
/// <returns></returns>
|
|
private company_collateral savecompany_collateral(int? id, company_collateral req)
|
|
{
|
|
company_collateral r;
|
|
var isAddNew = id == null || id == 0;
|
|
if (isAddNew)
|
|
{
|
|
r = new company_collateral
|
|
{
|
|
OptId = CurUser.UserId,
|
|
OptName = CurUser.UserName,
|
|
OptDate = DateTime.Now,
|
|
Status = company_collateralStatusEnum.抵押.ToString()
|
|
};
|
|
db.company_collateral.Add(r);
|
|
}
|
|
else
|
|
{
|
|
r = db.company_collateral.Find(id);
|
|
}
|
|
|
|
r.ClientId = req.ClientId;
|
|
r.VarietyId = req.VarietyId ?? 0;
|
|
r.ProductAmount = req.ProductAmount;
|
|
r.Rate = req.Rate;
|
|
r.HappenDate = req.HappenDate;
|
|
r.SerialNumber = req.SerialNumber;
|
|
r.Comments = req.Comments;
|
|
|
|
//设置关联数据
|
|
var client = ClientDataQueryService.GetClient(r.ClientId, true);
|
|
if (client != null)
|
|
{
|
|
r.ClientName = client.Name;
|
|
r.ClientNumber = client.Number;
|
|
}
|
|
if (isAddNew)
|
|
{
|
|
//新增编号
|
|
r.Number = UniqueTimeId.GetStr();
|
|
}
|
|
r.Rate /= 100;
|
|
r.OptStatus = "未确认";
|
|
|
|
db.SaveChanges();
|
|
|
|
return r;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品确认
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
public JsonResult excute(IEnumerable<int> ids)
|
|
{
|
|
new company_collateralBLL().ExcuteCompanyCollateral(ids, CurUser);
|
|
return JsonSuccess("执行成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 子公司抵押品拒绝
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
public JsonResult reject(string ids)
|
|
{
|
|
var entryids = ids.Split(","[0]).Select(s => Convert.ToInt32(s)).ToList();
|
|
var entrys = db.company_collateral.Where(e => entryids.Contains(e.id)).ToList();
|
|
entrys.ForEach(e =>
|
|
{
|
|
e.OptStatus = "拒绝";
|
|
e.OptId = CurUser.UserId;
|
|
e.OptName = CurUser.UserName;
|
|
e.OptDate = DateTime.Now;
|
|
});
|
|
db.SaveChanges();
|
|
|
|
return JsonSuccess("拒绝成功");
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult setBackStatus(company_collateralReq req)
|
|
{
|
|
var intid = DecryptInt(req.EncryptId);
|
|
var r = db.company_collateral.Find(intid);
|
|
|
|
if (r == null)
|
|
{
|
|
return JsonError("该抵押品记录不存在");
|
|
}
|
|
|
|
if (req.BackDate < r.HappenDate)
|
|
{
|
|
return JsonError("赎回时间不能小于抵押时间");
|
|
}
|
|
|
|
if (req.BackDate > DateTime.Now)
|
|
{
|
|
return JsonError("赎回时间不能大于当前时间");
|
|
}
|
|
|
|
r.Status = company_collateralStatusEnum.赎回.ToString();
|
|
r.OptStatus = "未确认";
|
|
r.BackDate = req.BackDate;
|
|
r.OptId = CurUser.UserId;
|
|
r.OptName = CurUser.UserName;
|
|
r.OptDate = DateTime.Now;
|
|
|
|
var spotPrice = DataCacheProvider.GetUnderlyingDataSource().GetData(r.UnderlyingId ?? 0)?.Price;
|
|
//查看当前客户可用资金是否符合出金条件
|
|
var clientbalance = ClientBalanceUtility.GetClientBanlances(new List<int> { r.ClientId }, DateTime.MinValue, DateTime.Now.Date).FirstOrDefault();
|
|
//当日可用资金(除去抵押品部分的价值,默认客户先消费现金,再消费抵押品,所以出金时可用资金要除去抵押品的价值)
|
|
var availableFund = (clientbalance == null ? 0 : clientbalance.AvailableAmount);
|
|
//如果出金大于可用资金(修改操作时需要算差价)则抛出错误
|
|
if ((spotPrice * r.ProductAmount * r.Rate ?? 0.0) > availableFund)
|
|
{
|
|
var variety = db.variety.Find(r.VarietyId);
|
|
return JsonError("部分执行错误,客户:" + r.ClientName + " 赎回抵押品:" + (variety == null ? "" : variety.ShortName) + "失败,实际可用资金:" + availableFund.ToString("0.00") + ",小于抵押品抵押价值;");
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
return JsonSuccess("赎回成功");
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
} |