增加了部分用于本地进行临时处理的逻辑

master
土豆兄弟 4 years ago
parent 6fcd298ab1
commit d258b20740

@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface LieheMessageRepository extends JpaRepository<LieheMessageDO, Long> { public interface LieheMessageRepository extends JpaRepository<LieheMessageDO, Long> {
@Modifying @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); void updateSendStatus( Integer sendStatus, Long recId);
} }

@ -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;
}

@ -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<E> 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;
}
}

@ -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<D> 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;
}
}

@ -13,4 +13,13 @@ public interface ABMessageService {
*/ */
boolean updateSendStatus(Long recId, boolean success); boolean updateSendStatus(Long recId, boolean success);
/**
* -
* @param recId
* @param sucess
* @return
*/
boolean updateSendLHStatus(Long recId, boolean sucess);
} }

@ -69,7 +69,6 @@ public class ABClientServiceImpl implements ABClientService {
} }
// 调用异步任务进行转发AB单 - 这里是这有一条数据 // 调用异步任务进行转发AB单 - 这里是这有一条数据
// 返回处理结果 // 返回处理结果
// TODO: 2020/8/11 0011 暂时关闭下游接口 - 进行测试
abDownTask.doRunTask(dtos); abDownTask.doRunTask(dtos);
return Boolean.TRUE; return Boolean.TRUE;
} }
@ -90,7 +89,6 @@ public class ABClientServiceImpl implements ABClientService {
} }
// 调用异步任务进行转发AB单 - 这里是这有一条数据 // 调用异步任务进行转发AB单 - 这里是这有一条数据
// 返回处理结果 // 返回处理结果
// TODO: 2020/8/11 0011 暂时关闭下游接口 - 进行测试
abDownTask.doLieheRunTask(dtos); abDownTask.doLieheRunTask(dtos);
return Boolean.TRUE; return Boolean.TRUE;
} }

@ -1,6 +1,7 @@
package com.yuyou.openapi.openapi.service.impl; package com.yuyou.openapi.openapi.service.impl;
import com.yuyou.openapi.openapi.dao.ABMessageRepository; import com.yuyou.openapi.openapi.dao.ABMessageRepository;
import com.yuyou.openapi.openapi.dao.LieheMessageRepository;
import com.yuyou.openapi.openapi.service.ABMessageService; import com.yuyou.openapi.openapi.service.ABMessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -14,6 +15,9 @@ public class ABMessageServiceImpl implements ABMessageService {
@Autowired @Autowired
private ABMessageRepository abMessageRepository; private ABMessageRepository abMessageRepository;
@Autowired
private LieheMessageRepository lieheMessageRepository;
@Override @Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateSendStatus(Long recId, boolean success) { public boolean updateSendStatus(Long recId, boolean success) {
@ -27,4 +31,18 @@ public class ABMessageServiceImpl implements ABMessageService {
} }
return Boolean.TRUE; 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;
}
} }

@ -142,7 +142,7 @@ public class ABDownTask {
public void doLieheRunTask(List<ABMessageDTO> messageDTOList){ public void doLieheRunTask(List<ABMessageDTO> messageDTOList){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ liehe task start running, task name is {} ] ======", "LieheABDownTask"); 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(); Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ liehe task start end, task name is {},cost milliSecond is {} ] ======", "LieheABDownTask", (endMilliSecond-satrtMilliSecond)); 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); log.info("========== [liehe ready send json is {} ] =============", jsonStr);
// 请求的响应处理 // 请求的响应处理
// todo 失败重发请求3次 // 失败重发请求3次
while (count <= 3){ while (count <= 3){
// 调用HTTP请求发送数据 // 调用HTTP请求发送数据
HttpResponse httpResponse = sendLieheReq(jsonStr); 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()); log.info("========== [liehe request success, response is {} ] ==========", httpResponse.body());
break; break;
}else{ }else{
@ -190,6 +190,12 @@ public class ABDownTask {
if (count > 3) { if (count > 3) {
return Boolean.FALSE; 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; return Boolean.TRUE;
} }

@ -64,9 +64,7 @@ public class SignUtils {
} }
sbKey = sbKey.append(KEY_STR + secretKey); sbKey = sbKey.append(KEY_STR + secretKey);
System.out.println("字符串=" + sbKey.toString());
String sign = SecureUtil.md5(sbKey.toString()).toUpperCase(); String sign = SecureUtil.md5(sbKey.toString()).toUpperCase();
System.out.println("sign=" + sign);
return sign; return sign;
} }

@ -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 {
}

@ -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() {
}
}

@ -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<String> 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<YiZaoLocalDTO.D> data = yiZaoLocalDTO.getData();
ArrayList<ResultBean.E> 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();
}
}
}
);
}
}

@ -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<String> 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());
}
}
);
}
}
Loading…
Cancel
Save