From ce9e65c561988ca79476029a1814c1202a477ee2 Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Fri, 28 Aug 2020 10:30:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuyou/openapi/openapi/task/ABDownTask.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java b/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java index 8522706..ad374f5 100644 --- a/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java +++ b/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java @@ -9,15 +9,14 @@ import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.yuyou.openapi.openapi.common.enums.IntentionEnum; -import com.yuyou.openapi.openapi.model.dto.LieheMessageCovDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageCovDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; +import com.yuyou.openapi.openapi.model.dto.LieheMessageCovDTO; import com.yuyou.openapi.openapi.service.ABMessageService; import com.yuyou.openapi.openapi.utils.DateUtils; import com.yuyou.openapi.openapi.utils.SignUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -177,7 +176,7 @@ public class ABDownTask { // 请求的响应处理 // todo 失败重发请求3次 -/* while (count <= 3){ + while (count <= 3){ // 调用HTTP请求发送数据 HttpResponse httpResponse = sendReq(jsonStr); if (httpResponse.isOk() && httpResponse.body().contains("OK")){ @@ -190,7 +189,7 @@ public class ABDownTask { } if (count > 3) { return Boolean.FALSE; - }*/ + } return Boolean.TRUE; } From d258b20740531682348a08f33c8e9b87cd396bfa Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Mon, 7 Sep 2020 15:20:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=94=A8=E4=BA=8E=E6=9C=AC=E5=9C=B0=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=A4=84=E7=90=86=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openapi/dao/LieheMessageRepository.java | 2 +- .../openapi/model/pojo/ABZMLocalDTO.java | 23 ++++++ .../openapi/model/pojo/ResultBean.java | 33 +++++++++ .../openapi/model/pojo/YiZaoLocalDTO.java | 33 +++++++++ .../openapi/service/ABMessageService.java | 9 +++ .../service/impl/ABClientServiceImpl.java | 2 - .../service/impl/ABMessageServiceImpl.java | 18 +++++ .../openapi/openapi/task/ABDownTask.java | 12 +++- .../openapi/openapi/utils/SignUtils.java | 2 - src/main/resources/application.yml | 8 +-- .../openapi/OpenapiApplicationTest.java | 16 +++++ .../openapi/OpenapiApplicationTests.java | 13 ---- .../com/yuyou/openapi/openapi/SimpleTest.java | 50 +++++++++++++ .../com/yuyou/openapi/openapi/ZMSortTest.java | 72 +++++++++++++++++++ 14 files changed, 268 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/yuyou/openapi/openapi/model/pojo/ABZMLocalDTO.java create mode 100644 src/main/java/com/yuyou/openapi/openapi/model/pojo/ResultBean.java create mode 100644 src/main/java/com/yuyou/openapi/openapi/model/pojo/YiZaoLocalDTO.java create mode 100644 src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTest.java delete mode 100644 src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTests.java create mode 100644 src/test/java/com/yuyou/openapi/openapi/SimpleTest.java create mode 100644 src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java diff --git a/src/main/java/com/yuyou/openapi/openapi/dao/LieheMessageRepository.java b/src/main/java/com/yuyou/openapi/openapi/dao/LieheMessageRepository.java index 12f193a..f526fc2 100644 --- a/src/main/java/com/yuyou/openapi/openapi/dao/LieheMessageRepository.java +++ b/src/main/java/com/yuyou/openapi/openapi/dao/LieheMessageRepository.java @@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository; @Repository public interface LieheMessageRepository extends JpaRepository { @Modifying - @Query("update ABMessageDO t set t.sendStatus = ?1 where t.recId = ?2") + @Query("update LieheMessageDO t set t.sendStatus = ?1 where t.recId = ?2") void updateSendStatus( Integer sendStatus, Long recId); } diff --git a/src/main/java/com/yuyou/openapi/openapi/model/pojo/ABZMLocalDTO.java b/src/main/java/com/yuyou/openapi/openapi/model/pojo/ABZMLocalDTO.java new file mode 100644 index 0000000..2c8735e --- /dev/null +++ b/src/main/java/com/yuyou/openapi/openapi/model/pojo/ABZMLocalDTO.java @@ -0,0 +1,23 @@ +package com.yuyou.openapi.openapi.model.pojo; + +import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO; +import lombok.Data; + +@Data +public class ABZMLocalDTO { + + /** + * 记录Id + */ + private String recordId; + + /** + * 数据集合 + */ + private ABZMMessageDTO.Datas data; + + /** + * 标记集合 + */ + private ABZMMessageDTO.Tag tag; +} diff --git a/src/main/java/com/yuyou/openapi/openapi/model/pojo/ResultBean.java b/src/main/java/com/yuyou/openapi/openapi/model/pojo/ResultBean.java new file mode 100644 index 0000000..1d1a839 --- /dev/null +++ b/src/main/java/com/yuyou/openapi/openapi/model/pojo/ResultBean.java @@ -0,0 +1,33 @@ +package com.yuyou.openapi.openapi.model.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ResultBean { + + + private List data; + + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class E{ + + private Long start_time; + + private Long client_type; + + private String act_name; + + private String mobile; + + private Long rec_id; + } +} diff --git a/src/main/java/com/yuyou/openapi/openapi/model/pojo/YiZaoLocalDTO.java b/src/main/java/com/yuyou/openapi/openapi/model/pojo/YiZaoLocalDTO.java new file mode 100644 index 0000000..a5ea815 --- /dev/null +++ b/src/main/java/com/yuyou/openapi/openapi/model/pojo/YiZaoLocalDTO.java @@ -0,0 +1,33 @@ +package com.yuyou.openapi.openapi.model.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class YiZaoLocalDTO { + + + private List data; + + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class D{ + + private String start_time; + + private String client_type; + + private String act_name; + + private String mobile; + + private String rec_id; + } +} diff --git a/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java b/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java index 4edffd6..bb12b68 100644 --- a/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java +++ b/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java @@ -13,4 +13,13 @@ public interface ABMessageService { */ boolean updateSendStatus(Long recId, boolean success); + + /** + * 更新猎河的发送记录 - 单条更新 + * @param recId + * @param sucess + * @return + */ + boolean updateSendLHStatus(Long recId, boolean sucess); + } diff --git a/src/main/java/com/yuyou/openapi/openapi/service/impl/ABClientServiceImpl.java b/src/main/java/com/yuyou/openapi/openapi/service/impl/ABClientServiceImpl.java index 8c87dcd..e033529 100644 --- a/src/main/java/com/yuyou/openapi/openapi/service/impl/ABClientServiceImpl.java +++ b/src/main/java/com/yuyou/openapi/openapi/service/impl/ABClientServiceImpl.java @@ -69,7 +69,6 @@ public class ABClientServiceImpl implements ABClientService { } // 调用异步任务进行转发AB单 - 这里是这有一条数据 // 返回处理结果 - // TODO: 2020/8/11 0011 暂时关闭下游接口 - 进行测试 abDownTask.doRunTask(dtos); return Boolean.TRUE; } @@ -90,7 +89,6 @@ public class ABClientServiceImpl implements ABClientService { } // 调用异步任务进行转发AB单 - 这里是这有一条数据 // 返回处理结果 - // TODO: 2020/8/11 0011 暂时关闭下游接口 - 进行测试 abDownTask.doLieheRunTask(dtos); return Boolean.TRUE; } diff --git a/src/main/java/com/yuyou/openapi/openapi/service/impl/ABMessageServiceImpl.java b/src/main/java/com/yuyou/openapi/openapi/service/impl/ABMessageServiceImpl.java index e70a78b..bd57d07 100644 --- a/src/main/java/com/yuyou/openapi/openapi/service/impl/ABMessageServiceImpl.java +++ b/src/main/java/com/yuyou/openapi/openapi/service/impl/ABMessageServiceImpl.java @@ -1,6 +1,7 @@ package com.yuyou.openapi.openapi.service.impl; import com.yuyou.openapi.openapi.dao.ABMessageRepository; +import com.yuyou.openapi.openapi.dao.LieheMessageRepository; import com.yuyou.openapi.openapi.service.ABMessageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -14,6 +15,9 @@ public class ABMessageServiceImpl implements ABMessageService { @Autowired private ABMessageRepository abMessageRepository; + @Autowired + private LieheMessageRepository lieheMessageRepository; + @Override @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) public boolean updateSendStatus(Long recId, boolean success) { @@ -27,4 +31,18 @@ public class ABMessageServiceImpl implements ABMessageService { } return Boolean.TRUE; } + + @Override + @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) + public boolean updateSendLHStatus(Long recId, boolean sucess) { + if (recId == null) { + return Boolean.FALSE; + } + if (sucess) { + lieheMessageRepository.updateSendStatus(1, recId); + }else { + lieheMessageRepository.updateSendStatus(0, recId); + } + return Boolean.TRUE; + } } diff --git a/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java b/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java index 5ebecc4..a25986c 100644 --- a/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java +++ b/src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java @@ -142,7 +142,7 @@ public class ABDownTask { public void doLieheRunTask(List messageDTOList){ Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); log.info("====== [ liehe task start running, task name is {} ] ======", "LieheABDownTask"); - messageDTOList.forEach(each -> lieheRunTask(each)); + messageDTOList.forEach(this::lieheRunTask); Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); log.info("====== [ liehe task start end, task name is {},cost milliSecond is {} ] ======", "LieheABDownTask", (endMilliSecond-satrtMilliSecond)); } @@ -175,11 +175,11 @@ public class ABDownTask { log.info("========== [liehe ready send json is {} ] =============", jsonStr); // 请求的响应处理 - // todo 失败重发请求3次 + // 失败重发请求3次 while (count <= 3){ // 调用HTTP请求发送数据 HttpResponse httpResponse = sendLieheReq(jsonStr); - if (httpResponse.isOk() && httpResponse.body().contains("OK")){ + if (httpResponse.isOk() && httpResponse.body().contains("ok")){ log.info("========== [liehe request success, response is {} ] ==========", httpResponse.body()); break; }else{ @@ -190,6 +190,12 @@ public class ABDownTask { if (count > 3) { return Boolean.FALSE; } + // 更新记录 + boolean updateSendStatus = abMessageService.updateSendLHStatus(Long.valueOf(lieheMessageCovDTO.getRecId()), Boolean.TRUE); + if (!updateSendStatus){ + // 这里仅仅打日志, 不影响正常返回 + log.error("========== [liehe update send status fail, recId is {} ] ==========",lieheMessageCovDTO.getRecId()); + } return Boolean.TRUE; } diff --git a/src/main/java/com/yuyou/openapi/openapi/utils/SignUtils.java b/src/main/java/com/yuyou/openapi/openapi/utils/SignUtils.java index c7b25c9..58f3605 100644 --- a/src/main/java/com/yuyou/openapi/openapi/utils/SignUtils.java +++ b/src/main/java/com/yuyou/openapi/openapi/utils/SignUtils.java @@ -64,9 +64,7 @@ public class SignUtils { } sbKey = sbKey.append(KEY_STR + secretKey); - System.out.println("字符串=" + sbKey.toString()); String sign = SecureUtil.md5(sbKey.toString()).toUpperCase(); - System.out.println("sign=" + sign); return sign; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 33c174f..f215fa8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -62,9 +62,9 @@ ab: maxPoolSize: 16 queueCapacity: 3 ThreadNamePrefix: "AB-Req-" - liehe: - url: http://qkapi.liehe.com/v1.0/create_phone_tip - channel: quke_yy - secretkey: c49bb9dd6860fe5630f1894b3723b430 + liehe: + url: http://qkapi.liehe.com/v1.0/create_phone_tip + channel: quke_yy + secretkey: c49bb9dd6860fe5630f1894b3723b430 logging: config: classpath:logback.xml \ No newline at end of file diff --git a/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTest.java b/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTest.java new file mode 100644 index 0000000..457b866 --- /dev/null +++ b/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTest.java @@ -0,0 +1,16 @@ +package com.yuyou.openapi.openapi; + + +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * SpringBoot测试基类 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class OpenapiApplicationTest { + +} diff --git a/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTests.java b/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTests.java deleted file mode 100644 index 267e50c..0000000 --- a/src/test/java/com/yuyou/openapi/openapi/OpenapiApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yuyou.openapi.openapi; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class OpenapiApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/com/yuyou/openapi/openapi/SimpleTest.java b/src/test/java/com/yuyou/openapi/openapi/SimpleTest.java new file mode 100644 index 0000000..220335f --- /dev/null +++ b/src/test/java/com/yuyou/openapi/openapi/SimpleTest.java @@ -0,0 +1,50 @@ +package com.yuyou.openapi.openapi; + +import com.alibaba.fastjson.JSON; +import com.yuyou.openapi.openapi.model.pojo.ResultBean; +import com.yuyou.openapi.openapi.model.pojo.YiZaoLocalDTO; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; + +public class SimpleTest { + + + @Test + public void testYZ() throws IOException { + List list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\2.json")); + list.forEach( + each ->{ + YiZaoLocalDTO yiZaoLocalDTO = JSON.parseObject(each, YiZaoLocalDTO.class); + if (yiZaoLocalDTO != null){ + ResultBean resultBean = new ResultBean(); + List data = yiZaoLocalDTO.getData(); + ArrayList objects = new ArrayList<>(); + data.forEach( + one ->{ + ResultBean.E e = new ResultBean.E(); + e.setAct_name(one.getAct_name()); + e.setClient_type(Long.valueOf(one.getClient_type())); + e.setMobile(one.getMobile()); + e.setRec_id(Long.valueOf(one.getRec_id())); + e.setStart_time(Long.valueOf(one.getStart_time())); + objects.add(e); + } + ); + resultBean.setData(objects); + try { + Path write = Files.write(Paths.get("C:\\Users\\Administrator\\Desktop\\2-1.json"), JSON.toJSONString(resultBean).getBytes(), StandardOpenOption.CREATE_NEW); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + ); + } +} diff --git a/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java b/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java new file mode 100644 index 0000000..999bb36 --- /dev/null +++ b/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java @@ -0,0 +1,72 @@ +package com.yuyou.openapi.openapi; + + +import com.alibaba.fastjson.JSON; +import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO; +import com.yuyou.openapi.openapi.model.pojo.ABZMLocalDTO; +import com.yuyou.openapi.openapi.model.pojo.ResultBean; +import com.yuyou.openapi.openapi.model.pojo.YiZaoLocalDTO; +import com.yuyou.openapi.openapi.service.ABClientService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Date; +import java.util.List; + +/** + * 掌门数据临时处理类 + */ +@Slf4j +public class ZMSortTest extends OpenapiApplicationTest{ + + @Autowired + @Qualifier("ABClientServiceProxy") + private ABClientService abClientService; + + /** + * 测试本地进行补推ZM质检单 + */ + @Test + public void testZM() throws IOException { + List list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\1.json")); + list.forEach( + each->{ + ABZMLocalDTO abzmLocalDTO = JSON.parseObject(each.trim(), ABZMLocalDTO.class); + if (abzmLocalDTO == null) { + log.error("Param dtos is empty"); + } + ABZMMessageDTO abzmMessageDTO = new ABZMMessageDTO(); + if (abzmLocalDTO !=null){ + BeanUtils.copyProperties(abzmLocalDTO, abzmMessageDTO); + abzmMessageDTO.setAppId("5aSn5Z2d56eR5oqA"); + abzmMessageDTO.setTimestamp(new Date().getTime()); + } + if (StringUtils.isNotBlank(abzmMessageDTO.getData().getMobile()) + && StringUtils.isNotBlank(abzmMessageDTO.getData().getName()) + && StringUtils.isNotBlank(abzmMessageDTO.getData().getGrade()) + && StringUtils.isNotBlank(abzmMessageDTO.getData().getCourse()) + ){ +// System.out.println(abzmMessageDTO); + boolean insert = abClientService.recordZMClientMsg(abzmMessageDTO); + if (insert){ + log.info("success"); + }else { + log.info("error"); + } + }else{ + log.error("========== [insert into DB fail, this msg content is {} ] ==========",abzmMessageDTO.toString()); + } + } + ); + } + + + +}