WebCreditGrantingInfoController.java
13.3 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package com.lhcredit.project.webbusiness.controller;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lhcredit.common.utils.DateUtils;
import com.lhcredit.common.utils.JsonPathUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.http.HttpTemplate;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.framework.web.service.FastDFSClient;
import com.lhcredit.project.business.BasicInformation.service.BasicInformationService;
import com.lhcredit.project.business.TianYC.entity.param.RequestParams;
import com.lhcredit.project.business.creditGrantingInfo.domain.CreditGrantingInfoExcel;
import com.lhcredit.project.business.creditGrantingInfo.domain.HistoricalTransactions;
import com.lhcredit.project.business.creditGrantingRisk.domain.CreditGrantingRisk;
import com.lhcredit.project.business.creditGrantingRisk.service.ICreditGrantingRiskService;
import com.lhcredit.project.business.financeInfo.domain.FinanceInfo;
import com.lhcredit.project.business.financeInfo.service.IFinanceInfoService;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.reportDirectoryData.service.QxbHttpUtils;
import com.lhcredit.project.business.universalEvaluationMode.domain.UniversalEvaluationMode;
import com.lhcredit.project.business.universalEvaluationMode.service.IUniversalEvaluationModeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.project.business.creditGrantingInfo.domain.CreditGrantingInfo;
import com.lhcredit.project.business.creditGrantingInfo.service.ICreditGrantingInfoService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import static com.lhcredit.common.utils.JsonPathUtils.*;
/**
* 信用评级申请信息对外接口
*
* @author lhcredit
* @date 2024-06-11
*/
@RestController
@RequestMapping("/web/creditGrantingInfo")
@Validated
public class WebCreditGrantingInfoController extends BaseController {
@Autowired
private ICreditGrantingInfoService creditGrantingInfoService;
@Autowired
private HttpTemplate httpTemplate;
@Value("${dataCenters.url}")
private String apiUrl;
@Autowired
private BasicInformationService basicInformationService;
@Autowired
private IFinanceInfoService financeInfoService;
@Autowired
private IUniversalEvaluationModeService evaluationModeService;
@Autowired
private ICreditGrantingRiskService creditGrantingRiskService;
@RequestMapping("test")
public void test(){
List<CreditGrantingInfo> list = creditGrantingInfoService.selectCreditGrantingInfoList(null);
list.stream().forEach(i->{creditGrantingRiskService.insert(i.getId(), i.getEname());});
}
@RequestMapping("getCreditResult")
public AjaxResult getCreditResult(@NotNull(message = "id不能为空")Long cgId){
CreditGrantingInfo creditGrantingInfo = creditGrantingInfoService.selectCreditGrantingInfoById(cgId);
List<FinanceInfo> list = financeInfoService.selectFinanceInfoList(FinanceInfo.builder().cmId(cgId).build());
creditGrantingInfo.setFinanceInfoList(list);
//todo 根据id 查询通用指标
List<UniversalEvaluationMode> evaluationModeList = evaluationModeService.getEvaluationModeListByCgid(cgId);
creditGrantingInfo.setEvaluationModeList(evaluationModeList);
return AjaxResult.success(creditGrantingInfo);
}
/**
* 增加授信额度申请
* @return
*/
@RequestMapping("/creditLimitAddApplication")
public AjaxResult creditLimitAddApplication(@RequestBody Object params){
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(params));
CreditGrantingInfo creditGrantingInfo = creditGrantingInfoService.selectCreditGrantingInfoById(jsonObject.getLong("cgId"));
if (jsonObject.getLong("creditLimit")<=creditGrantingInfo.getCreditLimitLast()){
return AjaxResult.error("申请必须大于授信金额");
}
int i = creditGrantingInfoService.updateCreditGrantingInfo(CreditGrantingInfo.builder().id(jsonObject.getLong("cgId")).creditLimitAdd(jsonObject.getLong("creditLimit"))
.creditLimitAddInfo(jsonObject.getString("info")).creditLimitAddAnnex(jsonObject.getString("annex")).build());
return toAjax(i);
}
/**
* 向下调整授信额度
* @param cgId
* @param limitSub
* @return
*/
@RequestMapping("/creditLimitSub")
public AjaxResult creditLimitSub(@NotNull(message = "id不能为空") Long cgId,@NotNull(message = "分值不能为空") Double limitSub){
CreditGrantingInfo creditGrantingInfo = creditGrantingInfoService.selectCreditGrantingInfoById(cgId);
Long creditLimitLast = creditGrantingInfo.getCreditLimitLast();
if (limitSub>=creditLimitLast)return AjaxResult.error("授信额度修改失败!");
int i = creditGrantingInfoService.updateCreditGrantingInfo(CreditGrantingInfo.builder().id(cgId).creditLimitLast(new BigDecimal(limitSub).setScale(2,BigDecimal.ROUND_HALF_UP).longValue()).build());
return toAjax(i);
}
/**
* 查询信用评级申请列表接口
*/
@ApiOperation("查询信用评级申请列表")
@Log(title = "信用评级申请", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
@RequestMapping("list")
public Object list(String ename, Long creditLimitSt, Long creditLimitEd, String creditStatus,
String creditLv, Date creditTimeSt, Date creditTimeEd, Integer sort, Boolean outPut, HttpServletResponse response) {
FrontUserMon userInfo = getUserInfo();
if (outPut==false){
startPage();
}
List<CreditGrantingInfo> list=creditGrantingInfoService.selectPageList(ename,creditLimitSt,creditLimitEd,creditStatus,creditLv,creditTimeSt,creditTimeEd,sort,userInfo.getOrgId());
if (outPut){
List<CreditGrantingInfoExcel> excelList=JSONArray.parseArray(JSON.toJSONString(list), CreditGrantingInfoExcel.class);
com.lhcredit.common.utils.poi.ExcelUtil<CreditGrantingInfoExcel> util = new com.lhcredit.common.utils.poi.ExcelUtil<CreditGrantingInfoExcel>(CreditGrantingInfoExcel.class);
util.exportExcel(excelList, "creditGrantingInfo",response);
return "";
}
return toAjax(list);
}
@RequestMapping("genPdf")
public AjaxResult genPdf(String name,Long cgId){
String pdf = creditGrantingInfoService.genPdf(cgId);
System.out.println(pdf);
return AjaxResult.success(new HashMap<String,Object>(){{put("url",pdf);}});
}
@RequestMapping("getBasic")
public AjaxResult getBasic(String name,Long id){
RequestParams requestParams = new RequestParams();
requestParams.setName(name);
JSONObject jsonObject = basicInformationService.baseinfo2(requestParams);
if (!jsonObject.getString("code").equals("2000")){
return AjaxResult.error(jsonObject.getString("msg"));
}
CreditGrantingInfo creditGrantingInfo = new CreditGrantingInfo();
FrontUserMon userInfo = getUserInfo();
userInfo = new FrontUserMon();
//--------初始化bean信息------------------------------------
creditGrantingInfo.setEname(jsonPathString(jsonObject,"data.name"));
JSONObject basicInfo=new JSONObject();
basicInfo.put("establishDate",jsonPathString(jsonObject,"data.termStart"));
basicInfo.put("legalPersonName", jsonPathString(jsonObject,"data.operName"));
basicInfo.put("regCapital", jsonPathString(jsonObject,"data.registCapiNew"));
basicInfo.put("base", jsonPathString(jsonObject,"data.base"));
basicInfo.put("regLocation", jsonPathString(jsonObject,"data.address"));
basicInfo.put("businessScope", jsonPathString(jsonObject,"data.scope"));
basicInfo.put("regNumber", jsonPathString(jsonObject,"data.regNo"));
basicInfo.put("industry", jsonPathString(jsonObject,"data.industryCode"));
basicInfo.put("bondNum", jsonPathString(jsonObject,"data.bondNum"));
creditGrantingInfo.setBasicInfo(basicInfo.toJSONString());
//-------初始化财务信息-------------------------
// List<FinanceInfo> list=financeInfoService.getReportSystemApiData(name,jsonPathString(jsonObject,"data.regLocation"),userInfo.getId(),userInfo.getOrgId());
// creditGrantingInfo.setFinanceInfoList(list);
return AjaxResult.success(creditGrantingInfo);
}
public static void main(String[] args) {
Object object = QxbHttpUtils.sendHttpRequest("http://lhapi.lhdna.com/api/V4.0/baseinfo2?", new JSONObject() {{
put("name", "义乌市大进百货有限公司");
}});
System.out.println(JSONObject.parseObject(object.toString()).getJSONObject("data").toJSONString());
}
@PostMapping("/add")
public AjaxResult add(@RequestBody CreditGrantingInfo creditGrantingInfo){
System.out.println(JSON.toJSONString(creditGrantingInfo));
if (null!=creditGrantingInfo.getId()){
creditGrantingInfoService.deleteCreditGrantingInfoByIds(creditGrantingInfo.getId().toString());
}
// Object object = QxbHttpUtils.sendHttpRequest("http://lhapi.lhdna.com/api/V4.0/baseinfo2?", new JSONObject() {{
// put("name", "义乌市大进百货有限公司");
// }});
// creditGrantingInfo.setBasicInfo(JSONObject.parseObject(object.toString()).getJSONObject("data").toJSONString());
if (StringUtils.isNotEmpty(creditGrantingInfo.getCollateralList())&&creditGrantingInfo.getCollateralList().equals("null"))creditGrantingInfo.setCollateralList(null);
if (StringUtils.isNotEmpty(creditGrantingInfo.getGuaranteeContract())&&creditGrantingInfo.getGuaranteeContract().equals("null"))creditGrantingInfo.setGuaranteeContract(null);
FrontUserMon userInfo = getUserInfo();
// FrontUserMon userInfo= new FrontUserMon();
// userInfo.setId(27L);
// userInfo.setOrgId(25L);
creditGrantingInfo.setUserId(userInfo.getId());
creditGrantingInfo.setOrgId(userInfo.getOrgId());
//判断财务数据为空的情况不计算
if (StringUtils.isEmpty(creditGrantingInfo.getFinanceInfoList())||creditGrantingInfo.getFinanceInfoList().size()==0){
return AjaxResult.error("财务数据异常,平台不支持授信!");
}
//如果历史交易数据不为空,则解析
if (StringUtils.isNotEmpty(creditGrantingInfo.getHistoricalTransactionsAnnex())){
HistoricalTransactions historicalTransactions = changeHistoricalTransactionsAnnex(creditGrantingInfo.getHistoricalTransactionsAnnex());
creditGrantingInfo.setHistoricalTransactions(null!=historicalTransactions?JSON.toJSONString(historicalTransactions):null);
}
creditGrantingInfo=creditGrantingInfoService.calculateCreditIndicators(creditGrantingInfo);
creditGrantingInfo.setCreditLimitLast(creditGrantingInfo.getCreditLimit());
List<FinanceInfo> financeInfoList = creditGrantingInfo.getFinanceInfoList();
creditGrantingInfoService.updateCreditGrantingInfo(creditGrantingInfo);
CreditGrantingRisk creditGrantingRisk=creditGrantingRiskService.insert(creditGrantingInfo.getId(), creditGrantingInfo.getEname());
return toAjax(creditGrantingInfo.getId());
}
public HistoricalTransactions changeHistoricalTransactionsAnnex(String annex){
try{
String string = JSONObject.parseObject(annex).getString("url");
URL url=new URL(string);
InputStream inputStream = url.openStream();
com.lhcredit.common.utils.poi.ExcelUtil<HistoricalTransactions> utils=new com.lhcredit.common.utils.poi.ExcelUtil<HistoricalTransactions>(HistoricalTransactions.class);
List<HistoricalTransactions> historicalTransactions = utils.importExcel(inputStream);
return historicalTransactions.stream().sorted(Comparator.comparing(HistoricalTransactions::getYear).reversed()).collect(Collectors.toList()).get(0);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}