Commit bb97589a authored by tangtuo's avatar tangtuo

修改更新版权状态为定时任务更新

parent 9e217241
......@@ -5,7 +5,9 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@EnableSwagger2Doc
@EnableCaching
@SpringBootApplication(scanBasePackages = {"com.fzm.admin", "com.fzm.common"})
......
package com.fzm.admin.listener;
import cn.fzm.chain.simplesdk.client.ParaChainClient;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.fzm.common.config.RabbitMQConfig;
import com.fzm.common.entity.CopyrightApply;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.dto.CopyrightQueryRequest;
import com.fzm.common.entity.dto.CopyrightQueryResponse;
import com.fzm.common.entity.dto.EvidenceHashMessage;
import com.fzm.common.entity.vo.NftVo;
import com.fzm.common.enums.CopyrightApplyState;
import com.fzm.common.properties.CopyrightProperties;
import com.fzm.common.service.CopyrightApplyService;
import com.fzm.common.service.NftService;
import com.fzm.common.utils.CopyrightSignUtil;
import com.fzm.common.utils.JsonUtil;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
/**
* @author tangtuo
* @date 2021/12/23 14:56
*/
@Slf4j
@Component
public class CopyrightLister {
@Resource
private CopyrightProperties copyrightProperties;
@Resource
private RabbitTemplate rabbitTemplate;
@Resource
private CopyrightApplyService copyrightApplyService;
@Resource
private ParaChainClient paraChainClient;
@Resource
private NftService nftService;
private static String abi = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"values\",\"type\":\"uint256[]\"}],\"name\":\"TransferBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"TransferSingle\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"value\",\"type\":\"string\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"URI\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"accounts\",\"type\":\"address[]\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"}],\"name\":\"balanceOfBatch\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"burnToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"burnTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getTokenInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"getUserTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mintToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"mintTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeBatchTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"tokenInfo\",\"type\":\"string\"}],\"name\":\"setTokenInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"uri\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";
@Value("${chain.para.cAddr}")
private String contractAddr;
/**
* 主动查询当前流水号对应的版权审批结果
*
* @param serial_code
*/
@RabbitListener(queues = RabbitMQConfig.COPYRIGHT_QUEUE)
public void listerCopyrightApply(String serial_code, Message message, Channel channel) throws IOException {
log.info("监听者接收消息, 流水号为: {}", serial_code);
long deliveryTag = message.getMessageProperties().getDeliveryTag();
try {
CopyrightQueryRequest request = new CopyrightQueryRequest(serial_code, copyrightProperties.getAppId());
TreeMap<String, String> map = this.beanToMap(request, copyrightProperties.getAppSecret());
String sign = CopyrightSignUtil.generateSign(map);
request.setSign(sign);
String json = JSONUtil.toJsonStr(request);
log.info("查询审核结果, 当前流水号为:{} , 请求参数为 : {}", serial_code, json);
String response = HttpUtil.post(copyrightProperties.getQueryUrl(), json, 10000);
log.info("查询审核结果接口响应内容: {}", response);
if (StringUtils.isBlank(response)) {
// 接口无响应, 把消息丢进延时队列, 稍后重试
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
channel.basicAck(deliveryTag, false);
log.error("版权局查询存证接口无响应");
return;
}
CopyrightQueryResponse copyrightResponse = JsonUtil.toObject(response, CopyrightQueryResponse.class);
if (copyrightResponse == null) {
// 接口无响应,手动签收, 把消息丢进延时队列, 稍后重试
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
channel.basicAck(deliveryTag, false);
log.error("版权局查询存证接口无响应");
return;
}
if (!copyrightResponse.isSuccess()) {
// 接口请求失败,手动签收, 把消息丢进延时队列, 稍后重试
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
channel.basicAck(deliveryTag, false);
log.error("接口响应失败, 失败原因:{}", copyrightResponse.getMessage());
return;
}
CopyrightApply copyrightApply = copyrightApplyService.getBySerialNum(serial_code);
// if (copyrightApply == null) {
// log.error("unknown serial_code: {}", serial_code);
//package com.fzm.admin.listener;
//
//import cn.fzm.chain.simplesdk.client.ParaChainClient;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.lang.TypeReference;
//import cn.hutool.http.HttpUtil;
//import cn.hutool.json.JSONUtil;
//import com.fzm.common.config.RabbitMQConfig;
//import com.fzm.common.entity.CopyrightApply;
//import com.fzm.common.entity.Nft;
//import com.fzm.common.entity.dto.CopyrightQueryRequest;
//import com.fzm.common.entity.dto.CopyrightQueryResponse;
//import com.fzm.common.entity.dto.EvidenceHashMessage;
//import com.fzm.common.entity.vo.NftVo;
//import com.fzm.common.enums.CopyrightApplyState;
//import com.fzm.common.properties.CopyrightProperties;
//import com.fzm.common.service.CopyrightApplyService;
//import com.fzm.common.service.NftService;
//import com.fzm.common.utils.CopyrightSignUtil;
//import com.fzm.common.utils.JsonUtil;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.util.Map;
//import java.util.TreeMap;
//
///**
// * @author tangtuo
// * @date 2021/12/23 14:56
// */
//@Slf4j
//@Component
//public class CopyrightLister {
//
// @Resource
// private CopyrightProperties copyrightProperties;
//
// @Resource
// private RabbitTemplate rabbitTemplate;
//
// @Resource
// private CopyrightApplyService copyrightApplyService;
//
// @Resource
// private ParaChainClient paraChainClient;
//
// @Resource
// private NftService nftService;
//
// private static String abi = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"values\",\"type\":\"uint256[]\"}],\"name\":\"TransferBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"TransferSingle\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"value\",\"type\":\"string\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"URI\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"accounts\",\"type\":\"address[]\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"}],\"name\":\"balanceOfBatch\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"burnToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"burnTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getTokenInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"getUserTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mintToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"mintTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeBatchTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"tokenInfo\",\"type\":\"string\"}],\"name\":\"setTokenInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"uri\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";
//
// @Value("${chain.para.cAddr}")
// private String contractAddr;
//
// /**
// * 主动查询当前流水号对应的版权审批结果
// *
// * @param serial_code
// */
// @RabbitListener(queues = RabbitMQConfig.COPYRIGHT_QUEUE)
// public void listerCopyrightApply(String serial_code, Message message, Channel channel) throws IOException {
// log.info("监听者接收消息, 流水号为: {}", serial_code);
// long deliveryTag = message.getMessageProperties().getDeliveryTag();
// try {
// CopyrightQueryRequest request = new CopyrightQueryRequest(serial_code, copyrightProperties.getAppId());
// TreeMap<String, String> map = this.beanToMap(request, copyrightProperties.getAppSecret());
// String sign = CopyrightSignUtil.generateSign(map);
// request.setSign(sign);
// String json = JSONUtil.toJsonStr(request);
// log.info("查询审核结果, 当前流水号为:{} , 请求参数为 : {}", serial_code, json);
// String response = HttpUtil.post(copyrightProperties.getQueryUrl(), json, 10000);
// log.info("查询审核结果接口响应内容: {}", response);
// if (StringUtils.isBlank(response)) {
// // 接口无响应, 把消息丢进延时队列, 稍后重试
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// channel.basicAck(deliveryTag, false);
// log.error("版权局查询存证接口无响应");
// return;
// }
//审核状态(0:未提交,1:待审核,2:同意,3:驳回,4:已提交,5:待终审,6:审核通过)
if (!copyrightResponse.getAudit_status().equals(3) && !copyrightResponse.getAudit_status().equals(6)) {
if (copyrightResponse.getAudit_status().equals(1)) {
// 待审核
copyrightApply.setRegisterState(CopyrightApplyState.EXAMINE.getCode());
} else if (copyrightResponse.getAudit_status().equals(5)) {
// 待终审
copyrightApply.setRegisterState(CopyrightApplyState.FINAL_JUDGMENT.getCode());
}
// 审核还未完成, 需要把当前流水号丢进死信队列, 6小时后再去查询
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
} else {
if (copyrightResponse.getAudit_status().equals(6)) {
// 审核成功
String nftHash = copyrightApply.getNftHash();
copyrightApply.setEvidenceDate(DateUtil.parse(copyrightResponse.getApply_time(), "yyyy-MM-dd"));
copyrightApply.setRegisterCode(copyrightResponse.getCertificate().getRegister_code());
copyrightApply.setRegisterState(CopyrightApplyState.SUCCEEDED.getCode());
Nft nft = nftService.getByNftHash(nftHash);
String tokenInfo = paraChainClient.evmGetTokenInfo(abi, contractAddr, nft.getTokenId(), nft.getPublishAddress());
NftVo detail = nftService.getDetail(nftHash);
String newTokenInfo = appendTokenInfo(tokenInfo, detail.getCopyright());
log.info("追加tokenInfo, 新生成后的tokenInfo为: {}", newTokenInfo);
String hash = paraChainClient.evmSetTokenInfo(abi, contractAddr, 0, nft.getTokenId(), newTokenInfo, nft.getPublishAddress(), null, true);
if (StringUtils.isBlank(hash)) {
log.error("nft追加tokenInfo失败,当前流水号为: 【{}】,交易哈希:【{}】", serial_code, hash);
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
return;
}
// 发送交易hash到死信队列,5秒后查询真实哈希,然后更新存证hash
EvidenceHashMessage msg = new EvidenceHashMessage(serial_code, hash);
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "evidence.hash.query", msg);
// String realTxHash = paraChainClient.getRealTxHashFromGrp(hash);
// log.info("真实哈希为: {}", realTxHash);
// copyrightApply.setEvidenceHash(realTxHash);
} else {
// 审核失败
copyrightApply.setRejectReason(copyrightResponse.getRemark());
copyrightApply.setRegisterState(CopyrightApplyState.FAILED.getCode());
}
}
copyrightApplyService.updateById(copyrightApply);
} catch (Exception e) {
// 如果上链失败或者更新状态失败, 那么就把消息重新丢入延时队列,稍后重试
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
log.error(e.getMessage(), e);
} finally {
channel.basicAck(deliveryTag, false);
}
}
private TreeMap<String, String> beanToMap(CopyrightQueryRequest request, String app_secret) {
TreeMap<String, String> map = JSONUtil.toBean(JSONUtil.toJsonStr(request), new TypeReference<TreeMap<String, String>>() {
}, true);
map.put("app_secret", app_secret);
return map;
}
private String appendTokenInfo(String tokenInfo, NftVo.Copyright copyright) {
String[] split = tokenInfo.split("&");
TreeMap<String, String> map = new TreeMap<>();
for (String s : split) {
String[] arr = s.split("=");
String key = arr[0];
String value;
if (arr.length < 2) {
value = "";
} else {
value = arr[1];
}
map.put(key, value);
}
map.put("evidencer", copyright.getEvidencer());
map.put("opusName", copyright.getOpusName());
map.put("opusType", copyright.getOpusType());
map.put("author", copyright.getAuthor());
map.put("copyrightOwner", copyright.getCopyrightOwner());
map.put("registerCode", copyright.getRegisterCode());
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : map.entrySet()) {
String value = entry.getValue();
String key = entry.getKey();
stringBuilder.append(key).append("=").append(value).append("&");
}
return stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
}
public static void main(String[] args) {
String str = "https://filmchain-file.obs.cn-east-3.myhuaweicloud.com/5f7d224aab0c4c22ae77aa2a21a0787c/权利取得方式证明材料附件 (7).docx";
String s = str.replaceAll(" ", "");
System.out.println(s.equals(str));
}
}
// CopyrightQueryResponse copyrightResponse = JsonUtil.toObject(response, CopyrightQueryResponse.class);
// if (copyrightResponse == null) {
// // 接口无响应,手动签收, 把消息丢进延时队列, 稍后重试
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// channel.basicAck(deliveryTag, false);
// log.error("版权局查询存证接口无响应");
// return;
// }
// if (!copyrightResponse.isSuccess()) {
// // 接口请求失败,手动签收, 把消息丢进延时队列, 稍后重试
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// channel.basicAck(deliveryTag, false);
// log.error("接口响应失败, 失败原因:{}", copyrightResponse.getMessage());
// return;
// }
// CopyrightApply copyrightApply = copyrightApplyService.getBySerialNum(serial_code);
//// if (copyrightApply == null) {
//// log.error("unknown serial_code: {}", serial_code);
//// return;
//// }
// //审核状态(0:未提交,1:待审核,2:同意,3:驳回,4:已提交,5:待终审,6:审核通过)
// if (!copyrightResponse.getAudit_status().equals(3) && !copyrightResponse.getAudit_status().equals(6)) {
// if (copyrightResponse.getAudit_status().equals(1)) {
// // 待审核
// copyrightApply.setRegisterState(CopyrightApplyState.EXAMINE.getCode());
// } else if (copyrightResponse.getAudit_status().equals(5)) {
// // 待终审
// copyrightApply.setRegisterState(CopyrightApplyState.FINAL_JUDGMENT.getCode());
// }
// // 审核还未完成, 需要把当前流水号丢进死信队列, 6小时后再去查询
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// } else {
// if (copyrightResponse.getAudit_status().equals(6)) {
// // 审核成功
// String nftHash = copyrightApply.getNftHash();
// copyrightApply.setEvidenceDate(DateUtil.parse(copyrightResponse.getApply_time(), "yyyy-MM-dd"));
// copyrightApply.setRegisterCode(copyrightResponse.getCertificate().getRegister_code());
// copyrightApply.setRegisterState(CopyrightApplyState.SUCCEEDED.getCode());
// Nft nft = nftService.getByNftHash(nftHash);
// String tokenInfo = paraChainClient.evmGetTokenInfo(abi, contractAddr, nft.getTokenId(), nft.getPublishAddress());
// NftVo detail = nftService.getDetail(nftHash);
// String newTokenInfo = appendTokenInfo(tokenInfo, detail.getCopyright());
// log.info("追加tokenInfo, 新生成后的tokenInfo为: {}", newTokenInfo);
// String hash = paraChainClient.evmSetTokenInfo(abi, contractAddr, 0, nft.getTokenId(), newTokenInfo, nft.getPublishAddress(), null, true);
// if (StringUtils.isBlank(hash)) {
// log.error("nft追加tokenInfo失败,当前流水号为: 【{}】,交易哈希:【{}】", serial_code, hash);
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// return;
// }
// // 发送交易hash到死信队列,5秒后查询真实哈希,然后更新存证hash
// EvidenceHashMessage msg = new EvidenceHashMessage(serial_code, hash);
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "evidence.hash.query", msg);
//// String realTxHash = paraChainClient.getRealTxHashFromGrp(hash);
//// log.info("真实哈希为: {}", realTxHash);
//// copyrightApply.setEvidenceHash(realTxHash);
// } else {
// // 审核失败
// copyrightApply.setRejectReason(copyrightResponse.getRemark());
// copyrightApply.setRegisterState(CopyrightApplyState.FAILED.getCode());
// }
// }
// copyrightApplyService.updateById(copyrightApply);
// } catch (Exception e) {
// // 如果上链失败或者更新状态失败, 那么就把消息重新丢入延时队列,稍后重试
// rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
// log.error(e.getMessage(), e);
// } finally {
// channel.basicAck(deliveryTag, false);
// }
//
// }
//
//
// private TreeMap<String, String> beanToMap(CopyrightQueryRequest request, String app_secret) {
// TreeMap<String, String> map = JSONUtil.toBean(JSONUtil.toJsonStr(request), new TypeReference<TreeMap<String, String>>() {
// }, true);
// map.put("app_secret", app_secret);
// return map;
// }
//
// private String appendTokenInfo(String tokenInfo, NftVo.Copyright copyright) {
// String[] split = tokenInfo.split("&");
// TreeMap<String, String> map = new TreeMap<>();
// for (String s : split) {
// String[] arr = s.split("=");
// String key = arr[0];
// String value;
// if (arr.length < 2) {
// value = "";
// } else {
// value = arr[1];
// }
// map.put(key, value);
// }
// map.put("evidencer", copyright.getEvidencer());
// map.put("opusName", copyright.getOpusName());
// map.put("opusType", copyright.getOpusType());
// map.put("author", copyright.getAuthor());
// map.put("copyrightOwner", copyright.getCopyrightOwner());
// map.put("registerCode", copyright.getRegisterCode());
// StringBuilder stringBuilder = new StringBuilder();
// for (Map.Entry<String, String> entry : map.entrySet()) {
// String value = entry.getValue();
// String key = entry.getKey();
// stringBuilder.append(key).append("=").append(value).append("&");
// }
// return stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
// }
//
//
// public static void main(String[] args) {
// String str = "https://filmchain-file.obs.cn-east-3.myhuaweicloud.com/5f7d224aab0c4c22ae77aa2a21a0787c/权利取得方式证明材料附件 (7).docx";
// String s = str.replaceAll(" ", "");
// System.out.println(s.equals(str));
// }
//}
package com.fzm.admin.schedule;
import cn.fzm.chain.simplesdk.client.ParaChainClient;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.fzm.common.config.RabbitMQConfig;
import com.fzm.common.entity.CopyrightApply;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.dto.CopyrightQueryRequest;
import com.fzm.common.entity.dto.CopyrightQueryResponse;
import com.fzm.common.entity.dto.EvidenceHashMessage;
import com.fzm.common.entity.vo.NftVo;
import com.fzm.common.enums.CopyrightApplyState;
import com.fzm.common.properties.CopyrightProperties;
import com.fzm.common.service.CopyrightApplyService;
import com.fzm.common.service.NftService;
import com.fzm.common.utils.CopyrightSignUtil;
import com.fzm.common.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
/**
* @author tangtuo
* @date 2022/1/10 15:17
*/
@Slf4j
@Component
public class CopyrightTask {
@Resource
private CopyrightApplyService copyrightApplyService;
@Resource
private Redisson redisson;
@Resource
private CopyrightProperties copyrightProperties;
@Resource
private ParaChainClient paraChainClient;
@Resource
private NftService nftService;
private static String abi = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"indexed\":false,\"internalType\":\"uint256[]\",\"name\":\"values\",\"type\":\"uint256[]\"}],\"name\":\"TransferBatch\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"TransferSingle\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"value\",\"type\":\"string\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"URI\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"accounts\",\"type\":\"address[]\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"}],\"name\":\"balanceOfBatch\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"burnToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"burnTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getTokenInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"getUserTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mintToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"name\":\"mintTokenBatch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"ids\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeBatchTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"tokenInfo\",\"type\":\"string\"}],\"name\":\"setTokenInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferToken\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"uri\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";
@Value("${chain.para.cAddr}")
private String contractAddr;
@Resource
private RabbitTemplate rabbitTemplate;
private Integer audit_status;
/**
* 定时任务更新版权申请状态
*/
@Scheduled(cron = "0 */2 * * * ?")
public void updateCopyrightState() throws InterruptedException {
// 加锁,防止集群部署时,定时任务在多个节点上执行
RLock lock = redisson.getLock("update:copyright:state");
if (!lock.tryLock(30, TimeUnit.SECONDS)) {
log.warn("更新版权状态的定时任务已在其他节点运行");
return;
}
try {
List<String> list = copyrightApplyService.getSerialCodes();
if (CollectionUtil.isEmpty(list)) {
log.info("当前无待更新状态的申请记录");
return;
}
for (String serial_code : list) {
try {
log.info("更新状态: 当前流水号为: {}", serial_code);
CopyrightQueryRequest request = new CopyrightQueryRequest(serial_code, copyrightProperties.getAppId());
TreeMap<String, String> map = this.beanToMap(request, copyrightProperties.getAppSecret());
String sign = CopyrightSignUtil.generateSign(map);
request.setSign(sign);
String json = JSONUtil.toJsonStr(request);
log.info("查询审核结果, 当前流水号为:{} , 请求参数为 : {}", serial_code, json);
String response = HttpUtil.post(copyrightProperties.getQueryUrl(), json, 10000);
log.info("查询审核结果接口响应内容: {}", response);
if (StringUtils.isBlank(response)) {
log.error("版权局查询存证接口无响应, 流水号: {}", serial_code);
continue;
}
CopyrightQueryResponse copyrightResponse = JsonUtil.toObject(response, CopyrightQueryResponse.class);
if (copyrightResponse == null) {
log.error("版权局查询存证接口无响应, 流水号: {}", serial_code);
continue;
}
if (!copyrightResponse.isSuccess()) {
log.error("接口响应失败, 失败原因:{}, 流水号: {}", copyrightResponse.getMessage(), serial_code);
continue;
}
CopyrightApply copyrightApply = copyrightApplyService.getBySerialNum(serial_code);
//审核状态(0:未提交,1:待审核,2:同意,3:驳回,4:已提交,5:待终审,6:审核通过)
Integer audit_status = copyrightResponse.getAudit_status();
Integer registerState = getRegisterState(audit_status);
if (registerState == null || registerState.equals(copyrightApply.getRegisterState())) {
log.info("当前版权状态无更新, 流水号为: {}", serial_code);
continue;
}
copyrightApply.setRegisterState(registerState);
if (registerState.equals(CopyrightApplyState.SUCCEEDED.getCode())) {
// 审核成功
String nftHash = copyrightApply.getNftHash();
copyrightApply.setEvidenceDate(DateUtil.parse(copyrightResponse.getApply_time(), "yyyy-MM-dd"));
copyrightApply.setRegisterCode(copyrightResponse.getCertificate().getRegister_code());
copyrightApply.setRegisterState(CopyrightApplyState.SUCCEEDED.getCode());
Nft nft = nftService.getByNftHash(nftHash);
String tokenInfo = paraChainClient.evmGetTokenInfo(abi, contractAddr, nft.getTokenId(), nft.getPublishAddress());
NftVo detail = nftService.getDetail(nftHash);
String newTokenInfo = appendTokenInfo(tokenInfo, detail.getCopyright());
log.info("追加tokenInfo, 新生成后的tokenInfo为: {}", newTokenInfo);
String hash = paraChainClient.evmSetTokenInfo(abi, contractAddr, 0, nft.getTokenId(), newTokenInfo, nft.getPublishAddress(), null, true);
if (StringUtils.isBlank(hash)) {
log.error("nft追加tokenInfo失败,当前流水号为: 【{}】,交易哈希:【{}】", serial_code, hash);
continue;
}
// 发送交易hash到死信队列,5秒后查询真实哈希,然后更新存证hash
EvidenceHashMessage msg = new EvidenceHashMessage(serial_code, hash);
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "evidence.hash.query", msg);
} else if (registerState.equals(CopyrightApplyState.FAILED.getCode())) {
// 审核失败,更新驳回原因
copyrightApply.setRejectReason(copyrightResponse.getRemark());
}
copyrightApplyService.updateById(copyrightApply);
} catch (Exception e) {
log.error("更新版权状态发送异常, 当前流水号为:{}", serial_code);
log.error(e.getMessage(), e);
}
}
} finally {
lock.unlock();
}
}
private TreeMap<String, String> beanToMap(CopyrightQueryRequest request, String app_secret) {
TreeMap<String, String> map = JSONUtil.toBean(JSONUtil.toJsonStr(request), new TypeReference<TreeMap<String, String>>() {
}, true);
map.put("app_secret", app_secret);
return map;
}
private String appendTokenInfo(String tokenInfo, NftVo.Copyright copyright) {
String[] split = tokenInfo.split("&");
TreeMap<String, String> map = new TreeMap<>();
for (String s : split) {
String[] arr = s.split("=");
String key = arr[0];
String value;
if (arr.length < 2) {
value = "";
} else {
value = arr[1];
}
map.put(key, value);
}
map.put("evidencer", copyright.getEvidencer());
map.put("opusName", copyright.getOpusName());
map.put("opusType", copyright.getOpusType());
map.put("author", copyright.getAuthor());
map.put("copyrightOwner", copyright.getCopyrightOwner());
map.put("registerCode", copyright.getRegisterCode());
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : map.entrySet()) {
String value = entry.getValue();
String key = entry.getKey();
stringBuilder.append(key).append("=").append(value).append("&");
}
return stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
}
private Integer getRegisterState(Integer audi_status) {
// audi_status 审核状态(0:未提交,1:待审核,2:同意,3:驳回,4:已提交,5:待终审,6:审核通过)
switch (audi_status) {
case 1:
return CopyrightApplyState.EXAMINE.getCode();
case 5:
return CopyrightApplyState.FINAL_JUDGMENT.getCode();
case 3:
return CopyrightApplyState.FAILED.getCode();
case 6:
return CopyrightApplyState.SUCCEEDED.getCode();
default:
return null;
}
}
}
......@@ -28,7 +28,7 @@ spring:
useGlobalDataSourceStat: true
redis:
host: 172.16.101.135
host: localhost
port: 6379
password: 123456
lettuce:
......
......@@ -92,6 +92,9 @@ public class CopyrightApply {
@ApiModelProperty(value = "申请时间")
private Date applyTime;
@ApiModelProperty(value = "版权申请后台核验通过时间")
private Date passTime;
@ApiModelProperty(value = "登记状态 0-待审核 1-登记成功 2-审核失败")
private Integer registerState;
......
......@@ -21,6 +21,9 @@ public class CopyrightDTO {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("草稿id")
private Integer draftId;
@NotBlank(message = "nft哈希不能为空")
@ApiModelProperty(value = "nft哈希")
private String nftHash;
......
......@@ -37,6 +37,9 @@ public class CopyrightRequest {
@Data
public static class CopyrightDetail {
@ApiModelProperty(value = "流水号")
private String serial_code;
@ApiModelProperty(value = "权利归属方式名称图片")
private String affilia_photo;
......@@ -144,6 +147,7 @@ public class CopyrightRequest {
private String works_type_name;
public CopyrightDetail(CopyrightVo copyrightVo, OpusCategory opusCategory) {
this.serial_code = copyrightVo.getSerialNum();
this.affilia_photo = copyrightVo.getAuthorityAscriptionProve();
this.agency_photo = copyrightVo.getRegisterEntrust();
this.author_photo = "";
......
......@@ -12,6 +12,8 @@ import javax.validation.constraints.NotNull;
@Data
public class DraftDTO {
private Integer id;
@NotBlank(message = "草稿内容不能为空")
private String content;
......
package com.fzm.common.entity.vo;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fzm.common.entity.CopyrightApplyOwnerRelation;
import com.fzm.common.entity.CopyrightAuthor;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.User;
import com.fzm.common.enums.CopyrightApplyState;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import sun.management.counter.perf.PerfInstrumentation;
import java.util.Date;
import java.util.stream.Collectors;
......@@ -45,6 +42,8 @@ public class NftVo {
@ApiModelProperty("作者")
private String author;
@ApiModelProperty("简介")
private String synopsis;
@ApiModelProperty("文件哈希")
private String fileHash;
......@@ -83,15 +82,18 @@ public class NftVo {
@ApiModelProperty("著作权人")
private String copyrightOwner;
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("作品完成时间")
private Date opusCompleteDate;
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("作品首次发表时间")
private Date firstPublishDate;
@ApiModelProperty("登记时间")
private Date registerDate;
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("存证时间")
private Date evidenceTime;
......@@ -123,6 +125,7 @@ public class NftVo {
this.nftHash = nft.getNftHash();
this.fileHash = nft.getFileHash();
this.evidenceTime = nft.getPublishTime();
this.synopsis = nft.getSynopsis();
this.copyright = (copyrightVo == null) ? null : new Copyright(copyrightVo);
}
......
......@@ -26,4 +26,7 @@ public interface CopyrightApplyMapper extends BaseMapper<CopyrightApply> {
List<CopyrightApply> list(@Param("userId") Integer userId, @Param("state") Integer state);
List<CopyrightApplyVo> pages(@Param("telephone") String telephone, @Param("serialNum") String serialNum, @Param("registerState") Integer registerState, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate);
List<String> getSerialCodes();
}
......@@ -135,4 +135,12 @@ public interface CopyrightApplyService extends IService<CopyrightApply> {
* @return
*/
Boolean existsByNftHash(String nftHash);
/**
* 查询所有待更新状态的版权申请的流水号
*
* @return
*/
List<String> getSerialCodes();
}
......@@ -8,7 +8,6 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.common.config.RabbitMQConfig;
import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.*;
import com.fzm.common.entity.dto.CopyrightDTO;
......@@ -31,14 +30,16 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
......@@ -92,10 +93,10 @@ public class CopyrightApplyServiceImpl extends ServiceImpl<CopyrightApplyMapper,
private CopyrightProperties copyrightProperties;
@Resource
private RabbitTemplate rabbitTemplate;
private Redisson redisson;
@Resource
private Redisson redisson;
private DraftService draftService;
@Override
......@@ -152,6 +153,10 @@ public class CopyrightApplyServiceImpl extends ServiceImpl<CopyrightApplyMapper,
CopyrightAuthorityRelation relation = new CopyrightAuthorityRelation(copyrightApply.getId(), authorityId);
relations.add(relation);
}
// 如果是从草稿箱进来的需要删除草稿信息
if (copyrightDTO.getDraftId() != null) {
draftService.removeById(copyrightDTO.getDraftId());
}
copyrightAuthorityRelationService.saveBatch(relations);
return copyrightApply.getId();
}
......@@ -369,10 +374,10 @@ public class CopyrightApplyServiceImpl extends ServiceImpl<CopyrightApplyMapper,
}
// 申请成功
String serial_code = copyrightResponse.getSerial_code();
rabbitTemplate.convertAndSend(RabbitMQConfig.COPYRIGHT_DIRECT, "copyright.apply", serial_code);
copyright.setSerialNum(serial_code);
copyright.setRegisterState(CopyrightApplyState.SUBMITTED.getCode());
copyright.setRejectReason("");
copyright.setPassTime(new Date());
return updateById(copyright);
} finally {
lock.unlock();
......@@ -434,4 +439,9 @@ public class CopyrightApplyServiceImpl extends ServiceImpl<CopyrightApplyMapper,
return count(queryWrapper) > 0;
}
@Override
public List<String> getSerialCodes() {
return copyrightApplyMapper.getSerialCodes();
}
}
......@@ -103,17 +103,9 @@ public class DraftServiceImpl extends ServiceImpl<DraftMapper, Draft> implements
@Override
public Integer saveDraft(DraftDTO draft) {
if (draft.getCopyrightId() != null) {
CopyrightApply copyright = copyrightApplyService.getById(draft.getCopyrightId());
if (copyright != null && copyright.getRegisterState().equals(CopyrightApplyState.WITHDRAW.getCode())) {
copyrightApplyService.removeById(draft.getCopyrightId());
copyrightAuthorService.delByCopyrightId(draft.getCopyrightId());
copyrightAuthorityRelationService.delByCopyrightId(draft.getCopyrightId());
}
}
Draft d = new Draft();
BeanUtil.copyProperties(draft, d, true);
this.save(d);
this.saveOrUpdate(d);
return d.getId();
}
}
......@@ -47,4 +47,10 @@
</where>
order by c.apply_time desc
</select>
<select id="getSerialCodes" resultType="java.lang.String">
SELECT serial_num
FROM tb_copyright_apply
WHERE register_state IN (2, 6, 7)
<!-- AND (NOW() - INTERVAL 24 HOUR) >= pass_time -->
</select>
</mapper>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -550,3 +550,24 @@ alter table tb_nft add column evidencer varchar(20) not null default '' comment
ALTER TABLE tb_copyright_author MODIFY COLUMN `name` VARCHAR ( 100 ) NOT NULL DEFAULT '' COMMENT '作者姓名或名称';
ALTER TABLE tb_copyright_author MODIFY COLUMN `sign` VARCHAR ( 100 ) NOT NULL DEFAULT '' COMMENT '签名';
ALTER TABLE tb_copyright_owner MODIFY COLUMN `owner` VARCHAR ( 100 ) NOT NULL DEFAULT '' COMMENT '著作权人';
-- v2.0.1
ALTER TABLE tb_copyright_apply ADD COLUMN pass_time datetime DEFAULT NULL COMMENT '版权申请后台核验通过时间' AFTER apply_time;
UPDATE `tb_opus_category` SET `value` = '文字作品' WHERE `id` = 1;
UPDATE `tb_opus_category` SET `value` = '口述作品' WHERE `id` = 2;
UPDATE `tb_opus_category` SET `value` = '音乐作品' WHERE `id` = 3;
UPDATE `tb_opus_category` SET `value` = '戏剧作品' WHERE `id` = 4;
UPDATE `tb_opus_category` SET `value` = '曲艺作品' WHERE `id` = 5;
UPDATE `tb_opus_category` SET `value` = '舞蹈作品' WHERE `id` = 6;
UPDATE `tb_opus_category` SET `value` = '杂技艺术' WHERE `id` = 7;
UPDATE `tb_opus_category` SET `value` = '美术作品' WHERE `id` = 8;
UPDATE `tb_opus_category` SET `value` = '建筑作品' WHERE `id` = 9;
UPDATE `tb_opus_category` SET `value` = '摄影作品' WHERE `id` = 10;
UPDATE `tb_opus_category` SET `value` = '电影作品' WHERE `id` = 11;
UPDATE `tb_opus_category` SET `value` = '以类似摄制电影的方法创作的作品' WHERE `id` = 12;
UPDATE `tb_opus_category` SET `value` = '工程设计图、产品设计图' WHERE `id` = 13;
UPDATE `tb_opus_category` SET `value` = '地图、示意图' WHERE `id` = 14;
UPDATE `tb_opus_category` SET `value` = '模型作品' WHERE `id` = 15;
UPDATE `tb_opus_category` SET `value` = '录音制品' WHERE `id` = 16;
UPDATE `tb_opus_category` SET `value` = '录像制品' WHERE `id` = 17;
UPDATE `tb_opus_category` SET `value` = '其他作品' WHERE `id` = 18;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment