commit d3ce851dd9aba5bc4d72b5e6475680e0ed2b8376 Author: fengjianhuang <729846467@qq.com> Date: Thu May 25 15:07:01 2023 +0800 admin diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46ca6e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +*.jar +*.war +*.class +*.lock +*.DS_Store +*.swp +*.out +target/ +*.iml +*.ipr +*.iws +*.bak +.settings/ +.classpath +.project +.metadata/ +.idea/ +logs/ +log/ +*.log +dependency-reduced-pom.xml +.flattened-pom.xml +**/bin/* +/out/ +*.lck +pom-xml-flattened diff --git a/g3fo-admin-api/.gitignore b/g3fo-admin-api/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/g3fo-admin-api/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/g3fo-admin-api/pom.xml b/g3fo-admin-api/pom.xml new file mode 100644 index 0000000..702950e --- /dev/null +++ b/g3fo-admin-api/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + + com.afe.g3fo + g3fo-admin + ${revision} + ../pom.xml + + jar + + g3fo-admin-api + g3fo-admin-api + g3fo-admin-api + + + + org.projectlombok + lombok + + + + com.afe.g3fo + g3fo-framework + + + + + \ No newline at end of file diff --git a/g3fo-admin-api/src/main/java/com/afe/g3fo/admin/exception/AdminBizException.java b/g3fo-admin-api/src/main/java/com/afe/g3fo/admin/exception/AdminBizException.java new file mode 100644 index 0000000..345bc98 --- /dev/null +++ b/g3fo-admin-api/src/main/java/com/afe/g3fo/admin/exception/AdminBizException.java @@ -0,0 +1,11 @@ +package com.afe.g3fo.admin.exception; + +import com.afe.g3fo.framework.exception.BizException; +import com.afe.g3fo.framework.exception.IException; + +public class AdminBizException extends BizException { + + private static final long serialVersionUID = 1L; + + +} diff --git a/g3fo-admin-service/.gitignore b/g3fo-admin-service/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/g3fo-admin-service/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/g3fo-admin-service/Dockerfile b/g3fo-admin-service/Dockerfile new file mode 100644 index 0000000..042b7b7 --- /dev/null +++ b/g3fo-admin-service/Dockerfile @@ -0,0 +1,27 @@ + +# 基础镜像 +FROM openjdk:17-alpine + +## 设置时区为东八区(北京时间) +#RUN apk add --no-cache tzdata \ +# && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ +# && echo "Asia/Shanghai" > /etc/timezone + +# 复制打包后的 JAR 文件到容器中 +ENV HOSTNAME="g3fo-admin" +COPY /target/g3fo-admin-service-1.0.0-SNAPSHOT.jar /app.jar +ARG JAVA_OPTS="-XX:NewRatio=1 -XX:SurvivorRatio=1 -Xss1024k -Xmx512m -Xms512m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Xloggc:/data/logs/jvm/gc.log" +ENV JAVA_OPTS=$JAVA_OPTS +ENV RUN_ARGS="--spring.cloud.nacos.discovery.ip=$HOSTNAME --dubbo.provider.host=$HOSTNAME" +# 容器启动时执行的命令 + +#ADD *.jar g3fo-demo-service-1.0.0-SNAPSHOT.jar + +##指定配置文件,方便在容器中运行时挂载配置文件路径 +#ENTRYPOINT ["java", "-jar", "/app.jar", "$RUN_ARGS"] +ENTRYPOINT java -jar /app.jar $RUN_ARGS + +#ENTRYPOINT ["java", "-jar", "/app.jar"] + +# 为容器设置端口映射(可选) +EXPOSE 18002 \ No newline at end of file diff --git a/g3fo-admin-service/pom.xml b/g3fo-admin-service/pom.xml new file mode 100644 index 0000000..baa6efb --- /dev/null +++ b/g3fo-admin-service/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + + com.afe.g3fo + g3fo-admin + ${revision} + ../pom.xml + + jar + + g3fo-admin-service + g3fo-admin-service + g3fo-admin-service + + + + + + com.afe.g3fo + g3fo-admin-api + + + + + com.afe.g3fo + g3fo-framework-service + + + p6spy + p6spy + + + cn.hutool + hutool-all + + + org.springframework.boot + spring-boot-autoconfigure + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.afe.g3fo + g3fo-framework-service + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 3.0.6 + + + + repackage + + + + + + + diff --git a/g3fo-admin-service/src/main/java/com/afe/g3fo/Application.java b/g3fo-admin-service/src/main/java/com/afe/g3fo/Application.java new file mode 100644 index 0000000..01a10c8 --- /dev/null +++ b/g3fo-admin-service/src/main/java/com/afe/g3fo/Application.java @@ -0,0 +1,27 @@ +package com.afe.g3fo; + +import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * boot class + * + * @Author yangguangjing + * @Date 2023年4月10日 + */ +@EnableDubbo +@MapperScan +@DubboComponentScan +@SpringBootApplication +@EnableDiscoveryClient +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/SwaggerConfig.java b/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/SwaggerConfig.java new file mode 100644 index 0000000..a795651 --- /dev/null +++ b/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/SwaggerConfig.java @@ -0,0 +1,35 @@ +package com.afe.g3fo.admin.config; + +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Contact; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.tags.Tag; + +@OpenAPIDefinition( + tags = { + @Tag(name = "用户管理", description = "用户管理") + }, + info = @Info( + title = "G3-admin-API", + description = "用户模块接口文档", + version = "1.0.0-SNAPSHOT", + contact = @Contact(name = "g3support", email = "g3sfsupport@afe-solutions.com", url = "http://www.afe-solutions.com") + ), + servers = { + @Server(description = "开发环境", url = "http://127.0.0.1:8081/doc.html") + }, + security = @SecurityRequirement(name = "Oauth2"), + externalDocs = @ExternalDocumentation( + description = "项目编译部署说明", + url = "http://localhost/deploy/README.md" + ) +) +@Configuration +public class SwaggerConfig { + +} diff --git a/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/UserGlobalExceptionHandler.java b/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/UserGlobalExceptionHandler.java new file mode 100644 index 0000000..531b304 --- /dev/null +++ b/g3fo-admin-service/src/main/java/com/afe/g3fo/admin/config/UserGlobalExceptionHandler.java @@ -0,0 +1,43 @@ +package com.afe.g3fo.admin.config; + +import com.afe.g3fo.admin.exception.AdminBizException; +import com.afe.g3fo.framework.common.Result; +import com.afe.g3fo.framework.service.exception.GlobalExceptionHandler; +import com.afe.g3fo.plugin.dubbo.exception.DubboException; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @Author:fengjianhuang + * @Package:com.afe.g3fo.user.exception + * @Project:g3fo-user + * @name:UserGlobalExceptionHandler + * @Date:2023/5/15 14:00 + * @Filename:UserGlobalExceptionHandler + */ +@ControllerAdvice +@Slf4j +public class UserGlobalExceptionHandler extends GlobalExceptionHandler { + @ResponseBody + @ExceptionHandler(DubboException.class) + public Result handleRpcException(DubboException e, HttpServletRequest request) { + log.error(e.getMessage(), e); + String code = String.valueOf(e.getCode()); + return StringUtils.isNotBlank(code) ? Result.error(code, e.getMessage()) : Result.error(e.getMessage()); + } + + /** + * 业务异常 + */ + @ResponseBody + @ExceptionHandler(AdminBizException.class) + public Result handleServiceException(AdminBizException e, HttpServletRequest request) { + log.error(e.getMessage(), e); + String code = e.getCode(); + return StringUtils.isNotBlank(code) ? Result.error(code, e.getMessage()) : Result.error(e.getMessage()); + } +} diff --git a/g3fo-admin-service/src/main/resources/bootstrap.yml b/g3fo-admin-service/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c4377a7 --- /dev/null +++ b/g3fo-admin-service/src/main/resources/bootstrap.yml @@ -0,0 +1,23 @@ +app: + service-name: g3fo-admin + env: dev +spring: + application: + name: ${app.service-name} + profiles: + active: dev + cloud: + nacos: + config: + server-addr: nacos:8848 #nacos配置中心地址 + namespace: ${app.env} #配置中心的命名空间id + group: DEFAULT_GROUP #配置分组,默认没有也可以 + file-extension: yml #配置文件后缀,用于拼接配置配置文件名称,目前只支持yml和properties + refresh-enabled: true #配置自动刷新 + encode: UTF-8 # 配置编码 + extension-configs: + - data-id: dubbo.yml + refresh: false + - data-id: redis.yml + - data-id: mysql.yml + - data-id: common.yml \ No newline at end of file diff --git a/g3fo-admin-service/src/main/resources/mapper/UserInfoMapper.xml b/g3fo-admin-service/src/main/resources/mapper/UserInfoMapper.xml new file mode 100644 index 0000000..c6fa4bd --- /dev/null +++ b/g3fo-admin-service/src/main/resources/mapper/UserInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/g3fo-admin-service/src/main/resources/mapper/UserLoginInfoMapper.xml b/g3fo-admin-service/src/main/resources/mapper/UserLoginInfoMapper.xml new file mode 100644 index 0000000..efcd924 --- /dev/null +++ b/g3fo-admin-service/src/main/resources/mapper/UserLoginInfoMapper.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/g3fo-admin-service/src/main/resources/spy.properties b/g3fo-admin-service/src/main/resources/spy.properties new file mode 100644 index 0000000..7092d26 --- /dev/null +++ b/g3fo-admin-service/src/main/resources/spy.properties @@ -0,0 +1,21 @@ +module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory +# 自定义日志打印 +logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger +#日志输出到控制台 +appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger +# 使用日志系统记录 sql +#appender=com.p6spy.engine.spy.appender.Slf4JLogger +# 设置 p6spy driver 代理 +deregisterdrivers=false +# 取消JDBC URL前缀 +useprefix=true +# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset. +excludecategories=info,debug,result,batch,resultset +# 日期格式 +dateformat=yyyy-MM-dd HH:mm:ss +# 实际驱动可多个 +#driverlist=org.h2.Driver +# 是否开启慢SQL记录 +outagedetection=true +# 慢SQL记录标准 2 秒 +outagedetectioninterval=2 diff --git a/g3fo-admin-service/src/test/com/afe/g3fo/user/LoginTest.java b/g3fo-admin-service/src/test/com/afe/g3fo/user/LoginTest.java new file mode 100644 index 0000000..fdb858d --- /dev/null +++ b/g3fo-admin-service/src/test/com/afe/g3fo/user/LoginTest.java @@ -0,0 +1,66 @@ +package com.afe.g3fo.user; + +import cn.hutool.core.bean.BeanUtil; +import com.afe.g3fo.framework.common.Result; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import jakarta.annotation.Resource; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.LocalDateTime; + +/** + * @Author:fengjianhuang + * @Package:PACKAGE_NAME + * @Project:g3fo-user + * @name:LoginTest + * @Date:2023/5/9 13:25 + * @Filename:LoginTest + */ + +@SpringBootTest +public class LoginTest { + @Resource + UserLoginInfoService userLoginInfoService; + @Resource + UserInfoService userInfoService; + @Resource + UserLoginInfoMapper userLoginInfoMapper; + @Resource + UserLoginFacade userLoginFacade; + @Test + void insertData() throws Exception { + UserLoginInfo userLoginInfo =new UserLoginInfo(); + userLoginInfo.setLoginChannel("PT"); + userLoginInfo.setUserName("jim"); + userLoginInfo.setLoginPassword(PasswordEncryptionUtils.encrypt("Afe12345")); + userLoginInfo.setLoginStatus(1); + userLoginInfo.setUserId(231313131133l); + userLoginInfo.setLastLoginDate(LocalDateTime.now()); + userLoginInfo.setPwdExpiryDate(LocalDateTime.now()); +// int insert = userLoginInfoMapper.insert(userLoginInfo); + userLoginInfoService.save(userLoginInfo); +// List list = userInfoService.list(); + System.currentTimeMillis(); + } + @Test + void login(){ + UserLoginReq userLoginReq=new UserLoginReq(); + userLoginReq.setLoginPassword("Afe12345"); + userLoginReq.setUserName("jim"); + userLoginReq.setLoginChannel("PT"); + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.lambda().eq(UserLoginInfo::getUserName,userLoginReq.getUserName()); + queryWrapper.lambda().eq(UserLoginInfo::getLoginChannel,userLoginReq.getLoginChannel()); + UserLoginInfo userLoginInfo = userLoginInfoService.getOne(queryWrapper); + try { + if(PasswordEncryptionUtils.encrypt(userLoginReq.getLoginPassword()).equals(userLoginInfo.getLoginPassword())){ + UserLoginRsp userLoginRsp= BeanUtil.copyProperties(userLoginInfo,UserLoginRsp.class); + return; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/g3fo-admin-service/src/test/com/afe/g3fo/user/UserTest.java b/g3fo-admin-service/src/test/com/afe/g3fo/user/UserTest.java new file mode 100644 index 0000000..dbd515f --- /dev/null +++ b/g3fo-admin-service/src/test/com/afe/g3fo/user/UserTest.java @@ -0,0 +1,36 @@ +package com.afe.g3fo.user; + +import jakarta.annotation.Resource; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.LocalDateTime; + +/** + * @Author:fengjianhuang + * @Package:com.afe.g3fo.user + * @Project:g3fo-user + * @name:UserTest + * @Date:2023/5/9 16:32 + * @Filename:UserTest + */ +@SpringBootTest +public class UserTest { + @Resource + UserInfoService userInfoService; + + @Test + void insertData() throws Exception { + UserInfo userInfo =new UserInfo(); + userInfo.setCreateUser("sys"); + userInfo.setUserName("jim"); + userInfo.setLocalName("jim"); + userInfo.setEngName("jim"); + userInfo.setDepartment(""); + userInfo.setExpiryDate(LocalDateTime.now()); + userInfo.setCreatDate(LocalDateTime.now()); + userInfo.setUserStatus(1); + userInfo.setUserType(1); + userInfoService.save(userInfo); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c1c68a2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + + com.afe.g3fo + g3fo-master + 0.0.1-SNAPSHOT + + g3fo-admin + pom + ${revision} + + + g3fo-user + user service + + + + g3fo-admin-api + g3fo-admin-service + + + + 1.0.0-SNAPSHOT + + + + + + + com.afe.g3fo + g3fo-admin-api + ${project.version} + + + + + +