|
@@ -0,0 +1,365 @@
|
|
|
+package com.huyi.service.repayment.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.huyi.service.base.entity.ZcFinanceInf;
|
|
|
+import com.huyi.service.base.entity.ZcFinanceRecord;
|
|
|
+import com.huyi.service.base.service.IZcFinanceInfService;
|
|
|
+import com.huyi.service.base.service.IZcFinanceRecordService;
|
|
|
+import com.huyi.service.repayment.service.IOwnRepaymentService;
|
|
|
+import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
|
|
|
+import com.tianhu.common.core.domain.R;
|
|
|
+import com.tianhu.common.core.utils.CommonUtil;
|
|
|
+import com.tianhu.common.core.utils.DateUtils;
|
|
|
+import com.tianhu.common.core.utils.file.ExcelFileUtils;
|
|
|
+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.redis.common.RedisUtils;
|
|
|
+import com.tianhu.common.redis.domain.SysDictData;
|
|
|
+import com.tianhu.common.security.annotation.PreAuthorize;
|
|
|
+import com.tianhu.system.api.RemoteConfigService;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 还款controller
|
|
|
+ *
|
|
|
+ * @author ch
|
|
|
+ * @date 2021-8-24
|
|
|
+ */
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/repayment")
|
|
|
+public class repaymentController extends BaseController {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(repaymentController.class);
|
|
|
+ @Autowired
|
|
|
+ private IOwnRepaymentService ownRepaymentService;
|
|
|
+ @Autowired
|
|
|
+ private RemoteConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceRecordService zcFinanceRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceInfService zcFinanceInfService;
|
|
|
+ /**
|
|
|
+ * 查询全部还款列表
|
|
|
+ * @param type
|
|
|
+ * @param value
|
|
|
+ * @param repaymentDate
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public AjaxResult list(String type, String value,
|
|
|
+ @RequestParam(required = false) Map repaymentDate,
|
|
|
+ String status, QueryRequest request) {
|
|
|
+ Map map = new HashMap(16);
|
|
|
+ if(CommonUtil.isNotEmpty(type)){
|
|
|
+ if("00".equals(type)){
|
|
|
+ //资金方
|
|
|
+ map.put("scyName",value);
|
|
|
+ }else if("01".equals(type)){
|
|
|
+ //融信编号
|
|
|
+ map.put("zfiNumber",value);
|
|
|
+ }else if("02".equals(type)){
|
|
|
+ //融资编号
|
|
|
+ map.put("zfrNumber",value);
|
|
|
+ }else {
|
|
|
+ //融资方
|
|
|
+ map.put("supplier",value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //承诺还款日期
|
|
|
+ map.put("start",repaymentDate.get("repaymentDate[0]"));
|
|
|
+ map.put("end",repaymentDate.get("repaymentDate[1]"));
|
|
|
+ //还款状态
|
|
|
+ map.put("zfrApplyStatus",status);
|
|
|
+ IPage<Map> list = ownRepaymentService.selectRepaymentList(map,request);
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询还款详情
|
|
|
+ * @param zfrId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "service:repayment:query")
|
|
|
+ @GetMapping(value = "/{zfrId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("zfrId") String zfrId)
|
|
|
+ {
|
|
|
+ Map map = new HashMap(16);
|
|
|
+ map.put("zfrId",zfrId);
|
|
|
+ List<Map> result = ownRepaymentService.selectById(map);
|
|
|
+
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 待还款导出
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "service:repayment:export")
|
|
|
+ @Log(title = "待还款导出", businessType = BusinessType.EXPORT)
|
|
|
+ @Transactional(rollbackFor=Exception.class)
|
|
|
+ @PostMapping("/export")
|
|
|
+ public R export(HttpServletResponse response){
|
|
|
+
|
|
|
+ //最终结果集
|
|
|
+ List detailList = new ArrayList();
|
|
|
+ //判断到处哪些日志
|
|
|
+ Map map = new HashMap();
|
|
|
+ //map.put("zfrApplyStatus","01");
|
|
|
+ List<Map> list = ownRepaymentService.selectNoPageRepaymentList(map);
|
|
|
+ //从缓存中获取字典值用于转义。
|
|
|
+ List<SysDictData> workState = RedisUtils.getDictCache("zc_zfr_apply_status");
|
|
|
+ Map<String,String> stateMap = new HashMap();
|
|
|
+ for (Object object : workState) {
|
|
|
+ if (object instanceof SysDictData) {
|
|
|
+ SysDictData dictData = (SysDictData)object;
|
|
|
+ stateMap.put(dictData.getDictValue(),dictData.getDictLabel());
|
|
|
+ } else if (object instanceof JSONObject) {
|
|
|
+ JSONObject dictData = (JSONObject)object;
|
|
|
+ stateMap.put(String.valueOf(dictData.get("dictValue")),String.valueOf(dictData.get("dictLabel")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将获得的list中的是否加班字段替换为汉字
|
|
|
+ for(Map changeMap:list){
|
|
|
+ String zfrApplyStatus = CommonUtil.objToString(changeMap.get("zfrApplyStatus"));
|
|
|
+ changeMap.put("zfrApplyStatus",stateMap.get(zfrApplyStatus));
|
|
|
+ detailList.add(changeMap);
|
|
|
+ }
|
|
|
+ //导出文档名称
|
|
|
+ String fileName = "待还款列表";
|
|
|
+ //查询表头
|
|
|
+ List<String> tableT = new ArrayList<>();
|
|
|
+ tableT.add("融信编号#zfiNumber");
|
|
|
+ tableT.add("还款承诺函编号#zfiPaymentNumber");
|
|
|
+ tableT.add("最终还款方#core");
|
|
|
+ tableT.add("还款金额(元)#zfrLoanAmount");
|
|
|
+ tableT.add("还款银行账户#zfpcrAccount");
|
|
|
+ tableT.add("实际还款日期#zfrPayDate");
|
|
|
+ tableT.add("承诺付款日期#zfrRepaymentDate");
|
|
|
+ tableT.add("还款状态#zfrApplyStatus");
|
|
|
+ //执行导出
|
|
|
+ try {
|
|
|
+ HSSFWorkbook wb = ExcelFileUtils.export(response,fileName,tableT,detailList);
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ // 设置contentType为excel格式
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
+ //默认Excel名称
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + "员工日志详情"+ URLEncoder.encode(fileName + ".xls", "UTF-8"));
|
|
|
+ response.flushBuffer();
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ wb.write(outputStream);
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException var20) {
|
|
|
+ var20.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception var22) {
|
|
|
+ log.error("导出Excel异常{}", var22.getMessage());
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 还款明细下载
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "service:repayment:downLoad")
|
|
|
+ @Log(title = "还款明细下载", businessType = BusinessType.EXPORT)
|
|
|
+ @Transactional(rollbackFor=Exception.class)
|
|
|
+ @PostMapping("/export/{zfrId}")
|
|
|
+ public AjaxResult downLoad(HttpServletResponse response,@PathVariable String zfrId) throws Exception {
|
|
|
+
|
|
|
+// String directory = "D:\\" ;
|
|
|
+ String directory = configService.selectConfigByKey("zc_repayment_export").getMsg();
|
|
|
+ //查询还款明细表
|
|
|
+ Map map = new HashMap(16);
|
|
|
+ map.put("zfrId",zfrId);
|
|
|
+ List<Map> result = ownRepaymentService.selectById(map);
|
|
|
+ //编号
|
|
|
+ String zfrPayNumber = CommonUtil.objToString(result.get(0).get("zfrPayNumber"));
|
|
|
+ //最终付款方
|
|
|
+ String core = CommonUtil.objToString(result.get(0).get("core"));
|
|
|
+ //还款承诺函编号
|
|
|
+ String zfiPaymentNumber = CommonUtil.objToString(result.get(0).get("zfiPaymentNumber"));
|
|
|
+ //承诺付款日期
|
|
|
+ String zfrRepaymentDate = CommonUtil.objToString(result.get(0).get("zfrRepaymentDate"));
|
|
|
+ //承诺付款金额
|
|
|
+ String zfrLoanAmount = CommonUtil.objToString(result.get(0).get("zfrLoanAmount"));
|
|
|
+ //付款账户名称
|
|
|
+ String payName = core;
|
|
|
+ //付款账户账号
|
|
|
+ String zfpcrAccount = CommonUtil.objToString(result.get(0).get("zfpcrAccount"));
|
|
|
+ //付款账户开户行
|
|
|
+ String zfpcrAccountBank = CommonUtil.objToString(result.get(0).get("zfpcrAccountBank"));
|
|
|
+ //收款方
|
|
|
+ String receive = CommonUtil.objToString(result.get(0).get("supplier"));
|
|
|
+ //还款账户名
|
|
|
+ String returnName = "";
|
|
|
+ if("0".equals(CommonUtil.objToString(result.get(0).get("zpfType")))){
|
|
|
+ returnName = receive;
|
|
|
+ }else {
|
|
|
+ returnName = core;
|
|
|
+ }
|
|
|
+ //还款账户账号
|
|
|
+ String returnAccountNumber = zfpcrAccount;
|
|
|
+ //收款金额
|
|
|
+ String receiveAmount = zfrLoanAmount;
|
|
|
+
|
|
|
+ // 模版位置
|
|
|
+ String contracts = configService.selectConfigByKey("zc_repayment_export_docx").getMsg();
|
|
|
+ //contracts = "C:\\Users\\chenh\\Desktop\\RepaymentList.docx";
|
|
|
+// contracts = Test.class.getClassLoader().getResource("RepaymentList.docx").getPath();
|
|
|
+ String fileName = "HKXQ"+ DateUtils.dateTimeNow() + ".docx";
|
|
|
+ String filePath = directory + fileName;
|
|
|
+ log.info("<===================模板=================>"+filePath);
|
|
|
+ System.out.println(contracts);
|
|
|
+ FileUtils.copyFile(new File(contracts), new File(filePath));
|
|
|
+ FileInputStream inputStream = new FileInputStream(contracts);
|
|
|
+ //模板字段取值
|
|
|
+ Map docMap = new HashMap();
|
|
|
+ try {
|
|
|
+ docMap.put("zfrPayNumber",zfrPayNumber);
|
|
|
+ docMap.put("core",core);
|
|
|
+ docMap.put("zfiPaymentNumber",zfiPaymentNumber);
|
|
|
+ docMap.put("zfrRepaymentDate",zfrRepaymentDate);
|
|
|
+ docMap.put("zfrLoanAmount",zfrLoanAmount);
|
|
|
+ docMap.put("payName",payName);
|
|
|
+ docMap.put("zfpcrAccount",zfpcrAccount);
|
|
|
+ docMap.put("zfpcrAccountBank",zfpcrAccountBank);
|
|
|
+ docMap.put("receive",receive);
|
|
|
+ docMap.put("returnName",returnName);
|
|
|
+ docMap.put("returnAccountNumber",returnAccountNumber);
|
|
|
+ docMap.put("receiveAmount",receiveAmount);
|
|
|
+ System.out.println(docMap);
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(inputStream).render(docMap);
|
|
|
+ //写入模板
|
|
|
+ template.writeToFile(filePath);
|
|
|
+ //关闭流
|
|
|
+ inputStream.close();
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ File zipFile = new File(filePath);
|
|
|
+ if(zipFile.exists()){
|
|
|
+ down(response, fileName, directory);
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件下载
|
|
|
+ * @param response 请求
|
|
|
+ * @param fileName 文件名
|
|
|
+ * @param path 文件
|
|
|
+ */
|
|
|
+ public void down(HttpServletResponse response, String fileName, String path) {
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
+ byte[] buff = new byte[1024];
|
|
|
+ //创建缓冲输入流
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+
|
|
|
+ //这个路径为待下载文件的路径
|
|
|
+ bis = new BufferedInputStream(new FileInputStream(new File(path + fileName )));
|
|
|
+ int read = bis.read(buff);
|
|
|
+
|
|
|
+ //通过while循环写入到指定了的文件夹中
|
|
|
+ while (read != -1) {
|
|
|
+ outputStream.write(buff, 0, buff.length);
|
|
|
+ outputStream.flush();
|
|
|
+ read = bis.read(buff);
|
|
|
+ }
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 下载失败
|
|
|
+ } finally {
|
|
|
+ if (bis != null) {
|
|
|
+ try {
|
|
|
+ bis.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 还款登记
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "service:repayment:edit")
|
|
|
+ @Log(title = "还款登记", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult RepaymentRegistration(@RequestBody Map map){
|
|
|
+ //附件url
|
|
|
+ List<Map<String, String>> file = (List<Map<String, String>>) map.get("zfrApplyFile");
|
|
|
+ if(file.size() == 0){
|
|
|
+ return AjaxResult.error("请上传附件");
|
|
|
+ }
|
|
|
+ String zfrApplyFile="";
|
|
|
+ String zfrApplyFileId = "";
|
|
|
+ if(file.size()>0) {
|
|
|
+ for (int j = 0; j < file.size(); j++) {
|
|
|
+ Map<String, String> fileUrl = file.get(j);
|
|
|
+ if (j == 0) {
|
|
|
+ zfrApplyFile = fileUrl.get("url");
|
|
|
+ zfrApplyFileId = CommonUtil.objToString(fileUrl.get("uid"));
|
|
|
+ } else {
|
|
|
+ zfrApplyFile += "," + fileUrl.get("url");
|
|
|
+ zfrApplyFileId += "," + CommonUtil.objToString(fileUrl.get("uid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //主键
|
|
|
+ String zfrId = CommonUtil.objToString(map.get("zfrId"));
|
|
|
+ ZcFinanceRecord zcFinanceRecord = new ZcFinanceRecord();
|
|
|
+ zcFinanceRecord.setZfrId(zfrId);
|
|
|
+ //添加上传文件
|
|
|
+ zcFinanceRecord.setZfrApplyFile(zfrApplyFileId);
|
|
|
+ //修改融资状态未已结算
|
|
|
+ zcFinanceRecord.setZfrStatus("03");
|
|
|
+ zcFinanceRecordService.updateZcFinanceRecord(zcFinanceRecord);
|
|
|
+ //融信Id
|
|
|
+ ZcFinanceRecord record = zcFinanceRecordService.getById(zfrId);
|
|
|
+ String zfiId = record.getZfrFinanceId();
|
|
|
+ //修改融信状态未失效
|
|
|
+ ZcFinanceInf zcFinanceInf = new ZcFinanceInf();
|
|
|
+ zcFinanceInf.setZfiId(zfiId);
|
|
|
+ zcFinanceInf.setZfiStatus("03");
|
|
|
+ zcFinanceInfService.updateZcFinanceInf(zcFinanceInf);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|