Commit b56080c8 by jx-art

清除邮箱配置

parent 7d15a12a
......@@ -379,32 +379,33 @@
</exclusions>
</dependency>
<!--qc -->
<dependency>
<groupId>com.netease.yanxuan</groupId>
<artifactId>yanxuan-qc-service-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.netease.yanxuan</groupId>
<artifactId>yanxuan-qc-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.netease.mail.yanxuan</groupId>
<artifactId>dschedule-boot-starter</artifactId>
<version>1.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.netease.mailsaas</groupId>
<artifactId>saas-kit-java-bundle</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.netease.yanxuan</groupId>-->
<!-- <artifactId>yanxuan-qc-service-client</artifactId>-->
<!-- <version>2.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.netease.yanxuan</groupId>-->
<!-- <artifactId>yanxuan-qc-parent</artifactId>-->
<!-- <version>2.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.netease.mail.yanxuan</groupId>-->
<!-- <artifactId>dschedule-boot-starter</artifactId>-->
<!-- <version>1.0.3-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.netease.mailsaas</groupId>-->
<!-- <artifactId>saas-kit-java-bundle</artifactId>-->
<!-- <version>0.1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.assertj</groupId>-->
<!-- <artifactId>assertj-core</artifactId>-->
<!-- <version>3.18.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.18.1</version>
</dependency>
</dependencies>
......
......@@ -12,7 +12,7 @@ import tk.mybatis.spring.annotation.MapperScan;
* 项目启动类
*/
@ComponentScan(basePackages = "com.netease.mail.yanxuan.change")
@ComponentScan(basePackages = "com.netease.mail.yanxuan.qc")
//@ComponentScan(basePackages = "com.netease.mail.yanxuan.qc")
@MapperScan("com.netease.mail.yanxuan.change.dal.mapper")
@EnableApolloConfig
@EnableMissaClients(basePackages = "com.netease.mail.yanxuan.change")
......
package com.netease.mail.yanxuan.change.integration.email.conig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.netease.mail.yanxuan.change.integration.email.enums.EmailType;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcStatusException;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcTimeoutException;
import com.netease.mail.yanxuan.change.integration.email.util.EncodeUtil;
import com.netease.mail.yanxuan.change.integration.email.util.HttpClientUtil;
import org.aspectj.weaver.Checker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* rpc 请求封装,在 HttpClientUtil 基础上加入了返回值处理和日志
*
* @author lwtang
* @date 2019-02-19
*/
@Component
public class RpcTemplate {
private Logger logger = LoggerFactory.getLogger(RpcTemplate.class);
@Value("${act.rpc.get.retry:1}")
private int rpcGetRetry;
@Value("${act.rpc.post.retry:0}")
private int rpcPostRetry;
public RpcTemplate() {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
}
private String convertParam(Object param) {
if (param instanceof String) {
return (String) param;
}
String reqParam = "";
if (param instanceof Map) {
reqParam = EncodeUtil.encodeMap((Map) param);
} else if (param != null) {
reqParam = JSON.toJSONString(param);
}
return reqParam;
}
private <T> T execute(String url, Object params, CallHandler<T> handler,
CallTemplate callTemplate, int retryTime, Method method) {
int tryTimes = 0;
RpcException rpcException = null;
String respBody = null;
int statusCode = 200;
while (tryTimes <= retryTime) {
long startTime = System.currentTimeMillis();
try {
respBody = callTemplate.executeCall();
if (StringUtils.isEmpty(respBody)) {
throw new RpcException("response empty");
}
T t = handler.handle(respBody);
return t;
} catch (RpcTimeoutException e) {
rpcException = e;
} catch (RpcStatusException e) {
rpcException = e;
statusCode = e.getCode();
} catch (RpcException e) {
rpcException = e;
} catch (Exception e) {
rpcException = new RpcException(e);
} finally {
if (logger.isDebugEnabled()) {
long costTime = System.currentTimeMillis() - startTime;
String reqParam = convertParam(params);
logger.debug(
"process request, url={}, method={}, params={}, statusCode = {}, response={}, cost={}ms",
url, method.name(), reqParam, statusCode, respBody, costTime);
}
}
tryTimes++;
}
logger.error("request error, url={}, params={}, statusCode = {}, respBody={}", url,
convertParam(params), statusCode, respBody, rpcException);
if (rpcException == null) {
rpcException = new RpcException("服务异常");
}
throw rpcException;
}
/**
* Get 请求
*
* @param url
* @param params
* @param header
* @param timeout
* -1 取默认的超时时间
* @param handler
* @param <T>
* @return
*/
public <T> T get(String url, Map<String, Object> params, Map<String, String> header,
int timeout, CallHandler<T> handler, Integer retryTimes) {
CallTemplate template = () -> HttpClientUtil.get(url, params, header, timeout);
return this.execute(url, params, handler, template, retryTimes, Method.GET);
}
public <T> T get(String url, Map<String, Object> params, CallHandler<T> handler) {
return get(url, params, null, -1, handler, rpcGetRetry);
}
/**
* Post请求(url encoded)
*
* @param url
* @param params
* @param timeout
* @param handler
* @param <T>
* @return
*/
public <T> T post(String url, Map<String, Object> params, int timeout, CallHandler<T> handler,
Integer retryTime) {
CallTemplate template = () -> HttpClientUtil.post(url, params, timeout);
return this.execute(url, params, handler, template, retryTime, Method.POST);
}
/**
* Post请求(url encoded)
*
* @param url
* @param params
* @param timeout
* @param handler
* @param <T>
* @return
*/
public <T> T post(String url, Map<String, Object> params, int timeout, CallHandler<T> handler) {
CallTemplate template = () -> HttpClientUtil.post(url, params, timeout);
return this.execute(url, params, handler, template, rpcPostRetry, Method.POST);
}
/**
* Post Json请求
*
* @param url
* @param params
* @param timeout
* @param handler
* @param <T>
* @return
*/
public <T> T postJson(String url, String params, int timeout, CallHandler<T> handler,
Integer retryTime) {
CallTemplate template = () -> HttpClientUtil.postJson(url, params, timeout);
return this.execute(url, params, handler, template, retryTime, Method.POST);
}
/**
* Post Json请求
*
* @param url
* @param params
* @param timeout
* @param handler
* @param <T>
* @return
*/
public <T> T postJson(String url, String params, int timeout, CallHandler<T> handler) {
CallTemplate template = () -> HttpClientUtil.postJson(url, params, timeout);
return this.execute(url, params, handler, template, rpcPostRetry, Method.POST);
}
enum RpcStatus {
/**
* 成功
*/
SUCCESS(1),
/**
* 告警(请求成功,但非理想值)
*/
WARNING(2),
/**
* 异常
*/
EXCEPTION(3),
/**
* 超时
*/
TIMEOUT(4);
private int value;
RpcStatus(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
enum Method {
/**
* Get请求
*/
GET,
/**
* Post表单请求
*/
POST,
}
/**
* 模板调用
*/
@FunctionalInterface
public interface CallTemplate {
/**
* 模板调用类
*/
String executeCall();
}
/**
* 报文解析
*/
@FunctionalInterface
public interface CallHandler<T> {
/**
* 报文解析
*
* @param resp
* response body
*/
T handle(String resp) throws IOException;
/**
* 校验数据体
*
* @param t
* @return
*/
default boolean check(T t) {
return true;
}
}
}
//package com.netease.mail.yanxuan.change.integration.email.conig;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.parser.ParserConfig;
//import com.netease.mail.yanxuan.change.integration.email.enums.EmailType;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcStatusException;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcTimeoutException;
//import com.netease.mail.yanxuan.change.integration.email.util.EncodeUtil;
//import com.netease.mail.yanxuan.change.integration.email.util.HttpClientUtil;
//import org.aspectj.weaver.Checker;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//
//import java.io.IOException;
//import java.util.List;
//import java.util.Map;
//
///**
// * rpc 请求封装,在 HttpClientUtil 基础上加入了返回值处理和日志
// *
// * @author lwtang
// * @date 2019-02-19
// */
//@Component
//public class RpcTemplate {
//
//
// private Logger logger = LoggerFactory.getLogger(RpcTemplate.class);
//
// @Value("${act.rpc.get.retry:1}")
// private int rpcGetRetry;
//
// @Value("${act.rpc.post.retry:0}")
// private int rpcPostRetry;
//
// public RpcTemplate() {
// ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
// }
//
// private String convertParam(Object param) {
// if (param instanceof String) {
// return (String) param;
// }
// String reqParam = "";
// if (param instanceof Map) {
// reqParam = EncodeUtil.encodeMap((Map) param);
// } else if (param != null) {
// reqParam = JSON.toJSONString(param);
// }
// return reqParam;
// }
//
// private <T> T execute(String url, Object params, CallHandler<T> handler,
// CallTemplate callTemplate, int retryTime, Method method) {
// int tryTimes = 0;
// RpcException rpcException = null;
// String respBody = null;
// int statusCode = 200;
// while (tryTimes <= retryTime) {
// long startTime = System.currentTimeMillis();
// try {
// respBody = callTemplate.executeCall();
// if (StringUtils.isEmpty(respBody)) {
// throw new RpcException("response empty");
// }
//
// T t = handler.handle(respBody);
// return t;
// } catch (RpcTimeoutException e) {
// rpcException = e;
// } catch (RpcStatusException e) {
// rpcException = e;
// statusCode = e.getCode();
// } catch (RpcException e) {
// rpcException = e;
// } catch (Exception e) {
// rpcException = new RpcException(e);
// } finally {
// if (logger.isDebugEnabled()) {
// long costTime = System.currentTimeMillis() - startTime;
// String reqParam = convertParam(params);
// logger.debug(
// "process request, url={}, method={}, params={}, statusCode = {}, response={}, cost={}ms",
// url, method.name(), reqParam, statusCode, respBody, costTime);
// }
// }
// tryTimes++;
// }
//
// logger.error("request error, url={}, params={}, statusCode = {}, respBody={}", url,
// convertParam(params), statusCode, respBody, rpcException);
//
// if (rpcException == null) {
// rpcException = new RpcException("服务异常");
// }
// throw rpcException;
// }
//
// /**
// * Get 请求
// *
// * @param url
// * @param params
// * @param header
// * @param timeout
// * -1 取默认的超时时间
// * @param handler
// * @param <T>
// * @return
// */
// public <T> T get(String url, Map<String, Object> params, Map<String, String> header,
// int timeout, CallHandler<T> handler, Integer retryTimes) {
// CallTemplate template = () -> HttpClientUtil.get(url, params, header, timeout);
// return this.execute(url, params, handler, template, retryTimes, Method.GET);
// }
//
// public <T> T get(String url, Map<String, Object> params, CallHandler<T> handler) {
// return get(url, params, null, -1, handler, rpcGetRetry);
// }
//
// /**
// * Post请求(url encoded)
// *
// * @param url
// * @param params
// * @param timeout
// * @param handler
// * @param <T>
// * @return
// */
// public <T> T post(String url, Map<String, Object> params, int timeout, CallHandler<T> handler,
// Integer retryTime) {
// CallTemplate template = () -> HttpClientUtil.post(url, params, timeout);
// return this.execute(url, params, handler, template, retryTime, Method.POST);
// }
//
// /**
// * Post请求(url encoded)
// *
// * @param url
// * @param params
// * @param timeout
// * @param handler
// * @param <T>
// * @return
// */
// public <T> T post(String url, Map<String, Object> params, int timeout, CallHandler<T> handler) {
// CallTemplate template = () -> HttpClientUtil.post(url, params, timeout);
// return this.execute(url, params, handler, template, rpcPostRetry, Method.POST);
// }
//
// /**
// * Post Json请求
// *
// * @param url
// * @param params
// * @param timeout
// * @param handler
// * @param <T>
// * @return
// */
// public <T> T postJson(String url, String params, int timeout, CallHandler<T> handler,
// Integer retryTime) {
// CallTemplate template = () -> HttpClientUtil.postJson(url, params, timeout);
// return this.execute(url, params, handler, template, retryTime, Method.POST);
// }
//
// /**
// * Post Json请求
// *
// * @param url
// * @param params
// * @param timeout
// * @param handler
// * @param <T>
// * @return
// */
// public <T> T postJson(String url, String params, int timeout, CallHandler<T> handler) {
// CallTemplate template = () -> HttpClientUtil.postJson(url, params, timeout);
// return this.execute(url, params, handler, template, rpcPostRetry, Method.POST);
// }
//
// enum RpcStatus {
//
// /**
// * 成功
// */
// SUCCESS(1),
//
// /**
// * 告警(请求成功,但非理想值)
// */
// WARNING(2),
//
// /**
// * 异常
// */
// EXCEPTION(3),
//
// /**
// * 超时
// */
// TIMEOUT(4);
//
// private int value;
//
// RpcStatus(int value) {
// this.value = value;
// }
//
// public int getValue() {
// return value;
// }
// }
//
// enum Method {
//
// /**
// * Get请求
// */
// GET,
//
// /**
// * Post表单请求
// */
// POST,
// }
//
// /**
// * 模板调用
// */
// @FunctionalInterface
// public interface CallTemplate {
//
// /**
// * 模板调用类
// */
// String executeCall();
// }
//
// /**
// * 报文解析
// */
// @FunctionalInterface
// public interface CallHandler<T> {
//
// /**
// * 报文解析
// *
// * @param resp
// * response body
// */
// T handle(String resp) throws IOException;
//
// /**
// * 校验数据体
// *
// * @param t
// * @return
// */
// default boolean check(T t) {
// return true;
// }
// }
//
//}
package com.netease.mail.yanxuan.change.integration.email.conig;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import com.netease.mail.yanxuan.change.integration.email.email.JumpLinkModel;
import com.netease.mail.yanxuan.change.integration.email.email.ProblemConfigureModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ctrip.framework.apollo.spring.annotation.EnableAutoUpdateApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ValueMapping;
import lombok.Data;
import org.springframework.util.CollectionUtils;
/**
* 第三方平台通用apollo配置
*/
@Data
@Component
@EnableAutoUpdateApolloConfig("3rd.base")
public class ThirdCommonApolloConfig {
private static final String DEFAULT = "default";
/**
* 异常超级管理员(各个接入的服务业务架构统一角色id)
*/
@Value("${abnormalAdminRoleId:7956010101}")
private Long abnormalAdminRoleId;
/**
* 各工作台待办跳转链接
*/
@ValueMapping("${jumpLink:[]}")
private List<JumpLinkModel> jumpLinkMap;
/**
* 各工作台邮件
*/
@ValueMapping("${emailFlowUrl:[]}")
private List<JumpLinkModel> emailFlowUrl;
/**
* 根据产品号获取跳转链接
*
* @param productCode
* @return
*/
public Optional<JumpLinkModel> getJumpLinkByProductCode(String productCode) {
List<JumpLinkModel> list = jumpLinkMap.stream().filter(x -> productCode.equals(x.getProductCode()))
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(list)) {
return Optional.of(list.get(0));
} else {
list = jumpLinkMap.stream().filter(x -> DEFAULT.equals(x.getProductCode())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(list)) {
return Optional.of(list.get(0));
}
}
return Optional.of(jumpLinkMap.get(0));
}
@ValueMapping("${warehouseConfigureModel:{}}")
private ProblemConfigureModel warehouseConfigureModel;
@ValueMapping("${carrierConfigureModel:{}}")
private ProblemConfigureModel carrierConfigureModel;
}
//package com.netease.mail.yanxuan.change.integration.email.conig;
//
//
//import java.util.List;
//import java.util.Optional;
//import java.util.stream.Collectors;
//
//
//import com.netease.mail.yanxuan.change.integration.email.email.JumpLinkModel;
//import com.netease.mail.yanxuan.change.integration.email.email.ProblemConfigureModel;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import com.ctrip.framework.apollo.spring.annotation.EnableAutoUpdateApolloConfig;
//import com.ctrip.framework.apollo.spring.annotation.ValueMapping;
//
//import lombok.Data;
//import org.springframework.util.CollectionUtils;
///**
// * 第三方平台通用apollo配置
// */
//@Data
//@Component
//@EnableAutoUpdateApolloConfig("3rd.base")
//public class ThirdCommonApolloConfig {
//
// private static final String DEFAULT = "default";
//
// /**
// * 异常超级管理员(各个接入的服务业务架构统一角色id)
// */
// @Value("${abnormalAdminRoleId:7956010101}")
// private Long abnormalAdminRoleId;
//
// /**
// * 各工作台待办跳转链接
// */
// @ValueMapping("${jumpLink:[]}")
// private List<JumpLinkModel> jumpLinkMap;
//
// /**
// * 各工作台邮件
// */
// @ValueMapping("${emailFlowUrl:[]}")
// private List<JumpLinkModel> emailFlowUrl;
//
//
// /**
// * 根据产品号获取跳转链接
// *
// * @param productCode
// * @return
// */
// public Optional<JumpLinkModel> getJumpLinkByProductCode(String productCode) {
// List<JumpLinkModel> list = jumpLinkMap.stream().filter(x -> productCode.equals(x.getProductCode()))
// .collect(Collectors.toList());
// if (!CollectionUtils.isEmpty(list)) {
// return Optional.of(list.get(0));
// } else {
// list = jumpLinkMap.stream().filter(x -> DEFAULT.equals(x.getProductCode())).collect(Collectors.toList());
// if (!CollectionUtils.isEmpty(list)) {
// return Optional.of(list.get(0));
// }
// }
// return Optional.of(jumpLinkMap.get(0));
// }
//
// @ValueMapping("${warehouseConfigureModel:{}}")
// private ProblemConfigureModel warehouseConfigureModel;
//
// @ValueMapping("${carrierConfigureModel:{}}")
// private ProblemConfigureModel carrierConfigureModel;
//
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import org.assertj.core.util.Lists;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
public class BaseConvertor {
@SneakyThrows
public static <T> T convert(Object object, final Class<T> clazz) {
if (object == null) {
return null;
}
T t = clazz.newInstance();
BeanUtils.copyProperties(object, t);
return t;
}
@SneakyThrows
public static void copyProperties(Object source, Object target) {
BeanUtils.copyProperties(source, target);
}
@SneakyThrows
public static <T> List<T> convert(List<?> objects, final Class<T> clazz) {
if (org.apache.commons.collections.CollectionUtils.isEmpty(objects)) {
return new ArrayList<>();
}
List<T> retList = Lists.newArrayList();
objects.forEach(object -> {
try {
T t = clazz.newInstance();
BeanUtils.copyProperties(object, t);
retList.add(t);
} catch (Exception ex) {
try {
throw ex;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
return retList;
}
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import org.assertj.core.util.Lists;
//import lombok.SneakyThrows;
//import org.springframework.beans.BeanUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class BaseConvertor {
// @SneakyThrows
// public static <T> T convert(Object object, final Class<T> clazz) {
// if (object == null) {
// return null;
// }
// T t = clazz.newInstance();
// BeanUtils.copyProperties(object, t);
// return t;
// }
//
// @SneakyThrows
// public static void copyProperties(Object source, Object target) {
// BeanUtils.copyProperties(source, target);
// }
//
// @SneakyThrows
// public static <T> List<T> convert(List<?> objects, final Class<T> clazz) {
// if (org.apache.commons.collections.CollectionUtils.isEmpty(objects)) {
// return new ArrayList<>();
// }
// List<T> retList = Lists.newArrayList();
// objects.forEach(object -> {
// try {
// T t = clazz.newInstance();
// BeanUtils.copyProperties(object, t);
// retList.add(t);
// } catch (Exception ex) {
// try {
// throw ex;
// } catch (InstantiationException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
// }
// });
// return retList;
// }
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
import java.io.IOException;
public class EmailTemplateRpcResult<T> implements RpcTemplate.CallHandler<T> {
private static final String CODE = "code";
private static final String RESULT = "data";
private static final String MESSAGE = "errorMessage";
private Class<T> tClass;
public EmailTemplateRpcResult(Class<T> tClass){
this.tClass = tClass;
}
@Override
public T handle(String resp) throws IOException {
JSONObject rpcResult = JSON.parseObject(resp);
EmailTemplateResponResult responResult = new EmailTemplateResponResult();
int code = rpcResult.getIntValue(CODE);
if(code == ResponseCode.SUCCESS.getCode()){
String data = rpcResult.getString(RESULT);
responResult.setData(data);
return (T) responResult;
}
String errorMessage = rpcResult.getString(MESSAGE);
throw new RpcException("email template response error, code : " + code + " , errorMessage : " + errorMessage);
}
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
//import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
//
//import java.io.IOException;
//
//public class EmailTemplateRpcResult<T> implements RpcTemplate.CallHandler<T> {
//
// private static final String CODE = "code";
//
// private static final String RESULT = "data";
//
// private static final String MESSAGE = "errorMessage";
//
// private Class<T> tClass;
//
// public EmailTemplateRpcResult(Class<T> tClass){
// this.tClass = tClass;
// }
//
// @Override
// public T handle(String resp) throws IOException {
// JSONObject rpcResult = JSON.parseObject(resp);
// EmailTemplateResponResult responResult = new EmailTemplateResponResult();
// int code = rpcResult.getIntValue(CODE);
// if(code == ResponseCode.SUCCESS.getCode()){
// String data = rpcResult.getString(RESULT);
// responResult.setData(data);
// return (T) responResult;
// }
// String errorMessage = rpcResult.getString(MESSAGE);
// throw new RpcException("email template response error, code : " + code + " , errorMessage : " + errorMessage);
// }
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
import com.netease.mail.yanxuan.change.integration.email.dto.UserInfoDTO;
import java.io.IOException;
public class IusRpcResult<T> implements RpcTemplate.CallHandler<T> {
private static final String CODE = "code";
private static final String RESULT = "data";
private static final String ERROR_CODE = "errorCode";
private static final String ERROR_MESSAGE = "errorMsg";
private Class<T> tClass;
public IusRpcResult(Class<T> tClass) {
this.tClass = tClass;
}
@Override
public T handle(String resp) throws IOException {
JSONObject rpcResult = JSON.parseObject(resp);
ResponseResult responResult = new ResponseResult();
int code = rpcResult.getIntValue(CODE);
if (code == ResponseCode.SUCCESS.getCode()) {
String data = rpcResult.getString(RESULT);
UserInfoDTO jsonObject = JSON.parseObject(data, UserInfoDTO.class);
responResult.setData(jsonObject);
return (T) responResult;
}
String errorMessage = rpcResult.getString(ERROR_MESSAGE);
Integer errorCode = rpcResult.getInteger(ERROR_CODE);
throw new RpcException("ius response error, resp=" + JSON.toJSONString(resp) + " , errorCode : " + errorCode
+ " , errorMessage : " + errorMessage);
}
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
//import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
//import com.netease.mail.yanxuan.change.integration.email.dto.UserInfoDTO;
//import java.io.IOException;
//
//public class IusRpcResult<T> implements RpcTemplate.CallHandler<T> {
//
// private static final String CODE = "code";
//
// private static final String RESULT = "data";
//
// private static final String ERROR_CODE = "errorCode";
//
// private static final String ERROR_MESSAGE = "errorMsg";
//
// private Class<T> tClass;
//
// public IusRpcResult(Class<T> tClass) {
// this.tClass = tClass;
// }
//
// @Override
// public T handle(String resp) throws IOException {
// JSONObject rpcResult = JSON.parseObject(resp);
// ResponseResult responResult = new ResponseResult();
// int code = rpcResult.getIntValue(CODE);
// if (code == ResponseCode.SUCCESS.getCode()) {
// String data = rpcResult.getString(RESULT);
// UserInfoDTO jsonObject = JSON.parseObject(data, UserInfoDTO.class);
// responResult.setData(jsonObject);
// return (T) responResult;
// }
// String errorMessage = rpcResult.getString(ERROR_MESSAGE);
// Integer errorCode = rpcResult.getInteger(ERROR_CODE);
// throw new RpcException("ius response error, resp=" + JSON.toJSONString(resp) + " , errorCode : " + errorCode
// + " , errorMessage : " + errorMessage);
// }
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import lombok.Builder;
import lombok.Data;
import java.util.List;
@Data
@Builder
public class OverTimeFlowVo {
/**
* 用户邮箱
*/
private String uid;
/**
* 工单列表
*/
private List<OverTimeUserVo> flowIdList;
@Override
protected Object clone() throws CloneNotSupportedException {
OverTimeFlowVo vo = (OverTimeFlowVo) super.clone();
vo.setUid(vo.getUid());
vo.setFlowIdList(BaseConvertor.convert(vo.getFlowIdList(), OverTimeUserVo.class));
return vo;
}
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import lombok.Builder;
//import lombok.Data;
//import java.util.List;
//
//@Data
//@Builder
//public class OverTimeFlowVo {
//
// /**
// * 用户邮箱
// */
// private String uid;
//
// /**
// * 工单列表
// */
// private List<OverTimeUserVo> flowIdList;
//
// @Override
// protected Object clone() throws CloneNotSupportedException {
// OverTimeFlowVo vo = (OverTimeFlowVo) super.clone();
// vo.setUid(vo.getUid());
// vo.setFlowIdList(BaseConvertor.convert(vo.getFlowIdList(), OverTimeUserVo.class));
// return vo;
// }
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import com.netease.mail.yanxuan.qc.service.client.meta.abnormal.LabelModel;
import lombok.Data;
import java.util.List;
@Data
public class ProblemConfigureModel {
/**
* 问题类型配置表id
*/
private Long problemTypeId;
/**
* 异常环节
*/
private List<LabelModel> abnormalLinks;
/**
* 问题分类
*/
private List<LabelModel> flowProblems;
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import com.netease.mail.yanxuan.qc.service.client.meta.abnormal.LabelModel;
//import lombok.Data;
//
//import java.util.List;
//
//@Data
//public class ProblemConfigureModel {
// /**
// * 问题类型配置表id
// */
// private Long problemTypeId;
// /**
// * 异常环节
// */
// private List<LabelModel> abnormalLinks;
// /**
// * 问题分类
// */
// private List<LabelModel> flowProblems;
//}
package com.netease.mail.yanxuan.change.integration.email.email;
import com.alibaba.fastjson.JSON;
import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
import java.io.IOException;
/**
* 直接序列化返回对象
*
* @author lwtang
* @date 2019-02-20
*/
public class RpcObjectHandler<T> implements RpcTemplate.CallHandler<T> {
private Class<T> tClass;
public RpcObjectHandler(Class<T> tClass) {this.tClass = tClass;}
@Override
public T handle(String resp) throws IOException {
return JSON.parseObject(resp, tClass);
}
}
//package com.netease.mail.yanxuan.change.integration.email.email;
//
//import com.alibaba.fastjson.JSON;
//import com.netease.mail.yanxuan.change.integration.email.conig.RpcTemplate;
//
//import java.io.IOException;
//
///**
// * 直接序列化返回对象
// *
// * @author lwtang
// * @date 2019-02-20
// */
//public class RpcObjectHandler<T> implements RpcTemplate.CallHandler<T> {
//
// private Class<T> tClass;
//
//
// public RpcObjectHandler(Class<T> tClass) {this.tClass = tClass;}
//
// @Override
// public T handle(String resp) throws IOException {
// return JSON.parseObject(resp, tClass);
// }
//}
package com.netease.mail.yanxuan.change.integration.email.service;
import com.netease.mail.yanxuan.change.integration.email.email.*;
import com.netease.mail.yanxuan.change.integration.email.enums.EmailEhcFlowEnum;
import java.io.File;
import java.util.Collection;
import java.util.List;
public interface IEmailEhcService {
/**
* 任务工单发送邮件
*
* @param toList
* 收件人列表
* @param ccList
* 抄送人列表
* @param model
* 要素
* @param emailEhcFlowEnum
*/
void sendTaskEmail(Collection<String> toList, Collection<String> ccList, AbnormalTaskFlowEhcEmailModel model,
EmailEhcFlowEnum emailEhcFlowEnum);
/**
* 供应商专属邮件发送
*
* @param supplierId
* @param model
* @param emailEhcFlowEnum
*/
void sendSupplierEmail(String supplierId, AbnormalTaskFlowEhcEmailModel model, EmailEhcFlowEnum emailEhcFlowEnum);
/**
* 供应商惩罚工单发送邮件
*
* @param toList
* @param ccList
* @param model
* @param emailEhcFlowEnum
*/
void sendPunishEmail(Collection<String> toList, Collection<String> ccList, AbnormalPunishFlowEhcEmailModel model,
EmailEhcFlowEnum emailEhcFlowEnum);
/**
* 异常问题工单发送邮件
*
* @param toList
* 收件人列表
* @param ccList
* 抄送人列表.
* @param emailEhcFlowEnum
* 邮件模板
* @param abnormalEhcEmailModel
* 数据
*/
void sendAbnormalEmail(Collection<String> toList, Collection<String> ccList, EmailEhcFlowEnum emailEhcFlowEnum,
AbnormalEhcEmailModel abnormalEhcEmailModel);
/**
* 批量事件工单发送邮件
*
* @param toList
* @param ccList
* @param model
* @param
*/
void sendBathEventEmail(Collection<String> toList, Collection<String> ccList, AbnormalBathEventEhcEmailModel model,
EmailEhcFlowEnum emailEhcFlowEnum);
/**
* 临期/过期工单发送邮件
*
* @param toList
* @param ccList
* @param model
* @param emailEhcFlowEnum
*/
void sendOverTimeEmail(Collection<String> toList, Collection<String> ccList, FlowEhcOverTimeEmailModel model,
EmailEhcFlowEnum emailEhcFlowEnum);
/**
* 邮件发送
*
* @param toList
* 收件人列表
* @param ccList
* 抄送人列表
* @param factor
* 要素
* @param fileList
* 附件
*/
void sendEmail(Collection<String> toList, Collection<String> ccList, EmailEhcFactor factor, List<File> fileList);
/**
* 获取邮件发送工单地址
*
* @param uid
* @return
*/
String getEmailContentUrl(String uid);
/**
* 获取异常任务工单邮件发送地址
*
* @param uid
* @param execUserType
* @return
*/
String getTaskFlowEmailUrl(String uid, Integer execUserType);
}
//package com.netease.mail.yanxuan.change.integration.email.service;
//
//import com.netease.mail.yanxuan.change.integration.email.email.*;
//import com.netease.mail.yanxuan.change.integration.email.enums.EmailEhcFlowEnum;
//import java.io.File;
//import java.util.Collection;
//import java.util.List;
//
//public interface IEmailEhcService {
// /**
// * 任务工单发送邮件
// *
// * @param toList
// * 收件人列表
// * @param ccList
// * 抄送人列表
// * @param model
// * 要素
// * @param emailEhcFlowEnum
// */
// void sendTaskEmail(Collection<String> toList, Collection<String> ccList, AbnormalTaskFlowEhcEmailModel model,
// EmailEhcFlowEnum emailEhcFlowEnum);
//
// /**
// * 供应商专属邮件发送
// *
// * @param supplierId
// * @param model
// * @param emailEhcFlowEnum
// */
// void sendSupplierEmail(String supplierId, AbnormalTaskFlowEhcEmailModel model, EmailEhcFlowEnum emailEhcFlowEnum);
//
// /**
// * 供应商惩罚工单发送邮件
// *
// * @param toList
// * @param ccList
// * @param model
// * @param emailEhcFlowEnum
// */
// void sendPunishEmail(Collection<String> toList, Collection<String> ccList, AbnormalPunishFlowEhcEmailModel model,
// EmailEhcFlowEnum emailEhcFlowEnum);
//
// /**
// * 异常问题工单发送邮件
// *
// * @param toList
// * 收件人列表
// * @param ccList
// * 抄送人列表.
// * @param emailEhcFlowEnum
// * 邮件模板
// * @param abnormalEhcEmailModel
// * 数据
// */
// void sendAbnormalEmail(Collection<String> toList, Collection<String> ccList, EmailEhcFlowEnum emailEhcFlowEnum,
// AbnormalEhcEmailModel abnormalEhcEmailModel);
//
// /**
// * 批量事件工单发送邮件
// *
// * @param toList
// * @param ccList
// * @param model
// * @param
// */
// void sendBathEventEmail(Collection<String> toList, Collection<String> ccList, AbnormalBathEventEhcEmailModel model,
// EmailEhcFlowEnum emailEhcFlowEnum);
//
// /**
// * 临期/过期工单发送邮件
// *
// * @param toList
// * @param ccList
// * @param model
// * @param emailEhcFlowEnum
// */
// void sendOverTimeEmail(Collection<String> toList, Collection<String> ccList, FlowEhcOverTimeEmailModel model,
// EmailEhcFlowEnum emailEhcFlowEnum);
//
// /**
// * 邮件发送
// *
// * @param toList
// * 收件人列表
// * @param ccList
// * 抄送人列表
// * @param factor
// * 要素
// * @param fileList
// * 附件
// */
// void sendEmail(Collection<String> toList, Collection<String> ccList, EmailEhcFactor factor, List<File> fileList);
//
// /**
// * 获取邮件发送工单地址
// *
// * @param uid
// * @return
// */
// String getEmailContentUrl(String uid);
//
// /**
// * 获取异常任务工单邮件发送地址
// *
// * @param uid
// * @param execUserType
// * @return
// */
// String getTaskFlowEmailUrl(String uid, Integer execUserType);
//}
package com.netease.mail.yanxuan.change.integration.email.service;
import com.netease.mail.yanxuan.change.integration.email.email.EmailFactor;
import java.io.File;
import java.util.Collection;
import java.util.List;
/**
* 发送邮件
*/
public interface IEmailService {
/**
* @param to 收件人
* @param emailFactor 邮件要素
*/
void sendEmail(String to, EmailFactor emailFactor);
/**
* @param toList 收件人列表
* @param factor 要素
*/
void sendEmail(Collection<String> toList, EmailFactor factor);
/**
* @param toList 收件人
* @param ccList 抄送人
* @param factor 要素
* @param fileList 附件
*/
void sendEmail(String toList, String ccList, EmailFactor factor,List<File> fileList);
/**
*
* @param toList 收件人列表
* @param ccList 抄送人列表
* @param factor 要素
*/
void sendEmail(Collection<String> toList, Collection<String> ccList, EmailFactor factor);
/**
* @param toList 收件人列表
* @param ccList 抄送人列表
* @param factor 要素
* @param fileList 附件
*/
void sendEmail(Collection<String> toList, Collection<String> ccList, EmailFactor factor, List<File> fileList);
}
//package com.netease.mail.yanxuan.change.integration.email.service;
//
//import com.netease.mail.yanxuan.change.integration.email.email.EmailFactor;
//import java.io.File;
//import java.util.Collection;
//import java.util.List;
//
///**
// * 发送邮件
// */
//public interface IEmailService {
//
// /**
// * @param to 收件人
// * @param emailFactor 邮件要素
// */
// void sendEmail(String to, EmailFactor emailFactor);
//
// /**
// * @param toList 收件人列表
// * @param factor 要素
// */
// void sendEmail(Collection<String> toList, EmailFactor factor);
//
// /**
// * @param toList 收件人
// * @param ccList 抄送人
// * @param factor 要素
// * @param fileList 附件
// */
// void sendEmail(String toList, String ccList, EmailFactor factor,List<File> fileList);
//
// /**
// *
// * @param toList 收件人列表
// * @param ccList 抄送人列表
// * @param factor 要素
// */
// void sendEmail(Collection<String> toList, Collection<String> ccList, EmailFactor factor);
//
// /**
// * @param toList 收件人列表
// * @param ccList 抄送人列表
// * @param factor 要素
// * @param fileList 附件
// */
// void sendEmail(Collection<String> toList, Collection<String> ccList, EmailFactor factor, List<File> fileList);
//
//
//}
package com.netease.mail.yanxuan.change.integration.email.service;
import java.util.List;
import com.netease.mail.yanxuan.change.integration.email.dto.DeptIdLevelLeaderDTO;
import com.netease.mail.yanxuan.change.integration.email.dto.ThirdOrgPosDTO;
import com.netease.mail.yanxuan.change.integration.email.dto.UserInfoDTO;
import com.netease.mail.yanxuan.change.integration.email.dto.UserUniteOrgMetaDTO;
import com.netease.mail.yanxuan.change.integration.email.email.SearchResult;
import com.netease.mail.yanxuan.change.integration.email.dto.UserProductRoleStaticsInfosDTO;
import com.netease.mail.yanxuan.change.integration.email.email.UserVO;
import com.netease.yanxuan.flowx.sdk.meta.dto.base.UserBaseDTO;
/**
* @author jiyuwang 商品是否有模块化受控标准
*/
public interface IIusService {
/**
* 获取用户的部门信息和在职情况
*
* @param uid
* @return
*/
UserInfoDTO getUserInfo(String uid);
/**
* 查询用户集合,不传时查全部
* http://yx.mail.netease.com/bee#/interface/list;serviceCode=yanxuan-ius;branchName=master;selectedInterface=1010712
* @param productCode
* @param uid
* @return
*/
List<UserInfoDTO> queryUserInfo(String productCode, String uid);
/**
* 根据uid获取部门
*
* @param uid
* @return
*/
String getOrgByUid(String uid);
/**
* 判断用户是否离职
*
* @param uid
* @return true: 离职;false: 未离职
*/
boolean checkUserIsLeave(String uid);
/**
* 获取部门负责人
*
* @param uid
* @param orgPosId
* @return
*/
List<DeptIdLevelLeaderDTO> getDeptIdLevelLeader(String uid, Integer orgPosId);
/**
* 根据用户获取三级部门负责人
*
* @param uid
* @return
*/
List<DeptIdLevelLeaderDTO> getThreeLevelDeptLeader(String uid);
/**
* 获取四级部门负责人
* @param uid
* @return
*/
List<DeptIdLevelLeaderDTO> getForthLevelDeptLeader(String uid);
/**
* 模糊查询用户信息
*/
List<UserUniteOrgMetaDTO> fuzzyQueryUserInformation(int queryType, String keyword);
/**
* 模糊查询用户信息(权限中心)
*/
List<UserUniteOrgMetaDTO> fuzzyQueryUserInfo(Long orgPosId, int level, int type, int queryType, String keyword);
/**
* 获得该系统下的该用户组织身份权限或者特殊权限
*
* @param staff
* @param roleId
* @param orgPosId
* @param stationId
* @param locked
* @param keyword
* @param curPage
* @param pageSize
* @return
*/
SearchResult<UserProductRoleStaticsInfosDTO> getAllUserProductRoleInfos(Integer staff, Long roleId, Long orgPosId,
Integer stationId, Integer locked, String keyword, Integer curPage, Integer pageSize);
/**
* 根据产品号和 roleId 获取用户列表
*
* @param productCode
* @param roleId
* @return
*/
List<UserBaseDTO> listUserByRoleId(String productCode, Long roleId);
/**
* 根据uid获取三级部门人员相关信息
* @param uid
* @return
*/
UserVO lv3UserInfo(String uid);
/**
* 获取用户所在系统编码(弃用)
*
* @param uid
* @return
*/
@Deprecated
List<String> listProductHasUid(String uid);
/**
* 三级部门查询列表
* @param name
* @return
*/
List<ThirdOrgPosDTO> getThirdOrgPosName(String name);
}
//package com.netease.mail.yanxuan.change.integration.email.service;
//
//import java.util.List;
//
//import com.netease.mail.yanxuan.change.integration.email.dto.DeptIdLevelLeaderDTO;
//import com.netease.mail.yanxuan.change.integration.email.dto.ThirdOrgPosDTO;
//import com.netease.mail.yanxuan.change.integration.email.dto.UserInfoDTO;
//import com.netease.mail.yanxuan.change.integration.email.dto.UserUniteOrgMetaDTO;
//import com.netease.mail.yanxuan.change.integration.email.email.SearchResult;
//import com.netease.mail.yanxuan.change.integration.email.dto.UserProductRoleStaticsInfosDTO;
//import com.netease.mail.yanxuan.change.integration.email.email.UserVO;
//import com.netease.yanxuan.flowx.sdk.meta.dto.base.UserBaseDTO;
//
///**
// * @author jiyuwang 商品是否有模块化受控标准
// */
//public interface IIusService {
//
// /**
// * 获取用户的部门信息和在职情况
// *
// * @param uid
// * @return
// */
// UserInfoDTO getUserInfo(String uid);
//
// /**
// * 查询用户集合,不传时查全部
// * http://yx.mail.netease.com/bee#/interface/list;serviceCode=yanxuan-ius;branchName=master;selectedInterface=1010712
// * @param productCode
// * @param uid
// * @return
// */
// List<UserInfoDTO> queryUserInfo(String productCode, String uid);
//
// /**
// * 根据uid获取部门
// *
// * @param uid
// * @return
// */
// String getOrgByUid(String uid);
//
// /**
// * 判断用户是否离职
// *
// * @param uid
// * @return true: 离职;false: 未离职
// */
// boolean checkUserIsLeave(String uid);
//
// /**
// * 获取部门负责人
// *
// * @param uid
// * @param orgPosId
// * @return
// */
// List<DeptIdLevelLeaderDTO> getDeptIdLevelLeader(String uid, Integer orgPosId);
//
// /**
// * 根据用户获取三级部门负责人
// *
// * @param uid
// * @return
// */
// List<DeptIdLevelLeaderDTO> getThreeLevelDeptLeader(String uid);
//
// /**
// * 获取四级部门负责人
// * @param uid
// * @return
// */
// List<DeptIdLevelLeaderDTO> getForthLevelDeptLeader(String uid);
//
// /**
// * 模糊查询用户信息
// */
// List<UserUniteOrgMetaDTO> fuzzyQueryUserInformation(int queryType, String keyword);
//
// /**
// * 模糊查询用户信息(权限中心)
// */
// List<UserUniteOrgMetaDTO> fuzzyQueryUserInfo(Long orgPosId, int level, int type, int queryType, String keyword);
//
// /**
// * 获得该系统下的该用户组织身份权限或者特殊权限
// *
// * @param staff
// * @param roleId
// * @param orgPosId
// * @param stationId
// * @param locked
// * @param keyword
// * @param curPage
// * @param pageSize
// * @return
// */
// SearchResult<UserProductRoleStaticsInfosDTO> getAllUserProductRoleInfos(Integer staff, Long roleId, Long orgPosId,
// Integer stationId, Integer locked, String keyword, Integer curPage, Integer pageSize);
//
// /**
// * 根据产品号和 roleId 获取用户列表
// *
// * @param productCode
// * @param roleId
// * @return
// */
// List<UserBaseDTO> listUserByRoleId(String productCode, Long roleId);
//
// /**
// * 根据uid获取三级部门人员相关信息
// * @param uid
// * @return
// */
// UserVO lv3UserInfo(String uid);
//
// /**
// * 获取用户所在系统编码(弃用)
// *
// * @param uid
// * @return
// */
// @Deprecated
// List<String> listProductHasUid(String uid);
//
// /**
// * 三级部门查询列表
// * @param name
// * @return
// */
// List<ThirdOrgPosDTO> getThirdOrgPosName(String name);
//
//
//
//
//}
package com.netease.mail.yanxuan.change.integration.email.service;
import com.netease.mail.yanxuan.change.integration.email.email.SupplierEmailResponseResult;
import com.netease.mail.yanxuan.change.integration.email.email.SupplierEmailSendReq;
public interface ISupplierEmailService {
SupplierEmailResponseResult sendSupplierEmail(SupplierEmailSendReq req);
}
\ No newline at end of file
//package com.netease.mail.yanxuan.change.integration.email.service;
//
//
//import com.netease.mail.yanxuan.change.integration.email.email.SupplierEmailResponseResult;
//import com.netease.mail.yanxuan.change.integration.email.email.SupplierEmailSendReq;
//
//public interface ISupplierEmailService {
//
// SupplierEmailResponseResult sendSupplierEmail(SupplierEmailSendReq req);
//}
\ No newline at end of file
package com.netease.mail.yanxuan.change.integration.email.service;
import java.io.File;
import java.util.Collection;
import java.util.List;
public interface IUasEhcClient {
/**
* 邮件发送
*
* @param subject
* @param content
* @param toList
* @param ccList
* @param fileList
*/
void sendEmail(String subject, String content, Collection<String> toList, Collection<String> ccList,
List<File> fileList);
}
\ No newline at end of file
//package com.netease.mail.yanxuan.change.integration.email.service;
//
//import java.io.File;
//import java.util.Collection;
//import java.util.List;
//
//public interface IUasEhcClient {
//
// /**
// * 邮件发送
// *
// * @param subject
// * @param content
// * @param toList
// * @param ccList
// * @param fileList
// */
// void sendEmail(String subject, String content, Collection<String> toList, Collection<String> ccList,
// List<File> fileList);
//}
\ No newline at end of file
package com.netease.mail.yanxuan.change.integration.email.util;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
/**
* @author lwtang
* @date 2019-02-19
*/
public class EncodeUtil {
private static final char[] CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f' };
public static String encode(String text) {
try {
return URLEncoder.encode(text, "UTF-8");
} catch (Exception e) {
return text;
}
}
public static String encodeMap(Map<?, ?> map) {
List<String> lines = new ArrayList<>();
for (Map.Entry<?, ?> entry: map.entrySet()) {
lines.add(String.valueOf(entry.getKey()) + "=" + String.valueOf(entry.getValue()));
}
return StringUtils.join(lines, "&");
}
public static String decode(String text) {
try {
return URLDecoder.decode(text, "UTF-8");
} catch (Exception e) {
return text;
}
}
public static String ASCIIHex(String text) {
byte[] bytes = text.getBytes();
char[] chars = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
chars[2 * i] = CHARS[bytes[i] >> 4];
chars[2 * i + 1] = CHARS[bytes[i] % 16];
}
return new String(chars).toUpperCase();
}
}
//package com.netease.mail.yanxuan.change.integration.email.util;
//
//import java.net.URLDecoder;
//import java.net.URLEncoder;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import org.apache.commons.lang3.StringUtils;
//
///**
// * @author lwtang
// * @date 2019-02-19
// */
//public class EncodeUtil {
//
// private static final char[] CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8',
// '9', 'a', 'b', 'c', 'd', 'e', 'f' };
//
// public static String encode(String text) {
// try {
// return URLEncoder.encode(text, "UTF-8");
// } catch (Exception e) {
// return text;
// }
// }
//
// public static String encodeMap(Map<?, ?> map) {
// List<String> lines = new ArrayList<>();
// for (Map.Entry<?, ?> entry: map.entrySet()) {
// lines.add(String.valueOf(entry.getKey()) + "=" + String.valueOf(entry.getValue()));
// }
// return StringUtils.join(lines, "&");
// }
//
// public static String decode(String text) {
// try {
// return URLDecoder.decode(text, "UTF-8");
// } catch (Exception e) {
// return text;
// }
// }
//
// public static String ASCIIHex(String text) {
// byte[] bytes = text.getBytes();
// char[] chars = new char[bytes.length * 2];
// for (int i = 0; i < bytes.length; i++) {
// chars[2 * i] = CHARS[bytes[i] >> 4];
// chars[2 * i + 1] = CHARS[bytes[i] % 16];
// }
// return new String(chars).toUpperCase();
// }
//
//}
package com.netease.mail.yanxuan.change.integration.email.util;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcConnectException;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcStatusException;
import com.netease.mail.yanxuan.change.integration.email.exception.RpcTimeoutException;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.config.*;
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.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.CodingErrorAction;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* HttpClient 封装
*
* @author lwtang
* @date 2019-02-19
*/
public class HttpClientUtil {
private static final Logger LOG = LoggerFactory.getLogger(HttpClientUtil.class);
private static final int DEFAULT_TIME_OUT = 5000;
private static final String DEFAULT_ENCODING = "UTF-8";
private static PoolingHttpClientConnectionManager connManager = null;
private static CloseableHttpClient httpclient = null;
static {
try {
SSLContext sslContext = SSLContexts.custom().build();
sslContext.init(null, new TrustManager[] { new DefaultTrustManager() }, null);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslContext)).build();
connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
httpclient = HttpClients.custom().setConnectionManager(connManager).build();
// Create socket configuration
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true)
.setSoReuseAddress(true).setSoTimeout(DEFAULT_TIME_OUT).setTcpNoDelay(true).build();
connManager.setDefaultSocketConfig(socketConfig);
// Create message constraints
MessageConstraints messageConstraints = MessageConstraints.custom()
.setMaxHeaderCount(200).setMaxLineLength(2000).build();
// Create connection configuration
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(Consts.UTF_8)
.setMessageConstraints(messageConstraints).build();
connManager.setDefaultConnectionConfig(connectionConfig);
connManager.setMaxTotal(300);
connManager.setDefaultMaxPerRoute(100);
} catch (KeyManagementException e) {
LOG.error("KeyManagementException", e);
} catch (NoSuchAlgorithmException e) {
LOG.error("NoSuchAlgorithmException", e);
}
}
public static String get(String url, Map<String, Object> params, Map<String, String> header,
int timeout) {
return doGet(url, params, header, DEFAULT_ENCODING, timeout);
}
public static String doGet(String url, Map<String, Object> params, Map<String, String> header,
String encoding, int timeout) {
String responseString = null;
HttpGet get = new HttpGet();
fillUrl(url, params, encoding, get);
fillHeader(header, get);
fillConfig(timeout, timeout, get);
try {
CloseableHttpResponse response = httpclient.execute(get);
try {
int resHttpCode = response.getStatusLine().getStatusCode();
if( resHttpCode != 200) {
throw new RpcStatusException(resHttpCode, "status code " + resHttpCode + " not equal 200");
}
HttpEntity entity = response.getEntity();
try {
if (entity != null) {
responseString = EntityUtils.toString(entity, encoding);
}
} finally {
if (entity != null) {
entity.getContent().close();
}
}
return responseString;
} catch (Exception e) {
LOG.error("[HttpUtils Get response error]", e);
throw e;
} finally {
if (response != null) {
response.close();
}
}
} catch (ConnectException e) {
throw new RpcConnectException("request connect failed!");
} catch (SocketTimeoutException e) {
throw new RpcTimeoutException("request timeout!");
} catch (IOException e) {
LOG.error("[query webservice error]", e);
} finally {
get.releaseConnection();
}
return responseString;
}
public static String postJson(String url, String params, int timeout) {
Map<String, String> header = new HashMap<>();
header.put("Content-type", ContentType.APPLICATION_JSON.getMimeType());
return doPost(url, new StringEntity(params, DEFAULT_ENCODING), header, DEFAULT_ENCODING,
timeout);
}
public static String post(String url, Map<String, Object> params, int timeout) {
Map<String, String> header = new HashMap<>();
header.put("Content-type", ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
HttpEntity httpEntity = null;
if (params != null && params.size() > 0) {
List<BasicNameValuePair> formParams = params.entrySet().stream()
.map(entry -> new BasicNameValuePair(entry.getKey(),
entry.getValue() == null ? "" : entry.getValue().toString()))
.collect(Collectors.toList());
try {
httpEntity = new UrlEncodedFormEntity(formParams, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RpcException(e);
}
}
return doPost(url, httpEntity, header, DEFAULT_ENCODING, timeout);
}
public static String doPost(String url, HttpEntity params, Map<String, String> header,
String encoding, int timeout) {
String responseContent = null;
HttpPost post = new HttpPost(url);
fillHeader(header, post);
fillConfig(timeout, timeout, post);
post.setEntity(params);
try {
CloseableHttpResponse response = httpclient.execute(post);
try {
HttpEntity entity = response.getEntity();
responseContent = EntityUtils.toString(entity, encoding);
} finally {
if (response != null) {
response.close();
}
}
} catch (ConnectException e) {
throw new RpcConnectException("request connect failed!");
} catch (SocketTimeoutException e) {
throw new RpcTimeoutException("request timeout!");
} catch (IOException e) {
LOG.error("[query webservice error]", e);
} finally {
post.releaseConnection();
}
return responseContent;
}
/**
* concat url
*/
private static String fillUrl(String url, Map<String, Object> params, String encoding,
HttpRequestBase requestBase) {
StringBuilder sb = new StringBuilder();
sb.append(url);
int i = 0;
if (params != null && params.size() > 0) {
for (Map.Entry<String, Object> entry: params.entrySet()) {
if (i == 0 && !url.contains("?")) {
sb.append("?");
} else {
sb.append("&");
}
sb.append(entry.getKey());
sb.append("=");
Object v = entry.getValue();
String value = v == null ? "" : v.toString();
encoding = encoding == null ? Consts.UTF_8.name() : encoding;
try {
sb.append(URLEncoder.encode(value, encoding));
} catch (UnsupportedEncodingException e) {
LOG.warn("encoding common get params error, value={}", value, e);
try {
sb.append(URLEncoder.encode(value, encoding));
} catch (Exception ex) {
e.printStackTrace();
}
}
i++;
}
}
requestBase.setURI(URI.create(sb.toString()));
return sb.toString();
}
private static void fillHeader(Map<String, String> header, HttpRequestBase requestBase) {
if (header == null || header.size() == 0) {
return;
}
Header[] headers = header.entrySet().stream()
.map(entry -> new BasicHeader(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()).toArray(new Header[header.size()]);
if (headers.length > 0) {
requestBase.setHeaders(headers);
}
}
/**
* fill common conf
*/
private static void fillConfig(int connectTimeout, int soTimeout, HttpRequestBase requestBase) {
if (connectTimeout <= 0) {
connectTimeout = DEFAULT_TIME_OUT;
}
if (soTimeout <= 0) {
soTimeout = DEFAULT_TIME_OUT;
}
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(soTimeout)
.setConnectTimeout(connectTimeout).setConnectionRequestTimeout(connectTimeout).build();
requestBase.setConfig(requestConfig);
}
public static class DefaultTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
}
//package com.netease.mail.yanxuan.change.integration.email.util;
//
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcConnectException;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcException;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcStatusException;
//import com.netease.mail.yanxuan.change.integration.email.exception.RpcTimeoutException;
//import org.apache.http.Consts;
//import org.apache.http.Header;
//import org.apache.http.HttpEntity;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpGet;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.client.methods.HttpRequestBase;
//import org.apache.http.config.*;
//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.entity.ContentType;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.apache.http.message.BasicHeader;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.ssl.SSLContexts;
//import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.net.ssl.SSLContext;
//import javax.net.ssl.TrustManager;
//import javax.net.ssl.X509TrustManager;
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.net.ConnectException;
//import java.net.SocketTimeoutException;
//import java.net.URI;
//import java.net.URLEncoder;
//import java.nio.charset.CodingErrorAction;
//import java.security.KeyManagementException;
//import java.security.NoSuchAlgorithmException;
//import java.security.cert.CertificateException;
//import java.security.cert.X509Certificate;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
///**
// * HttpClient 封装
// *
// * @author lwtang
// * @date 2019-02-19
// */
//public class HttpClientUtil {
//
// private static final Logger LOG = LoggerFactory.getLogger(HttpClientUtil.class);
//
// private static final int DEFAULT_TIME_OUT = 5000;
//
// private static final String DEFAULT_ENCODING = "UTF-8";
//
// private static PoolingHttpClientConnectionManager connManager = null;
//
// private static CloseableHttpClient httpclient = null;
//
//
// static {
// try {
// SSLContext sslContext = SSLContexts.custom().build();
// sslContext.init(null, new TrustManager[] { new DefaultTrustManager() }, null);
//
// Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
// .<ConnectionSocketFactory>create()
// .register("http", PlainConnectionSocketFactory.INSTANCE)
// .register("https", new SSLConnectionSocketFactory(sslContext)).build();
//
// connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
// httpclient = HttpClients.custom().setConnectionManager(connManager).build();
// // Create socket configuration
// SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true)
// .setSoReuseAddress(true).setSoTimeout(DEFAULT_TIME_OUT).setTcpNoDelay(true).build();
// connManager.setDefaultSocketConfig(socketConfig);
// // Create message constraints
// MessageConstraints messageConstraints = MessageConstraints.custom()
// .setMaxHeaderCount(200).setMaxLineLength(2000).build();
// // Create connection configuration
// ConnectionConfig connectionConfig = ConnectionConfig.custom()
// .setMalformedInputAction(CodingErrorAction.IGNORE)
// .setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(Consts.UTF_8)
// .setMessageConstraints(messageConstraints).build();
// connManager.setDefaultConnectionConfig(connectionConfig);
// connManager.setMaxTotal(300);
// connManager.setDefaultMaxPerRoute(100);
// } catch (KeyManagementException e) {
// LOG.error("KeyManagementException", e);
// } catch (NoSuchAlgorithmException e) {
// LOG.error("NoSuchAlgorithmException", e);
// }
// }
//
// public static String get(String url, Map<String, Object> params, Map<String, String> header,
// int timeout) {
// return doGet(url, params, header, DEFAULT_ENCODING, timeout);
// }
//
// public static String doGet(String url, Map<String, Object> params, Map<String, String> header,
// String encoding, int timeout) {
// String responseString = null;
//
// HttpGet get = new HttpGet();
// fillUrl(url, params, encoding, get);
// fillHeader(header, get);
// fillConfig(timeout, timeout, get);
//
// try {
// CloseableHttpResponse response = httpclient.execute(get);
// try {
// int resHttpCode = response.getStatusLine().getStatusCode();
// if( resHttpCode != 200) {
// throw new RpcStatusException(resHttpCode, "status code " + resHttpCode + " not equal 200");
// }
// HttpEntity entity = response.getEntity();
// try {
// if (entity != null) {
// responseString = EntityUtils.toString(entity, encoding);
// }
// } finally {
// if (entity != null) {
// entity.getContent().close();
// }
// }
// return responseString;
// } catch (Exception e) {
// LOG.error("[HttpUtils Get response error]", e);
// throw e;
// } finally {
// if (response != null) {
// response.close();
// }
// }
// } catch (ConnectException e) {
// throw new RpcConnectException("request connect failed!");
// } catch (SocketTimeoutException e) {
// throw new RpcTimeoutException("request timeout!");
// } catch (IOException e) {
// LOG.error("[query webservice error]", e);
// } finally {
// get.releaseConnection();
// }
// return responseString;
// }
//
//
//
// public static String postJson(String url, String params, int timeout) {
// Map<String, String> header = new HashMap<>();
// header.put("Content-type", ContentType.APPLICATION_JSON.getMimeType());
// return doPost(url, new StringEntity(params, DEFAULT_ENCODING), header, DEFAULT_ENCODING,
// timeout);
// }
//
//
// public static String post(String url, Map<String, Object> params, int timeout) {
// Map<String, String> header = new HashMap<>();
// header.put("Content-type", ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
//
// HttpEntity httpEntity = null;
// if (params != null && params.size() > 0) {
// List<BasicNameValuePair> formParams = params.entrySet().stream()
// .map(entry -> new BasicNameValuePair(entry.getKey(),
// entry.getValue() == null ? "" : entry.getValue().toString()))
// .collect(Collectors.toList());
//
// try {
// httpEntity = new UrlEncodedFormEntity(formParams, DEFAULT_ENCODING);
// } catch (UnsupportedEncodingException e) {
// throw new RpcException(e);
// }
// }
// return doPost(url, httpEntity, header, DEFAULT_ENCODING, timeout);
// }
//
//
// public static String doPost(String url, HttpEntity params, Map<String, String> header,
// String encoding, int timeout) {
// String responseContent = null;
//
// HttpPost post = new HttpPost(url);
//
// fillHeader(header, post);
// fillConfig(timeout, timeout, post);
//
// post.setEntity(params);
// try {
// CloseableHttpResponse response = httpclient.execute(post);
// try {
// HttpEntity entity = response.getEntity();
// responseContent = EntityUtils.toString(entity, encoding);
// } finally {
// if (response != null) {
// response.close();
// }
// }
// } catch (ConnectException e) {
// throw new RpcConnectException("request connect failed!");
// } catch (SocketTimeoutException e) {
// throw new RpcTimeoutException("request timeout!");
// } catch (IOException e) {
// LOG.error("[query webservice error]", e);
// } finally {
// post.releaseConnection();
// }
// return responseContent;
// }
//
// /**
// * concat url
// */
// private static String fillUrl(String url, Map<String, Object> params, String encoding,
// HttpRequestBase requestBase) {
// StringBuilder sb = new StringBuilder();
// sb.append(url);
// int i = 0;
// if (params != null && params.size() > 0) {
// for (Map.Entry<String, Object> entry: params.entrySet()) {
// if (i == 0 && !url.contains("?")) {
// sb.append("?");
// } else {
// sb.append("&");
// }
// sb.append(entry.getKey());
// sb.append("=");
// Object v = entry.getValue();
// String value = v == null ? "" : v.toString();
// encoding = encoding == null ? Consts.UTF_8.name() : encoding;
// try {
// sb.append(URLEncoder.encode(value, encoding));
// } catch (UnsupportedEncodingException e) {
// LOG.warn("encoding common get params error, value={}", value, e);
// try {
// sb.append(URLEncoder.encode(value, encoding));
// } catch (Exception ex) {
// e.printStackTrace();
// }
// }
// i++;
// }
// }
// requestBase.setURI(URI.create(sb.toString()));
// return sb.toString();
// }
//
//
// private static void fillHeader(Map<String, String> header, HttpRequestBase requestBase) {
// if (header == null || header.size() == 0) {
// return;
// }
//
// Header[] headers = header.entrySet().stream()
// .map(entry -> new BasicHeader(entry.getKey(), entry.getValue()))
// .collect(Collectors.toList()).toArray(new Header[header.size()]);
//
// if (headers.length > 0) {
// requestBase.setHeaders(headers);
// }
// }
//
//
// /**
// * fill common conf
// */
// private static void fillConfig(int connectTimeout, int soTimeout, HttpRequestBase requestBase) {
// if (connectTimeout <= 0) {
// connectTimeout = DEFAULT_TIME_OUT;
// }
// if (soTimeout <= 0) {
// soTimeout = DEFAULT_TIME_OUT;
// }
//
// RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(soTimeout)
// .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(connectTimeout).build();
// requestBase.setConfig(requestConfig);
// }
//
//
// public static class DefaultTrustManager implements X509TrustManager {
//
// @Override
// public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
// throws CertificateException {}
//
// @Override
// public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
// throws CertificateException {}
//
// @Override
// public X509Certificate[] getAcceptedIssuers() {
// return new X509Certificate[0];
// }
// }
//
//}
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