init project v1.0.0
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
# microservices-platform
|
||||
|
||||
## 如果您觉得有帮助,请点右上角 "Star" 支持一下谢谢
|
||||
|
||||
[TOC]
|
||||
|
||||
## 1. 项目介绍
|
||||
|
||||
* 技术交流群 [250883130](http://shang.qq.com/wpa/qunwpa?idkey=17544199255998bda0d938fb72b08d076c40c52c9904520b76eb5eb0585da71e)
|
||||
* **详细在线文档** [点击查看](https://www.kancloud.cn/zlt2000/microservices-platform/919412)
|
||||
* 前后端分离的企业级微服务架构
|
||||
* 基于`Spring Boot 2.0.X`、`Spring Cloud Finchley`和`Spring Cloud Alibaba`
|
||||
* 深度定制`Spring Security`真正实现了基于`RBAC`、`jwt`和`oauth2`的无状态统一权限认证的解决方案
|
||||
* 提供应用管理,方便第三方系统接入
|
||||
* 引入组件化的思想实现高内聚低耦合,项目代码简洁注释丰富上手容易
|
||||
* 注重代码规范,严格控制包依赖,每个工程基本都是最小依赖
|
||||
* 非常适合学习和企业中使用
|
||||
|
||||
## 2. 功能介绍
|
||||
|
||||
* **统一认证功能**
|
||||
* 支持oauth2的四种模式登录
|
||||
* 支持用户名、密码加图形验证码登录
|
||||
* 支持手机号加密码登录
|
||||
* 支持openId登录
|
||||
* 支持第三方系统单点登录
|
||||
* **分布式系统基础支撑**
|
||||
* 服务注册发现、路由与负载均衡
|
||||
* 服务降级与熔断
|
||||
* 服务调用链监控
|
||||
* 统一配置中心
|
||||
* 统一日志中心
|
||||
* 统一分布式缓存操作类、cacheManager配置扩展
|
||||
* 分布式锁
|
||||
* 分布式任务调度器
|
||||
* 应用监控(应用健康、JVM、内存、线程)
|
||||
* 慢查询SQL监控
|
||||
* **业务基础功能支撑**
|
||||
* 高性能方法级幂等性支持
|
||||
* RBAC权限管理,实现细粒度控制(方法、url级别)
|
||||
* 快速实现导入、导出功能
|
||||
* 数据库访问层自动实现crud操作
|
||||
* 代码生成器
|
||||
* 基于Hutool的各种便利开发工具
|
||||
* 网关聚合所有服务的Swagger接口文档
|
||||
* 统一跨域处理
|
||||
* 统一异常处理
|
||||
|
||||
## 3. 模块说明
|
||||
|
||||
```lua
|
||||
central-platform -- 父项目,公共依赖
|
||||
│ ├─zlt-business -- 业务模块一级工程
|
||||
│ │ ├─user-center -- 用户中心[7000]
|
||||
│ │ ├─file-center -- 文件中心[5000]
|
||||
│ │ ├─generator-center -- 代码生成器[7300]
|
||||
│ │─zlt-commons -- 通用工具一级工程
|
||||
│ │ ├─zlt-auth-client-spring-boot-starter -- 封装spring security client端的通用操作逻辑
|
||||
│ │ ├─zlt-common-spring-boot-starter -- 封装通用操作逻辑
|
||||
│ │ ├─zlt-db-spring-boot-starter -- 封装数据库通用操作逻辑
|
||||
│ │ ├─zlt-log-spring-boot-starter -- 封装log通用操作逻辑
|
||||
│ │ ├─zlt-redis-spring-boot-starter -- 封装Redis通用操作逻辑
|
||||
│ │ ├─zlt-ribbon-spring-boot-starter -- 封装Ribbon和Feign的通用操作逻辑
|
||||
│ │ ├─zlt-swagger2-spring-boot-starter -- 封装Swagger通用操作逻辑
|
||||
│ │ ├─zlt-mq-spring-boot-starter -- 封装mq通用操作逻辑
|
||||
│ ├─zlt-config -- 配置中心
|
||||
│ ├─zlt-doc -- 项目文档
|
||||
│ ├─zlt-gateway -- api网关一级工程
|
||||
│ │ ├─spring-cloud-gateway -- 开发中..
|
||||
│ │ ├─zuul-gateway -- netflix-zuul[9200]
|
||||
│ ├─zlt-job -- 分布式任务调度一级工程
|
||||
│ │ ├─job-admin -- 任务管理器[8081]
|
||||
│ │ ├─job-core -- 任务调度核心代码
|
||||
│ │ ├─job-executor-samples -- 任务执行者executor样例[8082]
|
||||
│ ├─zlt-monitor -- 监控一级工程
|
||||
│ │ ├─sc-admin -- 应用监控[6500]
|
||||
│ │ ├─log-center -- 日志中心[6200]
|
||||
│ ├─zlt-uaa -- spring-security认证中心[8000]
|
||||
│ ├─zlt-register -- 注册中心Nacos[8848]
|
||||
│ ├─zlt-search -- 搜索引擎一级工程
|
||||
│ ├─zlt-web -- 前端一级工程
|
||||
│ │ ├─back-web -- 后台前端[8066]
|
||||
```
|
||||
|
||||
## 4. 截图(点击可大图预览)
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/登录.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/权限分配.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/代码生成器.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/文档中心.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/日志中心01.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/日志中心02.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/慢查询sql.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/任务中心.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/应用监控01.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/应用监控02.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/nacos-conf.png"/></td>
|
||||
<td><img src="zlt-doc/截屏/nacos-discovery.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="zlt-doc/截屏/elk.png"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -0,0 +1,319 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>8</java.version>
|
||||
<commons-collections4.version>4.2</commons-collections4.version>
|
||||
<fastjson.version>1.2.54</fastjson.version>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
<swagger.ui.version>1.8.7</swagger.ui.version>
|
||||
<swagger.mg.ui.version>1.0.6</swagger.mg.ui.version>
|
||||
<swagger.butler.version>1.2.0</swagger.butler.version>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<druid-starter>1.1.10</druid-starter>
|
||||
<jasypt.version>1.14</jasypt.version>
|
||||
<sharding-jdbc>2.0.3</sharding-jdbc>
|
||||
<security-oauth2.version>2.3.4.RELEASE</security-oauth2.version>
|
||||
<security-jwt.version>1.0.9.RELEASE</security-jwt.version>
|
||||
<redisson.version>3.9.1</redisson.version>
|
||||
<kaptcha.version>0.0.9</kaptcha.version>
|
||||
<hutool.version>4.3.1</hutool.version>
|
||||
<mybatis-plus-boot-starter.version>3.0.6</mybatis-plus-boot-starter.version>
|
||||
<aliyun-sdk-oss>3.4.0</aliyun-sdk-oss>
|
||||
<qiniu-java-sdk>7.2.17</qiniu-java-sdk>
|
||||
<easypoi.version>3.0.3</easypoi.version>
|
||||
<spring-boot-admin.version>2.0.4</spring-boot-admin.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<commons-configuration.version>1.10</commons-configuration.version>
|
||||
<platform-bom>Cairo-SR3</platform-bom>
|
||||
<spring-cloud-alibaba-dependencies.version>0.2.1.RELEASE</spring-cloud-alibaba-dependencies.version>
|
||||
<spring-boot-dependencies.version>2.0.8.RELEASE</spring-boot-dependencies.version>
|
||||
<spring-cloud-dependencies.version>Finchley.SR2</spring-cloud-dependencies.version>
|
||||
<spring-boot-maven-plugin.version>2.1.1.RELEASE</spring-boot-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- 自定义 starter -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-swagger2-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<!-- druid 官方 starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid-starter}</version>
|
||||
</dependency>
|
||||
<!-- mybatis-plus start -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mybatis-plus-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<!-- 加入spring security spring security oauth2的处理 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth</groupId>
|
||||
<artifactId>spring-security-oauth2</artifactId>
|
||||
<version>${security-oauth2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-jwt</artifactId>
|
||||
<version>${security-jwt.version}</version>
|
||||
</dependency>
|
||||
<!-- 在Redis基础上的一个Java实用工具包 -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-bean-validators</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>${swagger.ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>swagger-mg-ui</artifactId>
|
||||
<version>${swagger.mg.ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.didispace</groupId>
|
||||
<artifactId>swagger-butler-core</artifactId>
|
||||
<version>${swagger.butler.version}</version>
|
||||
</dependency>
|
||||
<!-- kaptcha 验证码生成工具 -->
|
||||
<dependency>
|
||||
<groupId>com.github.axet</groupId>
|
||||
<artifactId>kaptcha</artifactId>
|
||||
<version>${kaptcha.version}</version>
|
||||
</dependency>
|
||||
<!-- hutool java工具类库 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>${aliyun-sdk-oss}</version>
|
||||
</dependency>
|
||||
<!-- 七牛依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>${qiniu-java-sdk}</version>
|
||||
</dependency>
|
||||
<!-- easypoi -->
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-base</artifactId>
|
||||
<version>${easypoi.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-web</artifactId>
|
||||
<version>${easypoi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-annotation</artifactId>
|
||||
<version>${easypoi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>${mybatis-plus-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||
<version>${spring-boot-admin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>${velocity.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>${commons-configuration.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spring.platform</groupId>
|
||||
<artifactId>platform-bom</artifactId>
|
||||
<version>${platform-bom}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<!-- 公共 -->
|
||||
<module>zlt-commons</module>
|
||||
<!-- 认证 -->
|
||||
<module>zlt-uaa</module>
|
||||
<!-- 网关 -->
|
||||
<module>zlt-gateway</module>
|
||||
<!-- 业务 -->
|
||||
<module>zlt-business</module>
|
||||
<!-- 前端 -->
|
||||
<module>zlt-web</module>
|
||||
<!-- 任务 -->
|
||||
<module>zlt-job</module>
|
||||
<!-- 监控 -->
|
||||
<module>zlt-monitor</module>
|
||||
<!-- 搜索 -->
|
||||
<module>zlt-search</module>
|
||||
<!-- 配置 -->
|
||||
<module>zlt-config</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
*.iml
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,80 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>code-generator</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-swagger2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.central.generator;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class CodeGeneratorApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CodeGeneratorApp.class, args);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.central.generator.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.generator.service.SysGeneratorService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
/**
|
||||
* @Author: zlt
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "代码生成器")
|
||||
@RequestMapping("/generator")
|
||||
public class SysGeneratorController {
|
||||
@Autowired
|
||||
private SysGeneratorService sysGeneratorService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("/list")
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
return sysGeneratorService.queryList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*/
|
||||
@RequestMapping("/code")
|
||||
public void code(String tables, HttpServletResponse response) throws IOException {
|
||||
byte[] data = sysGeneratorService.generatorCode(tables.split(","));
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"generator.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.generator.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zlt
|
||||
*/
|
||||
@Component
|
||||
@Mapper
|
||||
public interface SysGeneratorMapper extends SuperMapper {
|
||||
List<Map<String, Object>> queryList(Page<Map<String, Object>> page, @Param("p") Map<String, Object> map);
|
||||
|
||||
int queryTotal(Map<String, Object> map);
|
||||
|
||||
Map<String, String> queryTable(String tableName);
|
||||
|
||||
List<Map<String, String>> queryColumns(String tableName);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package com.central.generator.model;
|
||||
|
||||
/**
|
||||
* @Author: zlt
|
||||
*/
|
||||
public class ColumnEntity {
|
||||
/**
|
||||
* 列名
|
||||
*/
|
||||
private String columnName;
|
||||
/**
|
||||
* 列名类型
|
||||
*/
|
||||
private String dataType;
|
||||
/**
|
||||
* 列名备注
|
||||
*/
|
||||
private String comments;
|
||||
/**
|
||||
* 属性名称(第一个字母大写),如:user_name => UserName
|
||||
*/
|
||||
private String attrName;
|
||||
/**
|
||||
* 属性名称(第一个字母小写),如:user_name => userName
|
||||
*/
|
||||
private String attrname;
|
||||
/**
|
||||
* 属性类型
|
||||
*/
|
||||
private String attrType;
|
||||
/**
|
||||
* auto_increment
|
||||
*/
|
||||
private String extra;
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(String comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public String getAttrName() {
|
||||
return attrName;
|
||||
}
|
||||
|
||||
public void setAttrName(String attrName) {
|
||||
this.attrName = attrName;
|
||||
}
|
||||
|
||||
public String getAttrname() {
|
||||
return attrname;
|
||||
}
|
||||
|
||||
public void setAttrname(String attrname) {
|
||||
this.attrname = attrname;
|
||||
}
|
||||
|
||||
public String getAttrType() {
|
||||
return attrType;
|
||||
}
|
||||
|
||||
public void setAttrType(String attrType) {
|
||||
this.attrType = attrType;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.central.generator.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: zlt
|
||||
*/
|
||||
public class TableEntity {
|
||||
/**
|
||||
* 表的名称
|
||||
*/
|
||||
private String tableName;
|
||||
/**
|
||||
* 表的备注
|
||||
*/
|
||||
private String comments;
|
||||
/**
|
||||
* 表的主键
|
||||
*/
|
||||
private ColumnEntity pk;
|
||||
/**
|
||||
* 表的列名(不包含主键)
|
||||
*/
|
||||
private List<ColumnEntity> columns;
|
||||
/**
|
||||
* 类名(第一个字母大写),如:sys_user => SysUser
|
||||
*/
|
||||
private String className;
|
||||
/**
|
||||
* 类名(第一个字母小写),如:sys_user => sysUser
|
||||
*/
|
||||
private String classname;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(String comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public ColumnEntity getPk() {
|
||||
return pk;
|
||||
}
|
||||
|
||||
public void setPk(ColumnEntity pk) {
|
||||
this.pk = pk;
|
||||
}
|
||||
|
||||
public List<ColumnEntity> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<ColumnEntity> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getClassname() {
|
||||
return classname;
|
||||
}
|
||||
|
||||
public void setClassname(String classname) {
|
||||
this.classname = classname;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.central.generator.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author zlt
|
||||
*/
|
||||
@Service
|
||||
public interface SysGeneratorService extends IService {
|
||||
PageResult queryList(Map<String, Object> map);
|
||||
|
||||
Map<String, String> queryTable(String tableName);
|
||||
|
||||
List<Map<String, String>> queryColumns(String tableName);
|
||||
|
||||
byte[] generatorCode(String[] tableNames);
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.central.generator.service.impl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.generator.mapper.SysGeneratorMapper;
|
||||
import com.central.generator.service.SysGeneratorService;
|
||||
import com.central.generator.utils.GenUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysGeneratorServiceImpl extends ServiceImpl implements SysGeneratorService {
|
||||
@Autowired
|
||||
private SysGeneratorMapper sysGeneratorMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<Map<String, Object>> queryList(Map<String, Object> map) {
|
||||
Page<Map<String, Object>> page = new Page<>(MapUtils.getInteger(map, "page"), MapUtils.getInteger(map, "limit"));
|
||||
|
||||
List<Map<String, Object>> list = sysGeneratorMapper.queryList(page, map);
|
||||
return PageResult.<Map<String, Object>>builder().data(list).code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> queryTable(String tableName) {
|
||||
return sysGeneratorMapper.queryTable(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> queryColumns(String tableName) {
|
||||
return sysGeneratorMapper.queryColumns(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] generatorCode(String[] tableNames) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream)
|
||||
) {
|
||||
for (String tableName : tableNames) {
|
||||
//查询表信息
|
||||
Map<String, String> table = queryTable(tableName);
|
||||
//查询列信息
|
||||
List<Map<String, String>> columns = queryColumns(tableName);
|
||||
//生成代码
|
||||
GenUtils.generatorCode(table, columns, zip);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("generatorCode-error: ", e);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
package com.central.generator.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.central.common.utils.DateUtils;
|
||||
import com.central.generator.model.ColumnEntity;
|
||||
import com.central.generator.model.TableEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
/**
|
||||
* 代码生成器工具类
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
public class GenUtils {
|
||||
private final static String FILE_NAME_MODEL = "Model.java.vm";
|
||||
private final static String FILE_NAME_MAPPER = "Mapper.java.vm";
|
||||
private final static String FILE_NAME_MAPPERXML = "Mapper.xml.vm";
|
||||
private final static String FILE_NAME_SERVICE = "Service.java.vm";
|
||||
private final static String FILE_NAME_SERVICEIMPL = "ServiceImpl.java.vm";
|
||||
private final static String FILE_NAME_CONTROLLER = "Controller.java.vm";
|
||||
private final static String FILE_NAME_PAGE = "index.html.vm";
|
||||
|
||||
public static List<String> getTemplates() {
|
||||
List<String> templates = new ArrayList<String>();
|
||||
templates.add("template/"+FILE_NAME_MODEL);
|
||||
templates.add("template/"+FILE_NAME_MAPPER);
|
||||
templates.add("template/"+FILE_NAME_MAPPERXML);
|
||||
templates.add("template/"+FILE_NAME_SERVICE);
|
||||
templates.add("template/"+FILE_NAME_SERVICEIMPL);
|
||||
templates.add("template/"+FILE_NAME_CONTROLLER);
|
||||
|
||||
templates.add("template/"+FILE_NAME_PAGE);
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*/
|
||||
public static void generatorCode(Map<String, String> table,
|
||||
List<Map<String, String>> columns, ZipOutputStream zip) {
|
||||
//配置信息
|
||||
Configuration config = getConfig();
|
||||
boolean hasBigDecimal = false;
|
||||
//表信息
|
||||
TableEntity tableEntity = new TableEntity();
|
||||
tableEntity.setTableName(table.get("tableName"));
|
||||
tableEntity.setComments(table.get("tableComment"));
|
||||
//表名转换成Java类名
|
||||
String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix"));
|
||||
tableEntity.setClassName(className);
|
||||
tableEntity.setClassname(StringUtils.uncapitalize(className));
|
||||
|
||||
//列信息
|
||||
List<ColumnEntity> columsList = new ArrayList<>();
|
||||
for (Map<String, String> column : columns) {
|
||||
ColumnEntity columnEntity = new ColumnEntity();
|
||||
columnEntity.setColumnName(column.get("columnName"));
|
||||
columnEntity.setDataType(column.get("dataType"));
|
||||
columnEntity.setComments(column.get("columnComment"));
|
||||
columnEntity.setExtra(column.get("extra"));
|
||||
|
||||
//列名转换成Java属性名
|
||||
String attrName = columnToJava(columnEntity.getColumnName());
|
||||
columnEntity.setAttrName(attrName);
|
||||
columnEntity.setAttrname(StringUtils.uncapitalize(attrName));
|
||||
|
||||
//列的数据类型,转换成Java类型
|
||||
String attrType = config.getString(columnEntity.getDataType(), "unknowType");
|
||||
columnEntity.setAttrType(attrType);
|
||||
if (!hasBigDecimal && attrType.equals("BigDecimal")) {
|
||||
hasBigDecimal = true;
|
||||
}
|
||||
//是否主键
|
||||
if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null) {
|
||||
tableEntity.setPk(columnEntity);
|
||||
}
|
||||
|
||||
columsList.add(columnEntity);
|
||||
}
|
||||
tableEntity.setColumns(columsList);
|
||||
|
||||
//没主键,则第一个字段为主键
|
||||
if (tableEntity.getPk() == null) {
|
||||
tableEntity.setPk(tableEntity.getColumns().get(0));
|
||||
}
|
||||
|
||||
//设置velocity资源加载器
|
||||
Properties prop = new Properties();
|
||||
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
Velocity.init(prop);
|
||||
String mainPath = config.getString("mainPath");
|
||||
mainPath = StringUtils.isBlank(mainPath) ? "io.renren" : mainPath;
|
||||
//封装模板数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("tableName", tableEntity.getTableName());
|
||||
map.put("comments", tableEntity.getComments());
|
||||
map.put("pk", tableEntity.getPk());
|
||||
map.put("className", tableEntity.getClassName());
|
||||
map.put("classname", tableEntity.getClassname());
|
||||
map.put("pathName", tableEntity.getClassname().toLowerCase());
|
||||
map.put("columns", tableEntity.getColumns());
|
||||
map.put("hasBigDecimal", hasBigDecimal);
|
||||
map.put("mainPath", mainPath);
|
||||
map.put("package", config.getString("package"));
|
||||
map.put("moduleName", config.getString("moduleName"));
|
||||
map.put("author", config.getString("author"));
|
||||
map.put("email", config.getString("email"));
|
||||
map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
|
||||
VelocityContext context = new VelocityContext(map);
|
||||
|
||||
//获取模板列表
|
||||
List<String> templates = getTemplates();
|
||||
for (String template : templates) {
|
||||
//渲染模板
|
||||
try (
|
||||
StringWriter sw = new StringWriter()
|
||||
) {
|
||||
Template tpl = Velocity.getTemplate(template, "UTF-8");
|
||||
tpl.merge(context, sw);
|
||||
|
||||
//添加到zip
|
||||
zip.putNextEntry(new ZipEntry(getFileName(template, tableEntity.getClassName(), config.getString("package"), config.getString("moduleName"))));
|
||||
IOUtils.write(sw.toString(), zip, "UTF-8");
|
||||
zip.closeEntry();
|
||||
} catch (IOException e) {
|
||||
log.error("generatorCode-error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 列名转换成Java属性名
|
||||
*/
|
||||
public static String columnToJava(String columnName) {
|
||||
return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 表名转换成Java类名
|
||||
*/
|
||||
public static String tableToJava(String tableName, String tablePrefix) {
|
||||
if (StringUtils.isNotBlank(tablePrefix)) {
|
||||
tableName = tableName.replace(tablePrefix, "");
|
||||
}
|
||||
return columnToJava(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
*/
|
||||
public static Configuration getConfig() {
|
||||
try {
|
||||
return new PropertiesConfiguration("generator.properties");
|
||||
} catch (ConfigurationException e) {
|
||||
throw new RuntimeException("获取配置文件失败,", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件名
|
||||
*/
|
||||
public static String getFileName(String template, String className, String packageName, String moduleName) {
|
||||
String packagePath = "main" + File.separator + "java" + File.separator;
|
||||
if (StringUtils.isNotBlank(packageName)) {
|
||||
packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_MODEL)) {
|
||||
return packagePath + "model" + File.separator + className + ".java";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_MAPPER)) {
|
||||
return packagePath + "mapper" + File.separator + className + "Mapper.java";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_SERVICE)) {
|
||||
return packagePath + "service" + File.separator + "I" + className + "Service.java";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_SERVICEIMPL)) {
|
||||
return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_CONTROLLER)) {
|
||||
return packagePath + "controller" + File.separator + className + "Controller.java";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_MAPPERXML)) {
|
||||
return "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + className + "Mapper.xml";
|
||||
}
|
||||
|
||||
if (template.contains(FILE_NAME_PAGE)) {
|
||||
return "main" + File.separator + "view" + File.separator + "pages" +
|
||||
File.separator + moduleName + File.separator + "index.html";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/user-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.generator.model
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 7300
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: code-generator
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
file-extension: yml
|
||||
shared-dataids: common.yml
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
@@ -0,0 +1,33 @@
|
||||
#包前缀
|
||||
package=com.central
|
||||
#模块名,生成的类的package为:com.central.generator
|
||||
moduleName=generator
|
||||
#作者名
|
||||
author=zlt
|
||||
#Email
|
||||
email=
|
||||
#表前缀,如表tb_sys_user 生成类 sys_user
|
||||
tablePrefix=tb_
|
||||
|
||||
#数据转换类型
|
||||
tinyint=Integer
|
||||
smallint=Integer
|
||||
mediumint=Integer
|
||||
int=Integer
|
||||
integer=Integer
|
||||
bigint=Long
|
||||
float=Float
|
||||
double=Double
|
||||
decimal=BigDecimal
|
||||
bit=Boolean
|
||||
|
||||
char=String
|
||||
varchar=String
|
||||
tinytext=String
|
||||
text=String
|
||||
mediumtext=String
|
||||
longtext=String
|
||||
|
||||
date=Date
|
||||
datetime=Date
|
||||
timestamp=Date
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.generator.mapper.SysGeneratorMapper">
|
||||
<select id="queryList" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from
|
||||
information_schema.tables
|
||||
where table_schema = (select database())
|
||||
<if test="p.tableName != null and p.tableName.trim() != ''">
|
||||
and table_name like concat('%', #{p.tableName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryTotal" resultType="int">
|
||||
select count(*) from information_schema.tables where table_schema = (select database())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database()) and table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
<select id="queryColumns" resultType="map">
|
||||
select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns
|
||||
where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,74 @@
|
||||
package ${package}.${moduleName}.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import ${package}.${moduleName}.model.${className};
|
||||
import ${package}.${moduleName}.service.${className}Service;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/${pathName}")
|
||||
@Api(tags = "${comments}")
|
||||
public class ${className}Controller {
|
||||
@Autowired
|
||||
private I${className}Service ${classname}Service;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ApiOperation(value = "查询列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
|
||||
})
|
||||
@GetMapping("/${className}")
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
return ${classname}Service.findList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@ApiOperation(value = "查询")
|
||||
@GetMapping("/${className}/{id}")
|
||||
public Result findUserById(@PathVariable Long ${pk.attrname}) {
|
||||
${className} model = ${classname}Service.getById(id);
|
||||
return Result.succeed(model, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增or更新
|
||||
*/
|
||||
@ApiOperation(value = "保存")
|
||||
@PostMapping("/${className}")
|
||||
public Result save(@RequestBody ${className} ${classname}) {
|
||||
${classname}Service.saveOrUpdateUser(${classname});
|
||||
return Result.succeed("保存成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@ApiOperation(value = "删除")
|
||||
@DeleteMapping("/${className}/{id}")
|
||||
public Result delete(@PathVariable Long ${pk.attrname}) {
|
||||
${classname}Service.removeById(${pk.attrname});
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package ${package}.${moduleName}.dao;
|
||||
|
||||
import ${package}.${moduleName}.entity.${className};
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${className}Mapper extends SuperMapper<${className}> {
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
* @param page
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<${className}> findList(Page<${className}> page, @Param("p") Map<String, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper">
|
||||
<select id="findList" resultType="${package}.${moduleName}.model.${className}">
|
||||
select * from ${tableName} t
|
||||
order by t.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,31 @@
|
||||
package ${package}.${moduleName}.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.EqualsAndHashCode;
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("${tableName}")
|
||||
public class ${className} extends SuperEntity {
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.columnName != $pk.columnName && $column.columnName != "createTime" && $column.columnName != "updateTime")
|
||||
private $column.attrType $column.attrname;
|
||||
#end
|
||||
#end
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package ${package}.${moduleName}.service;
|
||||
|
||||
import ${package}.${moduleName}.entity.${className};
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
public interface I${className}Service extends IService<${className}> {
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageResult<${className}> findList(Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package ${package}.${moduleName}.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import ${package}.${moduleName}.entity.${className};
|
||||
import ${package}.${moduleName}.dao.${className}Dao;
|
||||
import ${package}.${moduleName}.service.${className}Service;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements I${className}Service {
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public PageResult<${className}> findList(Map<String, Object> params){
|
||||
Integer page = MapUtils.getInteger(params, "page");
|
||||
Integer limit = MapUtils.getInteger(params, "limit");
|
||||
if (page == null) {
|
||||
page = 1;
|
||||
}
|
||||
if (limit == null) {
|
||||
limit = -1;
|
||||
}
|
||||
Page<${className}> page = new Page<>(page, limit);
|
||||
List<${className}> list = baseMapper.findList(page, params);
|
||||
return PageResult.<${className}>builder().data(list).code(0).count(page.getTotal()).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">
|
||||
<h2 class="header-title">${comments}</h2>
|
||||
<span class="layui-breadcrumb pull-right">
|
||||
<a href="#!console">首页</a>
|
||||
<a><cite>${comments}</cite></a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-form toolbar">
|
||||
搜索:
|
||||
<input id="${classname}-edit-value" class="layui-input search-input" type="text" placeholder="输入关键字"/> 
|
||||
<button id="${classname}-btn-search" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索</button>
|
||||
<button id="${classname}-btn-add" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<table class="layui-table" id="${classname}-table" lay-filter="${classname}-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
var config = layui.config;
|
||||
var layer = layui.layer;
|
||||
var util = layui.util;
|
||||
var admin = layui.admin;
|
||||
|
||||
//渲染表格
|
||||
table.render({
|
||||
elem: '#${classname}-table',
|
||||
url: config.base_server + 'api-${moduleName}/${pathName}/list',
|
||||
where: {
|
||||
access_token: config.getToken().access_token
|
||||
},
|
||||
page: true,
|
||||
cols: [[
|
||||
{type: 'numbers'},
|
||||
{field: 'id', sort: true, title: 'ID',width: 80},
|
||||
{field: 'name', sort: true, title: 'name'},
|
||||
{field: 'code', sort: true, title: 'code'},
|
||||
{align: 'center', toolbar: '#${classname}-table-bar', title: '操作',width: 250}
|
||||
]]
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,83 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>file-center</artifactId>
|
||||
<description>文件中心</description>
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-swagger2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
</dependency>
|
||||
<!-- 七牛依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.central;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 文件中心
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class FileCenterApp {
|
||||
public static void main(String[] args) {
|
||||
// 固定端口
|
||||
SpringApplication.run(FileCenterApp.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 阿里云配置
|
||||
*/
|
||||
@Configuration
|
||||
public class AliyunOSSConfig {
|
||||
@Value("${aliyun.oss.endpoint:xxxxx}")
|
||||
private String endpoint;
|
||||
@Value("${aliyun.oss.access-key:xxxxx}")
|
||||
private String accessKeyId;
|
||||
@Value("${aliyun.oss.accessKeySecret:xxxxx}")
|
||||
private String accessKeySecret;
|
||||
|
||||
/**
|
||||
* 阿里云文件存储client
|
||||
* 只有配置了aliyun.oss.access-key才可以使用
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "aliyun.oss.access-key", matchIfMissing = true)
|
||||
public OSSClient ossClient() {
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
return ossClient;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import com.central.common.config.DefaultAsycTaskConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 线程池配置、启用异步
|
||||
* @Async quartz 需要使用
|
||||
*/
|
||||
@Configuration
|
||||
public class AsycTaskExecutorConfig extends DefaultAsycTaskConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import com.central.db.config.DefaultMybatisPlusConfig;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2018/12/10
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan({"com.central.file.mapper*"})
|
||||
public class MybatisPlusConfig extends DefaultMybatisPlusConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.central.file.service.IFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.central.file.model.FileType;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* FileService工厂<br>
|
||||
* 将各个实现类放入map
|
||||
*/
|
||||
@Configuration
|
||||
public class OssServiceFactory {
|
||||
|
||||
private Map<FileType, IFileService> map = new HashMap<>();
|
||||
@Autowired
|
||||
private IFileService aliyunOssServiceImpl;
|
||||
|
||||
@Autowired
|
||||
private IFileService qiniuOssServiceImpl;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
map.put(FileType.ALIYUN, aliyunOssServiceImpl);
|
||||
map.put(FileType.QINIU, qiniuOssServiceImpl);
|
||||
}
|
||||
|
||||
public IFileService getFileService(String fileType) {
|
||||
return map.get(FileType.valueOf(fileType));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import com.central.common.config.DefaultPasswordConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/1/2
|
||||
*/
|
||||
@Configuration
|
||||
public class PasswordConfig extends DefaultPasswordConfig {
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.central.file.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.util.Auth;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 七牛云配置
|
||||
*/
|
||||
@Configuration
|
||||
public class QiniuOSSConfig {
|
||||
@Value("${qiniu.oss.access-key:xxxxx}")
|
||||
private String accessKeyId;
|
||||
@Value("${qiniu.oss.accessKeySecret:xxxxx}")
|
||||
private String accessKeySecret;
|
||||
|
||||
/**
|
||||
* 华东机房
|
||||
*/
|
||||
@Bean
|
||||
public com.qiniu.storage.Configuration qiniuConfig() {
|
||||
return new com.qiniu.storage.Configuration(Zone.zone2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建一个七牛上传工具实例
|
||||
*/
|
||||
@Bean
|
||||
public UploadManager uploadManager() {
|
||||
return new UploadManager(qiniuConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证信息实例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Auth auth() {
|
||||
return Auth.create(accessKeyId, accessKeySecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建七牛空间管理实例
|
||||
*/
|
||||
@Bean
|
||||
public BucketManager bucketManager() {
|
||||
return new BucketManager(auth(), qiniuConfig());
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.central.file.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.file.service.IFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.file.config.OssServiceFactory;
|
||||
import com.central.file.model.FileInfo;
|
||||
import com.central.file.model.FileType;
|
||||
|
||||
/**
|
||||
* 文件上传 同步oss db双写 目前仅实现了阿里云,七牛云
|
||||
* 参考src/main/view/upload.html
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@RestController
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private OssServiceFactory fileServiceFactory;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* 根据fileType选择上传方式
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/files-anon")
|
||||
public FileInfo upload(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
String fileType = FileType.QINIU.toString();
|
||||
IFileService fileService = fileServiceFactory.getFileService(fileType);
|
||||
return fileService.upload(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件删除
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@DeleteMapping("/files/{id}")
|
||||
public Result delete(@PathVariable String id) {
|
||||
try {
|
||||
FileInfo fileInfo = fileServiceFactory.getFileService(FileType.QINIU.toString()).getById(id);
|
||||
if (fileInfo != null) {
|
||||
IFileService fileService = fileServiceFactory.getFileService(fileInfo.getSource());
|
||||
fileService.removeById(fileInfo);
|
||||
}
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception ex) {
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件查询
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/files")
|
||||
public PageResult<FileInfo> findFiles(@RequestParam Map<String, Object> params) {
|
||||
return fileServiceFactory.getFileService(FileType.QINIU.toString()).findList(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.central.file.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
|
||||
import com.central.file.model.FileInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 上传存储db
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
public interface FileMapper extends SuperMapper<FileInfo> {
|
||||
List<FileInfo> findList(Page<FileInfo> page, @Param("f") Map<String, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.central.file.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* file实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("file_info")
|
||||
public class FileInfo extends Model<FileInfo> {
|
||||
private static final long serialVersionUID = -1438078028040922174L;
|
||||
|
||||
@TableId
|
||||
private String id;
|
||||
/**
|
||||
* 原始文件名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 是否图片
|
||||
*/
|
||||
private Boolean isImg;
|
||||
/**
|
||||
* 上传文件类型
|
||||
*/
|
||||
private String contentType;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private long size;
|
||||
/**
|
||||
* 冗余字段
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* oss访问路径 oss需要设置公共读
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* FileType字段
|
||||
*/
|
||||
private String source;
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.central.file.model;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 仅支持阿里云 oss ,七牛云等
|
||||
*/
|
||||
public enum FileType {
|
||||
//七牛
|
||||
QINIU,
|
||||
//阿里云
|
||||
ALIYUN
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.central.file.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.file.model.FileInfo;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 文件service 目前仅支持阿里云oss,七牛云
|
||||
*/
|
||||
public interface IFileService extends IService<FileInfo> {
|
||||
FileInfo upload(MultipartFile file ) throws Exception;
|
||||
|
||||
PageResult<FileInfo> findList(Map<String, Object> params);
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.central.file.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.model.SysUser;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.file.mapper.FileMapper;
|
||||
import com.central.file.model.FileInfo;
|
||||
import com.central.file.model.FileType;
|
||||
import com.central.file.service.IFileService;
|
||||
import com.central.file.utils.FileUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* AbstractIFileService 抽取类
|
||||
* 根据filetype 实例化具体oss对象
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractIFileService extends ServiceImpl<FileMapper, FileInfo> implements IFileService {
|
||||
@Override
|
||||
public FileInfo upload(MultipartFile file ) throws Exception {
|
||||
FileInfo fileInfo = FileUtil.getFileInfo(file);
|
||||
FileInfo oldFileInfo = baseMapper.selectById(fileInfo.getId());
|
||||
if (oldFileInfo != null) {
|
||||
return oldFileInfo;
|
||||
}
|
||||
if (!fileInfo.getName().contains(".")) {
|
||||
throw new IllegalArgumentException("缺少后缀名");
|
||||
}
|
||||
uploadFile(file, fileInfo);
|
||||
fileInfo.setSource(fileType().name());// 设置文件来源
|
||||
baseMapper.insert(fileInfo);// 将文件信息保存到数据库
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件来源
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract FileType fileType();
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file
|
||||
* @param fileInfo
|
||||
*/
|
||||
protected abstract void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除文件资源
|
||||
*
|
||||
* @param fileInfo
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean deleteFile(FileInfo fileInfo);
|
||||
|
||||
@Override
|
||||
public PageResult<FileInfo> findList(Map<String, Object> params){
|
||||
Page<FileInfo> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<FileInfo> list = baseMapper.findList(page, params);
|
||||
return PageResult.<FileInfo>builder().data(list).code(0).count(page.getTotal()).build();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.central.file.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.central.file.mapper.FileMapper;
|
||||
import com.central.file.model.FileInfo;
|
||||
import com.central.file.model.FileType;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 阿里云oss存储文件
|
||||
*/
|
||||
@Service("aliyunOssServiceImpl")
|
||||
public class AliyunOssServiceImplI extends AbstractIFileService {
|
||||
@Autowired
|
||||
private OSSClient ossClient;
|
||||
@Value("${aliyun.oss.bucketName:xxxxx}")
|
||||
private String bucketName;
|
||||
@Value("${aliyun.oss.domain:xxxxx}")
|
||||
private String domain;
|
||||
|
||||
@Override
|
||||
protected FileType fileType() {
|
||||
return FileType.ALIYUN;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception {
|
||||
ossClient.putObject(bucketName, fileInfo.getName(), file.getInputStream());
|
||||
fileInfo.setUrl(domain + "/" + fileInfo.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean deleteFile(FileInfo fileInfo) {
|
||||
ossClient.deleteObject(bucketName, fileInfo.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.central.file.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.central.file.model.FileInfo;
|
||||
import com.central.file.model.FileType;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.qiniu.util.StringMap;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 七牛云oss存储文件
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("qiniuOssServiceImpl")
|
||||
public class QiniuOssServiceImplI extends AbstractIFileService implements InitializingBean {
|
||||
@Autowired
|
||||
private UploadManager uploadManager;
|
||||
@Autowired
|
||||
private BucketManager bucketManager;
|
||||
@Autowired
|
||||
private Auth auth;
|
||||
@Value("${qiniu.oss.bucketName:xxxxx}")
|
||||
private String bucket;
|
||||
@Value("${qiniu.oss.endpoint:xxxxx}")
|
||||
private String endpoint;
|
||||
private StringMap putPolicy;
|
||||
|
||||
@Override
|
||||
protected FileType fileType() {
|
||||
return FileType.QINIU;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传凭证
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getUploadToken() {
|
||||
return this.auth.uploadToken(bucket, null, 3600, putPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception {
|
||||
// 调用put方法上传
|
||||
uploadManager.put(file.getBytes(), fileInfo.getName(), auth.uploadToken(bucket));
|
||||
fileInfo.setUrl(endpoint + "/" + fileInfo.getName());
|
||||
fileInfo.setPath(endpoint + "/" + fileInfo.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean deleteFile(FileInfo fileInfo) {
|
||||
try {
|
||||
Response response = bucketManager.delete(this.bucket, fileInfo.getPath());
|
||||
int retry = 0;
|
||||
while (response.needRetry() && retry++ < 3) {
|
||||
response = bucketManager.delete(bucket, fileInfo.getPath());
|
||||
}
|
||||
} catch (QiniuException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.putPolicy = new StringMap();
|
||||
putPolicy.put("returnBody",
|
||||
"{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"width\":$(imageInfo.width), \"height\":${imageInfo.height}}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.central.file.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import com.central.file.model.FileInfo;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 文件工具类
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
public static FileInfo getFileInfo(MultipartFile file) throws Exception {
|
||||
String md5 = fileMd5(file.getInputStream());
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setId(md5);// 将文件的md5设置为文件表的id
|
||||
fileInfo.setName(file.getOriginalFilename());
|
||||
fileInfo.setContentType(file.getContentType());
|
||||
fileInfo.setIsImg(fileInfo.getContentType().startsWith("image/"));
|
||||
fileInfo.setSize(file.getSize());
|
||||
fileInfo.setCreateTime(new Date());
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件的md5
|
||||
*
|
||||
* @param inputStream
|
||||
* @return
|
||||
*/
|
||||
public static String fileMd5(InputStream inputStream) {
|
||||
try {
|
||||
return DigestUtils.md5Hex(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String saveFile(MultipartFile file, String path) {
|
||||
try {
|
||||
File targetFile = new File(path);
|
||||
if (targetFile.exists()) {
|
||||
return path;
|
||||
}
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
file.transferTo(targetFile);
|
||||
return path;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String pathname) {
|
||||
File file = new File(pathname);
|
||||
if (file.exists()) {
|
||||
boolean flag = file.delete();
|
||||
if (flag) {
|
||||
File[] files = file.getParentFile().listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
file.getParentFile().delete();
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#aliyun:
|
||||
# oss:
|
||||
# access-key: 你的密钥
|
||||
# accessKeySecret: 你的密钥
|
||||
# endpoint: 你的端点
|
||||
# bucketName: 你的名称
|
||||
# domain: 你的说明
|
||||
|
||||
qiniu:
|
||||
oss:
|
||||
access-key: tpi8mObnfzZi4ggBX8Bw7zydjoTQ0WeML3RkPKsX
|
||||
accessKeySecret: HZBXmSyUTy-haYp0KbBTtsil-GoKjVS2kDKT8Yow
|
||||
endpoint: http://pkqtmn0p1.bkt.clouddn.com
|
||||
bucketName: public-oss
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/file_center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
|
||||
redis:
|
||||
host: ${zlt.redis.host}
|
||||
port: ${zlt.redis.port}
|
||||
timeout: ${zlt.redis.timeout}
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.file.model
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: INPUT
|
||||
zlt:
|
||||
swagger:
|
||||
enabled: true
|
||||
title: 文件中心
|
||||
description: 文件中心接口文档
|
||||
version: 1.0
|
||||
base-package: com.central.file.controller
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 5000
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: file-center
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
file-extension: yml
|
||||
shared-dataids: common.yml
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.file.mapper.FileMapper">
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="f.name != null and f.name != ''">
|
||||
and t.name like concat('%', #{f.name}, '%')
|
||||
</if>
|
||||
<if test="f.beginTime != null and f.beginTime != ''">
|
||||
and t.create_time >= #{f.beginTime}
|
||||
</if>
|
||||
<if test="f.endTime != null and f.endTime != ''">
|
||||
and t.create_time <= #{f.endTime}
|
||||
</if>
|
||||
<if test="f.searchKey != null and f.searchKey != ''">
|
||||
and t.name like concat('%', #{f.searchKey}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.file.model.FileInfo">
|
||||
select * from file_info t
|
||||
<include refid="where" />
|
||||
order by t.create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
*
|
||||
* Base64 encode / decode
|
||||
*
|
||||
* @author haitao.tu
|
||||
* @date 2010-04-26
|
||||
* @email tuhaitao@foxmail.com
|
||||
*
|
||||
*/
|
||||
|
||||
function Base64() {
|
||||
|
||||
// private property
|
||||
_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
// public method for encoding
|
||||
this.encode = function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
input = _utf8_encode(input);
|
||||
while (i < input.length) {
|
||||
chr1 = input.charCodeAt(i++);
|
||||
chr2 = input.charCodeAt(i++);
|
||||
chr3 = input.charCodeAt(i++);
|
||||
enc1 = chr1 >> 2;
|
||||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
||||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
||||
enc4 = chr3 & 63;
|
||||
if (isNaN(chr2)) {
|
||||
enc3 = enc4 = 64;
|
||||
} else if (isNaN(chr3)) {
|
||||
enc4 = 64;
|
||||
}
|
||||
output = output +
|
||||
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
|
||||
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// public method for decoding
|
||||
this.decode = function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
while (i < input.length) {
|
||||
enc1 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = _keyStr.indexOf(input.charAt(i++));
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
output = output + String.fromCharCode(chr1);
|
||||
if (enc3 != 64) {
|
||||
output = output + String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 != 64) {
|
||||
output = output + String.fromCharCode(chr3);
|
||||
}
|
||||
}
|
||||
output = _utf8_decode(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
// private method for UTF-8 encoding
|
||||
_utf8_encode = function (string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
var c = string.charCodeAt(n);
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
} else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
} else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
return utftext;
|
||||
}
|
||||
|
||||
// private method for UTF-8 decoding
|
||||
_utf8_decode = function (utftext) {
|
||||
var string = "";
|
||||
var i = 0;
|
||||
var c = c1 = c2 = 0;
|
||||
while ( i < utftext.length ) {
|
||||
c = utftext.charCodeAt(i);
|
||||
if (c < 128) {
|
||||
string += String.fromCharCode(c);
|
||||
i++;
|
||||
} else if((c > 191) && (c < 224)) {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
||||
i += 2;
|
||||
} else {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
c3 = utftext.charCodeAt(i+2);
|
||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
(function(b){b.fn.fakeLoader=function(m){var f=b.extend({timeToHide:1200,pos:"fixed",top:"0px",left:"0px",width:"100%",height:"100%",zIndex:"999",bgColor:"#2ecc71",spinner:"spinner7",imagePath:""},m);var l='<div class="fl spinner1"><div class="double-bounce1"></div><div class="double-bounce2"></div></div>';var k='<div class="fl spinner2"><div class="spinner-container container1"><div class="circle1"></div><div class="circle2"></div><div class="circle3"></div><div class="circle4"></div></div><div class="spinner-container container2"><div class="circle1"></div><div class="circle2"></div><div class="circle3"></div><div class="circle4"></div></div><div class="spinner-container container3"><div class="circle1"></div><div class="circle2"></div><div class="circle3"></div><div class="circle4"></div></div></div>';var j='<div class="fl spinner3"><div class="dot1"></div><div class="dot2"></div></div>';var i='<div class="fl spinner4"></div>';var h='<div class="fl spinner5"><div class="cube1"></div><div class="cube2"></div></div>';var g='<div class="fl spinner6"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div>';var e='<div class="fl spinner7"><div class="circ1"></div><div class="circ2"></div><div class="circ3"></div><div class="circ4"></div></div>';var d=b(this);var c={position:f.pos,width:f.width,height:f.height,top:f.top,left:f.left};d.css(c);d.each(function(){var n=f.spinner;switch(n){case"spinner1":d.html(l);break;case"spinner2":d.html(k);break;case"spinner3":d.html(j);break;case"spinner4":d.html(i);break;case"spinner5":d.html(h);break;case"spinner6":d.html(g);break;case"spinner7":d.html(e);break;default:d.html(l)}if(f.imagePath!=""){d.html('<div class="fl"><img src="'+f.imagePath+'"></div>');a()}});setTimeout(function(){b(d).fadeOut()},f.timeToHide);return this.css({backgroundColor:f.bgColor,zIndex:f.zIndex})};function a(){var c=b(window).width();var e=b(window).height();var d=b(".fl").outerWidth();var f=b(".fl").outerHeight();b(".fl").css({position:"absolute",left:(c/2)-(d/2),top:(e/2)-(f/2)})}b(window).load(function(){a();b(window).resize(function(){a()})})}(jQuery));
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
/*
|
||||
jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
|
||||
Liscensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
|
||||
*/
|
||||
(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)<M.distance){break}L.target=M.target;J=C(L,"dragstart",K);if(J!==false){F.dragging=K;F.proxy=L.dragProxy=E(J||K)[0]}case"mousemove":if(F.dragging){J=C(L,"drag",K);if(B.drop){B.drop.allowed=(J!==false);B.drop.handler(L)}if(J!==false){break}L.type="mouseup"}case"mouseup":A.remove(document,"mousemove mouseup",H);if(F.dragging){if(B.drop){B.drop.handler(L)}C(L,"dragend",K)}G(K,true);F.dragging=F.proxy=M.elem=false;break}return true}function C(M,K,L){M.type=K;var J=E.event.handle.call(L,M);return J===false?false:J||M.result}function I(J){return Math.pow(J,2)}function D(){return(F.dragging===false)}function G(K,J){if(!K){return }K.unselectable=J?"off":"on";K.onselectstart=function(){return J};if(K.style){K.style.MozUserSelect=J?"":"none"}}})(jQuery);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
/*! Lazy Load 1.9.3 - MIT license - Copyright 2010-2013 Mika Tuupola */
|
||||
!function(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function g(){var b=0;i.each(function(){var c=a(this);if(!j.skip_invisible||c.is(":visible"))if(a.abovethetop(this,j)||a.leftofbegin(this,j));else if(a.belowthefold(this,j)||a.rightoffold(this,j)){if(++b>j.failure_limit)return!1}else c.trigger("appear"),b=0})}var h,i=this,j={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null,placeholder:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};return f&&(d!==f.failurelimit&&(f.failure_limit=f.failurelimit,delete f.failurelimit),d!==f.effectspeed&&(f.effect_speed=f.effectspeed,delete f.effectspeed),a.extend(j,f)),h=j.container===d||j.container===b?e:a(j.container),0===j.event.indexOf("scroll")&&h.bind(j.event,function(){return g()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,(c.attr("src")===d||c.attr("src")===!1)&&c.is("img")&&c.attr("src",j.placeholder),c.one("appear",function(){if(!this.loaded){if(j.appear){var d=i.length;j.appear.call(b,d,j)}a("<img />").bind("load",function(){var d=c.attr("data-"+j.data_attribute);c.hide(),c.is("img")?c.attr("src",d):c.css("background-image","url('"+d+"')"),c[j.effect](j.effect_speed),b.loaded=!0;var e=a.grep(i,function(a){return!a.loaded});if(i=a(e),j.load){var f=i.length;j.load.call(b,f,j)}}).attr("src",c.attr("data-"+j.data_attribute))}}),0!==j.event.indexOf("scroll")&&c.bind(j.event,function(){b.loaded||c.trigger("appear")})}),e.bind("resize",function(){g()}),/(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&i.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){g()}),this},a.belowthefold=function(c,f){var g;return g=f.container===d||f.container===b?(b.innerHeight?b.innerHeight:e.height())+e.scrollTop():a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return g=f.container===d||f.container===b?e.width()+e.scrollLeft():a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollTop():a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollLeft():a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!(a.rightoffold(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.abovethetop(b,c))},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})}(jQuery,window,document);
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,28 @@
|
||||
(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;d<a.length&&0==a[d];)d++;this.num=Array(a.length-d+c);for(var b=0;b<a.length-d;b++)this.num[b]=a[b+d]}function p(a,c){this.totalCount=a;this.dataCount=c}function t(){this.buffer=[];this.length=0}u.prototype={getLength:function(){return this.data.length},
|
||||
write:function(a){for(var c=0;c<this.data.length;c++)a.put(this.data.charCodeAt(c),8)}};o.prototype={addData:function(a){this.dataList.push(new u(a));this.dataCache=null},isDark:function(a,c){if(0>a||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e<c.length;e++)b+=c[e].dataCount;
|
||||
for(e=0;e<this.dataList.length;e++)c=this.dataList[e],d.put(c.mode,4),d.put(c.getLength(),j.getLengthInBits(c.mode,a)),c.write(d);if(d.getLengthInBits()<=8*b)break}this.typeNumber=a}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17;this.modules=Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){this.modules[d]=Array(this.moduleCount);for(var b=0;b<this.moduleCount;b++)this.modules[d][b]=null}this.setupPositionProbePattern(0,0);this.setupPositionProbePattern(this.moduleCount-
|
||||
7,0);this.setupPositionProbePattern(0,this.moduleCount-7);this.setupPositionAdjustPattern();this.setupTimingPattern();this.setupTypeInfo(a,c);7<=this.typeNumber&&this.setupTypeNumber(a);null==this.dataCache&&(this.dataCache=o.createData(this.typeNumber,this.errorCorrectLevel,this.dataList));this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,c){for(var d=-1;7>=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]=
|
||||
0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c<this.modules.length;c++)for(var d=1*c,b=0;b<this.modules[c].length;b++){var e=1*b;this.modules[c][b]&&(a.beginFill(0,100),a.moveTo(e,d),a.lineTo(e+1,d),a.lineTo(e+1,d+1),a.lineTo(e,d+1),a.endFill())}return a},
|
||||
setupTimingPattern:function(){for(var a=8;a<this.moduleCount-8;a++)null==this.modules[a][6]&&(this.modules[a][6]=0==a%2);for(a=8;a<this.moduleCount-8;a++)null==this.modules[6][a]&&(this.modules[6][a]=0==a%2)},setupPositionAdjustPattern:function(){for(var a=j.getPatternPosition(this.typeNumber),c=0;c<a.length;c++)for(var d=0;d<a.length;d++){var b=a[c],e=a[d];if(null==this.modules[b][e])for(var f=-2;2>=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c=
|
||||
j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount-
|
||||
b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0<i;i-=2)for(6==i&&i--;;){for(var g=0;2>g;g++)if(null==this.modules[b][i-g]){var n=!1;f<a.length&&(n=1==(a[f]>>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a,
|
||||
c),b=new t,e=0;e<d.length;e++){var f=d[e];b.put(f.mode,4);b.put(f.getLength(),j.getLengthInBits(f.mode,a));f.write(b)}for(e=a=0;e<c.length;e++)a+=c[e].dataCount;if(b.getLengthInBits()>8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d=
|
||||
0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g<c.length;g++){var n=c[g].dataCount,h=c[g].totalCount-n,b=Math.max(b,n),e=Math.max(e,h);f[g]=Array(n);for(var k=0;k<f[g].length;k++)f[g][k]=255&a.buffer[k+d];d+=n;k=j.getErrorCorrectPolynomial(h);n=(new q(f[g],k.getLength()-1)).mod(k);i[g]=Array(k.getLength()-1);for(k=0;k<i[g].length;k++)h=k+n.getLength()-i[g].length,i[g][k]=0<=h?n.get(h):0}for(k=g=0;k<c.length;k++)g+=c[k].totalCount;d=Array(g);for(k=n=0;k<b;k++)for(g=0;g<c.length;g++)k<f[g].length&&
|
||||
(d[n++]=f[g][k]);for(k=0;k<e;k++)for(g=0;g<c.length;g++)k<i[g].length&&(d[n++]=i[g][k]);return d};s=4;for(var j={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,
|
||||
78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(a){for(var c=a<<10;0<=j.getBCHDigit(c)-j.getBCHDigit(j.G15);)c^=j.G15<<j.getBCHDigit(c)-j.getBCHDigit(j.G15);return(a<<10|c)^j.G15_MASK},getBCHTypeNumber:function(a){for(var c=a<<12;0<=j.getBCHDigit(c)-
|
||||
j.getBCHDigit(j.G18);)c^=j.G18<<j.getBCHDigit(c)-j.getBCHDigit(j.G18);return a<<12|c},getBCHDigit:function(a){for(var c=0;0!=a;)c++,a>>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+
|
||||
a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;d<a;d++)c=c.multiply(new q([1,l.gexp(d)],0));return c},getLengthInBits:function(a,c){if(1<=c&&10>c)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+
|
||||
a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b<c;b++)for(var e=0;e<c;e++){for(var f=0,i=a.isDark(b,e),g=-1;1>=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5<f&&(d+=3+f-5)}for(b=0;b<c-1;b++)for(e=0;e<c-1;e++)if(f=0,a.isDark(b,e)&&f++,a.isDark(b+1,e)&&f++,a.isDark(b,e+1)&&f++,a.isDark(b+1,e+1)&&f++,0==f||4==f)d+=3;for(b=0;b<c;b++)for(e=0;e<c-6;e++)a.isDark(b,e)&&!a.isDark(b,e+1)&&a.isDark(b,e+
|
||||
2)&&a.isDark(b,e+3)&&a.isDark(b,e+4)&&!a.isDark(b,e+5)&&a.isDark(b,e+6)&&(d+=40);for(e=0;e<c;e++)for(b=0;b<c-6;b++)a.isDark(b,e)&&!a.isDark(b+1,e)&&a.isDark(b+2,e)&&a.isDark(b+3,e)&&a.isDark(b+4,e)&&!a.isDark(b+5,e)&&a.isDark(b+6,e)&&(d+=40);for(e=f=0;e<c;e++)for(b=0;b<c;b++)a.isDark(b,e)&&f++;a=Math.abs(100*f/c/c-50)/5;return d+10*a}},l={glog:function(a){if(1>a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256),
|
||||
LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<<m;for(m=8;256>m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d<this.getLength();d++)for(var b=0;b<a.getLength();b++)c[d+b]^=l.gexp(l.glog(this.get(d))+l.glog(a.get(b)));return new q(c,0)},mod:function(a){if(0>
|
||||
this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b<this.getLength();b++)d[b]=this.get(b);for(b=0;b<a.getLength();b++)d[b]^=l.gexp(l.glog(a.get(b))+c);return(new q(d,0)).mod(a)}};p.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],
|
||||
[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,
|
||||
116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,
|
||||
43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,
|
||||
3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,
|
||||
55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,
|
||||
45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]];p.getRSBlocks=function(a,c){var d=p.getRsBlockTable(a,c);if(void 0==d)throw Error("bad rs block @ typeNumber:"+a+"/errorCorrectLevel:"+c);for(var b=d.length/3,e=[],f=0;f<b;f++)for(var h=d[3*f+0],g=d[3*f+1],j=d[3*f+2],l=0;l<h;l++)e.push(new p(g,j));return e};p.getRsBlockTable=function(a,c){switch(c){case 1:return p.RS_BLOCK_TABLE[4*(a-1)+0];case 0:return p.RS_BLOCK_TABLE[4*(a-1)+1];case 3:return p.RS_BLOCK_TABLE[4*
|
||||
(a-1)+2];case 2:return p.RS_BLOCK_TABLE[4*(a-1)+3]}};t.prototype={get:function(a){return 1==(this.buffer[Math.floor(a/8)]>>>7-a%8&1)},put:function(a,c){for(var d=0;d<c;d++)this.putBit(1==(a>>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,
|
||||
correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f<a.getModuleCount();f++)for(var i=0;i<a.getModuleCount();i++){d.fillStyle=a.isDark(f,i)?h.foreground:h.background;var g=Math.ceil((i+1)*b)-Math.floor(i*b),
|
||||
j=Math.ceil((f+1)*b)-Math.floor(f*b);d.fillRect(Math.round(i*b),Math.round(f*e),g,j)}}else{a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();c=r("<table></table>").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e<a.getModuleCount();e++){f=r("<tr></tr>").css("height",b+"px").appendTo(c);for(i=0;i<a.getModuleCount();i++)r("<td></td>").css("width",
|
||||
d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery);
|
||||
@@ -0,0 +1,422 @@
|
||||
/**
|
||||
* @name jQuery.touchSlider
|
||||
* @version 201209_2
|
||||
* @since 201106
|
||||
* @param Object settings 환경변수 오브젝트
|
||||
* roll - 순환 (default true)
|
||||
* flexible - 유동 레이아웃 (default false)
|
||||
* view - 다중 컬럼 (default 1)
|
||||
* speed - 애니메이션 속도 (default 75)
|
||||
* range - 넘김 판정 범위 (default 0.15)
|
||||
* page - 초기 페이지 (default 1)
|
||||
* transition - CSS3 transition 사용 (default false)
|
||||
* btn_prev - prev 버튼 (jQuery Object, default null)
|
||||
* btn_next - next 버튼 (jQuery Object, default null)
|
||||
* paging - page 버튼 (jQuery Object, default null)
|
||||
* initComplete - 초기화 콜백
|
||||
* counter - 슬라이드 콜백, 카운터
|
||||
*
|
||||
* @example
|
||||
$("#target").touchSlider({
|
||||
flexible : true
|
||||
});
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
$.fn.touchSlider = function (settings) {
|
||||
|
||||
settings.supportsCssTransitions = (function (style) {
|
||||
var prefixes = ['Webkit','Moz','Ms'];
|
||||
for(var i=0, l=prefixes.length; i < l; i++ ) {
|
||||
if( typeof style[prefixes[i] + 'Transition'] !== 'undefined') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})(document.createElement('div').style);
|
||||
|
||||
settings = jQuery.extend({
|
||||
roll : true,
|
||||
flexible : false,
|
||||
btn_prev : null,
|
||||
btn_next : null,
|
||||
paging : null,
|
||||
speed : 75,
|
||||
view : 1,
|
||||
range : 0.15,
|
||||
page : 1,
|
||||
transition : false,
|
||||
initComplete : null,
|
||||
counter : null,
|
||||
multi : false
|
||||
}, settings);
|
||||
|
||||
var opts = [];
|
||||
opts = $.extend({}, $.fn.touchSlider.defaults, settings);
|
||||
|
||||
return this.each(function () {
|
||||
|
||||
$.fn.extend(this, touchSlider);
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.opts = opts;
|
||||
this._view = this.opts.view;
|
||||
this._speed = this.opts.speed;
|
||||
this._tg = $(this);
|
||||
this._list = this._tg.children().children();
|
||||
this._width = parseInt(this._tg.css("width"));
|
||||
this._item_w = parseInt(this._list.css("width"));
|
||||
this._len = this._list.length;
|
||||
this._range = this.opts.range * this._width;
|
||||
this._pos = [];
|
||||
this._start = [];
|
||||
this._startX = 0;
|
||||
this._startY = 0;
|
||||
this._left = 0;
|
||||
this._top = 0;
|
||||
this._drag = false;
|
||||
this._scroll = false;
|
||||
this._btn_prev;
|
||||
this._btn_next;
|
||||
|
||||
this.init();
|
||||
|
||||
$(this)
|
||||
.bind("touchstart", this.touchstart)
|
||||
.bind("touchmove", this.touchmove)
|
||||
.bind("touchend", this.touchend)
|
||||
.bind("dragstart", this.touchstart)
|
||||
.bind("drag", this.touchmove)
|
||||
.bind("dragend", this.touchend)
|
||||
|
||||
$(window).bind("orientationchange resize", function () {
|
||||
_this.resize(_this);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var touchSlider = {
|
||||
|
||||
init : function () {
|
||||
var _this = this;
|
||||
|
||||
$(this).children().css({
|
||||
"width":this._width + "px",
|
||||
"overflow":"visible"
|
||||
});
|
||||
|
||||
if(this.opts.flexible) this._item_w = this._width / this._view;
|
||||
if(this.opts.roll) this._len = Math.ceil(this._len / this._view) * this._view;
|
||||
|
||||
var page_gap = (this.opts.page > 1 && this.opts.page <= this._len) ? (this.opts.page - 1) * this._item_w : 0;
|
||||
|
||||
for(var i=0; i<this._len; ++i) {
|
||||
this._pos[i] = this._item_w * i - page_gap;
|
||||
this._start[i] = this._pos[i];
|
||||
this._list.eq(i).css({
|
||||
"float" : "none",
|
||||
"display" : "block",
|
||||
"position" : "absolute",
|
||||
"top" : "0",
|
||||
"left" : this._pos[i] + "px",
|
||||
"width" : this._item_w + "px"
|
||||
});
|
||||
if(this.opts.supportsCssTransitions && this.opts.transition) {
|
||||
this._list.eq(i).css({
|
||||
"-moz-transition" : "0ms",
|
||||
"-moz-transform" : "",
|
||||
"-ms-transition" : "0ms",
|
||||
"-ms-transform" : "",
|
||||
"-webkit-transition" : "0ms",
|
||||
"-webkit-transform" : "",
|
||||
"transition" : "0ms",
|
||||
"transform" : ""
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(this.opts.btn_prev && this.opts.btn_next) {
|
||||
this.opts.btn_prev.bind("click", function() {
|
||||
_this.animate(1, true);
|
||||
return false;
|
||||
})
|
||||
this.opts.btn_next.bind("click", function() {
|
||||
_this.animate(-1, true);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if(this.opts.paging) {
|
||||
$(this._list).each(function (i, el) {
|
||||
//var btn_page = _this.opts.paging.eq(0).clone();
|
||||
var btn_page = _this.opts.paging.eq(i);
|
||||
//_this.opts.paging.before(btn_page);
|
||||
|
||||
btn_page.bind("click", function(e) {
|
||||
_this.go_page(i, e);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
//this.opts.paging.remove();
|
||||
}
|
||||
|
||||
this.counter();
|
||||
this.initComplete();
|
||||
},
|
||||
|
||||
initComplete : function () {
|
||||
if(typeof(this.opts.initComplete) == "function") {
|
||||
this.opts.initComplete(this);
|
||||
}
|
||||
},
|
||||
|
||||
resize : function (e) {
|
||||
if(e.opts.flexible) {
|
||||
var tmp_w = e._item_w;
|
||||
|
||||
e._width = parseInt(e._tg.css("width"));
|
||||
e._item_w = e._width / e._view;
|
||||
e._range = e.opts.range * e._width;
|
||||
|
||||
for(var i=0; i<e._len; ++i) {
|
||||
e._pos[i] = e._pos[i] / tmp_w * e._item_w;
|
||||
e._start[i] = e._start[i] / tmp_w * e._item_w;
|
||||
e._list.eq(i).css({
|
||||
"left" : e._pos[i] + "px",
|
||||
"width" : e._item_w + "px"
|
||||
});
|
||||
if(this.opts.supportsCssTransitions && this.opts.transition) {
|
||||
e._list.eq(i).css({
|
||||
"-moz-transition" : "0ms",
|
||||
"-moz-transform" : "",
|
||||
"-ms-transition" : "0ms",
|
||||
"-ms-transform" : "",
|
||||
"-webkit-transition" : "0ms",
|
||||
"-webkit-transform" : "",
|
||||
"transition" : "0ms",
|
||||
"transform" : ""
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.counter();
|
||||
},
|
||||
|
||||
touchstart : function (e) {
|
||||
if((e.type == "touchstart" && e.originalEvent.touches.length <= 1) || e.type == "dragstart") {
|
||||
this._startX = e.pageX || e.originalEvent.touches[0].pageX;
|
||||
this._startY = e.pageY || e.originalEvent.touches[0].pageY;
|
||||
this._scroll = false;
|
||||
|
||||
this._start = [];
|
||||
for(var i=0; i<this._len; ++i) {
|
||||
this._start[i] = this._pos[i];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
touchmove : function (e) {
|
||||
if((e.type == "touchmove" && e.originalEvent.touches.length <= 1) || e.type == "drag") {
|
||||
this._left = (e.pageX || e.originalEvent.touches[0].pageX) - this._startX;
|
||||
this._top = (e.pageY || e.originalEvent.touches[0].pageY) - this._startY;
|
||||
var w = this._left < 0 ? this._left * -1 : this._left;
|
||||
var h = this._top < 0 ? this._top * -1 : this._top;
|
||||
|
||||
if (w < h || this._scroll) {
|
||||
this._left = 0;
|
||||
this._drag = false;
|
||||
this._scroll = true;
|
||||
} else {
|
||||
e.preventDefault();
|
||||
this._drag = true;
|
||||
this._scroll = false;
|
||||
this.position(e);
|
||||
}
|
||||
|
||||
for(var i=0; i<this._len; ++i) {
|
||||
var tmp = this._start[i] + this._left;
|
||||
|
||||
if(this.opts.supportsCssTransitions && this.opts.transition) {
|
||||
var trans = "translate3d(" + tmp + "px,0,0)";
|
||||
this._list.eq(i).css({
|
||||
"left" : "",
|
||||
"-moz-transition" : "0ms",
|
||||
"-moz-transform" : trans,
|
||||
"-ms-transition" : "0ms",
|
||||
"-ms-transform" : trans,
|
||||
"-webkit-transition" : "0ms",
|
||||
"-webkit-transform" : trans,
|
||||
"transition" : "0ms",
|
||||
"transform" : trans
|
||||
});
|
||||
} else {
|
||||
this._list.eq(i).css("left", tmp + "px");
|
||||
}
|
||||
|
||||
this._pos[i] = tmp;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
touchend : function (e) {
|
||||
if((e.type == "touchend" && e.originalEvent.touches.length <= 1) || e.type == "dragend") {
|
||||
if(this._scroll) {
|
||||
this._drag = false;
|
||||
this._scroll = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.animate(this.direction());
|
||||
this._drag = false;
|
||||
this._scroll = false;
|
||||
}
|
||||
},
|
||||
|
||||
position : function (d) {
|
||||
var gap = this._view * this._item_w;
|
||||
|
||||
if(d == -1 || d == 1) {
|
||||
this._startX = 0;
|
||||
this._start = [];
|
||||
for(var i=0; i<this._len; ++i) {
|
||||
this._start[i] = this._pos[i];
|
||||
}
|
||||
this._left = d * gap;
|
||||
} else {
|
||||
if(this._left > gap) this._left = gap;
|
||||
if(this._left < - gap) this._left = - gap;
|
||||
}
|
||||
|
||||
if(this.opts.roll) {
|
||||
var tmp_pos = [];
|
||||
for(var i=0; i<this._len; ++i) {
|
||||
tmp_pos[i] = this._pos[i];
|
||||
}
|
||||
tmp_pos.sort(function(a,b){return a-b;});
|
||||
|
||||
|
||||
var max_chk = tmp_pos[this._len-this._view];
|
||||
var p_min = $.inArray(tmp_pos[0], this._pos);
|
||||
var p_max = $.inArray(max_chk, this._pos);
|
||||
|
||||
|
||||
if(this._view <= 1) max_chk = this._len - 1;
|
||||
if(this.opts.multi) {
|
||||
if((d == 1 && tmp_pos[0] >= 0) || (this._drag && tmp_pos[0] >= 100)) {
|
||||
for(var i=0; i<this._view; ++i, ++p_min, ++p_max) {
|
||||
this._start[p_max] = this._start[p_min] - gap;
|
||||
this._list.eq(p_max).css("left", this._start[p_max] + "px");
|
||||
}
|
||||
} else if((d == -1 && tmp_pos[0] <= 0) || (this._drag && tmp_pos[0] <= -100)) {
|
||||
for(var i=0; i<this._view; ++i, ++p_min, ++p_max) {
|
||||
this._start[p_min] = this._start[p_max] + gap;
|
||||
this._list.eq(p_min).css("left", this._start[p_min] + "px");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((d == 1 && tmp_pos[0] >= 0) || (this._drag && tmp_pos[0] > 0)) {
|
||||
for(var i=0; i<this._view; ++i, ++p_min, ++p_max) {
|
||||
this._start[p_max] = this._start[p_min] - gap;
|
||||
this._list.eq(p_max).css("left", this._start[p_max] + "px");
|
||||
}
|
||||
} else if((d == -1 && tmp_pos[max_chk] <= 0) || (this._drag && tmp_pos[max_chk] <= 0)) {
|
||||
for(var i=0; i<this._view; ++i, ++p_min, ++p_max) {
|
||||
this._start[p_min] = this._start[p_max] + gap;
|
||||
this._list.eq(p_min).css("left", this._start[p_min] + "px");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(this.limit_chk()) this._left = this._left / 2;
|
||||
}
|
||||
},
|
||||
|
||||
animate : function (d, btn_click) {
|
||||
if(this._drag || !this._scroll || btn_click) {
|
||||
var _this = this;
|
||||
var speed = this._speed;
|
||||
|
||||
if(btn_click) this.position(d);
|
||||
|
||||
var gap = d * (this._item_w * this._view);
|
||||
if(this._left == 0 || (!this.opts.roll && this.limit_chk()) ) gap = 0;
|
||||
|
||||
this._list.each(function (i, el) {
|
||||
_this._pos[i] = _this._start[i] + gap;
|
||||
|
||||
if(_this.opts.supportsCssTransitions && _this.opts.transition) {
|
||||
var transition = speed + "ms";
|
||||
var transform = "translate3d(" + _this._pos[i] + "px,0,0)";
|
||||
|
||||
if(btn_click) transition = "0ms";
|
||||
|
||||
$(this).css({
|
||||
"left" : "",
|
||||
"-moz-transition" : transition,
|
||||
"-moz-transform" : transform,
|
||||
"-ms-transition" : transition,
|
||||
"-ms-transform" : transform,
|
||||
"-webkit-transition" : transition,
|
||||
"-webkit-transform" : transform,
|
||||
"transition" : transition,
|
||||
"transform" : transform
|
||||
});
|
||||
} else {
|
||||
$(this).stop();
|
||||
$(this).animate({"left": _this._pos[i] + "px"}, speed);
|
||||
}
|
||||
});
|
||||
|
||||
this.counter();
|
||||
}
|
||||
},
|
||||
|
||||
direction : function () {
|
||||
var r = 0;
|
||||
|
||||
if(this._left < -(this._range)) r = -1;
|
||||
else if(this._left > this._range) r = 1;
|
||||
|
||||
if(!this._drag || this._scroll) r = 0;
|
||||
|
||||
return r;
|
||||
},
|
||||
|
||||
limit_chk : function () {
|
||||
var last_p = parseInt((this._len - 1) / this._view) * this._view;
|
||||
return ( (this._start[0] == 0 && this._left > 0) || (this._start[last_p] == 0 && this._left < 0) );
|
||||
},
|
||||
|
||||
go_page : function (i, e) {
|
||||
var crt = ($.inArray(0, this._pos) / this._view) + 1;
|
||||
var cal = crt - (i + 1);
|
||||
|
||||
while(cal != 0) {
|
||||
if(cal < 0) {
|
||||
this.animate(-1, true);
|
||||
cal++;
|
||||
} else if(cal > 0) {
|
||||
this.animate(1, true);
|
||||
cal--;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
counter : function () {
|
||||
if(typeof(this.opts.counter) == "function") {
|
||||
var param = {
|
||||
total : Math.ceil(this._len / this._view),
|
||||
current : ($.inArray(0, this._pos) / this._view) + 1
|
||||
};
|
||||
this.opts.counter(param);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,599 @@
|
||||
/**
|
||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||
*
|
||||
* @namespace md5
|
||||
* @version 0.4.2
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = typeof window === 'object' ? window : {};
|
||||
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||
if (NODE_JS) {
|
||||
root = global;
|
||||
}
|
||||
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
var AMD = typeof define === 'function' && define.amd;
|
||||
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var EXTRA = [128, 32768, 8388608, -2147483648];
|
||||
var SHIFT = [0, 8, 16, 24];
|
||||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
|
||||
|
||||
var blocks = [], buffer8;
|
||||
if (ARRAY_BUFFER) {
|
||||
var buffer = new ArrayBuffer(68);
|
||||
buffer8 = new Uint8Array(buffer);
|
||||
blocks = new Uint32Array(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
* @memberof md5
|
||||
* @description Output hash as hex string
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {String} Hex string
|
||||
* @example
|
||||
* md5.hex('The quick brown fox jumps over the lazy dog');
|
||||
* // equal to
|
||||
* md5('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method digest
|
||||
* @memberof md5
|
||||
* @description Output hash as bytes array
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Array} Bytes array
|
||||
* @example
|
||||
* md5.digest('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method array
|
||||
* @memberof md5
|
||||
* @description Output hash as bytes array
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Array} Bytes array
|
||||
* @example
|
||||
* md5.array('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method arrayBuffer
|
||||
* @memberof md5
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @example
|
||||
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
/**
|
||||
* @method buffer
|
||||
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||
* @memberof md5
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @example
|
||||
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
var createOutputMethod = function (outputType) {
|
||||
return function (message) {
|
||||
return new Md5(true).update(message)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @method create
|
||||
* @memberof md5
|
||||
* @description Create Md5 object
|
||||
* @returns {Md5} Md5 object.
|
||||
* @example
|
||||
* var hash = md5.create();
|
||||
*/
|
||||
/**
|
||||
* @method update
|
||||
* @memberof md5
|
||||
* @description Create and update Md5 object
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Md5} Md5 object.
|
||||
* @example
|
||||
* var hash = md5.update('The quick brown fox jumps over the lazy dog');
|
||||
* // equal to
|
||||
* var hash = md5.create();
|
||||
* hash.update('The quick brown fox jumps over the lazy dog');
|
||||
*/
|
||||
var createMethod = function () {
|
||||
var method = createOutputMethod('hex');
|
||||
if (NODE_JS) {
|
||||
method = nodeWrap(method);
|
||||
}
|
||||
method.create = function () {
|
||||
return new Md5();
|
||||
};
|
||||
method.update = function (message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createOutputMethod(type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var nodeWrap = function (method) {
|
||||
var crypto = require('crypto');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var nodeMethod = function (message) {
|
||||
if (typeof message === 'string') {
|
||||
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (message.length === undefined) {
|
||||
return method(message);
|
||||
}
|
||||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
|
||||
};
|
||||
return nodeMethod;
|
||||
};
|
||||
|
||||
/**
|
||||
* Md5 class
|
||||
* @class Md5
|
||||
* @description This is internal class.
|
||||
* @see {@link md5.create}
|
||||
*/
|
||||
function Md5(sharedMemory) {
|
||||
if (sharedMemory) {
|
||||
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
this.blocks = blocks;
|
||||
this.buffer8 = buffer8;
|
||||
} else {
|
||||
if (ARRAY_BUFFER) {
|
||||
var buffer = new ArrayBuffer(68);
|
||||
this.buffer8 = new Uint8Array(buffer);
|
||||
this.blocks = new Uint32Array(buffer);
|
||||
} else {
|
||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
}
|
||||
}
|
||||
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = 0;
|
||||
this.finalized = this.hashed = false;
|
||||
this.first = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Update hash
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {Md5} Md5 object.
|
||||
* @see {@link md5.update}
|
||||
*/
|
||||
Md5.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
var notString = typeof(message) != 'string';
|
||||
if (notString && message.constructor == root.ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
||||
var buffer8 = this.buffer8;
|
||||
|
||||
while (index < length) {
|
||||
if (this.hashed) {
|
||||
this.hashed = false;
|
||||
blocks[0] = blocks[16];
|
||||
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
|
||||
if (notString) {
|
||||
if (ARRAY_BUFFER) {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
buffer8[i++] = message[index];
|
||||
}
|
||||
} else {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ARRAY_BUFFER) {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
buffer8[i++] = code;
|
||||
} else if (code < 0x800) {
|
||||
buffer8[i++] = 0xc0 | (code >> 6);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
buffer8[i++] = 0xe0 | (code >> 12);
|
||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
buffer8[i++] = 0xf0 | (code >> 18);
|
||||
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
|
||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
||||
} else if (code < 0x800) {
|
||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastByteIndex = i;
|
||||
this.bytes += i - this.start;
|
||||
if (i >= 64) {
|
||||
this.start = i - 64;
|
||||
this.hash();
|
||||
this.hashed = true;
|
||||
} else {
|
||||
this.start = i;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Md5.prototype.finalize = function () {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
this.finalized = true;
|
||||
var blocks = this.blocks, i = this.lastByteIndex;
|
||||
blocks[i >> 2] |= EXTRA[i & 3];
|
||||
if (i >= 56) {
|
||||
if (!this.hashed) {
|
||||
this.hash();
|
||||
}
|
||||
blocks[0] = blocks[16];
|
||||
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
blocks[14] = this.bytes << 3;
|
||||
this.hash();
|
||||
};
|
||||
|
||||
Md5.prototype.hash = function () {
|
||||
var a, b, c, d, bc, da, blocks = this.blocks;
|
||||
|
||||
if (this.first) {
|
||||
a = blocks[0] - 680876937;
|
||||
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
||||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
} else {
|
||||
a = this.h0;
|
||||
b = this.h1;
|
||||
c = this.h2;
|
||||
d = this.h3;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
}
|
||||
|
||||
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
|
||||
a = (a << 7 | a >>> 25) + b << 0;
|
||||
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
|
||||
d = (d << 12 | d >>> 20) + a << 0;
|
||||
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
|
||||
c = (c << 17 | c >>> 15) + d << 0;
|
||||
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
|
||||
b = (b << 22 | b >>> 10) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
|
||||
a = (a << 5 | a >>> 27) + b << 0;
|
||||
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
|
||||
d = (d << 9 | d >>> 23) + a << 0;
|
||||
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
|
||||
c = (c << 14 | c >>> 18) + d << 0;
|
||||
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
|
||||
b = (b << 20 | b >>> 12) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[5] - 378558;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[8] - 2022574463;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[11] + 1839030562;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[14] - 35309556;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[1] - 1530992060;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[4] + 1272893353;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[7] - 155497632;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[10] - 1094730640;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[13] + 681279174;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[0] - 358537222;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[3] - 722521979;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[6] + 76029189;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
bc = b ^ c;
|
||||
a += (bc ^ d) + blocks[9] - 640364487;
|
||||
a = (a << 4 | a >>> 28) + b << 0;
|
||||
d += (bc ^ a) + blocks[12] - 421815835;
|
||||
d = (d << 11 | d >>> 21) + a << 0;
|
||||
da = d ^ a;
|
||||
c += (da ^ b) + blocks[15] + 530742520;
|
||||
c = (c << 16 | c >>> 16) + d << 0;
|
||||
b += (da ^ c) + blocks[2] - 995338651;
|
||||
b = (b << 23 | b >>> 9) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[0] - 198630844;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[5] - 57434055;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[10] - 1051523;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[15] - 30611744;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
a += (c ^ (b | ~d)) + blocks[4] - 145523070;
|
||||
a = (a << 6 | a >>> 26) + b << 0;
|
||||
d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
|
||||
d = (d << 10 | d >>> 22) + a << 0;
|
||||
c += (a ^ (d | ~b)) + blocks[2] + 718787259;
|
||||
c = (c << 15 | c >>> 17) + d << 0;
|
||||
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
||||
b = (b << 21 | b >>> 11) + c << 0;
|
||||
|
||||
if (this.first) {
|
||||
this.h0 = a + 1732584193 << 0;
|
||||
this.h1 = b - 271733879 << 0;
|
||||
this.h2 = c - 1732584194 << 0;
|
||||
this.h3 = d + 271733878 << 0;
|
||||
this.first = false;
|
||||
} else {
|
||||
this.h0 = this.h0 + a << 0;
|
||||
this.h1 = this.h1 + b << 0;
|
||||
this.h2 = this.h2 + c << 0;
|
||||
this.h3 = this.h3 + d << 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as hex string
|
||||
* @returns {String} Hex string
|
||||
* @see {@link md5.hex}
|
||||
* @example
|
||||
* hash.hex();
|
||||
*/
|
||||
Md5.prototype.hex = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||
|
||||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
|
||||
};
|
||||
|
||||
/**
|
||||
* @method toString
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as hex string
|
||||
* @returns {String} Hex string
|
||||
* @see {@link md5.hex}
|
||||
* @example
|
||||
* hash.toString();
|
||||
*/
|
||||
Md5.prototype.toString = Md5.prototype.hex;
|
||||
|
||||
/**
|
||||
* @method digest
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as bytes array
|
||||
* @returns {Array} Bytes array
|
||||
* @see {@link md5.digest}
|
||||
* @example
|
||||
* hash.digest();
|
||||
*/
|
||||
Md5.prototype.digest = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||
return [
|
||||
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF,
|
||||
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF,
|
||||
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF,
|
||||
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* @method array
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as bytes array
|
||||
* @returns {Array} Bytes array
|
||||
* @see {@link md5.array}
|
||||
* @example
|
||||
* hash.array();
|
||||
*/
|
||||
Md5.prototype.array = Md5.prototype.digest;
|
||||
|
||||
/**
|
||||
* @method arrayBuffer
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @see {@link md5.arrayBuffer}
|
||||
* @example
|
||||
* hash.arrayBuffer();
|
||||
*/
|
||||
Md5.prototype.arrayBuffer = function () {
|
||||
this.finalize();
|
||||
|
||||
var buffer = new ArrayBuffer(16);
|
||||
var blocks = new Uint32Array(buffer);
|
||||
blocks[0] = this.h0;
|
||||
blocks[1] = this.h1;
|
||||
blocks[2] = this.h2;
|
||||
blocks[3] = this.h3;
|
||||
return buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @method buffer
|
||||
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||
* @memberof Md5
|
||||
* @instance
|
||||
* @description Output hash as ArrayBuffer
|
||||
* @returns {ArrayBuffer} ArrayBuffer
|
||||
* @see {@link md5.buffer}
|
||||
* @example
|
||||
* hash.buffer();
|
||||
*/
|
||||
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
|
||||
|
||||
var exports = createMethod();
|
||||
|
||||
if (COMMON_JS) {
|
||||
module.exports = exports;
|
||||
} else {
|
||||
/**
|
||||
* @method md5
|
||||
* @description Md5 hash function, export to global in browsers.
|
||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||
* @returns {String} md5 hashes
|
||||
* @example
|
||||
* md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||
* md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
|
||||
* md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
||||
*
|
||||
* // It also supports UTF-8 encoding
|
||||
* md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||
*
|
||||
* // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
||||
* md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||
* md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||
*/
|
||||
root.md5 = exports;
|
||||
if (AMD) {
|
||||
define(function () {
|
||||
return exports;
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,34 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<header>
|
||||
<meta charset="UTF-8">
|
||||
</header>
|
||||
<div>
|
||||
<form method="POST" enctype="multipart/form-data" id="upload_form">
|
||||
<table>
|
||||
<tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
|
||||
<tr><td></td><td><input type="button" value="上传文件" onclick="uploadImage()"/></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
|
||||
<script type="text/javascript" src="/js/jquery.form.js" ></script>
|
||||
<script type="text/javascript">
|
||||
function uploadImage(){
|
||||
$("#upload_form").ajaxSubmit({
|
||||
url : "/files-anon",
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
asyn:false,
|
||||
success:function(data){
|
||||
if(data.code!='10000'){
|
||||
alert(JSON.stringify(data));
|
||||
return;
|
||||
}
|
||||
alert(JSON.stringify(data));
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<div>
|
||||
<form method="POST" enctype="multipart/form-data" id="upload_form">
|
||||
<table>
|
||||
<tr><td>File1 to upload:</td><td><input type="file" name="file1" /></td></tr>
|
||||
<tr><td>File2 to upload:</td><td><input type="file" name="file2" /></td></tr>
|
||||
<tr><td></td><td><input type="button" value="上传文件" onclick="uploadImage()"/></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
|
||||
<script type="text/javascript" src="/js/jquery.form.js" ></script>
|
||||
<script type="text/javascript">
|
||||
function uploadImage(){
|
||||
$("#upload_form").ajaxSubmit({
|
||||
url : "/files-anon",
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
asyn:false,
|
||||
success:function(data){
|
||||
if(data.code!='10000'){
|
||||
alert(JSON.stringify(data));
|
||||
return;
|
||||
}
|
||||
alert(JSON.stringify(data));
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<description>业务中心</description>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!-- 用户中心 -->
|
||||
<module>user-center</module>
|
||||
<!-- 文件中心 -->
|
||||
<module>file-center</module>
|
||||
<!-- 代码生成器 -->
|
||||
<module>code-generator</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,84 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>user-center</artifactId>
|
||||
<description>用户中心</description>
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-swagger2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-annotation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.central;
|
||||
|
||||
import com.central.common.annotation.EnableLoginArgResolver;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableLoginArgResolver
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@EnableTransactionManagement
|
||||
@SpringBootApplication
|
||||
public class UserCenterApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UserCenterApp.class, args);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.central.user.config;
|
||||
|
||||
import com.central.common.config.DefaultAsycTaskConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 线程池配置、启用异步
|
||||
* @Async quartz 需要使用
|
||||
*/
|
||||
@Configuration
|
||||
public class AsycTaskExecutorConfig extends DefaultAsycTaskConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.central.user.config;
|
||||
|
||||
import com.central.common.exception.DefaultExceptionAdvice;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2018/12/22
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class ExceptionAdvice extends DefaultExceptionAdvice {
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.central.user.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
|
||||
import com.central.db.config.DefaultMybatisPlusConfig;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2018/12/10
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan({"com.central.user.mapper*"})
|
||||
public class MybatisPlusConfig extends DefaultMybatisPlusConfig {
|
||||
@Bean
|
||||
public ISqlInjector sqlInjector(){
|
||||
return new LogicSqlInjector();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.central.user.config;
|
||||
|
||||
import com.central.common.config.DefaultPasswordConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/1/2
|
||||
*/
|
||||
@Configuration
|
||||
public class PasswordConfig extends DefaultPasswordConfig {
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.central.user.service.ISysMenuService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "菜单模块api")
|
||||
@Slf4j
|
||||
@RequestMapping("/menus")
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
private ISysMenuService menuService;
|
||||
|
||||
/**
|
||||
* 两层循环实现建树
|
||||
*
|
||||
* @param sysMenus
|
||||
* @return
|
||||
*/
|
||||
public static List<SysMenu> treeBuilder(List<SysMenu> sysMenus) {
|
||||
List<SysMenu> menus = new ArrayList<>();
|
||||
for (SysMenu sysMenu : sysMenus) {
|
||||
if (ObjectUtils.equals(-1L, sysMenu.getParentId())) {
|
||||
menus.add(sysMenu);
|
||||
}
|
||||
for (SysMenu menu : sysMenus) {
|
||||
if (menu.getParentId().equals(sysMenu.getId())) {
|
||||
if (sysMenu.getSubMenus() == null) {
|
||||
sysMenu.setSubMenus(new ArrayList<>());
|
||||
}
|
||||
sysMenu.getSubMenus().add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@ApiOperation(value = "删除菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
try {
|
||||
menuService.removeById(id);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("memu-delete-error", ex);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据roleId获取对应的菜单")
|
||||
@GetMapping("/{roleId}/menus")
|
||||
public List<Map<String, Object>> findMenusByRoleId(@PathVariable Long roleId) {
|
||||
Set<Long> roleIds = new HashSet<Long>() {{
|
||||
add(roleId);
|
||||
}};
|
||||
//获取该角色对应的菜单
|
||||
List<SysMenu> roleMenus = menuService.findByRoles(roleIds);
|
||||
//全部的菜单列表
|
||||
List<SysMenu> allMenus = menuService.findAll();
|
||||
List<Map<String, Object>> authTrees = new ArrayList<>();
|
||||
|
||||
Map<Long, SysMenu> roleMenusMap = roleMenus.stream().collect(Collectors.toMap(SysMenu::getId, SysMenu -> SysMenu));
|
||||
|
||||
for (SysMenu sysMenu : allMenus) {
|
||||
Map<String, Object> authTree = new HashMap<>();
|
||||
authTree.put("id", sysMenu.getId());
|
||||
authTree.put("name", sysMenu.getName());
|
||||
authTree.put("pId", sysMenu.getParentId());
|
||||
authTree.put("open", true);
|
||||
authTree.put("checked", false);
|
||||
if (roleMenusMap.get(sysMenu.getId()) != null) {
|
||||
authTree.put("checked", true);
|
||||
}
|
||||
authTrees.add(authTree);
|
||||
}
|
||||
return authTrees;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据roleCodes获取对应的权限")
|
||||
@SuppressWarnings("unchecked")
|
||||
@Cacheable(value = "menu", key ="#roleCodes")
|
||||
@GetMapping("/{roleCodes}")
|
||||
public List<SysMenu> findMenuByRoles(@PathVariable String roleCodes) {
|
||||
List<SysMenu> result = null;
|
||||
if (StringUtils.isNotEmpty(roleCodes)) {
|
||||
Set<String> roleSet = (Set<String>)Convert.toCollection(HashSet.class, String.class, roleCodes);
|
||||
result = menuService.findByRoleCodes(roleSet, CommonConstant.PERMISSION);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给角色分配菜单
|
||||
*/
|
||||
@ApiOperation(value = "角色分配菜单")
|
||||
@PostMapping("/granted")
|
||||
public Result setMenuToRole(@RequestBody SysMenu sysMenu) {
|
||||
menuService.setMenuToRole(sysMenu.getRoleId(), sysMenu.getMenuIds());
|
||||
return Result.succeed("操作成功");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询所有菜单")
|
||||
@GetMapping("/findAlls")
|
||||
public PageResult<SysMenu> findAlls() {
|
||||
List<SysMenu> list = menuService.findAll();
|
||||
return PageResult.<SysMenu>builder().data(list).code(0).count((long) list.size()).build();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取菜单以及顶级菜单")
|
||||
@GetMapping("/findOnes")
|
||||
public PageResult<SysMenu> findOnes() {
|
||||
List<SysMenu> list = menuService.findOnes();
|
||||
return PageResult.<SysMenu>builder().data(list).code(0).count((long) list.size()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单 或者 更新
|
||||
*
|
||||
* @param menu
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "新增菜单")
|
||||
@PostMapping("saveOrUpdate")
|
||||
public Result saveOrUpdate(@RequestBody SysMenu menu) {
|
||||
try {
|
||||
menuService.saveOrUpdate(menu);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("memu-saveOrUpdate-error", ex);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录用户的菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/current")
|
||||
@ApiOperation(value = "查询当前用户菜单")
|
||||
public List<SysMenu> findMyMenu(@LoginUser SysUser user) {
|
||||
List<SysRole> roles = user.getRoles();
|
||||
if (CollectionUtil.isEmpty(roles)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<SysMenu> menus = menuService.findByRoleCodes(roles.parallelStream().map(SysRole::getCode).collect(Collectors.toSet()), CommonConstant.MENU);
|
||||
List<SysMenu> sysMenus = treeBuilder(menus);
|
||||
return sysMenus;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.user.service.ISysRoleService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "角色模块api")
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
/**
|
||||
* 后台管理查询角色
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "后台管理查询角色")
|
||||
@GetMapping("/roles")
|
||||
public PageResult<SysRole> findRoles(@RequestParam Map<String, Object> params) {
|
||||
return sysRoleService.findRoles(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色新增或者更新
|
||||
*
|
||||
* @param sysRole
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/roles/saveOrUpdate")
|
||||
public Result saveOrUpdate(@RequestBody SysRole sysRole) {
|
||||
return sysRoleService.saveOrUpdateRole(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理删除角色
|
||||
* delete /role/1
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@ApiOperation(value = "后台管理删除角色")
|
||||
@DeleteMapping("/roles/{id}")
|
||||
public Result deleteRole(@PathVariable Long id) {
|
||||
try {
|
||||
if (id == 1L) {
|
||||
return Result.failed("管理员不可以删除");
|
||||
}
|
||||
sysRoleService.deleteRole(id);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception e) {
|
||||
log.error("role-deleteRole-error", e);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.*;
|
||||
import com.central.common.utils.ExcelUtil;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.central.common.utils.SysUserUtil;
|
||||
import com.central.user.service.ISysUserService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 用户
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RefreshScope
|
||||
@Api(tags = "用户模块api")
|
||||
public class SysUserController {
|
||||
@Autowired
|
||||
private ISysUserService appUserService;
|
||||
|
||||
/**
|
||||
* 当前登录用户 LoginAppUser
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据access_token当前登录用户")
|
||||
@GetMapping("/users/current")
|
||||
public LoginAppUser getLoginAppUser(@LoginUser(isFull = true) SysUser user) {
|
||||
return SysUserUtil.getLoginAppUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户实体对象SysUser
|
||||
*/
|
||||
@GetMapping(value = "/users/name/{username}")
|
||||
@ApiOperation(value = "根据用户名查询用户实体")
|
||||
@Cacheable(value = "user", key = "#username")
|
||||
public SysUser selectByUsername(@PathVariable String username) {
|
||||
return appUserService.selectByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户登录对象LoginAppUser
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/login", params = "username")
|
||||
@ApiOperation(value = "根据用户名查询用户")
|
||||
public LoginAppUser findByUsername(String username) {
|
||||
return appUserService.findByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号查询用户、角色信息
|
||||
*
|
||||
* @param mobile 手机号
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/mobile", params = "mobile")
|
||||
@ApiOperation(value = "根据手机号查询用户")
|
||||
public SysUser findByMobile(String mobile) {
|
||||
return appUserService.findByMobile(mobile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据OpenId查询用户信息
|
||||
*
|
||||
* @param openId openId
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/openId", params = "openId")
|
||||
@ApiOperation(value = "根据OpenId查询用户")
|
||||
public SysUser findByOpenId(String openId) {
|
||||
return appUserService.findByOpenId(openId);
|
||||
}
|
||||
|
||||
@GetMapping("/users/{id}")
|
||||
public SysUser findUserById(@PathVariable Long id) {
|
||||
return appUserService.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台修改用户
|
||||
*
|
||||
* @param sysUser
|
||||
*/
|
||||
@PutMapping("/users")
|
||||
@CachePut(value = "user", key = "#sysUser.username")
|
||||
public void updateSysUser(@RequestBody SysUser sysUser) {
|
||||
appUserService.updateById(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台给用户分配角色
|
||||
*
|
||||
* @param id
|
||||
* @param roleIds
|
||||
*/
|
||||
@PostMapping("/users/{id}/roles")
|
||||
public void setRoleToUser(@PathVariable Long id, @RequestBody Set<Long> roleIds) {
|
||||
appUserService.setRoleToUser(id, roleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的角色
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/users/{id}/roles")
|
||||
public List<SysRole> findRolesByUserId(@PathVariable Long id) {
|
||||
return appUserService.findRolesByUserId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户查询
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "用户查询列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
|
||||
})
|
||||
@GetMapping("/users")
|
||||
public PageResult<SysUser> findUsers(@RequestParam Map<String, Object> params) {
|
||||
return appUserService.findUsers(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改用户状态")
|
||||
@GetMapping("/users/updateEnabled")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "enabled", value = "是否启用", required = true, dataType = "Boolean")
|
||||
})
|
||||
public Result updateEnabled(@RequestParam Map<String, Object> params) {
|
||||
Long id = MapUtils.getLong(params, "id");
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed("超级管理员不给予修改");
|
||||
}
|
||||
return appUserService.updateEnabled(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台,给用户重置密码
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PutMapping(value = "/users/{id}/password")
|
||||
public Result resetPassword(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed("超级管理员不给予修改");
|
||||
}
|
||||
appUserService.updatePassword(id, null, null);
|
||||
return Result.succeed("重置成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自己修改密码
|
||||
*/
|
||||
@PutMapping(value = "/users/password")
|
||||
public Result resetPassword(@RequestBody SysUser sysUser) {
|
||||
if (checkAdmin(sysUser.getId())) {
|
||||
return Result.failed("超级管理员不给予修改");
|
||||
}
|
||||
appUserService.updatePassword(sysUser.getId(), sysUser.getOldPassword(), sysUser.getNewPassword());
|
||||
return Result.succeed("重置成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@DeleteMapping(value = "/users/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed("超级管理员不给予修改");
|
||||
}
|
||||
appUserService.delUser(id);
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增or更新
|
||||
*
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(value = "user", key = "#sysUser.username")
|
||||
@PostMapping("/users/saveOrUpdate")
|
||||
public Result saveOrUpdate(@RequestBody SysUser sysUser) {
|
||||
return appUserService.saveOrUpdateUser(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/users/export")
|
||||
public void exportUser(@RequestParam Map<String, Object> params, HttpServletResponse response) throws IOException {
|
||||
List<SysUserExcel> result = appUserService.findAllUsers(params);
|
||||
//导出操作
|
||||
ExcelUtil.exportExcel(result, null, "用户", SysUserExcel.class, "test", response);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/users/import")
|
||||
public Result importExcl(@RequestParam("file") MultipartFile excl) throws Exception {
|
||||
int rowNum = 0;
|
||||
if(!excl.isEmpty()) {
|
||||
List<SysUserExcel> list = ExcelUtil.importExcel(excl, 0, 1, SysUserExcel.class);
|
||||
rowNum = list.size();
|
||||
if (rowNum > 0) {
|
||||
List<SysUser> users = new ArrayList<>(rowNum);
|
||||
list.forEach(u -> {
|
||||
SysUser user = new SysUser();
|
||||
BeanUtil.copyProperties(u, user);
|
||||
user.setPassword(CommonConstant.DEF_USER_PASSWORD);
|
||||
user.setType(UserType.BACKEND.name());
|
||||
users.add(user);
|
||||
});
|
||||
appUserService.saveUsers(users);
|
||||
}
|
||||
}
|
||||
return Result.succeed("导入数据成功,一共【"+rowNum+"】行");
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否超级管理员
|
||||
*/
|
||||
private boolean checkAdmin(long id) {
|
||||
return id == 1L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.common.model.SysMenu;
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
public interface SysMenuMapper extends SuperMapper<SysMenu> {
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.central.common.model.SysPermission;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 权限
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysPermissionMapper {
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into sys_permission(permission, name, createTime, updateTime) values(#{permission}, #{name}, #{createTime}, #{createTime})")
|
||||
int save(SysPermission sysPermission);
|
||||
|
||||
@Update("update sys_permission t set t.name = #{name}, t.permission = #{permission}, t.updateTime = #{updateTime} where t.id = #{id}")
|
||||
int update(SysPermission sysPermission);
|
||||
|
||||
@Delete("delete from sys_permission where id = #{id}")
|
||||
int delete(Long id);
|
||||
|
||||
@Select("select * from sys_permission t where t.id = #{id}")
|
||||
SysPermission findById(Long id);
|
||||
|
||||
@Select("select * from sys_permission t where t.permission = #{permission}")
|
||||
SysPermission findByPermission(String permission);
|
||||
|
||||
int count(Map<String, Object> params);
|
||||
|
||||
List<SysPermission> findList(Map<String, Object> params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
|
||||
import com.central.common.model.SysRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色
|
||||
*/
|
||||
public interface SysRoleMapper extends SuperMapper<SysRole> {
|
||||
List<SysRole> findList(Page<SysRole> page, @Param("r") Map<String, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色菜单
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper {
|
||||
@Insert("insert into sys_role_menu(role_id, menu_id) values(#{roleId}, #{menuId})")
|
||||
int save(@Param("roleId") Long roleId, @Param("menuId") Long menuId);
|
||||
|
||||
int delete(@Param("roleId") Long roleId, @Param("menuId") Long menuId);
|
||||
|
||||
List<SysMenu> findMenusByRoleIds(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
||||
|
||||
List<SysMenu> findMenusByRoleCodes(@Param("roleCodes") Set<String> roleCodes, @Param("type") Integer type);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.central.common.model.SysPermission;
|
||||
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色权限关系
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRolePermissionMapper {
|
||||
|
||||
@Insert("insert into sys_role_permission(roleId, permissionId) values(#{roleId}, #{permissionId})")
|
||||
int saveRolePermission(@Param("roleId") Long roleId, @Param("permissionId") Long permissionId);
|
||||
|
||||
int deleteRolePermission(@Param("roleId") Long roleId, @Param("permissionId") Long permissionId);
|
||||
|
||||
Set<SysPermission> findPermissionsByRoleIds(@Param("roleIds") Set<Long> roleIds);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.common.model.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户表 Mapper 接口
|
||||
*
|
||||
* @author zlt
|
||||
* @data 2018-10-29
|
||||
*/
|
||||
public interface SysUserMapper extends SuperMapper<SysUser> {
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
* @param page
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<SysUser> findList(Page<SysUser> page, @Param("u") Map<String, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.central.common.model.SysRole;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 用户角色关系
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper {
|
||||
int deleteUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
@Insert("insert into sys_role_user(user_id, role_id) values(#{userId}, #{roleId})")
|
||||
int saveUserRoles(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Select("select r.* from sys_role_user ru inner join sys_role r on r.id = ru.role_id where ru.user_id = #{userId}")
|
||||
List<SysRole> findRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ids 获取
|
||||
*
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
@Select("<script>select r.*,ru.user_id from sys_role_user ru inner join sys_role r on r.id = ru.role_id where ru.user_id IN " +
|
||||
" <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'> " +
|
||||
" #{item} " +
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
List<SysRole> findRolesByUserIds(List<Long> userIds);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.central.user.model;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户导出实例
|
||||
* @Author: zlt
|
||||
*/
|
||||
@Data
|
||||
public class SysUserExcel implements Serializable {
|
||||
private static final long serialVersionUID = -5886012896705137070L;
|
||||
|
||||
@Excel(name = "用户姓名", height = 20, width = 30, isImportField = "true_st")
|
||||
private String username;
|
||||
|
||||
@Excel(name = "用户昵称", height = 20, width = 30, isImportField = "true_st")
|
||||
private String nickname;
|
||||
|
||||
@Excel(name = "手机号码", height = 20, width = 30, isImportField = "true_st")
|
||||
private String mobile;
|
||||
|
||||
@Excel(name = "学生性别", replace = { "男_0", "女_1" }, suffix = "生", isImportField = "true_st")
|
||||
private Integer sex;
|
||||
|
||||
@Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss", isImportField = "true_st", width = 20)
|
||||
private Date createTime;
|
||||
|
||||
@Excel(name = "修改时间", format = "yyyy-MM-dd HH:mm:ss", isImportField = "true_st", width = 20)
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.ISuperService;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysMenuService extends ISuperService<SysMenu> {
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*/
|
||||
List<SysMenu> findAll();
|
||||
|
||||
/**
|
||||
* 查询所有一级菜单
|
||||
*/
|
||||
List<SysMenu> findOnes();
|
||||
|
||||
/**
|
||||
* 角色分配菜单
|
||||
* @param roleId
|
||||
* @param menuIds
|
||||
*/
|
||||
void setMenuToRole(Long roleId, Set<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoles(Set<Long> roleIds);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @param roleIds 是否菜单
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoles(Set<Long> roleIds, Integer type);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleCodes
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoleCodes(Set<String> roleCodes, Integer type);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.service.ISuperService;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysRoleService extends ISuperService<SysRole> {
|
||||
void saveRole(SysRole sysRole);
|
||||
|
||||
void deleteRole(Long id);
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageResult<SysRole> findRoles(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 新增或更新角色
|
||||
* @param sysRole
|
||||
* @return Result
|
||||
*/
|
||||
Result saveOrUpdateRole(SysRole sysRole);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.model.SysUser;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysUserService extends ISuperService<SysUser> {
|
||||
/**
|
||||
* 获取UserDetails对象
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
LoginAppUser findByUsername(String username);
|
||||
|
||||
LoginAppUser findByOpenId(String username);
|
||||
|
||||
LoginAppUser findByMobile(String username);
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByUsername(String username);
|
||||
/**
|
||||
* 根据手机号查询用户
|
||||
* @param mobile
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByMobile(String mobile);
|
||||
/**
|
||||
* 根据openId查询用户
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByOpenId(String openId);
|
||||
|
||||
/**
|
||||
* 用户分配角色
|
||||
* @param id
|
||||
* @param roleIds
|
||||
*/
|
||||
void setRoleToUser(Long id, Set<Long> roleIds);
|
||||
|
||||
/**
|
||||
* 更新密码
|
||||
* @param id
|
||||
* @param oldPassword
|
||||
* @param newPassword
|
||||
* @return
|
||||
*/
|
||||
Result updatePassword(Long id, String oldPassword, String newPassword);
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageResult<SysUser> findUsers(Map<String, Object> params);
|
||||
|
||||
|
||||
/**
|
||||
* 用户角色列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 状态变更
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Result updateEnabled(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 查询全部用户
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<SysUserExcel> findAllUsers(Map<String, Object> params);
|
||||
|
||||
Result saveOrUpdateUser(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
boolean delUser(Long id);
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*
|
||||
* @param users
|
||||
*/
|
||||
void saveUsers(List<SysUser> users);
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.user.mapper.SysMenuMapper;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.service.ISysMenuService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends SuperServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
|
||||
@Resource
|
||||
private SysRoleMenuMapper sysRoleMenuMapper;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void setMenuToRole(Long roleId, Set<Long> menuIds) {
|
||||
sysRoleMenuMapper.delete(roleId, null);
|
||||
|
||||
if (!CollectionUtils.isEmpty(menuIds)) {
|
||||
menuIds.forEach(menuId -> {
|
||||
sysRoleMenuMapper.save(roleId, menuId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findByRoles(Set<Long> roleIds) {
|
||||
return sysRoleMenuMapper.findMenusByRoleIds(roleIds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @param roleIds 是否菜单
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findByRoles(Set<Long> roleIds, Integer type) {
|
||||
return sysRoleMenuMapper.findMenusByRoleIds(roleIds, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByRoleCodes(Set<String> roleCodes, Integer type) {
|
||||
return sysRoleMenuMapper.findMenusByRoleCodes(roleCodes, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findAll() {
|
||||
return baseMapper.selectList(
|
||||
new QueryWrapper<SysMenu>().orderByAsc("sort")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有一级菜单
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findOnes() {
|
||||
return baseMapper.selectList(
|
||||
new QueryWrapper<SysMenu>()
|
||||
.eq("type", 1)
|
||||
.orderByAsc("sort")
|
||||
);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.model.*;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.central.user.mapper.SysRoleMapper;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.mapper.SysUserRoleMapper;
|
||||
import com.central.user.service.ISysRoleService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends SuperServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
||||
private final static String LOCK_KEY_ROLECODE = CommonConstant.LOCK_KEY_PREFIX+"rolecode:";
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Autowired
|
||||
private DistributedLock lock;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveRole(SysRole sysRole) {
|
||||
String roleCode = sysRole.getCode();
|
||||
super.saveIdempotency(sysRole, lock
|
||||
, LOCK_KEY_ROLECODE+roleCode, new QueryWrapper<SysRole>().eq("code", roleCode), "角色code已存在");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deleteRole(Long id) {
|
||||
baseMapper.deleteById(id);
|
||||
roleMenuMapper.delete(id, null);
|
||||
userRoleMapper.deleteUserRole(null, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysRole> findRoles(Map<String, Object> params) {
|
||||
Integer curPage = MapUtils.getInteger(params, "page");
|
||||
Integer limit = MapUtils.getInteger(params, "limit");
|
||||
Page<SysRole> page = new Page<>(curPage == null ? 0 : curPage, limit == null ? -1 : limit);
|
||||
List<SysRole> list = baseMapper.findList(page, params);
|
||||
return PageResult.<SysRole>builder().data(list).code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result saveOrUpdateRole(SysRole sysRole) {
|
||||
if (sysRole.getId() == null) {
|
||||
this.saveRole(sysRole);
|
||||
} else {
|
||||
baseMapper.updateById(sysRole);
|
||||
}
|
||||
return Result.succeed("操作成功");
|
||||
}
|
||||
}
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.model.*;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import com.central.user.mapper.SysUserMapper;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.central.user.mapper.SysUserRoleMapper;
|
||||
import com.central.user.service.ISysUserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* userService
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
private final static String LOCK_KEY_USERNAME = CommonConstant.LOCK_KEY_PREFIX+"username:";
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Autowired
|
||||
private DistributedLock lock;
|
||||
|
||||
@Override
|
||||
public LoginAppUser findByUsername(String username) {
|
||||
SysUser sysUser = this.selectByUsername(username);
|
||||
return getLoginAppUser(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginAppUser findByOpenId(String username) {
|
||||
SysUser sysUser = this.selectByOpenId(username);
|
||||
return getLoginAppUser(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginAppUser findByMobile(String username) {
|
||||
SysUser sysUser = this.selectByMobile(username);
|
||||
return getLoginAppUser(sysUser);
|
||||
}
|
||||
|
||||
private LoginAppUser getLoginAppUser(SysUser sysUser) {
|
||||
if (sysUser != null) {
|
||||
LoginAppUser loginAppUser = new LoginAppUser();
|
||||
BeanUtils.copyProperties(sysUser, loginAppUser);
|
||||
|
||||
List<SysRole> sysRoles = userRoleMapper.findRolesByUserId(sysUser.getId());
|
||||
// 设置角色
|
||||
loginAppUser.setRoles(sysRoles);
|
||||
|
||||
if (!CollectionUtils.isEmpty(sysRoles)) {
|
||||
Set<Long> roleIds = sysRoles.parallelStream().map(r -> r.getId()).collect(Collectors.toSet());
|
||||
List<SysMenu> menus = roleMenuMapper.findMenusByRoleIds(roleIds, CommonConstant.PERMISSION);
|
||||
if (!CollectionUtils.isEmpty(menus)) {
|
||||
Set<String> permissions = menus.parallelStream().map(p -> p.getPathMethod()+":"+p.getPath())
|
||||
.collect(Collectors.toSet());
|
||||
// 设置权限集合
|
||||
loginAppUser.setPermissions(permissions);
|
||||
}
|
||||
}
|
||||
return loginAppUser;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByUsername(String username) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("username", username)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户
|
||||
* @param mobile
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByMobile(String mobile) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("mobile", mobile)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openId查询用户
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByOpenId(String openId) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("openId", openId)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
private SysUser getUser(List<SysUser> users) {
|
||||
SysUser user = null;
|
||||
if (users != null && !users.isEmpty()) {
|
||||
user = users.get(0);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户设置角色
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void setRoleToUser(Long id, Set<Long> roleIds) {
|
||||
SysUser sysUser = baseMapper.selectById(id);
|
||||
if (sysUser == null) {
|
||||
throw new IllegalArgumentException("用户不存在");
|
||||
}
|
||||
|
||||
userRoleMapper.deleteUserRole(id, null);
|
||||
if (!CollectionUtils.isEmpty(roleIds)) {
|
||||
roleIds.forEach(roleId -> {
|
||||
userRoleMapper.saveUserRoles(id, roleId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Result updatePassword(Long id, String oldPassword, String newPassword) {
|
||||
SysUser sysUser = baseMapper.selectById(id);
|
||||
if (StrUtil.isNotBlank(oldPassword)) {
|
||||
if (!passwordEncoder.matches(oldPassword, sysUser.getPassword())) {
|
||||
return Result.failed("旧密码错误");
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(newPassword)) {
|
||||
newPassword = CommonConstant.DEF_USER_PASSWORD;
|
||||
}
|
||||
SysUser user = new SysUser();
|
||||
user.setId(id);
|
||||
user.setPassword(passwordEncoder.encode(newPassword));
|
||||
baseMapper.updateById(user);
|
||||
return Result.succeed("修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysUser> findUsers(Map<String, Object> params) {
|
||||
Page<SysUser> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<SysUser> list = baseMapper.findList(page, params);
|
||||
long total = page.getTotal();
|
||||
if (total > 0) {
|
||||
List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList());
|
||||
|
||||
List<SysRole> sysRoles = userRoleMapper.findRolesByUserIds(userIds);
|
||||
list.forEach(u -> {
|
||||
u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId()))
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
}
|
||||
return PageResult.<SysUser>builder().data(list).code(0).count(total).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findRolesByUserId(Long userId) {
|
||||
return userRoleMapper.findRolesByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateEnabled(Map<String, Object> params) {
|
||||
Long id = MapUtils.getLong(params, "id");
|
||||
Boolean enabled = MapUtils.getBoolean(params, "enabled");
|
||||
|
||||
SysUser appUser = baseMapper.selectById(id);
|
||||
if (appUser == null) {
|
||||
return Result.failed("用户不存在");
|
||||
}
|
||||
appUser.setEnabled(enabled);
|
||||
appUser.setUpdateTime(new Date());
|
||||
|
||||
int i = baseMapper.updateById(appUser);
|
||||
log.info("修改用户:{}", appUser);
|
||||
|
||||
return i > 0 ? Result.succeed(appUser, "更新成功") : Result.failed("更新失败");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Result saveOrUpdateUser(SysUser sysUser) {
|
||||
if (sysUser.getId() == null) {
|
||||
if (StringUtils.isBlank(sysUser.getType())) {
|
||||
sysUser.setType(UserType.BACKEND.name());
|
||||
}
|
||||
sysUser.setPassword(passwordEncoder.encode(CommonConstant.DEF_USER_PASSWORD));
|
||||
sysUser.setEnabled(Boolean.TRUE);
|
||||
}
|
||||
String username = sysUser.getUsername();
|
||||
boolean result = super.saveOrUpdateIdempotency(sysUser, lock
|
||||
, LOCK_KEY_USERNAME+username, new QueryWrapper<SysUser>().eq("username", username)
|
||||
, username+"已存在");
|
||||
//更新角色
|
||||
if (result && StrUtil.isNotEmpty(sysUser.getRoleId())) {
|
||||
userRoleMapper.deleteUserRole(sysUser.getId(), null);
|
||||
List roleIds = Arrays.asList(sysUser.getRoleId().split(","));
|
||||
if (!CollectionUtils.isEmpty(roleIds)) {
|
||||
roleIds.forEach(roleId -> {
|
||||
userRoleMapper.saveUserRoles(sysUser.getId(), Long.parseLong(roleId.toString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
return result ? Result.succeed(sysUser, "操作成功") : Result.failed("操作失败");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delUser(Long id) {
|
||||
userRoleMapper.deleteUserRole(id, null);
|
||||
return baseMapper.deleteById(id) > 0 ? true : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserExcel> findAllUsers(Map<String, Object> params) {
|
||||
List<SysUserExcel> sysUserExcels = new ArrayList<>();
|
||||
List<SysUser> list = baseMapper.findList(new Page<>(1, -1), params);
|
||||
|
||||
for (SysUser sysUser : list) {
|
||||
SysUserExcel sysUserExcel = new SysUserExcel();
|
||||
BeanUtils.copyProperties(sysUser, sysUserExcel);
|
||||
sysUserExcels.add(sysUserExcel);
|
||||
}
|
||||
return sysUserExcels;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveUsers(List<SysUser> users) {
|
||||
users.forEach(u -> baseMapper.insert(u));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/user-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
|
||||
redis:
|
||||
host: ${zlt.redis.host}
|
||||
port: ${zlt.redis.port}
|
||||
timeout: ${zlt.redis.timeout}
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.common.model
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
|
||||
zlt:
|
||||
swagger:
|
||||
enabled: true
|
||||
title: 用户中心
|
||||
description: 用户中心接口文档
|
||||
version: 1.0
|
||||
base-package: com.central.user.controller
|
||||
cache-manager:
|
||||
configs:
|
||||
- key: menu
|
||||
second: 600
|
||||
- key: user
|
||||
second: 1800
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 7000
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: user-center
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
file-extension: yml
|
||||
shared-dataids: common.yml
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysMenuMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysPermissionMapper">
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="permission != null and permission != ''">
|
||||
and t.permission like concat('%', #{permission}, '%')
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
and t.name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="searchKey != null and searchKey != ''">
|
||||
and t.name like concat('%', #{searchKey}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
<select id="count" resultType="int">
|
||||
select count(*) from sys_permission t
|
||||
<include refid="where" />
|
||||
</select>
|
||||
|
||||
<select id="findList" resultType="com.central.common.model.SysPermission">
|
||||
select * from sys_permission t
|
||||
<include refid="where" />
|
||||
order by t.id desc
|
||||
<!--<if test="start != null and start >= 0 and length != null and length > 0">-->
|
||||
<!--limit #{start}, #{length}-->
|
||||
<!--</if>-->
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysRoleMapper">
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="r.name != null and r.name != ''">
|
||||
and t.name like concat('%', #{r.name}, '%')
|
||||
</if>
|
||||
|
||||
<if test="r.searchKey != null and r.searchKey != '' and r.searchKey=='name'">
|
||||
and t.name like concat('%', #{r.searchValue}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.common.model.SysRole">
|
||||
select * from sys_role t
|
||||
<include refid="where" />
|
||||
order by t.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysRoleMenuMapper">
|
||||
|
||||
<update id="delete">
|
||||
delete from sys_role_menu
|
||||
<where>
|
||||
<if test="roleId != null">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
<if test="menuId != null">
|
||||
and menu_id = #{menuId}
|
||||
</if>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<select id="findMenusByRoleIds" resultType="com.central.common.model.SysMenu">
|
||||
select distinct t.* from sys_menu t
|
||||
inner join sys_role_menu r on r.menu_id = t.id
|
||||
where
|
||||
r.role_id in
|
||||
<foreach collection="roleIds" index="index" item="roleId"
|
||||
open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
<if test="type != null">
|
||||
and t.type = #{type}
|
||||
</if>
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
|
||||
<select id="findMenusByRoleCodes" resultType="com.central.common.model.SysMenu">
|
||||
select distinct t.* from sys_menu t
|
||||
inner join sys_role_menu r on r.menu_id = t.id
|
||||
inner join sys_role rl on rl.id = r.role_id
|
||||
where
|
||||
rl.code in
|
||||
<foreach collection="roleCodes" index="index" item="roleCode"
|
||||
open="(" separator="," close=")">
|
||||
#{roleCode}
|
||||
</foreach>
|
||||
<if test="type != null">
|
||||
and t.type = #{type}
|
||||
</if>
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysRolePermissionMapper">
|
||||
|
||||
<delete id="deleteRolePermission">
|
||||
delete from sys_role_permission
|
||||
<where>
|
||||
<if test="roleId != null">
|
||||
and roleId = #{roleId}
|
||||
</if>
|
||||
<if test="permissionId != null">
|
||||
and permissionId = #{permissionId}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<select id="findPermissionsByRoleIds" resultType="com.central.common.model.SysPermission">
|
||||
select p.* from
|
||||
sys_permission p
|
||||
inner join sys_role_permission rp on
|
||||
p.id = rp.permissionId
|
||||
<where>
|
||||
rp.roleId in
|
||||
<foreach collection="roleIds" item="roleId" open="("
|
||||
separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysUserMapper">
|
||||
<sql id="where">
|
||||
<where>
|
||||
t.is_del=0
|
||||
<if test="u.id != null and u.id != ''">
|
||||
and t.id like concat('%', #{u.id}, '%')
|
||||
</if>
|
||||
<if test="u.username != null and u.username != ''">
|
||||
and t.username like concat('%', #{u.username}, '%')
|
||||
</if>
|
||||
<if test="u.nickname != null and u.nickname != ''">
|
||||
and t.nickname like concat('%', #{u.nickname}, '%')
|
||||
</if>
|
||||
<if test="u.enabled != null and u.enabled != ''">
|
||||
and t.enabled = #{u.enabled}
|
||||
</if>
|
||||
<if test="u.type != null and u.type != ''">
|
||||
and t.type = #{u.type}
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='user_id'">
|
||||
and t.id like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='username'">
|
||||
and t.username like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='nick_name'">
|
||||
and t.nickname like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='mobile'">
|
||||
and t.mobile like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.common.model.SysUser">
|
||||
select * from sys_user t
|
||||
<include refid="where" />
|
||||
order by t.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysUserRoleMapper">
|
||||
<delete id="deleteUserRole">
|
||||
delete from sys_role_user
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="roleId != null">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1 @@
|
||||
*.iml
|
||||
@@ -0,0 +1,23 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-commons</artifactId>
|
||||
<description>通用组件</description>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>zlt-redis-spring-boot-starter</module>
|
||||
<module>zlt-common-spring-boot-starter</module>
|
||||
<module>zlt-db-spring-boot-starter</module>
|
||||
<module>zlt-swagger2-spring-boot-starter</module>
|
||||
<module>zlt-log-spring-boot-starter</module>
|
||||
<module>zlt-ribbon-spring-boot-starter</module>
|
||||
<module>zlt-auth-client-spring-boot-starter</module>
|
||||
<module>zlt-mq-spring-boot-starter</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-commons</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
|
||||
<description>认证客户端通用组件</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-oauth2</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.central.oauth2.common.config;
|
||||
|
||||
import com.central.oauth2.common.properties.SecurityProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
|
||||
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
|
||||
import org.springframework.security.oauth2.provider.token.TokenStore;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Import(DefaultSecurityHandlerConfig.class)
|
||||
public class DefaultResourceServerConf extends ResourceServerConfigurerAdapter {
|
||||
@Autowired
|
||||
private TokenStore tokenStore;
|
||||
|
||||
@Resource
|
||||
private AuthenticationEntryPoint authenticationEntryPoint;
|
||||
|
||||
@Resource
|
||||
private OAuth2WebSecurityExpressionHandler expressionHandler;
|
||||
|
||||
@Resource
|
||||
private OAuth2AccessDeniedHandler oAuth2AccessDeniedHandler;
|
||||
|
||||
@Autowired
|
||||
private SecurityProperties securityProperties;
|
||||
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) {
|
||||
resources.tokenStore(tokenStore)
|
||||
.stateless(true)
|
||||
.authenticationEntryPoint(authenticationEntryPoint)
|
||||
.expressionHandler(expressionHandler)
|
||||
.accessDeniedHandler(oAuth2AccessDeniedHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl = setHttp(http)
|
||||
.authorizeRequests()
|
||||
.antMatchers(securityProperties.getIgnore().getUrls()).permitAll()
|
||||
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
||||
.anyRequest();
|
||||
setAuthenticate(authorizedUrl);
|
||||
//允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
|
||||
http.headers()
|
||||
.frameOptions()
|
||||
.disable()
|
||||
.and()
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* url权限控制,默认是认证就通过,可以重写实现个性化
|
||||
* @param authorizedUrl
|
||||
*/
|
||||
public HttpSecurity setAuthenticate(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl) {
|
||||
return authorizedUrl.authenticated().and();
|
||||
}
|
||||
|
||||
/**
|
||||
* 留给子类重写扩展功能
|
||||
* @param http
|
||||
*/
|
||||
public HttpSecurity setHttp(HttpSecurity http) {
|
||||
return http;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.central.oauth2.common.config;
|
||||
|
||||
import com.central.common.utils.ResponseUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
|
||||
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public class DefaultSecurityHandlerConfig {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 未登录,返回401
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public AuthenticationEntryPoint authenticationEntryPoint() {
|
||||
return (request, response, authException) -> {
|
||||
ResponseUtil.responseWriter(objectMapper, response, authException.getMessage(), HttpStatus.UNAUTHORIZED.value());
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
|
||||
OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
|
||||
expressionHandler.setApplicationContext(applicationContext);
|
||||
return expressionHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理spring security oauth 处理失败返回消息格式
|
||||
*/
|
||||
@Bean
|
||||
public OAuth2AccessDeniedHandler oAuth2AccessDeniedHandler() {
|
||||
return new OAuth2AccessDeniedHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
|
||||
ResponseUtil.responseWriter(objectMapper, response, authException.getMessage(), HttpStatus.FORBIDDEN.value());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.central.oauth2.common.config;
|
||||
|
||||
import com.central.oauth2.common.store.*;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* token存储配置
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
public class TokenStoreConfig {
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "db")
|
||||
@Import(AuthDbTokenStore.class)
|
||||
public class JdbcTokenConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "redis", matchIfMissing = true)
|
||||
@Import(AuthRedisTokenStore.class)
|
||||
public class RedisTokenConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "authJwt")
|
||||
@Import(AuthJwtTokenStore.class)
|
||||
public class AuthJwtTokenConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "resJwt")
|
||||
@Import(ResJwtTokenStore.class)
|
||||
public class ResJwtTokenConfig {
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.central.oauth2.common.constants;
|
||||
|
||||
/**
|
||||
* 权限常量
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2018/7/24 16:05
|
||||
*/
|
||||
public enum AuthoritiesEnum {
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN("ROLE_ADMIN"),
|
||||
/**
|
||||
* 普通用户
|
||||
*/
|
||||
USER("ROLE_USER"),
|
||||
/**
|
||||
* 匿名用户
|
||||
*/
|
||||
ANONYMOUS("ROLE_ANONYMOUS");
|
||||
|
||||
private String role;
|
||||
|
||||
AuthoritiesEnum(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.oauth2.common.properties;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 认证配置
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class AuthProperties {
|
||||
/**
|
||||
* 要认证的url
|
||||
*/
|
||||
private String[] httpUrls = {};
|
||||
|
||||
/**
|
||||
* 是否开启url权限验证
|
||||
*/
|
||||
private boolean urlEnabled = false;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user