init
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.gzzn.omms.adminapi;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AdminApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminApiApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.gzzn.omms.adminapi.config;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
public class DataSourceConfig {
|
||||
@Bean(name = "primaryDataSource")
|
||||
@Primary
|
||||
@ConfigurationProperties(prefix="spring.datasource.primary")
|
||||
public DataSource primaryDataSource()
|
||||
{
|
||||
return DataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
|
||||
@Bean(name = "secondaryDataSource")
|
||||
@ConfigurationProperties(prefix="spring.datasource.secondary")
|
||||
public DataSource secondaryDataSource()
|
||||
{
|
||||
return DataSourceBuilder.create().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.gzzn.omms.adminapi.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaRepositories(
|
||||
entityManagerFactoryRef="entityManagerFactoryPrimary",
|
||||
transactionManagerRef="transactionManagerPrimary",
|
||||
basePackages= { "com.gzzn.omms.adminapi.domain.primary.dao" }
|
||||
) //设置Repository所在位置
|
||||
public class PrimaryConfig
|
||||
{
|
||||
|
||||
@Autowired @Qualifier("primaryDataSource")
|
||||
private DataSource primaryDataSource;
|
||||
|
||||
@Primary
|
||||
@Bean(name = "entityManagerPrimary")
|
||||
public EntityManager entityManager(EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return entityManagerFactoryPrimary(builder).getObject().createEntityManager();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(name = "entityManagerFactoryPrimary")
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.dataSource(primaryDataSource)
|
||||
.properties(getVendorProperties(primaryDataSource))
|
||||
.packages("com.gzzn.omms.adminapi.domain.primary.entity") //设置实体类所在位置
|
||||
.persistenceUnit("primaryPersistenceUnit")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Autowired private JpaProperties jpaProperties;
|
||||
private Map<String, String> getVendorProperties(DataSource dataSource)
|
||||
{
|
||||
return jpaProperties.getHibernateProperties(dataSource);
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(name = "transactionManagerPrimary")
|
||||
public PlatformTransactionManager transactionManagerPrimary(EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return new JpaTransactionManager(entityManagerFactoryPrimary(builder).getObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.gzzn.omms.adminapi.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaRepositories(
|
||||
entityManagerFactoryRef="entityManagerFactorySecondary",
|
||||
transactionManagerRef="transactionManagerSecondary",
|
||||
basePackages= { "com.gzzn.omms.adminapi.domain.secondary.dao" }
|
||||
) //设置Repository所在位置
|
||||
|
||||
public class SecondaryConfig
|
||||
{
|
||||
@Autowired
|
||||
@Qualifier("secondaryDataSource")
|
||||
private DataSource secondaryDataSource;
|
||||
|
||||
@Bean(name = "entityManagerSecondary")
|
||||
public EntityManager entityManager(EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return entityManagerFactorySecondary(builder).getObject().createEntityManager();
|
||||
}
|
||||
|
||||
@Bean(name = "entityManagerFactorySecondary")
|
||||
public LocalContainerEntityManagerFactoryBean
|
||||
entityManagerFactorySecondary (EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.dataSource(secondaryDataSource)
|
||||
.properties(getVendorProperties(secondaryDataSource))
|
||||
.packages("com.gzzn.omms.adminapi.domain.secondary.entity") //设置实体类所在位置
|
||||
.persistenceUnit("secondaryPersistenceUnit")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private JpaProperties jpaProperties;
|
||||
private Map<String, String> getVendorProperties(DataSource dataSource)
|
||||
{
|
||||
return jpaProperties.getHibernateProperties(dataSource);
|
||||
}
|
||||
|
||||
@Bean(name = "transactionManagerSecondary")
|
||||
PlatformTransactionManager transactionManagerSecondary(EntityManagerFactoryBuilder builder)
|
||||
{
|
||||
return new JpaTransactionManager(entityManagerFactorySecondary(builder).getObject());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gzzn.omms.adminapi.controller.basicdata;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.gzzn.omms.adminapi.domain.secondary.dao.basicdata.IABCDao;
|
||||
import com.gzzn.omms.adminapi.domain.secondary.dao.basicdata.ICheckinGroupDao;
|
||||
import com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata.ABC;
|
||||
import com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata.CheckinGroup;
|
||||
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
||||
|
||||
/**
|
||||
* 值机岛
|
||||
* @author zhouxiunai
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class CheckinGroupController {
|
||||
|
||||
@Autowired
|
||||
private ICheckinGroupDao checkinGroupDao;
|
||||
|
||||
@Autowired
|
||||
private IABCDao ABCDao;
|
||||
|
||||
@GetMapping(value="/basicdata/checkinGroup")
|
||||
public ResponseDto getCheckinGroup() {
|
||||
|
||||
ABC abc = ABCDao.findOne("1");
|
||||
|
||||
return ResponseDto.success(abc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.gzzn.omms.adminapi.domain;
|
||||
|
||||
public interface BaseEntity {
|
||||
public void load();
|
||||
public void save();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.gzzn.omms.adminapi.domain.secondary.dao.basicdata;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata.ABC;
|
||||
|
||||
public interface IABCDao extends CrudRepository<ABC,String>{
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.gzzn.omms.adminapi.domain.secondary.dao.basicdata;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata.CheckinGroup;
|
||||
|
||||
public interface ICheckinGroupDao extends CrudRepository<CheckinGroup,String> {
|
||||
|
||||
public CheckinGroup findByCheckinGroupCode(String code);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="ABC")
|
||||
public class ABC {
|
||||
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
private String id;
|
||||
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.gzzn.omms.adminapi.domain.secondary.entity.baiscdata;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.gzzn.omms.adminapi.domain.BaseEntity;
|
||||
import com.gzzn.omms.adminapi.domain.secondary.dao.basicdata.ICheckinGroupDao;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 值机岛
|
||||
* @author zhouxiunai
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="ORMS_CHECKIN_GROUP")
|
||||
public class CheckinGroup {
|
||||
@Id
|
||||
@Column(name = "CHECKIN_GROUP_CODE")
|
||||
private String checkinGroupCode;
|
||||
|
||||
|
||||
|
||||
@Column(name = "CHECKIN_GROUP_NAME")
|
||||
private String checkinGroupName;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.gzzn.omms.adminapi.dto;
|
||||
|
||||
import com.gzzn.omms.adminapi.enums.ResultCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xiunai
|
||||
*
|
||||
* @date 2018年5月16日
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ResponseDto {
|
||||
private Boolean is_success;
|
||||
private Integer err_code;
|
||||
private String err_msg;
|
||||
|
||||
private Object body;
|
||||
|
||||
public ResponseDto() {}
|
||||
|
||||
public ResponseDto(Integer code, String msg) {
|
||||
this.setIs_success(false);
|
||||
this.setErr_code(code);
|
||||
this.setErr_msg(msg);
|
||||
}
|
||||
|
||||
public static ResponseDto success() {
|
||||
ResponseDto result = new ResponseDto();
|
||||
result.setIs_success(true);
|
||||
result.setResultCode(ResultCode.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResponseDto success(Object data) {
|
||||
ResponseDto result = new ResponseDto();
|
||||
result.setIs_success(true);
|
||||
result.setResultCode(ResultCode.SUCCESS);
|
||||
result.setBody(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResponseDto failure(ResultCode resultCode) {
|
||||
ResponseDto result = new ResponseDto();
|
||||
result.setIs_success(false);
|
||||
result.setResultCode(resultCode);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ResponseDto failure(ResultCode resultCode, Object data) {
|
||||
ResponseDto result = new ResponseDto();
|
||||
result.setIs_success(false);
|
||||
result.setResultCode(resultCode);
|
||||
result.setBody(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResultCode(ResultCode code) {
|
||||
this.setErr_code(code.code());
|
||||
this.setErr_msg(code.message());
|
||||
}
|
||||
|
||||
public Object getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(Object body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Boolean getIs_success() {
|
||||
return is_success;
|
||||
}
|
||||
|
||||
public void setIs_success(Boolean is_success) {
|
||||
this.is_success = is_success;
|
||||
}
|
||||
|
||||
public Integer getErr_code() {
|
||||
return err_code;
|
||||
}
|
||||
|
||||
public void setErr_code(Integer err_code) {
|
||||
this.err_code = err_code;
|
||||
}
|
||||
|
||||
public String getErr_msg() {
|
||||
return err_msg;
|
||||
}
|
||||
|
||||
public void setErr_msg(String err_msg) {
|
||||
this.err_msg = err_msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.gzzn.omms.adminapi.enums;
|
||||
|
||||
public enum ResultCode {
|
||||
/* 成功状态码 */
|
||||
SUCCESS(1, "成功"),
|
||||
Failure(0,"失败"),
|
||||
|
||||
/* 参数错误:10001-19999 */
|
||||
PARAM_IS_INVALID(10001, "参数无效"),
|
||||
PARAM_IS_BLANK(10002, "参数为空"),
|
||||
PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
|
||||
PARAM_NOT_COMPLETE(10004, "参数缺失"),
|
||||
|
||||
/* 用户错误:20001-29999*/
|
||||
USER_NOT_LOGGED_IN(20001, "用户未登录"),
|
||||
USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
|
||||
USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
|
||||
USER_NOT_EXIST(20004, "用户不存在"),
|
||||
USER_HAS_EXISTED(20005, "用户已存在"),
|
||||
|
||||
/* 业务错误:30001-39999 */
|
||||
SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),
|
||||
SPECIFIED_ASSETSCATALOG_NOT_FOUND(31001, "资源目录分类不存在"),
|
||||
SPECIFIED_RESOURCELIST_NOT_FOUND(31002, "资源目录不存在"),
|
||||
SPECIFIED_MAINDATAMODEL_NOT_FOUND(32001, "主数据模型不存在"),
|
||||
SPECIFIED_MAINDATAMODEL_TABLE_EXISTED(32002, "主数据模型存储表已存在"),
|
||||
|
||||
/* 系统错误:40001-49999 */
|
||||
SYSTEM_INNER_ERROR(40001, "系统繁忙,请稍后重试"),
|
||||
|
||||
/* 数据错误:50001-599999 */
|
||||
RESULE_DATA_NONE(50001, "数据未找到"),
|
||||
DATA_IS_WRONG(50002, "数据有误"),
|
||||
DATA_ALREADY_EXISTED(50003, "数据已存在"),
|
||||
|
||||
/* 接口错误:60001-69999 */
|
||||
INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
|
||||
INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
|
||||
INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
|
||||
INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
|
||||
INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
|
||||
INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),
|
||||
INTERFACE_NOT_IMPLEMENT(60007, "接口暂未实现"),
|
||||
|
||||
/* 权限错误:70001-79999 */
|
||||
PERMISSION_NO_ACCESS(70001, "无访问权限");
|
||||
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
ResultCode(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public static String getMessage(String name) {
|
||||
for (ResultCode item : ResultCode.values()) {
|
||||
if (item.name().equals(name)) {
|
||||
return item.message;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Integer getCode(String name) {
|
||||
for (ResultCode item : ResultCode.values()) {
|
||||
if (item.name().equals(name)) {
|
||||
return item.code;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.gzzn.omms.adminapi.exception.handler;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.jboss.logging.MDC;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.gzzn.omms.adminapi.utils.JsonUtil;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class ExceptionAspect {
|
||||
private final static Logger logger = LoggerFactory.getLogger(ExceptionAspect.class);
|
||||
|
||||
@Pointcut("execution(public * com.gzzn.zdgov.controller.*.*(..))")
|
||||
public void log(){
|
||||
|
||||
}
|
||||
|
||||
@Before("log()")
|
||||
public void doBefore(JoinPoint joinPoint){
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
ContentCachingRequestWrapper wrapperRequest = new ContentCachingRequestWrapper(request);
|
||||
|
||||
MDC.clear();
|
||||
MDC.put("request_id", getRequestId(request));
|
||||
|
||||
//url
|
||||
try {
|
||||
logger.info("request={url={},method={},content_type={},body={},params={},remoteip={}}",
|
||||
request.getRequestURL(),
|
||||
request.getMethod(),
|
||||
request.getContentType(),
|
||||
JsonUtil.getString(joinPoint.getArgs()),
|
||||
getRequestParams(wrapperRequest),
|
||||
request.getRemoteAddr()
|
||||
);
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterReturning(pointcut = "log()",returning = "object")//打印输出结果
|
||||
public void doAfterReturing(Object object){
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String jsonStr;
|
||||
try
|
||||
{
|
||||
jsonStr = objectMapper.writeValueAsString(object);
|
||||
}
|
||||
catch (JsonProcessingException e)
|
||||
{
|
||||
jsonStr = "[unknown]";
|
||||
}
|
||||
|
||||
logger.info("response={}",jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
private String getResponseBody(ContentCachingResponseWrapper response) {
|
||||
ContentCachingResponseWrapper wrapper = WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
|
||||
if(wrapper != null) {
|
||||
byte[] buf = wrapper.getContentAsByteArray();
|
||||
if(buf.length > 0) {
|
||||
String payload;
|
||||
try {
|
||||
payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
payload = "[unknown]";
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印请求参数
|
||||
* @param request
|
||||
*/
|
||||
private String getRequestBody(ContentCachingRequestWrapper request) {
|
||||
ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
|
||||
if(wrapper != null) {
|
||||
byte[] buf = wrapper.getContentAsByteArray();
|
||||
if(buf.length > 0) {
|
||||
String payload;
|
||||
try {
|
||||
payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
payload = "[unknown]";
|
||||
}
|
||||
return payload.replaceAll("\\n","");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求地址上的参数
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getRequestParams(HttpServletRequest request) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Enumeration<String> enu = request.getParameterNames();
|
||||
//获取请求参数
|
||||
while (enu.hasMoreElements()) {
|
||||
String name = enu.nextElement();
|
||||
sb.append(name + "=").append(request.getParameter(name));
|
||||
if(enu.hasMoreElements()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private String getRequestId(HttpServletRequest request)
|
||||
{
|
||||
String requestId = null;
|
||||
String parameterRequestId = request.getParameter("requestId");
|
||||
String headerRequestId = request.getHeader("requestId");
|
||||
if (parameterRequestId == null && headerRequestId == null)
|
||||
{
|
||||
requestId = UUID.randomUUID().toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
requestId = parameterRequestId != null ? parameterRequestId : headerRequestId;
|
||||
}
|
||||
|
||||
return requestId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.gzzn.omms.adminapi.exception.handler;
|
||||
|
||||
import org.jboss.logging.MDC;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
||||
import com.gzzn.omms.adminapi.enums.ResultCode;
|
||||
|
||||
|
||||
|
||||
@ControllerAdvice
|
||||
public class ExceptionHandle {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通用未知异常捕获处理
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public ResponseDto exceptionHandle(Exception e)
|
||||
{
|
||||
logger.error("[未知系统异常]",e);
|
||||
|
||||
String reponseErrMsg = "";
|
||||
String requestId = (String) MDC.get("request_id");
|
||||
String errorMessage = e.getMessage();
|
||||
if(errorMessage!=null)
|
||||
{
|
||||
reponseErrMsg = "requestId:"+requestId + ",errorMsg:" + errorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
reponseErrMsg = "requestId:"+requestId + ",errorMsg:null";
|
||||
}
|
||||
|
||||
return ResponseDto.failure(ResultCode.SYSTEM_INNER_ERROR,reponseErrMsg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.gzzn.omms.adminapi.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
|
||||
public class JsonUtil {
|
||||
public static String getString(Object object) throws JsonProcessingException
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
|
||||
java.lang.String jsonStr = ow.writeValueAsString(object);
|
||||
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getObject(String str,Class<T> valueType) throws JsonParseException, JsonMappingException, IOException
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
T obj = mapper.readValue(str, valueType);
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
spring:
|
||||
datasource:
|
||||
primary:
|
||||
username: zmsm
|
||||
password: 123456
|
||||
url: jdbc:mysql://130.120.3.158:3306/zmsm?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
|
||||
tomcat:
|
||||
max-active: 30
|
||||
test-on-borrow: true
|
||||
initial-size: 3
|
||||
|
||||
third:
|
||||
username: ommsxc
|
||||
password: ommsxc
|
||||
url: jdbc:oracle:thin:@130.120.2.105:1521/orcl
|
||||
driver: oracle.jdbc.driver.OracleDriver
|
||||
tomcat:
|
||||
max-active: 30
|
||||
test-on-borrow: true
|
||||
initial-size: 3
|
||||
|
||||
secondary:
|
||||
username: dc0305
|
||||
password: 123456
|
||||
url: jdbc:oracle:thin:@130.120.2.219:1521/orcl
|
||||
driver: oracle.jdbc.driver.OracleDriver
|
||||
tomcat:
|
||||
max-active: 30
|
||||
test-on-borrow: true
|
||||
initial-size: 3
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
show_sql: true
|
||||
@@ -0,0 +1,48 @@
|
||||
<configuration>
|
||||
<springProperty scope="context" name="loggingLevelRoot" source="logging.level.root"
|
||||
defaultValue="info"/>
|
||||
<springProperty scope="context" name="loggingFile" source="logging.file"
|
||||
defaultValue="logs/adminapi.log" />
|
||||
|
||||
<springProperty scope="context" name="elkHost" source="elkHost"
|
||||
defaultValue="localhost:4569" />
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${loggingFile}</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${loggingFile}.%i-%d{yyyy-MM-dd}</fileNamePattern>
|
||||
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>60</maxHistory>
|
||||
<totalSizeCap>20GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg %n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="SOCKET"
|
||||
class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
||||
<destination>${elkHost}</destination>
|
||||
|
||||
<!-- encoder is required -->
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder" >
|
||||
<customFields>{"app_name":"xnsj","model_name":"adminapi"}</customFields>
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg %n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="${loggingLevelRoot}">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="SOCKET" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.gzzn.omms.adminapi;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class AdminApiApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user