新增service层数据加解密逻辑

master
queyounan 4 years ago
commit 2aff92811d

@ -61,6 +61,11 @@
<version>4.13</version> <version>4.13</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -3,6 +3,7 @@ package com.yuyou.openapi.openapi.api;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.yuyou.openapi.openapi.common.CommonResponse; import com.yuyou.openapi.openapi.common.CommonResponse;
import com.yuyou.openapi.openapi.common.ResponseCode; import com.yuyou.openapi.openapi.common.ResponseCode;
import com.yuyou.openapi.openapi.model.convert.ABMessageConverter;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO;
import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO; import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO;
@ -10,7 +11,6 @@ import com.yuyou.openapi.openapi.model.vo.ABClientZMMessageVO;
import com.yuyou.openapi.openapi.service.ABClientService; import com.yuyou.openapi.openapi.service.ABClientService;
import com.yuyou.openapi.openapi.utils.SecurityOperationUtil; import com.yuyou.openapi.openapi.utils.SecurityOperationUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -18,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* Copyright (C), 2012 - 2018, qyx * Copyright (C), 2012 - 2018, qyx
* FileName: DBABClient * FileName: DBABClient
@ -47,10 +49,9 @@ public class ABClient {
// 记录日志 // 记录日志
log.info("====== [ one request comming,request content is {} ] ======", vo.toString()); log.info("====== [ one request comming,request content is {} ] ======", vo.toString());
// 转换实体类映射 // 转换实体类映射
ABMessageDTO dto = new ABMessageDTO(); List<ABMessageDTO> dtos = ABMessageConverter.convertABMessageDTOFromVO(vo);
BeanUtils.copyProperties(vo, dto);
// 调用业务处理接口 // 调用业务处理接口
abClientService.recordAndSendABClientMsg(dto); abClientService.recordAndSendABClientMsg(dtos);
// 返回校验成功的结果 // 返回校验成功的结果
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }

@ -1,8 +1,14 @@
package com.yuyou.openapi.openapi.model.convert; package com.yuyou.openapi.openapi.model.convert;
import cn.hutool.core.date.DateUtil;
import com.yuyou.openapi.openapi.common.security.SecurityConstants;
import com.yuyou.openapi.openapi.common.security.SecurityService;
import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO; import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO; import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -13,6 +19,7 @@ import java.util.List;
* @version 1.0 * @version 1.0
* @date 2020/8/10 * @date 2020/8/10
*/ */
@Slf4j
public class ABMessageConverter { public class ABMessageConverter {
/** /**
@ -22,9 +29,45 @@ public class ABMessageConverter {
*/ */
public static List<ABMessageDTO> convertABMessageDTOFromVO(ABClientInterMessageVO abMessageVO) { public static List<ABMessageDTO> convertABMessageDTOFromVO(ABClientInterMessageVO abMessageVO) {
ArrayList<ABMessageDTO> dataList = new ArrayList<>(); ArrayList<ABMessageDTO> dataList = new ArrayList<>();
if (abMessageVO == null){
return dataList;
}
List<ABClientInterMessageVO.DetailInfo> detailInfoList = abMessageVO.getData();
if (CollectionUtils.isEmpty(detailInfoList)){
return dataList;
}
detailInfoList.forEach(
each->{
ABMessageDTO abMessageDTO = new ABMessageDTO();
abMessageDTO.setAppId(abMessageVO.getAppId());
abMessageDTO.setTimestamp(abMessageVO.getTimestamp());
BeanUtils.copyProperties(each, abMessageDTO);
dataList.add(abMessageDTO);
}
);
return dataList; return dataList;
} }
/**
* DTODO
* @param list
* @return
*/
public static List<ABMessageDO> convertABMessageDOFromDTO(List<ABMessageDTO> list) {
if (CollectionUtils.isEmpty(list)) {
return null;
}
List<ABMessageDO> abMessageDOs = new ArrayList<>();
list.forEach(each -> {
ABMessageDO abMessageDO = convertABMessageDOFromDTO(each);
if (abMessageDO != null) {
abMessageDOs.add(abMessageDO);
}
});
return abMessageDOs;
}
/** /**
* DTODO * DTODO
* @param abMessageDTO * @param abMessageDTO
@ -32,6 +75,20 @@ public class ABMessageConverter {
*/ */
public static ABMessageDO convertABMessageDOFromDTO(ABMessageDTO abMessageDTO) { public static ABMessageDO convertABMessageDOFromDTO(ABMessageDTO abMessageDTO) {
ABMessageDO abMessageDO = new ABMessageDO(); ABMessageDO abMessageDO = new ABMessageDO();
if (abMessageDTO == null) {
return abMessageDO;
}
BeanUtils.copyProperties(abMessageDTO, abMessageDO);
abMessageDO.setPushTime(DateUtil.date(abMessageDTO.getTimestamp() * 1000));
abMessageDO.setStartTime(DateUtil.date(abMessageDTO.getStartTime() * 1000));
// AES加密
try {
SecurityService.encrypt(abMessageDTO.getMobile(), SecurityConstants.PHONE);
} catch (Exception e) {
log.error("Encrypt Mobile raise Error, error is :", e);
}
abMessageDO.setPnum(abMessageDTO.getMobile());
return abMessageDO; return abMessageDO;
} }
} }

@ -1,6 +1,7 @@
package com.yuyou.openapi.openapi.model.vo; package com.yuyou.openapi.openapi.model.vo;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/** /**
* Copyright (C), 2012 - 2018, qyx * Copyright (C), 2012 - 2018, qyx
@ -12,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* <author> <time> <version> <desc> * <author> <time> <version> <desc>
* x 2020/8/4 v1.0 * x 2020/8/4 v1.0
*/ */
@Data
public class ABClientBaseVO { public class ABClientBaseVO {
/** /**

@ -3,6 +3,7 @@ package com.yuyou.openapi.openapi.model.vo;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
@ -18,6 +19,7 @@ import java.util.List;
* <author> <time> <version> <desc> * <author> <time> <version> <desc>
* x 2020/8/5 v1.0 * x 2020/8/5 v1.0
*/ */
@EqualsAndHashCode(callSuper = true)
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ -42,7 +44,7 @@ public class ABClientInterMessageVO extends ABClientBaseVO implements Serializab
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
static class DetailInfo { public static class DetailInfo{
/** /**
* poneNum Base64 * poneNum Base64
*/ */

@ -3,6 +3,8 @@ package com.yuyou.openapi.openapi.service;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO;
import java.util.List;
/** /**
* Copyright (C), 2012 - 2018, qyx * Copyright (C), 2012 - 2018, qyx
* FileName: ABClientService * FileName: ABClientService
@ -19,7 +21,8 @@ public interface ABClientService {
/** /**
* , * ,
*/ */
void recordAndSendABClientMsg(ABMessageDTO dto); void recordAndSendABClientMsg(List<ABMessageDTO> list);
/** /**
* , * ,
@ -27,4 +30,5 @@ public interface ABClientService {
* @param dto Bean * @param dto Bean
*/ */
void recordZMClientMsg(ABZMMessageDTO dto); void recordZMClientMsg(ABZMMessageDTO dto);
} }

@ -1,5 +1,8 @@
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.model.convert.ABMessageConverter;
import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABZMMessageDTO;
import com.yuyou.openapi.openapi.service.ABClientService; import com.yuyou.openapi.openapi.service.ABClientService;
@ -8,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Copyright (C), 2012 - 2018, qyx * Copyright (C), 2012 - 2018, qyx
@ -19,25 +23,26 @@ import java.util.ArrayList;
* <author> <time> <version> <desc> * <author> <time> <version> <desc>
* x 2020/8/4 v1.0 * x 2020/8/4 v1.0
*/ */
@Service @Service("ABClientServiceImpl")
public class ABClientServiceImpl implements ABClientService { public class ABClientServiceImpl implements ABClientService {
@Autowired @Autowired
private ABDownTask abDownTask; private ABDownTask abDownTask;
@Override @Autowired
public void recordAndSendABClientMsg(ABMessageDTO dto) { private ABMessageRepository abMessageRepository;
// 调用异步任务进行转发AB单 - 这里是这有一条数据
ArrayList<ABMessageDTO> dtoArrayList = new ArrayList<>();
dtoArrayList.add(dto);
boolean handleResult = abDownTask.doRunTask(dtoArrayList);
// 处理数据模型转换
@Override
public void recordAndSendABClientMsg(List<ABMessageDTO> list) {
// 调用接口进行入库 // 调用接口进行入库
List<ABMessageDO> abMessageDOs = ABMessageConverter.convertABMessageDOFromDTO(list);
List<ABMessageDO> dos = abMessageRepository.saveAll(abMessageDOs);
// TODO: 2020/8/10 0010 需要规划返回值类型
// 调用异步任务进行转发AB单 - 这里是这有一条数据
// TODO: 2020/8/10 0010 经过加密类进行处理 dtos
boolean handleResult = abDownTask.doRunTask(list);
// 返回处理结果 // 返回处理结果
} }
/** /**

@ -1,6 +1,7 @@
package com.yuyou.openapi.openapi.task; package com.yuyou.openapi.openapi.task;
import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
@ -9,6 +10,7 @@ import cn.hutool.json.JSONUtil;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.dto.ABMessageCovDTO; import com.yuyou.openapi.openapi.model.dto.ABMessageCovDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -16,6 +18,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* *
@ -58,7 +61,15 @@ public class ABDownTask {
int count = 0; // 设置请求失败计数 int count = 0; // 设置请求失败计数
// 数据实体进行映射转换 - 目前是只有一条给 // 数据实体进行映射转换 - 目前是只有一条给
ABMessageCovDTO abMessageCovDTO = new ABMessageCovDTO(); ABMessageCovDTO abMessageCovDTO = new ABMessageCovDTO();
abMessageCovDTO.setData(messageDTOList); // 对特殊情况进行过滤,只要AB单的用户,且字段加密规则要重新进行制定
List<ABMessageDTO> filterData = messageDTOList.stream()
.filter(item -> (1 == item.getClientType()) || 2 == item.getClientType())
.map(item -> {
StringUtils.reverse(Base64.encode(item.getMobile()));
return item;
})
.collect(Collectors.toList());
abMessageCovDTO.setData(filterData);
// 补充其他的下游请求字段 // 补充其他的下游请求字段
abMessageCovDTO.setNonce_str((System.currentTimeMillis()/1000)); abMessageCovDTO.setNonce_str((System.currentTimeMillis()/1000));
abMessageCovDTO.setApp_id(appId); abMessageCovDTO.setApp_id(appId);

Loading…
Cancel
Save