Authored by mali

增加infuxdb日志

package com.yohoufo.common.alarm;
import com.alibaba.fastjson.JSONObject;
/**
* Created by li.ma on 2019/2/26.
*/
public class UfoInfluxdbEvent extends Event{
private UfoInfluxdbVo ufoInfluxdbVo;
public UfoInfluxdbEvent(UfoInfluxdbVo ufoInfluxdbVo) {
this.ufoInfluxdbVo = ufoInfluxdbVo;
}
public UfoInfluxdbVo getUfoInfluxdbVo() {
return ufoInfluxdbVo;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
... ...
package com.yohoufo.common.alarm;
import com.yoho.core.common.alarm.EventReporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.Objects;
/**
* Created by li.ma on 2019/2/26.
*/
public class UfoInfluxdbEventHandler implements IEventHandler<UfoInfluxdbEvent> {
private static final Logger logger = LoggerFactory.getLogger(UfoInfluxdbEventHandler.class);
private EventReporter eventReporter;
private String tag_context;
private String cloud = "qcloud";
private final static String database = "ufo";
@Override
public void handle(UfoInfluxdbEvent event) {
logger.info("method UfoInfluxdbEventHandler onApplicationEvent, event", event);
if (Objects.isNull(event) || Objects.isNull(event.getUfoInfluxdbVo())) {
return;
}
UfoInfluxdbVo ufoInfluxdbVo = event.getUfoInfluxdbVo();
complete(ufoInfluxdbVo);
eventReporter.report(database, ufoInfluxdbVo.getMeasurement(), ufoInfluxdbVo.getTags(), ufoInfluxdbVo.getFields());
logger.info("method UfoInfluxdbEventHandler onApplicationEvent end, event", event);
}
private void complete(UfoInfluxdbVo ufoInfluxdbVo) {
if (null == ufoInfluxdbVo || null == ufoInfluxdbVo.getTags()) {
logger.warn("method UfoInfluxdbEventHandler ufoInfluxdbVo.getTags is null", ufoInfluxdbVo);
return;
}
Map<String, String> tags = ufoInfluxdbVo.getTags();
tags.put("cloud", cloud);
tags.put("context", tag_context);
}
public void setEventReporter(EventReporter eventReporter) {
this.eventReporter = eventReporter;
}
public void setCloud(String cloud) {
this.cloud = cloud;
}
public void setTag_context(String tag_context) {
this.tag_context = tag_context;
}
}
\ No newline at end of file
... ...
package com.yohoufo.common.alarm;
import com.alibaba.fastjson.JSONObject;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import java.util.HashMap;
import java.util.Map;
/**
* Created by li.ma on 2019/2/26.
*/
public class UfoInfluxdbVo {
private String eventType;
private String measurement;
private Map<String, String> tags;
private Map<String, Object> fields;
public String getEventType() {
return eventType;
}
public void setEventType(String eventType) {
this.eventType = eventType;
}
public Map<String, String> getTags() {
return tags;
}
public void setTags(Map<String, String> tags) {
this.tags = tags;
}
public Map<String, Object> getFields() {
return fields;
}
public void setFields(Map<String, Object> fields) {
this.fields = fields;
}
public String getMeasurement() {
return measurement;
}
public void setMeasurement(String measurement) {
this.measurement = measurement;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
public static class Builder {
private String eventType;
private String measurement;
private Map<String, String> tags;
private Map<String, Object> fields = new HashMap<>();
public Builder setEventType(String eventType) {
this.eventType = eventType;
return this;
}
public Builder setTags(Map<String, String> tags) {
this.tags = tags;
return this;
}
public Builder setFields(Map<String, Object> fields) {
this.fields = fields;
return this;
}
public Builder addInitField(InfluxdbFieldEnum fieldEnum) {
this.fields.put(fieldEnum.getFiledName(), 1);
return this;
}
public Builder addField(String fieldName, Object fieldValue) {
this.fields.put(fieldName, fieldValue);
return this;
}
public Builder setMeasurement(InfluxdbMeasurementEnum measurementEnum) {
this.measurement = measurementEnum.getMeasurement();
return this;
}
public UfoInfluxdbVo build() {
UfoInfluxdbVo event = new UfoInfluxdbVo();
event.setFields(this.fields);
event.setMeasurement(this.measurement);
event.setTags(this.tags);
event.setEventType(this.eventType);
return event;
}
}
}
... ...
package com.yohoufo.common.constant;
/**
* Created by li.ma on 2019/2/27.
*/
public enum InfluxdbFieldEnum {
FIELD_COUNT("count");
String filedName;
InfluxdbFieldEnum(String filedName) {
this.filedName = filedName;
}
public String getFiledName() {
return filedName;
}
}
... ...
package com.yohoufo.common.constant;
/**
* Created by li.ma on 2019/2/26.
*/
public enum InfluxdbMeasurementEnum {
MEASUREMENT_SELLER_ENTER("sellerEnter"),// = "sellerEnter", // 商家入驻
MEASUREMENT_ORDER_CANCEL("orderCancel");// = "orderCancel"; // 订单取消
String measurement;
InfluxdbMeasurementEnum(String measurement) {
this.measurement = measurement;
}
public String getMeasurement() {
return measurement;
}
}
... ...
... ... @@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
... ... @@ -155,6 +159,9 @@ public class BuyerOrderCancelService {
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, bpcr, transferCase);
}
... ... @@ -268,6 +275,9 @@ public class BuyerOrderCancelService {
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, bpcr, transferCase);
}
... ...
... ... @@ -7,6 +7,11 @@ import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerEnterApplyMapper;
... ... @@ -272,6 +277,9 @@ public class SellerEnterApplyService {
if (noStoredSeller && isMatchedET){
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
storedSellerService.addUserAsStoredSeller(uid, targetEst, slfb);
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
}else{
logger.warn("in upgradeLevel add StoredSeller fail, uid {} orderCode {}",
uid, orderCode);
... ... @@ -289,6 +297,9 @@ public class SellerEnterApplyService {
uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
merchantOrderPaymentService.changeWalletToSuperSeller(uid);
}
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
}else{
logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
uid, orderCode);
... ... @@ -383,6 +394,9 @@ public class SellerEnterApplyService {
int result = 0;
if (!noStoredSeller && isMatchedET && levelNeedUpgrade) {
doUpgradeSuper(targetEst, currentLevel, level, uid);
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
}
return result;
}
... ...
... ... @@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.alarm.UfoInfluxdbEvent;
import com.yohoufo.common.alarm.UfoInfluxdbVo;
import com.yohoufo.common.constant.InfluxdbFieldEnum;
import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
... ... @@ -579,6 +583,9 @@ public class SellerOrderCancelService {
//记录状态信息
logger.info("in cancelAfterPayExistBuyAction record status change, orderCode {}", buyerOrderCode);
orderStatusFlowService.addAsy(buyerOrderCode,targetBOStatus.getCode());
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
}
return result;
... ...
... ... @@ -110,4 +110,11 @@
<ref bean="accessStatistics"/>
</mvc:interceptors>
<!-- 上报influxdb 事件 -->
<bean id="ufoInfluxdbEventHandler" class="com.yohoufo.common.alarm.UfoInfluxdbEventHandler">
<property name="eventReporter" ref="eventReporter"/>
<property name="tag_context" value="${web.context:default}"/>
<!--<property name="cloud" value="${cloud:qcloud}"/>-->
</bean>
</beans>
\ No newline at end of file
... ...