Explorar el Código

修改定时调度

humuyu hace 3 años
padre
commit
7092e8f134

+ 1 - 0
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/AdminOrderServiceImpl.java

@@ -431,6 +431,7 @@ public class AdminOrderServiceImpl implements AdminOrderService {
 		orderCochain.setBusinessNo(businessNo);
 		orderCochain.setCreateTime(LocalDateTime.now());
 		orderCochain.setUpdateTime(LocalDateTime.now());
+		orderCochain.setContractNo(contractOrderEntity.getContractNo());
 		orderCochainService.save(orderCochain);
 	}
 

+ 80 - 73
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/OrderCochainServiceImpl.java

@@ -3,6 +3,7 @@ package me.zhengjie.application.admin.service.impl;
 import java.io.File;
 import java.io.InputStream;
 import java.nio.charset.Charset;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -13,6 +14,7 @@ import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -54,7 +56,6 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 	AdminOrderService adminOrderService;
 	@Autowired
 	CochainService cochainService;
-
 	@Autowired
 	OrderFileMapper orderFileMapper;
 	@Autowired
@@ -64,23 +65,19 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 
 	private static String UPLOAD_FILE_PATH;
 
-	@PostConstruct
+//	@PostConstruct
 	public void init() {
 		new Thread(new Runnable() {
 
 			@Override
 			public void run() {
 				try {
-					Thread.sleep(1000l);
+					Thread.sleep(2000l);
 				} catch (InterruptedException e) {
 					e.printStackTrace();
 				}
-				try {
 					chainEvidence();
-				} catch (Exception e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
+				
 			}
 		}).start();
 		// t.set
@@ -94,13 +91,11 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 		UPLOAD_FILE_PATH = downloadPath;
 	}
 
-	private void chainEvidence() throws Exception {
+	private void chainEvidence()  {
 
 		QueryWrapper<OrderCochainEntity> qw = new QueryWrapper<>();
-		qw = qw.in("status", 0, 2).orderByAsc("create_time").last("limit 1");
-
+		qw = qw.lt("count", 3).in("status", 0, 2).orderByAsc("create_time").last("limit 1");
 		OrderCochainEntity cochainEntity = orderCochainService.getOne(qw);
-
 		if (cochainEntity == null) {
 			log.info("没有上链数据:");
 			return;
@@ -116,67 +111,80 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 		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);
+		OrderCochainEntity chain = new OrderCochainEntity();
+		chain.setBusinessNo(businessNo);
+		try {
+			// 身份证正面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;
+			// 处理视频
+			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);
+			// 调用区块
+			String keyResult = cochainService.getKey(businessNo);
+			JSONObject jsonObj = JSONObject.parseObject(keyResult);
+			if (jsonObj.getIntValue("code") == 0) {
+				JSONObject jsonObject = jsonObj.getJSONObject("data");
+				String key = jsonObject.getString("key");
+				long size = targetFile.length();
+				chain.setZipPath(uploadPath);
+				cochainService.sendRequest(chain, key, String.valueOf(size));
+				// 修改数据库的值
+				orderCochainService.update(chain, OrderCochainEntity::getBusinessNo);
+			}
+			log.info("【结束】调用上链业务编号:" + businessNo);
+			// 删除本地的所有文件
+			FileUtils.forceDelete(targetFile.getParentFile());
+		} catch (Exception e) {
+			log.error("上链数据出现异常:" + e.getMessage());
+			// 修改数据库的值
+			chain.setRemark(e.getMessage());
+			chain.setCount(chain.getCount() + 1);
+			orderCochainService.update(chain, OrderCochainEntity::getBusinessNo);
 
-		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());
+		}
 	}
 
 	/**
@@ -184,7 +192,7 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 	 */
 	@XxlJob("cochain")
 	public void jobCochain() {
-		// chainEvidence();
+		 chainEvidence();
 	}
 
 	/**
@@ -255,5 +263,4 @@ public class OrderCochainServiceImpl extends AbstractServiceImpl<IOrderCochainDa
 
 	}
 
-
 }

+ 10 - 12
eladmin-system/src/main/java/me/zhengjie/base/chain/CochainService.java

@@ -17,7 +17,8 @@ import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.base.util.UUIDGenerator;
-import me.zhengjie.dao.mybatis.entity.CochainLogEntity;
+
+import me.zhengjie.dao.mybatis.entity.OrderCochainEntity;
 
 @Slf4j
 @Component
@@ -28,7 +29,7 @@ public class CochainService {
 	public static final String APP_SECRET = "caf91ca41ef87e8acaad5cc16390c5eeb4ddbb8ab70eec8703c621b9e5ee4e98";
 	public static final String PRODUCE = "http://58.240.76.108:9080/produce";
 
-	public static final String COCHAIN = "http://58.240.76.108:9080/cochain";
+	public static final String COCHAIN = "http://221.6.10.202:8051/cochain";
 
 	public static String sha1_HMAC(String message) {
 		HMac mac = new HMac(HmacAlgorithm.HmacSHA1, APP_SECRET.getBytes());
@@ -36,11 +37,10 @@ public class CochainService {
 		return macHex1;
 	}
 
-//{"code":"0","data":{"key":"d220a49e284dfb207e94595a2cbdb3a0d0b58602","taskId":"11111"},"msg":"操作成功"}
 	public String getKey(String taskId) {
 		Map<String, String> params = new HashMap<>();
 		params.put("app_id", APP_ID);
-		params.put("task_id", "11111");
+		params.put("task_id", taskId);
 		String json = JSON.toJSONString(params);
 		System.out.print(json);
 		String base64 = Base64.encode(json.getBytes(StandardCharsets.UTF_8));
@@ -60,9 +60,6 @@ public class CochainService {
 
 	public static void main(String[] args) {
 
-		if (1 == 1)
-
-			return;
 //	    data = {
 //	            "app_id": APP_ID,
 //	            "key": APP_ID,
@@ -111,7 +108,7 @@ public class CochainService {
 
 	}
 
-	public String sendRequest(CochainLogEntity chainLog, String key, String size) {
+	public void sendRequest(OrderCochainEntity chainLog, String key, String size) {
 
 //	    data = {
 //	            "app_id": APP_ID,
@@ -133,7 +130,7 @@ public class CochainService {
 
 		JSONObject value = new JSONObject();
 		value.put("platCode", APP_ID);
-		value.put("bisCode", chainLog.getBisCode());
+		value.put("bisCode", chainLog.getBusinessNo());
 		value.put("type", "file");
 		value.put("length", size);
 		value.put("time", String.valueOf(new Date().getTime()));
@@ -141,7 +138,6 @@ public class CochainService {
 
 		data.put("app_id", APP_ID);
 		data.put("key", key);
-		chainLog.setSha1Code(key);
 		data.put("value", value);
 		// 使用基本编码
 		String json = JSON.toJSONString(data);
@@ -154,16 +150,18 @@ public class CochainService {
 		content.put("signature", sha);
 		String body = HttpUtil.createPost(COCHAIN).contentType("application/json").body(content.toJSONString())
 				.execute().body();
-		chainLog.setResContent(body);
+		chainLog.setRemark(body);
 		// 判断状态
 		JSONObject jsonObj = JSONObject.parseObject(body);
 		int status = jsonObj.getIntValue("status");
 		if (status == 200) {
 			chainLog.setStatus("1");
+			chainLog.setCount(0);
 		} else {
 			chainLog.setStatus("0");
+			chainLog.setCount(chainLog.getCount()+1);
 		}
-		return body;
+		
 
 	}
 }

+ 21 - 10
eladmin-system/src/main/java/me/zhengjie/base/plus/AbstractService.java

@@ -5,6 +5,8 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.reflection.property.PropertyNamer;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -16,6 +18,8 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 public interface AbstractService<T> extends IService<T> {
+	static final Log logger = LogFactory.getLog(AbstractService.class);
+
 	/**
 	 * 博客地址:https://blog.csdn.net/qq_19266669/article/details/114369195
 	 * 查看AbstractLambdaWrapper通过方法得到字段名称
@@ -59,6 +63,7 @@ public interface AbstractService<T> extends IService<T> {
 		}
 		return false;
 	}
+
 	/**
 	 * 根据 whereEntity 条件,更新记录
 	 *
@@ -78,21 +83,27 @@ public interface AbstractService<T> extends IService<T> {
 		}
 		return false;
 	}
-	default boolean update(T entity, SFunction<T, ?> column) throws Exception {
+
+	default boolean update(T entity, SFunction<T, ?> column) {
 		// 这里是反射,通过反射来得到
 
 //		Field startRange = clazz.getDeclaredField(attribute[0]);
 //		startRange.setAccessible(true);
 //		Object val = startRange.get(obj);
-		String columnName = columnToString(column);
-		String fieldName = getFieldName(column);
-		Class<?> clazz = entity.getClass();
-		Field field = clazz.getDeclaredField(fieldName);
-		// 抑制Java对修饰符的检查
-		field.setAccessible(true);
-		Object value = field.get(entity);
-		field.set(entity, null);
-		return update(entity, columnName, value);
+		try {
+			String columnName = columnToString(column);
+			String fieldName = getFieldName(column);
+			Class<?> clazz = entity.getClass();
+			Field field = clazz.getDeclaredField(fieldName);
+			// 抑制Java对修饰符的检查
+			field.setAccessible(true);
+			Object value = field.get(entity);
+			field.set(entity, null);
+			return update(entity, columnName, value);
+		} catch (Exception e) {
+			logger.error("update class" + entity.getClass() + " exception :" + e.getMessage());
+			return false;
+		}
 
 	}
 

+ 29 - 0
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/OrderCochainEntity.java

@@ -34,6 +34,30 @@ public class OrderCochainEntity implements Serializable {
 	 */
 	@TableField("status")
 	private String status;
+	
+	@TableField("contract_no")
+	private String contractNo;
+	
+	
+	/**
+	 * 计数数据
+	 */
+	@TableField("count")
+	private int count;
+	
+	
+	/**
+	 * 请求参数
+	 */
+	@TableField("req_param")
+	private String reqParam;
+
+	/**
+	 * 返回的参数内容
+	 */
+	@TableField("remark")
+	private String remark;
+	
 	/**
 	 * 创建时间
 	 */
@@ -45,4 +69,9 @@ public class OrderCochainEntity implements Serializable {
 	 */
 	@TableField("update_time")
 	private LocalDateTime updateTime;
+	/**
+	 * zip路径
+	 */
+	@TableField("zip_path")
+	private String  zipPath;
 }