Commit 50f22636 authored by huagnxiner's avatar huagnxiner

添加发送给TFH的数据同步代码

parent e3dba202
......@@ -20,6 +20,7 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
......@@ -304,6 +305,59 @@ public class HttpClientUtil {
return null;
}
/**
* 发送application/json 格式数据
* @param url
* @param jsonParams
* @param charSet
* @return
*/
public static String doPostJson(String url,String jsonParams, String charSet) {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse = null;
long beginTime = System.currentTimeMillis();
try {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(jsonParams, "UTF-8"));
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String body = null;
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && httpEntity != null) {
if (StringUtils.isNotBlank(charSet)) {
body = EntityUtils.toString(httpEntity, charSet);
} else {
body = EntityUtils.toString(httpEntity, DEFAULT_ENCODING);
}
EntityUtils.consume(httpEntity);
}
logUrlInfo(beginTime, url);
return body;
} catch (Exception e) {
LOG.error(e.toString(), e);
} finally {
if (httpResponse != null) {
try {
httpResponse.close();
} catch (IOException e) {
LOG.error(e.toString(), e);
}
}
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
LOG.error(e.toString(), e);
}
}
}
return null;
}
public static String doPostChatset(
String url, List<NameValuePair> params, String postCharset, String responseCharset
) {
......
package com.house365.beans.entity;
import javax.validation.constraints.NotNull;
/**
* @author huang xiner
* @version 1.0
* @date 2021/9/18 12:21
*/
public class MessageDto {
/**
* 用户id
*/
@NotNull
private Integer userId;
/**
* accid
*/
private String accid;
/**
* 楼盘id
*/
private Integer listid;
/**
* 物业类型:1住宅 ,2写字楼, 3别墅 ,4商铺, 5公寓
*/
private Integer channel;
/**
* 姓名
*/
private String name;
/**
* 城市
*/
private String city;
/**
* 头像
*/
private String avatar;
/**
* 平台来源:1代理,2直卖 ,3房博士, 4城市客服 默认为2
*/
private Integer source;
/**
* 描述
*/
private String description;
/**
* 微信链接
*/
private String wechat_link;
/**
* 电话
*/
private String tel;
/**
* vr带看地址
*/
private String vr_daikan;
/**
* 操作
*/
private String operate;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getAccid() {
return accid;
}
public void setAccid(String accid) {
this.accid = accid;
}
public Integer getListid() {
return listid;
}
public void setListid(Integer listid) {
this.listid = listid;
}
public Integer getChannel() {
return channel;
}
public void setChannel(Integer channel) {
this.channel = channel;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public Integer getSource() {
return source;
}
public void setSource(Integer source) {
this.source = source;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getWechat_link() {
return wechat_link;
}
public void setWechat_link(String wechat_link) {
this.wechat_link = wechat_link;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getVr_daikan() {
return vr_daikan;
}
public void setVr_daikan(String vr_daikan) {
this.vr_daikan = vr_daikan;
}
public String getOperate() {
return operate;
}
public void setOperate(String operate) {
this.operate = operate;
}
@Override
public String toString() {
return "MessageDto{" +
"userId=" + userId +
", accid='" + accid + '\'' +
", listid=" + listid +
", channel=" + channel +
", name='" + name + '\'' +
", city='" + city + '\'' +
", avatar='" + avatar + '\'' +
", source=" + source +
", description='" + description + '\'' +
", wechat_link='" + wechat_link + '\'' +
", tel='" + tel + '\'' +
", vr_daikan='" + vr_daikan + '\'' +
", operate='" + operate + '\'' +
'}';
}
}
......@@ -32,7 +32,7 @@ import java.util.Date;
* @version 1.0, 2016-09-14
* @since 1.0
*/
public class UserEntity extends DomainObject {
public class UserEntity extends DomainObject implements Cloneable {
private static final long serialVersionUID = 1L;
......@@ -966,5 +966,9 @@ public class UserEntity extends DomainObject {
return new EqualsBuilder().append(getId(), other.getId()).isEquals();
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
......@@ -20,6 +20,7 @@ import com.house365.beans.entity.*;
import com.house365.beans.system.Page;
import com.house365.beans.vo.RoleVo;
import com.house365.beans.vo.UserVo;
import com.house365.commons.system.HttpClientUtil;
import com.house365.rest.exception.ServiceException;
import com.house365.rest.parameter.House365RestResponse;
import com.house365.web.system.controller.BaseController;
......@@ -28,6 +29,8 @@ import com.house365.ws.beans.request.*;
import com.house365.ws.beans.response.*;
import com.house365.ws.interfaces.server.*;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.DefaultValueProcessor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
......@@ -98,6 +101,8 @@ public class RoleController extends BaseController {
@Value("${twodimensional.code.url}")
private String twoDimensionalUrl;
@Value("${tlf.sendMessage.url}")
private String tlfSendMessageUrl;
/**
* 去新增角色
......@@ -593,6 +598,31 @@ public class RoleController extends BaseController {
cornetInParam.add(new BasicNameValuePair("avatar", entity.getHeadImgURL()));
String updateResult = HttpUtil.doPostWithHeader("http://yunxinim.house365.com/api/5b9235bea9f88", cornetInParam, accessToken, "");
logger.info("******SYNC_TO_CRM_RESULT*******" + updateResult);
//3.调用团立方接口,同步修改的数据到团立方
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.registerDefaultValueProcessor(Integer.class, new DefaultValueProcessor() {
@Override
public Object getDefaultValue(Class type) {
return null;
}});
jsonConfig.registerDefaultValueProcessor(String.class, new DefaultValueProcessor() {
@Override
public Object getDefaultValue(Class type) {
return null;
}
});
MessageDto mdto=new MessageDto();
mdto.setUserId(entity.getId());
mdto.setAccid(entity.getAccId());
mdto.setName(entity.getRealName());
mdto.setAvatar(entity.getHeadImgURL());
mdto.setTel(entity.getMobile());
String messObj = JSONObject.fromObject(mdto,jsonConfig).toString();
logger.info("******SYNC_TO_TRL*******" + messObj);
String res = HttpClientUtil.doPostJson(tlfSendMessageUrl, messObj, "");
logger.info("******SYNC_TO_TRL_RESULT*******" + res);
return "redirect:/role/edit/" + entity.getId();
} catch (Exception ex) {
addErrorMessage(model, ex.getMessage());
......
......@@ -8,6 +8,7 @@ import com.google.common.base.Strings;
import com.house365.beans.entity.*;
import com.house365.beans.system.Page;
import com.house365.beans.vo.UserVo;
import com.house365.commons.system.HttpClientUtil;
import com.house365.rest.exception.IllegalServiceParameterException;
import com.house365.rest.exception.ServiceException;
import com.house365.web.system.controller.BaseController;
......@@ -18,6 +19,8 @@ import com.house365.ws.beans.util.HResult;
import com.house365.ws.interfaces.server.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.DefaultValueProcessor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
......@@ -74,6 +77,9 @@ public class UserController extends BaseController {
@Value("${tlf.bandpeople.url}")
private String tlfBandPeopleUrl;
@Value("${tlf.sendMessage.url}")
private String tlfSendMessageUrl;
/**
* 去新增账户
*
......@@ -513,6 +519,7 @@ public class UserController extends BaseController {
UserEntity userEntity = (UserEntity) httpRequest.getSession().getAttribute(SessionConstants.THREAD_USER_KEY);
//获取更新前用户信息
UserEntity oldEntity = user.getById(entity.getId());
UserEntity tempOldEntity=(UserEntity)oldEntity.clone();
oldEntity.setUpdateUserid(entity.getId());
oldEntity.setUpdateUsername(entity.getName());
oldEntity.setUpdateTime(new Date());
......@@ -557,6 +564,30 @@ public class UserController extends BaseController {
logger.info("******SYNC_TO_CRM_RESULT*******" + updateResult);
}
}
//调用团立方接口,同步修改的数据团立方,修改手机号或者姓名才发送数据
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.registerDefaultValueProcessor(Integer.class, new DefaultValueProcessor() {
@Override
public Object getDefaultValue(Class type) {
return null;
}});
jsonConfig.registerDefaultValueProcessor(String.class, new DefaultValueProcessor() {
@Override
public Object getDefaultValue(Class type) {
return null;
}
});
if(!entity.getRealName().equals(tempOldEntity.getRealName())||entity.getMobile().equals(tempOldEntity.getMobile())) {
MessageDto mdto=new MessageDto();
mdto.setUserId(entity.getId());
mdto.setAccid(oldEntity.getAccId());
mdto.setName(entity.getRealName());
mdto.setTel(entity.getMobile());
String messObj = JSONObject.fromObject(mdto,jsonConfig).toString();
logger.info("******SYNC_TO_TRL*******" + messObj);
String res = HttpClientUtil.doPostJson(tlfSendMessageUrl, messObj, "");
logger.info("******SYNC_TO_TRL_RESULT*******" + res);
}
user.updateUserAndSyncToWechat(request);
redirectAttributes.addAttribute("message", "更新成功");
......
......@@ -77,6 +77,7 @@ CLOUD.PULL.URL = http://cdx2.prod.house365.com:8083/user/hgs/loginaccountinfo
tlf.bandpeople.url = http://mobitfadmin.house365.com/house365-taofanghui/bindPeople/userInfo
#一键呼二维码中包含的url
twodimensional.code.url = https://m.house365.com/Home/WxNews/dail?
#同步修改用户数据团立方url
tlf.sendMessage.url = http://mobitfadmin.house365.com/house365-taofanghui/sendMessage/sendData
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment