...
|
...
|
@@ -5,6 +5,7 @@ import java.util.ArrayList; |
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
...
|
...
|
@@ -12,7 +13,7 @@ import java.util.stream.Collectors; |
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.common.collect.Lists;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -22,7 +23,6 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
...
|
...
|
@@ -55,10 +55,12 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; |
|
|
import com.yohoufo.dal.product.IdentifyRecordsMapper;
|
|
|
import com.yohoufo.dal.product.IdentifyRelationMapper;
|
|
|
import com.yohoufo.dal.product.ProductChainMapper;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.TransferRecordsHistoryMapper;
|
|
|
import com.yohoufo.dal.product.TransferRecordsMapper;
|
|
|
import com.yohoufo.dal.product.model.IdentifyRecord;
|
|
|
import com.yohoufo.dal.product.model.IdentifyRelation;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.ProductChain;
|
|
|
import com.yohoufo.dal.product.model.TransferRecords;
|
|
|
import com.yohoufo.dal.product.model.TransferRecordsHistory;
|
...
|
...
|
@@ -66,8 +68,9 @@ import com.yohoufo.product.mq.TopicConstants; |
|
|
import com.yohoufo.product.response.IdentifyShareInfoResp;
|
|
|
import com.yohoufo.product.response.IdentifyTrackResp;
|
|
|
import com.yohoufo.product.response.ProductIdentifyResp;
|
|
|
import com.yohoufo.product.service.MessageFacade;
|
|
|
import com.yohoufo.product.service.ProductIdentifyService;
|
|
|
import com.yohoufo.product.service.SendMessageService;
|
|
|
import com.yohoufo.product.service.UserInfoProxyService;
|
|
|
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -118,16 +121,32 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
private TransferRecordsHistoryMapper transferRecordsHistoryMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SendMessageService sendMessageService;
|
|
|
private MessageFacade messageFacade;
|
|
|
|
|
|
@Autowired
|
|
|
private UserInfoProxyService userInfoProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Resource(name = "yhProducer")
|
|
|
private YhProducer yhProducer;
|
|
|
|
|
|
@Value("${uic.url:http://uic.yohoops.org/uic}")
|
|
|
private String uicUrl;
|
|
|
|
|
|
@Value("${ip.port.uic.server}")
|
|
|
private String uicServerIpAndPort;
|
|
|
|
|
|
@Value("${ufo.nfc.syncBlockChain.url}")
|
|
|
private String syncBlockChain_url;
|
|
|
|
|
|
private static final String UIC_PROFILE_URL = "/uic/profile/getProfile";
|
|
|
|
|
|
public static final String DEFAULT_HEAD_IMG = "http://img11.static.yhbimg.com/yhb-img01/2016/07/05/13/017ec560b82c132ab2fdb22f7cf6f42b83.png?imageView/{mode}/w/{width}/h/{height}";
|
|
|
|
|
|
private static final String DEFAULT_FROM = "YOHO!";
|
|
|
|
|
|
public static final Integer OPERATE_TYPE_APPLYING = 0;//申请中
|
|
|
|
|
|
public static final Integer OPERATE_TYPE_PASS = 1;//同意
|
...
|
...
|
@@ -367,10 +386,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
if(buyerOrder == null){
|
|
|
throw new GatewayException(403, "订单不存在");
|
|
|
}
|
|
|
//向物权所有人发短信“用户189******59向您发起商品xxxxxx的物权转移申请,您可以 打开有货APP站内信查看并确认”
|
|
|
sendSmsToOwner(insertItem.getFromUid(), String.valueOf(uid), orderCode);
|
|
|
|
|
|
//向物权所有人发送站内信
|
|
|
//向物权所有人发短信、站内信
|
|
|
messageFacade.applyToBeOwner(insertItem.getFromUid(), String.valueOf(uid), tagId, nfcUid, orderCode);
|
|
|
|
|
|
//发送定时mq
|
|
|
yhProducer.send(TopicConstants.MQ_TOPIC_CONFIRM_OWNER_DELAY, insertItem, null, 3*24*60);//3天
|
...
|
...
|
@@ -408,6 +425,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
int result = transferRecordsHistoryMapper.insert(histroy);
|
|
|
|
|
|
if(status.equals(OPERATE_TYPE_REJECT)) {
|
|
|
//“不同意”则拒绝物权占有,短信通知申请⼈人“您发起商品xxxxxx的物权转 移申请,当前物权所有⼈人拒绝转移申请,您可以重新发起物权申请”
|
|
|
messageFacade.ownerReject(String.valueOf(toUid), queryIdentifyRecord(tagId, nfcUid).getOrderCode());
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -420,30 +439,71 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
transferRecords.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
transferRecordsMapper.insert(transferRecords);
|
|
|
|
|
|
//更新identify_record
|
|
|
result = identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
|
|
|
//区块链
|
|
|
syncBlockChain(tagId, nfcUid, toUid);
|
|
|
|
|
|
//清理缓存
|
|
|
clearIdentifyCache(tagId, nfcUid);
|
|
|
|
|
|
//更新identify_record
|
|
|
return identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private void sendSmsToOwner(String fromUid, String uid, Long orderCode) {
|
|
|
List<String> uidList = Lists.newArrayList(fromUid, uid);
|
|
|
Map<Integer, ProfileInfoRsp> profileMap = queryIcoAndMobile(uidList);
|
|
|
String fromMobile = profileMap.get(Integer.parseInt(fromUid)).getMobile();
|
|
|
String toMobileMask = MobileHelper.coverMobile2(profileMap.get(Integer.parseInt(uid)).getMobile());
|
|
|
|
|
|
//商品信息
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
|
|
|
private void syncBlockChain(String tagId, String nfcUid, Integer toUid){
|
|
|
IdentifyRecord record = queryIdentifyRecord(tagId, nfcUid);
|
|
|
//商品信息
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectOnlyByOrderCode(record.getOrderCode());
|
|
|
Integer skup = buyerOrderGoods.getSkup();
|
|
|
//skup获取 productInfo
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
content.append("用户").append(toMobileMask).append("向您发起商品").append(sellerOrderGoods.getProductName());
|
|
|
content.append("的物权转移申请,您可以打开有货APP站内信查看并确认");
|
|
|
sendMessageService.smsSendByMobile(content.toString(), Lists.newArrayList(fromMobile));
|
|
|
}
|
|
|
|
|
|
SellerOrderGoods goodsInfo = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
//去product表获取商品货号
|
|
|
Product productInfo = productMapper.selectByPrimaryKey(goodsInfo.getProductId());
|
|
|
if(productInfo == null){
|
|
|
logger.info("syncBlockChain get sellerGoods from sellerOrderGoodsMapper is null, productId is {}",goodsInfo.getProductId() );
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//商品图片,尺寸,颜色,来源,所有人等信息
|
|
|
String image = ImageUrlAssist.getImageAbsoluteUrl(goodsInfo.getImageUrl(), "goodsimg");
|
|
|
String size = goodsInfo.getSizeName();
|
|
|
String color = goodsInfo.getColorName();
|
|
|
String productCode = productInfo.getProductCode();
|
|
|
|
|
|
String ownerName = "";
|
|
|
|
|
|
//根据uid去uic获取用户手机号,并进行模糊处理。吃掉异常,防止超时影响正常逻辑
|
|
|
try{
|
|
|
Map<String,Integer> request = Collections.singletonMap("uid", toUid);
|
|
|
JSONObject jsonObject = serviceCaller.get("uic.getProfileAction", "http://" + uicServerIpAndPort + UIC_PROFILE_URL, request, JSONObject.class, null).get(1);
|
|
|
|
|
|
if(null != jsonObject.getJSONObject("data") && null != jsonObject.getJSONObject("data").getString("mobile_phone")) {
|
|
|
String mobile = jsonObject.getJSONObject("data").getString("mobile_phone");;
|
|
|
ownerName = MobileHelper.coverMobile2(mobile);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.info("syncBlockChain get mobile from uic error, e is {}", e);
|
|
|
}
|
|
|
//获取手机号失败的情况,owner 默认是uid模糊处理
|
|
|
if(StringUtils.isBlank(ownerName)){
|
|
|
ownerName = blurUid(toUid);
|
|
|
}
|
|
|
//组装信息 同步至区块链写代理
|
|
|
Map<String, Object> infoMap = new HashMap<>();
|
|
|
infoMap.put("tagid", tagId);
|
|
|
infoMap.put("product_url", image);
|
|
|
infoMap.put("color", color);
|
|
|
infoMap.put("size", size);
|
|
|
infoMap.put("goods_no", productCode);
|
|
|
infoMap.put("source", DEFAULT_FROM); //默认来源yoho
|
|
|
infoMap.put("transaction_time", DateUtil.getCurrentTimeSecond());
|
|
|
infoMap.put("owner", ownerName);
|
|
|
infoMap.put("auth_time", DateUtil.getCurrentTimeSecond());
|
|
|
logger.info("req url is {}, params is {}", syncBlockChain_url, infoMap);
|
|
|
String result = serviceCaller.post("", syncBlockChain_url, infoMap, String.class, null).get(5);
|
|
|
logger.info(" result is {}", result);
|
|
|
}
|
|
|
|
|
|
private void rebuildResult(ProductIdentifyResp result, String tagId, String nfcUid, Integer uid) {
|
|
|
boolean isOwner = queryIsOwner(tagId, nfcUid, uid);
|
|
|
result.setIfOwner(isOwner);
|
...
|
...
|
@@ -462,12 +522,12 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
result.setApplyStatus(history.getStatus());
|
|
|
}
|
|
|
|
|
|
ProfileInfoRsp[] profileInfoArray = getUserProfilesByUids(Lists.newArrayList(String.valueOf(uid)));
|
|
|
if(ArrayUtils.isEmpty(profileInfoArray)) {
|
|
|
Map<Integer,ProfileInfoRsp> profileMap = userInfoProxyService.queryIcoAndMobile(Lists.newArrayList(String.valueOf(uid)));
|
|
|
if(MapUtils.isEmpty(profileMap)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ProfileInfoRsp profileInfo = profileInfoArray[0];
|
|
|
ProfileInfoRsp profileInfo = profileMap.get(uid);
|
|
|
IdentifyTrackResp track = new IdentifyTrackResp();
|
|
|
track.setUid(uid);
|
|
|
track.setType(MESSAGE_TYPE_APPLICANT);
|
...
|
...
|
@@ -514,7 +574,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
allUidList.addAll(ownerUidList);
|
|
|
|
|
|
//查询头像和手机号
|
|
|
Map<Integer, ProfileInfoRsp> profileMap = queryIcoAndMobile(allUidList);
|
|
|
Map<Integer, ProfileInfoRsp> profileMap = userInfoProxyService.queryIcoAndMobile(allUidList);
|
|
|
List<IdentifyTrackResp> historyTrackList = buildTransferTrackList(profileMap, transferList);
|
|
|
trackRespList.addAll(historyTrackList);
|
|
|
|
...
|
...
|
@@ -557,21 +617,6 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
return trackList;
|
|
|
}
|
|
|
|
|
|
private Map<Integer,ProfileInfoRsp> queryIcoAndMobile(List<String> uidList) {
|
|
|
Map<Integer,ProfileInfoRsp> profileMap = Maps.newHashMap();
|
|
|
ProfileInfoRsp[] profileInfoArray = getUserProfilesByUids(uidList);
|
|
|
if(ArrayUtils.isEmpty(profileInfoArray)) {
|
|
|
return profileMap;
|
|
|
}
|
|
|
|
|
|
for(int i=0; i< profileInfoArray.length; i++) {
|
|
|
ProfileInfoRsp item = profileInfoArray[i];
|
|
|
profileMap.put(item.getUid(), item);
|
|
|
}
|
|
|
|
|
|
return profileMap;
|
|
|
}
|
|
|
|
|
|
//获取订单详情
|
|
|
private ProductIdentifyResp getOrderDetail(BuyerOrder buyerOrder, IdentifyRecord identifyRecord, String tagId) {
|
|
|
ProductIdentifyResp result = new ProductIdentifyResp();
|
...
|
...
|
@@ -686,7 +731,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
}
|
|
|
|
|
|
|
|
|
private IdentifyRecord queryIdentifyRecord(String tagId, String nfcUid) {
|
|
|
@Override
|
|
|
public IdentifyRecord queryIdentifyRecord(String tagId, String nfcUid) {
|
|
|
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyRecord:").
|
|
|
appendVar(tagId).appendVar(":").appendVar(nfcUid);
|
|
|
IdentifyRecord result = clientCache.get(kb, IdentifyRecord.class);
|
...
|
...
|
@@ -729,22 +775,6 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量查询用户基本信息--头像信息+手机号
|
|
|
* @return
|
|
|
*/
|
|
|
private ProfileInfoRsp[] getUserProfilesByUids(List<String> uidList) {
|
|
|
try{
|
|
|
String uids = String.join(",", uidList);
|
|
|
String url = uicUrl + "/profile/getUserProfilesByUids";
|
|
|
logger.info("getUserProfilesByUids start call uic.getUserProfilesByUids uidList={}, url={} ", uidList, url);
|
|
|
return serviceCaller.post("uic.getUserProfilesByUids", url, uids, ProfileInfoRsp[].class,null).get();
|
|
|
}catch(Exception e){
|
|
|
logger.warn("getUserProfilesByUids call uic.getUserProfilesByUids error! uidList={}, e {}", uidList, e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询用户基本信息--头像信息(不要取此接口的手机号)
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -813,48 +843,23 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ |
|
|
}
|
|
|
|
|
|
|
|
|
// /**
|
|
|
// * 批量获取买家信息
|
|
|
// *
|
|
|
// * @return
|
|
|
// *//*
|
|
|
// private AsyncFuture<ProfileInfoRsp[]> getUserProfileInfo(List<Integer> uidsList) {
|
|
|
// //参数校验
|
|
|
// if(uidsList == null || uidsList.size() == 0){
|
|
|
// return null;
|
|
|
// }
|
|
|
// StringBuilder sb = new StringBuilder();
|
|
|
// for(Integer uid : uidsList ){
|
|
|
// if(uid != null && uid > 0){
|
|
|
// sb.append(uid).append(",");
|
|
|
// }
|
|
|
// }
|
|
|
// String s = sb.toString();
|
|
|
// if(s.length() == 0){
|
|
|
// return null;
|
|
|
// }
|
|
|
//
|
|
|
// String uids = s.substring(0, s.length() - 1);
|
|
|
// //调用多个的只有这个才行
|
|
|
// return serviceCaller.asyncCall("uic.getUserProfilesByUids", uids, ProfileInfoRsp[].class);
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
// /**
|
|
|
// * 转换用户信息 为map
|
|
|
// * @return
|
|
|
// */
|
|
|
// private Map<Integer, ProfileInfoRsp> convertUserInfoToMap(ProfileInfoRsp[] infos) {
|
|
|
//
|
|
|
// Map<Integer, ProfileInfoRsp> result = new HashMap<>();
|
|
|
// if(infos == null || infos.length == 0){
|
|
|
// return result;
|
|
|
// }
|
|
|
// List<ProfileInfoRsp> resultList = Arrays.asList(infos);
|
|
|
//// List<ProfileInfoRsp> resultList = rsp.stream().map(profileInfoRsp -> JSONObject.parseObject(JSONObject.toJSONString(profileInfoRsp),ProfileInfoRsp.class)).collect(Collectors.toList());
|
|
|
// result = resultList.stream().collect(Collectors.toMap(ProfileInfoRsp :: getUid, (ProfileInfoRsp obj) -> obj));
|
|
|
// return result;
|
|
|
// }
|
|
|
|
|
|
private String blurUid( Integer uid ) {
|
|
|
if ( uid == null ) {
|
|
|
return null;
|
|
|
}
|
|
|
String tmp =String.valueOf(uid).trim();
|
|
|
if(tmp.length() <= 4){
|
|
|
int j = tmp.length();
|
|
|
for (int i=0; i< 11 - j; i++){
|
|
|
tmp = "*".concat(tmp);
|
|
|
}
|
|
|
}else {
|
|
|
tmp = tmp.substring(tmp.length()-4, tmp.length());
|
|
|
for (int i=0; i< 7; i++){
|
|
|
tmp = "*".concat(tmp);
|
|
|
}
|
|
|
}
|
|
|
return tmp;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|