区块链调试

This commit is contained in:
zhangqinbin
2021-09-02 16:43:13 +08:00
parent b240cd0542
commit f67f010eeb
2 changed files with 29 additions and 13 deletions

View File

@ -1,15 +1,22 @@
package com.chinaunicom.mall.ebtp.extend.blockchain.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chinaunicom.mall.ebtp.common.config.CustomLocalDateTimeTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 实体类 BlockChainLog
@ -77,5 +84,10 @@ public class BlockChainLog implements Serializable {
*/
@ApiModelProperty(value = "0-成功 1-失败")
private Integer status;
@TableField(fill = FieldFill.INSERT,typeHandler = CustomLocalDateTimeTypeHandler.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
private LocalDateTime createDate;
}

View File

@ -22,6 +22,7 @@ import com.chinaunicom.mall.ebtp.extend.crypconfigure.dao.CrypConfigureMapper;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -41,6 +42,7 @@ import static com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl.
* @author yss
*
*/
@Slf4j
@Service
public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMapper,CrypConfigure> implements ICrypConfigureService {
@ -68,10 +70,10 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
*/
@Override
public Boolean callUniInterface(CrypBean bean){
BlockChainLog log = new BlockChainLog();
log.setId(PropertyUtils.getSnowflakeId());
BlockChainLog blockChainLog = new BlockChainLog();
blockChainLog.setId(PropertyUtils.getSnowflakeId());
//天擎地址
log.setInterfaceUrl(bean.getUrl());
blockChainLog.setInterfaceUrl(bean.getUrl());
try {
LinkedHashMap<String, Object> map = JSONArray.parseObject(JSONArray.toJSONString(bean.getObject()), LinkedHashMap.class);
@ -89,34 +91,36 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
String json = getUniBss(bean.getReqName(),map);
log.setParam(json);
blockChainLog.setParam(json);//请求参数
String str = UniBssServiceImpl.uniBssHttpPost(bean.getUrl(), json);
log.setResult(str);//返回参数
blockChainLog.setResult(str);//返回参数
UniBss uniBssRsp = JSONArray.parseObject(str, UniBss.class);
if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) {
log.debug("返回接口:"+uniBssRsp);
Object rspObject = uniBssRsp.getUniBssBody().getSingleOrderQryRsp();
LinkedHashMap<String, Object> rspMap = JSONArray.parseObject(JSONArray.toJSONString(rspObject), LinkedHashMap.class);
if(rspMap.get("Code")!=null&&"200".equals(rspMap.get("Code").toString())){
log.setStatus(0);//成功
this.iBlockChainLogService.save(log);
log.debug("请求成功:"+rspMap);
blockChainLog.setStatus(0);//成功
this.iBlockChainLogService.save(blockChainLog);
return true;
}else{
log.setStatus(1);//失败
blockChainLog.setStatus(1);//失败
}
} else {
log.setStatus(1);//失败
blockChainLog.setStatus(1);//失败
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.assertStringNotNullByKey("天擎接口调用错误," +
"RESP_CODE:" + uniBssRsp.getUniBssHead().getRespCode() + "" +
"(" + UniBssConstant.getRESP_CODE_Map(uniBssRsp.getUniBssHead().getRespCode()) + ")。" +
"RESP_DESC:" + uniBssRsp.getUniBssHead().getRespDesc(), bean);
}
}catch (Exception e){
log.setStatus(1);
log.setResult(e.getMessage());
blockChainLog.setStatus(1);
blockChainLog.setResult(e.getMessage());
}
this.iBlockChainLogService.save(log);
this.iBlockChainLogService.save(blockChainLog);
return false;
}