master
tanyp 2023-03-20 17:29:00 +08:00
parent 0bb0eb66b5
commit f34079757e
30 changed files with 1536 additions and 101 deletions

79
pom.xml
View File

@ -8,78 +8,17 @@
<version>2.7.9</version>
<relativePath/>
</parent>
<groupId>com.tansci</groupId>
<artifactId>tansci-boot</artifactId>
<version>1.0.0</version>
<name>tansci-boot</name>
<groupId>com.tansci</groupId>
<artifactId>tansci-boot-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>tansci-boot-parent</name>
<description>Tansci Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<mybatis-plus-boot.varsion>3.4.3.1</mybatis-plus-boot.varsion>
<druid-spring-boot.varsion>1.2.6</druid-spring-boot.varsion>
<sa-token-spring-boot.varsion>1.34.0</sa-token-spring-boot.varsion>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus-boot.varsion}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid-spring-boot.varsion}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>${sa-token-spring-boot.varsion}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>tansci-boot</module>
</modules>
</project>

View File

@ -11,7 +11,7 @@
Target Server Version : 50721
File Encoding : 65001
Date: 20/03/2023 15:08:06
Date: 20/03/2023 17:12:50
*/
SET NAMES utf8mb4;
@ -249,19 +249,23 @@ DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主键',
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '登录名',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '姓名/昵称',
`nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '姓名/昵称',
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '密码',
`status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '状态',
`type` int(1) NULL DEFAULT NULL COMMENT '用户类型1、管理员2、普通用户',
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '手机号',
`head_portrait` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
`gender` int(1) NULL DEFAULT NULL COMMENT '性别0、男1、女',
`birthday` date NULL DEFAULT NULL COMMENT '出生日期',
`is_login` int(1) NULL DEFAULT 0 COMMENT '禁止登录0未禁用1已禁用',
`sort` int(12) NULL DEFAULT NULL COMMENT '排序',
`office_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '组织机构id',
`is_del` int(1) NULL DEFAULT 0 COMMENT '删除标识0未删除1已删除',
`open_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '唯一标识',
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '地址',
`id_card` varchar(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '身份证号码',
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
`create_by` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建人',
`create_date` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新人',
`update_date` datetime NULL DEFAULT NULL COMMENT '更新时间',
`create_date` datetime NULL DEFAULT NULL COMMENT '创建时间',
`remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`, `username`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;

View File

@ -1,23 +0,0 @@
package com.tansci.handler;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @ClassName GlobalExceptionHandler.java
* @ClassPath com.tansci.handler.GlobalExceptionHandler.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:02
**/
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler
public SaResult handlerException(Exception e) {
e.printStackTrace();
return SaResult.error(e.getMessage());
}
}

92
tansci-boot/pom.xml Normal file
View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tansci</groupId>
<artifactId>tansci-boot-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.tansci</groupId>
<artifactId>tansci-boot</artifactId>
<version>1.0.0</version>
<name>tansci-boot</name>
<description>Tansci Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<mybatis-plus-boot.varsion>3.4.3.1</mybatis-plus-boot.varsion>
<druid-spring-boot.varsion>1.2.6</druid-spring-boot.varsion>
<sa-token-spring-boot.varsion>1.34.0</sa-token-spring-boot.varsion>
<knife4j-spring-boot.version>3.0.3</knife4j-spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus-boot.varsion}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid-spring-boot.varsion}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>${sa-token-spring-boot.varsion}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,69 @@
package com.tansci.common;
import org.apache.commons.lang3.StringUtils;
/**
* @ClassName WrapMapper.java
* @ClassPath com.tansci.common.WrapMapper.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:28
**/
public class WrapMapper {
private WrapMapper() {
}
public static <E> Wrapper<E> wrap(int code, String message, E o) {
return new Wrapper<E>(code, message, o);
}
public static <E> Wrapper<E> wrap(int code, String message) {
return new Wrapper<E>(code, message);
}
public static <E> Wrapper<E> wrap(int code) {
return wrap(code, null);
}
public static <E> Wrapper<E> wrap(Exception e) {
return new Wrapper<E>(Wrapper.ERROR_CODE, e.getMessage());
}
public static <E> E unWrap(Wrapper<E> wrapper) {
return wrapper.getResult();
}
public static <E> Wrapper<E> illegalArgument() {
return wrap(Wrapper.ILLEGAL_ARGUMENT_CODE_, Wrapper.ILLEGAL_ARGUMENT_MESSAGE);
}
public static <E> Wrapper<E> error() {
return wrap(Wrapper.ERROR_CODE, Wrapper.ERROR_MESSAGE);
}
public static <E> Wrapper<E> error(String message) {
return wrap(Wrapper.ERROR_CODE, StringUtils.isBlank(message) ? Wrapper.ERROR_MESSAGE : message);
}
public static <E> Wrapper<E> error(int code, String message) {
return wrap(code, StringUtils.isBlank(message) ? Wrapper.ERROR_MESSAGE : message);
}
public static <E> Wrapper<E> ok() {
return new Wrapper<E>();
}
public static <E> Wrapper<E> wrap(E o) {
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, o);
}
public static <E> Wrapper<E> ok(E o) {
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, o);
}
public static <E> Wrapper<E> success() {
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE);
}
}

View File

@ -0,0 +1,206 @@
package com.tansci.common;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
/**
* @ClassName Wrapper.java
* @ClassPath com.tansci.common.Wrapper.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:29
**/
public class Wrapper<T> implements Serializable {
/**
* .
*/
public static final int SUCCESS_CODE = 200;
/**
* .
*/
public static final String SUCCESS_MESSAGE = "操作成功";
/**
* .
*/
public static final int ERROR_CODE = 500;
/**
* .
*/
public static final String ERROR_MESSAGE = "系统异常,请稍后重试!";
/**
*
*/
public static final int ILLEGAL_ARGUMENT_CODE_ = 400;
/**
*
*/
public static final String ILLEGAL_ARGUMENT_MESSAGE = "请求参数非法,请核查!";
/**
*
*/
public static final int AUTHORIZATION_CODE = 403;
/**
*
*/
public static final String AUTHORIZATION_MESSAGE = "用户凭证已过期,请重新登录!";
/**
* .
*/
private int code;
/**
* .
*/
private String message;
/**
*
*/
private T result;
/**
* Instantiates a new wrapper. default code=200
*/
public Wrapper() {
this(SUCCESS_CODE, SUCCESS_MESSAGE);
}
/**
* Instantiates a new wrapper.
*
* @param code the code
* @param message the message
*/
public Wrapper(int code, String message) {
this.code(code).message(message);
}
/**
* Instantiates a new wrapper.
*
* @param code the code
* @param message the message
* @param result the result
*/
public Wrapper(int code, String message, T result) {
super();
this.code(code).message(message).result(result);
}
/**
* Gets the .
*
* @return the
*/
public int getCode() {
return code;
}
/**
* Sets the .
*
* @param code the new
*/
public void setCode(int code) {
this.code = code;
}
/**
* Gets the .
*
* @return the
*/
public String getMessage() {
return message;
}
/**
* Sets the .
*
* @param message the new
*/
public void setMessage(String message) {
this.message = message;
}
/**
* Gets the .
*
* @return the
*/
public T getResult() {
return result;
}
/**
* Sets the .
*
* @param result the new
*/
public void setResult(T result) {
this.result = result;
}
/**
* Sets the .
*
* @param code the new
* @return the wrapper
*/
public Wrapper<T> code(int code) {
this.setCode(code);
return this;
}
/**
* Sets the .
*
* @param message the new
* @return the wrapper
*/
public Wrapper<T> message(String message) {
this.setMessage(message);
return this;
}
/**
* Sets the .
*
* @param result the new
* @return the wrapper
*/
public Wrapper<T> result(T result) {
this.setResult(result);
return this;
}
@Override
public String toString() {
return "Wrapper{" +
"code=" + code +
", message='" + message + '\'' +
", result=" + result +
'}';
}
@JsonIgnore
public boolean isSuccess() {
return this.getCode() == Wrapper.SUCCESS_CODE;
}
@JsonIgnore
public boolean isFail() {
return !isSuccess();
}
}

View File

@ -0,0 +1,21 @@
package com.tansci.common.constant;
/**
* @ClassName Constants.java
* @ClassPath com.tansci.common.constant.Constants.java
* @Description
* @Author tanyp
* @Date 2023/3/20 17:02
**/
public class Constants {
/**
*
*/
public final static Integer NOT_DEL_FALG = 0;
/**
*
*/
public final static Integer IS_DEL_FALG = 1;
}

View File

@ -0,0 +1,48 @@
package com.tansci.common.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.Objects;
/**
* @ClassName Enums.java
* @ClassPath com.tansci.common.constant.Enums.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:25
**/
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum Enums {
/**
*
*/
USER_GENDER_MALE(0, "user_gender", "男"),
USER_GENDER_GIRL(1, "user_gender", "女"),
/**
*
*/
USER_TYPE_1(1, "user_type", "管理员"),
USER_TYPE_2(2, "user_type", "商户"),
;
private Integer key;
private String group;
private String value;
public static String getVlaueByGroup(Integer key, String group) {
for (Enums item : Enums.values()) {
if (Objects.equals(key, item.key) && Objects.equals(group, item.group)) {
return item.getValue();
}
}
return null;
}
}

View File

@ -0,0 +1,27 @@
package com.tansci.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* @ClassName CorsConfig.java
* @ClassPath com.tansci.config.CorsConfig.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:23
**/
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路由
registry.addMapping("/**")
.allowedOriginPatterns("*") // 设置允许跨域请求的域名
.allowCredentials(true) // 是否允许证书cookies
.allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS") // 设置允许的方法
.maxAge(3600); // 跨域允许时间
}
}

View File

@ -0,0 +1,48 @@
package com.tansci.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @ClassName Knife4jConfig.java
* @ClassPath com.tansci.config.Knife4jConfig.java
* @Description Knife4j
* @Author tanyp
* @Date 2023/3/20 15:22
**/
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Knife4jConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.tansci.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API 文档")
.description("接口文档")
.contact(new Contact("tanyp", "http://127.0.0.1:8081/doc.html", ""))
.version("1.0.0")
.build();
}
}

View File

@ -0,0 +1,28 @@
package com.tansci.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName MybatisPlusConfig.java
* @ClassPath com.tansci.config.MybatisPlusConfig.java
* @Description MybatisPlus
* @Author tanyp
* @Date 2023/3/20 15:24
**/
@Configuration
@MapperScan("com.tansci.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}

View File

@ -0,0 +1,43 @@
package com.tansci.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.tansci.common.WrapMapper;
import com.tansci.common.Wrapper;
import com.tansci.domain.SysUser;
import com.tansci.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @ClassName AuthController.java
* @ClassPath com.tansci.controller.AuthController.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:52
**/
@Slf4j
@RestController
@RequestMapping("/auth")
@Api(value = "auth", tags = "鉴权管理")
public class AuthController {
@Autowired
private SysUserService sysUserService;
@ApiOperation(value = "登录", notes = "登录")
@PostMapping("/login")
public Wrapper<SysUser> login(@RequestBody SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.login(user.getUsername()));
}
@ApiOperation(value = "登出", notes = "登出")
@GetMapping("/logout")
public Wrapper<Object> logout() {
StpUtil.logout();
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, "登出成功!");
}
}

View File

@ -0,0 +1,69 @@
package com.tansci.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tansci.common.WrapMapper;
import com.tansci.common.Wrapper;
import com.tansci.domain.SysUser;
import com.tansci.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @ClassName SysUserController.java
* @ClassPath com.tansci.controller.SysUserController.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:52
**/
@Slf4j
@RestController
@RequestMapping("/user")
@Api(value = "user", tags = "用户管理")
public class SysUserController {
@Autowired
private SysUserService sysUserService;
@ApiOperation(value = "用户分页", notes = "用户分页")
@GetMapping("/page")
public Wrapper<IPage<SysUser>> page(Page page, SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.page(page, user));
}
@ApiOperation(value = "用户列表", notes = "用户列表")
@GetMapping("/list")
public Wrapper<List<SysUser>> list(SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.list(user));
}
@ApiOperation(value = "添加用户信息", notes = "添加用户信息")
@PostMapping("/save")
public Wrapper<Boolean> save(@RequestBody SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.save(user));
}
@ApiOperation(value = "修改用户信息", notes = "修改用户信息")
@PostMapping("/update")
public Wrapper<Boolean> update(@RequestBody SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.update(user));
}
@ApiOperation(value = "删除用户", notes = "删除用户")
@GetMapping("/del")
public Wrapper<Boolean> del(SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.del(user));
}
@ApiOperation(value = "修改密码", notes = "修改密码")
@PostMapping("/modifyPass")
public Wrapper<Integer> modifyPass(@RequestBody SysUser user) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysUserService.modifyPass(user));
}
}

View File

@ -0,0 +1,83 @@
package com.tansci.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;
/**
* @ClassName SysDic.java
* @ClassPath com.tansci.SysDic.java
* @Description
* @Author tanyp
* @Date 2023/03/20 10:38
**/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "sys_dic")
@ApiModel(value = "数据字典")
public class SysDic {
@TableId(type = IdType.ASSIGN_UUID)
@ApiModelProperty(value = "主键id", hidden = true)
private String id;
@ApiModelProperty(value = "父ID")
private String parentId;
@ApiModelProperty(value = "分组名称")
private String groupName;
@ApiModelProperty(value = "类型0、系统1、业务")
private Integer type;
@TableField(exist = false)
@ApiModelProperty(value = "类型名称")
private String typeName;
@ApiModelProperty(value = "值")
private Integer dicValue;
@ApiModelProperty(value = "名称")
private String dicLabel;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "预留字段1")
private String text1;
@ApiModelProperty(value = "预留字段3")
private String text2;
@ApiModelProperty(value = "预留字段2")
private String text3;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间")
private LocalDateTime updateTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "描述")
private String remarks;
@TableField(exist = false)
private List<SysDic> children;
}

View File

@ -0,0 +1,86 @@
package com.tansci.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;
/**
* @ClassName SysMenu.java
* @ClassPath com.tansci.domain.SysMenu.java
* @Description
* @Author tanyp
* @Date 2023/03/20 10:38
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName(value = "sys_menu")
@ApiModel(value = "菜单")
public class SysMenu {
@TableId(type = IdType.ASSIGN_UUID)
@ApiModelProperty(value = "主键id", hidden = true)
private String id;
@ApiModelProperty(value = "菜单名称")
private String name;
@ApiModelProperty(value = "中文名称")
private String chineseName;
@ApiModelProperty(value = "英文名称")
private String englishName;
@ApiModelProperty(value = "父菜单ID")
private String parentId;
@ApiModelProperty(value = "状态0删除1正常2禁用")
private Integer status;
@ApiModelProperty(value = "菜单UR")
private String url;
@ApiModelProperty(value = "图标")
private String icon;
@ApiModelProperty(value = "级别")
private Integer level;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "类型0、菜单1、按钮2、链接3、嵌套页面")
private Integer type;
@ApiModelProperty(value = "描述")
private String remarks;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间")
private LocalDateTime updateTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@TableField(exist = false)
@ApiModelProperty(value = "角色id")
private String roleId;
@TableField(exist = false)
@ApiModelProperty(value = "子级菜单")
private List<SysMenu> children;
}

View File

@ -0,0 +1,60 @@
package com.tansci.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @ClassName SysRole.java
* @ClassPath com.tansci.domain.SysRole.java
* @Description
* @Author tanyp
* @Date 2023/03/20 10:38
**/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "sys_role")
@ApiModel(value = "权限")
public class SysRole {
@TableId(type = IdType.ASSIGN_UUID)
@ApiModelProperty(value = "主键id")
private String id;
@ApiModelProperty(value = "角色名称")
private String name;
@ApiModelProperty(value = "状态0、默认1、启用2、禁用")
private Integer status;
@TableField(exist = false)
private String statusName;
@ApiModelProperty(value = "创建人")
private String creator;
@TableField(exist = false)
private String creatorName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "更新时间")
private LocalDateTime updateTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "描述")
private String remarks;
}

View File

@ -0,0 +1,108 @@
package com.tansci.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* @pathcom.tansci.domain.SysUser.java
* @classNameSysUser.java
* @description
* @authortanyp
* @dateTime2023/03/20 10:38
* @editNote
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "sys_user")
@ApiModel(value = "用户")
public class SysUser {
@ApiModelProperty(value = "主键ID")
@TableId(type = IdType.ASSIGN_UUID)
private String id;
@ApiModelProperty(value = "用户名称")
private String username;
@ApiModelProperty(value = "密码")
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private String password;
@ApiModelProperty(value = "用户昵称")
private String nickname;
@ApiModelProperty(value = "用户类型1、管理员2、普通用户")
private Integer type;
@TableField(exist = false)
private String typeName;
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "头像")
private String avatar;
@ApiModelProperty(value = "性别0、男1、女")
private Integer gender;
@TableField(exist = false)
private String genderName;
@ApiModelProperty(value = "出生日期")
private LocalDate birthday;
@ApiModelProperty(value = "地址")
private String address;
@ApiModelProperty(value = "唯一标识")
private String openId;
@ApiModelProperty(value = "身份证号码")
private String idCard;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "禁止登录0未禁用1已禁用")
private Integer isLogin;
@ApiModelProperty(value = "删除标识0未删除1已删除")
private Integer isDel;
@ApiModelProperty(value = "创建人")
private String createBy;
@ApiModelProperty(value = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
private LocalDateTime updateTime;
@ApiModelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
private LocalDateTime createTime;
@ApiModelProperty(value = "备注")
private String remarks;
@TableField(exist = false)
@ApiModelProperty(value = "角色id")
private String roleId;
@TableField(exist = false)
@ApiModelProperty(value = "token")
private String token;
}

View File

@ -0,0 +1,42 @@
package com.tansci.exception;
import lombok.Getter;
/**
* @ClassName BusinessException.java
* @ClassPath com.tansci.exception.BusinessException.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:31
**/
@Getter
public class BusinessException extends RuntimeException {
/**
*
*/
private int code = 500;
/**
*
*/
private String message;
public BusinessException(String message) {
super(message);
this.message = message;
}
public BusinessException(int code, String message) {
super(message);
this.code = code;
this.message = message;
}
public BusinessException(int code, String message, Throwable throwable) {
super(message, throwable);
this.code = code;
this.message = message;
}
}

View File

@ -0,0 +1,44 @@
package com.tansci.handler;
import com.tansci.common.WrapMapper;
import com.tansci.common.Wrapper;
import com.tansci.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @ClassName GlobalExceptionHandler.java
* @ClassPath com.tansci.handler.GlobalExceptionHandler.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:02
**/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
// @ExceptionHandler
// public SaResult handlerException(Exception e) {
// e.printStackTrace();
// return SaResult.error(e.getMessage());
// }
@ExceptionHandler(value = Exception.class)
public Wrapper handleException(Exception e) {
if (e instanceof BusinessException) {
BusinessException ex = (BusinessException) e;
log.error("系统自定义业务异常:{}", ex.getMessage());
return WrapMapper.wrap(ex.getCode(), ex.getMessage(), null);
} else if (e instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex = (MethodArgumentNotValidException) e;
log.error("参数校验异常:{}", ex.getBindingResult().getFieldError().getDefaultMessage());
return WrapMapper.wrap(Wrapper.ILLEGAL_ARGUMENT_CODE_, "参数有误:" + ex.getBindingResult().getFieldError().getDefaultMessage(), null);
} else {
log.error("统一系统异常:{}", e);
return WrapMapper.wrap(Wrapper.ERROR_CODE, Wrapper.ERROR_MESSAGE, null);
}
}
}

View File

@ -0,0 +1,16 @@
package com.tansci.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tansci.domain.SysUser;
import org.apache.ibatis.annotations.Mapper;
/**
* @ClassName SysUserMapper.java
* @ClassPath com.tansci.mapper.SysUserMapper.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:50
**/
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
}

View File

@ -0,0 +1,33 @@
package com.tansci.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tansci.domain.SysUser;
import java.util.List;
/**
* @ClassName SysUserService.java
* @ClassPath com.tansci.service.SysUserService.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:51
**/
public interface SysUserService extends IService<SysUser> {
IPage<SysUser> page(Page page, SysUser user);
List<SysUser> list(SysUser user);
Integer modifyPass(SysUser user);
boolean save(SysUser user);
boolean update(SysUser user);
boolean del(SysUser user);
SysUser login(String username);
}

View File

@ -0,0 +1,110 @@
package com.tansci.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tansci.common.constant.Constants;
import com.tansci.domain.SysUser;
import com.tansci.exception.BusinessException;
import com.tansci.mapper.SysUserMapper;
import com.tansci.service.SysUserService;
import com.tansci.utils.Sha256Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
/**
* @ClassName SysUserServiceImpl.java
* @ClassPath com.tansci.service.impl.SysUserServiceImpl.java
* @Description
* @Author tanyp
* @Date 2023/3/20 15:51
**/
@Slf4j
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
@Override
public IPage<SysUser> page(Page page, SysUser user) {
return this.baseMapper.selectPage(page,
Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getIsDel, Constants.NOT_DEL_FALG)
.eq(Objects.nonNull(user.getUsername()), SysUser::getUsername, user.getUsername())
.eq(Objects.nonNull(user.getPhone()), SysUser::getPhone, user.getPhone())
.eq(Objects.nonNull(user.getNickname()), SysUser::getNickname, user.getNickname())
.eq(Objects.nonNull(user.getType()), SysUser::getType, user.getType())
);
}
@Override
public List<SysUser> list(SysUser user) {
return this.baseMapper.selectList(
Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getIsDel, Constants.NOT_DEL_FALG)
.eq(Objects.nonNull(user.getType()), SysUser::getType, user.getType())
);
}
@Override
public Integer modifyPass(SysUser user) {
SysUser sysUser = this.baseMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, user.getUsername()));
if (Objects.isNull(sysUser) || !Objects.equals(Sha256Util.getSHA256(sysUser.getPassword()), Sha256Util.getSHA256(user.getPassword()))) {
throw new BusinessException("原始密码错误,请重新输入!");
}
sysUser.setPassword(Sha256Util.getSHA256(user.getPassword()));
sysUser.setUpdateTime(LocalDateTime.now());
return this.baseMapper.updateById(sysUser);
}
@Override
public boolean save(SysUser user) {
Integer count = this.baseMapper.selectCount(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, user.getUsername()));
if (Objects.nonNull(count) && count > 0) {
throw new BusinessException("用户名称已存在!");
}
user.setIsDel(Constants.NOT_DEL_FALG);
user.setCreateTime(LocalDateTime.now());
user.setPassword(Sha256Util.getSHA256(user.getPassword()));
int row = this.baseMapper.insert(user);
return false;
}
@Override
public boolean update(SysUser user) {
user.setUpdateTime(LocalDateTime.now());
int row = this.baseMapper.updateById(user);
return false;
}
@Override
public boolean del(SysUser user) {
user.setIsDel(Constants.IS_DEL_FALG);
this.baseMapper.updateById(user);
return false;
}
@Override
public SysUser login(String username) {
SysUser user = this.baseMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
if (Objects.nonNull(user)) {
// 生成token
StpUtil.login(user.getId());
// 获取token信息
return SysUser.builder()
.username(user.getUsername())
.nickname(user.getNickname())
.type(user.getType())
.token(StpUtil.getTokenInfo().getTokenValue())
.build();
}
return null;
}
}

View File

@ -0,0 +1,45 @@
package com.tansci.utils;
import java.io.UnsupportedEncodingException;
/**
* @ClassName Md5Utils.java
* @ClassPath com.tansci.utils.Md5Utils.java
* @Description MD5
* @Author tanyp
* @Date 2023/3/20 15:34
**/
public class Md5Utils {
private static final int HEX_VALUE_COUNT = 16;
public static String getMD5(byte[] bytes) {
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char[] str = new char[16 * 2];
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
md.update(bytes);
byte[] tmp = md.digest();
int k = 0;
for (int i = 0; i < HEX_VALUE_COUNT; i++) {
byte byte0 = tmp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
} catch (Exception e) {
e.printStackTrace();
}
return new String(str);
}
public static String getMD5(String value, String encode) {
String result = "";
try {
result = getMD5(value.getBytes(encode));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -0,0 +1,56 @@
package com.tansci.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @ClassName Sha256Util.java
* @ClassPath com.tansci.utils.Sha256Util.java
* @Description SHA256
* @Author tanyp
* @Date 2023/3/20 15:33
**/
public class Sha256Util {
/**
* javaSHA256
*
* @param str
* @return
*/
public static String getSHA256(String str) {
MessageDigest messageDigest;
String encodestr = "";
try {
messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(str.getBytes("UTF-8"));
encodestr = byte2Hex(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return encodestr;
}
/**
* byte16
*
* @param bytes
* @return
*/
private static String byte2Hex(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer();
String temp = null;
for (int i = 0; i < bytes.length; i++) {
temp = Integer.toHexString(bytes[i] & 0xFF);
if (temp.length() == 1) {
//1得到一位的进行补0操作
stringBuffer.append("0");
}
stringBuffer.append(temp);
}
return stringBuffer.toString();
}
}

View File

@ -0,0 +1,151 @@
package com.tansci.utils;
import javax.servlet.http.HttpServletRequest;
/**
* @ClassName SystemUtils.java
* @ClassPath com.tansci.utils.SystemUtils.java
* @Description SystemUtils
* @Author tanyp
* @Date 2023/3/20 15:32
**/
public class SystemUtils {
/**
* @MonthName getOS
* @Description
* @Author tanyp
* @Date 2022/6/1 15:30
* @Param [request]
* @return java.lang.String
**/
public static String getOS(HttpServletRequest request) {
String osName = "";
String userAgent = request.getHeader("User-Agent").toUpperCase();
if (userAgent.contains("WINDOWS")) {
if (userAgent.contains("WINDOWS NT 10.0")) {
osName = "Windows 10";
} else if (userAgent.contains("WINDOWS NT 6.3")) {
osName = "Windows 8.1";
} else if (userAgent.contains("WINDOWS NT 6.2")) {
osName = "Windows 8";
} else if (userAgent.contains("WINDOWS NT 6.1")) {
osName = "Windows 7";
} else if (userAgent.contains("WINDOWS NT 6.0")) {
osName = "Windows Vista";
} else if (userAgent.contains("WINDOWS NT 5.2")) {
osName = "Windows XP";
} else if (userAgent.contains("WINDOWS NT 5.1")) {
osName = "Windows XP";
} else if (userAgent.contains("WINDOWS NT 5.01")) {
osName = "Windows 2000";
} else if (userAgent.contains("WINDOWS NT 5.0")) {
osName = "Windows 2000";
} else if (userAgent.contains("WINDOWS NT 4.0")) {
osName = "Windows NT 4.0";
} else if (userAgent.contains("WINDOWS 98; WIN 9X 4.90")) {
osName = "Windows ME";
} else if (userAgent.contains("WINDOWS 98")) {
osName = "Windows 98";
} else if (userAgent.contains("WINDOWS 95")) {
osName = "Windows 95";
} else if (userAgent.contains("WINDOWS CE")) {
osName = "Windows CE";
}
} else if (userAgent.contains("MAC")) {
osName = "Mac";
} else if (userAgent.contains("UNIX")) {
osName = "UNIX";
} else if (userAgent.contains("LINUX")) {
osName = "Linux";
} else if (userAgent.contains("SUNOS")) {
osName = "SunOS";
}
return osName;
}
/**
* @MonthName getBrowser
* @Description
* @Author tanyp
* @Date 2022/6/1 15:29
* @Param [request]
* @return java.lang.String
**/
public static String getBrowser(HttpServletRequest request) {
String browserName = "";
String userAgent = request.getHeader("User-Agent").toUpperCase();
if (userAgent == null || userAgent.equals("")) {
return "";
}
if (userAgent.indexOf("MSIE") > 0) {
browserName = "IE";
} else if (userAgent.indexOf("FIREFOX") > 0) {
browserName = "Firefox";
} else if (userAgent.indexOf("CHROME") > 0) {
browserName = "Chrome";
} else if (userAgent.indexOf("SAFARI") > 0) {
browserName = "Safari";
} else if (userAgent.indexOf("CAMINO") > 0) {
browserName = "Camino";
} else if (userAgent.indexOf("KONQUEROR") > 0) {
browserName = "Konqueror";
} else if (userAgent.indexOf("EDGE") > 0) {
browserName = "Microsoft Edge";
}
return browserName;
}
/**
* @methodNamegetIpAddress
* @descriptionIP
* @authortanyp
* @dateTime2022/2/15 14:19
* @Params [request]
* @Return java.lang.String
* @editNote
*/
public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_VIA");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("REMOTE_ADDR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if (ip.contains(",")) {
return ip.split(",")[0];
} else {
return ip;
}
}
}

View File

@ -0,0 +1,30 @@
package com.tansci.utils;
import java.util.UUID;
/**
* @ClassName UUIDUtils.java
* @ClassPath com.tansci.utils.UUIDUtils.java
* @Description UUID
* @Author tanyp
* @Date 2023/3/20 15:33
**/
public class UUIDUtils {
public static String getUUID() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
/**
* @MonthName getUUID
* @Description
* @Author tanyp
* @Date 2022/03/29 10:38
* @Param [len]
* @return java.lang.String
**/
public static String getUUID(Integer len) {
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
}
}