|
|
@@ -0,0 +1,752 @@
|
|
|
+package com.huyi.service.financeRecord.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.huyi.service.base.entity.*;
|
|
|
+import com.huyi.service.base.service.*;
|
|
|
+import com.huyi.service.constant.FileConstants;
|
|
|
+import com.keao.tianhu.core.util.AmtUtil;
|
|
|
+import com.spire.doc.Document;
|
|
|
+import com.spire.doc.FileFormat;
|
|
|
+import com.tianhu.common.core.cfca.AxqCommonUtil;
|
|
|
+import com.tianhu.common.core.domain.R;
|
|
|
+import com.tianhu.common.core.utils.*;
|
|
|
+import com.tianhu.common.core.utils.poi.WordUtil;
|
|
|
+import com.tianhu.common.core.web.controller.BaseController;
|
|
|
+import com.tianhu.common.core.web.domain.AjaxResult;
|
|
|
+import com.tianhu.common.log.annotation.Log;
|
|
|
+import com.tianhu.common.log.enums.BusinessType;
|
|
|
+import com.tianhu.common.security.annotation.PreAuthorize;
|
|
|
+import com.tianhu.common.security.service.TokenService;
|
|
|
+import com.tianhu.system.api.RemoteConfigService;
|
|
|
+import com.tianhu.system.api.RemoteFileService;
|
|
|
+import com.tianhu.system.api.domain.SysUser;
|
|
|
+import com.tianhu.system.api.model.LoginUser;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 融资盖章
|
|
|
+ * peixh
|
|
|
+ * 2021-08-24
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/recordSeal")
|
|
|
+public class RecordSealController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TokenService tokenService;
|
|
|
+ //融信服务类
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceInfService financeInfService;
|
|
|
+ //供应商授信服务类
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceSupplierQuotaService financeSupplierQuotaService;
|
|
|
+ //融信和应收账款的关系
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceBillRelService financeBillRelService;
|
|
|
+ //授信和合同的关系表
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceQuotaConRelService quotaConRelService;
|
|
|
+ //产品和合同的关系表
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceProConRelService proConRelService;
|
|
|
+ //合同服务类
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceContractService contractService;
|
|
|
+ //文件服务类
|
|
|
+ @Autowired
|
|
|
+ private IPubFileInfService fileInfService;
|
|
|
+ //公司服务类
|
|
|
+ @Autowired
|
|
|
+ private ISysCompanyService companyService;
|
|
|
+ //银行账户表
|
|
|
+ @Autowired
|
|
|
+ private IPayBankAccInfService bankAccInfService;
|
|
|
+ //系统参数服务类
|
|
|
+ @Autowired
|
|
|
+ private RemoteConfigService configService;
|
|
|
+ //融信和文件的关系服务类
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceFileRelService financeFileRelService;
|
|
|
+ @Autowired
|
|
|
+ private RemoteFileService remoteFileService;
|
|
|
+ /**
|
|
|
+ * 获取合同文件
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PutMapping("/getContractFile")
|
|
|
+ public AjaxResult getContract(@RequestBody Map<String,Object> map)throws Exception
|
|
|
+ {
|
|
|
+
|
|
|
+ //存放合同编号
|
|
|
+ List<String> contractIdList = new ArrayList<>();
|
|
|
+ //获取授信编号
|
|
|
+ String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
|
|
|
+ //获取产品
|
|
|
+ String zfpcrProductId = CommonUtil.objToString(map.get("zfpcrProductId"));
|
|
|
+ //获取融信编号
|
|
|
+ String zfiId = CommonUtil.objToString(map.get("zfiId"));
|
|
|
+ //获取融信编号
|
|
|
+ ZcFinanceInf financeInf = financeInfService.getById(zfiId);
|
|
|
+ if(financeInf == null){
|
|
|
+ throw new Exception("获取融信信息失败");
|
|
|
+ }
|
|
|
+ //节点
|
|
|
+ String code = "01";
|
|
|
+
|
|
|
+ if(CommonUtil.isEmpty(code)){
|
|
|
+ throw new Exception("盖章节点异常");
|
|
|
+ }
|
|
|
+ //获取接收方
|
|
|
+ String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
|
|
|
+ //开立方
|
|
|
+ String zfiCoreId = CommonUtil.objToString(map.get("zfiCoreId"));
|
|
|
+ //金额
|
|
|
+ String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
|
|
|
+ //承诺还款日期
|
|
|
+ String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
|
|
|
+ //还款编号
|
|
|
+ String zfiPaymentNumber = CommonUtil.objToString(map.get("zfiPaymentNumber"));
|
|
|
+ //获取开立方
|
|
|
+ String openName = "";
|
|
|
+ //获取开立方的社会统一码
|
|
|
+ String openCode = "";
|
|
|
+ //开户银行
|
|
|
+ String openBank = "";
|
|
|
+ //账号
|
|
|
+ String openAccount = "";
|
|
|
+ //获取接收方
|
|
|
+ String receiverName = "";
|
|
|
+ //获取开立方的社会统一码
|
|
|
+ String receiverCode = "";
|
|
|
+ //开户银行
|
|
|
+ String receiverBank = "";
|
|
|
+ //账号
|
|
|
+ String receiverAccount = "";
|
|
|
+ //大写金额
|
|
|
+ String zfiAmountBig = "";
|
|
|
+ //起止日期
|
|
|
+ String stopDate = "";
|
|
|
+ SysCompany company = companyService.getById(zfiCoreId);
|
|
|
+ if(company != null){
|
|
|
+ //企业名称
|
|
|
+ openName = company.getScyName();
|
|
|
+ //社会统一代码
|
|
|
+ openCode = company.getScySocialCode();
|
|
|
+ //查询银行账号
|
|
|
+ LambdaQueryWrapper<PayBankAccInf> bankAccInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiCstno,zfiCoreId);
|
|
|
+ //基本户
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiBasic,"1");
|
|
|
+ //正常
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiStatus,"0");
|
|
|
+ //查询
|
|
|
+ List<PayBankAccInf> bankAccInfList = bankAccInfService.findPayBankAccInfs(bankAccInfLambdaQueryWrapper);
|
|
|
+ if(bankAccInfList.size() > 0){
|
|
|
+ //银行名称
|
|
|
+ openBank = bankAccInfList.get(0).getPbaiBankName();
|
|
|
+ //账号
|
|
|
+ openAccount = bankAccInfList.get(0).getPbaiBankaccountId();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ SysCompany supplierCompany = companyService.getById(zfiSupplierId);
|
|
|
+ if(supplierCompany != null){
|
|
|
+ //企业名称
|
|
|
+ receiverName = supplierCompany.getScyName();
|
|
|
+ //社会统一代码
|
|
|
+ receiverCode = supplierCompany.getScySocialCode();
|
|
|
+ //查询银行账号
|
|
|
+ LambdaQueryWrapper<PayBankAccInf> bankAccInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiCstno,zfiSupplierId);
|
|
|
+ //基本户
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiBasic,"1");
|
|
|
+ //正常
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiStatus,"0");
|
|
|
+ //查询
|
|
|
+ List<PayBankAccInf> bankAccInfList = bankAccInfService.findPayBankAccInfs(bankAccInfLambdaQueryWrapper);
|
|
|
+ if(bankAccInfList.size() > 0){
|
|
|
+ //银行名称
|
|
|
+ receiverBank = bankAccInfList.get(0).getPbaiBankName();
|
|
|
+ //账号
|
|
|
+ receiverAccount = bankAccInfList.get(0).getPbaiBankaccountId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取签发金额大写
|
|
|
+ zfiAmountBig = AmtUtil.convert(AmtUtil.moneyFormat(zfiAmount));
|
|
|
+ //承诺日期
|
|
|
+ //获取当前时间
|
|
|
+ Date date = DateUtils.getNowDate();
|
|
|
+ //格式化当前日期
|
|
|
+ String currecntDate = DateUtils.parseDateToStr("yyyy年MM月dd日",date);
|
|
|
+ Date expireDate = DateUtils.StrToDate(zfiExpireDate);
|
|
|
+ String expireDateA = DateUtils.parseDateToStr("yyyy年MM月dd日",expireDate);
|
|
|
+ stopDate = currecntDate +"-"+expireDateA;
|
|
|
+ //查询授信额度下的文件
|
|
|
+ LambdaQueryWrapper<ZcFinanceQuotaConRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(ZcFinanceQuotaConRel::getZfqcrCreditId,zfiCoreQuotaId);
|
|
|
+ List<ZcFinanceQuotaConRel> relList = quotaConRelService.findZcFinanceQuotaConRels(lambdaQueryWrapper);
|
|
|
+ if(relList.size() > 0 ){
|
|
|
+ //提取合同编号
|
|
|
+ contractIdList = CommonUtil.getIdFromList(relList,"zfqcrContractId");
|
|
|
+ }else if(relList.size() == 0 ){
|
|
|
+ //授信额度下没有合同则查询产品下关联的合同
|
|
|
+ LambdaQueryWrapper<ZcFinanceProConRel> proConRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ proConRelLambdaQueryWrapper.eq(ZcFinanceProConRel::getZfpcrProductId,zfpcrProductId);
|
|
|
+ List<ZcFinanceProConRel> proConRelsList = proConRelService.findZcFinanceProConRels(proConRelLambdaQueryWrapper);
|
|
|
+ if(proConRelsList.size() > 0 ){
|
|
|
+ //提取合同编号
|
|
|
+ contractIdList = CommonUtil.getIdFromList(proConRelsList,"zfpcrContractId");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回
|
|
|
+ Map<String,Object> p = new HashMap<>();
|
|
|
+ //文件信息
|
|
|
+ List<Map<String,String>> list = new ArrayList<>();
|
|
|
+ List<PubFileInf> fileInfList = new ArrayList<>();
|
|
|
+ p.put("list",list);
|
|
|
+ if(contractIdList.size() < 1){
|
|
|
+ return AjaxResult.success(p);
|
|
|
+ }else{
|
|
|
+ //查询合同
|
|
|
+ LambdaQueryWrapper<ZcFinanceContract> contractLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ contractLambdaQueryWrapper.in(ZcFinanceContract::getZfcId,contractIdList);
|
|
|
+ contractLambdaQueryWrapper.like(ZcFinanceContract::getZfcNode,code);
|
|
|
+ List<ZcFinanceContract> contractList = contractService.findZcFinanceContracts(contractLambdaQueryWrapper);
|
|
|
+ if(contractList.size() > 0 ){
|
|
|
+ //提取文件编号
|
|
|
+ List<String> fileIdList = CommonUtil.getIdFromList(contractList,"zfcFile");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,fileIdList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ fileInfList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(fileInfList.size() > 0 ){
|
|
|
+ //提取所有的文件url
|
|
|
+ List<String> urlList = CommonUtil.getIdFromList(fileInfList,"pfiFileUrl");
|
|
|
+ //提取文件名
|
|
|
+ List<String> fileNameList = CommonUtil.getIdFromList(fileInfList,"pfiFileName");
|
|
|
+ for(int i =0 ; i < urlList.size() ;i++){
|
|
|
+ //TODO 文件路径需要修改
|
|
|
+ //替换word文档中的变量
|
|
|
+ //String directory = FileConstants.REMOTE_FILE_PATH;
|
|
|
+ String directory = configService.selectConfigByKey("credit_file_path").getMsg();
|
|
|
+ //文件下载
|
|
|
+ String filePath = downloadFile(urlList.get(i),fileNameList.get(i));
|
|
|
+ //往word中填充数据
|
|
|
+ Map<String,Object> ps = new HashMap<>();
|
|
|
+ //开立方
|
|
|
+ ps.put("openName",openName);
|
|
|
+ //开立方社会统一代码
|
|
|
+ ps.put("openCode",openCode);
|
|
|
+ //开立方银行
|
|
|
+ ps.put("openBank",openBank);
|
|
|
+ //开立方账号
|
|
|
+ ps.put("openAccount",openAccount);
|
|
|
+ //接收方
|
|
|
+ ps.put("receiverName",receiverName);
|
|
|
+ //接收方社会统一代码
|
|
|
+ ps.put("receiverCode",receiverCode);
|
|
|
+ //接收方银行
|
|
|
+ ps.put("receiverBank",receiverBank);
|
|
|
+ //接收方账号
|
|
|
+ ps.put("receiverAccount",receiverAccount);
|
|
|
+ //小写金额
|
|
|
+ ps.put("zfiAmount",AmtUtil.moneyFormat(zfiAmount));
|
|
|
+ //大写金额
|
|
|
+ ps.put("zfiAmountBig",zfiAmountBig);
|
|
|
+ //起止日期
|
|
|
+ ps.put("stopDate",stopDate);
|
|
|
+ //当前日期
|
|
|
+ ps.put("currecntDate",currecntDate);
|
|
|
+ //还款编号
|
|
|
+ ps.put("zfiPaymentNumber",zfiPaymentNumber);
|
|
|
+ //承诺还款日
|
|
|
+ ps.put("expireDate",expireDateA);
|
|
|
+ //调用替换word中的变量
|
|
|
+ WordUtil.wordTemplate(filePath,filePath,ps);
|
|
|
+ //加载word示例文档
|
|
|
+ Document doc = new Document();
|
|
|
+ doc.loadFromFile(filePath);
|
|
|
+ //保存为PDF格式
|
|
|
+ //截取文件名称
|
|
|
+ //获取.的位置
|
|
|
+ int index = fileNameList.get(i).indexOf(".");
|
|
|
+ String fileName = fileNameList.get(i).substring(0,index);
|
|
|
+ doc.saveToFile(directory + fileName + currecntDate + ".pdf", FileFormat.PDF);
|
|
|
+ filePath = directory + fileName + currecntDate + ".pdf";
|
|
|
+ File pdfFile = new File(filePath);
|
|
|
+ FileInputStream inputFile = new FileInputStream(pdfFile);
|
|
|
+ byte[] buffer = new byte[(int)pdfFile.length()];
|
|
|
+ inputFile.read(buffer);
|
|
|
+ inputFile.close();
|
|
|
+ String base64 = new BASE64Encoder().encode(buffer);
|
|
|
+ //声明map
|
|
|
+ Map<String,String> pm = new HashMap<>();
|
|
|
+ pm.put("filePath",filePath);
|
|
|
+ pm.put("base64",base64);
|
|
|
+ list.add(pm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ p.put("list",list);
|
|
|
+ return AjaxResult.success(p);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同盖章
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/contractSigning")
|
|
|
+ public AjaxResult contractSigning(@RequestBody Map<String,Object> map) throws Exception {
|
|
|
+
|
|
|
+ //存放合同编号
|
|
|
+ List<String> contractIdList = new ArrayList<>();
|
|
|
+ //获取授信编号
|
|
|
+ String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
|
|
|
+ //获取产品
|
|
|
+ String zfpcrProductId = CommonUtil.objToString(map.get("zfpcrProductId"));
|
|
|
+ //获取融信编号
|
|
|
+ String zfiId = CommonUtil.objToString(map.get("zfiId"));
|
|
|
+ //获取融信编号
|
|
|
+ ZcFinanceInf financeInf = financeInfService.getById(zfiId);
|
|
|
+ if(financeInf == null){
|
|
|
+ throw new Exception("获取融信信息失败");
|
|
|
+ }
|
|
|
+ //节点
|
|
|
+ String code = "01";
|
|
|
+
|
|
|
+ if(CommonUtil.isEmpty(code)){
|
|
|
+ throw new Exception("盖章节点异常");
|
|
|
+ }
|
|
|
+ //获取接收方
|
|
|
+ String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
|
|
|
+ //开立方
|
|
|
+ String zfiCoreId = CommonUtil.objToString(map.get("zfiCoreId"));
|
|
|
+ //金额
|
|
|
+ String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
|
|
|
+ //承诺还款日期
|
|
|
+ String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
|
|
|
+ //还款编号
|
|
|
+ String zfiPaymentNumber = CommonUtil.objToString(map.get("zfiPaymentNumber"));
|
|
|
+ //获取开立方
|
|
|
+ String openName = "";
|
|
|
+ //获取开立方的社会统一码
|
|
|
+ String openCode = "";
|
|
|
+ //开户银行
|
|
|
+ String openBank = "";
|
|
|
+ //账号
|
|
|
+ String openAccount = "";
|
|
|
+ //获取接收方
|
|
|
+ String receiverName = "";
|
|
|
+ //获取开立方的社会统一码
|
|
|
+ String receiverCode = "";
|
|
|
+ //开户银行
|
|
|
+ String receiverBank = "";
|
|
|
+ //账号
|
|
|
+ String receiverAccount = "";
|
|
|
+ //大写金额
|
|
|
+ String zfiAmountBig = "";
|
|
|
+ //起止日期
|
|
|
+ String stopDate = "";
|
|
|
+ SysCompany company = companyService.getById(zfiCoreId);
|
|
|
+ if(company != null){
|
|
|
+ //企业名称
|
|
|
+ openName = company.getScyName();
|
|
|
+ //社会统一代码
|
|
|
+ openCode = company.getScySocialCode();
|
|
|
+ //查询银行账号
|
|
|
+ LambdaQueryWrapper<PayBankAccInf> bankAccInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiCstno,zfiCoreId);
|
|
|
+ //基本户
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiBasic,"1");
|
|
|
+ //正常
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiStatus,"0");
|
|
|
+ //查询
|
|
|
+ List<PayBankAccInf> bankAccInfList = bankAccInfService.findPayBankAccInfs(bankAccInfLambdaQueryWrapper);
|
|
|
+ if(bankAccInfList.size() > 0){
|
|
|
+ //银行名称
|
|
|
+ openBank = bankAccInfList.get(0).getPbaiBankName();
|
|
|
+ //账号
|
|
|
+ openAccount = bankAccInfList.get(0).getPbaiBankaccountId();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ SysCompany supplierCompany = companyService.getById(zfiSupplierId);
|
|
|
+ if(supplierCompany != null){
|
|
|
+ //企业名称
|
|
|
+ receiverName = supplierCompany.getScyName();
|
|
|
+ //社会统一代码
|
|
|
+ receiverCode = supplierCompany.getScySocialCode();
|
|
|
+ //查询银行账号
|
|
|
+ LambdaQueryWrapper<PayBankAccInf> bankAccInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiCstno,zfiSupplierId);
|
|
|
+ //基本户
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiBasic,"1");
|
|
|
+ //正常
|
|
|
+ bankAccInfLambdaQueryWrapper.eq(PayBankAccInf::getPbaiStatus,"0");
|
|
|
+ //查询
|
|
|
+ List<PayBankAccInf> bankAccInfList = bankAccInfService.findPayBankAccInfs(bankAccInfLambdaQueryWrapper);
|
|
|
+ if(bankAccInfList.size() > 0){
|
|
|
+ //银行名称
|
|
|
+ receiverBank = bankAccInfList.get(0).getPbaiBankName();
|
|
|
+ //账号
|
|
|
+ receiverAccount = bankAccInfList.get(0).getPbaiBankaccountId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取签发金额大写
|
|
|
+ zfiAmountBig = AmtUtil.convert(AmtUtil.moneyFormat(zfiAmount));
|
|
|
+ //承诺日期
|
|
|
+ //获取当前时间
|
|
|
+ Date date = DateUtils.getNowDate();
|
|
|
+ //格式化当前日期
|
|
|
+ String currecntDate = DateUtils.parseDateToStr("yyyy年MM月dd日",date);
|
|
|
+ Date expireDate = DateUtils.StrToDate(zfiExpireDate);
|
|
|
+ String expireDateA = DateUtils.parseDateToStr("yyyy年MM月dd日",expireDate);
|
|
|
+ stopDate = currecntDate +"-"+expireDateA;
|
|
|
+ //查询授信额度下的文件
|
|
|
+ LambdaQueryWrapper<ZcFinanceQuotaConRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(ZcFinanceQuotaConRel::getZfqcrCreditId,zfiCoreQuotaId);
|
|
|
+ List<ZcFinanceQuotaConRel> relList = quotaConRelService.findZcFinanceQuotaConRels(lambdaQueryWrapper);
|
|
|
+ if(relList.size() > 0 ){
|
|
|
+ //提取合同编号
|
|
|
+ contractIdList = CommonUtil.getIdFromList(relList,"zfqcrContractId");
|
|
|
+ }else if(relList.size() == 0 ){
|
|
|
+ //授信额度下没有合同则查询产品下关联的合同
|
|
|
+ LambdaQueryWrapper<ZcFinanceProConRel> proConRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ proConRelLambdaQueryWrapper.eq(ZcFinanceProConRel::getZfpcrProductId,zfpcrProductId);
|
|
|
+ List<ZcFinanceProConRel> proConRelsList = proConRelService.findZcFinanceProConRels(proConRelLambdaQueryWrapper);
|
|
|
+ if(proConRelsList.size() > 0 ){
|
|
|
+ //提取合同编号
|
|
|
+ contractIdList = CommonUtil.getIdFromList(proConRelsList,"zfpcrContractId");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PubFileInf> fileInfList = new ArrayList<>();
|
|
|
+ List<ZcFinanceContract> contractList = new ArrayList<>();
|
|
|
+ if(contractIdList.size() < 1){
|
|
|
+ return AjaxResult.success();
|
|
|
+ }else{
|
|
|
+ //查询合同
|
|
|
+ LambdaQueryWrapper<ZcFinanceContract> contractLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ contractLambdaQueryWrapper.in(ZcFinanceContract::getZfcId,contractIdList);
|
|
|
+ contractLambdaQueryWrapper.like(ZcFinanceContract::getZfcNode,code);
|
|
|
+ contractLambdaQueryWrapper.orderByAsc(ZcFinanceContract::getZfcFile);
|
|
|
+ contractList = contractService.findZcFinanceContracts(contractLambdaQueryWrapper);
|
|
|
+ if(contractList.size() > 0 ){
|
|
|
+ //提取文件编号
|
|
|
+ List<String> fileIdList = CommonUtil.getIdFromList(contractList,"zfcFile");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,fileIdList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ fileInfLambdaQueryWrapper.orderByAsc(PubFileInf::getPfiFileId);
|
|
|
+ fileInfList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 0 ; i < fileInfList.size(); i++){
|
|
|
+ //判断是否为已盖章文件
|
|
|
+ LambdaQueryWrapper<ZcFinanceFileRel> fileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileRelLambdaQueryWrapper.eq(ZcFinanceFileRel::getZffrFinanceId, zfiId);
|
|
|
+ fileRelLambdaQueryWrapper.eq(ZcFinanceFileRel::getZffrContractId, contractList.get(i).getZfcId());
|
|
|
+ // 核心企业盖章
|
|
|
+ if ("01".equals(tokenService.getLoginUser().getSysUser().getCompanyType())) {
|
|
|
+ // 查询融资企业是否盖章
|
|
|
+ fileRelLambdaQueryWrapper.eq(ZcFinanceFileRel::getZffrSupplierNode, code);
|
|
|
+ // 融资企业盖章
|
|
|
+ } else if ("02".equals(tokenService.getLoginUser().getSysUser().getCompanyType())) {
|
|
|
+ // 查询核心企业是否盖章
|
|
|
+ fileRelLambdaQueryWrapper.eq(ZcFinanceFileRel::getZffrCoreNode, code);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ZcFinanceFileRel> financeFileList = financeFileRelService.findZcFinanceFileRels(fileRelLambdaQueryWrapper);
|
|
|
+
|
|
|
+ // 文件路径
|
|
|
+ String filePath;
|
|
|
+ // 文件名称
|
|
|
+ String fileName;
|
|
|
+ // 不是已盖章文件
|
|
|
+ if (financeFileList.size() == 0) {
|
|
|
+ /**-------- word 变量替换 开始--------**/
|
|
|
+ //替换word文档中的变量
|
|
|
+ //String directory = FileConstants.REMOTE_FILE_PATH;
|
|
|
+ String directory = configService.selectConfigByKey("credit_file_path").getMsg();
|
|
|
+ //文件下载
|
|
|
+ filePath = downloadFile(fileInfList.get(i).getPfiFileUrl(),fileInfList.get(i).getPfiFileName());
|
|
|
+ //往word中填充数据
|
|
|
+ Map<String,Object> ps = new HashMap<>();
|
|
|
+ //开立方
|
|
|
+ ps.put("openName",openName);
|
|
|
+ //开立方社会统一代码
|
|
|
+ ps.put("openCode",openCode);
|
|
|
+ //开立方银行
|
|
|
+ ps.put("openBank",openBank);
|
|
|
+ //开立方账号
|
|
|
+ ps.put("openAccount",openAccount);
|
|
|
+ //接收方
|
|
|
+ ps.put("receiverName",receiverName);
|
|
|
+ //接收方社会统一代码
|
|
|
+ ps.put("receiverCode",receiverCode);
|
|
|
+ //接收方银行
|
|
|
+ ps.put("receiverBank",receiverBank);
|
|
|
+ //接收方账号
|
|
|
+ ps.put("receiverAccount",receiverAccount);
|
|
|
+ //小写金额
|
|
|
+ ps.put("zfiAmount",AmtUtil.moneyFormat(zfiAmount));
|
|
|
+ //大写金额
|
|
|
+ ps.put("zfiAmountBig",zfiAmountBig);
|
|
|
+ //起止日期
|
|
|
+ ps.put("stopDate",stopDate);
|
|
|
+ //当前日期
|
|
|
+ ps.put("currecntDate",currecntDate);
|
|
|
+ //还款编号
|
|
|
+ ps.put("zfiPaymentNumber",zfiPaymentNumber);
|
|
|
+ //承诺还款日
|
|
|
+ ps.put("expireDate",expireDateA);
|
|
|
+ //调用替换word中的变量
|
|
|
+ WordUtil.wordTemplate(filePath,filePath,ps);
|
|
|
+ /**-------- word 变量替换 结束--------**/
|
|
|
+ /**-------- word 转PDF 开始--------**/
|
|
|
+ //加载word示例文档
|
|
|
+ Document doc = new Document();
|
|
|
+ doc.loadFromFile(filePath);
|
|
|
+ //保存为PDF格式
|
|
|
+ //截取文件名称
|
|
|
+ //获取.的位置
|
|
|
+ int index = fileInfList.get(i).getPfiFileName().indexOf(".");
|
|
|
+ fileName = fileInfList.get(i).getPfiFileName().substring(0,index);
|
|
|
+ doc.saveToFile(directory + fileName + currecntDate + ".pdf", FileFormat.PDF);
|
|
|
+ filePath = directory + fileName + currecntDate + ".pdf";
|
|
|
+ /**-------- word 转PDF 结束--------**/
|
|
|
+ // 是已盖章文件
|
|
|
+ } else {
|
|
|
+ // 文件服务器的文件下载到本地
|
|
|
+ PubFileInf fileInf = fileInfService.getById(financeFileList.get(0).getZffrFileId());
|
|
|
+ filePath = downloadFile(fileInf.getPfiFileUrl(), fileInf.getPfiFileName());
|
|
|
+ int index = fileInf.getPfiFileName().indexOf(".");
|
|
|
+ fileName = fileInf.getPfiFileName().substring(0,index);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**-------- 获取合同盖章关键字 开始--------**/
|
|
|
+ //获取合同信息
|
|
|
+ //获取合同的节点
|
|
|
+ String contractNode = contractList.get(i).getZfcNode();
|
|
|
+ //关键字
|
|
|
+ String keyWords = "";
|
|
|
+ //判断节点是否用,分割
|
|
|
+ if(contractNode.contains(",")){
|
|
|
+ String [] arr = contractNode.split(",");
|
|
|
+ //字节所在的节点
|
|
|
+ int site = 0;
|
|
|
+ for(int j = 0 ; j < arr.length; j++){
|
|
|
+ if(code.equals(arr[j])){
|
|
|
+ site = j;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String signKeyWord = contractList.get(i).getZfcSignKeyword();
|
|
|
+ String [] arrKeyWord = signKeyWord.split(",");
|
|
|
+ if(arr.length != arrKeyWord.length){
|
|
|
+ throw new Exception("合同信息有误");
|
|
|
+ }
|
|
|
+ keyWords = arrKeyWord[site];
|
|
|
+
|
|
|
+ }else {
|
|
|
+ keyWords = contractList.get(i).getZfcSignKeyword();
|
|
|
+ }
|
|
|
+ if(CommonUtil.isEmpty(keyWords)){
|
|
|
+ throw new Exception("获取关键字失败");
|
|
|
+ }
|
|
|
+ /**-------- 获取合同盖章关键字 结束--------**/
|
|
|
+ /**-------- CFCA盖章 开始--------**/
|
|
|
+ //盖章
|
|
|
+ //人员编号
|
|
|
+ String userId = "CA74686406B322C7E05311016B0A442F";
|
|
|
+ //项目编号
|
|
|
+ String projectCode = DateUtils.dateTimeNow();
|
|
|
+ JSONObject jsonObject = AxqCommonUtil.contractSigning(userId,"MM",fileName,keyWords,"0","0","250","250",projectCode,filePath);
|
|
|
+ /**-------- CFCA盖章 结束--------**/
|
|
|
+ /**-------- CFCA盖章文件下载 开始--------**/
|
|
|
+ //获取错误码
|
|
|
+ String errorCode = null;
|
|
|
+ try {
|
|
|
+ errorCode = CommonUtil.objToString(jsonObject.get("errorCode"));
|
|
|
+ } catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(errorCode)){
|
|
|
+ //获取错误信息
|
|
|
+ String errorMessage = CommonUtil.objToString(jsonObject.get("errorMessage"));
|
|
|
+ throw new Exception(errorMessage);
|
|
|
+ }
|
|
|
+ String contractNo = CommonUtil.objToString(((JSONObject)(jsonObject.get("contract"))).get("contractNo"));
|
|
|
+ //String path = "D:/zhuomian/cfca/";
|
|
|
+ String path = configService.selectConfigByKey("cfca_file_path").getMsg();
|
|
|
+ //下载文件
|
|
|
+ AxqCommonUtil.downloadFile(contractNo,path);
|
|
|
+ /**-------- CFCA盖章文件下载 结束--------**/
|
|
|
+ //上传到文件服务器
|
|
|
+ //获取token
|
|
|
+ String token = SecurityUtils.getToken(ServletUtils.getRequest());
|
|
|
+ String companyId = tokenService.getLoginUser().getSysUser().getCompanyId();
|
|
|
+ //文件传输
|
|
|
+ File file = new File(path + contractNo + ".pdf");
|
|
|
+ FileInputStream input = new FileInputStream(file);
|
|
|
+ MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input));
|
|
|
+ R<com.tianhu.system.api.domain.PubFileInf> fileResult = remoteFileService.uploadFile(multipartFile,"01", "02","00",companyId,token);
|
|
|
+
|
|
|
+ ZcFinanceFileRel financeFileRel;
|
|
|
+ // 不是已盖章文件
|
|
|
+ if (financeFileList.size() == 0) {
|
|
|
+ // zc_finance_file_rel 存入数据
|
|
|
+ financeFileRel = new ZcFinanceFileRel();
|
|
|
+ financeFileRel.setZffrId(IdUtils.fastSimpleUUID());
|
|
|
+ financeFileRel.setZffrFinanceId(zfiId);
|
|
|
+ financeFileRel.setZffrContractId(contractList.get(i).getZfcId());
|
|
|
+ // 已盖章文件
|
|
|
+ } else {
|
|
|
+ // 修改zc_finance_file_rel 数据
|
|
|
+ financeFileRel = financeFileList.get(0);
|
|
|
+ }
|
|
|
+ financeFileRel.setZffrFileId(fileResult.getData().getPfiFileId());
|
|
|
+ financeFileRel.setZffrCfcaNumber(contractNo);
|
|
|
+ // 核心企业盖章
|
|
|
+ if ("01".equals(tokenService.getLoginUser().getSysUser().getCompanyType())) {
|
|
|
+ financeFileRel.setZffrCoreId(companyId);
|
|
|
+ financeFileRel.setZffrCoreUserId(tokenService.getLoginUser().getSysUser().getUserId());
|
|
|
+ financeFileRel.setZffrCoreTime(new Date());
|
|
|
+ financeFileRel.setZffrCoreNode(code);
|
|
|
+
|
|
|
+ // 融资企业盖章
|
|
|
+ } else if ("02".equals(tokenService.getLoginUser().getSysUser().getCompanyType())) {
|
|
|
+ financeFileRel.setZffrSupplierId(companyId);
|
|
|
+ financeFileRel.setZffrSupplierUserId(tokenService.getLoginUser().getSysUser().getUserId());
|
|
|
+ financeFileRel.setZffrSupplierTime(new Date());
|
|
|
+ financeFileRel.setZffrSupplierNode(code);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 不是已盖章文件
|
|
|
+ if (financeFileList.size() == 0) {
|
|
|
+ // zc_finance_file_rel 存入数据
|
|
|
+ financeFileRelService.createZcFinanceFileRel(financeFileRel);
|
|
|
+ // 已盖章文件
|
|
|
+ } else {
|
|
|
+ // 修改zc_finance_file_rel 数据
|
|
|
+ financeFileRelService.updateById(financeFileRel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**-------- 盖章完成修改融信状态并且发起审批 结束--------**/
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载远程文件并保存到本地
|
|
|
+ * @param remoteFilePath 远程文件路径
|
|
|
+ * @param localFilePath 本地文件路径(带文件名)
|
|
|
+ */
|
|
|
+ public static String downloadFile(String remoteFilePath, String localFilePath)
|
|
|
+ {
|
|
|
+ URL urlfile = null;
|
|
|
+ HttpURLConnection httpUrl = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
+
|
|
|
+ File path = new File(FileConstants.REMOTE_FILE_PATH);
|
|
|
+ //判断文件是否存在
|
|
|
+ if(!path.exists()){
|
|
|
+ path.mkdirs();
|
|
|
+ }
|
|
|
+ File f = new File(FileConstants.REMOTE_FILE_PATH + localFilePath);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ urlfile = new URL(remoteFilePath);
|
|
|
+ httpUrl = (HttpURLConnection)urlfile.openConnection();
|
|
|
+ httpUrl.connect();
|
|
|
+ bis = new BufferedInputStream(httpUrl.getInputStream());
|
|
|
+ bos = new BufferedOutputStream(new FileOutputStream(f));
|
|
|
+ int len = 2048;
|
|
|
+ byte[] b = new byte[len];
|
|
|
+ while ((len = bis.read(b)) != -1)
|
|
|
+ {
|
|
|
+ bos.write(b, 0, len);
|
|
|
+ }
|
|
|
+ bos.flush();
|
|
|
+ bis.close();
|
|
|
+ httpUrl.disconnect();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bis.close();
|
|
|
+ bos.close();
|
|
|
+ }
|
|
|
+ catch (IOException e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return f.getAbsolutePath();
|
|
|
+ }
|
|
|
+ /* public static void main(String[] args) {
|
|
|
+ String date = DateUtils.dateTimeNow();
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+ urlList.add("http://huyi.img.minpay.cc/file/000000/doc/20210823/8a2ea656-8f98-4d37-98a1-132c1d4fc768.doc");
|
|
|
+ //提取文件名
|
|
|
+ List<String> fileNameList = new ArrayList<>();
|
|
|
+ fileNameList.add("招采文件.doc");
|
|
|
+ for(int i =0 ; i < urlList.size() ;i++){
|
|
|
+ String directory = FileConstants.REMOTE_FILE_PATH;
|
|
|
+ //文件下载
|
|
|
+ String filePath = downloadFile(urlList.get(i),fileNameList.get(i));
|
|
|
+ //加载word示例文档
|
|
|
+ Document doc = new Document();
|
|
|
+ doc.loadFromFile(filePath);
|
|
|
+ //保存为PDF格式
|
|
|
+ doc.saveToFile(directory + fileNameList.get(i) +date+ ".pdf", FileFormat.PDF);
|
|
|
+ filePath = directory + fileNameList.get(i) +date+ ".pdf";
|
|
|
+ System.out.println("转换成功");
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|