Authored by caoyan

物权转移

@@ -42,5 +42,9 @@ @@ -42,5 +42,9 @@
42 <groupId>com.yoho.core</groupId> 42 <groupId>com.yoho.core</groupId>
43 <artifactId>yoho-core-rabbitmq</artifactId> 43 <artifactId>yoho-core-rabbitmq</artifactId>
44 </dependency> 44 </dependency>
  45 + <dependency>
  46 + <groupId>com.yoho.service.model</groupId>
  47 + <artifactId>message-service-model</artifactId>
  48 + </dependency>
45 </dependencies> 49 </dependencies>
46 </project> 50 </project>
  1 +package com.yohoufo.product.service;
  2 +
  3 +import com.yoho.core.rest.client.ServiceCaller;
  4 +import com.yoho.service.model.msgcenter.sms.McSmsByMobileBO;
  5 +import com.yoho.service.model.sms.response.CommonRspBO;
  6 +import org.apache.commons.collections.CollectionUtils;
  7 +import org.apache.commons.lang3.StringUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.beans.factory.annotation.Value;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * Created by chenchao on 2018/10/19.
  18 + */
  19 +@Service
  20 +public class SendMessageService {
  21 +
  22 +
  23 + private static Logger log = LoggerFactory.getLogger(SendMessageService.class);
  24 +
  25 + @Autowired
  26 + private ServiceCaller serviceCaller;
  27 +
  28 + @Value("${yoho.message.controller.url}")
  29 + private String messageUrl;
  30 +
  31 + public void smsSendByMobile(String content, List<String> mobileList) {
  32 + log.info("smsSendByMobile start, content {}, mobileList {}", content, mobileList);
  33 + if(StringUtils.isEmpty(content) || CollectionUtils.isEmpty(mobileList)) {
  34 + log.warn("smsSendByMobile fail! content is null or mobileList is empty");
  35 + return;
  36 + }
  37 + McSmsByMobileBO[] boArray = new McSmsByMobileBO[mobileList.size()];
  38 + for(int i=0; i<mobileList.size(); i++) {
  39 + McSmsByMobileBO smsBo = new McSmsByMobileBO();
  40 + smsBo.setMobile(mobileList.get(i));
  41 + smsBo.setContent(content);
  42 + //"smsProviderCode" : "3"
  43 + smsBo.setSmsProviderCode("3");
  44 + smsBo.setIsNoDisturb(0);//是否免打扰, 1-是 0-否
  45 + boArray[i] = smsBo;
  46 + }
  47 +
  48 + String url = messageUrl + "/mcSMS/smsSendByMobile";
  49 + log.info("sendMessage url is {}", url);
  50 + serviceCaller.post("message.sendMessage", url, boArray, CommonRspBO.class, null);
  51 + }
  52 +
  53 +}
@@ -67,6 +67,7 @@ import com.yohoufo.product.response.IdentifyShareInfoResp; @@ -67,6 +67,7 @@ import com.yohoufo.product.response.IdentifyShareInfoResp;
67 import com.yohoufo.product.response.IdentifyTrackResp; 67 import com.yohoufo.product.response.IdentifyTrackResp;
68 import com.yohoufo.product.response.ProductIdentifyResp; 68 import com.yohoufo.product.response.ProductIdentifyResp;
69 import com.yohoufo.product.service.ProductIdentifyService; 69 import com.yohoufo.product.service.ProductIdentifyService;
  70 +import com.yohoufo.product.service.SendMessageService;
70 71
71 72
72 @Service 73 @Service
@@ -116,6 +117,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -116,6 +117,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
116 @Autowired 117 @Autowired
117 private TransferRecordsHistoryMapper transferRecordsHistoryMapper; 118 private TransferRecordsHistoryMapper transferRecordsHistoryMapper;
118 119
  120 + @Autowired
  121 + private SendMessageService sendMessageService;
  122 +
119 @Resource(name = "yhProducer") 123 @Resource(name = "yhProducer")
120 private YhProducer yhProducer; 124 private YhProducer yhProducer;
121 125
@@ -339,10 +343,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -339,10 +343,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
339 throw new GatewayException(402, "已经是物权所有人"); 343 throw new GatewayException(402, "已经是物权所有人");
340 } 344 }
341 345
342 - TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, uid);  
343 - if(null != history && (history.getStatus().equals(OPERATE_TYPE_APPLYING)  
344 - || history.getStatus().equals(OPERATE_TYPE_PASS) || history.getStatus().equals(OPERATE_TYPE_REJECT))) {  
345 - throw new GatewayException(402, "当前不可再申请"); 346 + TransferRecordsHistory history = transferRecordsHistoryMapper.selectByToUid(tagId, nfcUid, null);
  347 + if(null != history && (history.getStatus().equals(OPERATE_TYPE_APPLYING))) {
  348 + throw new GatewayException(402, "当前不可申请");
346 } 349 }
347 350
348 //将申请记录插入数据库 351 //将申请记录插入数据库
@@ -355,6 +358,16 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -355,6 +358,16 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
355 insertItem.setStatus(OPERATE_TYPE_APPLYING); 358 insertItem.setStatus(OPERATE_TYPE_APPLYING);
356 int result = transferRecordsHistoryMapper.insert(insertItem); 359 int result = transferRecordsHistoryMapper.insert(insertItem);
357 360
  361 + //根据鉴定记录 获取订单号
  362 + Long orderCode = identifyRecord.getOrderCode();
  363 + //获取订单详细信息
  364 + BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
  365 + if(buyerOrder == null){
  366 + throw new GatewayException(403, "订单不存在");
  367 + }
  368 + //向物权所有人发短信“用户189******59向您发起商品xxxxxx的物权转移申请,您可以 打开有货APP站内信查看并确认”
  369 + sendSmsToOwner(insertItem.getFromUid(), String.valueOf(uid), orderCode);
  370 +
358 //向物权所有人发送站内信 371 //向物权所有人发送站内信
359 372
360 //发送定时mq 373 //发送定时mq
@@ -409,6 +422,23 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{ @@ -409,6 +422,23 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
409 return identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid); 422 return identifyRecordsMapper.updateOwner(tagId, nfcUid, toUid);
410 } 423 }
411 424
  425 + private void sendSmsToOwner(String fromUid, String uid, Long orderCode) {
  426 + List<String> uidList = Lists.newArrayList(fromUid, uid);
  427 + Map<Integer, ProfileInfoRsp> profileMap = queryIcoAndMobile(uidList);
  428 + String fromMobile = profileMap.get(Integer.parseInt(fromUid)).getMobile();
  429 + String toMobileMask = MobileHelper.coverMobile2(profileMap.get(Integer.parseInt(uid)).getMobile());
  430 +
  431 + //商品信息
  432 + BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
  433 + Integer skup = buyerOrderGoods.getSkup();
  434 + //skup获取 productInfo
  435 + SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
  436 + StringBuilder content = new StringBuilder();
  437 + content.append("用户").append(toMobileMask).append("向您发起商品").append(sellerOrderGoods.getProductName());
  438 + content.append("的物权转移申请,您可以打开有货APP站内信查看并确认");
  439 + sendMessageService.smsSendByMobile(content.toString(), Lists.newArrayList(fromMobile));
  440 + }
  441 +
412 private void rebuildResult(ProductIdentifyResp result, String tagId, String nfcUid, Integer uid) { 442 private void rebuildResult(ProductIdentifyResp result, String tagId, String nfcUid, Integer uid) {
413 boolean isOwner = queryIsOwner(tagId, nfcUid, uid); 443 boolean isOwner = queryIsOwner(tagId, nfcUid, uid);
414 result.setIfOwner(isOwner); 444 result.setIfOwner(isOwner);