Authored by qinchao

入驻和退驻后发消息

... ... @@ -32,5 +32,21 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-common</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rest-client-simple</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.service.model</groupId>
<artifactId>message-service-model</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.yohoufo.inboxclient.sdk;
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 InBoxSendSmsService {
private static Logger log = LoggerFactory.getLogger(InBoxSendSmsService.class);
@Autowired
private ServiceCaller serviceCaller;
@Value("${yoho.message.controller.url}")
private String messageUrl;
public void smsSendByMobile(String content, List<String> mobileList) {
log.info("InBoxSendSmsService smsSendByMobile start, content {}, mobileList {}", content, mobileList);
if(StringUtils.isEmpty(content) || CollectionUtils.isEmpty(mobileList)) {
log.warn("InBoxSendSmsService 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("InBoxSendSmsService sendMessage url is {}", url);
serviceCaller.post("message.sendMessage", url, boArray, CommonRspBO.class, null);
}
}
... ...
package com.yohoufo.inboxclient.sdk;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
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.Map;
import java.util.concurrent.TimeUnit;
/**
* Created by chenchao on 2018/9/18.
*/
@Service
public class InboxUserProxyService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
ServiceCaller serviceCaller;
@Value("${erp-gateway.url}")
private String erpGatewayUrl;
@Value("${uic.url:http://uic.yohoops.org/uic}")
private String uicUrl;
/**
* http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
* //profile/getProfile?uid=600032978
* @param uid
* @return
*/
public static final String PRFILE_API = "/profile/getProfile";
public String getMobile(int uid){
String url = uicUrl + PRFILE_API;
Map<String,Object> params = Maps.newHashMap();
params.put("uid", uid);
logger.info("InboxUserProxyService in getMobile enter, uid {}", uid);
ApiResponse userInfo ;
try {
userInfo = serviceCaller.get("users.getAddress", url, params,
ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
}catch (Exception ex){
logger.warn("InboxUserProxyService in getMobile fail, uid {}", uid, ex);
throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
}
JSONObject jsonObject;
String mobile;
if (userInfo == null || (jsonObject = (JSONObject)userInfo.getData()) == null
|| StringUtils.isBlank(mobile = jsonObject.getString("mobile_phone"))){
logger.warn("InboxUserProxyService in getMobile fail, uid {}, userInfo {}", uid, userInfo);
throw new ServiceException(ServiceError.PROFILE_IS_NULL);
}
return mobile;
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yohoufo.inboxclient.sdk.InBoxSDK;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -104,8 +105,9 @@ public class InBoxFacade {
//短信
//InboxBusinessTypeEnum smsIbt = InboxBusinessTypeEnum.SMS_SEND;
//String smsparams = buildParams(orderCode);
SmsContentEnum smsIbt=SmsContentEnum.SMS_SEND;
String content=smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt=SmsContentEnum.SMS_SEND;
//String content=smsIbt.getReplacedContent(prdName);
String content=getReplacedContent(InboxBusinessTypeEnum.SMS_SEND.getContent(),prdName);
String phone = userProxyService.getMobile(buyerUid);
if (StringUtils.isBlank(phone)){
... ... @@ -124,6 +126,10 @@ public class InBoxFacade {
}
private String getReplacedContent(String content ,Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
/**
* 订单生成,卖家取消售卖
*
... ... @@ -147,8 +153,11 @@ public class InBoxFacade {
return;
}
List<String> mobileList = Arrays.asList(phone);
SmsContentEnum smsIbt=SmsContentEnum.SMS_CLOSED_SELLER;
String content=smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt=SmsContentEnum.SMS_CLOSED_SELLER;
//String content=smsIbt.getReplacedContent(prdName);
String content=getReplacedContent(InboxBusinessTypeEnum.SMS_CLOSED_SELLER.getContent(),prdName);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("record noticeBuyerWhenSellerCancelAfterPaid inbox sms msg, buyerUid {}, orderCode {},prdName {}",
buyerUid, orderCode,prdName);
... ... @@ -203,8 +212,10 @@ public class InBoxFacade {
return;
}
List<String> mobileList = Arrays.asList(phone);
SmsContentEnum smsIbt=SmsContentEnum.SMS_CLOSED_PLATFORM;
String content=smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt=SmsContentEnum.SMS_CLOSED_PLATFORM;
//String content=smsIbt.getReplacedContent(prdName);
String content=getReplacedContent(InboxBusinessTypeEnum.SMS_CLOSED_PLATFORM.getContent(),prdName);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("record buyerGetEarnestMoneyWhenAppraiseFail inbox sms msg, buyerUid {}, orderCode {},prdName {}",
buyerUid, orderCode,prdName);
... ... @@ -339,8 +350,9 @@ public class InBoxFacade {
return;
}
List<String> mobileList = Arrays.asList(phone);
SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND;
String content = smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND;
//String content = smsIbt.getReplacedContent(prdName);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTIFIED_SEND.getContent(),prdName);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerSkupPaidByBuyer inbox sms msg,sellerUid {}, prdName {}",
sellerUid, prdName);
... ... @@ -465,8 +477,9 @@ public class InBoxFacade {
return;
}
List<String> mobileList = Arrays.asList(phone);
SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_UNSHELF;
String content = smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_UNSHELF;
//String content = smsIbt.getReplacedContent(prdName);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTIFIED_UNSHELF.getContent(),prdName);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record notifyUnshelfCauseBySpecialReason inbox sms msg,sellerUid {}, prdName {}, resp {}",
sellerUid, prdName);
... ... @@ -498,8 +511,10 @@ public class InBoxFacade {
List<String> mobileList = Arrays.asList(phone);
if (times == 2) {
SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND_SECOND;
String content = smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND_SECOND;
//String content = smsIbt.getReplacedContent(prdName);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_SECOND.getContent(),prdName);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {},resp {}",
sellerUid, prdName, times);
... ... @@ -508,8 +523,9 @@ public class InBoxFacade {
if (times == 3) {
SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND_FAILED;
String content = smsIbt.getReplacedContent(prdName);
//SmsContentEnum smsIbt = SmsContentEnum.SMS_NOTIFIED_SEND_FAILED;
//String content = smsIbt.getReplacedContent(prdName);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED.getContent(),prdName);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {},resp {}",
sellerUid, prdName, times);
... ...
... ... @@ -2,8 +2,12 @@ package com.yohoufo.order.service.proxy;
import org.slf4j.helpers.MessageFormatter;
/**
* 这个不再使用,短信相关的配置参考 InboxBusinessTypeEnum
*/
public enum SmsContentEnum {
// 买家
/**
SMS_SEND("您购买的商品{}已由平台发货。更多信息请查看Yoho!Buy有货APP [UFO飞碟好物-我的-购买]。"),
SMS_CLOSED_SELLER("卖家取消{}出售,您已获得卖家赔偿,将于1-3个工作日内转至您绑定的银行卡。更多信息请查看Yoho!Buy有货APP [UFO飞碟好物-我的-购买]。"),
SMS_CLOSED_PLATFORM("鉴定不通过:您购买的商品{}未通过平台鉴定,您已获得卖家赔偿,将于1-3个工作日内转至您绑定的银行卡。更多信息请查看Yoho!Buy有货APP [UFO飞碟好物-我的-购买]。"),
... ... @@ -16,9 +20,10 @@ public enum SmsContentEnum {
SMS_NOTIFIED_UNSHELF("因为特殊原因,您的商品{}暂停售卖,您支付的保证金将于1个工作日内退回您的支付账户。"),
//给卖家发通知 ,当买家取消订单(付款后取消,卖家发货后取消,卖家商品已经被平台签收)
SMS_CANCELED_BY_BUYER_AFTER_PAID("买家已取消订单,您的商品「商品名称」已下架,更多信息请查看Yoho!Buy有货APP [UFO飞碟好物-我的-出售]。"),
SMS_CANCELED_BY_BUYER_AFTER_PAID("买家已取消订单,您的商品{}已下架,更多信息请查看Yoho!Buy有货APP [UFO飞碟好物-我的-出售]。"),
SMS_CANCELED_BY_BUYER_AFTER_DELIVERY("买家已取消订单,请自行召回货品,如有其他疑问,请联系Yoho!Buy有货APP人工客服。"),
SMS_CANCELED_BY_BUYER_AFTER_RECEIVED("您的商品已顺丰到付退回,快递单号{},请注意查收。"),
**/
;
private String content;
... ...
... ... @@ -28,6 +28,11 @@
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-inboxclient</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
... ...
... ... @@ -5,10 +5,7 @@ import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.user.IUserAuthorizeInfoDao;
import com.yohoufo.dal.user.IZhiMaCertDao;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
... ...
package com.yohoufo.user.service.impl;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.dal.user.IStoredSellerDao;
import com.yohoufo.dal.user.model.StoredSeller;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.inboxclient.model.InBoxResponse;
import com.yohoufo.inboxclient.model.InboxReqVO;
import com.yohoufo.inboxclient.sdk.InBoxSDK;
import com.yohoufo.inboxclient.sdk.InBoxSendSmsService;
import com.yohoufo.inboxclient.sdk.InboxUserProxyService;
import com.yohoufo.user.cache.CacheService;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import com.yohoufo.user.service.IStoredSellerService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +23,8 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
@Service
public class StoredSellerServiceImpl implements IStoredSellerService {
... ... @@ -34,6 +43,15 @@ public class StoredSellerServiceImpl implements IStoredSellerService {
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private InBoxSDK inBoxSDK;
@Autowired
private InBoxSendSmsService inBoxSendSmsService;
@Autowired
private InboxUserProxyService inboxUserProxyService;
/*@Override
public void applyQuitStoredSeller(Integer uid){
... ... @@ -125,7 +143,38 @@ public class StoredSellerServiceImpl implements IStoredSellerService {
//保存到redis
cacheService.setStoredSeller( storedSeller);
//发送消息
sendMsg4enty(uid);
}
private void sendMsg4enty(Integer uid){
logger.info("sendMsg4enty inbox msg, uid {}",uid);
//采用异步方式新增消息
Runnable runnable = new Runnable() {
@Override
public void run() {
// 发送消息
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.SYSTEM_ENTER_SETTLED;
InboxReqVO inBoxReq = buildInboxReqVO(uid, null, ibt);
InBoxResponse resp = inBoxSDK.addInbox(inBoxReq);
logger.info("sendMsg4enty inbox msg, uid {}, resp {}",
uid, resp);
}
};
Thread thread = new Thread(runnable);
thread.start();
}
private InboxReqVO buildInboxReqVO(int uid, String params, InboxBusinessTypeEnum ibt) {
InboxReqVO req = new InboxReqVO();
req.setType(ibt.getType());
req.setBusinessType(ibt.getBusinessType());
//
req.setUid(uid);
req.setParams(params);
return req;
}
@Override
... ... @@ -157,6 +206,41 @@ public class StoredSellerServiceImpl implements IStoredSellerService {
cacheService.removeStoredSeller(uid);
logger.info("StoredSellerServiceImpl updateStoredSellerQuitStatus end ,uid is {} ,update num {}",uid,num);
return num;
}
private void sendMsg4quit(Integer uid){
logger.info("sendMsg4quit inbox msg, uid {}",uid);
//采用异步方式新增消息
Runnable runnable = new Runnable() {
@Override
public void run() {
// 发送消息
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.SYSTEM_EXIT_SETTLED;
InboxReqVO inBoxReq = buildInboxReqVO(uid, null, ibt);
InBoxResponse resp = inBoxSDK.addInbox(inBoxReq);
logger.info("sendMsg4quit inbox msg, uid {}, resp {}",
uid, resp);
// 发送短信
String content=InboxBusinessTypeEnum.SMS_EXIT_SETTLED.getContent();
String phone=inboxUserProxyService.getMobile(uid);
logger.info("sendMsg4quit inbox sms, uid {}, phone {}",
uid, phone);
if (StringUtils.isBlank(phone)){
logger.warn("endMsg4quit inbox sms fail cause of phone is empty, uid {} ", uid);
return;
}
List<String> mobileList = Arrays.asList(phone);
inBoxSendSmsService.smsSendByMobile(content,mobileList);
logger.info("sendMsg4quit inbox sms send end, uid {}, phone {}",
uid, phone);
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}
... ...