罗什业务代码开发完成

master
qyx-git 4 years ago
parent fbfbfaba02
commit dd68c5138b

@ -47,6 +47,8 @@ public class ABClient {
private ABDownTask abDownTask;
// ==================================== AB单推送 ==================================
/**
* AB -
*
@ -81,6 +83,23 @@ public class ABClient {
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
* AB -
*
* @return
*/
@PostMapping("/api/req/taginfo/luoshi")
@ResponseBody
public CommonResponse getDBTagInfoLuoshi(@RequestBody ABClientInterMessageVO vo) {
// 记录日志
log.info("====== [ Luoshi request comming, request content is {} ] ======", vo.toString());
// 转换实体类映射
List<ABMessageDTO> dtos = ABMessageConverter.convertABMessageDTOFromVO(vo);
// 调用业务处理接口 返回校验成功的结果
return abClientService.recordAndSendABClientMsgLuoshi(dtos) ?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
* AB

@ -0,0 +1,25 @@
package com.yuyou.openapi.openapi.dao;
import com.yuyou.openapi.openapi.model.dataobject.LuoshiMessageDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
* Copyright (C), 2012 - 2018, qyx
* FileName: LuoshiMessageRepository
* Author:
* Date: 2020/10/22 2:52 PM
* Description: TODO
* History:
* <author> <time> <version> <desc>
* 2020/10/22 v1.0
*/
@Repository
public interface LuoshiMessageRepository extends JpaRepository<LuoshiMessageDO, Long>{
@Modifying
@Query("update LuoshiMessageDO t set t.sendStatus = ?1 where t.recId = ?2")
void updateSendStatus(Integer sendStatus, Long recId);
}

@ -6,6 +6,7 @@ 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.LieheMessageDO;
import com.yuyou.openapi.openapi.model.dataobject.LuoshiMessageDO;
import com.yuyou.openapi.openapi.model.dataobject.ShijiMessageDO;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.vo.ABClientInterMessageVO;
@ -94,6 +95,25 @@ public class ABMessageConverter {
return abMessageDOs;
}
/**
* DTODO
* @param dtos
* @return
*/
public static List<LuoshiMessageDO> convertLuoshiABMessageDOFromDTO(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {
return null;
}
List<LuoshiMessageDO> abMessageDOs = new ArrayList<>();
dtos.forEach(each -> {
LuoshiMessageDO abMessageDO = convertLuoshiMessageDOFromDTO(each);
if (abMessageDO != null) {
abMessageDOs.add(abMessageDO);
}
});
return abMessageDOs;
}
/**
* DTODO
@ -178,7 +198,7 @@ public class ABMessageConverter {
}
/**
* Liehe DTODO
* Shiji DTODO
* @param abMessageDTO
* @return
*/
@ -208,6 +228,37 @@ public class ABMessageConverter {
return shijiMessageDO;
}
/**
* Luoshi DTODO
* @param abMessageDTO
* @return
*/
public static LuoshiMessageDO convertLuoshiMessageDOFromDTO(ABMessageDTO abMessageDTO) {
LuoshiMessageDO luoshiMessageDO = new LuoshiMessageDO();
if (abMessageDTO == null) {
return luoshiMessageDO;
}
BeanUtils.copyProperties(abMessageDTO, luoshiMessageDO);
luoshiMessageDO.setPushTime(DateUtils.date(abMessageDTO.getTimestamp()));
luoshiMessageDO.setStartTime(DateUtils.date(abMessageDTO.getStartTime()));
try{
luoshiMessageDO.setRecId(Long.valueOf(abMessageDTO.getRecId()));
}catch (Exception e){
log.error("String convert Long type Error.", e);
}
// AES加密
try {
String encryptedMobile = SecurityService.encrypt(abMessageDTO.getMobile(), SecurityConstants.PHONE);
luoshiMessageDO.setPnum(encryptedMobile);
} catch (Exception e) {
log.error("Encrypt Mobile raise Error, recId = {}, error is :", abMessageDTO.getRecId(), e);
luoshiMessageDO.setPnum(abMessageDTO.getMobile());
}
return luoshiMessageDO;
}

@ -0,0 +1,86 @@
package com.yuyou.openapi.openapi.model.dataobject;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
* Copyright (C), 2012 - 2018, qyx
* FileName: LuoshiMessageDO
* Author:
* Date: 2020/10/22 2:49 PM
* Description: TODO
* History:
* <author> <time> <version> <desc>
* 2020/10/22 v1.0
*/
@Data
@Table(name = "luoshi_message")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class LuoshiMessageDO {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
@Column(name = "gmt_create")
@CreatedDate
private Date gmtCreate;
@Column(name = "gmt_modified")
@LastModifiedDate
private Date gmtModified;
/**
* id
*/
@Column(name = "rec_id")
private Long recId;
/**
*
*/
@Column(name = "pnum")
private String pnum;
/**
*
*/
@Column(name = "act_name")
private String actName;
/**
*
*/
@Column(name = "start_time")
private Date startTime;
/**
* (1:A,2:B,3:C,4:D,5:E,6:F)
*/
@Column(name = "client_type")
private Integer clientType;
/**
* id
*/
@Column(name = "app_id")
private String appId;
/**
*
*/
@Column(name = "push_time")
private Date pushTime;
/**
* 0 0 - 1 -
*/
@Column(name = "send_status")
private Integer sendStatus = 0;
}

@ -0,0 +1,81 @@
package com.yuyou.openapi.openapi.model.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Copyright (C), 2012 - 2018, qyx
* FileName: LuoshiMessageCovDTO
* Author:
* Date: 2020/10/22 2:55 PM
* Description: TODO
* History:
* <author> <time> <version> <desc>
* 2020/10/22 v1.0
*/
/**
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LuoshiMessageCovDTO {
/**
* ID
*/
// @JSONField(serialize = false)
private String appId;
/**
*
*/
// @JSONField(serialize = false)
private Long timestamp;
/**
* : sha1(app_id=AppId&nonce_str=time_stamp)
*/
private String signature;
/**
* json
*/
private List<LuoshiData> data;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class LuoshiData{
/**
* poneNum Base64
*/
@JSONField(name = "info")
private String info;
/**
*
*/
@JSONField(name = "time")
private Long time;
/**
* Base64
*/
@JSONField(name = "subType")
@JsonIgnore
private String actName;
/**
* ABA-1B-2
*/
@JSONField(name = "type")
private Integer type;
}
}

@ -27,6 +27,11 @@ public interface ABClientService {
*/
boolean recordAndSendABClientMsgShiJi(List<ABMessageDTO> dtos);
/**
* ,
*/
boolean recordAndSendABClientMsgLuoshi(List<ABMessageDTO> dtos);
/**
* TODO:.recordAndSendABClientMsg
* @param dtos

@ -31,6 +31,11 @@ public interface ABMessageService {
*/
boolean updateSendSJSatus(Long recId, boolean sucess);
/**
* -
*/
boolean updateSendLSSatus(Long recId, boolean sucess);
/**
*
*/

@ -36,6 +36,8 @@ public class ABClientServiceImpl implements ABClientService {
private ABMessageRepository abMessageRepository;
@Autowired
private ShijiMessageRepository shijiMessageRepository;
@Autowired
private LuoshiMessageRepository luoshiMessageRepository;
@Autowired
private LieheMessageRepository lieheMessageRepository;
@ -101,6 +103,26 @@ public class ABClientServiceImpl implements ABClientService {
return Boolean.TRUE;
}
@Override
public boolean recordAndSendABClientMsgLuoshi(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {
log.error("Param dtos is empty");
return Boolean.FALSE;
}
// 调用接口进行入库
List<LuoshiMessageDO> abMessageDOS = ABMessageConverter.convertLuoshiABMessageDOFromDTO(dtos);
// TODO: 2020/8/10 0010 加密存储
List<LuoshiMessageDO> dos = luoshiMessageRepository.saveAll(abMessageDOS);
if (CollectionUtils.isEmpty(dos)){
log.error("========== [insert data error , please check .] ==========");
return Boolean.FALSE;
}
// 调用异步任务进行转发AB单 - 这里是这有一条数据
// 返回处理结果
abDownTask.doRunLuoshiTask(dtos);
return Boolean.TRUE;
}
@Override
public boolean recordAndSendLieheMsg(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {

@ -48,6 +48,16 @@ public class ABClientServiceProxy implements ABClientService {
return abClientService.recordAndSendABClientMsgShiJi(dto);
}
/**
* fixme 使
* @param dto
* @return
*/
@Override
public boolean recordAndSendABClientMsgLuoshi(List<ABMessageDTO> dto) {
return abClientService.recordAndSendABClientMsgLuoshi(dto);
}
@Override
public boolean recordAndSendLieheMsg(List<ABMessageDTO> dtos) {
return abClientService.recordAndSendLieheMsg(dtos);

@ -4,6 +4,7 @@ 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.dao.LuoshiMessageRepository;
import com.yuyou.openapi.openapi.dao.ShijiMessageRepository;
import com.yuyou.openapi.openapi.exception.SecretException;
import com.yuyou.openapi.openapi.model.dataobject.ABMessageDO;
@ -31,6 +32,8 @@ public class ABMessageServiceImpl implements ABMessageService {
@Autowired
private ShijiMessageRepository shijiMessageRepository;
@Autowired
private LuoshiMessageRepository luoshiMessageRepository;
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
@ -74,6 +77,20 @@ public class ABMessageServiceImpl implements ABMessageService {
return Boolean.TRUE;
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateSendLSSatus(Long recId, boolean sucess) {
if (recId == null) {
return Boolean.FALSE;
}
if (sucess) {
luoshiMessageRepository.updateSendStatus(1, recId);
}else {
luoshiMessageRepository.updateSendStatus(0, recId);
}
return Boolean.TRUE;
}
@Override
public List<ABMessageDTO> queryUnSendMessage(Date startPushTime, Date endPushTime) {

@ -9,10 +9,7 @@ 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.ABMessageCovDTO;
import com.yuyou.openapi.openapi.model.dto.ABMessageDTO;
import com.yuyou.openapi.openapi.model.dto.LieheMessageCovDTO;
import com.yuyou.openapi.openapi.model.dto.ShijiMessageCovDTO;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.service.ABMessageService;
import com.yuyou.openapi.openapi.utils.DateUtils;
import com.yuyou.openapi.openapi.utils.SignUtils;
@ -78,6 +75,18 @@ public class ABDownTask {
@Value("${ab.shiji.secretKey}")
private String shiJiSecretKey;
/**
* -
*/
@Value("${ab.luoshi.appId}")
private String luoShiAppId;
@Value("${ab.luoshi.url}")
private String luoShiUrl;
@Value("${ab.luoshi.secretKey}")
private String luoShiSecretKey;
/**
* ,
@ -232,6 +241,96 @@ public class ABDownTask {
return Boolean.TRUE;
}
/**
* ,
*
* @return
*/
@Async(value = "abTaskExecutor")
public void doRunLuoshiTask(List<ABMessageDTO> messageDTOList){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "doRunLuoshiTask");
runLuoshiTask(messageDTOList);
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "doRunLuoshiTask", (endMilliSecond-satrtMilliSecond));
}
/**
*
*
* @return
*/
private boolean runLuoshiTask(List<ABMessageDTO> messageDTOList){
int count = 0; // 设置请求失败计数
// 数据实体进行映射转换 - 目前是只有一条给
LuoshiMessageCovDTO luoshiMessageCovDTO = new LuoshiMessageCovDTO();
// 对特殊情况进行过滤,只要AB单的用户,且字段加密规则要重新进行制定
List<ABMessageDTO> collect = messageDTOList.stream()
.filter(item -> (1 == item.getClientType()) || 2 == item.getClientType())
.map(item -> {
// pno通配
String reverse = StringUtils.reverse(item.getMobile());
item.setMobile(reverse);
// startTime 通配下游到秒
Long startTime = item.getStartTime();
if (startTime != null && startTime.toString().length() == 13) {
item.setStartTime(startTime / 1000);
}
return item;
})
.collect(Collectors.toList());
List<LuoshiMessageCovDTO.LuoshiData> data = new ArrayList<>();
// 进行转换
collect.forEach(
each->{
LuoshiMessageCovDTO.LuoshiData luoshiData = new LuoshiMessageCovDTO.LuoshiData();
// BeanUtils.copyProperties(each, luoshiData);
luoshiData.setInfo(each.getMobile());
luoshiData.setType(1);
luoshiData.setTime(each.getStartTime());
data.add(luoshiData);
}
);
// 进行设置
if (!CollectionUtils.isEmpty(data)){
luoshiMessageCovDTO.setData(data);
}
// 补充其他的下游请求字段
long time = System.currentTimeMillis() / 1000;
luoshiMessageCovDTO.setTimestamp(time);
luoshiMessageCovDTO.setAppId(luoShiAppId);
luoshiMessageCovDTO.setSignature(SecureUtil.sha1("app_id="+ luoShiAppId +"&timestamp="+ time + "&secret=" + luoShiSecretKey));
// 数据实体转成Json 不忽略空kv 有序
String jsonStr = JSON.toJSONString(luoshiMessageCovDTO);
log.info("========== [ready send json is {} ] =============", jsonStr);
// 请求的响应处理
// todo 失败重发请求3次
while (count <= 3){
// 调用HTTP请求发送数据
HttpResponse httpResponse = sendLuoshiReq(jsonStr);
if (httpResponse.isOk() && httpResponse.body().contains("success")){
log.info("========== [request success, response is {} ] ==========", httpResponse.body());
break;
}else{
count ++;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
log.error("sleep error!");
}
log.error("========== [request fail, response is {} ] ==========", httpResponse.body());
}
}
if (count > 3) {
return Boolean.FALSE;
}
collect.forEach(
// FIXME: 2020/8/12 0012 可能会造成更新失败,检查更新语句
each -> abMessageService.updateSendLSSatus(Long.valueOf(each.getRecId()), Boolean.TRUE)
);
return Boolean.TRUE;
}
/**
* ,
*
@ -327,6 +426,20 @@ public class ABDownTask {
return httpResponse;
}
/**
* HTTP
*
* @param json body
* @return
*/
private HttpResponse sendLuoshiReq(String json){
HttpResponse httpResponse = HttpRequest
.post(luoShiUrl)
.body(json)
.execute();
return httpResponse;
}
/**
* liehe HTTP
* @param json

@ -1,6 +1,6 @@
spring:
profiles:
active: prod
active: dev
# 序列化忽略null的k-v配置
jackson:
default-property-inclusion: non_null
@ -40,6 +40,10 @@ ab:
appId: excin4hg3n29yc73ns9x
url: https://www.shijikj.cn/ex/infoColl
secretKey: ex456c24iejto89pavp
luoshi:
appId: Hangzhouyunuo
url: https://data.hzluoshi.cn/index/phoneapi
secretKey: 06be80a8084ab0fda5119049e335555a
---
# 端口
@ -72,6 +76,10 @@ ab:
appId: excin4hg3n29yc73ns9x
url: https://www.shijikj.cn/ex/infoColl
secretKey: ex456c24iejto89pavp
luoshi:
appId: Hangzhouyunuo
url: https://data.hzluoshi.cn/index/phoneapi
secretKey: 06be80a8084ab0fda5119049e335555a
logging:
config: classpath:logback.xml
---
@ -105,5 +113,9 @@ ab:
appId: excin4hg3n29yc73ns9x
url: https://www.shijikj.cn/ex/infoColl
secretKey: ex456c24iejto89pavp
luoshi:
appId: Hangzhouyunuo
url: https://data.hzluoshi.cn/index/phoneapi
secretKey: 06be80a8084ab0fda5119049e335555a
#logging:
# config: classpath:logback.xml

@ -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>
Loading…
Cancel
Save