From 2bde53c616b29ca878293ead211991eafecfe1b4 Mon Sep 17 00:00:00 2001 From: ljl Date: Thu, 9 Nov 2023 20:57:22 +0800 Subject: [PATCH] yh --- .../com/ms/api/dto/common/DoudianMessage.java | 18 +++++++++++++ .../java/com/ms/biz/listener/JobListener.java | 27 +++++++++++++++++++ .../java/com/ms/biz/paas/MqDemoService.java | 8 +++--- .../biz/spi/callback/BatchCreateService.java | 13 ++++++--- .../callback/DoudianMsgReceiveService.java | 17 ------------ .../main/java/com/ms/web/controller/Test.java | 12 ++++++--- 6 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 ms-api/src/main/java/com/ms/api/dto/common/DoudianMessage.java create mode 100644 ms-biz/src/main/java/com/ms/biz/listener/JobListener.java diff --git a/ms-api/src/main/java/com/ms/api/dto/common/DoudianMessage.java b/ms-api/src/main/java/com/ms/api/dto/common/DoudianMessage.java new file mode 100644 index 0000000..075f5bc --- /dev/null +++ b/ms-api/src/main/java/com/ms/api/dto/common/DoudianMessage.java @@ -0,0 +1,18 @@ +package com.ms.api.dto.common; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class DoudianMessage implements Serializable { + @JSONField(name = "tag") + private String tag; + + @JSONField(name = "msg_id") + private String msg_id; + + @JSONField(name = "data") + private String data; +} diff --git a/ms-biz/src/main/java/com/ms/biz/listener/JobListener.java b/ms-biz/src/main/java/com/ms/biz/listener/JobListener.java new file mode 100644 index 0000000..e7dc11a --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/listener/JobListener.java @@ -0,0 +1,27 @@ +package com.ms.biz.listener; + +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +//@Component +public class JobListener implements ApplicationListener, Runnable { + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + JobListener listener = event.getApplicationContext().getBean(JobListener.class); + new Thread(this).start(); + } + + @Override + public void run() { + while (true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.out.println("run run run..."); + } + } +} \ No newline at end of file diff --git a/ms-biz/src/main/java/com/ms/biz/paas/MqDemoService.java b/ms-biz/src/main/java/com/ms/biz/paas/MqDemoService.java index 58a0062..628fa84 100644 --- a/ms-biz/src/main/java/com/ms/biz/paas/MqDemoService.java +++ b/ms-biz/src/main/java/com/ms/biz/paas/MqDemoService.java @@ -56,9 +56,11 @@ public class MqDemoService implements ApplicationListener public void testConsumer() { DefaultMQPushConsumer consumer = MqFactory.newMqConsumer(GROUP, TOPIC, new MessageListenerConcurrently() { @Override - public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { - log.info("testConsumer Receive New Messages: {}", JSON.toJSONString(msgs)); + public ConsumeConcurrentlyStatus consumeMessage(List messages, ConsumeConcurrentlyContext context) { + log.info("testConsumer Receive New Messages: {}", JSON.toJSONString(messages)); + for (MessageExt message: messages) { + message.getBody(); + } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } }); diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java index 83b6890..5833b4d 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java @@ -8,6 +8,7 @@ import com.ms.biz.common.R; import com.ms.biz.common.SPIBaseService; import com.ms.biz.dto.openspi.request.BatchCreateParam; import com.ms.biz.dto.openspi.response.BatchCreateData; +import com.ms.biz.dto.openspi.response.BatchPayData; import com.ms.biz.service.DistributionOrderService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,9 +21,13 @@ public class BatchCreateService extends SPIBaseService implements ExtensionServi @Override public BaseResponse handle(BaseRequest req) { - BatchCreateParam param = req.getData(); - BatchCreateData data = new BatchCreateData(); - distributionOrderService.batchCreate(param, data); - return R.ok(data); + try { + BatchCreateParam param = req.getData(); + BatchCreateData data = new BatchCreateData(); + distributionOrderService.batchCreate(param, data); + return BaseResponse.builder().success(true).message("success").code("0").data(data).build(); + } catch (Exception e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code("100003").build(); + } } } \ No newline at end of file diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/DoudianMsgReceiveService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/DoudianMsgReceiveService.java index 3f2f1ca..063ca69 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/DoudianMsgReceiveService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/DoudianMsgReceiveService.java @@ -29,24 +29,7 @@ public class DoudianMsgReceiveService extends SPIBaseService implements Extensio } for (String msgStr: msgList) { DoudianMessage msg = JSON.parseObject(msgStr, DoudianMessage.class); - - } - - // ----逻辑校验---- - - // ----业务处理---- - boolean addRet = false; - try { - addRet = doudianMsgService.addDoudianMsg(msgBody); - } catch (Exception e) { - log.error(String.format("addDoudianMsg fail, exception: %s", e.getMessage())); } - - if (!addRet) { - log.info(String.format("fail msgBody: %s", JSON.toJSONString(msgList))); - return BaseResponse.builder().success(false).code("1").build(); - } - // 处理成功则返回 true code 0 return BaseResponse.builder().success(true).code("0").build(); } diff --git a/ms-web/src/main/java/com/ms/web/controller/Test.java b/ms-web/src/main/java/com/ms/web/controller/Test.java index 1d10c8d..5434dc0 100644 --- a/ms-web/src/main/java/com/ms/web/controller/Test.java +++ b/ms-web/src/main/java/com/ms/web/controller/Test.java @@ -1,13 +1,12 @@ package com.ms.web.controller; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; +import com.alibaba.fastjson.annotation.JSONField; import com.doudian.open.api.supplyCenter_cargo_detail.data.SupplyCenterCargoDetailData; import com.doudian.open.api.supplyCenter_cargo_detail.param.SupplyCenterCargoDetailParam; -import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.core.util.AuthThreadLocalUtil; +import com.ms.api.dto.common.DoudianMessage; import com.ms.api.dto.dsapi.response.CheckDsAppAuthExpireResponseDTO; import com.ms.api.dto.dsapi.response.GetAuthInfoResponseDTO; import com.ms.api.dto.dsapi.response.GetAuthShopMemberInfosResponseDTO; @@ -18,7 +17,7 @@ import com.ms.api.dto.dsorder.DsMessageCallbackDTO; import com.ms.biz.service.*; import com.ms.biz.tool.CommonTool; import com.ms.biz.util.DDApi; -import com.ms.dal.entity.Shop; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +26,7 @@ import org.springframework.web.bind.annotation.*; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; +import java.io.Serializable; import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -99,6 +99,10 @@ public class Test { } public static void main(String[] args) throws ParseException { + String str = "{\"data\":\"{\\\"activity_id\\\":\\\"0\\\",\\\"after\\\":\\\"false\\\",\\\"before\\\":\\\"true\\\",\\\"channel_id\\\":\\\"0\\\",\\\"channel_type\\\":0,\\\"process_time\\\":1699455945,\\\"product_id\\\":\\\"3649553844716833566\\\",\\\"shop_id\\\":\\\"121233657\\\",\\\"sku_id\\\":\\\"3384401776121602\\\"}\",\"tag\":\"420\",\"msg_id\":\"66533861744835594630:0:420:1699455945:2560971988:7264840234423027259\"}"; + DoudianMessage msg = JSON.parseObject(str, DoudianMessage.class); + System.out.println(msg); + System.out.println(Double.valueOf(CommonTool.doubleTrans(CommonTool.noZeros(2.00d)))); System.out.println("ni号顺11".length()); System.out.println("ni号顺11".substring(0, 6));