增加补推逻辑

master
土豆兄弟 4 years ago
parent d258b20740
commit b41a521f10

@ -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<ABMessageDTO> dtos = abMessageService.queryUnSendMessage(startDate, endDate);
if (CollectionUtils.isEmpty(dtos)){
return CommonResponse.createByErrorMessage("error");
}
abDownTask.doRunTask(dtos);
return CommonResponse.createBySuccess();
}
/**
* AB
*

@ -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<ABMessageDO,Long> {
@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<ABMessageDO> findAllByPushTimeAndSendStatus(Date startPushTime, Date endPushTime, Integer sendStatus);
}

@ -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<ABMessageDTO> queryUnSendMessage(Date startPushTime, Date endPushTime);
}

@ -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<ABMessageDTO> queryUnSendMessage(Date startPushTime, Date endPushTime) {
List<ABMessageDO> abMessageDOList = abMessageRepository.findAllByPushTimeAndSendStatus(startPushTime, endPushTime, 0);
List<ABMessageDTO> 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;
}
}

@ -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
# 下游请求配置信息

@ -37,7 +37,7 @@
<root level="INFO">
<!-- TODO prod 环境去掉std -->
<appender-ref ref="stdAppender"/>
<!--<appender-ref ref="fileAppender"/>-->
<!--<appender-ref ref="stdAppender"/>-->
<appender-ref ref="fileAppender"/>
</root>
</configuration>

@ -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<ABMessageDO> allByPushTimeAndSendStatus = abMessageRepository.findAllByPushTimeAndSendStatus(startDate, endDate, 0);
System.out.println(allByPushTimeAndSendStatus.size());
}
}

@ -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<String> list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\1.json"));
List<String> 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<String> list = Files.readAllLines(Paths.get("C:\\Users\\Administrator\\Desktop\\254.json"));
List<String> 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);
}
}

Loading…
Cancel
Save