Authored by mali

增加infuxdb日志

  1 +package com.yohoufo.common.alarm;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +
  5 +/**
  6 + * Created by li.ma on 2019/2/26.
  7 + */
  8 +public class UfoInfluxdbEvent extends Event{
  9 + private UfoInfluxdbVo ufoInfluxdbVo;
  10 +
  11 + public UfoInfluxdbEvent(UfoInfluxdbVo ufoInfluxdbVo) {
  12 + this.ufoInfluxdbVo = ufoInfluxdbVo;
  13 + }
  14 +
  15 + public UfoInfluxdbVo getUfoInfluxdbVo() {
  16 + return ufoInfluxdbVo;
  17 + }
  18 +
  19 + @Override
  20 + public String toString() {
  21 + return JSONObject.toJSONString(this);
  22 + }
  23 +}
  1 +package com.yohoufo.common.alarm;
  2 +
  3 +import com.yoho.core.common.alarm.EventReporter;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import java.util.Map;
  7 +import java.util.Objects;
  8 +
  9 +/**
  10 + * Created by li.ma on 2019/2/26.
  11 + */
  12 +public class UfoInfluxdbEventHandler implements IEventHandler<UfoInfluxdbEvent> {
  13 + private static final Logger logger = LoggerFactory.getLogger(UfoInfluxdbEventHandler.class);
  14 +
  15 + private EventReporter eventReporter;
  16 +
  17 + private String tag_context;
  18 +
  19 + private String cloud = "qcloud";
  20 +
  21 + private final static String database = "ufo";
  22 +
  23 + @Override
  24 + public void handle(UfoInfluxdbEvent event) {
  25 + logger.info("method UfoInfluxdbEventHandler onApplicationEvent, event", event);
  26 +
  27 + if (Objects.isNull(event) || Objects.isNull(event.getUfoInfluxdbVo())) {
  28 + return;
  29 + }
  30 +
  31 + UfoInfluxdbVo ufoInfluxdbVo = event.getUfoInfluxdbVo();
  32 +
  33 + complete(ufoInfluxdbVo);
  34 +
  35 + eventReporter.report(database, ufoInfluxdbVo.getMeasurement(), ufoInfluxdbVo.getTags(), ufoInfluxdbVo.getFields());
  36 +
  37 + logger.info("method UfoInfluxdbEventHandler onApplicationEvent end, event", event);
  38 + }
  39 +
  40 + private void complete(UfoInfluxdbVo ufoInfluxdbVo) {
  41 + if (null == ufoInfluxdbVo || null == ufoInfluxdbVo.getTags()) {
  42 + logger.warn("method UfoInfluxdbEventHandler ufoInfluxdbVo.getTags is null", ufoInfluxdbVo);
  43 + return;
  44 + }
  45 +
  46 + Map<String, String> tags = ufoInfluxdbVo.getTags();
  47 + tags.put("cloud", cloud);
  48 + tags.put("context", tag_context);
  49 + }
  50 +
  51 + public void setEventReporter(EventReporter eventReporter) {
  52 + this.eventReporter = eventReporter;
  53 + }
  54 +
  55 + public void setCloud(String cloud) {
  56 + this.cloud = cloud;
  57 + }
  58 +
  59 + public void setTag_context(String tag_context) {
  60 + this.tag_context = tag_context;
  61 + }
  62 +}
  1 +package com.yohoufo.common.alarm;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yohoufo.common.constant.InfluxdbFieldEnum;
  5 +import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
  6 +
  7 +import java.util.HashMap;
  8 +import java.util.Map;
  9 +
  10 +/**
  11 + * Created by li.ma on 2019/2/26.
  12 + */
  13 +public class UfoInfluxdbVo {
  14 +
  15 +
  16 + private String eventType;
  17 +
  18 + private String measurement;
  19 +
  20 + private Map<String, String> tags;
  21 +
  22 + private Map<String, Object> fields;
  23 +
  24 + public String getEventType() {
  25 + return eventType;
  26 + }
  27 +
  28 + public void setEventType(String eventType) {
  29 + this.eventType = eventType;
  30 + }
  31 +
  32 + public Map<String, String> getTags() {
  33 + return tags;
  34 + }
  35 +
  36 + public void setTags(Map<String, String> tags) {
  37 + this.tags = tags;
  38 + }
  39 +
  40 + public Map<String, Object> getFields() {
  41 + return fields;
  42 + }
  43 +
  44 + public void setFields(Map<String, Object> fields) {
  45 + this.fields = fields;
  46 + }
  47 +
  48 + public String getMeasurement() {
  49 + return measurement;
  50 + }
  51 +
  52 + public void setMeasurement(String measurement) {
  53 + this.measurement = measurement;
  54 + }
  55 +
  56 + @Override
  57 + public String toString() {
  58 + return JSONObject.toJSONString(this);
  59 + }
  60 +
  61 + public static class Builder {
  62 + private String eventType;
  63 +
  64 + private String measurement;
  65 +
  66 + private Map<String, String> tags;
  67 +
  68 + private Map<String, Object> fields = new HashMap<>();
  69 +
  70 + public Builder setEventType(String eventType) {
  71 + this.eventType = eventType;
  72 + return this;
  73 + }
  74 +
  75 + public Builder setTags(Map<String, String> tags) {
  76 + this.tags = tags;
  77 + return this;
  78 + }
  79 +
  80 +
  81 + public Builder setFields(Map<String, Object> fields) {
  82 + this.fields = fields;
  83 + return this;
  84 + }
  85 +
  86 + public Builder addInitField(InfluxdbFieldEnum fieldEnum) {
  87 + this.fields.put(fieldEnum.getFiledName(), 1);
  88 + return this;
  89 + }
  90 +
  91 + public Builder addField(String fieldName, Object fieldValue) {
  92 + this.fields.put(fieldName, fieldValue);
  93 + return this;
  94 + }
  95 +
  96 +
  97 + public Builder setMeasurement(InfluxdbMeasurementEnum measurementEnum) {
  98 + this.measurement = measurementEnum.getMeasurement();
  99 + return this;
  100 + }
  101 +
  102 +
  103 + public UfoInfluxdbVo build() {
  104 + UfoInfluxdbVo event = new UfoInfluxdbVo();
  105 + event.setFields(this.fields);
  106 + event.setMeasurement(this.measurement);
  107 + event.setTags(this.tags);
  108 + event.setEventType(this.eventType);
  109 + return event;
  110 + }
  111 + }
  112 +}
  1 +package com.yohoufo.common.constant;
  2 +
  3 +/**
  4 + * Created by li.ma on 2019/2/27.
  5 + */
  6 +public enum InfluxdbFieldEnum {
  7 + FIELD_COUNT("count");
  8 +
  9 + String filedName;
  10 +
  11 + InfluxdbFieldEnum(String filedName) {
  12 + this.filedName = filedName;
  13 + }
  14 +
  15 + public String getFiledName() {
  16 + return filedName;
  17 + }
  18 +}
  1 +package com.yohoufo.common.constant;
  2 +
  3 +/**
  4 + * Created by li.ma on 2019/2/26.
  5 + */
  6 +public enum InfluxdbMeasurementEnum {
  7 +
  8 + MEASUREMENT_SELLER_ENTER("sellerEnter"),// = "sellerEnter", // 商家入驻
  9 +
  10 + MEASUREMENT_ORDER_CANCEL("orderCancel");// = "orderCancel"; // 订单取消
  11 +
  12 + String measurement;
  13 +
  14 + InfluxdbMeasurementEnum(String measurement) {
  15 + this.measurement = measurement;
  16 + }
  17 +
  18 + public String getMeasurement() {
  19 + return measurement;
  20 + }
  21 +}
@@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.common.SellerOrderStatus; @@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
6 import com.yohobuy.ufo.model.order.common.SkupStatus; 6 import com.yohobuy.ufo.model.order.common.SkupStatus;
7 import com.yohobuy.ufo.model.order.common.TabType; 7 import com.yohobuy.ufo.model.order.common.TabType;
8 import com.yohoufo.common.alarm.EventBusPublisher; 8 import com.yohoufo.common.alarm.EventBusPublisher;
  9 +import com.yohoufo.common.alarm.UfoInfluxdbEvent;
  10 +import com.yohoufo.common.alarm.UfoInfluxdbVo;
  11 +import com.yohoufo.common.constant.InfluxdbFieldEnum;
  12 +import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
9 import com.yohoufo.common.utils.DateUtil; 13 import com.yohoufo.common.utils.DateUtil;
10 import com.yohoufo.dal.order.*; 14 import com.yohoufo.dal.order.*;
11 import com.yohoufo.dal.order.model.*; 15 import com.yohoufo.dal.order.model.*;
@@ -155,6 +159,9 @@ public class BuyerOrderCancelService { @@ -155,6 +159,9 @@ public class BuyerOrderCancelService {
155 ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid); 159 ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
156 EventBusPublisher.publishEvent(event); 160 EventBusPublisher.publishEvent(event);
157 161
  162 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
  163 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
  164 +
158 logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", 165 logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
159 buyerUid, orderCode, skup, bpcr, transferCase); 166 buyerUid, orderCode, skup, bpcr, transferCase);
160 } 167 }
@@ -268,6 +275,9 @@ public class BuyerOrderCancelService { @@ -268,6 +275,9 @@ public class BuyerOrderCancelService {
268 ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid); 275 ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
269 EventBusPublisher.publishEvent(event); 276 EventBusPublisher.publishEvent(event);
270 277
  278 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
  279 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
  280 +
271 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", 281 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
272 buyerUid, orderCode, skup, bpcr, transferCase); 282 buyerUid, orderCode, skup, bpcr, transferCase);
273 } 283 }
@@ -7,6 +7,11 @@ import com.yohobuy.ufo.model.order.common.EntrySellerType; @@ -7,6 +7,11 @@ import com.yohobuy.ufo.model.order.common.EntrySellerType;
7 import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus; 7 import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus;
8 import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel; 8 import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
9 import com.yohobuy.ufo.model.order.resp.EntryThreshold; 9 import com.yohobuy.ufo.model.order.resp.EntryThreshold;
  10 +import com.yohoufo.common.alarm.EventBusPublisher;
  11 +import com.yohoufo.common.alarm.UfoInfluxdbEvent;
  12 +import com.yohoufo.common.alarm.UfoInfluxdbVo;
  13 +import com.yohoufo.common.constant.InfluxdbFieldEnum;
  14 +import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
10 import com.yohoufo.common.exception.UfoServiceException; 15 import com.yohoufo.common.exception.UfoServiceException;
11 import com.yohoufo.common.utils.DateUtil; 16 import com.yohoufo.common.utils.DateUtil;
12 import com.yohoufo.dal.order.SellerEnterApplyMapper; 17 import com.yohoufo.dal.order.SellerEnterApplyMapper;
@@ -272,6 +277,9 @@ public class SellerEnterApplyService { @@ -272,6 +277,9 @@ public class SellerEnterApplyService {
272 if (noStoredSeller && isMatchedET){ 277 if (noStoredSeller && isMatchedET){
273 SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level); 278 SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
274 storedSellerService.addUserAsStoredSeller(uid, targetEst, slfb); 279 storedSellerService.addUserAsStoredSeller(uid, targetEst, slfb);
  280 +
  281 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
  282 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
275 }else{ 283 }else{
276 logger.warn("in upgradeLevel add StoredSeller fail, uid {} orderCode {}", 284 logger.warn("in upgradeLevel add StoredSeller fail, uid {} orderCode {}",
277 uid, orderCode); 285 uid, orderCode);
@@ -289,6 +297,9 @@ public class SellerEnterApplyService { @@ -289,6 +297,9 @@ public class SellerEnterApplyService {
289 uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET); 297 uid, orderCode, currentEnterType,preEnterType, noStoredSeller, level, isMatchedET);
290 merchantOrderPaymentService.changeWalletToSuperSeller(uid); 298 merchantOrderPaymentService.changeWalletToSuperSeller(uid);
291 } 299 }
  300 +
  301 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
  302 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
292 }else{ 303 }else{
293 logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}", 304 logger.warn("in upgradeLevel update StoredSeller fail, uid {} orderCode {}",
294 uid, orderCode); 305 uid, orderCode);
@@ -383,6 +394,9 @@ public class SellerEnterApplyService { @@ -383,6 +394,9 @@ public class SellerEnterApplyService {
383 int result = 0; 394 int result = 0;
384 if (!noStoredSeller && isMatchedET && levelNeedUpgrade) { 395 if (!noStoredSeller && isMatchedET && levelNeedUpgrade) {
385 doUpgradeSuper(targetEst, currentLevel, level, uid); 396 doUpgradeSuper(targetEst, currentLevel, level, uid);
  397 +
  398 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_SELLER_ENTER)
  399 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计入驻商家的记录
386 } 400 }
387 return result; 401 return result;
388 } 402 }
@@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo; @@ -6,6 +6,10 @@ import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
6 import com.yohobuy.ufo.model.order.common.*; 6 import com.yohobuy.ufo.model.order.common.*;
7 import com.yohoufo.common.alarm.EventBusPublisher; 7 import com.yohoufo.common.alarm.EventBusPublisher;
8 import com.yohoufo.common.alarm.SmsAlarmEvent; 8 import com.yohoufo.common.alarm.SmsAlarmEvent;
  9 +import com.yohoufo.common.alarm.UfoInfluxdbEvent;
  10 +import com.yohoufo.common.alarm.UfoInfluxdbVo;
  11 +import com.yohoufo.common.constant.InfluxdbFieldEnum;
  12 +import com.yohoufo.common.constant.InfluxdbMeasurementEnum;
9 import com.yohoufo.common.exception.UfoServiceException; 13 import com.yohoufo.common.exception.UfoServiceException;
10 import com.yohoufo.common.utils.DateUtil; 14 import com.yohoufo.common.utils.DateUtil;
11 import com.yohoufo.dal.order.*; 15 import com.yohoufo.dal.order.*;
@@ -579,6 +583,9 @@ public class SellerOrderCancelService { @@ -579,6 +583,9 @@ public class SellerOrderCancelService {
579 //记录状态信息 583 //记录状态信息
580 logger.info("in cancelAfterPayExistBuyAction record status change, orderCode {}", buyerOrderCode); 584 logger.info("in cancelAfterPayExistBuyAction record status change, orderCode {}", buyerOrderCode);
581 orderStatusFlowService.addAsy(buyerOrderCode,targetBOStatus.getCode()); 585 orderStatusFlowService.addAsy(buyerOrderCode,targetBOStatus.getCode());
  586 +
  587 + EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
  588 + .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
582 } 589 }
583 590
584 return result; 591 return result;
@@ -110,4 +110,11 @@ @@ -110,4 +110,11 @@
110 <ref bean="accessStatistics"/> 110 <ref bean="accessStatistics"/>
111 </mvc:interceptors> 111 </mvc:interceptors>
112 112
  113 +
  114 + <!-- 上报influxdb 事件 -->
  115 + <bean id="ufoInfluxdbEventHandler" class="com.yohoufo.common.alarm.UfoInfluxdbEventHandler">
  116 + <property name="eventReporter" ref="eventReporter"/>
  117 + <property name="tag_context" value="${web.context:default}"/>
  118 + <!--<property name="cloud" value="${cloud:qcloud}"/>-->
  119 + </bean>
113 </beans> 120 </beans>