Merge remote-tracking branch 'origin/cc_20230520_partner' into cc_20230520_partner
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.cool.store.http;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserSourceResponse {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private List<ChannelSource> data;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class ChannelSource{
|
||||
private String createTime;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer userId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.cool.store.job;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.cool.store.entity.SyncEcCustomerDO;
|
||||
import com.cool.store.mapper.HyPartnerLineInfoMapper;
|
||||
import com.cool.store.mapper.HyPartnerUserInfoMapper;
|
||||
import com.cool.store.sdk.ec.EcClient;
|
||||
import com.cool.store.sdk.ec.request.SyncEcCustomerRequest;
|
||||
import com.cool.store.service.EcSyncService;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EcSyncDataJob {
|
||||
|
||||
@XxlJob("SyncUserSourceJob")
|
||||
public void syncUserSourceJob() {
|
||||
XxlJobHelper.log("-------------------------------定时同步客户来源开始-------------------------------");
|
||||
syncUserSourceExecute();
|
||||
XxlJobHelper.log("-------------------------------定时同步客户来源结束-------------------------------");
|
||||
XxlJobHelper.handleSuccess();
|
||||
}
|
||||
|
||||
|
||||
@Value("${ec.baseUrl}")
|
||||
private String baseUrl;
|
||||
|
||||
@XxlJob("SyncAppletToEcJob")
|
||||
public void syncAppletToEcJob() {
|
||||
XxlJobHelper.log("-------------------------------定时同步小程序数据到ec开始-------------------------------");
|
||||
syncAppletToEcExecute();
|
||||
XxlJobHelper.log("-------------------------------定时同步小程序数据到ec结束-------------------------------");
|
||||
XxlJobHelper.handleSuccess();
|
||||
}
|
||||
|
||||
@Resource
|
||||
private EcSyncService ecSyncService;
|
||||
|
||||
@Resource
|
||||
private HyPartnerUserInfoMapper hyPartnerUserInfoMapper;
|
||||
|
||||
|
||||
//定时同步用户来源开始
|
||||
private void syncUserSourceExecute() {
|
||||
ecSyncService.getChannelSource();
|
||||
}
|
||||
|
||||
private final Integer count=50;
|
||||
|
||||
//定时同步小程序数据到ec
|
||||
private void syncAppletToEcExecute() {
|
||||
//获取总数
|
||||
int size = hyPartnerUserInfoMapper.selectByHourDateCount(getHourDayDate(-5, 0), DateUtil.now());
|
||||
//执行数
|
||||
int counts = size / count;
|
||||
//取余,如果大于1,就再加一
|
||||
int yu = size % count;
|
||||
if (yu > 0) {
|
||||
counts += 1;
|
||||
}
|
||||
for (int i = 1; i <= counts; i++) {
|
||||
List<SyncEcCustomerDO> list = hyPartnerUserInfoMapper.selectByHourDate(getHourDayDate(-5, 0), DateUtil.now(),count * (i - 1),count);
|
||||
SyncEcCustomerRequest syncEcCustomerRequest = new SyncEcCustomerRequest();
|
||||
syncEcCustomerRequest.setParameter(list);
|
||||
EcClient ecClient = new EcClient();
|
||||
ecClient.exec(baseUrl,syncEcCustomerRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String getHourDayDate(int hour, int day) {
|
||||
Date today = new Date();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(today);
|
||||
calendar.add(Calendar.HOUR, hour);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, day);
|
||||
Date twoDay = calendar.getTime();
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(twoDay);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.sdk.ec;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cool.store.sdk.ec.core.EcRequest;
|
||||
import com.cool.store.sdk.ec.core.EcResponse;
|
||||
import com.cool.store.utils.Get;
|
||||
import com.cool.store.utils.MapUtil;
|
||||
import com.cool.store.utils.Post;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EcClient {
|
||||
|
||||
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public <T extends EcResponse> T exec(String baseUrl,EcRequest<T> request) {
|
||||
String apiUrl = request.getApiUrl();
|
||||
// if (accessToken != null) {
|
||||
// apiUrl += "?token=" + accessToken;
|
||||
// }
|
||||
String method = request.getMethod();
|
||||
String result = "";
|
||||
if (method.equals("GET")) {
|
||||
result = Get.send(baseUrl+apiUrl, MapUtil.entityToUrlParam(request.getParameter()));
|
||||
} else {
|
||||
HashMap<String,String> headers = new HashMap<>(1);
|
||||
headers.put("Content-Type", "application/json");
|
||||
result = Post.send(baseUrl+apiUrl, JSON.toJSONString(request.getParameter()), headers);
|
||||
}
|
||||
|
||||
return JSON.parseObject(result, request.getResponseClass());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.cool.store.sdk.ec.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChangeFollowUserBo {
|
||||
|
||||
//跟进人
|
||||
private Long crmId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private Long followUserId;
|
||||
|
||||
//1:更新跟进人 2:创建跟进人并更改跟进人
|
||||
private Integer type;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.cool.store.sdk.ec.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SyncEcCustomerBo {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cool.store.sdk.ec.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UpdateCustomerBo {
|
||||
|
||||
private String username;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private Long crmId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.cool.store.sdk.ec.core;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
abstract public class EcRequest <T extends EcResponse> implements EcRequestI<T> {
|
||||
|
||||
private Object parameter;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return "POST";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
public void setParameter(Object parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getResponseClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.cool.store.sdk.ec.core;
|
||||
|
||||
public interface EcRequestI<T extends EcResponse> {
|
||||
|
||||
/**
|
||||
* 地址
|
||||
* @return -
|
||||
*/
|
||||
String getApiUrl();
|
||||
|
||||
/**
|
||||
* 方法
|
||||
* @return -
|
||||
*/
|
||||
String getMethod();
|
||||
|
||||
/**
|
||||
* 设置参数
|
||||
* @return -
|
||||
*/
|
||||
Object getParameter();
|
||||
|
||||
/**
|
||||
* 响应类类型
|
||||
* @return -
|
||||
*/
|
||||
Class<T> getResponseClass();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.cool.store.sdk.ec.core;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EcResponse {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.cool.store.sdk.ec.request;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcRequest;
|
||||
import com.cool.store.sdk.ec.response.ChangeFollowUserResponse;
|
||||
|
||||
public class ChangeFollowUserRequest extends EcRequest<ChangeFollowUserResponse> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getApiUrl() {
|
||||
return "/ec/selectChangeUser";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChangeFollowUserResponse> getResponseClass() {
|
||||
return ChangeFollowUserResponse.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.cool.store.sdk.ec.request;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcRequest;
|
||||
import com.cool.store.sdk.ec.response.SyncEcCustomerResponse;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SyncEcCustomerRequest extends EcRequest<SyncEcCustomerResponse> {
|
||||
|
||||
@Override
|
||||
public String getApiUrl() {
|
||||
return "/ec/appletToEc";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<SyncEcCustomerResponse> getResponseClass() {
|
||||
return SyncEcCustomerResponse.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.cool.store.sdk.ec.request;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcRequest;
|
||||
import com.cool.store.sdk.ec.response.UpdateCustomerResponse;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UpdateCustomerRequest extends EcRequest<UpdateCustomerResponse> {
|
||||
|
||||
@Override
|
||||
public String getApiUrl() {
|
||||
return "/ec/updateCustomer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<UpdateCustomerResponse> getResponseClass() {
|
||||
return UpdateCustomerResponse.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.cool.store.sdk.ec.response;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcResponse;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ChangeFollowUserResponse extends EcResponse {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cool.store.sdk.ec.response;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcResponse;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SyncEcCustomerResponse extends EcResponse {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cool.store.sdk.ec.response;
|
||||
|
||||
import com.cool.store.sdk.ec.core.EcResponse;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UpdateCustomerResponse extends EcResponse {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.request.CustomerInfoRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EcSyncService {
|
||||
boolean ecToApplet(List<CustomerInfoRequest> queryListData);
|
||||
|
||||
void getChannelSource();
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.HyPartnerBaseInfoDAO;
|
||||
import com.cool.store.dao.HyPartnerLineInfoDAO;
|
||||
import com.cool.store.dao.HyPartnerUserInfoDAO;
|
||||
import com.cool.store.entity.*;
|
||||
import com.cool.store.enums.LineStatusEnum;
|
||||
import com.cool.store.enums.WorkflowStageEnum;
|
||||
import com.cool.store.enums.WorkflowStatusEnum;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.http.UserSourceResponse;
|
||||
import com.cool.store.mapper.HyPartnerUserChannelMapper;
|
||||
import com.cool.store.request.CustomerInfoRequest;
|
||||
import com.cool.store.sdk.ec.EcClient;
|
||||
import com.cool.store.sdk.ec.bo.ChangeFollowUserBo;
|
||||
import com.cool.store.sdk.ec.bo.UpdateCustomerBo;
|
||||
import com.cool.store.sdk.ec.request.ChangeFollowUserRequest;
|
||||
import com.cool.store.sdk.ec.request.UpdateCustomerRequest;
|
||||
import com.cool.store.sdk.ec.response.ChangeFollowUserResponse;
|
||||
import com.cool.store.sdk.ec.response.UpdateCustomerResponse;
|
||||
import com.cool.store.service.EcSyncService;
|
||||
import com.cool.store.utils.Post;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EcSyncServiceImpl implements EcSyncService {
|
||||
|
||||
|
||||
|
||||
@Value("${ec.baseUrl}")
|
||||
private String baseUrl;
|
||||
|
||||
@Resource
|
||||
private HyPartnerLineInfoDAO hyPartnerLineInfoDAO;
|
||||
|
||||
@Resource
|
||||
private HyPartnerBaseInfoDAO hyPartnerBaseInfoDAO;
|
||||
|
||||
@Resource
|
||||
private HyPartnerUserInfoDAO hyPartnerUserInfoDAO;
|
||||
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
|
||||
|
||||
@Resource
|
||||
private HyPartnerUserChannelMapper hyPartnerUserChannelMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean ecToApplet(List<CustomerInfoRequest> queryListData) {
|
||||
for (CustomerInfoRequest customerInfoItem : queryListData) {
|
||||
try {
|
||||
Thread.sleep(500L);
|
||||
insertSelectiveSync(customerInfoItem);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendFeiShuRobotMessage("推送:"+JSONObject.toJSONString(e),"27243d49-97ca-4981-8aec-7c3bf84eb660");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getChannelSource() {
|
||||
String s = HttpUtil.get(baseUrl+"/ec/getChannelSource");
|
||||
UserSourceResponse userSourceResponse = JSONObject.parseObject(s, UserSourceResponse.class);
|
||||
for (UserSourceResponse.ChannelSource channelSource : userSourceResponse.getData()) {
|
||||
Long id = channelSource.getId();
|
||||
HyPartnerUserChannelDO selectByChannel = hyPartnerUserChannelMapper.selectByChannelId(id);
|
||||
HyPartnerUserChannelDO hyPartnerUserChannel = new HyPartnerUserChannelDO();
|
||||
hyPartnerUserChannel.setChannelId(channelSource.getId()).setChannelName(channelSource.getName());
|
||||
//有就更新 没有插入
|
||||
if (ObjectUtil.isNotNull(selectByChannel)) {
|
||||
hyPartnerUserChannel.setUpdateTime(new Date()).setId(selectByChannel.getId());
|
||||
hyPartnerUserChannelMapper.updateByPrimaryKeySelective(hyPartnerUserChannel);
|
||||
}else {
|
||||
hyPartnerUserChannel.setCreateTime(new Date());
|
||||
hyPartnerUserChannelMapper.insertSelective(hyPartnerUserChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步ec数据到表中 同时将部分数据同步到ec
|
||||
*
|
||||
* @param customerInfoItem
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertSelectiveSync(CustomerInfoRequest customerInfoItem) throws ApiException {
|
||||
if (StringUtil.isNotEmpty(customerInfoItem.getMobile())) {
|
||||
customerInfoItem.setMobile(customerInfoItem.getMobile().split(" ")[1]);
|
||||
}
|
||||
//获取客户来源id
|
||||
String channel = customerInfoItem.getChannel();
|
||||
HyPartnerUserChannelDO hyPartnerUserChannelDO = hyPartnerUserChannelMapper.selectByChannelName(channel);
|
||||
Long channelId =null;
|
||||
if (StringUtil.isNotEmpty(channel)) {
|
||||
if (ObjectUtil.isNull(hyPartnerUserChannelDO)||ObjectUtil.isNull(hyPartnerUserChannelDO.getId())) {
|
||||
getChannelSource();
|
||||
HyPartnerUserChannelDO channelDO = hyPartnerUserChannelMapper.selectByChannelName(channel);
|
||||
channelId=channelDO.getId();
|
||||
}else {
|
||||
HyPartnerUserChannelDO channelDO = hyPartnerUserChannelMapper.selectByChannelName(channel);
|
||||
channelId=channelDO.getId();
|
||||
}
|
||||
}
|
||||
String newPartnerId = UUIDUtils.get32UUID();
|
||||
HyPartnerUserInfoDO resultUser = new HyPartnerUserInfoDO();
|
||||
resultUser.setUsername(customerInfoItem.getName()).setMobile(customerInfoItem.getMobile());
|
||||
|
||||
HyPartnerLineInfoDO resultLine = new HyPartnerLineInfoDO();
|
||||
String followUserName = customerInfoItem.getFollowUserName();
|
||||
String followUserMobile = customerInfoItem.getFollowUserMobile();
|
||||
//传递过来有跟进人的情况下查询跟进人是否存在
|
||||
if (StringUtil.isNotEmpty(followUserMobile)&&StringUtil.isNotEmpty(followUserMobile)) {
|
||||
String userId = enterpriseUserDAO.selectByMobile("+86"+followUserMobile);
|
||||
if (StringUtil.isEmpty(userId)) {
|
||||
// 给飞书群发送消息 跟进人找不到
|
||||
sendFeiShuRobotMessage("推送:飞书架构中找不到该用户:【" + followUserName + "】,该用户电话号码为:" + followUserMobile,"27243d49-97ca-4981-8aec-7c3bf84eb660");
|
||||
throw new ApiException("飞书架构中找不到该用户:【" + followUserName + "】,该用户电话号码为:" + followUserMobile);
|
||||
}
|
||||
resultLine.setInvestmentManager(userId);
|
||||
}
|
||||
resultLine.setWorkflowStage(WorkflowStageEnum.INTENT.getCode()).setUserChannelId(Convert.toInt(channelId))
|
||||
.setLineStatus(StringUtil.isEmpty(customerInfoItem.getFollowUserName()) ? LineStatusEnum.PUBLIC_SEAS.getCode() : LineStatusEnum.PRIVATE_SEAS.getCode());
|
||||
|
||||
HyPartnerBaseInfoDO resultBase = new HyPartnerBaseInfoDO();
|
||||
resultBase.setUsername(customerInfoItem.getName()).setMobile(customerInfoItem.getMobile());
|
||||
|
||||
HyPartnerUserInfoDO newUserInfo = hyPartnerUserInfoDAO.selectByMobile(resultUser.getMobile());
|
||||
EcClient ecClient=new EcClient();
|
||||
//有就更新ec没有就插入
|
||||
if (newUserInfo != null) {
|
||||
// EC与沪姨合伙人同时存在的线索用户,但用户姓名不同,将沪姨合伙人线索姓名同步至EC覆盖原EC线索姓名
|
||||
if (!newUserInfo.getUsername().equals(resultUser.getUsername())) {
|
||||
UpdateCustomerRequest updateUserRequest=new UpdateCustomerRequest();
|
||||
UpdateCustomerBo updateCustomerBo = new UpdateCustomerBo();
|
||||
updateCustomerBo.setUsername(newUserInfo.getUsername()).setMobile(newUserInfo.getMobile()).setCrmId(customerInfoItem.getCrmId());
|
||||
updateUserRequest.setParameter(updateCustomerBo);
|
||||
UpdateCustomerResponse updateUserExec = ecClient.exec(baseUrl,updateUserRequest);
|
||||
}
|
||||
String oldPartnerId = newUserInfo.getPartnerId();
|
||||
//线索表
|
||||
HyPartnerLineInfoDO partnerLine = hyPartnerLineInfoDAO.getByPartnerId(oldPartnerId);
|
||||
if (partnerLine != null) {
|
||||
// EC与沪姨合伙人同时存在的线索用户,但存在不同的跟进人,将沪姨合伙人跟进人信息同步至EC覆盖原EC跟进人信息
|
||||
if (StringUtil.isEmpty(partnerLine.getInvestmentManager())) {
|
||||
if (StringUtil.isNotEmpty(resultLine.getInvestmentManager())) {
|
||||
resultLine.setId(partnerLine.getId()).setUpdateTime(new Date());
|
||||
hyPartnerLineInfoDAO.updateByPrimaryKeySelective(resultLine);
|
||||
}
|
||||
}else {
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(partnerLine.getInvestmentManager());
|
||||
enterpriseUser.setMobile(getNoWith86Number(enterpriseUser.getMobile()));
|
||||
//电话相同但是名字不同
|
||||
if (enterpriseUser.getMobile().equals(followUserMobile) && !enterpriseUser.getName().equals(followUserName)) {
|
||||
ChangeFollowUserRequest changeFollowUserRequest = new ChangeFollowUserRequest();
|
||||
ChangeFollowUserBo changeFollowUserBo = new ChangeFollowUserBo();
|
||||
changeFollowUserBo.setFollowUserId(customerInfoItem.getLastFollowUserId()).setCrmId(customerInfoItem.getCrmId())
|
||||
.setType(1).setUsername(enterpriseUser.getName()).setMobile(enterpriseUser.getMobile());
|
||||
changeFollowUserRequest.setParameter(changeFollowUserBo);
|
||||
ChangeFollowUserResponse changeFollowUserExec = ecClient.exec(baseUrl,changeFollowUserRequest);
|
||||
}
|
||||
//电话不同
|
||||
if (!enterpriseUser.getMobile().equals(followUserMobile)) {
|
||||
ChangeFollowUserRequest changeFollowUserRequest = new ChangeFollowUserRequest();
|
||||
ChangeFollowUserBo changeFollowUserBo = new ChangeFollowUserBo();
|
||||
changeFollowUserBo.setFollowUserId(customerInfoItem.getLastFollowUserId()).setCrmId(customerInfoItem.getCrmId())
|
||||
.setType(2).setUsername(enterpriseUser.getName()).setMobile(enterpriseUser.getMobile());
|
||||
changeFollowUserRequest.setParameter(changeFollowUserBo);
|
||||
ChangeFollowUserResponse changeFollowUserExec = ecClient.exec(baseUrl,changeFollowUserRequest);
|
||||
}
|
||||
}
|
||||
//base表
|
||||
HyPartnerBaseInfoDO partnerIdAndLine = hyPartnerBaseInfoDAO.getByPartnerIdAndLineId(partnerLine.getPartnerId(), partnerLine.getId());
|
||||
if (partnerIdAndLine == null) {
|
||||
resultBase.setPartnerId(newPartnerId).setPartnerLineId(partnerLine.getId()).setStatus(Integer.valueOf(WorkflowStatusEnum.INTENT_0.getCode())).
|
||||
setCreateTime(new Date());
|
||||
hyPartnerBaseInfoDAO.insertSelective(resultBase);
|
||||
}
|
||||
} else {
|
||||
resultLine.setPartnerId(newPartnerId).setCreateTime(new Date());
|
||||
hyPartnerLineInfoDAO.insertSelective(resultLine);
|
||||
|
||||
resultBase.setPartnerId(newPartnerId).setPartnerLineId(resultLine.getId()).setStatus(Integer.valueOf(WorkflowStatusEnum.INTENT_0.getCode())).
|
||||
setCreateTime(new Date());
|
||||
hyPartnerBaseInfoDAO.insertSelective(resultBase);
|
||||
}
|
||||
} else {
|
||||
resultUser.setPartnerId(newPartnerId).setCreateTime(new Date());
|
||||
hyPartnerUserInfoDAO.insertSelective(resultUser);
|
||||
|
||||
resultLine.setPartnerId(newPartnerId).setCreateTime(new Date());
|
||||
hyPartnerLineInfoDAO.insertSelective(resultLine);
|
||||
|
||||
resultBase.setPartnerId(newPartnerId).setPartnerLineId(resultLine.getId()).setStatus(Integer.valueOf(WorkflowStatusEnum.INTENT_0.getCode())).
|
||||
setCreateTime(new Date());
|
||||
hyPartnerBaseInfoDAO.insertSelective(resultBase);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到不带86开头的号码
|
||||
*
|
||||
* @param number
|
||||
* @return
|
||||
*/
|
||||
public static String getNoWith86Number(String number) {
|
||||
String regular = number;
|
||||
if (StringUtils.isNotBlank(regular)) {
|
||||
// 去掉+号
|
||||
while (regular.startsWith("+")) {
|
||||
regular = regular.substring(1);
|
||||
}
|
||||
// 号码以0开始,去掉前缀
|
||||
while (regular.startsWith("0")) {
|
||||
regular = regular.substring(1);
|
||||
}
|
||||
// 号码以86开始,去掉前缀
|
||||
while (regular.startsWith("86")) {
|
||||
regular = regular.substring(2);
|
||||
}
|
||||
// 号码以0开始,去掉前缀
|
||||
while (regular.startsWith("0")) {
|
||||
regular = regular.substring(1);
|
||||
}
|
||||
}
|
||||
return regular;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送飞书机器人
|
||||
*
|
||||
* @param text
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public String sendFeiShuRobotMessage(String text, String token) {
|
||||
HashMap<String, Object> map = new HashMap<>(4);
|
||||
HashMap<String, String> textMap = new HashMap<String, String>(4);
|
||||
textMap.put("text", text);
|
||||
map.put("content", textMap);
|
||||
map.put("msg_type", "text");
|
||||
String body = JSON.toJSONString(map);
|
||||
String send = "";
|
||||
try {
|
||||
send = Post.send("https://open.feishu.cn/open-apis/bot/v2/hook/" + token, body, new HashMap<String, String>(4) {{
|
||||
put("Content-Type", "application/json");
|
||||
}});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return send;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -569,8 +569,14 @@ public class HyPartnerLineInfoServiceImpl implements HyPartnerLineInfoService {
|
||||
}
|
||||
//省内调剂 有重点或者开放的 分配
|
||||
if (AcceptAdjustTypeEnum.PROVINCIAL_ADJUSTMENT.getCode().equals(acceptAdjustType)){
|
||||
Integer apply = hyOpenAreaInfoDAO.getChildrenCount("apply", hyOpenAreaInfoDO.getId());
|
||||
if (apply>CommonConstants.ZERO){
|
||||
|
||||
List<HyOpenAreaInfoDO> hyOpenAreaInfoDOList= new ArrayList<>();
|
||||
if(hyOpenAreaInfoDO != null){
|
||||
String areaPath = hyOpenAreaInfoDO.getAreaPath();
|
||||
String province = areaPath.substring(0, areaPath.indexOf("/", areaPath.indexOf("/") + 1));
|
||||
hyOpenAreaInfoDOList = hyOpenAreaInfoDAO.queryByKeyword(province, true, null, true);
|
||||
}
|
||||
if (hyOpenAreaInfoDOList.size()>CommonConstants.ZERO){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
@@ -633,18 +639,23 @@ public class HyPartnerLineInfoServiceImpl implements HyPartnerLineInfoService {
|
||||
public HyPartnerLineInfoDO generateDefaultLineInfo(String partnerId, String wantShopArea, Integer acceptAdjustType) {
|
||||
// 生成一条线索
|
||||
HyPartnerLineInfoDO hyPartnerLineInfoDO = hyPartnerLineInfoDAO.getByPartnerId(partnerId);
|
||||
Boolean flag = this.assignFollowUser(partnerId, wantShopArea, acceptAdjustType);
|
||||
String investmentManager = null;
|
||||
if (flag){
|
||||
investmentManager = getAssignFollowUser(partnerId, "intent");
|
||||
}
|
||||
if(hyPartnerLineInfoDO == null){
|
||||
hyPartnerLineInfoDO = new HyPartnerLineInfoDO();
|
||||
hyPartnerLineInfoDO.setPartnerId(partnerId);
|
||||
hyPartnerLineInfoDO.setWorkflowStage(WorkflowStageEnum.INTENT.getCode());
|
||||
hyPartnerLineInfoDO.setWorkflowStatus(WorkflowStatusEnum.INTENT_0.getCode());
|
||||
Boolean flag = this.assignFollowUser(hyPartnerLineInfoDO.getPartnerId(), wantShopArea, acceptAdjustType);
|
||||
hyPartnerLineInfoDO.setLineStatus(flag ? LineStatusEnum.PRIVATE_SEAS.getCode() : LineStatusEnum.PUBLIC_SEAS.getCode());
|
||||
if (flag){
|
||||
String investmentManager = getAssignFollowUser(partnerId, "intent");
|
||||
hyPartnerLineInfoDO.setInvestmentManager(investmentManager);
|
||||
}
|
||||
hyPartnerLineInfoDO.setInvestmentManager(investmentManager);
|
||||
hyPartnerLineInfoDAO.insertSelective(hyPartnerLineInfoDO);
|
||||
}else {
|
||||
hyPartnerLineInfoDO.setLineStatus(flag ? LineStatusEnum.PRIVATE_SEAS.getCode() : LineStatusEnum.PUBLIC_SEAS.getCode());
|
||||
hyPartnerLineInfoDO.setInvestmentManager(investmentManager);
|
||||
hyPartnerLineInfoDAO.updateByPrimaryKeySelective(hyPartnerLineInfoDO);
|
||||
}
|
||||
return hyPartnerLineInfoDO;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -42,13 +43,17 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
*/
|
||||
@Override
|
||||
public List<MDMAreaDO> getSonArea(String code) {
|
||||
String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_OTHERS);
|
||||
String provincesJson = redisUtilPool.getString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code));
|
||||
if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
}
|
||||
List<MDMAreaDO> areaDOList = mdmAreaMapper.getSonArea(code);
|
||||
//数据库也没有该数据就缓存空值,但是只缓存一分钟
|
||||
if (areaDOList == null || areaDOList.size() == 0) {
|
||||
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), "", 60);
|
||||
}
|
||||
//过期时间三小时
|
||||
redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
return areaDOList;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ public class PartnerUserInfoServiceImpl implements PartnerUserInfoService {
|
||||
if (CollectionUtils.isNotEmpty(hyOpenAreaInfoDOS)) {
|
||||
applyBaseInfoVO.setProvinceHasOpenArea(true);
|
||||
}
|
||||
applyBaseInfoVO.setPartnerLineId(hyPartnerLineInfoDO.getId());
|
||||
applyBaseInfoVO.setLineStatus(hyPartnerLineInfoDO.getLineStatus());
|
||||
String cacheKey = MessageFormat.format(RedisConstant.PARTNER_INTENTINFO_CACHE_KEY, partnerUserInfoRequest.getPartnerId(), hyPartnerLineInfoDO.getId());
|
||||
if (StringUtils.isNotBlank(redisUtilPool.getString(cacheKey))) {
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author leoxie
|
||||
*/
|
||||
public class Client {
|
||||
|
||||
private String url;
|
||||
private String method = "POST";
|
||||
private HashMap<String,String> header;
|
||||
private String data;
|
||||
private Integer timeout = 8000;
|
||||
private Integer maxLength = 10000;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Client.class);
|
||||
|
||||
public String exec() throws IOException {
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
OutputStreamWriter out = null;
|
||||
BufferedReader reader = null;
|
||||
StringBuilder res = null;
|
||||
String result = null;
|
||||
Long optTime = 0L;
|
||||
InputStream is = null;
|
||||
|
||||
LocalDateTime beginTime = LocalDateTime.now();
|
||||
|
||||
URL url = new URL(getUrl());
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
try {
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.setUseCaches(false);
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
|
||||
//设置超时时间
|
||||
connection.setConnectTimeout(getTimeout());
|
||||
connection.setReadTimeout(getTimeout());
|
||||
|
||||
// 设置请求方式
|
||||
connection.setRequestMethod(getMethod());
|
||||
// 设置发送数据的格式
|
||||
if (!getHeader().isEmpty()) {
|
||||
for (Map.Entry<String, String> entry : getHeader().entrySet()) {
|
||||
connection.setRequestProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
//发起连接
|
||||
connection.connect();
|
||||
|
||||
// utf-8编码[推送提交的参数]
|
||||
if (!getData().isEmpty()) {
|
||||
out = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
|
||||
out.append(getData());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
if(connection.getResponseCode() > 2000){
|
||||
is = connection.getErrorStream();
|
||||
}else{
|
||||
is = connection.getInputStream();
|
||||
}
|
||||
// 读取响应
|
||||
reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
String line;
|
||||
res = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
res.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
result = res.toString();
|
||||
return result;
|
||||
|
||||
}catch (Exception e){
|
||||
throw e;
|
||||
}finally {
|
||||
if (connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
if(out != null){
|
||||
out.close();
|
||||
}
|
||||
|
||||
if(reader != null){
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// log.info("request url is : " + getUrl());
|
||||
// log.info("request params is : " + getData());
|
||||
// if(result != null && result.length() < maxLength) {
|
||||
// log.info("response : " + result);
|
||||
// }
|
||||
// optTime = Duration.between(beginTime,LocalDateTime.now()).toMillis();
|
||||
// log.info("response time: " + optTime.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
assert !url.isEmpty();
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
assert !method.isEmpty();
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(HashMap<String, String> header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交参数
|
||||
*
|
||||
* 如果是json形式,那么就是json字符串,
|
||||
* 如果是表单形式,就是name1=value1&name2=value2 的形式
|
||||
* @param data
|
||||
*/
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author leoxie
|
||||
*/
|
||||
public class Get {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Get.class);
|
||||
|
||||
private static final Integer connectTimeout = 1000;
|
||||
private static final Integer timeout = 5000;
|
||||
|
||||
public static String send(String url, String param) throws IOException {
|
||||
return send(url,param,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定URL发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return URL 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String send(String url, String param,boolean hasLog) throws IOException {
|
||||
return send(url, param, hasLog, null);
|
||||
}
|
||||
|
||||
public static String send(String url, String param, boolean hasLog, HashMap<String,String> headers) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
try {
|
||||
String urlNameString = url + (param.isEmpty()?"":"?" + param);
|
||||
|
||||
log.info("url:"+url);
|
||||
log.info("param:"+param);
|
||||
|
||||
URL realUrl = new URL(urlNameString);
|
||||
// 打开和URL之间的连接
|
||||
connection = (HttpURLConnection)realUrl.openConnection();
|
||||
// 设置通用的请求属性
|
||||
connection.setRequestProperty("accept", "*/*");
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
|
||||
//添加头部信息
|
||||
if(headers != null && !headers.isEmpty()){
|
||||
for (Map.Entry<String,String> entry:headers.entrySet()) {
|
||||
connection.setRequestProperty(entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
connection.setConnectTimeout(connectTimeout);
|
||||
connection.setReadTimeout(timeout);
|
||||
// 建立实际的连接
|
||||
connection.connect();
|
||||
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> responseHeader = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
if(hasLog) {
|
||||
log.info("响应头");
|
||||
for (String key : responseHeader.keySet()) {
|
||||
log.info(key + "--->" + responseHeader.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
if(hasLog) {
|
||||
log.info("响应结果:" + result.toString());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
} finally {
|
||||
if (connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MapUtil {
|
||||
public static <T> void setMapValue(Map<String, Object> hashMap, String name, T value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
hashMap.put(name, value);
|
||||
}
|
||||
|
||||
public static <T> void setMapObjectValue(Map<String, Object> hashMap, T obj) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
String name = field.getName();
|
||||
String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
|
||||
Method m = obj.getClass().getMethod("get" + uName);
|
||||
Object value = m.invoke(obj);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
// 基础类型
|
||||
if (isBaseType(value)) {
|
||||
setMapValue(hashMap, name, value);
|
||||
} else if (value instanceof List) {
|
||||
if (((List) value).size() > 0) {
|
||||
setMapObjectValue(hashMap, ((List) value).get(0));
|
||||
}
|
||||
} else {
|
||||
setMapObjectValue(hashMap, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isBaseType(Object object) {
|
||||
Class className = object.getClass();
|
||||
return className.equals(Integer.class) ||
|
||||
className.equals(Byte.class) ||
|
||||
className.equals(Long.class) ||
|
||||
className.equals(Double.class) ||
|
||||
className.equals(Float.class) ||
|
||||
className.equals(Character.class) ||
|
||||
className.equals(Short.class) ||
|
||||
className.equals(Boolean.class) ||
|
||||
className.equals(String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体类对象转URL参
|
||||
* @param t 实体类对象
|
||||
* @param callSuper 是否转换父类成员
|
||||
* @param <T> 实体类泛型
|
||||
* @return a=1&b=2
|
||||
*/
|
||||
public static <T> String entityToUrlParam(T t, boolean callSuper){
|
||||
// URL 参数存储器
|
||||
StringBuffer urlParam = new StringBuffer();
|
||||
//扩展转换父类成员功能
|
||||
entitySuperclassToUrlParam(t, t.getClass(),callSuper,urlParam);
|
||||
if(urlParam.length()>0){
|
||||
//去除最后一个&字符
|
||||
urlParam.deleteCharAt(urlParam.length() - 1);
|
||||
}
|
||||
return urlParam.toString();
|
||||
}
|
||||
|
||||
public static <T> String entityToUrlParam(T t) {
|
||||
if (t == null) {
|
||||
return null;
|
||||
}
|
||||
return entityToUrlParam(t, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体类对象转URL参
|
||||
* @param t 实体类对象
|
||||
* @param clazz 实体类类型
|
||||
* @param callSuper 是否转换父类成员
|
||||
* @param urlParam URL 参数存储器
|
||||
* @param <T> 实体类泛型
|
||||
* @return a=1&b=2
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> void entitySuperclassToUrlParam(T t,Class clazz,boolean callSuper,StringBuffer urlParam){
|
||||
//如果实体类对象为Object类型,则不处理
|
||||
if(!clazz.equals(Object.class)) {
|
||||
//获取实体类对象下的所有成员,并保存到 URL 参数存储器中
|
||||
Arrays.stream(clazz.getDeclaredFields()).forEach(field -> {
|
||||
//设置可以操作私有成员
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
//获取成员值
|
||||
Object value = field.get(t);
|
||||
//成员值为 Null 时,则不处理
|
||||
if (Objects.nonNull(value)) {
|
||||
urlParam.append(field.getName()).append("=").append(value).append("&");
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
//是否转换父类成员
|
||||
if(callSuper){
|
||||
//获取父类类型
|
||||
clazz = clazz.getSuperclass();
|
||||
//递归调用,获取父类的处理结果
|
||||
entitySuperclassToUrlParam(t,clazz,callSuper,urlParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author leoxie
|
||||
*/
|
||||
public class Post {
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
* @param url 发送请求的 URL
|
||||
* @param data 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String send(String url, String data,HashMap<String,String> headers) throws IOException {
|
||||
Client client = new Client();
|
||||
client.setData(data);
|
||||
client.setUrl(url);
|
||||
|
||||
HashMap<String, String> headerMap = new HashMap<>(16);
|
||||
headerMap.put("Content-Type","application/x-www-form-urlencoded");
|
||||
|
||||
//添加头部信息
|
||||
if(!headers.isEmpty()){
|
||||
for (Map.Entry<String,String> entry:headers.entrySet()) {
|
||||
headerMap.put(entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
client.setHeader(headerMap);
|
||||
|
||||
return client.exec();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user