Authored by caoyan

物权转移

@@ -25,6 +25,20 @@ public enum CacheEnum { @@ -25,6 +25,20 @@ public enum CacheEnum {
25 */ 25 */
26 PRODUCT_CATEGORY_SEARCH("yh:ufo:resources:product_category_search", 1 * 60, "resources.cachetime.product_category_search"), 26 PRODUCT_CATEGORY_SEARCH("yh:ufo:resources:product_category_search", 1 * 60, "resources.cachetime.product_category_search"),
27 27
  28 + /**
  29 + * 消息盒子-某类型下未读消息总数,缓存5分钟
  30 + */
  31 + USERS_INBOX_TYPE_UNREADCOUNT("yh:users:inbox_type_unreadcount", 5 * 60, "users.cachetime.inbox_type_unreadcount"),
  32 +
  33 + /**
  34 + * 消息盒子-消息,缓存5分钟
  35 + */
  36 + USERS_INBOX_LIST("yh:users:inbox_list", 5 * 60, "users.cachetime.inbox_list"),
  37 +
  38 + /**
  39 + * 消息盒子-消息总数,缓存5分钟
  40 + */
  41 + USERS_INBOX_LIST_TOTAL("yh:users:inbox_list_total", 5 * 60, "users.cachetime.inbox_list_total"),
28 /* 42 /*
29 * end 43 * end
30 */; 44 */;
@@ -14,4 +14,6 @@ public interface IInBoxAttrDao { @@ -14,4 +14,6 @@ public interface IInBoxAttrDao {
14 void insert(InBoxAttr inboxAttr); 14 void insert(InBoxAttr inboxAttr);
15 15
16 List<InBoxAttr> selectInboxAttrList(@Param("uid") Integer uid, @Param("inboxIdList") List<Integer> inboxIdList); 16 List<InBoxAttr> selectInboxAttrList(@Param("uid") Integer uid, @Param("inboxIdList") List<Integer> inboxIdList);
  17 +
  18 + int updateJsonContent(@Param("uid") Integer uid, @Param("inboxId") Integer inboxId, @Param("jsonContent") String jsonContent);
17 } 19 }
@@ -29,4 +29,9 @@ @@ -29,4 +29,9 @@
29 </foreach> 29 </foreach>
30 </if> 30 </if>
31 </select> 31 </select>
  32 +
  33 + <update id="updateJsonContent">
  34 + update inbox_attr set json_content=#{jsonContent}
  35 + where inbox_id=#{inboxId} and uid=#{uid}
  36 + </update>
32 </mapper> 37 </mapper>
@@ -125,9 +125,10 @@ public class ProductIdentifyController { @@ -125,9 +125,10 @@ public class ProductIdentifyController {
125 @RequestParam(value = "nfcUid",required = false) String nfcUid, 125 @RequestParam(value = "nfcUid",required = false) String nfcUid,
126 @RequestParam(value = "from_uid", required = true) Integer fromUid, 126 @RequestParam(value = "from_uid", required = true) Integer fromUid,
127 @RequestParam(value = "to_uid", required = true) Integer toUid, 127 @RequestParam(value = "to_uid", required = true) Integer toUid,
128 - @RequestParam(value = "status", required = true) Integer status) throws GatewayException { 128 + @RequestParam(value = "status", required = true) Integer status,
  129 + @RequestParam(value = "inbox_id", required = true) Integer inboxId) throws GatewayException {
129 try{ 130 try{
130 - int result = identifyService.confirmOwner(tagId, nfcUid, fromUid, toUid, status); 131 + int result = identifyService.confirmOwner(tagId, nfcUid, fromUid, toUid, status, inboxId);
131 return new ApiResponse.ApiResponseBuilder().code(200).data(result).build(); 132 return new ApiResponse.ApiResponseBuilder().code(200).data(result).build();
132 }catch (Exception e){ 133 }catch (Exception e){
133 logger.warn("confirmTransferOwner error! tagId={}, nfcUid={}, fromUid={}, toUid is{}, e is {}", tagId, nfcUid, fromUid, toUid, e); 134 logger.warn("confirmTransferOwner error! tagId={}, nfcUid={}, fromUid={}, toUid is{}, e is {}", tagId, nfcUid, fromUid, toUid, e);
@@ -17,7 +17,7 @@ public interface ProductIdentifyService { @@ -17,7 +17,7 @@ public interface ProductIdentifyService {
17 17
18 int applyToBeOwner(String tagId, String nfcUid, Integer uid) throws GatewayException; 18 int applyToBeOwner(String tagId, String nfcUid, Integer uid) throws GatewayException;
19 19
20 - int confirmOwner(String tagId, String nfcUid, Integer fromUid, Integer toUid, Integer status) throws GatewayException; 20 + int confirmOwner(String tagId, String nfcUid, Integer fromUid, Integer toUid, Integer status, Integer inboxId) throws GatewayException;
21 21
22 IdentifyRecord queryIdentifyRecord(String tagId, String nfcUid); 22 IdentifyRecord queryIdentifyRecord(String tagId, String nfcUid);
23 23
@@ -12,6 +12,7 @@ import java.util.stream.Collectors; @@ -12,6 +12,7 @@ import java.util.stream.Collectors;
12 12
13 import javax.annotation.Resource; 13 import javax.annotation.Resource;
14 14
  15 +import org.apache.commons.collections.CollectionUtils;
15 import org.apache.commons.collections.MapUtils; 16 import org.apache.commons.collections.MapUtils;
16 import org.apache.commons.lang3.StringUtils; 17 import org.apache.commons.lang3.StringUtils;
17 import org.elasticsearch.common.collect.Lists; 18 import org.elasticsearch.common.collect.Lists;
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.beans.factory.annotation.Value; 22 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
23 24
  25 +import com.alibaba.fastjson.JSON;
24 import com.alibaba.fastjson.JSONObject; 26 import com.alibaba.fastjson.JSONObject;
25 import com.yoho.core.config.ConfigReader; 27 import com.yoho.core.config.ConfigReader;
26 import com.yoho.core.rabbitmq.YhProducer; 28 import com.yoho.core.rabbitmq.YhProducer;
@@ -35,8 +37,10 @@ import com.yoho.service.model.uic.request.UserInfoBO; @@ -35,8 +37,10 @@ import com.yoho.service.model.uic.request.UserInfoBO;
35 import com.yohobuy.ufo.model.order.common.OperateTypeEnum; 37 import com.yohobuy.ufo.model.order.common.OperateTypeEnum;
36 import com.yohobuy.ufo.model.order.constants.QNliveConstants; 38 import com.yohobuy.ufo.model.order.constants.QNliveConstants;
37 import com.yohoufo.common.cache.CacheClient; 39 import com.yohoufo.common.cache.CacheClient;
  40 +import com.yohoufo.common.cache.CacheEnum;
38 import com.yohoufo.common.exception.GatewayException; 41 import com.yohoufo.common.exception.GatewayException;
39 import com.yohoufo.common.helper.ImageUrlAssist; 42 import com.yohoufo.common.helper.ImageUrlAssist;
  43 +import com.yohoufo.common.redis.NoSyncGracefulRedisTemplate;
40 import com.yohoufo.common.utils.DateUtil; 44 import com.yohoufo.common.utils.DateUtil;
41 import com.yohoufo.common.utils.MobileHelper; 45 import com.yohoufo.common.utils.MobileHelper;
42 import com.yohoufo.dal.order.BuyerOrderGoodsMapper; 46 import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
@@ -63,6 +67,8 @@ import com.yohoufo.dal.product.model.Product; @@ -63,6 +67,8 @@ import com.yohoufo.dal.product.model.Product;
63 import com.yohoufo.dal.product.model.ProductChain; 67 import com.yohoufo.dal.product.model.ProductChain;
64 import com.yohoufo.dal.product.model.TransferRecords; 68 import com.yohoufo.dal.product.model.TransferRecords;
65 import com.yohoufo.dal.product.model.TransferRecordsHistory; 69 import com.yohoufo.dal.product.model.TransferRecordsHistory;
  70 +import com.yohoufo.dal.user.IInBoxAttrDao;
  71 +import com.yohoufo.dal.user.model.InBoxAttr;
66 import com.yohoufo.product.mq.TopicConstants; 72 import com.yohoufo.product.mq.TopicConstants;
67 import com.yohoufo.product.response.IdentifyShareInfoResp; 73 import com.yohoufo.product.response.IdentifyShareInfoResp;
68 import com.yohoufo.product.response.IdentifyTrackResp; 74 import com.yohoufo.product.response.IdentifyTrackResp;
@@ -127,6 +133,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -127,6 +133,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
127 133
128 @Autowired 134 @Autowired
129 private ProductMapper productMapper; 135 private ProductMapper productMapper;
  136 +
  137 + @Autowired
  138 + private IInBoxAttrDao inBoxAttrDao;
130 139
131 @Resource(name = "yhProducer") 140 @Resource(name = "yhProducer")
132 private YhProducer yhProducer; 141 private YhProducer yhProducer;
@@ -136,6 +145,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -136,6 +145,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
136 145
137 @Value("${uic.url}") 146 @Value("${uic.url}")
138 private String uicServerIpAndPort; 147 private String uicServerIpAndPort;
  148 +
  149 + @Resource(name="NoSyncGracefulRedisTemplate")
  150 + private NoSyncGracefulRedisTemplate redisTemplate;
139 151
140 @Value("${ufo.nfc.syncBlockChain.url}") 152 @Value("${ufo.nfc.syncBlockChain.url}")
141 private String syncBlockChain_url; 153 private String syncBlockChain_url;
@@ -389,14 +401,13 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -389,14 +401,13 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
389 messageFacade.applyToBeOwner(insertItem.getFromUid(), String.valueOf(uid), tagId, nfcUid, orderCode); 401 messageFacade.applyToBeOwner(insertItem.getFromUid(), String.valueOf(uid), tagId, nfcUid, orderCode);
390 402
391 //发送定时mq 403 //发送定时mq
392 -// yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 3*24*60);//3天  
393 - yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 5); 404 + yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 3*24*60);//3天
394 405
395 return result; 406 return result;
396 } 407 }
397 408
398 @Override 409 @Override
399 - public int confirmOwner(String tagId, String nfcUid, Integer fromUid, Integer toUid, Integer status) throws GatewayException { 410 + public int confirmOwner(String tagId, String nfcUid, Integer fromUid, Integer toUid, Integer status, Integer inboxId) throws GatewayException {
400 if(null == status || !(status.equals(OPERATE_TYPE_PASS) || status.equals(OPERATE_TYPE_REJECT))){ 411 if(null == status || !(status.equals(OPERATE_TYPE_PASS) || status.equals(OPERATE_TYPE_REJECT))){
401 throw new GatewayException(402, "参数status错误"); 412 throw new GatewayException(402, "参数status错误");
402 } 413 }
@@ -425,6 +436,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -425,6 +436,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
425 int result = transferRecordsHistoryMapper.insert(histroy); 436 int result = transferRecordsHistoryMapper.insert(histroy);
426 437
427 if(status.equals(OPERATE_TYPE_REJECT)) { 438 if(status.equals(OPERATE_TYPE_REJECT)) {
  439 + setFinalTimeToEnd(inboxId, fromUid);
428 //“不同意”则拒绝物权占有,短信通知申请⼈人“您发起商品xxxxxx的物权转 移申请,当前物权所有⼈人拒绝转移申请,您可以重新发起物权申请” 440 //“不同意”则拒绝物权占有,短信通知申请⼈人“您发起商品xxxxxx的物权转 移申请,当前物权所有⼈人拒绝转移申请,您可以重新发起物权申请”
429 messageFacade.ownerReject(String.valueOf(toUid), queryIdentifyRecord(tagId, nfcUid).getOrderCode()); 441 messageFacade.ownerReject(String.valueOf(toUid), queryIdentifyRecord(tagId, nfcUid).getOrderCode());
430 return result; 442 return result;
@@ -441,6 +453,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -441,6 +453,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
441 453
442 //更新identify_record 454 //更新identify_record
443 result = identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid); 455 result = identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
  456 + setFinalTimeToEnd(inboxId, fromUid);
  457 +
444 //区块链 458 //区块链
445 syncBlockChain(tagId, nfcUid, toUid); 459 syncBlockChain(tagId, nfcUid, toUid);
446 460
@@ -450,6 +464,36 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -450,6 +464,36 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
450 return result; 464 return result;
451 } 465 }
452 466
  467 + private void setFinalTimeToEnd(Integer inboxId, Integer uid) {
  468 + if(null == inboxId) {
  469 + return;
  470 + }
  471 + List<InBoxAttr> attrList = inBoxAttrDao.selectInboxAttrList(uid, Lists.newArrayList(inboxId));
  472 + if(CollectionUtils.isEmpty(attrList)) {
  473 + return;
  474 + }
  475 +
  476 + InBoxAttr attr = attrList.get(0);
  477 + String jsonContent = attr.getJsonContent();
  478 + JSONObject jo = JSON.parseObject(jsonContent);
  479 + jo.replace("finalTime", 0);
  480 + inBoxAttrDao.updateJsonContent(uid, inboxId, jo.toJSONString());
  481 + //清缓存
  482 + deleteIboxsByRedis(uid, 2);
  483 + }
  484 +
  485 + private void deleteIboxsByRedis(int uid, int type){
  486 + logger.info("deleteIboxsByRedis params uid is {} type is {}",uid,type);
  487 + RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_LIST.generateKey(uid);
  488 + redisTemplate.delete(inboxKey);
  489 + RedisKeyBuilder key = CacheEnum.USERS_INBOX_TYPE_UNREADCOUNT.generateKey(uid,type);
  490 + redisTemplate.delete(key);
  491 + RedisKeyBuilder inboxTotalKey = CacheEnum.USERS_INBOX_LIST_TOTAL.generateKey(uid,"N");
  492 + redisTemplate.delete(inboxTotalKey);
  493 + RedisKeyBuilder inboxTypeTotalKey = CacheEnum.USERS_INBOX_LIST_TOTAL.generateKey(uid,type);
  494 + redisTemplate.delete(inboxTypeTotalKey);
  495 + }
  496 +
453 private void syncBlockChain(String tagId, String nfcUid, Integer toUid){ 497 private void syncBlockChain(String tagId, String nfcUid, Integer toUid){
454 IdentifyRecord record = queryIdentifyRecord(tagId, nfcUid); 498 IdentifyRecord record = queryIdentifyRecord(tagId, nfcUid);
455 //商品信息 499 //商品信息
@@ -475,7 +519,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -475,7 +519,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
475 //根据uid去uic获取用户手机号,并进行模糊处理。吃掉异常,防止超时影响正常逻辑 519 //根据uid去uic获取用户手机号,并进行模糊处理。吃掉异常,防止超时影响正常逻辑
476 try{ 520 try{
477 Map<String,Integer> request = Collections.singletonMap("uid", toUid); 521 Map<String,Integer> request = Collections.singletonMap("uid", toUid);
478 - JSONObject jsonObject = serviceCaller.get("uic.getProfileAction", "http://" + uicServerIpAndPort + UIC_PROFILE_URL, request, JSONObject.class, null).get(1); 522 + JSONObject jsonObject = serviceCaller.get("uic.getProfileAction", uicServerIpAndPort + UIC_PROFILE_URL, request, JSONObject.class, null).get(1);
479 523
480 if(null != jsonObject.getJSONObject("data") && null != jsonObject.getJSONObject("data").getString("mobile_phone")) { 524 if(null != jsonObject.getJSONObject("data") && null != jsonObject.getJSONObject("data").getString("mobile_phone")) {
481 String mobile = jsonObject.getJSONObject("data").getString("mobile_phone");; 525 String mobile = jsonObject.getJSONObject("data").getString("mobile_phone");;