Merge branch 'master' of http://git.hchbox.com/yuyou/client into master

开发代码暂存

# Conflicts:
#	src/main/java/com/yuyou/openapi/openapi/task/ABDownTask.java
#	src/main/resources/application.yml
master
土豆兄弟 4 years ago
commit e40590e73e

@ -117,6 +117,24 @@ public class ABClient {
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
* AB -
*
* @return
*/
@PostMapping("/api/req/taginfo/yhxkb")
@ResponseBody
public CommonResponse getDBTagInfoYH(@RequestBody ABClientInterMessageVO vo) {
// 记录日志
log.info("====== [ Shuangying request comming, request content is {} ] ======", vo.toString());
// 转换实体类映射
List<ABMessageDTO> dtos = ABMessageConverter.convertABMessageDTOFromVO(vo);
// 调用业务处理接口 返回校验成功的结果
return abClientService.recordAndSendABClientMsgYH(dtos) ?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
/**
@ -261,6 +279,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
@ -599,4 +673,8 @@ public class ABClient {
return abClientService.recordFudaojunClientMsg(atoCvt)?
CommonResponse.createBySuccess() : CommonResponse.createByErrorMessage("调用失败请重试");
}
}

@ -22,11 +22,11 @@ public class ThreadPoolConfig {
* 线
*/
@Value(value = "${ab.customer.thread_pool.corePoolSize}")
private int corePoolSize = 2;
private int corePoolSize = 4;
@Value(value = "${ab.customer.thread_pool.maxPoolSize}")
private int maxPoolSize = 16;
private int maxPoolSize = 32;
@Value(value = "${ab.customer.thread_pool.queueCapacity}")
private int queueCapacity = 3;
private int queueCapacity = 100;
@Value(value = "${ab.customer.thread_pool.ThreadNamePrefix}")
private String ThreadNamePrefix = "MyThreadPoolExecutor-";

@ -0,0 +1,9 @@
package com.yuyou.openapi.openapi.consts;
public class SpecialCityConst {
/**
*
*/
public static final String[] SPECIAL_RANDOM_CITYS = {"重庆","杭州","宁波","舟山","绍兴","金华","嘉兴","昆明","拉萨","天津","成都","绵阳","南充","宜宾","上海","吉安","苏州","无锡","南通","泰州","淮安","连云港","镇江","南京","长沙","武汉","南阳","三亚","贵阳","广州","深圳","佛山","惠州","东莞","珠海","中山","清远","福州","北京","芜湖","合肥","六安","安庆"};
}

@ -0,0 +1,18 @@
package com.yuyou.openapi.openapi.dao;
import com.yuyou.openapi.openapi.model.dataobject.PhonesDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
*
*/
@Repository
public interface PhonesRepository extends JpaRepository<PhonesDO,Long> {
@Query(value = "SELECT r.city FROM `tb_phones` p LEFT JOIN `tb_regions` r ON p.region_id = r.id WHERE p.number = :number", nativeQuery = true)
String findByNumber(@Param("number") String number);
}

@ -0,0 +1,18 @@
package com.yuyou.openapi.openapi.dao;
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);
}

@ -0,0 +1,25 @@
package com.yuyou.openapi.openapi.dao;
import com.yuyou.openapi.openapi.model.dataobject.YHMessageDO;
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 YHMessageRepository extends JpaRepository<YHMessageDO, Long>{
@Modifying
@Query("update YHMessageDO t set t.sendStatus = ?1 where t.recId = ?2")
void updateSendStatus(Integer sendStatus, Long recId);
}

@ -170,6 +170,25 @@ public class ABMessageConverter {
return abMessageDOs;
}
/**
* DTODO
* @param dtos
* @return
*/
public static List<YHMessageDO> convertYHABMessageDOFromDTO(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {
return null;
}
List<YHMessageDO> abMessageDOs = new ArrayList<>();
dtos.forEach(each -> {
YHMessageDO abMessageDO = convertYHMessageDOFromDTO(each);
if (abMessageDO != null) {
abMessageDOs.add(abMessageDO);
}
});
return abMessageDOs;
}
/**
* DTODO
@ -466,6 +485,38 @@ public class ABMessageConverter {
return shuangYingMessageDO;
}
/**
* Luoshi DTODO
* @param abMessageDTO
* @return
*/
public static YHMessageDO convertYHMessageDOFromDTO(ABMessageDTO abMessageDTO) {
YHMessageDO yhMessageDO = new YHMessageDO();
if (abMessageDTO == null) {
return yhMessageDO;
}
BeanUtils.copyProperties(abMessageDTO, yhMessageDO);
yhMessageDO.setPushTime(DateUtils.date(abMessageDTO.getTimestamp()));
yhMessageDO.setStartTime(DateUtils.date(abMessageDTO.getStartTime()));
try{
yhMessageDO.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);
yhMessageDO.setPnum(encryptedMobile);
} catch (Exception e) {
log.error("Encrypt Mobile raise Error, recId = {}, error is :", abMessageDTO.getRecId(), e);
yhMessageDO.setPnum(abMessageDTO.getMobile());
}
return yhMessageDO;
}
/**
* Luoshi DTODO
* @param abMessageDTO
@ -643,4 +694,5 @@ public class ABMessageConverter {
String matchActName = StringUtils.substringBeforeLast(decodeStr, "-");
detailInfo.setActName(matchActName);
}
}

@ -0,0 +1,40 @@
package com.yuyou.openapi.openapi.model.dataobject;
import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
/**
* AB
* @version 1.0
* @date 2020/8/6
*/
@Data
@Table(name = "tb_phones")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class PhonesDO {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
/**
*
*/
@Column(name = "number")
private Integer number;
/**
* 1 2 3
*/
@Column(name = "type")
private Integer type;
/**
* ID
*/
@Column(name = "region_id")
private Integer regionId;
}

@ -0,0 +1,42 @@
package com.yuyou.openapi.openapi.model.dataobject;
import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
@Data
@Table(name = "tb_regions")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class ReginsDO {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
/**
*
*/
@Column(name = "province")
private String province;
/**
*
*/
@Column(name = "city")
private String city;
/**
*
*/
@Column(name = "zip_code")
private String zipCode;
/**
* ID
*/
@Column(name = "area_code")
private String areaCode;
}

@ -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,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 = "yh_message")
@Entity
@EntityListeners(AuditingEntityListener.class)
public class YHMessageDO {
@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,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,82 @@
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: ShuangYingMessageCovDTO
* 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 YHMessageCovDTO {
/**
* ID
*/
// @JSONField(serialize = false)
@JSONField(name = "app_id")
private String appId;
/**
*
*/
// @JSONField(serialize = false)
private Long timestamp;
/**
* : sha1(app_id=AppId&nonce_str=time_stamp)
*/
private String signature;
/**
* json
*/
private List<YHData> data;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class YHData{
/**
* 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;
}
}

@ -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;
@ -37,6 +39,11 @@ public interface ABClientService {
*/
boolean recordAndSendABClientMsgShuangYing(List<ABMessageDTO> dtos);
/**
* ,
*/
boolean recordAndSendABClientMsgYH(List<ABMessageDTO> dtos);
/**
* ,
*/
@ -153,4 +160,13 @@ public interface ABClientService {
* @param dto Bean
*/
boolean recordFudaojunClientMsg(FudaojunMessageDTO dto);
/**
*
* @param vo
* @return |
*/
boolean saveXmj(ABClientXMJMessageVO vo) throws BaiyeException;
}

@ -46,6 +46,12 @@ public interface ABMessageService {
*/
boolean updateSendHeXXSatus(Long recId, boolean sucess);
/**
* -
*/
boolean updateSendYHSatus(Long recId, boolean sucess);
/**
* -
*/
@ -61,4 +67,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,24 @@
package com.yuyou.openapi.openapi.service.impl;
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;
/**
@ -44,6 +51,9 @@ public class ABClientServiceImpl implements ABClientService {
@Autowired
private ShuangYingMessageRepository shuangYingMessageRepository;
@Autowired
private YHMessageRepository yhMessageRepository;
@Autowired
private PandaMessageRepository pandaMessageRepository;
@ -95,6 +105,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)) {
@ -271,6 +284,26 @@ public class ABClientServiceImpl implements ABClientService {
return Boolean.TRUE;
}
@Override
public boolean recordAndSendABClientMsgYH(List<ABMessageDTO> dtos) {
if (CollectionUtils.isEmpty(dtos)) {
log.error("Param dtos is empty");
return Boolean.FALSE;
}
// 调用接口进行入库
List<YHMessageDO> abMessageDOS = ABMessageConverter.convertYHABMessageDOFromDTO(dtos);
List<YHMessageDO> dos = yhMessageRepository.saveAll(abMessageDOS);
if (CollectionUtils.isEmpty(dos)){
log.error("========== [insert data error , please check .] ==========");
return Boolean.FALSE;
}
// 调用异步任务进行转发AB单 - 这里是这有一条数据
// 返回处理结果
abDownTask.doRunYHTask(dtos);
return Boolean.TRUE;
}
@Override
public boolean recordAndSendLieheMsg(List<LieheMessageDTO> dtos) {
@ -664,4 +697,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;
@ -63,6 +64,11 @@ public class ABClientServiceProxy implements ABClientService {
return abClientService.recordAndSendABClientMsgShuangYing(dtos);
}
@Override
public boolean recordAndSendABClientMsgYH(List<ABMessageDTO> dtos) {
return abClientService.recordAndSendABClientMsgYH(dtos);
}
/**
* fixme 使
* @param dto
@ -158,6 +164,11 @@ public class ABClientServiceProxy implements ABClientService {
return abClientService.recordFudaojunClientMsg(dto);
}
@Override
public boolean saveXmj(ABClientXMJMessageVO vo) {
return abClientService.saveXmj(vo);
}
/**
*
* @param base64Value

@ -30,6 +30,9 @@ public class ABMessageServiceImpl implements ABMessageService {
@Autowired
private ShuangYingMessageRepository shuangYingMessageRepository;
@Autowired
private YHMessageRepository yhMessageRepository;
@Autowired
private ShijiMessageRepository shijiMessageRepository;
@Autowired
@ -41,6 +44,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) {
@ -125,6 +131,21 @@ public class ABMessageServiceImpl implements ABMessageService {
return Boolean.TRUE;
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateSendYHSatus(Long recId, boolean sucess) {
if (recId == null) {
return Boolean.FALSE;
}
if (sucess) {
yhMessageRepository.updateSendStatus(1, recId);
}else {
yhMessageRepository.updateSendStatus(0, recId);
}
return Boolean.TRUE;
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateSendShuangYingSatus(Long recId, boolean sucess) {
@ -177,4 +198,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,6 +30,7 @@ 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.stream.Collectors;
@ -143,6 +147,27 @@ public class ABDownTask {
@Value("${ab.sy.secretKey}")
private String shuangyingSecretKey;
@Value("${ab.xmj.appId}")
private String xmjAppid;
@Value("${ab.xmj.url}")
private String xmjUrl;
@Value("${ab.xmj.secretKey}")
private String xmjSecret;
@Value("${ab.yh.appId}")
private String yhAppid;
@Value("${ab.yh.url}")
private String yhUrl;
@Value("${ab.yh.secretKey}")
private String yhSecret;
/**
* ,
*
@ -381,7 +406,97 @@ public class ABDownTask {
}
collect.forEach(
// FIXME: 2020/8/12 0012 可能会造成更新失败,检查更新语句
each -> abMessageService.updateSendHeXXSatus(Long.valueOf(each.getRecId()), Boolean.TRUE)
each -> abMessageService.updateSendShuangYingSatus(Long.valueOf(each.getRecId()), Boolean.TRUE)
);
return Boolean.TRUE;
}
/**
* ,
*
*/
@Async(value = "abTaskExecutor")
public void doRunYHTask(List<ABMessageDTO> messageDTOList){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "doRunYHTask");
runYHTask(messageDTOList);
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "doRunYHTask", (endMilliSecond-satrtMilliSecond));
}
/**
*
*
* @return
*/
private boolean runYHTask(List<ABMessageDTO> messageDTOList){
int count = 0; // 设置请求失败计数
// 数据实体进行映射转换 - 目前是只有一条给
YHMessageCovDTO yhMessageCovDTO = new YHMessageCovDTO();
// 对特殊情况进行过滤,只要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<YHMessageCovDTO.YHData> data = new ArrayList<>();
// 进行转换
collect.forEach(
each->{
YHMessageCovDTO.YHData yhData = new YHMessageCovDTO.YHData();
// BeanUtils.copyProperties(each, luoshiData);
yhData.setInfo(each.getMobile());
yhData.setType(1);
yhData.setTime(each.getStartTime());
yhData.setActName(Base64.encode(each.getActName()));
data.add(yhData);
}
);
// 进行设置
if (!CollectionUtils.isEmpty(data)){
yhMessageCovDTO.setData(data);
}
// 补充其他的下游请求字段
long time = System.currentTimeMillis() / 1000;
yhMessageCovDTO.setTimestamp(time);
yhMessageCovDTO.setAppId(yhAppid);
yhMessageCovDTO.setSignature(SecureUtil.sha1("app_id="+ yhAppid +"&timestamp="+ time + "&secret=" + yhSecret));
// 数据实体转成Json 不忽略空kv 有序
String jsonStr = JSON.toJSONString(yhMessageCovDTO);
log.info("========== [ready send json is {} ] =============", jsonStr);
// 请求的响应处理
// todo 失败重发请求3次
while (count <= 3){
// 调用HTTP请求发送数据
HttpResponse httpResponse = sendYHReq(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.updateSendYHSatus(Long.valueOf(each.getRecId()), Boolean.TRUE)
);
return Boolean.TRUE;
}
@ -740,6 +855,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());
});
}
/**
* , -
@ -944,6 +1108,21 @@ public class ABDownTask {
return httpResponse;
}
/**
* HTTP
*
* @param json body
* @return
*/
private HttpResponse sendYHReq(String json){
HttpResponse httpResponse = HttpRequest
.post(yhUrl)
.body(json)
.execute();
return httpResponse;
}
/**
* HTTP

@ -1,6 +1,6 @@
spring:
profiles:
active: dev
active: stg
# 序列化忽略null的k-v配置
jackson:
default-property-inclusion: non_null
@ -19,18 +19,22 @@ 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://localhost:3306/push?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
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
thread_pool:
corePoolSize: 2
maxPoolSize: 16
queueCapacity: 3
corePoolSize: 4
maxPoolSize: 32
queueCapacity: 100
ThreadNamePrefix: "AB-Req-"
liehe:
appID: 29cb2b84cf2bb0
@ -64,6 +68,11 @@ ab:
appId: by_sy
url: http://linkon.natapp4.cc/sales/openClientController/addClientList
secretKey: 8b74dc958fe1196ebc77208b
yh:
appId: Q1
url: http://www.huameiou.com:18877/api/users/receiveinfo
secretKey: 3F0716E9EA9246D0A9C5B2BA1B3ADB4E
---
# 端口
server:
@ -74,7 +83,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://localhost:3306/push?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
password: Yuyou@2020
# 下游请求配置信息
@ -83,9 +92,9 @@ ab:
url: https://openapi.ppke.com.cn/openapi/tmk/valid/receive
app_id: YY9X8XCZ
thread_pool:
corePoolSize: 2
maxPoolSize: 16
queueCapacity: 3
corePoolSize: 4
maxPoolSize: 32
queueCapacity: 100
ThreadNamePrefix: "AB-Req-"
liehe:
appID: 29cb2b84cf2bb0
@ -115,10 +124,18 @@ 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
sy:
appId: by_sy
url: http://47.110.153.34/openClientController/addClientList
secretKey: 8b74dc958fe1196ebc77208b
yh:
appId: Q1
url: http://www.huameiou.com:18877/api/users/receiveinfo
secretKey: 3F0716E9EA9246D0A9C5B2BA1B3ADB4E
logging:
config: classpath:logback.xml
---
@ -131,7 +148,7 @@ spring:
# 数据库相关配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.99.218.9: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&rewriteBatchedStatements=true
username: root
password: Yuyou@2020
# 下游请求配置信息
@ -140,9 +157,9 @@ ab:
url: https://sandbox.openapi.ppke.com.cn/openapi/tmk/valid/receive
app_id: YY9X8XCZ
thread_pool:
corePoolSize: 2
maxPoolSize: 16
queueCapacity: 3
corePoolSize: 4
maxPoolSize: 32
queueCapacity: 100
ThreadNamePrefix: "AB-Req-"
liehe:
appID: 29cb2b84cf2bb0
@ -176,5 +193,13 @@ ab:
appId: by_sy
url: http://47.110.153.34/openClientController/addClientList
secretKey: 8b74dc958fe1196ebc77208b
xmj:
appId: R1JaQKdh
url: http://tt.api.jikefx.cn/xmj/api/record_import
secretKey: 9I7Mlbqcy8JXPKExDH3A6zZCjps0rGWf
yh:
appId: Q1
url: http://www.huameiou.com:18877/api/users/receiveinfo
secretKey: 3F0716E9EA9246D0A9C5B2BA1B3ADB4E
#logging:
# config: classpath:logback.xml

@ -1,16 +1,174 @@
package com.yuyou.openapi.openapi;
import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import com.yuyou.openapi.openapi.dao.PhonesRepository;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import java.nio.charset.Charset;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
/**
* SpringBoot
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class OpenapiApplicationTest {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
*
*/
@Test
public void testBatchInsert1(){
@Data
class Regions{
private String id;
private String province;
private String city;
private String zip_code;
private String area_code;
}
String sql = "INSERT INTO `tb_regions` (id,province,city,zip_code,area_code) VALUES (?, ?, ?, ?, ?)";
List<String> list = FileUtil.readLines("D:\\apk整理\\Phone-Number-Range-master\\phone2.sql", Charset.defaultCharset());
List<Regions> reList = Lists.newArrayList();
list.forEach(
each->{
String left = StringUtils.substringAfter(each, "(");
String right = StringUtils.substringBefore(left, ")");
String s = right.replaceAll("\'", "");
String[] split = s.split(",");
if (split.length == 5){
Regions regions = new Regions();
regions.setId(split[0]);
regions.setProvince(split[1]);
regions.setCity(split[2]);
regions.setZip_code(split[3]);
regions.setArea_code(split[4]);
reList.add(regions);
}
}
);
int[] ints = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
preparedStatement.setInt(1,Integer.valueOf(reList.get(i).getId()));
preparedStatement.setString(2,reList.get(i).getProvince());
preparedStatement.setString(3,reList.get(i).getCity());
preparedStatement.setString(4,reList.get(i).getZip_code());
preparedStatement.setString(5,reList.get(i).getArea_code());
}
@Override
public int getBatchSize() {
return reList.size();
}
});
log.info("受影响的行数为: {}", ints.length);
}
/**
*
*/
@Test
public void testBatchInsert2(){
// String sql = FileUtil.readString("D:\\apk整理\\Phone-Number-Range-master\\phone2.sql", Charset.defaultCharset());
@Data
class Phones{
private String id;
private String number;
private String type;
private String region_id;
}
String sql = "INSERT INTO `tb_phones` (id,number,type,region_id)VALUES (?, ?, ?, ?)";
List<String> list = FileUtil.readLines("D:\\apk整理\\Phone-Number-Range-master\\phones1.sql", Charset.defaultCharset());
List<Phones> reList = Lists.newArrayList();
list.forEach(
each->{
String left = StringUtils.substringAfter(each, "(");
String right = StringUtils.substringBefore(left, ")");
String s = right.replaceAll("\'", "");
String[] split = s.split(",");
if (split.length == 4){
Phones phones = new Phones();
phones.setId(split[0]);
phones.setNumber(split[1]);
phones.setType(split[2]);
phones.setRegion_id(split[3]);
reList.add(phones);
}
}
);
int[] ints = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
preparedStatement.setInt(1,Integer.valueOf(reList.get(i).getId().trim()));
preparedStatement.setInt(2,Integer.valueOf(reList.get(i).getNumber().trim()));
preparedStatement.setInt(3,Integer.valueOf(reList.get(i).getType().trim()));
preparedStatement.setInt(4,Integer.valueOf(reList.get(i).getRegion_id().trim()));
}
@Override
public int getBatchSize() {
return reList.size();
}
});
log.info("受影响的行数为: {}", ints.length);
}
@Autowired
private PhonesRepository phonesRepository;
/**
*
*/
@Test
public void testMatchArea(){
String phone = "18958049294";
if (phone.length() == 11 ){
String substring = StringUtils.substring(phone, 0, phone.length() - 4);
System.out.println(phonesRepository.findByNumber(substring)); // 1300018
}
}
}

@ -2,8 +2,10 @@ package com.yuyou.openapi.openapi;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.yuyou.openapi.openapi.api.enums.LuoShiAppIDEnum;
import com.yuyou.openapi.openapi.consts.SpecialCityConst;
import com.yuyou.openapi.openapi.model.pojo.ResultBean;
import com.yuyou.openapi.openapi.model.pojo.YiZaoLocalDTO;
import org.apache.commons.lang3.StringUtils;
@ -81,4 +83,19 @@ public class SimpleTest {
System.out.println(matchActName);
}
/**
*
*/
@Test
public void testMatchCity(){
for (int i = 0; i < 100; i++) {
System.out.println(SpecialCityConst.SPECIAL_RANDOM_CITYS[RandomUtil.randomInt(0, 42)]);
}
}
}

Loading…
Cancel
Save