FinanceIndex.java
11.4 KB
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
package com.lhcredit.project.business.calculateRatings;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.common.utils.CalcuScore.CalcuParam;
import com.lhcredit.common.utils.DateUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.spring.SpringUtils;
import com.lhcredit.project.business.creditGrantingInfo.domain.CreditGrantingInfo;
import com.lhcredit.project.business.financeInfo.domain.FinanceInfo;
import com.lhcredit.project.business.scorecardScoreDetailed.domain.ScorecardScoreDetailed;
import com.lhcredit.project.business.scorecardScoreDetailed.service.IScorecardScoreDetailedService;
import com.lhcredit.project.business.scorecardScoreDetailed.service.ScorecardScoreDetailedServiceImpl;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Data
@NoArgsConstructor
public class FinanceIndex {
private FinanceInfo cur;
private FinanceInfo last;
private FinanceInfo llast;
private List<ScorecardScoreDetailed> scoreDetaileds;
protected String companyType;
protected String size;
private static final Double[] industry_average=new Double[]{6.7,8.0,12.9,4.3};
public static FinanceIndex of(FinanceInfo cur,FinanceInfo last,FinanceInfo llast){
FinanceIndex financeInfo = new FinanceIndex();
financeInfo.setCur(cur);
financeInfo.setLast(last);
financeInfo.setLlast(llast);
return financeInfo;
}
public static Double getCompanyEstablishYear(Date date) {
long datePoor = getDatePoor(date, new Date());
Double yearNum=Math.abs(datePoor/365D);;
return yearNum;
}
public static long getDatePoor(Date endDate, Date nowDate) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - nowDate.getTime();
// 计算差多少天
long day = diff / nd;
return day;
}
//根据营业总收入收入获取 企业规模
public String getCompanyScale(String type) {
IScorecardScoreDetailedService bean = SpringUtils.getBean(IScorecardScoreDetailedService.class);
scoreDetaileds=bean.selectScorecardScoreDetailedList(ScorecardScoreDetailed.builder().tempType(type).build());
BigDecimal bigDecimal = new BigDecimal("40000");
BigDecimal operRev = cur.getOperRev();
String sizeStr=null;
if (operRev.doubleValue()>=bigDecimal.doubleValue()){
//>=4亿元
sizeStr= "大型";
}else if(operRev.doubleValue()>=2000&&operRev.doubleValue()<bigDecimal.doubleValue()){
sizeStr= "中型";
}else{
sizeStr= "小型";
}
this.size=sizeStr;
return sizeStr;
}
//销售增长率
/**
销售增长率=(第n年营业总收入-第n-1年营业总收入)÷第n-1年营业总收入。若第n-1年营业总收入为0或空缺,则根据《企业绩效评价标准值(第n年)》(以下简称《绩效评价》),将销售增长率定为批发和零售行业销售(营业)增长率的平均值,根据企业规模划分的大、中、小型对应选取批发和零售行业大、中、小型的指标。
*/
public Double idx_xszzl() {
Double bl=null;
if ("大型".equals(size)) {bl=industry_average[1];}
else {
bl=industry_average[2];
}
//上一年缺失
if (null==last||null==last.getOperRev()){
return bl;
}
//((cur-last)/last)*100
double v = ((cur.getOperRev().subtract(last.getOperRev())).divide(last.getOperRev(), 4, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal("100")).doubleValue();
if (v>=bl){return bl;}
if (v>0&&v<bl){return v;}
if (v<=0){return 0D;}
return null;
}
/**
根据总资产周转率和《绩效评价》中总资产周转率和流动资产周转率指标对流动资产周转率进行估算。总资产周转率=第n年销售总收入×2÷(第n年资产总额+第n-1年资产总额)。若第n-1年资产总额=0,则总资产周转率=第n年销售总收入÷第n年资产总额
*/
public Double idx_ldzczzl() {
Double val=null;
if (null==last||numIsNullAndZero(last.getTotAssets())){
val=cur.getOperRev().divide(cur.getTotAssets(),4,BigDecimal.ROUND_HALF_UP).doubleValue();
return val;
}
//a*2/(b+c)
val = cur.getOperRev().multiply(new BigDecimal(2)).divide((cur.getTotAssets().add(last.getTotAssets())), 4, BigDecimal.ROUND_HALF_UP).doubleValue();
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("流动资产周转率")&&f.getRemark().equals(size)).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(val, sclist);
return object;
}
public boolean numIsNullAndZero(Object o){
if (null==o){return true;}
if (o instanceof BigDecimal){
return ((BigDecimal) o).doubleValue()==0;
}
return Double.valueOf(o.toString())==0;
}
//存货
public Double idx_ch() {
Double val=null;
if (null==last||numIsNullAndZero(last.getTotAssets())){
val=cur.getOperRev().divide(cur.getTotAssets(),4,BigDecimal.ROUND_HALF_UP).doubleValue();
return val;
}
//a*2/(b+c)
val = cur.getOperRev().multiply(new BigDecimal(2)).divide((cur.getTotAssets().add(last.getTotAssets())), 4, BigDecimal.ROUND_HALF_UP).doubleValue();
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("存货周转率")&&f.getRemark().equals(size)).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(val, sclist);
return object;
}
//速冻比率
public Double idx_sdbl() {
Double val = idx_zcfzl();
//todo 调用计算执行
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("速动比率")&&f.getRemark().equals(size)).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(val, sclist);
return object;
}
public Double idx_zcfzl(){
Double val=cur.getTotLiab().divide(cur.getTotAssets(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).doubleValue();
return val;
}
public Double idx_jbtzxs(String lv) {
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("级别调整系数")).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(lv, sclist);
return object;
}
//资产负债率调整系数
public Double idx_zcfzltzxs() {
if (numIsNullAndZero(cur.getTotAssets())){
return 54.1D;
}
Double val=cur.getTotLiab().divide(cur.getTotAssets(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).doubleValue();
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("资产负债率调整系数")).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(val, sclist);
return object;
}
public Double calculation_indicators(Object val,String name,String size){
List<ScorecardScoreDetailed> sclist = null;
if (StringUtils.isEmpty(size)){
sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals(name)).collect(Collectors.toList());
}else{
sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals(name)&&f.getRemark().equals(size)).collect(Collectors.toList());
}
Double object = new ScoreCardUtils.Calculation().calculation_scoring(val, sclist);
return object;
}
public Double idx_dyw(CreditGrantingInfo creditGrantingInfo) {
Double dyw=0D;
if(StringUtils.isNotEmpty(creditGrantingInfo.getCollateralList())){
JSONArray array = JSONArray.parseArray(creditGrantingInfo.getCollateralList().toString());
array= Optional.ofNullable(array).orElse(new JSONArray());
for (int i = 0; i < array.size(); i++) {
JSONObject dywObj = array.getJSONObject(i);
//抵押物评估价值*折扣率+保证额*30%
Double dy=dywObj.getDouble("assessValue")*dywObj.getDouble("discountRate");
if (null==dyw)dyw=0D;
dyw=dyw+dy;
}
}
return dyw;
}
public Double idx_dbe(CreditGrantingInfo creditGrantingInfo) {
Double dbe=0D;
if(StringUtils.isNotEmpty(creditGrantingInfo.getGuaranteeContract())){
JSONArray array = Optional.ofNullable(JSONArray.parseArray(creditGrantingInfo.getGuaranteeContract().toString())).orElse(new JSONArray());
// array=Optional.ofNullable(array).orElse(new JSONArray()).stream().map(m -> ((JSONObject) m).getDouble("money") * (30 / 100.0)).collect(Collectors.summingDouble(d -> d));
for (int i = 0; i < array.size(); i++) {
JSONObject dywObj = array.getJSONObject(i);
//抵押物评估价值*折扣率+保证额*30%
Double db=dywObj.getDouble("money")*(30/100.0);
if (null==dbe)dbe=0D;
dbe=dbe+db;
}
}
return dbe;
}
public Double idx_sstzxs(String basicInfo) {
JSONObject jsonObject = JSONObject.parseObject(basicInfo);
String bondNum = jsonObject.getString("bondNum");
String key="";
if (StringUtils.isEmpty(bondNum)){
key ="未上市";
}else if (StringUtils.startsWith(bondNum, "60")&&bondNum.length()==6||
(StringUtils.startsWith(bondNum, "0")&&bondNum.length()==6&&!StringUtils.startsWith(bondNum, "002"))||
StringUtils.startsWith(bondNum, "900")&&bondNum.length()==6||
StringUtils.startsWith(bondNum, "2")&&bondNum.length()==5||
StringUtils.startsWith(bondNum, "9")&&bondNum.length()==5
){
key="中小板上市";
} else if (StringUtils.startsWith(bondNum, "3")&&bondNum.length()==6) {
key="创业板/境外上市";
}else if (StringUtils.startsWith(bondNum, "43")&&bondNum.length()==6||
StringUtils.startsWith(bondNum, "83")&&bondNum.length()==6||
StringUtils.startsWith(bondNum, "87")&&bondNum.length()==6||
StringUtils.startsWith(bondNum, "88")&&bondNum.length()==6
) {
key="新三板上市";
}else if (StringUtils.startsWith(bondNum, "68")&&bondNum.length()==6){
key="科创板上市";
}else {
key="创业板/境外上市";//境外
}
List<ScorecardScoreDetailed> sclist = scoreDetaileds.stream().filter(f -> f.getScoreName().equals("上市调整系数")).collect(Collectors.toList());
Double object = new ScoreCardUtils.Calculation().calculation_scoring(key, sclist);
return object;
}
public static void main(String[] args) {
System.out.println(StringUtils.startsWith("6002165", "21"));
}
}