CreditLineController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. package com.huyi.service.creditLine.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.huyi.service.base.entity.*;
  6. import com.huyi.service.base.service.*;
  7. import com.huyi.service.creditLine.service.CreditLineService;
  8. import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
  9. import com.tianhu.common.core.constant.SalaryConstants;
  10. import com.tianhu.common.core.domain.R;
  11. import com.tianhu.common.core.utils.*;
  12. import com.tianhu.common.core.web.controller.BaseController;
  13. import com.tianhu.common.core.web.domain.AjaxResult;
  14. import com.tianhu.common.log.annotation.Log;
  15. import com.tianhu.common.log.enums.BusinessType;
  16. import com.tianhu.common.security.annotation.PreAuthorize;
  17. import com.tianhu.common.security.service.TokenService;
  18. import com.tianhu.system.api.domain.SysUser;
  19. import com.tianhu.system.api.model.LoginUser;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import org.springframework.web.bind.annotation.*;
  24. import javax.servlet.ServletOutputStream;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.io.FileNotFoundException;
  27. import java.io.IOException;
  28. import java.io.InputStream;
  29. import java.math.BigDecimal;
  30. import java.net.MalformedURLException;
  31. import java.net.URL;
  32. import java.net.URLConnection;
  33. import java.net.URLEncoder;
  34. import java.text.SimpleDateFormat;
  35. import java.util.*;
  36. import java.util.regex.Pattern;
  37. /**
  38. * 授信额度Controller
  39. *
  40. * @author pxh
  41. * @date 2021-02-04
  42. */
  43. @RestController
  44. @RequestMapping("/creditLine")
  45. public class CreditLineController extends BaseController {
  46. @Autowired
  47. private TokenService tokenService;
  48. @Autowired
  49. private CreditLineService creditLineService;
  50. @Autowired
  51. private IZcFinanceInfService zcFinanceInfService;
  52. @Autowired
  53. private IZcFinanceProComRelService iZcFinanceProComRelService;
  54. @Autowired
  55. private IZcFinanceQuotaConRelService iZcFinanceQuotaConRelService;
  56. @Autowired
  57. private IZcFinanceContractService iZcFinanceContractService;
  58. @Autowired
  59. private IZcFinanceSupplierQuotaService iZcFinanceSupplierQuotaService;
  60. @Autowired
  61. private IPubFileInfService iPubFileInfService;
  62. public final static String REGEX = "^\\d\\.([0-9]{1,2}|[0-9][0-9])$|^[0-9]\\d{0,1}(\\.\\d{1,2}){0,1}$|^100(\\.0{1,2}){0,1}$";
  63. /**
  64. * 查询授信额度列表
  65. */
  66. @PreAuthorize(hasPermi = "credit:line:list")
  67. @GetMapping("/list")
  68. public R list(//资金方名称
  69. @RequestParam(required=false) String rzScyName,
  70. //授信额度范围
  71. @RequestParam (required=false) String AmountA,
  72. //授信额度范围
  73. @RequestParam (required=false) String AmountB,
  74. //状态(00:有效 01:失效)
  75. @RequestParam (required=false) String zfpcrStatus,
  76. //开始日期
  77. @RequestParam (required = false) Map startTime,
  78. //结束日期
  79. @RequestParam (required = false) Map endTime,
  80. //授信类型(融资产品类型)
  81. @RequestParam (required = false) String zfpType,
  82. //融资产品
  83. @RequestParam (required = false) String zfpName,
  84. //类型
  85. @RequestParam (required = false) String zfpcrQuery,
  86. @RequestParam (required = false) String zfpcrValue,
  87. QueryRequest request) {
  88. //查询当前操作员
  89. LoginUser userInfo = tokenService.getLoginUser();
  90. SysUser user = userInfo.getSysUser();
  91. //获取企业
  92. String companyId = user.getCompanyId();
  93. //获取企业类型
  94. String companyType = user.getCompanyType();
  95. Map map = new HashMap();
  96. if (!SalaryConstants.OPEX.equals(companyId)) {
  97. map.put("companyId", companyId);
  98. }
  99. //企业类型
  100. map.put("companyType",companyType);
  101. //授信额度范围
  102. // if (CommonUtil.isNotEmpty(AmountA)) {
  103. // map.put("AmountA", CommonUtil.objToBigDecimal(AmountA));
  104. // }
  105. // if (CommonUtil.isNotEmpty(AmountB)) {
  106. // map.put("AmountB", CommonUtil.objToBigDecimal(AmountB));
  107. // }
  108. //类型
  109. if ("00".equals(zfpcrQuery)){
  110. //资金方
  111. map.put("rzScyName",zfpcrValue);
  112. }else if ("01".equals(zfpcrQuery)){
  113. //融资产品名称
  114. map.put("zfpName",zfpcrValue);
  115. }else if ("02".equals(zfpcrQuery)){
  116. //企业名称
  117. map.put("scyName",zfpcrValue);
  118. }
  119. //状态状态(00:有效 01:失效)
  120. if (!"02".equals(zfpcrStatus)) {
  121. map.put("zfpcrStatus", zfpcrStatus);
  122. }
  123. //开始日期区间
  124. map.put("startTimeA",startTime.get("startTime[0]"));
  125. map.put("startTimeB",startTime.get("startTime[1]"));
  126. //结束日期区间
  127. map.put("endTimeA",endTime.get("endTime[0]"));
  128. map.put("endTimeB",endTime.get("endTime[1]"));
  129. //授信类型(融资产品类型)
  130. if (!"2".equals(zfpType)) {
  131. map.put("zfpType", zfpType);
  132. }
  133. //供应商
  134. if ("02".equals(companyType)){
  135. IPage<Map> list = creditLineService.selectSupplierCreditList(map, request);
  136. List listAll = list.getRecords();
  137. for (int j = 0; j < listAll.size(); j++) {
  138. Map<String, String> m = (Map<String, String>) listAll.get(j);
  139. //授信额度
  140. String zfsqAmount = m.get("zfsqAmount");
  141. //授信id
  142. String zfsqId = m.get("zfsqId");
  143. //通过融资产品查询融信表申请金额
  144. QueryWrapper<ZcFinanceInf> queryWrapper = new QueryWrapper<>();
  145. //授信id
  146. queryWrapper.in("zfi_supplier_quota_id", zfsqId);
  147. //状态(00:待确权 01:待签收 02:已生效 03:已失效 04:融资中 05:已融资 06:平台退回 07:已失效(到期失效)08:已失效(还款成功失效)99:删除)
  148. //queryWrapper.and(i -> i.ne("zfi_status", "00").or().ne("zfi_status", "03"));
  149. queryWrapper.notIn("zfi_status","00","03","07","08");
  150. queryWrapper.select("IFNULL(CAST(ROUND(SUM(zfi_amount),2)AS CHAR),'0.00') AS zfiAmount");
  151. ZcFinanceInf zcFinanceInf = zcFinanceInfService.getOne(queryWrapper);
  152. //申请金额(已用)
  153. String zfiAmount = "0.00";
  154. if (zcFinanceInf != null) {
  155. zfiAmount = zcFinanceInf.getZfiAmount();
  156. }
  157. //可用额度(授信额度 - 申请金额)
  158. String usableAmount = AmtUtil.subtract(zfsqAmount, zfiAmount, 2);
  159. //已使用额度
  160. m.put("zfiAmount", zfiAmount);
  161. //可用额度
  162. m.put("usableAmount", usableAmount);
  163. //企业类型
  164. m.put("companyType", companyType);
  165. }
  166. return R.ok(list);
  167. }else {
  168. IPage<Map> list = creditLineService.selectCreditLineList(map, request);
  169. List listAll = list.getRecords();
  170. for (int j = 0; j < listAll.size(); j++) {
  171. Map<String, String> m = (Map<String, String>) listAll.get(j);
  172. //授信额度
  173. String zfpcrAmount = m.get("zfpcrAmount");
  174. //授信id
  175. String zfpcrId = m.get("zfpcrId");
  176. //融资产品
  177. String zfpcrProductId = m.get("zfpcrProductId");
  178. //融资产品方向(0:正向,1反向)
  179. String zfpTypes = m.get("zfpType");
  180. //通过融资产品查询融信表申请金额
  181. QueryWrapper<ZcFinanceInf> queryWrapper = new QueryWrapper<>();
  182. //授信id
  183. queryWrapper.in("zfi_core_quota_id", zfpcrId);
  184. //状态(00:待确权 01:待签收 02:已生效 03:已失效 04:融资中 05:已融资 06:平台退回 07:已失效(到期失效)08:已失效(还款成功失效)99:删除)
  185. //queryWrapper.and(i -> i.ne("zfi_status", "00").or().ne("zfi_status", "03"));
  186. queryWrapper.notIn("zfi_status","00","03","07","08");
  187. queryWrapper.select("IFNULL(CAST(ROUND(SUM(zfi_amount),2)AS CHAR),'0.00') AS zfiAmount");
  188. ZcFinanceInf zcFinanceInf = zcFinanceInfService.getOne(queryWrapper);
  189. //申请金额(已用)
  190. String zfiAmount = "0.00";
  191. if (zcFinanceInf != null) {
  192. zfiAmount = zcFinanceInf.getZfiAmount();
  193. }
  194. //可用额度(反向保理:授信额度 - 申请金额;正向保理:授信额度 - 已分配额度)
  195. String usableAmount = "0.00";
  196. //查询核心企业授信额度ID下的供应商授信额度总和
  197. QueryWrapper<ZcFinanceSupplierQuota> supplierQueryWrapper = new QueryWrapper<>();
  198. supplierQueryWrapper.eq("zfsq_core_quota_id", zfpcrId);
  199. supplierQueryWrapper.eq("zfsq_status","00");
  200. supplierQueryWrapper.select("IFNULL(CAST(ROUND(SUM(zfsq_amount),2)AS CHAR),'0.00') AS zfsqAmount");
  201. ZcFinanceSupplierQuota supplierQuota = iZcFinanceSupplierQuotaService.getOne(supplierQueryWrapper);
  202. //供应商已使用额度总和
  203. String totalAmount = supplierQuota.getZfsqAmount();
  204. //已使用额度
  205. m.put("zfiAmount", zfiAmount);
  206. //可用额度(正向保理:授信额度 - 已分配额度)
  207. if ("0".equals(zfpTypes)){
  208. usableAmount = AmtUtil.subtract(zfpcrAmount, totalAmount, 2);
  209. }
  210. //可用额度(反向保理:授信额度 - 申请金额)
  211. else if ("1".equals(zfpTypes)){
  212. usableAmount = AmtUtil.subtract(zfpcrAmount, zfiAmount, 2);
  213. }
  214. m.put("usableAmount", usableAmount);
  215. //企业类型
  216. m.put("companyType", companyType);
  217. //供应商授信额度
  218. m.put("supplierAmount", totalAmount);
  219. }
  220. return R.ok(list);
  221. }
  222. }
  223. /**
  224. * 授信额度信息详情
  225. */
  226. @PreAuthorize(hasPermi = "credit:line:query")
  227. @GetMapping(value = "/{zfpcrId}")
  228. public AjaxResult getInfo(@PathVariable("zfpcrId") String zfpcrId)
  229. {
  230. Map result = new HashMap();
  231. //授信信息
  232. Map map = new HashMap();
  233. map.put("zfpcrId",zfpcrId);
  234. List<Map> list = creditLineService.selectCreditLineDetail(map);
  235. //授信合同信息关联表
  236. LambdaQueryWrapper<ZcFinanceQuotaConRel> queryWrapper = new LambdaQueryWrapper<>();
  237. queryWrapper.eq(ZcFinanceQuotaConRel::getZfqcrCreditId,zfpcrId);
  238. List<ZcFinanceQuotaConRel> quotaConRelList = iZcFinanceQuotaConRelService.findZcFinanceQuotaConRels(queryWrapper);
  239. List id = new ArrayList();
  240. for (int i = 0; i < quotaConRelList.size(); i++) {
  241. String contractId = quotaConRelList.get(i).getZfqcrContractId();
  242. id.add(contractId);
  243. }
  244. //通过主键查询合同表
  245. if (id.size() > 0) {
  246. Map map1 = new HashMap();
  247. map1.put("id",CommonUtil.listToStr4InSql(id));
  248. List<Map> contractList = creditLineService.selectContractList(map1);
  249. // LambdaQueryWrapper<ZcFinanceContract> contractWrapper = new LambdaQueryWrapper<>();
  250. // contractWrapper.in(ZcFinanceContract::getZfcId, id);
  251. // List<ZcFinanceContract> contractList = iZcFinanceContractService.findZcFinanceContracts(contractWrapper);
  252. // for (int i = 0; i < contractList.size(); i++) {
  253. // String zfcFile = contractList.get(i).getZfcFile();
  254. // PubFileInf pubFileInf = iPubFileInfService.getById(zfcFile);
  255. // String pfiUrl = pubFileInf.getPfiUrl();
  256. //
  257. // }
  258. result.put("ticketList",contractList);
  259. }
  260. result.put("list",list);
  261. return AjaxResult.success(result);
  262. }
  263. /**
  264. * 新增授信管理
  265. * @param map
  266. * @return
  267. * @throws Exception
  268. */
  269. @PreAuthorize(hasPermi = "credit:line:add")
  270. @Log(title = "授信管理", businessType = BusinessType.INSERT)
  271. @Transactional(rollbackFor = Exception.class)
  272. @PostMapping
  273. public AjaxResult add(@RequestBody Map<String,Object> map)throws Exception
  274. {
  275. //获取此操作员
  276. LoginUser userInfo = tokenService.getLoginUser();
  277. SysUser user = userInfo.getSysUser();
  278. String userId = user.getUserId() + "";
  279. //融资产品
  280. String zfpcrProductId = CommonUtil.objToString(map.get("zfpcrProductId"));
  281. //授信企业名称
  282. String zfpcrCompanyId = CommonUtil.objToString(map.get("zfpcrCompanyId"));
  283. //授信额度
  284. String zfpcrAmount = CommonUtil.objToString(map.get("zfpcrAmount"));
  285. //利率
  286. String zfpcrRate = CommonUtil.objToString(map.get("zfpcrRate"));
  287. //有效期
  288. String zfpcrDateType = CommonUtil.objToString(map.get("zfpcrDateType"));
  289. //日期范围
  290. List<String> dateTime = (List<String>) map.get("dateTime");
  291. //开始日期
  292. String zfpcrStartDate = "";
  293. //结束日期
  294. String zfpcrEndDate = "";
  295. if ("1".equals(zfpcrDateType)) {
  296. if (dateTime != null && !dateTime.isEmpty()) {
  297. //开始日期
  298. zfpcrStartDate = dateTime.get(0);
  299. //结束日期
  300. zfpcrEndDate = dateTime.get(1);
  301. }
  302. }
  303. //融资网点
  304. String zfpcrAddress = CommonUtil.objToString(map.get("zfpcrAddress"));
  305. //是否收取手续费(0:不收取, 1收取)
  306. String zfpcrCharge = CommonUtil.objToString(map.get("zfpcrCharge"));
  307. //平台服务费收取费率
  308. String zfpcrChargeRate = CommonUtil.objToString(map.get("zfpcrChargeRate"));
  309. //核心企业还款账户账号
  310. String zfpcrAccount = CommonUtil.objToString(map.get("zfpcrAccount"));
  311. //核心企业还款账户开户行
  312. String zfpcrAccountBank = CommonUtil.objToString(map.get("zfpcrAccountBank"));
  313. //融资放款方式
  314. String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  315. //记账簿托管方式
  316. String zfpcrBookkeepingType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  317. //校验百分百
  318. Pattern pattern = Pattern.compile(REGEX);
  319. //融资产品
  320. if(CommonUtil.isEmpty(zfpcrProductId)){
  321. return AjaxResult.error("融资产品不能为空");
  322. }
  323. LambdaQueryWrapper<ZcFinanceProComRel> queryWrapper = new LambdaQueryWrapper<>();
  324. queryWrapper.eq(ZcFinanceProComRel::getZfpcrProductId,zfpcrProductId);
  325. queryWrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,zfpcrCompanyId);
  326. int count = iZcFinanceProComRelService.count(queryWrapper);
  327. if (count > 0){
  328. return AjaxResult.error("此企业已授信该融资产品");
  329. }
  330. //授信企业名称
  331. if(CommonUtil.isEmpty(zfpcrCompanyId)){
  332. return AjaxResult.error("授信企业名称不能为空");
  333. }
  334. //授信额度
  335. if(CommonUtil.isNotEmpty(zfpcrAmount)) {
  336. if(AmtUtil.isMoney(zfpcrAmount) == false) {
  337. return AjaxResult.error("请输入正确的授信额度");
  338. }
  339. }else {
  340. return AjaxResult.error("授信额度不能为空");
  341. }
  342. //利率
  343. if(CommonUtil.isNotEmpty(zfpcrRate)) {
  344. if(!pattern.matcher(zfpcrRate).matches()) {
  345. return AjaxResult.error("请输入正确的利率");
  346. }
  347. }else {
  348. return AjaxResult.error("利率不能为空");
  349. }
  350. //有效期
  351. if(CommonUtil.isEmpty(zfpcrDateType)){
  352. return AjaxResult.error("有效期不能为空");
  353. }
  354. //时间范围
  355. if ("1".equals(zfpcrDateType)){
  356. //时间范围
  357. if(dateTime.size() == 0){
  358. return AjaxResult.error("时间范围不能为空");
  359. }
  360. }
  361. //是否收取手续费(0:不收取, 1收取)
  362. if(CommonUtil.isEmpty(zfpcrCharge)){
  363. return AjaxResult.error("是否收取手续费不能为空");
  364. }
  365. //平台服务费收取费率
  366. if("1".equals(zfpcrCharge)){
  367. if(CommonUtil.isNotEmpty(zfpcrChargeRate)) {
  368. if(!pattern.matcher(zfpcrChargeRate).matches()) {
  369. return AjaxResult.error("请输入正确的平台服务费收取费率");
  370. }
  371. }else {
  372. return AjaxResult.error("平台服务费收取费率不能为空");
  373. }
  374. }
  375. //核心企业还款账户账号
  376. if(CommonUtil.isEmpty(zfpcrAccount)){
  377. return AjaxResult.error("核心企业还款账户账号不能为空");
  378. }
  379. //核心企业还款账户账号
  380. if(CommonUtil.isEmpty(zfpcrAccountBank)){
  381. return AjaxResult.error("核心企业还款账户开户行不能为空");
  382. }
  383. if (zfpcrAccountBank.length() > 30){
  384. return AjaxResult.error("核心企业还款账户开户行长度过长");
  385. }
  386. //融资放款方式
  387. if(CommonUtil.isEmpty(zfpcrLoanType)){
  388. return AjaxResult.error("融资放款方式不能为空");
  389. }
  390. //记账簿托管方式
  391. if(CommonUtil.isEmpty(zfpcrBookkeepingType)){
  392. return AjaxResult.error("记账簿托管方式不能为空");
  393. }
  394. //合同信息
  395. List<Map<String, String>> tableData = (List<Map<String, String>>) map.get("ticketList");
  396. // if (tableData.size() == 0 ){
  397. // return AjaxResult.error("请选择合同信息");
  398. // }
  399. //执行新增
  400. ZcFinanceProComRel zcFinanceProComRel = new ZcFinanceProComRel();
  401. //主键
  402. String zfpcrId = IdUtils.fastSimpleUUID();
  403. zcFinanceProComRel.setZfpcrId(zfpcrId);
  404. //融资产品
  405. zcFinanceProComRel.setZfpcrProductId(zfpcrProductId);
  406. //授信企业名称
  407. zcFinanceProComRel.setZfpcrCompanyId(zfpcrCompanyId);
  408. //授信额度
  409. zcFinanceProComRel.setZfpcrAmount(zfpcrAmount);
  410. //原授信额度(如果授信额度没做修改,原授信额度不变
  411. zcFinanceProComRel.setZfpcrOldAmount(zfpcrAmount);
  412. //利率
  413. zcFinanceProComRel.setZfpcrRate(zfpcrRate);
  414. //有效期
  415. zcFinanceProComRel.setZfpcrDateType(zfpcrDateType);
  416. //开始日期
  417. zcFinanceProComRel.setZfpcrStartDate(zfpcrStartDate);
  418. //结束日期
  419. zcFinanceProComRel.setZfpcrEndDate(zfpcrEndDate);
  420. //融资网点
  421. zcFinanceProComRel.setZfpcrAddress(zfpcrAddress);
  422. //是否收取手续费(0:不收取, 1收取)
  423. zcFinanceProComRel.setZfpcrCharge(zfpcrCharge);
  424. //收取服务费
  425. if("1".equals(zfpcrCharge)){
  426. //平台服务费收取费率
  427. zcFinanceProComRel.setZfpcrChargeRate(zfpcrChargeRate);
  428. }else{
  429. zcFinanceProComRel.setZfpcrChargeRate("0.00");
  430. }
  431. //核心企业还款账户账号
  432. zcFinanceProComRel.setZfpcrAccount(zfpcrAccount);
  433. //核心企业还款账户开户行
  434. zcFinanceProComRel.setZfpcrAccountBank(zfpcrAccountBank);
  435. //融资放款方式
  436. zcFinanceProComRel.setZfpcrLoanType(zfpcrLoanType);
  437. //记账簿托管方式
  438. zcFinanceProComRel.setZfpcrBookkeepingType(zfpcrBookkeepingType);
  439. //状态(00:有效 01:失效)
  440. zcFinanceProComRel.setZfpcrStatus("00");
  441. //创建人
  442. zcFinanceProComRel.setCreateBy(userId);
  443. //创建时间
  444. zcFinanceProComRel.setCreateTime(DateUtils.getNowDate());
  445. iZcFinanceProComRelService.createZcFinanceProComRel(zcFinanceProComRel);
  446. //新增授信合同关联表
  447. for (int i = 0; i < tableData.size(); i++) {
  448. if (tableData != null) {
  449. String zfcId = tableData.get(i).get("zfcId");
  450. ZcFinanceQuotaConRel zcFinanceQuotaConRel = new ZcFinanceQuotaConRel();
  451. //合同id
  452. zcFinanceQuotaConRel.setZfqcrContractId(zfcId);
  453. //授信id
  454. zcFinanceQuotaConRel.setZfqcrCreditId(zfpcrId);
  455. iZcFinanceQuotaConRelService.createZcFinanceQuotaConRel(zcFinanceQuotaConRel);
  456. }
  457. }
  458. return AjaxResult.success();
  459. }
  460. /**
  461. * 修改授信管理
  462. * @param map
  463. * @return
  464. * @throws Exception
  465. */
  466. @PreAuthorize(hasPermi = "credit:line:edit")
  467. @Log(title = "授信管理", businessType = BusinessType.UPDATE)
  468. @Transactional(rollbackFor = Exception.class)
  469. @PutMapping
  470. public AjaxResult update(@RequestBody Map<String,Object> map)throws Exception
  471. {
  472. //主键
  473. String zfpcrId = CommonUtil.objToString(map.get("zfpcrId"));
  474. //获取此操作员
  475. LoginUser userInfo = tokenService.getLoginUser();
  476. SysUser user = userInfo.getSysUser();
  477. String userId = user.getUserId() + "";
  478. //融资产品
  479. String zfpcrProductId = CommonUtil.objToString(map.get("zfpcrProductId"));
  480. //授信企业名称
  481. String zfpcrCompanyId = CommonUtil.objToString(map.get("zfpcrCompanyId"));
  482. //授信额度
  483. String zfpcrAmount = CommonUtil.objToString(map.get("zfpcrAmount"));
  484. //原授信额度
  485. String zfpcrOldAmount = CommonUtil.objToString(map.get("zfpcrOldAmount"));
  486. //利率
  487. String zfpcrRate = CommonUtil.objToString(map.get("zfpcrRate"));
  488. //有效期
  489. String zfpcrDateType = CommonUtil.objToString(map.get("zfpcrDateType"));
  490. //日期范围
  491. List<String> dateTime = (List<String>) map.get("dateTime");
  492. //开始日期
  493. String zfpcrStartDate = "";
  494. //结束日期
  495. String zfpcrEndDate = "";
  496. if (dateTime != null) {
  497. //开始日期
  498. zfpcrStartDate = dateTime.get(0);
  499. //结束日期
  500. zfpcrEndDate = dateTime.get(1);
  501. }
  502. //融资网点
  503. String zfpcrAddress = CommonUtil.objToString(map.get("zfpcrAddress"));
  504. //是否收取手续费(0:不收取, 1收取)
  505. String zfpcrCharge = CommonUtil.objToString(map.get("zfpcrCharge"));
  506. //平台服务费收取费率
  507. String zfpcrChargeRate = CommonUtil.objToString(map.get("zfpcrChargeRate"));
  508. //核心企业还款账户账号
  509. String zfpcrAccount = CommonUtil.objToString(map.get("zfpcrAccount"));
  510. //核心企业还款账户开户行
  511. String zfpcrAccountBank = CommonUtil.objToString(map.get("zfpcrAccountBank"));
  512. //融资放款方式
  513. String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  514. //记账簿托管方式
  515. String zfpcrBookkeepingType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  516. //校验百分百
  517. Pattern pattern = Pattern.compile(REGEX);
  518. //融资产品
  519. if(CommonUtil.isEmpty(zfpcrProductId)){
  520. return AjaxResult.error("融资产品不能为空");
  521. }
  522. LambdaQueryWrapper<ZcFinanceProComRel> wrapper = new LambdaQueryWrapper<>();
  523. wrapper.eq(ZcFinanceProComRel::getZfpcrProductId,zfpcrProductId);
  524. wrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,zfpcrCompanyId);
  525. wrapper.ne(ZcFinanceProComRel::getZfpcrId,zfpcrId);
  526. int count = iZcFinanceProComRelService.count(wrapper);
  527. if (count > 0){
  528. return AjaxResult.error("此企业已授信盖融资产品");
  529. }
  530. //授信企业名称
  531. if(CommonUtil.isEmpty(zfpcrCompanyId)){
  532. return AjaxResult.error("授信企业名称不能为空");
  533. }
  534. //授信额度
  535. if(CommonUtil.isNotEmpty(zfpcrAmount)) {
  536. if(AmtUtil.isMoney(zfpcrAmount) == false) {
  537. return AjaxResult.error("请输入正确的授信额度");
  538. }
  539. }else {
  540. return AjaxResult.error("授信额度不能为空");
  541. }
  542. //利率
  543. if(CommonUtil.isNotEmpty(zfpcrRate)) {
  544. if(!pattern.matcher(zfpcrRate).matches()) {
  545. return AjaxResult.error("请输入正确的利率");
  546. }
  547. }else {
  548. return AjaxResult.error("利率不能为空");
  549. }
  550. //有效期
  551. if(CommonUtil.isEmpty(zfpcrDateType)){
  552. return AjaxResult.error("有效期不能为空");
  553. }
  554. //时间范围
  555. if ("1".equals(zfpcrDateType)){
  556. //时间范围
  557. if(dateTime.size() == 0){
  558. return AjaxResult.error("时间范围不能为空");
  559. }
  560. }
  561. //是否收取手续费(0:不收取, 1收取)
  562. if(CommonUtil.isEmpty(zfpcrCharge)){
  563. return AjaxResult.error("是否收取手续费不能为空");
  564. }
  565. //平台服务费收取费率
  566. if("1".equals(zfpcrCharge)){
  567. if(CommonUtil.isNotEmpty(zfpcrChargeRate)) {
  568. if(!pattern.matcher(zfpcrChargeRate).matches()) {
  569. return AjaxResult.error("请输入正确的平台服务费收取费率");
  570. }
  571. }else {
  572. return AjaxResult.error("平台服务费收取费率不能为空");
  573. }
  574. }
  575. //核心企业还款账户账号
  576. if(CommonUtil.isEmpty(zfpcrAccount)){
  577. return AjaxResult.error("核心企业还款账户账号不能为空");
  578. }
  579. //核心企业还款账户账号
  580. if(CommonUtil.isEmpty(zfpcrAccountBank)){
  581. return AjaxResult.error("核心企业还款账户开户行不能为空");
  582. }
  583. if (zfpcrAccountBank.length() > 30){
  584. return AjaxResult.error("核心企业还款账户开户行长度过长");
  585. }
  586. //融资放款方式
  587. if(CommonUtil.isEmpty(zfpcrLoanType)){
  588. return AjaxResult.error("融资放款方式不能为空");
  589. }
  590. //记账簿托管方式
  591. if(CommonUtil.isEmpty(zfpcrBookkeepingType)){
  592. return AjaxResult.error("记账簿托管方式不能为空");
  593. }
  594. //合同信息
  595. List<Map<String, String>> tableData = (List<Map<String, String>>) map.get("ticketList");
  596. // if (tableData.size() == 0 ){
  597. // return AjaxResult.error("请选择合同信息");
  598. // }
  599. //执行修改
  600. ZcFinanceProComRel zcFinanceProComRel = new ZcFinanceProComRel();
  601. //主键
  602. zcFinanceProComRel.setZfpcrId(zfpcrId);
  603. //融资产品
  604. zcFinanceProComRel.setZfpcrProductId(zfpcrProductId);
  605. //授信企业名称
  606. zcFinanceProComRel.setZfpcrCompanyId(zfpcrCompanyId);
  607. //授信额度
  608. zcFinanceProComRel.setZfpcrAmount(zfpcrAmount);
  609. //原授信额度(如果授信额度没做修改,原授信额度不变
  610. if (!zfpcrAmount.equals(zfpcrOldAmount)) {
  611. zcFinanceProComRel.setZfpcrOldAmount(zfpcrOldAmount);
  612. }
  613. //利率
  614. zcFinanceProComRel.setZfpcrRate(zfpcrRate);
  615. //有效期
  616. zcFinanceProComRel.setZfpcrDateType(zfpcrDateType);
  617. if ("1".equals(zfpcrDateType)) {
  618. //开始日期
  619. zcFinanceProComRel.setZfpcrStartDate(zfpcrStartDate);
  620. //结束日期
  621. zcFinanceProComRel.setZfpcrEndDate(zfpcrEndDate);
  622. }else{
  623. //开始日期
  624. zcFinanceProComRel.setZfpcrStartDate("");
  625. //结束日期
  626. zcFinanceProComRel.setZfpcrEndDate("");
  627. }
  628. //融资网点
  629. zcFinanceProComRel.setZfpcrAddress(zfpcrAddress);
  630. //是否收取手续费(0:不收取, 1收取)
  631. zcFinanceProComRel.setZfpcrCharge(zfpcrCharge);
  632. //收取服务费
  633. if("1".equals(zfpcrCharge)){
  634. //平台服务费收取费率
  635. zcFinanceProComRel.setZfpcrChargeRate(zfpcrChargeRate);
  636. }else{
  637. zcFinanceProComRel.setZfpcrChargeRate("0.00");
  638. }
  639. //核心企业还款账户账号
  640. zcFinanceProComRel.setZfpcrAccount(zfpcrAccount);
  641. //核心企业还款账户开户行
  642. zcFinanceProComRel.setZfpcrAccountBank(zfpcrAccountBank);
  643. //融资放款方式
  644. zcFinanceProComRel.setZfpcrLoanType(zfpcrLoanType);
  645. //记账簿托管方式
  646. zcFinanceProComRel.setZfpcrBookkeepingType(zfpcrBookkeepingType);
  647. //修改人
  648. zcFinanceProComRel.setUpdateBy(userId);
  649. //修改时间
  650. zcFinanceProComRel.setUpdateTime(DateUtils.getNowDate());
  651. iZcFinanceProComRelService.updateZcFinanceProComRel(zcFinanceProComRel);
  652. //查询原合同信息详情并删除
  653. LambdaQueryWrapper<ZcFinanceQuotaConRel> queryWrapper = new LambdaQueryWrapper<>();
  654. queryWrapper.eq(ZcFinanceQuotaConRel::getZfqcrCreditId,zfpcrId);
  655. List<ZcFinanceQuotaConRel> list = iZcFinanceQuotaConRelService.findZcFinanceQuotaConRels(queryWrapper);
  656. for (int i = 0; i < list.size(); i++) {
  657. LambdaQueryWrapper<ZcFinanceQuotaConRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  658. lambdaQueryWrapper.eq(ZcFinanceQuotaConRel::getZfqcrCreditId,list.get(i).getZfqcrCreditId());
  659. iZcFinanceQuotaConRelService.deleteZcFinanceQuotaConRel(lambdaQueryWrapper);
  660. }
  661. //新增授信合同
  662. // 关联表
  663. if (tableData != null && !tableData.isEmpty()) {
  664. for (int i = 0; i < tableData.size(); i++) {
  665. String zfcId = tableData.get(i).get("zfcId");
  666. ZcFinanceQuotaConRel zcFinanceQuotaConRel = new ZcFinanceQuotaConRel();
  667. //合同id
  668. zcFinanceQuotaConRel.setZfqcrContractId(zfcId);
  669. //授信id
  670. zcFinanceQuotaConRel.setZfqcrCreditId(zfpcrId);
  671. iZcFinanceQuotaConRelService.createZcFinanceQuotaConRel(zcFinanceQuotaConRel);
  672. }
  673. }
  674. return AjaxResult.success();
  675. }
  676. /**
  677. * 状态修改
  678. */
  679. @PreAuthorize(hasPermi = "credit:line:update")
  680. @Log(title = "授信管理", businessType = BusinessType.UPDATE)
  681. @Transactional(rollbackFor = Exception.class)
  682. @PutMapping("/changeStatus")
  683. public AjaxResult changeStatus(@RequestBody Map<String, String> map) throws Exception
  684. {
  685. //授信id
  686. String zfpcrId = map.get("zfpcrId");
  687. //已使用金额
  688. String zfiAmount = map.get("zfiAmount");
  689. //授信状态
  690. String zfpcrStatus = map.get("zfpcrStatus");
  691. ZcFinanceProComRel proComRel = iZcFinanceProComRelService.getById(zfpcrId);
  692. //到期时间
  693. String zfpcrEndDate = proComRel.getZfpcrEndDate();
  694. //开始日期
  695. String zfpcrStartDate = proComRel.getZfpcrStartDate();
  696. ZcFinanceProComRel zcFinanceProComRel = new ZcFinanceProComRel();
  697. //授信id
  698. zcFinanceProComRel.setZfpcrId(zfpcrId);
  699. //判断状态(如果是冻结操作判断是否符合冻结条件
  700. if ("00".equals(zfpcrStatus)) {
  701. if ("0.00".equals(zfiAmount)) {
  702. zcFinanceProComRel.setZfpcrStatus("01");
  703. iZcFinanceProComRelService.updateZcFinanceProComRel(zcFinanceProComRel);
  704. }else {
  705. return AjaxResult.error("此授信正在使用无法冻结");
  706. }
  707. }else {
  708. if (CommonUtil.isNotEmpty(zfpcrEndDate) && CommonUtil.isNotEmpty(zfpcrStartDate)){
  709. Date EndDate = DateUtils.parseDate(zfpcrEndDate,"yyyy-MM-dd");
  710. zfpcrEndDate = DateUtils.parseDateToStr("yyyyMMdd",EndDate);
  711. //当前时间
  712. String currentDate = DateUtils.dateTimeNow("yyyyMMdd");
  713. int result = CommonUtil.compare(zfpcrEndDate,currentDate);
  714. Date beginDate = DateUtils.parseDate(zfpcrStartDate,"yyyy-MM-dd");
  715. zfpcrStartDate = DateUtils.parseDateToStr("yyyyMMdd",beginDate);
  716. //当前日期和开始日期比较
  717. int ending = CommonUtil.compare(zfpcrStartDate,currentDate);
  718. //小于开始日期或者大于结束日期
  719. if (ending == 1 || result == -1 ){
  720. return AjaxResult.error("请先修改授信的有效期范围,只有在有效期范围内才可以解冻");
  721. }
  722. }
  723. zcFinanceProComRel.setZfpcrStatus("00");
  724. iZcFinanceProComRelService.updateZcFinanceProComRel(zcFinanceProComRel);
  725. }
  726. return AjaxResult.success();
  727. }
  728. public static void main(String args[]){
  729. //到期时间
  730. String zfpcrEndDate = "2021-11-02";
  731. Date EndDate = DateUtils.dateTime("yyyy-MM-dd",zfpcrEndDate);
  732. zfpcrEndDate = DateUtils.parseDateToStr("yyyyMMdd",EndDate);
  733. //当前时间
  734. String currentDate = DateUtils.dateTimeNow("yyyyMMdd");
  735. int a = CommonUtil.compare(zfpcrEndDate,currentDate);
  736. System.out.println(a);
  737. }
  738. /**
  739. * 文件下载
  740. * @param pfiFileUrl 文件url
  741. * @param resp
  742. * @throws MalformedURLException
  743. */
  744. @PostMapping("/jpgAuthorization")
  745. public void jpgAuthorization(@RequestParam(required=false) String pfiFileUrl, HttpServletResponse resp) throws MalformedURLException {
  746. // 下载网络文件
  747. int bytesum = 0;
  748. int byteread = 0;
  749. URL url = new URL(pfiFileUrl);
  750. try {
  751. URLConnection conn = url.openConnection();
  752. InputStream fis = conn.getInputStream();
  753. //1、得到文件的绝对路径,并且通过该路径得到一个字节输入流
  754. //2、创建字节输出流
  755. ServletOutputStream sos = resp.getOutputStream();
  756. //4、设置文件编码
  757. String filename = URLEncoder.encode("file.png", "UTF-8");//编码为UTF-8
  758. //5、告知客户端(浏览器)要下载文件
  759. resp.setHeader("content-disposition", "attachment;filename="+filename);
  760. resp.setHeader("content-type", "image/png/pdf/doc/docx");//文件类型
  761. //6、输出
  762. byte[] b = new byte[1024];
  763. int len = 0;
  764. while((len=fis.read(b)) != -1){
  765. sos.write(b, 0, len);
  766. }
  767. sos.close();
  768. fis.close();
  769. } catch (FileNotFoundException e) {
  770. e.printStackTrace();
  771. } catch (IOException e) {
  772. e.printStackTrace();
  773. }
  774. }
  775. }