Authored by caoyan

物权转移

... ... @@ -10,4 +10,6 @@ import com.yohoufo.dal.product.model.TransferRecords;
*/
public interface TransferRecordsMapper {
List<TransferRecords> selectByTagIdAndNfcUid(@Param("tagId") String tagId, @Param("nfcUid") String nfcUid);
int insert(TransferRecords transferRecords);
}
... ...
... ... @@ -27,5 +27,12 @@
<update id="updateOwner">
update transfer_records set from_uid=#{fromUid}, to_uid=#{toUid}
</update>
<insert id="insert" parameterType="com.yohoufo.dal.product.model.TransferRecords">
insert into
transfer_records(tag_id,nfc_uid,from_uid,to_uid,create_time)
values
(#{tagId,jdbcType=VARCHAR },#{nfcUid,jdbcType=VARCHAR },#{fromUid,jdbcType=VARCHAR},#{toUid,jdbcType=VARCHAR },#{createTime,jdbcType=INTEGER })
</insert>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.product.mq.consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.product.TransferRecordsHistoryMapper;
import com.yohoufo.dal.product.model.TransferRecordsHistory;
import com.yohoufo.product.mq.TopicConstants;
... ... @@ -13,12 +16,15 @@ import com.yohoufo.product.mq.TopicConstants;
* 物权确认超时
* Created by caoyan.
*/
@Service
@Component
public class ProductOwnerConfirmDelayMsgConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerFactory.getLogger("mqConsumerLog");
@Autowired
private TransferRecordsHistoryMapper transferRecordsHistoryMapper;
public static final Integer OPERATE_TYPE_APPLYING = 0;//申请中
public static final Integer OPERATE_TYPE_TIMEOUT = 3;//确认超时
public String getMessageTopic() {
... ... @@ -27,7 +33,24 @@ public class ProductOwnerConfirmDelayMsgConsumer implements YhConsumer {
@Override
public void handleMessage(Object message) {
LOGGER.info("begin handle productOwnerConfirmTimeout update message, message is {}.", message);
TransferRecordsHistory obj = JSON.parseObject(String.valueOf(message),TransferRecordsHistory.class);
transferRecordsHistoryMapper.updateStatus(obj.getTagId(), obj.getNfcUid(), OPERATE_TYPE_TIMEOUT);
TransferRecordsHistory dbItem = transferRecordsHistoryMapper.selectByToUid(obj.getTagId(), obj.getNfcUid(), Integer.valueOf(obj.getToUid()));
if(null != dbItem && dbItem.getStatus().equals(OPERATE_TYPE_APPLYING)) {
//将记录插入历史表transfer_recors_history
TransferRecordsHistory insertItem = new TransferRecordsHistory();
insertItem.setTagId(obj.getTagId());
insertItem.setNfcUid(obj.getNfcUid());
insertItem.setFromUid(obj.getFromUid());
insertItem.setToUid(obj.getToUid());
insertItem.setOperateTime(DateUtil.getCurrentTimeSecond());
insertItem.setStatus(OPERATE_TYPE_TIMEOUT);
transferRecordsHistoryMapper.insert(insertItem);
LOGGER.info("handle productOwnerConfirmTimeout update message success, message is {}.", message);
return;
}
LOGGER.info("not need to handle productOwnerConfirmTimeout update message, message is {}.", message);
}
}
... ...
... ... @@ -16,7 +16,8 @@ public class ProductIdentifyResp {
private String identifyPlat;
private List<IdentifyTrackResp> trackList;
private String transactionId;//区块链Id
private boolean isOwner;//当前登录的是否是物权所有人
private boolean ifOwner;//当前登录的是否是物权所有人
private String identifyUserName;//鉴定师名字
private Integer applyStatus;//申请物权转移状态
private String currentOwner;//当前物权所有人
}
... ...
... ... @@ -292,6 +292,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
if(identifyRecord == null){
throw new GatewayException(402, "鉴定信息不存在");
}
//根据鉴定记录 获取订单号
Long orderCode = identifyRecord.getOrderCode();
//2)订单号 获取订单详细信息
... ... @@ -307,6 +308,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
List<IdentifyTrackResp> trackList = getTrackList(identifyRecord, result.getIdentifyPlat());
result.setTrackList(trackList);
//5)设置当前物权所有人
result.setCurrentOwner(trackList.get(trackList.size()-1).getContent());
//设置缓存--可能会有延时,不影响的
setIdentifyCache(tagId, nfcUid, result);
... ... @@ -328,8 +332,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
}
TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, uid);
if(null != history) {
throw new GatewayException(402, "已经在申请中");
if(null != history && (history.getStatus().equals(OPERATE_TYPE_APPLYING)
|| history.getStatus().equals(OPERATE_TYPE_PASS) || history.getStatus().equals(OPERATE_TYPE_REJECT))) {
throw new GatewayException(402, "当前不可再申请");
}
//将申请记录插入数据库
... ... @@ -345,7 +350,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
//向物权所有人发送站内信
//发送定时mq
yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 5);//5分钟
yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 3*24*60);//3天
return result;
}
... ... @@ -365,31 +370,40 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
}
TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, toUid);
if(null != history && !history.getStatus().equals(OPERATE_TYPE_APPLYING)) {
if(null == history || !history.getStatus().equals(OPERATE_TYPE_APPLYING)) {
throw new GatewayException(402, "不是申请中状态");
}
//将记录插入历史表transfer_recors_history
TransferRecordsHistory insertItem = new TransferRecordsHistory();
insertItem.setTagId(tagId);
insertItem.setNfcUid(nfcUid);
insertItem.setFromUid(String.valueOf(identifyRecord.getOwner()));
insertItem.setToUid(String.valueOf(toUid));
insertItem.setOperateTime(DateUtil.getCurrentTimeSecond());
insertItem.setStatus(status);
int result = transferRecordsHistoryMapper.insert(insertItem);
TransferRecordsHistory histroy = new TransferRecordsHistory();
histroy.setTagId(tagId);
histroy.setNfcUid(nfcUid);
histroy.setFromUid(String.valueOf(identifyRecord.getOwner()));
histroy.setToUid(String.valueOf(toUid));
histroy.setOperateTime(DateUtil.getCurrentTimeSecond());
histroy.setStatus(status);
int result = transferRecordsHistoryMapper.insert(histroy);
if(status.equals(OPERATE_TYPE_REJECT)) {
return result;
}
//增加记录到transfer_records
TransferRecords transferRecords = new TransferRecords();
transferRecords.setTagId(tagId);
transferRecords.setNfcUid(nfcUid);
transferRecords.setFromUid(histroy.getFromUid());
transferRecords.setToUid(history.getToUid());
transferRecords.setCreateTime(DateUtil.getCurrentTimeSecond());
transferRecordsMapper.insert(transferRecords);
//更新identify_record
return identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
}
private void rebuildResult(ProductIdentifyResp result, String tagId, String nfcUid, Integer uid) {
boolean isOwner = queryIsOwner(tagId, nfcUid, uid);
result.setOwner(isOwner);
result.setIfOwner(isOwner);
if(isOwner) {
return;
}
... ...
... ... @@ -65,6 +65,8 @@ consumer:
#物权转移确认超时
- class: com.yohoufo.product.mq.consumer.ProductOwnerConfirmDelayMsgConsumer
topic: productOwner.updateTimeOut
delay:
interval: 4320
# crm
- address: 192.168.102.211:5672
... ...
... ... @@ -66,6 +66,8 @@ consumer:
#物权转移确认超时
- class: com.yohoufo.product.mq.consumer.ProductOwnerConfirmDelayMsgConsumer
topic: productOwner.updateTimeOut
delay:
interval: 4320
# crm
... ...