Authored by caoyan

Merge branch 'dev_物权转移' into test6.8.6

... ... @@ -42,5 +42,9 @@
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.service.model</groupId>
<artifactId>message-service-model</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
... ... @@ -11,4 +11,6 @@ public class IdentifyTrackResp {
private Integer time;
private String mobile;
private Integer type;//1:鉴定信息 2:EX主人 3:现主人 4:申请人
private String message;
private String tip;
}
... ...
package com.yohoufo.product.service;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.service.model.msgcenter.sms.McSmsByMobileBO;
import com.yoho.service.model.sms.response.CommonRspBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by chenchao on 2018/10/19.
*/
@Service
public class SendMessageService {
private static Logger log = LoggerFactory.getLogger(SendMessageService.class);
@Autowired
private ServiceCaller serviceCaller;
@Value("${yoho.message.controller.url}")
private String messageUrl;
public void smsSendByMobile(String content, List<String> mobileList) {
log.info("smsSendByMobile start, content {}, mobileList {}", content, mobileList);
if(StringUtils.isEmpty(content) || CollectionUtils.isEmpty(mobileList)) {
log.warn("smsSendByMobile fail! content is null or mobileList is empty");
return;
}
McSmsByMobileBO[] boArray = new McSmsByMobileBO[mobileList.size()];
for(int i=0; i<mobileList.size(); i++) {
McSmsByMobileBO smsBo = new McSmsByMobileBO();
smsBo.setMobile(mobileList.get(i));
smsBo.setContent(content);
//"smsProviderCode" : "3"
smsBo.setSmsProviderCode("3");
smsBo.setIsNoDisturb(0);//是否免打扰, 1-是 0-否
boArray[i] = smsBo;
}
String url = messageUrl + "/mcSMS/smsSendByMobile";
log.info("sendMessage url is {}", url);
serviceCaller.post("message.sendMessage", url, boArray, CommonRspBO.class, null);
}
}
... ...
... ... @@ -67,6 +67,7 @@ import com.yohoufo.product.response.IdentifyShareInfoResp;
import com.yohoufo.product.response.IdentifyTrackResp;
import com.yohoufo.product.response.ProductIdentifyResp;
import com.yohoufo.product.service.ProductIdentifyService;
import com.yohoufo.product.service.SendMessageService;
@Service
... ... @@ -116,6 +117,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
@Autowired
private TransferRecordsHistoryMapper transferRecordsHistoryMapper;
@Autowired
private SendMessageService sendMessageService;
@Resource(name = "yhProducer")
private YhProducer yhProducer;
... ... @@ -134,6 +138,8 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
public static final Integer OPERATE_TYPE_NO_APPLY = 4; //未申请
public static final Integer OPERATE_TYPE_CANNOT_APPLY = 5; //不能申请
public static final Integer MESSAGE_TYPE_JUDGE_INFO = 1; //鉴定信息
public static final Integer MESSAGE_TYPE_EX_OWNER = 2; //前主人
... ... @@ -339,10 +345,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
throw new GatewayException(402, "已经是物权所有人");
}
TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, uid);
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, "当前不可再申请");
TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, null);
if(null != history && (history.getStatus().equals(OPERATE_TYPE_APPLYING))) {
throw new GatewayException(402, "当前不可申请");
}
//将申请记录插入数据库
... ... @@ -355,6 +360,16 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
insertItem.setStatus(OPERATE_TYPE_APPLYING);
int result = transferRecordsHistoryMapper.insert(insertItem);
//根据鉴定记录 获取订单号
Long orderCode = identifyRecord.getOrderCode();
//获取订单详细信息
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if(buyerOrder == null){
throw new GatewayException(403, "订单不存在");
}
//向物权所有人发短信“用户189******59向您发起商品xxxxxx的物权转移申请,您可以 打开有货APP站内信查看并确认”
sendSmsToOwner(insertItem.getFromUid(), String.valueOf(uid), orderCode);
//向物权所有人发送站内信
//发送定时mq
... ... @@ -405,10 +420,30 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
transferRecords.setCreateTime(DateUtil.getCurrentTimeSecond());
transferRecordsMapper.insert(transferRecords);
//清理缓存
clearIdentifyCache(tagId, nfcUid);
//更新identify_record
return identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
}
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);
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));
}
private void rebuildResult(ProductIdentifyResp result, String tagId, String nfcUid, Integer uid) {
boolean isOwner = queryIsOwner(tagId, nfcUid, uid);
result.setIfOwner(isOwner);
... ... @@ -421,6 +456,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
if(null == history || !history.getStatus().equals(OPERATE_TYPE_APPLYING)) {
result.setApplyStatus(OPERATE_TYPE_NO_APPLY);//未申请
}else if(!(history.getToUid().equals(String.valueOf(uid)))) {
result.setApplyStatus(OPERATE_TYPE_CANNOT_APPLY);
return;
}else {
result.setApplyStatus(history.getStatus());
... ... @@ -434,7 +470,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
ProfileInfoRsp profileInfo = profileInfoArray[0];
IdentifyTrackResp track = new IdentifyTrackResp();
track.setUid(uid);
track.setType(MESSAGE_TYPE_APPLICANT);;
track.setType(MESSAGE_TYPE_APPLICANT);
String mobileMask = MobileHelper.coverMobile2(profileInfo.getMobile());//隐位的手机号码--隐藏中间6位
track.setContent(StringUtils.isEmpty(profileInfo.getNickname()) ? mobileMask : profileInfo.getNickname());
String headIcon = profileInfo.getHead_ico();
... ... @@ -443,6 +479,16 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
headIcon = configReader.getString("ufo.product.defaultUserHeadIcon", "http://head.static.yhbimg.com/yhb-head/2018/12/28/14/0160773bb87685aade796ea4f94e0587cf.png?imageView2/{mode}/w/{width}/h/{height}");
}
track.setHeadIcon(headIcon);
String message = "向" + result.getCurrentOwner() + "申请成为新主人";
String tip = "";
if(result.getApplyStatus().equals(OPERATE_TYPE_REJECT)) {
tip = "当前物权所有⼈人拒绝物权转移";
}else if(result.getApplyStatus().equals(OPERATE_TYPE_TIMEOUT)) {
tip = "当前主人确认申请超时,您可以重新发起申请";
}
track.setMessage(message);
track.setTip(tip);
result.getTrackList().add(track);
}
... ... @@ -668,6 +714,12 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
appendVar(tagId).appendVar(":").appendVar(nfcUid);
clientCache.setEx(kb, result,5 * 60 );
}
private void clearIdentifyCache(String tagId, String nfcUid) {
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyResultInfo:").
appendVar(tagId).appendVar(":").appendVar(nfcUid);
clientCache.delete(kb.toString());
}
private ProductIdentifyResp getIdentifyFromCache(String tagId, String nfcUid) {
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyResultInfo:").
... ...