From b41a521f1007440507442875c869a99fa3d109d8 Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Tue, 8 Sep 2020 20:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A1=A5=E6=8E=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuyou/openapi/openapi/api/ABClient.java | 37 +++++++++++++++++-- .../openapi/dao/ABMessageRepository.java | 6 +++ .../openapi/service/ABMessageService.java | 9 +++++ .../service/impl/ABMessageServiceImpl.java | 34 +++++++++++++++++ src/main/resources/application.yml | 5 +-- src/main/resources/logback.xml | 4 +- .../com/yuyou/openapi/openapi/ABTest.java | 31 ++++++++++++++++ .../com/yuyou/openapi/openapi/ZMSortTest.java | 22 ++++++++--- 8 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 src/test/java/com/yuyou/openapi/openapi/ABTest.java diff --git a/src/main/java/com/yuyou/openapi/openapi/api/ABClient.java b/src/main/java/com/yuyou/openapi/openapi/api/ABClient.java index 0c19e0f..bfc5f51 100644 --- a/src/main/java/com/yuyou/openapi/openapi/api/ABClient.java +++ b/src/main/java/com/yuyou/openapi/openapi/api/ABClient.java @@ -13,16 +13,19 @@ import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO; import com.yuyou.openapi.openapi.model.vo.ABClientQingqingMessageVO; import com.yuyou.openapi.openapi.model.vo.ABClientZMMessageVO; import com.yuyou.openapi.openapi.service.ABClientService; +import com.yuyou.openapi.openapi.service.ABMessageService; +import com.yuyou.openapi.openapi.task.ABDownTask; import com.yuyou.openapi.openapi.utils.SecurityOperationUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; /** @@ -43,6 +46,12 @@ public class ABClient { @Qualifier("ABClientServiceProxy") private ABClientService abClientService; + @Autowired + private ABMessageService abMessageService; + + @Autowired + private ABDownTask abDownTask; + /** * 获取上游公司的AB数据推送接口 @@ -61,6 +70,26 @@ public class ABClient { CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试"); } + @PostMapping("/api/resend") + @ResponseBody + public CommonResponse reSend(@RequestParam String startPushTime, @RequestParam String endPushTime){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date startDate = null; + Date endDate = null; + try { + startDate = simpleDateFormat.parse(startPushTime); + endDate = simpleDateFormat.parse(endPushTime); + } catch (ParseException e) { + log.error("parse error! error msg is : {} ", e.getMessage(),e); + } + List dtos = abMessageService.queryUnSendMessage(startDate, endDate); + if (CollectionUtils.isEmpty(dtos)){ + return CommonResponse.createByErrorMessage("error"); + } + abDownTask.doRunTask(dtos); + return CommonResponse.createBySuccess(); + } + /** * 获取上游公司的AB数据推送接口 * diff --git a/src/main/java/com/yuyou/openapi/openapi/dao/ABMessageRepository.java b/src/main/java/com/yuyou/openapi/openapi/dao/ABMessageRepository.java index 611760d..4949e08 100644 --- a/src/main/java/com/yuyou/openapi/openapi/dao/ABMessageRepository.java +++ b/src/main/java/com/yuyou/openapi/openapi/dao/ABMessageRepository.java @@ -6,6 +6,9 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.Date; +import java.util.List; + /** * 数据层调用接口 */ @@ -15,4 +18,7 @@ public interface ABMessageRepository extends JpaRepository { @Modifying @Query("update ABMessageDO t set t.sendStatus = ?1 where t.recId = ?2") void updateSendStatus( Integer sendStatus, Long recId); + + @Query("from ABMessageDO a where a.pushTime >= ?1 and a.pushTime < ?2 and a.sendStatus = ?3 ") + List findAllByPushTimeAndSendStatus(Date startPushTime, Date endPushTime, Integer sendStatus); } 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 bb12b68..6b58c43 100644 --- a/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java +++ b/src/main/java/com/yuyou/openapi/openapi/service/ABMessageService.java @@ -1,6 +1,10 @@ package com.yuyou.openapi.openapi.service; +import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; + +import java.util.Date; +import java.util.List; public interface ABMessageService { @@ -22,4 +26,9 @@ public interface ABMessageService { */ boolean updateSendLHStatus(Long recId, boolean sucess); + /** + * 查询未发送成功的数据 + */ + List queryUnSendMessage(Date startPushTime, Date endPushTime); + } 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 bd57d07..28bf1ec 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,13 +1,23 @@ package com.yuyou.openapi.openapi.service.impl; +import com.yuyou.openapi.openapi.common.security.SecurityConstants; +import com.yuyou.openapi.openapi.common.security.SecurityService; import com.yuyou.openapi.openapi.dao.ABMessageRepository; import com.yuyou.openapi.openapi.dao.LieheMessageRepository; +import com.yuyou.openapi.openapi.exception.SecretException; +import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO; +import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.service.ABMessageService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + @Service public class ABMessageServiceImpl implements ABMessageService { @@ -45,4 +55,28 @@ public class ABMessageServiceImpl implements ABMessageService { } return Boolean.TRUE; } + + @Override + public List queryUnSendMessage(Date startPushTime, Date endPushTime) { + + List abMessageDOList = abMessageRepository.findAllByPushTimeAndSendStatus(startPushTime, endPushTime, 0); + + List abMessageDTOList = new ArrayList<>(); + + abMessageDOList.forEach ( + abMessageDO->{ + ABMessageDTO abMessageDTO = new ABMessageDTO(); + BeanUtils.copyProperties(abMessageDO, abMessageDTO); + try { + abMessageDTO.setMobile(SecurityService.decrypt(abMessageDO.getPnum(), SecurityConstants.PHONE)); + }catch (SecretException e) { + e.printStackTrace(); + } + abMessageDTO.setRecId(String.valueOf(abMessageDO.getRecId())); + abMessageDTO.setStartTime(abMessageDO.getStartTime().getTime()); + abMessageDTOList.add(abMessageDTO); + } + ); + return abMessageDTOList; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f215fa8..4a2f588 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: dev + active: prod # 序列化忽略null的k-v配置 jackson: default-property-inclusion: non_null @@ -38,7 +38,6 @@ ab: secretkey: c49bb9dd6860fe5630f1894b3723b430 - --- # 端口 server: @@ -49,7 +48,7 @@ spring: # 数据库相关配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/push?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false + url: jdbc:mysql://47.99.218.9:3306/push?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false username: root password: Yuyou@2020 # 下游请求配置信息 diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index dcf078b..2a6fb61 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -37,7 +37,7 @@ - - + + \ No newline at end of file diff --git a/src/test/java/com/yuyou/openapi/openapi/ABTest.java b/src/test/java/com/yuyou/openapi/openapi/ABTest.java new file mode 100644 index 0000000..d5731c0 --- /dev/null +++ b/src/test/java/com/yuyou/openapi/openapi/ABTest.java @@ -0,0 +1,31 @@ +package com.yuyou.openapi.openapi; + +import com.yuyou.openapi.openapi.dao.ABMessageRepository; +import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@Slf4j +public class ABTest extends OpenapiApplicationTest{ + + @Autowired + private ABMessageRepository abMessageRepository; + + @Test + public void testQuery() throws ParseException { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + Date startDate = simpleDateFormat.parse("2020-09-08 13:37:46"); + Date endDate = simpleDateFormat.parse("2020-09-08 13:47:26"); + + List allByPushTimeAndSendStatus = abMessageRepository.findAllByPushTimeAndSendStatus(startDate, endDate, 0); + + System.out.println(allByPushTimeAndSendStatus.size()); + } +} diff --git a/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java b/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java index 999bb36..263b7a4 100644 --- a/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java +++ b/src/test/java/com/yuyou/openapi/openapi/ZMSortTest.java @@ -4,8 +4,6 @@ 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; @@ -17,11 +15,12 @@ import org.springframework.beans.factory.annotation.Qualifier; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Date; import java.util.List; /** - * 掌门数据临时处理类 + * 掌门数据临时处理类 extends OpenapiApplicationTest */ @Slf4j public class ZMSortTest extends OpenapiApplicationTest{ @@ -35,7 +34,7 @@ public class ZMSortTest extends OpenapiApplicationTest{ */ @Test public void testZM() throws IOException { - List list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\1.json")); + List list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\254_1.json")); list.forEach( each->{ ABZMLocalDTO abzmLocalDTO = JSON.parseObject(each.trim(), ABZMLocalDTO.class); @@ -67,6 +66,19 @@ public class ZMSortTest extends OpenapiApplicationTest{ ); } - + @Test + public void testZMMessage() throws IOException { + List list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\254.json")); + List result = new ArrayList<>(); + list.forEach( + each->{ + if (StringUtils.isNotBlank(each.trim())){ + result.add(each.trim()+ "}"); + } + } + ); + System.out.println(result.size()); + Files.write(Paths.get("C:\\Users\\Administrator\\Desktop\\254_1.json"),result); + } }