|
|
@@ -1,22 +1,43 @@
|
|
|
package me.zhengjie.application.admin.service.impl;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhengjie.application.admin.service.CochainLogService;
|
|
|
import me.zhengjie.application.admin.service.OrderCochainService;
|
|
|
+import me.zhengjie.application.bank.service.BorrowerService;
|
|
|
+import me.zhengjie.application.bank.service.GuaranteeService;
|
|
|
+import me.zhengjie.application.bank.service.MortgageService;
|
|
|
+import me.zhengjie.application.bank.service.OrderRoomIdService;
|
|
|
+import me.zhengjie.application.bank.service.OrderService;
|
|
|
+import me.zhengjie.base.chain.CochainService;
|
|
|
+import me.zhengjie.base.util.FileUploadUtil;
|
|
|
+import me.zhengjie.base.util.UUIDGenerator;
|
|
|
+import me.zhengjie.dao.mybatis.entity.BorrowerEntity;
|
|
|
import me.zhengjie.dao.mybatis.entity.CochainLogEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.FileInfoEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.GuaranteeEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.MortgageEntity;
|
|
|
import me.zhengjie.dao.mybatis.entity.OrderCochainEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.OrderFileEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.OrderRoomIdEntity;
|
|
|
import me.zhengjie.dao.mybatis.mapper.ICochainLogDao;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
-
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
+import me.zhengjie.dao.mybatis.mapper.OrderFileMapper;
|
|
|
|
|
|
/**
|
|
|
+ * TODO 这个需要去掉抵押人,可以有联合借款,联合抵押,现在都是按照单个处理,
|
|
|
+ *
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
|
* </p>
|
|
|
@@ -25,18 +46,283 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2022-07-25
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class CochainLogServiceImpl extends ServiceImpl<ICochainLogDao, CochainLogEntity> implements CochainLogService {
|
|
|
|
|
|
@Autowired
|
|
|
OrderCochainService orderCochainService;
|
|
|
+ @Autowired
|
|
|
+ BorrowerService borrowerService;
|
|
|
+ @Autowired
|
|
|
+ MortgageService mortgageService;
|
|
|
+ @Autowired
|
|
|
+ GuaranteeService guaranteeService;
|
|
|
|
|
|
- @PostConstruct
|
|
|
+ @Autowired
|
|
|
+ OrderService orderService;
|
|
|
+ @Autowired
|
|
|
+ CochainService cochainService;
|
|
|
+ @Autowired
|
|
|
+ CochainLogService cochainLogService;
|
|
|
+ @Autowired
|
|
|
+ OrderFileMapper orderFileMapper;
|
|
|
+ @Autowired
|
|
|
+ OrderRoomIdService orderRoomService;
|
|
|
+
|
|
|
+// @PostConstruct
|
|
|
public void init() {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000l);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ chainEvidence();
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
// t.set
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void chainEvidence() {
|
|
|
+
|
|
|
QueryWrapper<OrderCochainEntity> qw = new QueryWrapper<>();
|
|
|
- qw = qw.in("is_call", "0,1").orderByAsc("update_time").last("limit 1");
|
|
|
+ qw = qw.in("status", 0, 2).orderByAsc("create_time").last("limit 1");
|
|
|
|
|
|
OrderCochainEntity cochainEntity = orderCochainService.getOne(qw);
|
|
|
- System.out.println(cochainEntity);
|
|
|
+ if (cochainEntity == null) {
|
|
|
+ log.info("没有上链数据:");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 先读取借款人的,
|
|
|
+ String businessNo = cochainEntity.getBusinessNo();
|
|
|
+ // 查询数据
|
|
|
+ log.info("【开始】调用上链业务编号:"+businessNo);
|
|
|
+
|
|
|
+
|
|
|
+ CochainLogEntity cochainLog = new CochainLogEntity();
|
|
|
+ cochainLog.setBusinessNo(businessNo);
|
|
|
+ // 查询已经插入过的
|
|
|
+ QueryWrapper<CochainLogEntity> callCochainLog = cochainLogService.convertQuery(cochainLog);
|
|
|
+ callCochainLog.select("file_path");
|
|
|
+ List<String> cochainLogs = cochainLogService.listObjs(callCochainLog, a -> {
|
|
|
+ return String.valueOf(a.toString());
|
|
|
+ });
|
|
|
+ // 查询所有上传的图片
|
|
|
+ Map<String, FileInfoEntity> map = orderService.getUploadFile(businessNo);
|
|
|
+ // 借款人查询数据
|
|
|
+ BorrowerEntity borrower = new BorrowerEntity();
|
|
|
+ borrower.setBusinessNo(businessNo);
|
|
|
+ List<BorrowerEntity> borrowers = borrowerService.list(borrower);
|
|
|
+ for (BorrowerEntity obj : borrowers) {
|
|
|
+ List<CochainLogEntity> logs = new ArrayList<CochainLogEntity>();
|
|
|
+ // 身份证正面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardFront(), map, logs, cochainLogs);
|
|
|
+ // 身份证反面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardBack(), map, logs, cochainLogs);
|
|
|
+ // 合同
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCompactPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getEstatesPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getMarragePic(), map, logs, cochainLogs);
|
|
|
+ // 其他上传
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getOtherUpload(), map, logs, cochainLogs);
|
|
|
+ // 户口本
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getHkbPic(), map, logs, cochainLogs);
|
|
|
+ // 带有盖章的pdf
|
|
|
+ QueryWrapper<OrderFileEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("business_no", businessNo);
|
|
|
+ wrapper.eq("contract_id", obj.getId());
|
|
|
+ // 这里处理,如果没有盖章的就把签名的pdf上传
|
|
|
+ List<OrderFileEntity> orderFiles = orderFileMapper.selectList(wrapper);
|
|
|
+ for (OrderFileEntity orderFile : orderFiles) {
|
|
|
+ if (StringUtils.isNotBlank(orderFile.getSignedPdfUrl())) {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getSignedPdfUrl(), logs, cochainLogs);
|
|
|
+ } else {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getPdfUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理视频
|
|
|
+ QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("orderId", obj.getId());
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ List<OrderRoomIdEntity> orderRoomList = orderRoomService.list(queryWrapper);
|
|
|
+ if (orderRoomList != null && orderRoomList.size() > 0) {
|
|
|
+ OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getAppVideoUrl(), logs, cochainLogs);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getPcVideoUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ // 数据插入
|
|
|
+ cochainLogService.saveBatch(logs);
|
|
|
+ }
|
|
|
+ // 抵押人查询数据
|
|
|
+ MortgageEntity mortgage = new MortgageEntity();
|
|
|
+ mortgage.setBusinessNo(businessNo);
|
|
|
+ List<MortgageEntity> mortgages = mortgageService.list(mortgage);
|
|
|
+ for (MortgageEntity obj : mortgages) {
|
|
|
+ List<CochainLogEntity> logs = new ArrayList<CochainLogEntity>();
|
|
|
+ // 身份证正面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardFront(), map, logs, cochainLogs);
|
|
|
+ // 身份证反面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardBack(), map, logs, cochainLogs);
|
|
|
+ // 合同
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCompactPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getEstatesPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getMarragePic(), map, logs, cochainLogs);
|
|
|
+ // 其他上传
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getOtherUpload(), map, logs, cochainLogs);
|
|
|
+ // 户口本
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getHkbPic(), map, logs, cochainLogs);
|
|
|
+ // 带有盖章的pdf
|
|
|
+ QueryWrapper<OrderFileEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("business_no", businessNo);
|
|
|
+ wrapper.eq("contract_id", obj.getId());
|
|
|
+ // 这里处理,如果没有盖章的就把签名的pdf上传
|
|
|
+ List<OrderFileEntity> orderFiles = orderFileMapper.selectList(wrapper);
|
|
|
+ for (OrderFileEntity orderFile : orderFiles) {
|
|
|
+ if (StringUtils.isNotBlank(orderFile.getSignedPdfUrl())) {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getSignedPdfUrl(), logs, cochainLogs);
|
|
|
+ } else {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getPdfUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理视频
|
|
|
+ QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("orderId", obj.getId());
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ List<OrderRoomIdEntity> orderRoomList = orderRoomService.list(queryWrapper);
|
|
|
+ if (orderRoomList != null && orderRoomList.size() > 0) {
|
|
|
+ OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getAppVideoUrl(), logs, cochainLogs);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getPcVideoUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ // 数据插入
|
|
|
+ cochainLogService.saveBatch(logs);
|
|
|
+ }
|
|
|
+ // 担保人查询数据
|
|
|
+ GuaranteeEntity guarantee = new GuaranteeEntity();
|
|
|
+ guarantee.setBusinessNo(businessNo);
|
|
|
+ List<GuaranteeEntity> guarantees = guaranteeService.list(guarantee);
|
|
|
+ for (GuaranteeEntity obj : guarantees) {
|
|
|
+ List<CochainLogEntity> logs = new ArrayList<CochainLogEntity>();
|
|
|
+ // 身份证正面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardFront(), map, logs, cochainLogs);
|
|
|
+ // 身份证反面
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCardBack(), map, logs, cochainLogs);
|
|
|
+ // 合同
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getCompactPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getEstatesPic(), map, logs, cochainLogs);
|
|
|
+ // 房产证
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getMarragePic(), map, logs, cochainLogs);
|
|
|
+ // 其他上传
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getOtherUpload(), map, logs, cochainLogs);
|
|
|
+ // 户口本
|
|
|
+ recordCochain(businessNo, obj.getId(), obj.getHkbPic(), map, logs, cochainLogs);
|
|
|
+ // 带有盖章的pdf
|
|
|
+ QueryWrapper<OrderFileEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("business_no", businessNo);
|
|
|
+ wrapper.eq("contract_id", obj.getId());
|
|
|
+ // 这里处理,如果没有盖章的就把签名的pdf上传
|
|
|
+ List<OrderFileEntity> orderFiles = orderFileMapper.selectList(wrapper);
|
|
|
+ for (OrderFileEntity orderFile : orderFiles) {
|
|
|
+ if (StringUtils.isNotBlank(orderFile.getSignedPdfUrl())) {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getSignedPdfUrl(), logs, cochainLogs);
|
|
|
+ } else {
|
|
|
+ recordCochain(businessNo, obj.getId(), orderFile.getPdfUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理视频
|
|
|
+ QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("orderId", obj.getId());
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ List<OrderRoomIdEntity> orderRoomList = orderRoomService.list(queryWrapper);
|
|
|
+ if (orderRoomList != null && orderRoomList.size() > 0) {
|
|
|
+ OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getAppVideoUrl(), logs, cochainLogs);
|
|
|
+ recordCochain(businessNo, obj.getId(), orderRoomId.getPcVideoUrl(), logs, cochainLogs);
|
|
|
+ }
|
|
|
+ // 数据插入
|
|
|
+ cochainLogService.saveBatch(logs);
|
|
|
+ }
|
|
|
+ // 查询是否有失败的
|
|
|
+ CochainLogEntity success = new CochainLogEntity();
|
|
|
+ success.setBusinessNo(businessNo);
|
|
|
+ success.setStatus("0");
|
|
|
+ long count = cochainLogService.count(success);
|
|
|
+ if (count > 0) {
|
|
|
+ cochainEntity.setStatus("2");
|
|
|
+ cochainEntity.setUpdateTime(LocalDateTime.now());
|
|
|
+ } else {
|
|
|
+ cochainEntity.setStatus("1");
|
|
|
+ cochainEntity.setUpdateTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+ orderCochainService.updateById(cochainEntity);
|
|
|
+ log.info("【结束】调用上链业务编号:"+businessNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用第三方上链接口
|
|
|
+ */
|
|
|
+ @XxlJob("cochain")
|
|
|
+ public void jobCochain() {
|
|
|
+ chainEvidence();
|
|
|
}
|
|
|
+
|
|
|
+ public void recordCochain(String businessNo, Long orderId, String filePath, List<CochainLogEntity> logs,
|
|
|
+ List<String> cochainLogs) {
|
|
|
+ if (StringUtils.isNotBlank(filePath) && !cochainLogs.contains(filePath)) {
|
|
|
+ // 先初始化
|
|
|
+ CochainLogEntity chainLog = new CochainLogEntity();
|
|
|
+ String bisCode = UUIDGenerator.uuid();
|
|
|
+ chainLog.setBusinessNo(businessNo);
|
|
|
+ chainLog.setOrderId(orderId.toString());
|
|
|
+ chainLog.setFilePath(filePath);
|
|
|
+ chainLog.setCreateTime(LocalDateTime.now());
|
|
|
+ chainLog.setUpdateTime(LocalDateTime.now());
|
|
|
+ chainLog.setBisCode(bisCode);
|
|
|
+ long size = FileUploadUtil.getSize(filePath);
|
|
|
+ cochainService.sendRequest(chainLog, String.valueOf(size));
|
|
|
+ logs.add(chainLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void recordCochain(String businessNo, Long orderId, String fileId, Map<String, FileInfoEntity> map,
|
|
|
+ List<CochainLogEntity> logs, List<String> cochainLogs) {
|
|
|
+ if (StringUtils.isNotBlank(fileId)) {
|
|
|
+ // 先初始化
|
|
|
+ String[] list = { fileId };
|
|
|
+ if (fileId.contains(",")) {
|
|
|
+ list = fileId.split(",");
|
|
|
+ }
|
|
|
+ for (String key : list) {
|
|
|
+ // 计算是否已经包含了插入数据
|
|
|
+ FileInfoEntity fileInfo = map.get(key);
|
|
|
+ if (!cochainLogs.contains(fileInfo.getPath())) {
|
|
|
+ CochainLogEntity chainLog = new CochainLogEntity();
|
|
|
+ long size = FileUploadUtil.getSize(fileInfo.getPath());
|
|
|
+ String bisCode = UUIDGenerator.uuid();
|
|
|
+ chainLog.setBusinessNo(businessNo);
|
|
|
+ chainLog.setOrderId(orderId.toString());
|
|
|
+ chainLog.setFilePath(fileInfo.getPath());
|
|
|
+ chainLog.setImageId(fileId);
|
|
|
+ chainLog.setCreateTime(LocalDateTime.now());
|
|
|
+ chainLog.setUpdateTime(LocalDateTime.now());
|
|
|
+ chainLog.setBisCode(bisCode);
|
|
|
+ cochainService.sendRequest(chainLog, String.valueOf(size));
|
|
|
+ logs.add(chainLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|