From e7df2227c923af2a348f46479e32a04b40aec552 Mon Sep 17 00:00:00 2001 From: lvleigang <957075182@qq.com> Date: Mon, 25 Mar 2024 11:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=90=E4=BA=A4=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- application/pom.xml | 19 ++ .../dao/ITestApplicationDao.java | 14 ++ .../dao/TestApplicationEntity.xml | 11 + .../entity/TestApplicationEntity.java | 41 ++++ .../service/ITestApplicationService.java | 11 + .../impl/TestApplicationServiceImpl.java | 32 +++ core/pom.xml | 29 +++ .../frame/action/ApplicationContextUtil.java | 50 +++++ .../com/hzya/frame/entity/BaseResult.java | 117 +++++++++++ .../hzya/frame/entity/JsonResultEntity.java | 90 ++++++++ .../frame/exception/BaseSystemException.java | 29 +++ .../com/hzya/frame/test/dao/ITestDao.java | 13 ++ .../com/hzya/frame/test/dao/TestEntity.xml | 12 ++ .../hzya/frame/test/entity/TestEntity.java | 43 ++++ .../hzya/frame/test/service/ITestService.java | 10 + .../test/service/impl/TestServiceImpl.java | 32 +++ .../service/IUnifiedEntryService.java | 15 ++ .../service/impl/UnifiedEntryServiceImpl.java | 117 +++++++++++ core/src/main/resources/application-dev.yml | 5 + core/src/main/resources/application-local.yml | 5 + core/src/main/resources/application.yml | 47 +++++ core/src/main/resources/banner.txt | 23 +++ core/src/main/resources/logback-spring.xml | 63 ++++++ pom.xml | 192 ++++++++++++++++++ .../java/com/hzya/frame/AppRepository.java | 16 ++ .../frame/controller/EntranceController.java | 41 ++++ 27 files changed, 1081 insertions(+), 1 deletion(-) create mode 100644 application/pom.xml create mode 100644 application/src/main/java/com/hzya/frame/testApplication/dao/ITestApplicationDao.java create mode 100644 application/src/main/java/com/hzya/frame/testApplication/dao/TestApplicationEntity.xml create mode 100644 application/src/main/java/com/hzya/frame/testApplication/entity/TestApplicationEntity.java create mode 100644 application/src/main/java/com/hzya/frame/testApplication/service/ITestApplicationService.java create mode 100644 application/src/main/java/com/hzya/frame/testApplication/service/impl/TestApplicationServiceImpl.java create mode 100644 core/pom.xml create mode 100644 core/src/main/java/com/hzya/frame/action/ApplicationContextUtil.java create mode 100644 core/src/main/java/com/hzya/frame/entity/BaseResult.java create mode 100644 core/src/main/java/com/hzya/frame/entity/JsonResultEntity.java create mode 100644 core/src/main/java/com/hzya/frame/exception/BaseSystemException.java create mode 100644 core/src/main/java/com/hzya/frame/test/dao/ITestDao.java create mode 100644 core/src/main/java/com/hzya/frame/test/dao/TestEntity.xml create mode 100644 core/src/main/java/com/hzya/frame/test/entity/TestEntity.java create mode 100644 core/src/main/java/com/hzya/frame/test/service/ITestService.java create mode 100644 core/src/main/java/com/hzya/frame/test/service/impl/TestServiceImpl.java create mode 100644 core/src/main/java/com/hzya/frame/unifiedEntry/service/IUnifiedEntryService.java create mode 100644 core/src/main/java/com/hzya/frame/unifiedEntry/service/impl/UnifiedEntryServiceImpl.java create mode 100644 core/src/main/resources/application-dev.yml create mode 100644 core/src/main/resources/application-local.yml create mode 100644 core/src/main/resources/application.yml create mode 100644 core/src/main/resources/banner.txt create mode 100644 core/src/main/resources/logback-spring.xml create mode 100644 pom.xml create mode 100644 webapp/src/main/java/com/hzya/frame/AppRepository.java create mode 100644 webapp/src/main/java/com/hzya/frame/controller/EntranceController.java diff --git a/.gitignore b/.gitignore index ad8dcab..7e04681 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,8 @@ replay_pid* .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -78,3 +79,5 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk +.idea/ +/webapp/src/test/java/ diff --git a/application/pom.xml b/application/pom.xml new file mode 100644 index 0000000..8ece650 --- /dev/null +++ b/application/pom.xml @@ -0,0 +1,19 @@ + + + + kangarooDataCenter + com.hzya.frame + 1.0-SNAPSHOT + + 4.0.0 + application + + + com.hzya.frame + core + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/application/src/main/java/com/hzya/frame/testApplication/dao/ITestApplicationDao.java b/application/src/main/java/com/hzya/frame/testApplication/dao/ITestApplicationDao.java new file mode 100644 index 0000000..ac0b746 --- /dev/null +++ b/application/src/main/java/com/hzya/frame/testApplication/dao/ITestApplicationDao.java @@ -0,0 +1,14 @@ +package com.hzya.frame.testApplication.dao; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hzya.frame.testApplication.entity.TestApplicationEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ITestApplicationDao extends BaseMapper { + List queryAll(TestApplicationEntity testApplicationEntity); +} + diff --git a/application/src/main/java/com/hzya/frame/testApplication/dao/TestApplicationEntity.xml b/application/src/main/java/com/hzya/frame/testApplication/dao/TestApplicationEntity.xml new file mode 100644 index 0000000..904723b --- /dev/null +++ b/application/src/main/java/com/hzya/frame/testApplication/dao/TestApplicationEntity.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/application/src/main/java/com/hzya/frame/testApplication/entity/TestApplicationEntity.java b/application/src/main/java/com/hzya/frame/testApplication/entity/TestApplicationEntity.java new file mode 100644 index 0000000..d0f2a55 --- /dev/null +++ b/application/src/main/java/com/hzya/frame/testApplication/entity/TestApplicationEntity.java @@ -0,0 +1,41 @@ +package com.hzya.frame.testApplication.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +@TableName("sys_test_return") +public class TestApplicationEntity { + //sys_test_return + @TableId("id") + private String id; + @TableField("type") + private String type; + @TableField("value") + private String value; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} + diff --git a/application/src/main/java/com/hzya/frame/testApplication/service/ITestApplicationService.java b/application/src/main/java/com/hzya/frame/testApplication/service/ITestApplicationService.java new file mode 100644 index 0000000..66b18c7 --- /dev/null +++ b/application/src/main/java/com/hzya/frame/testApplication/service/ITestApplicationService.java @@ -0,0 +1,11 @@ +package com.hzya.frame.testApplication.service; + +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.entity.JsonResultEntity; + +public interface ITestApplicationService { + + JsonResultEntity testApplication(JSONObject jsonObject); + + +} diff --git a/application/src/main/java/com/hzya/frame/testApplication/service/impl/TestApplicationServiceImpl.java b/application/src/main/java/com/hzya/frame/testApplication/service/impl/TestApplicationServiceImpl.java new file mode 100644 index 0000000..5ee48a3 --- /dev/null +++ b/application/src/main/java/com/hzya/frame/testApplication/service/impl/TestApplicationServiceImpl.java @@ -0,0 +1,32 @@ +package com.hzya.frame.testApplication.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.entity.BaseResult; +import com.hzya.frame.entity.JsonResultEntity; +import com.hzya.frame.testApplication.dao.ITestApplicationDao; +import com.hzya.frame.testApplication.entity.TestApplicationEntity; +import com.hzya.frame.testApplication.service.ITestApplicationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service(value = "testApplicationService") +public class TestApplicationServiceImpl implements ITestApplicationService { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Resource + private ITestApplicationDao testApplicationDao; + + @Override + public JsonResultEntity testApplication(JSONObject jsonObject) { + logger.info("testApplication{}","qweqwe"); + logger.error("testApplication{},参数{}","qweqwe","12312312"); + TestApplicationEntity testApplicationEntity = new TestApplicationEntity(); + testApplicationEntity.setValue("名字"); + List testApplicationEntities = testApplicationDao.queryAll(testApplicationEntity); + return BaseResult.getSuccessMessageEntity("testApplication",testApplicationEntities); + } +} diff --git a/core/pom.xml b/core/pom.xml new file mode 100644 index 0000000..140b1f1 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,29 @@ + + + + kangarooDataCenter + com.hzya.frame + 1.0-SNAPSHOT + + 4.0.0 + core + + + local + + local + + + true + + + + dev + + dev + + + + \ No newline at end of file diff --git a/core/src/main/java/com/hzya/frame/action/ApplicationContextUtil.java b/core/src/main/java/com/hzya/frame/action/ApplicationContextUtil.java new file mode 100644 index 0000000..10b0fd5 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/action/ApplicationContextUtil.java @@ -0,0 +1,50 @@ +package com.hzya.frame.action; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @Content + * @Author 👻👻👻👻👻👻👻👻👻👻 gjh + * @Date 2022-12-05 9:40 + * @Version 1.0 + */ +@Component +public class ApplicationContextUtil implements ApplicationContextAware { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + private static ApplicationContext context; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + context = applicationContext; + } + public static ApplicationContext getApplicationContext(){ + return context; + } + + /** + * 通过name获取 Bean + * @param name beanName + * @return Object + */ + public static Object getBeanByName(String name){ + return getApplicationContext().getBean(name); + } + public static Map getBeansOfType(Class beaNameClass){ + return getApplicationContext().getBeansOfType(beaNameClass); + } + + public static T getBeanByClass(Class requiredType) throws BeansException { + return getApplicationContext().getBean(requiredType); + } + + public static Object getBeanByName2(String name){ + return getApplicationContext().getParentBeanFactory(); + } +} diff --git a/core/src/main/java/com/hzya/frame/entity/BaseResult.java b/core/src/main/java/com/hzya/frame/entity/BaseResult.java new file mode 100644 index 0000000..0a02bc9 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/entity/BaseResult.java @@ -0,0 +1,117 @@ +package com.hzya.frame.entity; + +import com.alibaba.fastjson.JSON; + +/** + * @Content定义全局 + * @Author 👻👻👻👻👻👻👻👻👻👻 gjh + * @Date 2022-12-06 9:54 + * @Version 1.0 + */ +public class BaseResult { + + /** + * 请求失败 + * + * @param message 提示信息 + * @return + */ + public static JsonResultEntity getFailureMessageEntity(String message) { + return new JsonResultEntity(message, false,"500"); + } + /** + * 请求失败 + * + * @param message 提示信息 + * @return + */ + public static JsonResultEntity getFailureMessageEntity(String message, Object mo) { + return new JsonResultEntity(message,false,"500", mo); + } + /*** + * @Content:请求失败 + * @Author 👻👻👻👻👻👻👻👻 gjh + * @Date 2022-12-06 11:00 + * @Param [message, type, status, mo] + * @return com.hzya.frame.web.entity.JsonResultEntity + **/ + public static JsonResultEntity getFailureMessageEntity(String message, String status) { + return new JsonResultEntity(message, false, status); + } + /*** + * @Content:请求失败 + * @Author 👻👻👻👻👻👻👻👻 gjh + * @Date 2022-12-06 11:00 + * @Param [message, type, status, mo] + * @return com.hzya.frame.web.entity.JsonResultEntity + **/ + public static JsonResultEntity getFailureMessageEntity(String message, String status,Object mo) { + return new JsonResultEntity(message, false, status,mo); + } + + + /** + * 请求成功 + * + * @param message 提示消息 + * @return + */ + public static JsonResultEntity getSuccessMessageEntity(String message) { + return new JsonResultEntity(message,true,"200"); + } + /** + * 请求成功 + * + * @param type 类型 + * @param message 提示消息 + * @param mo 返回对象 + * @return + */ + public static String getSuccessMessageEntityByStringResult(String message, String type, Object mo) { + return JSON.toJSONString(new JsonResultEntity(message, true,type, mo)); + } + + /** + * 请求成功 + * + * @param message 提示消息 + * @return + */ + public static String getSuccessMessageEntityByStringResult(String message) { + return JSON.toJSONString( new JsonResultEntity( message,true)); + } + + /**** + * @Content: 返回失败结果,返回的是字符串格式 + * @Author 👻👻👻👻👻👻👻👻 gjh + * @Date 2020-11-23 18:41 + * @Param [message, type] + * @return java.lang.String + **/ + public static String getFailureMessageEntityByString(String message) { + return JSON.toJSONString(new JsonResultEntity( message,false)); + } + /** + * 请求失败 + * + * @param type 类型 + * @param message 提示信息 + * @return + */ + public static String getFailureMessageEntityByString(String message, String type, Object mo) { + return JSON.toJSONString(new JsonResultEntity(message,false , type, mo)); + } + + /** + * 请求成功 + * @return + */ + public static JsonResultEntity getSuccessMessageEntity(Object obj) { + return new JsonResultEntity("成功",true,"200" ,obj); + } + public static JsonResultEntity getSuccessMessageEntity(String message, Object mo) { + return new JsonResultEntity(message,true,"200" ,mo); + } + + +} diff --git a/core/src/main/java/com/hzya/frame/entity/JsonResultEntity.java b/core/src/main/java/com/hzya/frame/entity/JsonResultEntity.java new file mode 100644 index 0000000..6d80c4b --- /dev/null +++ b/core/src/main/java/com/hzya/frame/entity/JsonResultEntity.java @@ -0,0 +1,90 @@ +package com.hzya.frame.entity; + +/** + * + * @author 郭军辉 + * 2016年12月14日下午5:21:35 + */ +public class JsonResultEntity { + /** 提示信息 */ + private String msg; + /** 返回类型 */ + private String type; + /** 是否成功 true成功 false失败 */ + private boolean flag; + /** 状态码*/ + private String status; + /** request 域放的对象 */ + private Object attribute; + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public boolean isFlag() { + return flag; + } + + public void setFlag(boolean flag) { + this.flag = flag; + } + + public Object getAttribute() { + return attribute; + } + + public void setAttribute(Object attribute) { + this.attribute = attribute; + } + + public JsonResultEntity(String msg, boolean flag, Object attribute) { + super(); + this.msg = msg; + this.flag = flag; + this.attribute = attribute; + } + + public JsonResultEntity(String msg, boolean flag, String status) { + this.msg = msg; + this.flag = flag; + this.status = status; + } + + public JsonResultEntity(String msg, boolean flag, String status, Object attribute) { + this.msg = msg; + this.flag = flag; + this.status = status; + this.attribute = attribute; + } + + public JsonResultEntity(String msg, boolean flag) { + super(); + this.msg = msg; + this.flag = flag; + } + + public JsonResultEntity() { + super(); + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/core/src/main/java/com/hzya/frame/exception/BaseSystemException.java b/core/src/main/java/com/hzya/frame/exception/BaseSystemException.java new file mode 100644 index 0000000..2f8b24f --- /dev/null +++ b/core/src/main/java/com/hzya/frame/exception/BaseSystemException.java @@ -0,0 +1,29 @@ +package com.hzya.frame.exception; + +/** + * @Auther: xiang2lin + * @Date: 2020/3/24 08:43 + * 异常类,业务代码全部抛出这个异常 + */ +public class BaseSystemException extends RuntimeException { + public BaseSystemException(String message) { + super(message); + } + public BaseSystemException(String message, Exception e) { + super(message,e); + } + + public BaseSystemException(Exception ex) { + super(ex); + } + + public BaseSystemException() { + super(); + } + + public BaseSystemException(Throwable throwable) { + super(throwable); + } + + +} diff --git a/core/src/main/java/com/hzya/frame/test/dao/ITestDao.java b/core/src/main/java/com/hzya/frame/test/dao/ITestDao.java new file mode 100644 index 0000000..8750651 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/test/dao/ITestDao.java @@ -0,0 +1,13 @@ +package com.hzya.frame.test.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hzya.frame.test.entity.TestEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ITestDao extends BaseMapper { + List queryAll(TestEntity testEntity); +} + diff --git a/core/src/main/java/com/hzya/frame/test/dao/TestEntity.xml b/core/src/main/java/com/hzya/frame/test/dao/TestEntity.xml new file mode 100644 index 0000000..f920815 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/test/dao/TestEntity.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/core/src/main/java/com/hzya/frame/test/entity/TestEntity.java b/core/src/main/java/com/hzya/frame/test/entity/TestEntity.java new file mode 100644 index 0000000..bed2bdb --- /dev/null +++ b/core/src/main/java/com/hzya/frame/test/entity/TestEntity.java @@ -0,0 +1,43 @@ +package com.hzya.frame.test.entity; + + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +@TableName("sys_test_return") +public class TestEntity { + //sys_test_return + @TableId("id") + private String id; + @TableField("type") + private String type; + @TableField("value") + private String value; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} + diff --git a/core/src/main/java/com/hzya/frame/test/service/ITestService.java b/core/src/main/java/com/hzya/frame/test/service/ITestService.java new file mode 100644 index 0000000..b377240 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/test/service/ITestService.java @@ -0,0 +1,10 @@ +package com.hzya.frame.test.service; + +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.entity.JsonResultEntity; + +public interface ITestService { + + + JsonResultEntity testCore(JSONObject jsonObject); +} diff --git a/core/src/main/java/com/hzya/frame/test/service/impl/TestServiceImpl.java b/core/src/main/java/com/hzya/frame/test/service/impl/TestServiceImpl.java new file mode 100644 index 0000000..9ae57d6 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/test/service/impl/TestServiceImpl.java @@ -0,0 +1,32 @@ +package com.hzya.frame.test.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.entity.BaseResult; +import com.hzya.frame.entity.JsonResultEntity; +import com.hzya.frame.test.dao.ITestDao; +import com.hzya.frame.test.entity.TestEntity; +import com.hzya.frame.test.service.ITestService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service(value = "testService") +public class TestServiceImpl implements ITestService { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Resource + private ITestDao testDao; + @Override + public JsonResultEntity testCore(JSONObject jsonObject) { + logger.info("testCore"); + logger.error("testCore"); + TestEntity testEntity = new TestEntity(); + testEntity.setValue("名字"); + List testEntityList = testDao.queryAll(testEntity); + return BaseResult.getSuccessMessageEntity("testCore",testEntityList); + } + +} diff --git a/core/src/main/java/com/hzya/frame/unifiedEntry/service/IUnifiedEntryService.java b/core/src/main/java/com/hzya/frame/unifiedEntry/service/IUnifiedEntryService.java new file mode 100644 index 0000000..2c44853 --- /dev/null +++ b/core/src/main/java/com/hzya/frame/unifiedEntry/service/IUnifiedEntryService.java @@ -0,0 +1,15 @@ +package com.hzya.frame.unifiedEntry.service; + +import com.hzya.frame.entity.JsonResultEntity; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.lang.reflect.InvocationTargetException; + +public interface IUnifiedEntryService { + + /** + * @Description 请求统一入口 + **/ + JsonResultEntity doBusiness(ServletRequest servletRequest, ServletResponse servletResponse) throws InvocationTargetException, IllegalAccessException; +} diff --git a/core/src/main/java/com/hzya/frame/unifiedEntry/service/impl/UnifiedEntryServiceImpl.java b/core/src/main/java/com/hzya/frame/unifiedEntry/service/impl/UnifiedEntryServiceImpl.java new file mode 100644 index 0000000..e28190b --- /dev/null +++ b/core/src/main/java/com/hzya/frame/unifiedEntry/service/impl/UnifiedEntryServiceImpl.java @@ -0,0 +1,117 @@ +package com.hzya.frame.unifiedEntry.service.impl; + + +import cn.dev33.satoken.exception.NotLoginException; +import cn.hutool.extra.servlet.ServletUtil; +import com.hzya.frame.action.ApplicationContextUtil; +import com.hzya.frame.entity.BaseResult; +import com.hzya.frame.entity.JsonResultEntity; +import com.hzya.frame.exception.BaseSystemException; +import com.hzya.frame.unifiedEntry.service.IUnifiedEntryService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; +import com.alibaba.fastjson.JSONObject; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +@Service(value = "unifiedEntryService") +public class UnifiedEntryServiceImpl implements IUnifiedEntryService { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Override + public JsonResultEntity doBusiness(ServletRequest servletRequest, ServletResponse servletResponse) throws InvocationTargetException, IllegalAccessException { + HttpServletRequest request = (HttpServletRequest) servletRequest; + String method = request.getMethod(); + //tailuo 要访问的Bean名称 + String service = request.getHeader("tl"); + //数据库表名称对于缓存的key + String tableKey = request.getHeader("as"); + //bean方法 + String serviceMethod = request.getHeader("dj"); + /** 根据调用的 serviceMethod 获取相关table名称*/ + //String tableName = serviceMethodCache.get(tableKey); + // + //if (ObjectUtils.isEmpty(tableName)) { + // throw new BaseSystemException("根据tableKey获取tableName失败!未获取到数据!请检查参数tableKey。"); + //} + String body = ServletUtil.getBody(servletRequest); + //获取类 + Object object = null; + try { + object = ApplicationContextUtil.getBeanByName(service); + } catch (SecurityException e) { + return BaseResult.getFailureMessageEntity(service + "未找到"); + } + //获取类下面的方法 + Method[] methods = object.getClass().getMethods(); + logger.info("methodsLength:" + methods.length); + if (methods == null || methods.length == 0) { + logger.info("当前methods:" + methods + "methodsLength = " + methods.length); + + return BaseResult.getFailureMessageEntity(service + "未找到" + serviceMethod + "方法"); + } else { + logger.info("当前methods222222:" + methods + "methodsLength = " + methods.length); + + } + for (Method m : methods) { + logger.info("当前mnAME:" + m.getName() + " :serviceMethod = " + serviceMethod.trim()); + + if (null != m) { + if (m.getName().equals(serviceMethod.trim())) { + if (m.getName().startsWith("thirdInterface")) {//TODO 后续可能要加强校验规则 + logger.info("第三方接口,不校验是否登陆"); + } else if (!"doLogin".equals(m.getName())) { + try { + //TODO 暂时先不校验 + //StpUtil.checkLogin(); + }catch (NotLoginException e){ + logger.error("token无效"); + return BaseResult.getFailureMessageEntity("token无效"); + } + } + logger.info("m.getNameEquals成功"); + + JSONObject jsonObject = new JSONObject(); + if (!ObjectUtils.isEmpty(body)) { + jsonObject.put("jsonStr", body); + } + //jsonObject.put("tableName", tableName); + + JsonResultEntity jsonResultEntity; + try { + logger.info("invoke开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + logger.info("请求的参数:jsonObject:" + jsonObject.toJSONString()); + jsonResultEntity = (JsonResultEntity) m.invoke(object, jsonObject); + if (jsonResultEntity != null) { + jsonResultEntity.setType(serviceMethod); + } + logger.info("invoke结束>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + return jsonResultEntity; + } catch (Exception e) { + e.printStackTrace(); + logger.info("METHOD doBusiness invokeException", e); + if (e instanceof InvocationTargetException) { + Throwable targetException = ((InvocationTargetException) e).getTargetException(); + if (targetException instanceof BaseSystemException) { + throw new BaseSystemException(targetException.getMessage()); + } else { + logger.info("METHOD doBusiness :", e); + e.printStackTrace(); + throw e; + } + } else { + throw e; + } + } + } + } + } + return BaseResult.getFailureMessageEntity(service + "未找到" + serviceMethod + "方法"); + } +} diff --git a/core/src/main/resources/application-dev.yml b/core/src/main/resources/application-dev.yml new file mode 100644 index 0000000..06c9f1a --- /dev/null +++ b/core/src/main/resources/application-dev.yml @@ -0,0 +1,5 @@ +########################开发环境####################### +logging: + #日志级别 指定目录级别 + level: + root: INFO \ No newline at end of file diff --git a/core/src/main/resources/application-local.yml b/core/src/main/resources/application-local.yml new file mode 100644 index 0000000..64e432a --- /dev/null +++ b/core/src/main/resources/application-local.yml @@ -0,0 +1,5 @@ +#######################本地环境####################### +logging: + #日志级别 指定目录级别 + level: + root: error \ No newline at end of file diff --git a/core/src/main/resources/application.yml b/core/src/main/resources/application.yml new file mode 100644 index 0000000..b12b64f --- /dev/null +++ b/core/src/main/resources/application.yml @@ -0,0 +1,47 @@ +server: + port: 9999 + servlet: + context-path: /kangarooDataCenter + localIP: 127.0.0.1 +spring: + mvc: + pathmatch: + use-suffix-pattern: true + profiles: +# active: @profileActive@ + active: @profile.active@ +# active: dev + servlet: + multipart: + enabled: true + #单个文件的大小 + max-file-size: 500MB + #单次请求的文件的总大小 + max-request-size: 550MB +# 默认数据源设置 + datasource: + dynamic: + primary: master #设置默认的数据源或者数据源组,默认值即为master + strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源 + datasource: + master: + url: jdbc:mysql://hzya.ufyct.com:9096/businesscenter?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true + username: root + password: hzya1314 + driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置 + +logging: + #日志配置路径 + config: classpath:logback-spring.xml + +mybatis-plus: + mapper-locations: classpath:/com/hzya/frame/**/dao/*.xml + type-aliases-package: com.hzya.frame.*.entity; + global-config: + id-type: 3 + db-column-underline: true + field-strategy: 2 + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + map-underscore-to-camel-case: false + call-setters-on-nulls: true \ No newline at end of file diff --git a/core/src/main/resources/banner.txt b/core/src/main/resources/banner.txt new file mode 100644 index 0000000..517e092 --- /dev/null +++ b/core/src/main/resources/banner.txt @@ -0,0 +1,23 @@ +${AnsiColor.BRIGHT_YELLOW} + + + _ooOoo_ + o8888888o + 88" . "88 + (| -_- |) + O\ = /O + ____/`---'\____ + .' \\| |// `. + / \\||| : |||// \ + / _||||| -:- |||||- \ + | | \\\ - /// | | + | \_| ''\---/'' | | + \ .-\__ `-` ___/-. / + ___`. .' /--.--\ `. . __ + ."" '< `.___\_<|>_/___.' >'"". + | | : `- \`.;`\ _ /`;.`/ - ` : | | + \ \ `-. \_ __\ /__ _/ .-` / / + ======`-.____`-.___\_____/___.-`____.-'====== + `=---=' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // 佛祖保佑 永不宕机 永无BUG // diff --git a/core/src/main/resources/logback-spring.xml b/core/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..4890b0e --- /dev/null +++ b/core/src/main/resources/logback-spring.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + INFO + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + + ${LOG_HOME_LOCAL}/%d{yyyy-MM-dd}/kangarooDataCenter%d{yyyy-MM}.log + + + ${LOG_HOME_DEV}/%d{yyyy-MM-dd}/kangarooDataCenter_%d{yyyy-MM}.log + + + 50 + + + + %d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] %logger{50} - %msg%n + + + + 50MB + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..decf9cd --- /dev/null +++ b/pom.xml @@ -0,0 +1,192 @@ + + + 4.0.0 + + com.hzya.frame + kangarooDataCenter + pom + 1.0-SNAPSHOT + + webapp + core + application + + + 2.5.14 + 1.8 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.14 + + + + + + org.springframework.boot + spring-boot-dependencies + ${boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + test + + + + org.slf4j + slf4j-api + 1.7.30 + + + + ch.qos.logback + logback-classic + 1.2.3 + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba + fastjson + 2.0.33 + + + + cn.hutool + hutool-all + 5.8.19 + + + + + cn.dev33 + sa-token-spring-boot-starter + 1.30.0 + + + cn.dev33 + sa-token-oauth2 + 1.30.0 + + + cn.dev33 + sa-token-jwt + 1.30.0 + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + 3.5.2 + + + + mysql + mysql-connector-java + 5.1.49 + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 + + + + + kangarooDataCenter + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 1.8 + 1.8 + UTF-8 + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.7.4 + + ${project.artifactId} + none + execute + + + + + + + + src/main/java + + **/*.xml + + + + src/main/resources + + **/*.yml + **/*.xml + **/*.xmreport + **/*.xlsx + **/*.json + **/*.xdb + + + + + + src/ + + **/*.yml + **/*.xml + **/*.json + + true + + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/webapp/src/main/java/com/hzya/frame/AppRepository.java b/webapp/src/main/java/com/hzya/frame/AppRepository.java new file mode 100644 index 0000000..6dbc85a --- /dev/null +++ b/webapp/src/main/java/com/hzya/frame/AppRepository.java @@ -0,0 +1,16 @@ +package com.hzya.frame; + + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication() +@MapperScan({"com.hzya.frame.testApplication.dao","com.hzya.frame.test.dao"}) +public class AppRepository extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(AppRepository.class); + } +} diff --git a/webapp/src/main/java/com/hzya/frame/controller/EntranceController.java b/webapp/src/main/java/com/hzya/frame/controller/EntranceController.java new file mode 100644 index 0000000..419df37 --- /dev/null +++ b/webapp/src/main/java/com/hzya/frame/controller/EntranceController.java @@ -0,0 +1,41 @@ +package com.hzya.frame.controller; + +import com.hzya.frame.entity.JsonResultEntity; +import com.hzya.frame.unifiedEntry.service.IUnifiedEntryService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +@Controller +@RequestMapping("/entranceController") +public class EntranceController { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private IUnifiedEntryService unifiedEntryService; + + @RequestMapping("/queryTest") + @ResponseBody + public String queryTest() { + logger.info("请求成功info"); + logger.error("请求成功error"); + return "请求成功"; + } + + /** + * @param servletRequest + * @param servletResponse + * @Description 请求统一入口 + **/ + @RequestMapping(value = "/option") + @ResponseBody + public JsonResultEntity option(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { + return unifiedEntryService.doBusiness(servletRequest, servletResponse); + } +}