using System;
|
using System.Collections.Generic;
|
using System.Diagnostics.Eventing.Reader;
|
using System.Linq;
|
using System.Web;
|
using System.Web.Mvc;
|
using CommonHelper;
|
using GasolineBlend.BLL;
|
using GasolineBlend.Entity;
|
|
namespace GasolineBlend.Controllers
|
{
|
public class SubjectController:BaseController
|
{
|
private SubjectBLL _acc = new SubjectBLL();
|
|
/// <summary>
|
/// 获取主体列表
|
/// </summary>
|
/// <param name="pid"></param>
|
/// <param name="TypeInfo"></param>
|
/// <param name="SubjectFilter">是否过滤自定义主体</param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetSubjectList(int pid,string TypeInfo,bool SubjectFilter=false,string FromName="",int CompanyId=0)
|
{
|
try
|
{
|
if (TypeInfo == "All")
|
{
|
var list = _acc.GetSubjectList(pid);
|
return SuccessNoShow(data: list);
|
}
|
else
|
{
|
var list = _acc.GetSubjectList(pid, TypeInfo, SubjectFilter, FromName, CompanyId);
|
return SuccessNoShow(data: list);
|
}
|
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "获取主体列表 GetSubjectList", e, OperatorProvider.Instance.Current==null?"GuestEx":OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
/// 添加/修改主体公司
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="Title"></param>
|
/// <param name="TypeInfo"></param>
|
/// <param name="GroupId"></param>
|
/// <param name="ProjId"></param>
|
/// <param name="RootFlag"></param>
|
/// <param name="CompanyCharId"></param>
|
/// <param name="StateId"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult AddSubjectCompany(int id, string Title,string TypeInfo,int GroupId,int ProjId,bool RootFlag,int CompanyCharId,int StateId,int TypeAdd=1)
|
{
|
try
|
{
|
Subject subject = new Subject();
|
subject.Title = Title;
|
subject.GroupId = GroupId;
|
subject.TypeInfo = _acc.GetSubjectTypeInfo(GroupId);
|
subject.ProjId = ProjId;
|
subject.RootFlag = RootFlag;
|
subject.CompanyCharId = CompanyCharId;
|
subject.StateId = StateId;
|
subject.TypeAdd = _acc.UpdateTypeAdd(TypeAdd,Title);
|
subject.id = id;
|
if (RootFlag && _acc.CheckRootNodeInStock(subject,false))
|
{
|
return Error("当前公司在评估基准日股权结构中存在直接股东!不允许作为根节点!", true, ShowDetail.ModalError.GetDisplayName());
|
}
|
else
|
{
|
if (id > 0)
|
{
|
if (_acc.ExistSubject(subject, true) == false)
|
{
|
|
var rev = _acc.UpdateSubject(subject);
|
if (rev)
|
{
|
//1. 将股权完整性检查结果存入mainProject表格 / mainSuject表
|
RightStockBLL rightStockBll = new RightStockBLL();
|
rightStockBll.UpdateRightStockIntegrity(ProjId, false);
|
|
//2. 如果节点的标识发生变化 或 根节点的属性发生变化
|
Subject subjectold = _acc.GetSubjectbyId(id);
|
if (subjectold.RootFlag != RootFlag ||
|
(subjectold.RootFlag && subjectold.CompanyCharId != CompanyCharId))
|
{
|
//根节点变化直接影响转换公式中的企业性质调整系数,所以预计损失比率要更新一次,连带着预计损失金额、久期、评估基准日支付金额一起更新
|
AssessDebtOutBLL assessDebtOutBll = new AssessDebtOutBLL();
|
assessDebtOutBll.UpdateDurationDiscountAll(ProjId);
|
}
|
|
//3. 如果根节点标识为true
|
if (subjectold.RootFlag != RootFlag)
|
{
|
//节点的股权完整性Flag与根节点Flag一致
|
_acc.UpdateSubject(id, RootFlag);
|
}
|
}
|
|
return rev ? Success() : Error();
|
}
|
else
|
{
|
var TypeName = _acc.GetSubjectbyTitle(Title, ProjId);
|
return Error("操作失败!'" + Title + "'在'" + TypeName + "'已存在!", true, ShowDetail.ModalError.GetDisplayName());
|
}
|
}
|
else
|
{
|
if (_acc.ExistSubject(subject, false) == false)
|
{
|
//添加新的节点信息
|
subject.StockIntegrityFlag = RootFlag;//节点的股权完整性Flag与根节点Flag一致
|
var rev = _acc.AddSubject(subject);
|
if (rev>0)
|
{
|
//1. 将股权完整性检查结果存入mainProject表格 / mainSuject表
|
RightStockBLL rightStockBll =new RightStockBLL();
|
rightStockBll.UpdateRightStockIntegrity(ProjId, false);
|
|
//2. 添加综合信息报告
|
AssessGeneralInfoBLL assessGeneralInfoBll=new AssessGeneralInfoBLL();
|
AssessGeneralInfo assessGeneralInfo = new AssessGeneralInfo();
|
assessGeneralInfo.CompanyId = rev;
|
assessGeneralInfoBll.AddGeneralInfo(assessGeneralInfo);
|
}
|
return rev>0 ? Success() : Error();
|
}
|
else
|
{
|
var TypeName = _acc.GetSubjectbyTitle(Title, ProjId);
|
return Error("操作失败!'" + Title + "'在'"+ TypeName + "'已存在!",true,ShowDetail.ModalError.GetDisplayName());
|
}
|
}
|
}
|
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "添加/修改主体公司 AddSubjectCompany", e, OperatorProvider.Instance.Current == null ? "GuestEx" : OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
/// <summary>
|
/// 批量更新主体的主体类型
|
/// </summary>
|
/// <param name="subjectIds"></param>
|
/// <param name="GroupId"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult UpdateSubjectsGroup(List<int> subjectIds, int GroupId)
|
{
|
try
|
{
|
string TypeInfo = _acc.GetSubjectTypeInfo(GroupId);
|
var rev = _acc.UpdateSubjectsGroup(subjectIds, GroupId,TypeInfo);
|
return rev ? Success() : Error();
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "批量更新主体的主体类型 GetSubjectbyId", e, OperatorProvider.Instance.Current==null?"GuestEx":OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
/// <summary>
|
/// 获取主体的基本信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetSubjectbyId(int id)
|
{
|
try
|
{
|
var rev = _acc.GetSubjectbyId(id);
|
return SuccessNoShow(data: rev);
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "获取主体的基本信息 GetSubjectbyId", e, OperatorProvider.Instance.Current==null?"GuestEx":OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
/// <summary>
|
/// 更新当前主体财务分析记录
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="FinDetails"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult UpdateSubjectFinDetails(int id,string FinDetails)
|
{
|
try
|
{
|
var rev = _acc.UpdateSubjectFinDetails(id, FinDetails);
|
return SuccessNoShow(data: rev);
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "更新当前主体财务分析记录 UpdateSubject", e, OperatorProvider.Instance.Current==null?"GuestEx":OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
/// <summary>
|
/// 删除某个公司
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult DeleteCompanybyId(int id)
|
{
|
try
|
{
|
Subject subject = _acc.GetSubjectbyId(id);
|
ProjectBLL projectBll = new ProjectBLL();
|
Project project = projectBll.GetProjOverview(subject.ProjId);
|
if (project.FirstSubjectId == id)
|
{
|
return Error("删除失败!项目概览>>放款及回收计划>>放款计划的直接融资主体需变更才能删除!");
|
}
|
else
|
{
|
var rev = _acc.DeleteCompanybyId(id, subject.ProjId);
|
//如果根节点标识是true
|
if (rev)
|
{
|
//1. 将股权完整性检查结果存入mainProject表格 / mainSuject表
|
RightStockBLL rightStockBll = new RightStockBLL();
|
rightStockBll.UpdateRightStockIntegrity(subject.ProjId, false);
|
|
//2. 如果节点是根节点
|
if (subject.RootFlag)
|
{
|
//根节点变化直接影响转换公式中的企业性质调整系数,所以预计损失比率要更新一次,连带着预计损失金额、久期、评估基准日支付金额一起更新
|
AssessDebtOutBLL assessDebtOutBll = new AssessDebtOutBLL();
|
assessDebtOutBll.UpdateDurationDiscountAll(subject.ProjId);
|
}
|
|
//3. 删除当前企业综合信息
|
AssessGeneralInfoBLL assessGeneralInfoBll=new AssessGeneralInfoBLL();
|
assessGeneralInfoBll.DeleteGeneralInfobyCompanyId(subject.id);
|
|
}
|
|
return rev ? Success() : Error();
|
}
|
}
|
catch (Exception e)
|
{
|
LogHelper.Write(Level.Error, "删除某个公司 DeleteCompanybyId", e, OperatorProvider.Instance.Current == null ? "GuestEx" : OperatorProvider.Instance.Current.LoginName);
|
return Error();
|
}
|
}
|
|
|
|
|
}
|
}
|