|
|
@@ -1,10 +1,39 @@
|
|
|
package me.zhengjie.application.admin.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+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.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.zhengjie.application.admin.service.AdminOrderService;
|
|
|
import me.zhengjie.application.admin.service.OrderCochainService;
|
|
|
+import me.zhengjie.base.chain.CochainService;
|
|
|
import me.zhengjie.base.plus.AbstractServiceImpl;
|
|
|
+import me.zhengjie.base.util.FileUploadUtil;
|
|
|
+import me.zhengjie.dao.mybatis.entity.ContractOrderEntity;
|
|
|
+import me.zhengjie.dao.mybatis.entity.FileInfoEntity;
|
|
|
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.ContractOrderMapper;
|
|
|
import me.zhengjie.dao.mybatis.mapper.IOrderCochainDao;
|
|
|
+import me.zhengjie.dao.mybatis.mapper.OrderFileMapper;
|
|
|
+import me.zhengjie.dao.mybatis.mapper.OrderRoomIdMapper;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -14,7 +43,217 @@ import me.zhengjie.dao.mybatis.mapper.IOrderCochainDao;
|
|
|
* @author humuyu
|
|
|
* @since 2022-07-25
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDao, OrderCochainEntity>
|
|
|
implements OrderCochainService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrderCochainService orderCochainService;
|
|
|
+ @Autowired
|
|
|
+ AdminOrderService adminOrderService;
|
|
|
+ @Autowired
|
|
|
+ CochainService cochainService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrderFileMapper orderFileMapper;
|
|
|
+ @Autowired
|
|
|
+ OrderRoomIdMapper orderRoomIdMapper;
|
|
|
+ @Autowired
|
|
|
+ ContractOrderMapper contractOrderMapper;
|
|
|
+
|
|
|
+ private static String UPLOAD_FILE_PATH;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000l);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ chainEvidence();
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ // t.set
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initCochainPath(String path) {
|
|
|
+ // 得到文件的临时目录
|
|
|
+ String applicationDir = FileUploadUtil.getApplicationTempDir();
|
|
|
+ String downloadPath = applicationDir + "/" + path + "/";
|
|
|
+ UPLOAD_FILE_PATH = downloadPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void chainEvidence() throws Exception {
|
|
|
+
|
|
|
+ QueryWrapper<OrderCochainEntity> qw = new QueryWrapper<>();
|
|
|
+ qw = qw.in("status", 0, 2).orderByAsc("create_time").last("limit 1");
|
|
|
+
|
|
|
+ OrderCochainEntity cochainEntity = orderCochainService.getOne(qw);
|
|
|
+
|
|
|
+ if (cochainEntity == null) {
|
|
|
+ log.info("没有上链数据:");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 业务编码
|
|
|
+ String businessNo = cochainEntity.getBusinessNo();
|
|
|
+ initCochainPath(businessNo);
|
|
|
+ List<File> zipList = new ArrayList<>();
|
|
|
+ QueryWrapper<ContractOrderEntity> orderqw = new QueryWrapper<>();
|
|
|
+ orderqw.eq("business_no", businessNo);
|
|
|
+ ContractOrderEntity contractOrder = contractOrderMapper.selectOne(orderqw);
|
|
|
+ // 查询数据
|
|
|
+ log.info("【开始】调用上链业务编号:" + businessNo);
|
|
|
+ // 查询所有上传的图片
|
|
|
+ Map<String, FileInfoEntity> map = adminOrderService.getUploadFile(businessNo);
|
|
|
+ // 身份证正面idcard_front_pic
|
|
|
+ download(contractOrder.getIdcardFrontPic(), map, "身份证正面", zipList);
|
|
|
+ // 身份证反面
|
|
|
+ download(contractOrder.getIdcardBackPic(), map, "身份证反面", zipList);
|
|
|
+ // 合同contract_attachment
|
|
|
+ download(contractOrder.getContractAttachment(), map, "合同", zipList);
|
|
|
+ // 抵押物 mortgage_pic
|
|
|
+ download(contractOrder.getMortgagePic(), map, "抵押物", zipList);
|
|
|
+ // 结婚证
|
|
|
+ download(contractOrder.getMarragePic(), map, "结婚证", zipList);
|
|
|
+ // 其他上传
|
|
|
+ download(contractOrder.getOtherUpload(), map, "其他上传", zipList);
|
|
|
+ // 户口本
|
|
|
+ download(contractOrder.getHkbPic(), map, "户口本", zipList);
|
|
|
+ // 配偶身份证正面照片
|
|
|
+ download(contractOrder.getJointIdcardFrontPic(), map, "共同借款身份证正面", zipList);
|
|
|
+ // 配偶身份证反面照片
|
|
|
+ download(contractOrder.getJointIdcardBackPic(), map, "共同借款身份证反面照片", zipList);
|
|
|
+
|
|
|
+ // 带有盖章的pdf
|
|
|
+ QueryWrapper<OrderFileEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("business_no", businessNo);
|
|
|
+ // 这里处理,如果没有盖章的就把签名的pdf上传
|
|
|
+ List<OrderFileEntity> orderFiles = orderFileMapper.selectList(wrapper);
|
|
|
+ for (OrderFileEntity orderFile : orderFiles) {
|
|
|
+ if (StringUtils.isNotBlank(orderFile.getSignedPdfUrl())) {
|
|
|
+ downloadByPath(orderFile.getSignedPdfUrl(), map, orderFile.getFileName(), zipList);
|
|
|
+ } else {
|
|
|
+ downloadByPath(orderFile.getPdfUrl(), map, orderFile.getFileName(), zipList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理视频
|
|
|
+ QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("business_no", businessNo);
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ List<OrderRoomIdEntity> orderRoomList = orderRoomIdMapper.selectList(queryWrapper);
|
|
|
+ if (orderRoomList != null && orderRoomList.size() > 0) {
|
|
|
+ OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
|
|
|
+ downloadByPath(orderRoomId.getAppVideoUrl(), map, "APP视频", zipList);
|
|
|
+ downloadByPath(orderRoomId.getPcVideoUrl(), map, "PC视频", zipList);
|
|
|
+ }
|
|
|
+ String fileName = businessNo + ".zip";
|
|
|
+ // 对文件进行压缩
|
|
|
+ File targetFile = new File(UPLOAD_FILE_PATH + fileName);
|
|
|
+ ZipUtil.zip(targetFile, Charset.forName("utf-8"), false, ArrayUtil.toArray(zipList, File.class));
|
|
|
+ // 将压缩完成的文件上传到文件服务器
|
|
|
+ String contentType = "application/x-zip-compressed";
|
|
|
+ String uploadPath = businessNo + "/" + fileName;
|
|
|
+
|
|
|
+ FileUploadUtil.uploadFile(uploadPath, contentType, targetFile);
|
|
|
+
|
|
|
+ log.info("【结束】调用上链业务编号:" + businessNo);
|
|
|
+ // 修改数据库的值
|
|
|
+ OrderCochainEntity orderCochain = new OrderCochainEntity();
|
|
|
+ orderCochain.setBusinessNo(businessNo);
|
|
|
+ orderCochain.setStatus("1");
|
|
|
+ orderCochainService.update(orderCochain, OrderCochainEntity::getBusinessNo);
|
|
|
+ //调用区块
|
|
|
+
|
|
|
+ // 删除本地的所有文件
|
|
|
+ FileUtils.forceDelete(targetFile.getParentFile());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用第三方上链接口
|
|
|
+ */
|
|
|
+ @XxlJob("cochain")
|
|
|
+ public void jobCochain() {
|
|
|
+ // chainEvidence();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过文件路径上传
|
|
|
+ *
|
|
|
+ * @param businessNo
|
|
|
+ * @param orderId
|
|
|
+ * @param filePath
|
|
|
+ * @param logs
|
|
|
+ * @param cochainLogs
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void downloadByPath(String filePath, Map<String, FileInfoEntity> map, String fileName, List<File> list)
|
|
|
+ throws Exception {
|
|
|
+ if (StringUtils.isNotBlank(filePath)) {
|
|
|
+ InputStream input = null;
|
|
|
+ try {
|
|
|
+ input = FileUploadUtil.getInputStream(filePath);
|
|
|
+ int index = filePath.lastIndexOf(".");
|
|
|
+ String suffix = filePath.substring(index);
|
|
|
+ String destFile = UPLOAD_FILE_PATH + fileName + suffix;
|
|
|
+ File file = new File(destFile);
|
|
|
+ FileUtils.copyInputStreamToFile(input, file);
|
|
|
+ list.add(file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (input != null) {
|
|
|
+ input.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void download(String fileId, Map<String, FileInfoEntity> map, String fileName, List<File> list)
|
|
|
+ throws Exception {
|
|
|
+ if (StringUtils.isBlank(fileId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 先初始化
|
|
|
+ String[] fileIds = { fileId };
|
|
|
+ if (fileId.contains(",")) {
|
|
|
+ fileIds = fileId.split(",");
|
|
|
+ }
|
|
|
+ int i = 1;
|
|
|
+ for (String key : fileIds) {
|
|
|
+ // 计算是否已经包含了插入数据
|
|
|
+ FileInfoEntity fileInfo = map.get(key);
|
|
|
+ InputStream input = null;
|
|
|
+ try {
|
|
|
+ String filePath = fileInfo.getPath();
|
|
|
+ input = FileUploadUtil.getInputStream(filePath);
|
|
|
+ int index = filePath.lastIndexOf(".");
|
|
|
+ String suffix = filePath.substring(index);
|
|
|
+ String destFile = UPLOAD_FILE_PATH + fileName + (i++) + suffix;
|
|
|
+ File file = new File(destFile);
|
|
|
+ FileUtils.copyInputStreamToFile(input, file);
|
|
|
+ list.add(file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (input != null) {
|
|
|
+ input.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|