chenzx
2024-12-26 bbcf5a65e0aeae3e6a4bae91284ce80ae8d3d5f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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();
            }
        }
 
 
 
 
    }
}