小麦君API:/api/req/taginfo/xiaomaijun

master
zzt 4 years ago
parent 0b01523d4e
commit ebb179781f

@ -245,6 +245,62 @@ public class ABClient {
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
*
* @date 2021-3-5 16:16:31
* @param vo
* @return
*/
@PostMapping("/api/req/taginfo/xiaomaijun")
@ResponseBody
public CommonResponse xiaoMaiJun(@RequestBody ABClientXMJMessageVO vo){
// 记录日志
log.info("====== [ xiaomaijun request comming, request content is {} ] ======", vo.toString());
return abClientService.saveXmj(vo) ?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
*
* @date 2021-3-5 16:16:59
* @param vo
* @return
*/
@PostMapping("/api/req/taginfo/shangyin")
@ResponseBody
public CommonResponse shuangYin(@RequestBody ABClientXMJMessageVO vo){
// 记录日志
log.info("====== [ xiaomaijun request comming, request content is {} ] ======", vo.toString());
return abClientService.saveXmj(vo) ?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
*
* @date 2021-3-5 16:16:59
* @param vo
* @return
*/
@PostMapping("/api/req/taginfo/shangyin")
@ResponseBody
public CommonResponse shuangYin(@RequestBody ABClientXMJMessageVO vo){
// 记录日志
log.info("====== [ xiaomaijun request comming, request content is {} ] ======", vo.toString());
return abClientService.saveXmj(vo) ?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
* AB
@ -583,4 +639,8 @@ public class ABClient {
return abClientService.recordFudaojunClientMsg(atoCvt)?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
}

@ -0,0 +1,20 @@
package com.yuyou.openapi.openapi.dao;
import com.yuyou.openapi.openapi.model.dataobject.LieheMessageDO;
import com.yuyou.openapi.openapi.model.dataobject.XiaomaMessageDO;
import com.yuyou.openapi.openapi.model.dataobject.XmjMessageDO;
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;
import javax.transaction.Transactional;
import java.util.Date;
@Repository
public interface XmjMessageRepository extends JpaRepository<XmjMessageDO, Long> {
@Modifying
@Transactional
@Query("update XmjMessageDO t set t.sendStatus = ?1,t.pushTime=?2 where t.recId = ?3")
Integer updateSendStatus(Integer sendStatus, Date time,Long recId);
}

@ -591,4 +591,5 @@ public class ABMessageConverter {
String matchActName = StringUtils.substringBeforeLast(decodeStr, "-");
detailInfo.setActName(matchActName);
}
}

@ -0,0 +1,97 @@
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;
/**
*
* @author zzt 2021/3/4 16:29
*/
@Data
@Table(name = "sy_message")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class SyMessageDO {
/**
* id
*/
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/**
* gmt_create
*/
@CreatedDate
@Column(name = "gmt_create")
private Date gmtCreate;
/**
* gmt_modified
*/
@Column(name = "gmt_modified")
@LastModifiedDate
private Date gmtModified;
/**
* id
*/
@Column(name = "rec_id")
private Long recId;
/**
* pnum
*/
@Column(name = "pnum")
private String pnum;
/**
*
*/
@Column(name = "act_name")
private String actName;
/**
*
*/
@Column(name = "start_time")
private Date startTime;
/**
* (1:a2:b3:c4:d5:e6:f)
*/
@Column(name = "client_type")
private Integer clientType;
/**
* id
*/
@Column(name = "app_id")
private String appId;
/**
*
*/
@Column(name = "receive_time")
private Date receiveTime;
/**
*
*/
@Column(name = "push_time")
private Date pushTime;
/**
* 1 0
*/
@Column(name = "send_status")
private Integer sendStatus;
}

@ -0,0 +1,97 @@
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;
/**
*
* @author zzt 2021/3/4 16:29
*/
@Data
@Table(name = "xmj_message")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class XmjMessageDO {
/**
* id
*/
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/**
* gmt_create
*/
@CreatedDate
@Column(name = "gmt_create")
private Date gmtCreate;
/**
* gmt_modified
*/
@Column(name = "gmt_modified")
@LastModifiedDate
private Date gmtModified;
/**
* id
*/
@Column(name = "rec_id")
private Long recId;
/**
* pnum
*/
@Column(name = "pnum")
private String pnum;
/**
*
*/
@Column(name = "act_name")
private String actName;
/**
*
*/
@Column(name = "start_time")
private Date startTime;
/**
* (1:a2:b3:c4:d5:e6:f)
*/
@Column(name = "client_type")
private Integer clientType;
/**
* id
*/
@Column(name = "app_id")
private String appId;
/**
*
*/
@Column(name = "receive_time")
private Date receiveTime;
/**
*
*/
@Column(name = "push_time")
private Date pushTime;
/**
* 1 0
*/
@Column(name = "send_status")
private Integer sendStatus;
}

@ -0,0 +1,35 @@
package com.yuyou.openapi.openapi.model.dto;
import lombok.*;
import java.util.List;
/**
* @author
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class XmjMessageDTO extends ABMessageDTO{
/**
* ,
*/
private List<ChatMsg> messages;
/**
*
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public static class ChatMsg {
private Long talkTime;
private Integer talkerType;
private String message;
}
}

@ -0,0 +1,29 @@
package com.yuyou.openapi.openapi.model.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.yuyou.openapi.openapi.model.vo.data.DetailInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
/**
*
* @author zt 2021-3-4 15:34:45
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ABClientXMJMessageVO extends ABClientBaseVO implements Serializable {
/**
*
*/
@JsonProperty(value = "data")
private List<DetailInfo> data;
}

@ -0,0 +1,95 @@
package com.yuyou.openapi.openapi.model.vo.data;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
/**
* @author zzt
* @date 2021/3/4 15:39
*/
@Data
public class DetailInfo {
// "data": [
// {
// "start_time": 1607003187354,
// "act_name": "5rWL6K+VNA==",
// "mobile": "MTMzNDY2NDc1OTU=",
// "messages": [
// {
// "talkTime": 1607003198000,
// "talkerType": 1,
// "message": ""
// },
// {
// "talkTime": 1607003198000,
// "talkerType": 2,
// "message": "喂-你好"
// },
// {
// "talkTime": 1607003201000,
// "talkerType": 1,
// "message": "您好。"
// },
// {
// "talkTime": 1607003201000,
// "talkerType": 2,
// "message": "你好,我这边是老端说险,老端说险是专业解决健康保障问题平台,值此平台5周年活动,我们针对关注健康的客户,免费赠险价值470元双人体检套餐一份。您有兴趣了解一下吗"
// },
// {
// "talkTime": 1607003220000,
// "talkerType": 1,
// "message": "没有。"
// },
// {
// "talkTime": 1607003220000,
// "talkerType": 2,
// "message": "那不好意思,打扰您了,祝您生活愉快,再见。"
// }
// ],
// "client_type": 1,
// "rec_id": 8471351
// }
// ]
/**
*
*/
@JsonProperty(value = "start_time")
private Long startTime;
/**
*
*/
@JsonProperty(value = "act_name")
private String actName;
/**
*
*/
@JsonProperty(value = "mobile")
private String mobile;
/**
*
*/
@JsonProperty(value = "messages")
private List<MessageInfo> messages;
/**
*
*/
@JsonProperty(value = "client_type")
private Integer clientType;
/**
*
*/
@JsonProperty(value = "rec_id")
private Long recId;
}

@ -0,0 +1,46 @@
package com.yuyou.openapi.openapi.model.vo.data;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* @author zzt
* @date 2021/3/4 15:39
*
*/
@Data
public class MessageInfo {
// "messages": [
// {
// "talkTime": 1607003198000,
// "talkerType": 1,
// "message": ""
// },
// {
// "talkTime": 1607003198000,
// "talkerType": 2,
// "message": "喂-你好"
// }
// ]
/**
*
*/
@JsonProperty(value = "talkTime")
private Long talkTime;
/**
*
*/
@JsonProperty(value = "talkerType")
private Integer talkerType;
/**
*
*
*/
@JsonProperty(value = "message")
private String message;
}

@ -1,6 +1,8 @@
package com.yuyou.openapi.openapi.service;
import com.yuyou.openapi.openapi.exception.BaiyeException;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.model.vo.ABClientXMJMessageVO;
import java.util.List;
@ -148,4 +150,11 @@ public interface ABClientService {
* @param dto Bean
*/
boolean recordFudaojunClientMsg(FudaojunMessageDTO dto);
/**
*
* @param vo
* @return |
*/
boolean saveXmj(ABClientXMJMessageVO vo) throws BaiyeException;
}

@ -57,4 +57,14 @@ public interface ABMessageService {
*/
List<ABMessageDTO> queryUnSendMessage(Date startPushTime, Date endPushTime);
/**
*
*
* @param sendStatus
* @param recId
* @param time
* @return |
*/
boolean updateXmj(Integer sendStatus, Long recId, Date time);
}

@ -1,17 +1,28 @@
package com.yuyou.openapi.openapi.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.yuyou.openapi.openapi.common.ResponseCode;
import com.yuyou.openapi.openapi.common.spi.ErrorCode;
import com.yuyou.openapi.openapi.dao.*;
import com.yuyou.openapi.openapi.exception.BaiyeException;
import com.yuyou.openapi.openapi.exception.CommonErrorCode;
import com.yuyou.openapi.openapi.model.convert.*;
import com.yuyou.openapi.openapi.model.dataobject.*;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.model.vo.ABClientXMJMessageVO;
import com.yuyou.openapi.openapi.model.vo.data.DetailInfo;
import com.yuyou.openapi.openapi.service.ABClientService;
import com.yuyou.openapi.openapi.task.ABDownTask;
import com.yuyou.openapi.openapi.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -92,6 +103,9 @@ public class ABClientServiceImpl implements ABClientService {
@Autowired
private JiaDongLiMessageRepository jiaDongLiMessageRepository;
@Autowired
private XmjMessageRepository xmjMessageRepository;
@Override
public boolean recordAndSendABClientMsg(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {
@ -641,4 +655,37 @@ public class ABClientServiceImpl implements ABClientService {
}
return Boolean.TRUE;
}
@Override
public boolean saveXmj(ABClientXMJMessageVO vo) {
if (vo==null){
throw new BaiyeException(CommonErrorCode.DATA_NOT_EXIT);
}
//数据解析入库
List<DetailInfo> data = vo.getData();
List<XmjMessageDO> xmjList = new ArrayList<>();
data.forEach(each->{
XmjMessageDO xmjMessageDO = new XmjMessageDO();
xmjMessageDO.setAppId(vo.getAppId());
xmjMessageDO.setActName(each.getActName());
xmjMessageDO.setRecId(each.getRecId());
xmjMessageDO.setClientType(each.getClientType());
xmjMessageDO.setReceiveTime(new Date());
xmjMessageDO.setStartTime(DateUtils.date(vo.getTimestamp()));
xmjMessageDO.setSendStatus(0);
xmjMessageDO.setPnum(each.getMobile());
xmjList.add(xmjMessageDO);
});
List<XmjMessageDO> rs = xmjMessageRepository.saveAll(xmjList);
if (CollectionUtils.isEmpty(rs)){
log.error("save xmj faild!"+vo.toString());
throw new BaiyeException(CommonErrorCode.RUNTIME_ERROR);
}
//完成数据下游推送
abDownTask.doPushXmj(vo);
return true;
}
}

@ -3,6 +3,7 @@ package com.yuyou.openapi.openapi.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.StrUtil;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.model.vo.ABClientXMJMessageVO;
import com.yuyou.openapi.openapi.service.ABClientService;
import org.springframework.stereotype.Service;
@ -153,6 +154,11 @@ public class ABClientServiceProxy implements ABClientService {
return abClientService.recordFudaojunClientMsg(dto);
}
@Override
public boolean saveXmj(ABClientXMJMessageVO vo) {
return abClientService.saveXmj(vo);
}
/**
*
* @param base64Value

@ -38,6 +38,9 @@ public class ABMessageServiceImpl implements ABMessageService {
@Autowired
private HeXiaoXiangMessageRepository heXiaoXiangMessageRepository;
@Autowired
private XmjMessageRepository xmjMessageRepository;
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateSendStatus(Long recId, boolean success) {
@ -160,4 +163,9 @@ public class ABMessageServiceImpl implements ABMessageService {
);
return abMessageDTOList;
}
@Override
public boolean updateXmj(Integer sendStatus, Long recId, Date time) {
return xmjMessageRepository.updateSendStatus(sendStatus,time,recId)>0;
}
}

@ -8,11 +8,14 @@ import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yuyou.openapi.openapi.api.enums.LuoShiAppIDEnum;
import com.yuyou.openapi.openapi.common.enums.IntentionEnum;
import com.yuyou.openapi.openapi.common.enums.SourceEnum;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.model.vo.ABClientXMJMessageVO;
import com.yuyou.openapi.openapi.model.vo.data.DetailInfo;
import com.yuyou.openapi.openapi.service.ABMessageService;
import com.yuyou.openapi.openapi.utils.SignUtils;
import lombok.extern.slf4j.Slf4j;
@ -27,8 +30,10 @@ import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@ -130,6 +135,17 @@ public class ABDownTask {
@Value("${ab.hexx.secretKey}")
private String hexxSecretKey;
@Value("${ab.xmj.appId}")
private String xmjAppid;
@Value("${ab.xmj.url}")
private String xmjUrl;
@Value("${ab.xmj.secretKey}")
private String xmjSecret;
/**
* ,
*
@ -636,6 +652,55 @@ public class ABDownTask {
);
return Boolean.TRUE;
}
public void doPushXmj(ABClientXMJMessageVO vo){
//数据转换
JSONObject jsonObject = new JSONObject();
jsonObject.put("app_id",xmjAppid);
long time=System.currentTimeMillis();
jsonObject.put("timestamp",time);
//TODO 补充字段,后续可能有值 taskCode
jsonObject.put("taskCode","1");
jsonObject.put("signature", SecureUtil.sha1("app_id="+ xmjAppid +"&timestamp="+ time + "&secret=" + xmjSecret));
JSONArray jsonArray = new JSONArray();
List<DetailInfo> datas = vo.getData();
datas.forEach(each->{
JSONObject data = new JSONObject();
data.put("recId",each.getRecId());
data.put("tag",IntentionEnum.codeOf(each.getClientType()));
data.put("mobile",StringUtils.reverse(each.getMobile()));
data.put("messages",each.getMessages());
jsonArray.add(data);
});
jsonObject.put("data",jsonArray);
log.info("xmj post json="+jsonObject.toJSONString());
//给下游推送。最多重试三次
int count=0;
while (count<3){
count++;
HttpResponse httpResponse = HttpRequest
.post(xmjUrl)
.body(jsonObject.toJSONString())
.execute();
log.info("xmj resp="+httpResponse.toString());
if (httpResponse.isOk()&&httpResponse.body().contains("0")){
break;
}else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("sleep error!");
}
}
}
//執行update
int finalCount = count;
datas.forEach(each->{
abMessageService.updateXmj(finalCount,each.getRecId(),new Date());
});
}
/**
* , -
@ -671,7 +736,7 @@ public class ABDownTask {
// 数据实体进行映射转换 - 目前是只有一条给
LieheMessageCovDTO2 lieheMessageCovDTO = convertLieheMessageCovDTOFromABMessageDTO2(messageDTO);
if (lieheMessageCovDTO == null) {
log.error("lieheMessageCovDTO is null.");
log.error(" is null.");
return false;
}
// 数据实体转成Json 不忽略空kv 有序

@ -24,6 +24,10 @@ spring:
password: root
# 下游请求配置信息
ab:
xmj:
appId: R1JaQKdh
url: http://tt.api.jikefx.cn/xmj/api/record_import
secretKey: 9I7Mlbqcy8JXPKExDH3A6zZCjps0rGWf
customer:
url: http://sandbox.openapi.ppke.com.cn/openapi/tmk/valid/receive
app_id: YY9X8XCZ
@ -111,6 +115,10 @@ ab:
taskid:
url: https://api.wooxin.cn/tketong/getLastAddId
secret: pmDclwRSYQgeiAKDghqXgs9m69OT7m69
xmj:
appId: R1JaQKdh
url: http://tt.api.jikefx.cn/xmj/api/record_import
secretKey: 9I7Mlbqcy8JXPKExDH3A6zZCjps0rGWf
logging:
config: classpath:logback.xml
---
@ -164,5 +172,9 @@ ab:
taskid:
url: https://api.wooxin.cn/tketong/getLastAddId
secret: pmDclwRSYQgeiAKDghqXgs9m69OT7m69
xmj:
appId: R1JaQKdh
url: http://tt.api.jikefx.cn/xmj/api/record_import
secretKey: 9I7Mlbqcy8JXPKExDH3A6zZCjps0rGWf
#logging:
# config: classpath:logback.xml
Loading…
Cancel
Save