Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ufo
/
yohoufo-fore
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
wujiexiang
6 years ago
Commit
a2b80f0fc829ab5b67d770f4d4bce266606f2f8d
1 parent
aa10fd9f
新客缓存清除通知
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
21 deletions
order/src/main/java/com/yohoufo/order/service/listener/processor/BuyerOrderChangeBusinessPostProcessor.java
order/src/main/java/com/yohoufo/order/service/proxy/BargainProxyService.java
order/src/main/java/com/yohoufo/order/service/proxy/AbsServiceCaller.java → order/src/main/java/com/yohoufo/order/service/proxy/BaseServiceCaller.java
web/src/main/resources/rabbitmq.yml
order/src/main/java/com/yohoufo/order/service/listener/processor/BuyerOrderChangeBusinessPostProcessor.java
View file @
a2b80f0
...
...
@@ -11,6 +11,7 @@ import com.yohoufo.order.constants.ActivityTypeEnum;
import
com.yohoufo.order.constants.MetaKey
;
import
com.yohoufo.order.service.listener.BuyerOrderChangeEvent
;
import
com.yohoufo.order.model.bo.ActivityBo
;
import
com.yohoufo.order.service.proxy.BaseServiceCaller
;
import
com.yohoufo.order.service.proxy.BargainProxyService
;
import
com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport
;
import
com.yohoufo.order.utils.LoggerUtils
;
...
...
@@ -40,7 +41,10 @@ public class BuyerOrderChangeBusinessPostProcessor {
private
BargainProxyService
bargainProxyService
;
@Resource
(
name
=
"ufoExpressInfoProducer"
)
private
YhProducer
ufoExpressInfoProducer
;
private
YhProducer
commonProducer
;
@Autowired
private
BaseServiceCaller
baseServiceCaller
;
//业务处理器
private
List
<
BusinessProcessor
>
processors
=
Lists
.
newArrayList
(
...
...
@@ -188,7 +192,6 @@ public class BuyerOrderChangeBusinessPostProcessor {
}
}
/**
* 下单通知
*/
...
...
@@ -197,12 +200,26 @@ public class BuyerOrderChangeBusinessPostProcessor {
@Override
public
void
create
(
BusinessProcessorContext
context
)
{
//1.mq通知
BuyerOrder
buyerOrder
=
context
.
buyerOrder
;
int
uid
=
buyerOrder
.
getUid
();
//1.清理缓存yohobuy_gateway新客缓存
logger
.
info
(
"[{}] notify resource to clear user cache"
,
uid
);
try
{
String
url
=
baseServiceCaller
.
getYohoGatewayUrl
()
+
"?method=app.resources.clearUserCache&&client_type=h5&uid="
+
uid
;
baseServiceCaller
.
proxyPost
(
"app.resources.clearUserCache"
,
url
,
null
);
}
catch
(
Exception
ex
)
{
logger
.
error
(
"clear user cache for resource,uid:{}"
,
uid
,
ex
);
}
//2.
logger
.
info
(
"[{}] notify fofp to consume buyer order"
,
uid
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"uid"
,
buyerOrder
.
getUid
()
);
jsonObject
.
put
(
"uid"
,
uid
);
jsonObject
.
put
(
"orderCode"
,
buyerOrder
.
getOrderCode
());
jsonObject
.
put
(
"createTime"
,
buyerOrder
.
getCreateTime
());
ufoExpressInfo
Producer
.
send
(
TOPIC
,
jsonObject
);
common
Producer
.
send
(
TOPIC
,
jsonObject
);
}
}
...
...
order/src/main/java/com/yohoufo/order/service/proxy/BargainProxyService.java
View file @
a2b80f0
...
...
@@ -8,8 +8,11 @@ import com.yoho.core.transaction.annoation.TxCompensateArgs;
import
com.yoho.error.exception.ServiceException
;
import
com.yohoufo.common.ApiResponse
;
import
com.yohoufo.common.exception.UfoServiceException
;
import
com.yohoufo.order.utils.LoggerUtils
;
import
lombok.Data
;
import
lombok.ToString
;
import
org.slf4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
...
...
@@ -22,7 +25,13 @@ import java.util.Objects;
@Component
public
class
BargainProxyService
extends
AbsServiceCaller
implements
Compensator
{
public
class
BargainProxyService
implements
Compensator
{
private
final
static
Logger
logger
=
LoggerUtils
.
getBuyerOrderLogger
();
@Autowired
private
BaseServiceCaller
baseServiceCaller
;
/**
* 获取用户砍价商品的最终价格
* 所有的业务校验都在activity服务端实现,如活动时间、是否达成
...
...
@@ -33,12 +42,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public
CutDownPriceProductOrderBo
queryCutPriceProductForOrder
(
int
uid
,
int
cutRecordId
)
{
logger
.
info
(
"getActivityPrice by uid {},cutRecordId {}"
,
uid
,
cutRecordId
);
String
url
=
erpGatewayUrl
+
"/erp/activity/cutPrice/queryCutPriceProductForOrder"
;
String
url
=
baseServiceCaller
.
getErpGatewayUrl
()
+
"/erp/activity/cutPrice/queryCutPriceProductForOrder"
;
CutPriceHelpUserRequestBO
requestBO
=
new
CutPriceHelpUserRequestBO
();
requestBO
.
setUserId
(
uid
);
requestBO
.
setCutRecordId
(
cutRecordId
);
ApiResponse
response
=
proxyPost
(
"activity.queryCutPriceProductForOrder"
,
url
,
requestBO
);
CutDownPriceProductOrderBo
cutDownPriceProductOrderBo
=
getResultFromApiResponse
(
response
,
CutDownPriceProductOrderBo
.
class
);
ApiResponse
response
=
baseServiceCaller
.
proxyPost
(
"activity.queryCutPriceProductForOrder"
,
url
,
requestBO
);
CutDownPriceProductOrderBo
cutDownPriceProductOrderBo
=
baseServiceCaller
.
getResultFromApiResponse
(
response
,
CutDownPriceProductOrderBo
.
class
);
if
(
Objects
.
isNull
(
cutDownPriceProductOrderBo
))
{
logger
.
warn
(
"can't getActivityPrice by uid {},cutRecordId {}"
,
uid
,
cutRecordId
);
throw
new
UfoServiceException
(
500
,
"未查询到用户砍价商品信息"
);
...
...
@@ -59,12 +68,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
public
void
addCutPriceUseRecord
(
@TxCompensateArgs
(
"uid"
)
int
uid
,
@TxCompensateArgs
(
"orderCode"
)
long
orderCode
,
@TxCompensateArgs
(
"cutRecordId"
)
int
cutRecordId
)
throws
ServiceException
{
logger
.
debug
(
"addCutPriceUseRecord by uid {},cutRecordId {},orderCode {}"
,
uid
,
cutRecordId
,
orderCode
);
String
url
=
erpGatewayUrl
+
"/erp/activity/cutPrice/addCutPriceUseRecord"
;
String
url
=
baseServiceCaller
.
getErpGatewayUrl
()
+
"/erp/activity/cutPrice/addCutPriceUseRecord"
;
CutPriceHelpUserRequestBO
requestBO
=
new
CutPriceHelpUserRequestBO
();
requestBO
.
setUserId
(
uid
);
requestBO
.
setCutRecordId
(
cutRecordId
);
requestBO
.
setOrderCode
(
orderCode
);
ApiResponse
response
=
proxyPost
(
"activity.addCutPriceUseRecord"
,
url
,
requestBO
);
ApiResponse
response
=
baseServiceCaller
.
proxyPost
(
"activity.addCutPriceUseRecord"
,
url
,
requestBO
);
logger
.
info
(
"addCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}"
,
uid
,
cutRecordId
,
orderCode
,
response
);
if
(
response
==
null
||
response
.
getCode
()
!=
200
)
{
...
...
@@ -86,12 +95,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public
void
cancelCutPriceUseRecord
(
int
uid
,
long
orderCode
,
int
cutRecordId
)
throws
ServiceException
{
logger
.
debug
(
"cancelCutPriceUseRecord by uid {},orderCode {},cutRecordId {}"
,
uid
,
orderCode
,
cutRecordId
);
String
url
=
erpGatewayUrl
+
"/erp/activity/cutPrice/cancelCutPriceUseRecord"
;
String
url
=
baseServiceCaller
.
getErpGatewayUrl
()
+
"/erp/activity/cutPrice/cancelCutPriceUseRecord"
;
CutPriceHelpUserRequestBO
requestBO
=
new
CutPriceHelpUserRequestBO
();
requestBO
.
setUserId
(
uid
);
requestBO
.
setCutRecordId
(
cutRecordId
);
requestBO
.
setOrderCode
(
orderCode
);
ApiResponse
response
=
proxyPost
(
"activity.cancelCutPriceUseRecord"
,
url
,
requestBO
);
ApiResponse
response
=
baseServiceCaller
.
proxyPost
(
"activity.cancelCutPriceUseRecord"
,
url
,
requestBO
);
logger
.
info
(
"cancelCutPriceUseRecord(uid:{},cutRecordId:{},orderCode:{}),result is {}"
,
uid
,
cutRecordId
,
orderCode
,
response
);
if
(
response
!=
null
&&
response
.
getCode
()
==
200
)
{
logger
.
info
(
"[{}] cancelCutPriceUseRecord success,cutRecordId {}"
,
orderCode
,
cutRecordId
);
...
...
@@ -111,12 +120,12 @@ public class BargainProxyService extends AbsServiceCaller implements Compensator
*/
public
void
payCutPrice
(
int
uid
,
long
orderCode
,
int
cutRecordId
)
throws
ServiceException
{
logger
.
debug
(
"payCutPrice by uid {},orderCode {},cutRecordId {}"
,
uid
,
orderCode
,
cutRecordId
);
String
url
=
erpGatewayUrl
+
"/erp/activity/cutPrice/payCutPrice"
;
String
url
=
baseServiceCaller
.
getErpGatewayUrl
()
+
"/erp/activity/cutPrice/payCutPrice"
;
CutPriceHelpUserRequestBO
requestBO
=
new
CutPriceHelpUserRequestBO
();
requestBO
.
setUserId
(
uid
);
requestBO
.
setCutRecordId
(
cutRecordId
);
requestBO
.
setOrderCode
(
orderCode
);
ApiResponse
response
=
proxyPost
(
"activity.payCutPrice"
,
url
,
requestBO
);
ApiResponse
response
=
baseServiceCaller
.
proxyPost
(
"activity.payCutPrice"
,
url
,
requestBO
);
logger
.
info
(
"payCutPrice(uid:{},cutRecordId:{},orderCode:{}),result is {}"
,
uid
,
cutRecordId
,
orderCode
,
response
);
if
(
response
!=
null
&&
response
.
getCode
()
==
200
)
{
logger
.
info
(
"[{}] payCutPrice success,cutRecordId {}"
,
orderCode
,
cutRecordId
);
...
...
order/src/main/java/com/yohoufo/order/service/proxy/
Abs
ServiceCaller.java → order/src/main/java/com/yohoufo/order/service/proxy/
Base
ServiceCaller.java
View file @
a2b80f0
...
...
@@ -9,6 +9,7 @@ import com.yohoufo.order.utils.LoggerUtils;
import
org.slf4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -17,21 +18,33 @@ import java.util.concurrent.TimeUnit;
* Created by jiexiang.wu on 2019/5/21.
*/
public
abstract
class
AbsServiceCaller
{
@Component
public
class
BaseServiceCaller
{
pr
otected
final
static
Logger
logger
=
LoggerUtils
.
getBuyerOrderLogger
();
pr
ivate
final
static
Logger
logger
=
LoggerUtils
.
getBuyerOrderLogger
();
@Autowired
private
ServiceCaller
serviceCaller
;
@Value
(
"${erp-gateway.url}"
)
pr
otected
String
erpGatewayUrl
;
pr
ivate
String
erpGatewayUrl
;
protected
ApiResponse
proxyPost
(
String
serviceName
,
String
url
,
Object
object
)
{
@Value
(
"${yoho.gateway.url:http://service.yoho.yohoops.org}"
)
private
String
yohoGatewayUrl
;
public
String
getErpGatewayUrl
()
{
return
erpGatewayUrl
;
}
public
String
getYohoGatewayUrl
()
{
return
yohoGatewayUrl
;
}
public
ApiResponse
proxyPost
(
String
serviceName
,
String
url
,
Object
object
)
{
return
doPost
(
serviceName
,
url
,
object
);
}
p
rotected
ApiResponse
doPost
(
String
serviceName
,
String
url
,
Object
object
)
{
p
ublic
ApiResponse
doPost
(
String
serviceName
,
String
url
,
Object
object
)
{
try
{
return
serviceCaller
.
post
(
serviceName
,
url
,
object
,
ApiResponse
.
class
,
null
).
get
(
500
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
ServiceException
e
)
{
...
...
@@ -43,7 +56,7 @@ public abstract class AbsServiceCaller {
}
p
rotected
<
T
>
T
getResultFromApiResponse
(
ApiResponse
resp
,
Class
<
T
>
clazz
)
{
p
ublic
<
T
>
T
getResultFromApiResponse
(
ApiResponse
resp
,
Class
<
T
>
clazz
)
{
if
(
resp
==
null
)
{
throw
new
UfoServiceException
(
500
,
"服务器访问异常"
);
}
...
...
web/src/main/resources/rabbitmq.yml
View file @
a2b80f0
...
...
@@ -113,7 +113,7 @@ producer:
producers
:
-
bean
:
ufoExpressInfoProducer
-
address
:
192.168.10
3.58
:5672
-
address
:
192.168.10
2.45
:5672
username
:
yoho
password
:
yoho
producers
:
...
...
Please
register
or
login
to post a comment