298 changed files with 56 additions and 20427 deletions
@ -1,6 +1,9 @@ |
|||
[submodule "esua-epdc/epdc-cloud-gateway-shibei"] |
|||
path = esua-epdc/epdc-cloud-gateway-shibei |
|||
url = http://121.42.41.42:7070/r/epdc-cloud-gateway-shibei.git |
|||
[submodule "esua-epdc/epdc-cloud-parent-shibei"] |
|||
path = esua-epdc/epdc-cloud-parent-shibei |
|||
url = http://121.42.41.42:7070/r/epdc-cloud-parent-shibei.git |
|||
[submodule "esua-epdc/epdc-cloud-gateway-shibei"] |
|||
path = esua-epdc/epdc-cloud-gateway-shibei |
|||
url = http://121.42.41.42:7070/r/epdc-cloud-gateway-shibei.git |
|||
[submodule "esua-epdc/epdc-cloud-commons-shibei"] |
|||
path = esua-epdc/epdc-cloud-commons-shibei |
|||
url = http://121.42.41.42:7070/r/epdc-cloud-commons-shibei.git |
|||
@ -0,0 +1 @@ |
|||
Subproject commit db7df9f067dcf46441b08174be82c3ce44e13932 |
|||
@ -1 +1 @@ |
|||
Subproject commit df286464819c7ec8d57c3744890289b905bd73a1 |
|||
Subproject commit d9805b690901f7e64cc8cd820fd96ea6e4aa8b87 |
|||
@ -1 +1 @@ |
|||
Subproject commit 5bbc8bdcdbad628c32c27c39d95c5a23f6cc213d |
|||
Subproject commit 71857553cfca23b808dadbe177d8391509a50cbd |
|||
@ -1,132 +0,0 @@ |
|||
<?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> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>epdc-common-clienttoken</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<name>epdc-common-clienttoken</name> |
|||
<url>http://www.example.com</url> |
|||
<description>客户端token</description> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons-tools</artifactId> |
|||
<version>${project.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-user-client</artifactId> |
|||
<version>${project.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-aop</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>com.vaadin.external.google</groupId> |
|||
<artifactId>android-json</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure-processor</artifactId> |
|||
<scope>compile</scope> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-log4j2</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>io.jsonwebtoken</groupId> |
|||
<artifactId>jjwt</artifactId> |
|||
<version>0.7.0</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
|
|||
<plugins> |
|||
<plugin> |
|||
<artifactId>maven-clean-plugin</artifactId> |
|||
</plugin> |
|||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> |
|||
<plugin> |
|||
<artifactId>maven-resources-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-compiler-plugin</artifactId> |
|||
<configuration> |
|||
<parameters>true</parameters> |
|||
<source>${maven.compiler.source}</source> <!-- 源代码使用的开发版本 --> |
|||
<target>${maven.compiler.target}</target> <!-- 需要生成的目标class文件的编译版本 --> |
|||
<encoding>${project.build.sourceEncoding}</encoding> |
|||
</configuration> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-war-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-install-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-deploy-plugin</artifactId> |
|||
</plugin> |
|||
|
|||
<!-- jar插件 --> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-jar-plugin</artifactId> |
|||
<version>2.4</version> |
|||
<configuration> |
|||
<archive> |
|||
<manifest> |
|||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> |
|||
</manifest> |
|||
</archive> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
|
|||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> |
|||
</build> |
|||
</project> |
|||
@ -1,31 +0,0 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 http://www.renren.io
|
|||
* <p> |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|||
* use this file except in compliance with the License. You may obtain a copy of |
|||
* the License at |
|||
* <p> |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* <p> |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
* License for the specific language governing permissions and limitations under |
|||
* the License. |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.common.token.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 登录效验 |
|||
* @author chenshun |
|||
* @email sunlightcs@gmail.com |
|||
* @date 2017/9/23 14:30 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface Login { |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 http://www.renren.io
|
|||
* <p> |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|||
* use this file except in compliance with the License. You may obtain a copy of |
|||
* the License at |
|||
* <p> |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* <p> |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
* License for the specific language governing permissions and limitations under |
|||
* the License. |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.common.token.annotation; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* 登录用户信息 |
|||
* |
|||
* @author chenshun |
|||
* @email sunlightcs@gmail.com |
|||
* @date 2017-03-23 20:39 |
|||
*/ |
|||
@Target(ElementType.PARAMETER) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface LoginUser { |
|||
|
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.annotation; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
@Retention(RetentionPolicy.CLASS)//生命注释保留时长,这里无需反射使用,使用CLASS级别
|
|||
@Target(ElementType.METHOD)//生命可以使用此注解的元素级别类型(如类、方法变量等)
|
|||
public @interface NeedClientToken { |
|||
|
|||
boolean value() default true; |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 数据端用户授权信息 |
|||
* @author: wangtong |
|||
* @create: 2020-05-26 15:39 |
|||
**/ |
|||
@Data |
|||
public class AnalysisUserAuthorizationDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 519392456658807347L; |
|||
|
|||
/** |
|||
* 令牌 |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 过期时长,单位秒 |
|||
*/ |
|||
private Integer expire; |
|||
|
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
private String deptName; |
|||
|
|||
/** |
|||
* 用户标签key |
|||
*/ |
|||
private String userTagKey; |
|||
|
|||
/** |
|||
* 注册状态 0-未注册,1-已注册 |
|||
*/ |
|||
private String registerState; |
|||
|
|||
/** |
|||
* 用户所有角色权限信息 |
|||
*/ |
|||
private List<DeptDataScopeDTO> deptDataScopeList; |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 数据端登录用户信息 |
|||
* @author: wangtong |
|||
* @create: 2020-05-26 15:32 |
|||
**/ |
|||
@Data |
|||
public class AnalysisUserLoginDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 3829451481560643039L; |
|||
|
|||
@NotBlank(message="用户名不能为空") |
|||
private String username; |
|||
|
|||
@NotBlank(message="密码不能为空") |
|||
private String password; |
|||
|
|||
@NotBlank(message="微信code不能为空") |
|||
private String wxCode; |
|||
|
|||
private String analysisOpenId; |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @program: esua-epdc |
|||
* @description: 数据端获取token |
|||
* @author: wangtong |
|||
* @create: 2020-05-26 20:25 |
|||
**/ |
|||
@Data |
|||
public class AnalysisUserTokenFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 5119156831661625353L; |
|||
|
|||
@NotNull(message = "用户ID不能为空") |
|||
private Long id; |
|||
|
|||
@NotBlank(message = "用户名不能为空") |
|||
private String username; |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* |
|||
* 用户所有角色权限信息 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/19 23:48 |
|||
*/ |
|||
@Data |
|||
public class DeptDataScopeDTO implements Serializable { |
|||
private static final long serialVersionUID = -6319876948812713836L; |
|||
|
|||
/** |
|||
* 部门ID |
|||
*/ |
|||
private Long deptId; |
|||
|
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
private String deptName; |
|||
|
|||
/** |
|||
* 部门类型 |
|||
*/ |
|||
private String typeKey; |
|||
} |
|||
@ -1,60 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import com.elink.esua.epdc.dto.UserTagInfo; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 用户token |
|||
* |
|||
* @author rongchao |
|||
* @Date 18-10-31 |
|||
*/ |
|||
@Data |
|||
public class TokenDto implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private String userId; |
|||
|
|||
/** |
|||
* 昵称 |
|||
*/ |
|||
private String nickname; |
|||
|
|||
/** |
|||
* 用户头像 |
|||
*/ |
|||
private String faceImg; |
|||
|
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
private String mobile; |
|||
|
|||
/** |
|||
* 真实姓名 |
|||
*/ |
|||
private String realName; |
|||
|
|||
/** |
|||
* 网格ID |
|||
*/ |
|||
private Long gridId; |
|||
|
|||
/** |
|||
* 性别(女性-0,男性-1) |
|||
*/ |
|||
private String sex; |
|||
|
|||
/** |
|||
* 用户标签信息列表 |
|||
*/ |
|||
private List<UserTagInfo> userTagInfos; |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* |
|||
* 工作端用户授权信息 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/19 20:17 |
|||
*/ |
|||
@Data |
|||
public class WorkUserAuthorizationDTO implements Serializable { |
|||
private static final long serialVersionUID = -4230190448906007120L; |
|||
|
|||
/** |
|||
* 令牌 |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 过期时长,单位秒 |
|||
*/ |
|||
private Integer expire; |
|||
|
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
private String deptName; |
|||
|
|||
/** |
|||
* 用户标签key |
|||
*/ |
|||
private String userTagKey; |
|||
|
|||
/** |
|||
* 注册状态 0-未注册,1-已注册 |
|||
*/ |
|||
private String registerState; |
|||
|
|||
/** |
|||
* 用户所有角色权限信息 |
|||
*/ |
|||
private List<DeptDataScopeDTO> deptDataScopeList; |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* |
|||
* 工作端用户登录信息 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/19 20:19 |
|||
*/ |
|||
@Data |
|||
public class WorkUserLoginDTO implements Serializable { |
|||
private static final long serialVersionUID = 1905641243346550379L; |
|||
|
|||
@NotBlank(message="用户名不能为空") |
|||
private String username; |
|||
|
|||
@NotBlank(message="密码不能为空") |
|||
private String password; |
|||
|
|||
@NotBlank(message="微信code不能为空") |
|||
private String wxCode; |
|||
|
|||
private String openId; |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* |
|||
* 工作端获取token Form DTO |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/19 20:35 |
|||
*/ |
|||
@Data |
|||
public class WorkUserTokenFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -2239027109939769097L; |
|||
|
|||
@NotNull(message = "用户ID不能为空") |
|||
private Long id; |
|||
|
|||
@NotBlank(message = "用户名不能为空") |
|||
private String username; |
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.enums; |
|||
|
|||
import com.elink.esua.epdc.common.token.error.IErrorCode; |
|||
|
|||
/** |
|||
* client token错误码 |
|||
* |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
public enum ErrorCode implements IErrorCode { |
|||
|
|||
SUCCESS(0, "请求成功"), |
|||
|
|||
ERR10001(10001, "clientToken不合法或者已过期"), |
|||
ERR10002(10002, "无法获取当前用户的信息,无法生成clientToken。"), |
|||
ERR10003(10003, "clientToken生成失败,请重试。"), |
|||
ERR10004(10004, "返回的Object类型不是EsuaResponse,无法添加token!"), |
|||
ERR10005(10005, "clentToken不能为空"), |
|||
|
|||
ERR500(500, "Internal Server Error"), |
|||
ERR501(501, "参数绑定异常"), |
|||
|
|||
ERR(ErrorCode.COMMON_ERR_CODE, "其他异常"); |
|||
|
|||
private int code; |
|||
|
|||
private String msg; |
|||
|
|||
ErrorCode(final int code, final String msg) { |
|||
this.code = code; |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public static final int COMMON_ERR_CODE = -1; |
|||
|
|||
@Override |
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
@Override |
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.error; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-20 |
|||
*/ |
|||
public interface IErrorCode { |
|||
int getCode(); |
|||
|
|||
String getMsg(); |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.property; |
|||
|
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-12-3 |
|||
*/ |
|||
@Component |
|||
@ConfigurationProperties(prefix = "token") |
|||
public class TokenPropertise { |
|||
|
|||
private long expire = 7200L; |
|||
|
|||
public long getExpire() { |
|||
return expire; |
|||
} |
|||
|
|||
public void setExpire(long expire) { |
|||
this.expire = expire; |
|||
} |
|||
} |
|||
@ -1,114 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.common.token.util; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import cn.hutool.core.map.MapUtil; |
|||
import com.elink.esua.epdc.common.token.dto.TokenDto; |
|||
import com.elink.esua.epdc.commons.tools.redis.RedisKeys; |
|||
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* CP用户Redis |
|||
* |
|||
* @author rongchao |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Component |
|||
public class CpUserDetailRedis { |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
public void set(TokenDto user, long expire) { |
|||
if (user == null) { |
|||
return; |
|||
} |
|||
String key = RedisKeys.getCpUserKey(user.getUserId()); |
|||
//bean to map
|
|||
Map<String, Object> map = BeanUtil.beanToMap(user, false, true); |
|||
redisUtils.hMSet(key, map, expire); |
|||
} |
|||
|
|||
/** |
|||
* 缓存用户信息,不同于{@link CpUserDetailRedis#set(TokenDto, long)}之处在于存放进redis时,拼接key的后缀可以自定义 |
|||
* |
|||
* @param user 用户信息 |
|||
* @param expire 超时时长 |
|||
* @param redisKeySuffix redis的key的后缀 |
|||
* @return void |
|||
* @author work@yujt.net.cn |
|||
* @date 2020/1/31 15:13 |
|||
*/ |
|||
public void set(TokenDto user, long expire, String redisKeySuffix) { |
|||
if (user == null) { |
|||
return; |
|||
} |
|||
String key = RedisKeys.getCpUserKey(redisKeySuffix); |
|||
//bean to map
|
|||
Map<String, Object> map = BeanUtil.beanToMap(user, false, true); |
|||
redisUtils.hMSet(key, map, expire); |
|||
} |
|||
|
|||
/** |
|||
* 获取token信息 |
|||
* |
|||
* @param userId |
|||
* @return |
|||
*/ |
|||
public TokenDto get(String userId) { |
|||
String key = RedisKeys.getCpUserKey(userId); |
|||
|
|||
Map<String, Object> map = redisUtils.hGetAll(key); |
|||
if (MapUtil.isEmpty(map)) { |
|||
return null; |
|||
} |
|||
|
|||
//map to bean
|
|||
TokenDto user = BeanUtil.mapToBean(map, TokenDto.class, true); |
|||
|
|||
return user; |
|||
} |
|||
|
|||
/** |
|||
* 删除用户信息 |
|||
* |
|||
* @param userId |
|||
*/ |
|||
public void logout(String userId) { |
|||
redisUtils.delete(RedisKeys.getCpUserKey(userId)); |
|||
} |
|||
|
|||
/** |
|||
* 设置redis时间 |
|||
* |
|||
* @param userId |
|||
* @param expire |
|||
* @author rongchao |
|||
*/ |
|||
public boolean expire(String userId, long expire) { |
|||
return redisUtils.expire(RedisKeys.getCpUserKey(userId), expire); |
|||
} |
|||
|
|||
/** |
|||
* 查询token剩余时间 |
|||
* |
|||
* @param userId |
|||
* @return long |
|||
* @author yujintao |
|||
* @date 2019/9/9 14:18 |
|||
*/ |
|||
public long getExpire(String userId) { |
|||
return redisUtils.getExpire(RedisKeys.getCpUserKey(userId)); |
|||
} |
|||
} |
|||
@ -1,51 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.util; |
|||
|
|||
import com.elink.esua.epdc.common.token.dto.TokenDto; |
|||
import com.elink.esua.epdc.common.token.property.TokenPropertise; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* token服务类 |
|||
* |
|||
* @author rongchao |
|||
* @Date 18-10-31 |
|||
*/ |
|||
@Component |
|||
public class TokenUtil { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
@Autowired |
|||
private TokenPropertise tokenPropertise; |
|||
|
|||
@Autowired |
|||
private CpUserDetailRedis redisUtils; |
|||
|
|||
public TokenDto getTokenInfo(String userId) { |
|||
TokenDto tokenDto = redisUtils.get(userId); |
|||
return tokenDto; |
|||
} |
|||
|
|||
public void expireToken(String userId) { |
|||
redisUtils.logout(userId); |
|||
} |
|||
|
|||
public boolean delayToken(String userId) { |
|||
return redisUtils.expire(userId, tokenPropertise.getExpire()); |
|||
} |
|||
|
|||
/** |
|||
* 获取token过期时间 |
|||
* |
|||
* @param userId |
|||
* @return long |
|||
* @author yujintao |
|||
* @date 2019/9/9 14:19 |
|||
*/ |
|||
public long getExpire(String userId) { |
|||
return redisUtils.getExpire(userId); |
|||
} |
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
package com.elink.esua.epdc.common.token.util; |
|||
|
|||
import com.elink.esua.epdc.common.token.dto.TokenDto; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.utils.WebUtil; |
|||
|
|||
/** |
|||
* 用户工具类 |
|||
* |
|||
* @author rongchao |
|||
* @Date 18-11-20 |
|||
*/ |
|||
public class UserUtil { |
|||
|
|||
/** |
|||
* 获取当前用户信息 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static TokenDto getCurrentUser() { |
|||
return (TokenDto) WebUtil.getAttributesFromRequest(Constant.APP_USER_KEY); |
|||
} |
|||
|
|||
/** |
|||
* 获取当前用户信息 |
|||
* |
|||
* @return com.elink.esua.common.token.dto.UserTokenDto |
|||
* @author yujintao |
|||
* @date 2018/12/5 9:24 |
|||
*/ |
|||
public static TokenDto getCurrentUserInfo() { |
|||
TokenDto tokenDto = getCurrentUser(); |
|||
if (tokenDto == null) { |
|||
return null; |
|||
} |
|||
return tokenDto; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前用户ID |
|||
* |
|||
* @return |
|||
*/ |
|||
public static String getCurrentUserId() { |
|||
TokenDto tokenDto = getCurrentUser(); |
|||
if (tokenDto == null) { |
|||
return null; |
|||
} |
|||
return tokenDto.getUserId(); |
|||
} |
|||
|
|||
public static void setCurrentUser(TokenDto user) { |
|||
WebUtil.setAttributesFromRequest(Constant.APP_USER_KEY, user); |
|||
} |
|||
} |
|||
@ -1,51 +0,0 @@ |
|||
<?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> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>epdc-commons-api-version-control</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-log4j2</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>com.vaadin.external.google</groupId> |
|||
<artifactId>android-json</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -1,42 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import org.springframework.core.annotation.AnnotationUtils; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.servlet.mvc.condition.RequestCondition; |
|||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|||
|
|||
import java.lang.reflect.Method; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
public class ApiRequestMappingHandlerMapping extends RequestMappingHandlerMapping { |
|||
@Override |
|||
protected RequestCondition<?> getCustomMethodCondition(Method method) { |
|||
return createCondition(method.getClass()); |
|||
} |
|||
|
|||
@Override |
|||
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) { |
|||
return createCondition(handlerType); |
|||
} |
|||
|
|||
private static RequestCondition<ApiVersionCondition> createCondition(Class<?> clazz) { |
|||
RequestMapping classRequestMapping = AnnotationUtils.findAnnotation(clazz, RequestMapping.class); |
|||
if (classRequestMapping == null) { |
|||
return null; |
|||
} |
|||
StringBuilder mappingUrlBuilder = new StringBuilder(); |
|||
if (classRequestMapping.value().length > 0) { |
|||
mappingUrlBuilder.append(classRequestMapping.value()[0]); |
|||
} |
|||
String mappingUrl = mappingUrlBuilder.toString(); |
|||
String mappingUrlVersion = "{version}"; |
|||
if (!mappingUrl.contains(mappingUrlVersion)) { |
|||
return null; |
|||
} |
|||
ApiVersion apiVersion = AnnotationUtils.findAnnotation(clazz, ApiVersion.class); |
|||
return apiVersion == null ? new ApiVersionCondition(1) : new ApiVersionCondition(apiVersion.value()); |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
@Target({ElementType.TYPE}) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface ApiVersion { |
|||
|
|||
/** |
|||
* 版本号 |
|||
* |
|||
* @return |
|||
*/ |
|||
int value(); |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import org.springframework.web.servlet.mvc.condition.RequestCondition; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
public class ApiVersionCondition implements RequestCondition<ApiVersionCondition> { |
|||
private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("/v(\\d+).*"); |
|||
|
|||
private int apiVersion; |
|||
|
|||
ApiVersionCondition(int apiVersion) { |
|||
this.apiVersion = apiVersion; |
|||
} |
|||
|
|||
public int getApiVersion() { |
|||
return apiVersion; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public ApiVersionCondition combine(ApiVersionCondition apiVersionCondition) { |
|||
return new ApiVersionCondition(apiVersionCondition.getApiVersion()); |
|||
} |
|||
|
|||
@Override |
|||
public ApiVersionCondition getMatchingCondition(HttpServletRequest httpServletRequest) { |
|||
Matcher m = VERSION_PREFIX_PATTERN.matcher(httpServletRequest.getRequestURI()); |
|||
if (m.find()) { |
|||
Integer version = Integer.valueOf(m.group(1)); |
|||
if (version >= this.apiVersion) { |
|||
return this; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public int compareTo(ApiVersionCondition apiVersionCondition, HttpServletRequest httpServletRequest) { |
|||
return apiVersionCondition.getApiVersion() - this.apiVersion; |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.api.version.config; |
|||
|
|||
import com.elink.esua.epdc.commons.api.version.ApiRequestMappingHandlerMapping; |
|||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
@Configuration |
|||
public class WebMvcRegistrationsConfig implements WebMvcRegistrations { |
|||
|
|||
@Override |
|||
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { |
|||
return new ApiRequestMappingHandlerMapping(); |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
<?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> |
|||
|
|||
<parent> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
|
|||
<artifactId>epdc-commons-dynamic-datasource</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons-mybatis</artifactId> |
|||
<version>1.0.0</version> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>io.seata</groupId> |
|||
<artifactId>seata-all</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 多数据源注解 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Target({ElementType.METHOD, ElementType.TYPE}) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
@Inherited |
|||
public @interface DataSource { |
|||
String value() default ""; |
|||
} |
|||
@ -1,71 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.aspect; |
|||
|
|||
import com.elink.esua.epdc.commons.dynamic.datasource.annotation.DataSource; |
|||
import com.elink.esua.epdc.commons.dynamic.datasource.config.DynamicDataSource; |
|||
import org.aspectj.lang.ProceedingJoinPoint; |
|||
import org.aspectj.lang.annotation.Around; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.core.Ordered; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.lang.reflect.Method; |
|||
|
|||
/** |
|||
* 多数据源,切面处理类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
@Order(Ordered.HIGHEST_PRECEDENCE) |
|||
public class DataSourceAspect { |
|||
protected Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
@Pointcut("@annotation(com.elink.esua.epdc.commons.dynamic.datasource.annotation.DataSource) " + |
|||
"|| @within(com.elink.esua.epdc.commons.dynamic.datasource.annotation.DataSource)") |
|||
public void dataSourcePointCut() { |
|||
|
|||
} |
|||
|
|||
@Around("dataSourcePointCut()") |
|||
public Object around(ProceedingJoinPoint point) throws Throwable { |
|||
MethodSignature signature = (MethodSignature) point.getSignature(); |
|||
Class targetClass = point.getTarget().getClass(); |
|||
Method method = signature.getMethod(); |
|||
|
|||
DataSource targetDataSource = (DataSource)targetClass.getAnnotation(DataSource.class); |
|||
DataSource methodDataSource = method.getAnnotation(DataSource.class); |
|||
if(targetDataSource != null || methodDataSource != null){ |
|||
String value; |
|||
if(methodDataSource != null){ |
|||
value = methodDataSource.value(); |
|||
}else { |
|||
value = targetDataSource.value(); |
|||
} |
|||
|
|||
DynamicDataSource.setDataSource(value); |
|||
logger.debug("set datasource is {}", value); |
|||
} |
|||
|
|||
try { |
|||
return point.proceed(); |
|||
} finally { |
|||
DynamicDataSource.clearDataSource(); |
|||
logger.debug("clean datasource"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.config; |
|||
|
|||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; |
|||
|
|||
/** |
|||
* 多数据源 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class DynamicDataSource extends AbstractRoutingDataSource { |
|||
private static ThreadLocal<String> contextHolder = new ThreadLocal<>(); |
|||
|
|||
@Override |
|||
protected Object determineCurrentLookupKey() { |
|||
return contextHolder.get(); |
|||
} |
|||
|
|||
public static void setDataSource(String dataSource) { |
|||
contextHolder.set(dataSource); |
|||
} |
|||
|
|||
public static void clearDataSource() { |
|||
contextHolder.remove(); |
|||
} |
|||
|
|||
} |
|||
@ -1,64 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.config; |
|||
|
|||
import com.alibaba.druid.pool.DruidDataSource; |
|||
import com.elink.esua.epdc.commons.dynamic.datasource.properties.DataSourceProperties; |
|||
import com.elink.esua.epdc.commons.dynamic.datasource.properties.DynamicDataSourceProperties; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 配置多数据源 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
@EnableConfigurationProperties(DynamicDataSourceProperties.class) |
|||
public class DynamicDataSourceConfig { |
|||
@Autowired |
|||
private DynamicDataSourceProperties properties; |
|||
|
|||
@Bean |
|||
@ConfigurationProperties(prefix = "spring.datasource.druid") |
|||
public DataSourceProperties dataSourceProperties() { |
|||
return new DataSourceProperties(); |
|||
} |
|||
|
|||
@Bean |
|||
public DynamicDataSource dynamicDataSource(DataSourceProperties dataSourceProperties) { |
|||
DynamicDataSource dynamicDataSource = new DynamicDataSource(); |
|||
dynamicDataSource.setTargetDataSources(getDynamicDataSource()); |
|||
|
|||
//默认数据源
|
|||
DruidDataSource defaultDataSource = DynamicDataSourceFactory.buildDruidDataSource(dataSourceProperties); |
|||
dynamicDataSource.setDefaultTargetDataSource(defaultDataSource); |
|||
|
|||
return dynamicDataSource; |
|||
} |
|||
|
|||
private Map<Object, Object> getDynamicDataSource(){ |
|||
Map<String, DataSourceProperties> dataSourcePropertiesMap = properties.getDatasource(); |
|||
Map<Object, Object> targetDataSources = new HashMap<>(dataSourcePropertiesMap.size()); |
|||
dataSourcePropertiesMap.forEach((k, v) -> { |
|||
DruidDataSource druidDataSource = DynamicDataSourceFactory.buildDruidDataSource(v); |
|||
targetDataSources.put(k, druidDataSource); |
|||
}); |
|||
|
|||
return targetDataSources; |
|||
} |
|||
|
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.config; |
|||
|
|||
import com.alibaba.druid.pool.DruidDataSource; |
|||
import com.elink.esua.epdc.commons.dynamic.datasource.properties.DataSourceProperties; |
|||
import com.elink.esua.epdc.commons.dynamic.datasource.properties.DataSourceProperties; |
|||
|
|||
import java.sql.SQLException; |
|||
|
|||
/** |
|||
* DruidDataSource |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class DynamicDataSourceFactory { |
|||
|
|||
public static DruidDataSource buildDruidDataSource(DataSourceProperties properties) { |
|||
DruidDataSource druidDataSource = new DruidDataSource(); |
|||
druidDataSource.setDriverClassName(properties.getDriverClassName()); |
|||
druidDataSource.setUrl(properties.getUrl()); |
|||
druidDataSource.setUsername(properties.getUsername()); |
|||
druidDataSource.setPassword(properties.getPassword()); |
|||
|
|||
druidDataSource.setInitialSize(properties.getInitialSize()); |
|||
druidDataSource.setMaxActive(properties.getMaxActive()); |
|||
druidDataSource.setMinIdle(properties.getMinIdle()); |
|||
druidDataSource.setMaxWait(properties.getMaxWait()); |
|||
druidDataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis()); |
|||
druidDataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis()); |
|||
druidDataSource.setMaxEvictableIdleTimeMillis(properties.getMaxEvictableIdleTimeMillis()); |
|||
druidDataSource.setValidationQuery(properties.getValidationQuery()); |
|||
druidDataSource.setValidationQueryTimeout(properties.getValidationQueryTimeout()); |
|||
druidDataSource.setTestOnBorrow(properties.isTestOnBorrow()); |
|||
druidDataSource.setTestOnReturn(properties.isTestOnReturn()); |
|||
druidDataSource.setPoolPreparedStatements(properties.isPoolPreparedStatements()); |
|||
druidDataSource.setMaxOpenPreparedStatements(properties.getMaxOpenPreparedStatements()); |
|||
druidDataSource.setSharePreparedStatements(properties.isSharePreparedStatements()); |
|||
|
|||
try { |
|||
druidDataSource.setFilters(properties.getFilters()); |
|||
druidDataSource.init(); |
|||
} catch (SQLException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return druidDataSource; |
|||
} |
|||
} |
|||
@ -1,202 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.properties; |
|||
|
|||
/** |
|||
* 多数据源属性 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class DataSourceProperties { |
|||
private String driverClassName; |
|||
private String url; |
|||
private String username; |
|||
private String password; |
|||
|
|||
/** |
|||
* Druid默认参数 |
|||
*/ |
|||
private int initialSize = 2; |
|||
private int maxActive = 10; |
|||
private int minIdle = -1; |
|||
private long maxWait = 60 * 1000L; |
|||
private long timeBetweenEvictionRunsMillis = 60 * 1000L; |
|||
private long minEvictableIdleTimeMillis = 1000L * 60L * 30L; |
|||
private long maxEvictableIdleTimeMillis = 1000L * 60L * 60L * 7; |
|||
private String validationQuery = "select 1"; |
|||
private int validationQueryTimeout = -1; |
|||
private boolean testOnBorrow = false; |
|||
private boolean testOnReturn = false; |
|||
private boolean testWhileIdle = true; |
|||
private boolean poolPreparedStatements = false; |
|||
private int maxOpenPreparedStatements = -1; |
|||
private boolean sharePreparedStatements = false; |
|||
private String filters = "stat,wall"; |
|||
|
|||
public String getDriverClassName() { |
|||
return driverClassName; |
|||
} |
|||
|
|||
public void setDriverClassName(String driverClassName) { |
|||
this.driverClassName = driverClassName; |
|||
} |
|||
|
|||
public String getUrl() { |
|||
return url; |
|||
} |
|||
|
|||
public void setUrl(String url) { |
|||
this.url = url; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return username; |
|||
} |
|||
|
|||
public void setUsername(String username) { |
|||
this.username = username; |
|||
} |
|||
|
|||
public String getPassword() { |
|||
return password; |
|||
} |
|||
|
|||
public void setPassword(String password) { |
|||
this.password = password; |
|||
} |
|||
|
|||
public int getInitialSize() { |
|||
return initialSize; |
|||
} |
|||
|
|||
public void setInitialSize(int initialSize) { |
|||
this.initialSize = initialSize; |
|||
} |
|||
|
|||
public int getMaxActive() { |
|||
return maxActive; |
|||
} |
|||
|
|||
public void setMaxActive(int maxActive) { |
|||
this.maxActive = maxActive; |
|||
} |
|||
|
|||
public int getMinIdle() { |
|||
return minIdle; |
|||
} |
|||
|
|||
public void setMinIdle(int minIdle) { |
|||
this.minIdle = minIdle; |
|||
} |
|||
|
|||
public long getMaxWait() { |
|||
return maxWait; |
|||
} |
|||
|
|||
public void setMaxWait(long maxWait) { |
|||
this.maxWait = maxWait; |
|||
} |
|||
|
|||
public long getTimeBetweenEvictionRunsMillis() { |
|||
return timeBetweenEvictionRunsMillis; |
|||
} |
|||
|
|||
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) { |
|||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; |
|||
} |
|||
|
|||
public long getMinEvictableIdleTimeMillis() { |
|||
return minEvictableIdleTimeMillis; |
|||
} |
|||
|
|||
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) { |
|||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; |
|||
} |
|||
|
|||
public long getMaxEvictableIdleTimeMillis() { |
|||
return maxEvictableIdleTimeMillis; |
|||
} |
|||
|
|||
public void setMaxEvictableIdleTimeMillis(long maxEvictableIdleTimeMillis) { |
|||
this.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis; |
|||
} |
|||
|
|||
public String getValidationQuery() { |
|||
return validationQuery; |
|||
} |
|||
|
|||
public void setValidationQuery(String validationQuery) { |
|||
this.validationQuery = validationQuery; |
|||
} |
|||
|
|||
public int getValidationQueryTimeout() { |
|||
return validationQueryTimeout; |
|||
} |
|||
|
|||
public void setValidationQueryTimeout(int validationQueryTimeout) { |
|||
this.validationQueryTimeout = validationQueryTimeout; |
|||
} |
|||
|
|||
public boolean isTestOnBorrow() { |
|||
return testOnBorrow; |
|||
} |
|||
|
|||
public void setTestOnBorrow(boolean testOnBorrow) { |
|||
this.testOnBorrow = testOnBorrow; |
|||
} |
|||
|
|||
public boolean isTestOnReturn() { |
|||
return testOnReturn; |
|||
} |
|||
|
|||
public void setTestOnReturn(boolean testOnReturn) { |
|||
this.testOnReturn = testOnReturn; |
|||
} |
|||
|
|||
public boolean isTestWhileIdle() { |
|||
return testWhileIdle; |
|||
} |
|||
|
|||
public void setTestWhileIdle(boolean testWhileIdle) { |
|||
this.testWhileIdle = testWhileIdle; |
|||
} |
|||
|
|||
public boolean isPoolPreparedStatements() { |
|||
return poolPreparedStatements; |
|||
} |
|||
|
|||
public void setPoolPreparedStatements(boolean poolPreparedStatements) { |
|||
this.poolPreparedStatements = poolPreparedStatements; |
|||
} |
|||
|
|||
public int getMaxOpenPreparedStatements() { |
|||
return maxOpenPreparedStatements; |
|||
} |
|||
|
|||
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) { |
|||
this.maxOpenPreparedStatements = maxOpenPreparedStatements; |
|||
} |
|||
|
|||
public boolean isSharePreparedStatements() { |
|||
return sharePreparedStatements; |
|||
} |
|||
|
|||
public void setSharePreparedStatements(boolean sharePreparedStatements) { |
|||
this.sharePreparedStatements = sharePreparedStatements; |
|||
} |
|||
|
|||
public String getFilters() { |
|||
return filters; |
|||
} |
|||
|
|||
public void setFilters(String filters) { |
|||
this.filters = filters; |
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.dynamic.datasource.properties; |
|||
|
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
|
|||
import java.util.LinkedHashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 多数据源属性 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@ConfigurationProperties(prefix = "dynamic") |
|||
public class DynamicDataSourceProperties { |
|||
private Map<String, DataSourceProperties> datasource = new LinkedHashMap<>(); |
|||
|
|||
public Map<String, DataSourceProperties> getDatasource() { |
|||
return datasource; |
|||
} |
|||
|
|||
public void setDatasource(Map<String, DataSourceProperties> datasource) { |
|||
this.datasource = datasource; |
|||
} |
|||
} |
|||
@ -1,85 +0,0 @@ |
|||
<?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> |
|||
|
|||
<parent> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
|
|||
<artifactId>epdc-commons-mybatis</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<properties> |
|||
<mybatisplus.version>3.1.2</mybatisplus.version> |
|||
<mysql.version>8.0.17</mysql.version> |
|||
<druid.version>1.1.18</druid.version> |
|||
<sqlserver.version>4.0</sqlserver.version> |
|||
<oracle.version>11.2.0.3</oracle.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons-tools</artifactId> |
|||
<version>1.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>mybatis-plus-boot-starter</artifactId> |
|||
<version>${mybatisplus.version}</version> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>mybatis-plus-generator</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>druid-spring-boot-starter</artifactId> |
|||
<version>${druid.version}</version> |
|||
</dependency> |
|||
<!--mysql驱动--> |
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
<version>${mysql.version}</version> |
|||
</dependency> |
|||
<!--oracle驱动--> |
|||
<dependency> |
|||
<groupId>com.oracle</groupId> |
|||
<artifactId>ojdbc6</artifactId> |
|||
<version>${oracle.version}</version> |
|||
</dependency> |
|||
<!--sqlserver驱动--> |
|||
<dependency> |
|||
<groupId>com.microsoft.sqlserver</groupId> |
|||
<artifactId>sqljdbc4</artifactId> |
|||
<version>${sqlserver.version}</version> |
|||
</dependency> |
|||
<!--postgresql驱动--> |
|||
<dependency> |
|||
<groupId>org.postgresql</groupId> |
|||
<artifactId>postgresql</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- seata 数据库分布式事务 start --> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-alibaba-seata</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.seata</groupId> |
|||
<artifactId>seata-all</artifactId> |
|||
</dependency> |
|||
<!-- seata 数据库分布式事务 end --> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -1,48 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 数据过滤注解 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface DataFilter { |
|||
/** |
|||
* 表的别名 |
|||
*/ |
|||
String tableAlias() default ""; |
|||
|
|||
/** |
|||
* 查询条件前缀,可选值有:[where、and] |
|||
*/ |
|||
String prefix() default ""; |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
String userId() default "creator"; |
|||
|
|||
/** |
|||
* 部门ID |
|||
*/ |
|||
String deptId() default "dept_id"; |
|||
|
|||
/** |
|||
* 是否拼接用户ID |
|||
*/ |
|||
boolean isPendingCreator() default true; |
|||
|
|||
} |
|||
@ -1,107 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.aspect; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
import com.elink.esua.epdc.commons.mybatis.annotation.DataFilter; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.DataScope; |
|||
import com.elink.esua.epdc.commons.mybatis.annotation.DataFilter; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.DataScope; |
|||
import com.elink.esua.epdc.commons.tools.enums.SuperAdminEnum; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.exception.ErrorCode; |
|||
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|||
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|||
import com.elink.esua.epdc.commons.tools.security.user.UserDetail; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 数据过滤,切面处理类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
public class DataFilterAspect { |
|||
@Pointcut("@annotation(com.elink.esua.epdc.commons.mybatis.annotation.DataFilter)") |
|||
public void dataFilterCut() { |
|||
|
|||
} |
|||
|
|||
@Before("dataFilterCut()") |
|||
public void dataFilter(JoinPoint point) { |
|||
Object params = point.getArgs()[0]; |
|||
if(params != null && params instanceof Map){ |
|||
UserDetail user = SecurityUser.getUser(); |
|||
|
|||
//如果不是超级管理员,则进行数据过滤
|
|||
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()){ |
|||
Map map = (Map)params; |
|||
String sqlFilter = getSqlFilter(user, point); |
|||
map.put(Constant.SQL_FILTER, new DataScope(sqlFilter)); |
|||
} |
|||
|
|||
return ; |
|||
} |
|||
|
|||
throw new RenException(ErrorCode.DATA_SCOPE_PARAMS_ERROR); |
|||
} |
|||
|
|||
/** |
|||
* 获取数据过滤的SQL |
|||
*/ |
|||
private String getSqlFilter(UserDetail user, JoinPoint point){ |
|||
MethodSignature signature = (MethodSignature) point.getSignature(); |
|||
DataFilter dataFilter = signature.getMethod().getAnnotation(DataFilter.class); |
|||
//获取表的别名
|
|||
String tableAlias = dataFilter.tableAlias(); |
|||
if(StringUtils.isNotBlank(tableAlias)){ |
|||
tableAlias += "."; |
|||
} |
|||
|
|||
StringBuilder sqlFilter = new StringBuilder(); |
|||
|
|||
//查询条件前缀
|
|||
String prefix = dataFilter.prefix(); |
|||
if(StringUtils.isNotBlank(prefix)){ |
|||
sqlFilter.append(" ").append(prefix); |
|||
} |
|||
|
|||
sqlFilter.append(" ("); |
|||
|
|||
//部门ID列表
|
|||
List<Long> deptIdList = user.getDeptIdList(); |
|||
if(CollUtil.isNotEmpty(deptIdList)){ |
|||
sqlFilter.append(tableAlias).append(dataFilter.deptId()); |
|||
|
|||
sqlFilter.append(" in(").append(StringUtils.join(deptIdList, ",")).append(")"); |
|||
} |
|||
|
|||
//查询本人数据
|
|||
if (dataFilter.isPendingCreator()) { |
|||
if(CollUtil.isNotEmpty(deptIdList)){ |
|||
sqlFilter.append(" or "); |
|||
} |
|||
sqlFilter.append(tableAlias).append(dataFilter.userId()).append("=").append(user.getId()); |
|||
} |
|||
sqlFilter.append(")"); |
|||
|
|||
return sqlFilter.toString(); |
|||
} |
|||
} |
|||
@ -1,166 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.mybatis.config; |
|||
|
|||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; |
|||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; |
|||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer; |
|||
import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS; |
|||
import com.baomidou.mybatisplus.core.MybatisConfiguration; |
|||
import com.baomidou.mybatisplus.core.config.GlobalConfig; |
|||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
|||
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; |
|||
import com.baomidou.mybatisplus.core.injector.ISqlInjector; |
|||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; |
|||
import io.seata.rm.datasource.DataSourceProxy; |
|||
import org.apache.ibatis.mapping.DatabaseIdProvider; |
|||
import org.apache.ibatis.plugin.Interceptor; |
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.InitializingBean; |
|||
import org.springframework.beans.factory.ObjectProvider; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.ApplicationContext; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.io.Resource; |
|||
import org.springframework.core.io.ResourceLoader; |
|||
import org.springframework.util.Assert; |
|||
import org.springframework.util.CollectionUtils; |
|||
import org.springframework.util.ObjectUtils; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import javax.sql.DataSource; |
|||
import java.util.Iterator; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* seata分布式事务数据源 |
|||
* |
|||
* @author rongchao |
|||
* @Date 19-8-21 |
|||
*/ |
|||
@Configuration |
|||
@EnableConfigurationProperties({MybatisPlusProperties.class}) |
|||
public class DataSourceConfig implements InitializingBean { |
|||
|
|||
private final Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
private final MybatisPlusProperties properties; |
|||
private final Interceptor[] interceptors; |
|||
private final ResourceLoader resourceLoader; |
|||
private final DatabaseIdProvider databaseIdProvider; |
|||
private final List<ConfigurationCustomizer> configurationCustomizers; |
|||
private final List<MybatisPlusPropertiesCustomizer> mybatisPlusPropertiesCustomizers; |
|||
private final ApplicationContext applicationContext; |
|||
|
|||
public DataSourceConfig(MybatisPlusProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider, ResourceLoader resourceLoader, ObjectProvider<DatabaseIdProvider> databaseIdProvider, ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider, ObjectProvider<List<MybatisPlusPropertiesCustomizer>> mybatisPlusPropertiesCustomizerProvider, ApplicationContext applicationContext) { |
|||
this.properties = properties; |
|||
this.interceptors = (Interceptor[]) interceptorsProvider.getIfAvailable(); |
|||
this.resourceLoader = resourceLoader; |
|||
this.databaseIdProvider = (DatabaseIdProvider) databaseIdProvider.getIfAvailable(); |
|||
this.configurationCustomizers = (List) configurationCustomizersProvider.getIfAvailable(); |
|||
this.mybatisPlusPropertiesCustomizers = (List) mybatisPlusPropertiesCustomizerProvider.getIfAvailable(); |
|||
this.applicationContext = applicationContext; |
|||
} |
|||
|
|||
@Override |
|||
public void afterPropertiesSet() { |
|||
if (!CollectionUtils.isEmpty(this.mybatisPlusPropertiesCustomizers)) { |
|||
this.mybatisPlusPropertiesCustomizers.forEach((i) -> { |
|||
i.customize(this.properties); |
|||
}); |
|||
} |
|||
|
|||
this.checkConfigFileExists(); |
|||
} |
|||
|
|||
private void checkConfigFileExists() { |
|||
if (this.properties.isCheckConfigLocation() && StringUtils.hasText(this.properties.getConfigLocation())) { |
|||
Resource resource = this.resourceLoader.getResource(this.properties.getConfigLocation()); |
|||
Assert.state(resource.exists(), "Cannot find config location: " + resource + " (please add config file or check your Mybatis configuration)"); |
|||
} |
|||
|
|||
} |
|||
|
|||
@Bean |
|||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { |
|||
DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource); |
|||
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean(); |
|||
factory.setDataSource(dataSourceProxy); |
|||
factory.setVfs(SpringBootVFS.class); |
|||
if (StringUtils.hasText(this.properties.getConfigLocation())) { |
|||
factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); |
|||
} |
|||
|
|||
this.applyConfiguration(factory); |
|||
if (this.properties.getConfigurationProperties() != null) { |
|||
factory.setConfigurationProperties(this.properties.getConfigurationProperties()); |
|||
} |
|||
|
|||
if (!ObjectUtils.isEmpty(this.interceptors)) { |
|||
factory.setPlugins(this.interceptors); |
|||
} |
|||
|
|||
if (this.databaseIdProvider != null) { |
|||
factory.setDatabaseIdProvider(this.databaseIdProvider); |
|||
} |
|||
|
|||
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) { |
|||
factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); |
|||
} |
|||
|
|||
if (this.properties.getTypeAliasesSuperType() != null) { |
|||
factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType()); |
|||
} |
|||
|
|||
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) { |
|||
factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); |
|||
} |
|||
|
|||
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { |
|||
factory.setMapperLocations(this.properties.resolveMapperLocations()); |
|||
} |
|||
|
|||
if (StringUtils.hasLength(this.properties.getTypeEnumsPackage())) { |
|||
factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage()); |
|||
} |
|||
|
|||
GlobalConfig globalConfig = this.properties.getGlobalConfig(); |
|||
if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, false, false).length > 0) { |
|||
MetaObjectHandler metaObjectHandler = (MetaObjectHandler) this.applicationContext.getBean(MetaObjectHandler.class); |
|||
globalConfig.setMetaObjectHandler(metaObjectHandler); |
|||
} |
|||
|
|||
if (this.applicationContext.getBeanNamesForType(IKeyGenerator.class, false, false).length > 0) { |
|||
IKeyGenerator keyGenerator = (IKeyGenerator) this.applicationContext.getBean(IKeyGenerator.class); |
|||
globalConfig.getDbConfig().setKeyGenerator(keyGenerator); |
|||
} |
|||
|
|||
if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false, false).length > 0) { |
|||
ISqlInjector iSqlInjector = (ISqlInjector) this.applicationContext.getBean(ISqlInjector.class); |
|||
globalConfig.setSqlInjector(iSqlInjector); |
|||
} |
|||
|
|||
factory.setGlobalConfig(globalConfig); |
|||
return factory.getObject(); |
|||
} |
|||
|
|||
private void applyConfiguration(MybatisSqlSessionFactoryBean factory) { |
|||
MybatisConfiguration configuration = this.properties.getConfiguration(); |
|||
if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) { |
|||
configuration = new MybatisConfiguration(); |
|||
} |
|||
|
|||
if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) { |
|||
Iterator var3 = this.configurationCustomizers.iterator(); |
|||
|
|||
while (var3.hasNext()) { |
|||
ConfigurationCustomizer customizer = (ConfigurationCustomizer) var3.next(); |
|||
customizer.customize(configuration); |
|||
} |
|||
} |
|||
|
|||
factory.setConfiguration(configuration); |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.config; |
|||
|
|||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; |
|||
import com.elink.esua.epdc.commons.mybatis.interceptor.DataFilterInterceptor; |
|||
import com.elink.esua.epdc.commons.mybatis.interceptor.DataFilterInterceptor; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.annotation.Order; |
|||
|
|||
/** |
|||
* mybatis-plus配置 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
public class MybatisPlusConfig { |
|||
|
|||
/** |
|||
* 配置数据权限 |
|||
*/ |
|||
@Bean |
|||
@Order(1) |
|||
public DataFilterInterceptor dataFilterInterceptor() { |
|||
return new DataFilterInterceptor(); |
|||
} |
|||
|
|||
/** |
|||
* 配置分页 |
|||
*/ |
|||
@Bean |
|||
@Order(0) |
|||
public PaginationInterceptor paginationInterceptor() { |
|||
return new PaginationInterceptor(); |
|||
} |
|||
|
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.dao; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* 基础Dao |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface BaseDao<T> extends BaseMapper<T> { |
|||
|
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 基础实体类,所有实体都需要继承 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Data |
|||
public abstract class BaseEntity implements Serializable { |
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(type = IdType.ID_WORKER) |
|||
private Long id; |
|||
/** |
|||
* 创建者 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Long creator; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createDate; |
|||
|
|||
} |
|||
@ -1,71 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 基础实体类,所有实体都需要继承 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Data |
|||
public abstract class BaseEpdcEntity implements Serializable { |
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(type = IdType.UUID) |
|||
private String id; |
|||
|
|||
/** |
|||
* 乐观锁 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Integer revision; |
|||
|
|||
/** |
|||
* 创建者 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createdBy; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|||
private Date createdTime; |
|||
|
|||
/** |
|||
* 修改者 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private String updatedBy; |
|||
|
|||
/** |
|||
* 修改时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|||
private Date updatedTime; |
|||
|
|||
/** |
|||
* 是否已删除(0-未删除,1-已删除) |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
@TableLogic |
|||
private String delFlag; |
|||
|
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.entity; |
|||
|
|||
/** |
|||
* 数据范围 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class DataScope { |
|||
private String sqlFilter; |
|||
|
|||
public DataScope(String sqlFilter) { |
|||
this.sqlFilter = sqlFilter; |
|||
} |
|||
|
|||
public String getSqlFilter() { |
|||
return sqlFilter; |
|||
} |
|||
|
|||
public void setSqlFilter(String sqlFilter) { |
|||
this.sqlFilter = sqlFilter; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return this.sqlFilter; |
|||
} |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.mybatis.entity; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 部门冗余字段基类 |
|||
* |
|||
* @author rongchao |
|||
* @Date 19-12-18 |
|||
*/ |
|||
@Data |
|||
public abstract class DeptScope extends BaseEpdcEntity implements Serializable { |
|||
|
|||
/*** |
|||
*所有部门名称 |
|||
*/ |
|||
private String allDeptNames; |
|||
|
|||
/*** |
|||
*所有部门ID |
|||
*/ |
|||
private String allDeptIds; |
|||
|
|||
/*** |
|||
*父所有部门 |
|||
*/ |
|||
private String parentDeptNames; |
|||
|
|||
/*** |
|||
*父所有部门 |
|||
*/ |
|||
private String parentDeptIds; |
|||
|
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.enums; |
|||
|
|||
/** |
|||
* 删除标识枚举类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public enum DelFlagEnum { |
|||
NORMAL(0), |
|||
DEL(1); |
|||
|
|||
private int value; |
|||
|
|||
DelFlagEnum(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int value() { |
|||
return this.value; |
|||
} |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.enums; |
|||
|
|||
/** |
|||
* 删除标识枚举 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/8/19 10:37 |
|||
*/ |
|||
public enum EpdcDelFlagEnum { |
|||
/** |
|||
* 未删 |
|||
*/ |
|||
NORMAL("0"), |
|||
/** |
|||
* 已删 |
|||
*/ |
|||
DEL("1"); |
|||
|
|||
private String value; |
|||
|
|||
EpdcDelFlagEnum(String value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public String value() { |
|||
return this.value; |
|||
} |
|||
} |
|||
@ -1,110 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.handler; |
|||
|
|||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
|||
import com.baomidou.mybatisplus.core.toolkit.Constants; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.BaseEntity; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; |
|||
import com.elink.esua.epdc.commons.mybatis.enums.DelFlagEnum; |
|||
import com.elink.esua.epdc.commons.mybatis.enums.EpdcDelFlagEnum; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|||
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|||
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|||
import com.elink.esua.epdc.commons.tools.security.user.UserDetail; |
|||
import org.apache.ibatis.reflection.MetaObject; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 公共字段,自动填充值 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Component |
|||
public class FieldMetaObjectHandler implements MetaObjectHandler { |
|||
private final static String CREATE_DATE = "createDate"; |
|||
private final static String CREATOR = "creator"; |
|||
private final static String UPDATE_DATE = "updateDate"; |
|||
private final static String UPDATER = "updater"; |
|||
private final static String DEPT_ID = "deptId"; |
|||
|
|||
@Override |
|||
public void insertFill(MetaObject metaObject) { |
|||
UserDetail user = SecurityUser.getUser(); |
|||
Date date = new Date(); |
|||
if (metaObject.getOriginalObject() instanceof BaseEpdcEntity) { |
|||
String userId = user == null ? Constant.APP_USER_FLAG : String.valueOf(user.getId()); |
|||
Long deptId = user == null ? null : user.getDeptId(); |
|||
setFieldValByName(FieldConstant.CREATED_TIME_HUMP, date, metaObject); |
|||
setFieldValByName(FieldConstant.CREATED_BY_HUMP, userId, metaObject); |
|||
setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, date, metaObject); |
|||
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, userId, metaObject); |
|||
setFieldValByName(FieldConstant.REVISION_HUMP, NumConstant.ZERO, metaObject); |
|||
//删除标识
|
|||
setFieldValByName(FieldConstant.DEL_FLAG_HUMP, EpdcDelFlagEnum.NORMAL.value(), metaObject); |
|||
// 数据权限标志
|
|||
setInsertFieldValByName(DEPT_ID, deptId, metaObject); |
|||
} else { |
|||
if (user == null) { |
|||
return; |
|||
} |
|||
//创建者
|
|||
setFieldValByName(CREATOR, user.getId(), metaObject); |
|||
//创建时间
|
|||
setFieldValByName(CREATE_DATE, date, metaObject); |
|||
//创建者所属部门
|
|||
setInsertFieldValByName(DEPT_ID, user.getDeptId(), metaObject); |
|||
//更新者
|
|||
setFieldValByName(UPDATER, user.getId(), metaObject); |
|||
//更新时间
|
|||
setFieldValByName(UPDATE_DATE, date, metaObject); |
|||
//删除标识
|
|||
setFieldValByName(FieldConstant.DEL_FLAG_HUMP, DelFlagEnum.NORMAL.value(), metaObject); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void updateFill(MetaObject metaObject) { |
|||
|
|||
Object originalObject = metaObject.getOriginalObject(); |
|||
Long id = SecurityUser.getUserId(); |
|||
|
|||
boolean fillEntity = false; |
|||
boolean fillEsuaEntity = false; |
|||
if (originalObject instanceof BaseEntity) { |
|||
fillEntity = true; |
|||
} else if (originalObject instanceof BaseEpdcEntity) { |
|||
fillEsuaEntity = true; |
|||
} else { |
|||
if (metaObject.hasGetter(Constants.ENTITY)) { |
|||
Object et = metaObject.getValue(Constants.ENTITY); |
|||
if (et instanceof BaseEpdcEntity) { |
|||
fillEsuaEntity = true; |
|||
} else if (et instanceof BaseEntity) { |
|||
fillEntity = true; |
|||
} |
|||
} |
|||
} |
|||
if (fillEntity) { |
|||
id = null == id ? NumConstant.ZERO_L : id; |
|||
//更新者
|
|||
setFieldValByName(UPDATER, id, metaObject); |
|||
//更新时间
|
|||
setFieldValByName(UPDATE_DATE, new Date(), metaObject); |
|||
} else if (fillEsuaEntity) { |
|||
String userId = null == id ? Constant.APP_USER_FLAG : String.valueOf(id); |
|||
setFieldValByName(FieldConstant.UPDATED_BY_HUMP, userId, metaObject); |
|||
setFieldValByName(FieldConstant.UPDATED_TIME_HUMP, new Date(), metaObject); |
|||
} |
|||
} |
|||
} |
|||
@ -1,102 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.interceptor; |
|||
|
|||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils; |
|||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|||
import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.DataScope; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.DataScope; |
|||
import org.apache.ibatis.executor.statement.StatementHandler; |
|||
import org.apache.ibatis.mapping.BoundSql; |
|||
import org.apache.ibatis.mapping.MappedStatement; |
|||
import org.apache.ibatis.mapping.SqlCommandType; |
|||
import org.apache.ibatis.plugin.*; |
|||
import org.apache.ibatis.reflection.MetaObject; |
|||
import org.apache.ibatis.reflection.SystemMetaObject; |
|||
|
|||
import java.sql.Connection; |
|||
import java.util.Map; |
|||
import java.util.Properties; |
|||
|
|||
/** |
|||
* 数据过滤 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})}) |
|||
public class DataFilterInterceptor extends AbstractSqlParserHandler implements Interceptor { |
|||
|
|||
@Override |
|||
public Object intercept(Invocation invocation) throws Throwable { |
|||
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget()); |
|||
MetaObject metaObject = SystemMetaObject.forObject(statementHandler); |
|||
|
|||
// SQL解析
|
|||
this.sqlParser(metaObject); |
|||
|
|||
// 先判断是不是SELECT操作
|
|||
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); |
|||
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { |
|||
return invocation.proceed(); |
|||
} |
|||
|
|||
// 针对定义了rowBounds,做为mapper接口方法的参数
|
|||
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); |
|||
String originalSql = boundSql.getSql(); |
|||
Object paramObj = boundSql.getParameterObject(); |
|||
|
|||
// 判断参数里是否有DataScope对象
|
|||
DataScope scope = null; |
|||
if (paramObj instanceof DataScope) { |
|||
scope = (DataScope) paramObj; |
|||
} else if (paramObj instanceof Map) { |
|||
for (Object arg : ((Map) paramObj).values()) { |
|||
if (arg instanceof DataScope) { |
|||
scope = (DataScope) arg; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 不用数据过滤
|
|||
if (scope == null) { |
|||
return invocation.proceed(); |
|||
} |
|||
|
|||
// 拼接新SQL
|
|||
String orderBy = "ORDER BY"; |
|||
String groupBy = "GROUP BY"; |
|||
if (originalSql.indexOf(groupBy) > -1) { |
|||
originalSql = originalSql.replace(groupBy, scope.getSqlFilter() + groupBy); |
|||
} else if (originalSql.indexOf(orderBy) > -1) { |
|||
originalSql = originalSql.replace(orderBy, scope.getSqlFilter() + orderBy); |
|||
} else { |
|||
originalSql = originalSql + scope.getSqlFilter(); |
|||
} |
|||
|
|||
// 重写SQL
|
|||
metaObject.setValue("delegate.boundSql.sql", originalSql); |
|||
return invocation.proceed(); |
|||
} |
|||
|
|||
@Override |
|||
public Object plugin(Object target) { |
|||
if (target instanceof StatementHandler) { |
|||
return Plugin.wrap(target, this); |
|||
} |
|||
return target; |
|||
} |
|||
|
|||
@Override |
|||
public void setProperties(Properties properties) { |
|||
|
|||
} |
|||
} |
|||
@ -1,125 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.service; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Collection; |
|||
|
|||
/** |
|||
* 基础服务接口,所有Service接口都要继承 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface BaseService<T> { |
|||
|
|||
/** |
|||
* 逻辑删除 |
|||
* @param ids ids |
|||
* @param entity 实体 |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
boolean logicDelete(Long[] ids, Class<T> entity); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入一条记录(选择字段,策略插入) |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
*/ |
|||
boolean insert(T entity); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入(批量),该方法不支持 Oracle、SQL Server |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
*/ |
|||
boolean insertBatch(Collection<T> entityList); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入(批量) |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
* @param batchSize 插入批次数量 |
|||
*/ |
|||
boolean insertBatch(Collection<T> entityList, int batchSize); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 选择修改 |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
*/ |
|||
boolean updateById(T entity); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 whereEntity 条件,更新记录 |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
* @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper} |
|||
*/ |
|||
boolean update(T entity, Wrapper<T> updateWrapper); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据ID 批量更新 |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
*/ |
|||
boolean updateBatchById(Collection<T> entityList); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据ID 批量更新 |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
* @param batchSize 更新批次数量 |
|||
*/ |
|||
boolean updateBatchById(Collection<T> entityList, int batchSize); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 查询 |
|||
* </p> |
|||
* |
|||
* @param id 主键ID |
|||
*/ |
|||
T selectById(Serializable id); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 删除 |
|||
* </p> |
|||
* |
|||
* @param id 主键ID |
|||
*/ |
|||
boolean deleteById(Serializable id); |
|||
|
|||
/** |
|||
* <p> |
|||
* 删除(根据ID 批量删除) |
|||
* </p> |
|||
* |
|||
* @param idList 主键ID列表 |
|||
*/ |
|||
boolean deleteBatchIds(Collection<? extends Serializable> idList); |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.service; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* CRUD基础服务接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public interface CrudService<T, D> extends BaseService<T> { |
|||
|
|||
PageData<D> page(Map<String, Object> params); |
|||
|
|||
List<D> list(Map<String, Object> params); |
|||
|
|||
D get(Long id); |
|||
|
|||
void save(D dto); |
|||
|
|||
void update(D dto); |
|||
|
|||
void delete(Long[] ids); |
|||
|
|||
} |
|||
@ -1,301 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|||
import com.baomidou.mybatisplus.core.enums.SqlMethod; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.metadata.OrderItem; |
|||
import com.baomidou.mybatisplus.core.toolkit.*; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; |
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.commons.mybatis.utils.EntityUtils; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|||
import org.apache.ibatis.binding.MapperMethod; |
|||
import org.apache.ibatis.session.SqlSession; |
|||
import org.mybatis.spring.SqlSessionUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 基础服务类,所有Service都要继承 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements BaseService<T> { |
|||
|
|||
@Autowired |
|||
protected M baseDao; |
|||
|
|||
/** |
|||
* 获取分页对象 |
|||
* |
|||
* @param params 分页查询参数 |
|||
* @param defaultOrderField 默认排序字段 |
|||
* @param isAsc 排序方式 |
|||
*/ |
|||
protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) { |
|||
Page<T> page = initPage(params); |
|||
|
|||
//默认排序
|
|||
if (StringUtils.isNotEmpty(defaultOrderField)) { |
|||
if (isAsc) { |
|||
page.addOrder(OrderItem.asc(defaultOrderField)); |
|||
} else { |
|||
page.addOrder(OrderItem.desc(defaultOrderField)); |
|||
} |
|||
} |
|||
return page; |
|||
} |
|||
|
|||
/** |
|||
* 获取分页对象 |
|||
* |
|||
* @param params 分页查询参数 |
|||
* @return com.baomidou.mybatisplus.core.metadata.IPage<T> |
|||
* @author yujintao |
|||
* @date 2019/6/12 10:57 |
|||
*/ |
|||
protected <T> IPage<T> getPage(Map<String, Object> params) { |
|||
Page<T> page = initPage(params); |
|||
return page; |
|||
} |
|||
|
|||
/** |
|||
* 初始化分页对象 |
|||
* |
|||
* @param params 分页查询参数 |
|||
* @return com.baomidou.mybatisplus.core.metadata.IPage<T> |
|||
* @author yujintao |
|||
* @date 2019/6/12 10:57 |
|||
*/ |
|||
private <T> Page<T> initPage(Map<String, Object> params) { |
|||
//分页参数
|
|||
long curPage = 1; |
|||
long limit = 10; |
|||
|
|||
if (params.get(Constant.PAGE) != null) { |
|||
curPage = Long.parseLong((String) params.get(Constant.PAGE)); |
|||
} |
|||
if (params.get(Constant.LIMIT) != null) { |
|||
limit = Long.parseLong((String) params.get(Constant.LIMIT)); |
|||
} |
|||
|
|||
//分页对象
|
|||
Page<T> page = new Page<>(curPage, limit); |
|||
|
|||
//分页参数
|
|||
params.put(Constant.PAGE, page); |
|||
|
|||
//排序字段
|
|||
String orderField = (String) params.get(Constant.ORDER_FIELD); |
|||
String order = (String) params.get(Constant.ORDER); |
|||
|
|||
//前端字段排序
|
|||
if (StringUtils.isNotEmpty(orderField) && StringUtils.isNotEmpty(order)) { |
|||
if (Constant.ASC.equalsIgnoreCase(order)) { |
|||
return page.addOrder(OrderItem.asc(orderField)); |
|||
} else { |
|||
return page.addOrder(OrderItem.desc(orderField)); |
|||
} |
|||
} |
|||
|
|||
return page; |
|||
} |
|||
|
|||
protected <T> PageData<T> getPageData(List<?> list, long total, Class<T> target) { |
|||
List<T> targetList = ConvertUtils.sourceToTarget(list, target); |
|||
|
|||
return new PageData<>(targetList, total); |
|||
} |
|||
|
|||
protected <T> PageData<T> getPageData(IPage page, Class<T> target) { |
|||
return getPageData(page.getRecords(), page.getTotal(), target); |
|||
} |
|||
|
|||
protected Map<String, Object> paramsToLike(Map<String, Object> params, String... likes) { |
|||
for (String like : likes) { |
|||
String val = (String) params.get(like); |
|||
if (StringUtils.isNotEmpty(val)) { |
|||
params.put(like, "%" + val + "%"); |
|||
} else { |
|||
params.put(like, null); |
|||
} |
|||
} |
|||
return params; |
|||
} |
|||
|
|||
/** |
|||
* 逻辑删除 |
|||
* |
|||
* @param ids ids |
|||
* @param entity 实体 |
|||
* @return boolean |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean logicDelete(Long[] ids, Class<T> entity) { |
|||
List<T> entityList = EntityUtils.deletedBy(ids, entity); |
|||
|
|||
return updateBatchById(entityList); |
|||
} |
|||
|
|||
/** |
|||
* <p> |
|||
* 判断数据库操作是否成功 |
|||
* </p> |
|||
* <p> |
|||
* 注意!! 该方法为 Integer 判断,不可传入 int 基本类型 |
|||
* </p> |
|||
* |
|||
* @param result 数据库操作返回影响条数 |
|||
* @return boolean |
|||
*/ |
|||
protected static boolean retBool(Integer result) { |
|||
return SqlHelper.retBool(result); |
|||
} |
|||
|
|||
protected Class<T> currentModelClass() { |
|||
return (Class<T>) ReflectionKit.getSuperClassGenericType(getClass(), 1); |
|||
} |
|||
|
|||
/** |
|||
* <p> |
|||
* 批量操作 SqlSession |
|||
* </p> |
|||
*/ |
|||
protected SqlSession sqlSessionBatch() { |
|||
return SqlHelper.sqlSessionBatch(currentModelClass()); |
|||
} |
|||
|
|||
/** |
|||
* 释放sqlSession |
|||
* |
|||
* @param sqlSession session |
|||
*/ |
|||
protected void closeSqlSession(SqlSession sqlSession) { |
|||
SqlSessionUtils.closeSqlSession(sqlSession, GlobalConfigUtils.currentSessionFactory(currentModelClass())); |
|||
} |
|||
|
|||
/** |
|||
* 获取SqlStatement |
|||
* |
|||
* @param sqlMethod |
|||
* @return |
|||
*/ |
|||
protected String sqlStatement(SqlMethod sqlMethod) { |
|||
return SqlHelper.table(currentModelClass()).getSqlStatement(sqlMethod.getMethod()); |
|||
} |
|||
|
|||
@Override |
|||
public boolean insert(T entity) { |
|||
return BaseServiceImpl.retBool(baseDao.insert(entity)); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean insertBatch(Collection<T> entityList) { |
|||
return insertBatch(entityList, 100); |
|||
} |
|||
|
|||
/** |
|||
* 批量插入 |
|||
* |
|||
* @param entityList |
|||
* @param batchSize |
|||
* @return |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean insertBatch(Collection<T> entityList, int batchSize) { |
|||
SqlSession batchSqlSession = sqlSessionBatch(); |
|||
int i = 0; |
|||
String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE); |
|||
try { |
|||
for (T anEntityList : entityList) { |
|||
batchSqlSession.insert(sqlStatement, anEntityList); |
|||
if (i >= 1 && i % batchSize == 0) { |
|||
batchSqlSession.flushStatements(); |
|||
} |
|||
i++; |
|||
} |
|||
batchSqlSession.flushStatements(); |
|||
} finally { |
|||
closeSqlSession(batchSqlSession); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
@Override |
|||
public boolean updateById(T entity) { |
|||
return BaseServiceImpl.retBool(baseDao.updateById(entity)); |
|||
} |
|||
|
|||
@Override |
|||
public boolean update(T entity, Wrapper<T> updateWrapper) { |
|||
return BaseServiceImpl.retBool(baseDao.update(entity, updateWrapper)); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean updateBatchById(Collection<T> entityList) { |
|||
return updateBatchById(entityList, 30); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean updateBatchById(Collection<T> entityList, int batchSize) { |
|||
if (CollectionUtils.isEmpty(entityList)) { |
|||
throw new IllegalArgumentException("Error: entityList must not be empty"); |
|||
} |
|||
SqlSession batchSqlSession = sqlSessionBatch(); |
|||
int i = 0; |
|||
String sqlStatement = sqlStatement(SqlMethod.UPDATE_BY_ID); |
|||
try { |
|||
for (T anEntityList : entityList) { |
|||
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); |
|||
param.put(Constants.ENTITY, anEntityList); |
|||
batchSqlSession.update(sqlStatement, param); |
|||
if (i >= 1 && i % batchSize == 0) { |
|||
batchSqlSession.flushStatements(); |
|||
} |
|||
i++; |
|||
} |
|||
batchSqlSession.flushStatements(); |
|||
} finally { |
|||
closeSqlSession(batchSqlSession); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
@Override |
|||
public T selectById(Serializable id) { |
|||
return baseDao.selectById(id); |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteById(Serializable id) { |
|||
return SqlHelper.delBool(baseDao.deleteById(id)); |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteBatchIds(Collection<? extends Serializable> idList) { |
|||
return SqlHelper.delBool(baseDao.deleteBatchIds(idList)); |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; |
|||
import com.elink.esua.epdc.commons.mybatis.service.CrudService; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* CRUD基础服务类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public abstract class CrudServiceImpl<M extends BaseMapper<T>, T, D> extends BaseServiceImpl<M, T> implements CrudService<T, D> { |
|||
|
|||
protected Class<D> currentDtoClass() { |
|||
return (Class<D>) ReflectionKit.getSuperClassGenericType(getClass(), 2); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<D> page(Map<String, Object> params) { |
|||
IPage<T> page = baseDao.selectPage( |
|||
getPage(params, Constant.CREATE_DATE, false), |
|||
getWrapper(params) |
|||
); |
|||
|
|||
return getPageData(page, currentDtoClass()); |
|||
} |
|||
|
|||
@Override |
|||
public List<D> list(Map<String, Object> params) { |
|||
List<T> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, currentDtoClass()); |
|||
} |
|||
|
|||
public abstract QueryWrapper<T> getWrapper(Map<String, Object> params); |
|||
|
|||
@Override |
|||
public D get(Long id) { |
|||
T entity = baseDao.selectById(id); |
|||
|
|||
return ConvertUtils.sourceToTarget(entity, currentDtoClass()); |
|||
} |
|||
|
|||
@Override |
|||
public void save(D dto) { |
|||
T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); |
|||
insert(entity); |
|||
} |
|||
|
|||
@Override |
|||
public void update(D dto) { |
|||
T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); |
|||
updateById(entity); |
|||
} |
|||
|
|||
@Override |
|||
public void delete(Long[] ids) { |
|||
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|||
} |
|||
} |
|||
@ -1,74 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.mybatis.utils; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.entity.DeptScope; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 部门信息实体工具类 |
|||
* |
|||
* @author rongchao |
|||
* @Date 19-12-18 |
|||
*/ |
|||
public class DeptEntityUtils { |
|||
|
|||
@Data |
|||
public static class DeptDto { |
|||
/** |
|||
* 父所有部门ID |
|||
*/ |
|||
private String parentDeptIds; |
|||
/** |
|||
* 父所有部门 |
|||
*/ |
|||
private String parentDeptNames; |
|||
/** |
|||
* 所有部门ID |
|||
*/ |
|||
private String allDeptIds; |
|||
/** |
|||
* 所有部门 |
|||
*/ |
|||
private String allDeptNames; |
|||
} |
|||
|
|||
/** |
|||
* 装载部门信息 |
|||
* |
|||
* @param dto |
|||
* @param entityClass |
|||
* @return T |
|||
* @author rongchao |
|||
* @since 2019-12-18 |
|||
*/ |
|||
public static <T extends DeptScope> T loadDeptInfo(DeptDto dto, Class<T> entityClass) { |
|||
try { |
|||
T t = entityClass.newInstance(); |
|||
t.setAllDeptIds(dto.getAllDeptIds()); |
|||
t.setAllDeptNames(dto.getAllDeptNames()); |
|||
t.setParentDeptIds(dto.getParentDeptIds()); |
|||
t.setParentDeptNames(dto.getParentDeptNames()); |
|||
return t; |
|||
} catch (InstantiationException e) { |
|||
e.printStackTrace(); |
|||
} catch (IllegalAccessException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 装载部门信息 |
|||
* |
|||
* @param dto |
|||
* @param entity |
|||
* @return void |
|||
* @author rongchao |
|||
* @since 2019-12-18 |
|||
*/ |
|||
public static <T extends DeptScope> void loadDeptInfo(DeptDto dto, T entity) { |
|||
entity.setAllDeptIds(dto.getAllDeptIds()); |
|||
entity.setAllDeptNames(dto.getAllDeptNames()); |
|||
entity.setParentDeptIds(dto.getParentDeptIds()); |
|||
entity.setParentDeptNames(dto.getParentDeptNames()); |
|||
} |
|||
} |
|||
@ -1,85 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.mybatis.utils; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.enums.DelFlagEnum; |
|||
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|||
|
|||
import java.lang.reflect.Field; |
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 实体工具类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class EntityUtils { |
|||
|
|||
/** |
|||
* 设置删除信息 |
|||
* @param ids ids |
|||
* @param entity 实体 |
|||
*/ |
|||
public static <T> List<T> deletedBy(Long[] ids, Class<T> entity) { |
|||
List<T> entityList = new ArrayList<>(ids.length); |
|||
for(Long id : ids){ |
|||
T entityObject = deletedBy(id, entity); |
|||
entityList.add(entityObject); |
|||
} |
|||
|
|||
return entityList; |
|||
} |
|||
|
|||
/** |
|||
* 设置删除信息 |
|||
* @param id id |
|||
* @param entity 实体 |
|||
*/ |
|||
public static <T> T deletedBy(Long id, Class<T> entity) { |
|||
Map<String, Object> map = new HashMap<>(4); |
|||
map.put("id", id); |
|||
map.put("updater", SecurityUser.getUserId()); |
|||
map.put("updateDate", new Date()); |
|||
map.put("delFlag", DelFlagEnum.DEL.value()); |
|||
|
|||
T entityObject = null; |
|||
try { |
|||
entityObject = entity.newInstance(); |
|||
} catch (Exception e) { |
|||
|
|||
} |
|||
|
|||
for (Map.Entry<String, Object> entry : map.entrySet()) { |
|||
setValue(entityObject, entry.getKey(), entry.getValue()); |
|||
} |
|||
|
|||
return entityObject; |
|||
} |
|||
|
|||
private static <T> void setValue(T entity, String key, Object value) { |
|||
Class<?> clazz = entity.getClass(); |
|||
|
|||
for (; clazz != Object.class; clazz = clazz.getSuperclass()) { |
|||
Field[] fields = clazz.getDeclaredFields(); |
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
|
|||
if (field.getName().equalsIgnoreCase(key)) { |
|||
try { |
|||
field.set(entity, value); |
|||
} catch (IllegalAccessException e) { |
|||
continue; |
|||
} |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
<?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> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>epdc-commons-tools-phone</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.googlecode.libphonenumber</groupId> |
|||
<artifactId>libphonenumber</artifactId> |
|||
<version>8.8.8</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.googlecode.libphonenumber</groupId> |
|||
<artifactId>carrier</artifactId> |
|||
<version>1.75</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.googlecode.libphonenumber</groupId> |
|||
<artifactId>geocoder</artifactId> |
|||
<version>2.85</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.googlecode.libphonenumber</groupId> |
|||
<artifactId>prefixmapper</artifactId> |
|||
<version>2.85</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
</project> |
|||
@ -1,79 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.utils; |
|||
|
|||
/** |
|||
* 电话DTO |
|||
* |
|||
* @author rongchao |
|||
* @Date 18-12-11 |
|||
*/ |
|||
public class PhoneDto { |
|||
|
|||
/** |
|||
* 省份名称 |
|||
*/ |
|||
private String provinceName; |
|||
|
|||
/** |
|||
* 城市名称 |
|||
*/ |
|||
private String cityName; |
|||
|
|||
/** |
|||
* 运营商:移动/电信/联通 |
|||
*/ |
|||
private String carrier; |
|||
|
|||
/** |
|||
* 省份名称 |
|||
* |
|||
* @return 获取provinceName属性值 |
|||
*/ |
|||
public String getProvinceName() { |
|||
return provinceName; |
|||
} |
|||
|
|||
/** |
|||
* 省份名称 |
|||
* |
|||
* @param provinceName 设置 provinceName 属性值为参数值 provinceName |
|||
*/ |
|||
public void setProvinceName(String provinceName) { |
|||
this.provinceName = provinceName; |
|||
} |
|||
|
|||
/** |
|||
* 城市名称 |
|||
* |
|||
* @return 获取cityName属性值 |
|||
*/ |
|||
public String getCityName() { |
|||
return cityName; |
|||
} |
|||
|
|||
/** |
|||
* 城市名称 |
|||
* |
|||
* @param cityName 设置 cityName 属性值为参数值 cityName |
|||
*/ |
|||
public void setCityName(String cityName) { |
|||
this.cityName = cityName; |
|||
} |
|||
|
|||
/** |
|||
* 运营商:移动/电信/联通 |
|||
* |
|||
* @return 获取carrier属性值 |
|||
*/ |
|||
public String getCarrier() { |
|||
return carrier; |
|||
} |
|||
|
|||
/** |
|||
* 运营商:移动/电信/联通 |
|||
* |
|||
* @param carrier 设置 carrier 属性值为参数值 carrier |
|||
*/ |
|||
public void setCarrier(String carrier) { |
|||
this.carrier = carrier; |
|||
} |
|||
} |
|||
@ -1,175 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.utils; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-12-11 |
|||
*/ |
|||
|
|||
import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper; |
|||
import com.google.i18n.phonenumbers.PhoneNumberUtil; |
|||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; |
|||
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; |
|||
|
|||
import java.util.Locale; |
|||
|
|||
/** |
|||
* 手机号归属地查询 |
|||
* jar依赖:com.googlecode.libphonenumber(Libphonenumber、Geocoder、Prefixmapper |
|||
* 、Carrier) pom依赖:http://mvnrepository.com/search?q=libphonenumber
|
|||
* 项目地址:https://github.com/googlei18n/libphonenumber
|
|||
* |
|||
* @author rongchao |
|||
* @Date 18-12-11 |
|||
*/ |
|||
public class PhoneUtil { |
|||
|
|||
/** |
|||
* 直辖市 |
|||
*/ |
|||
private final static String[] MUNICIPALITY = {"北京市", "天津市", "上海市", "重庆市"}; |
|||
|
|||
/** |
|||
* 自治区 |
|||
*/ |
|||
private final static String[] AUTONOMOUS_REGION = {"新疆", "内蒙古", "西藏", "宁夏", "广西"}; |
|||
|
|||
private static PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil |
|||
.getInstance(); |
|||
|
|||
/** |
|||
* 提供与电话号码相关的运营商信息 |
|||
*/ |
|||
private static PhoneNumberToCarrierMapper carrierMapper = PhoneNumberToCarrierMapper |
|||
.getInstance(); |
|||
|
|||
/** |
|||
* 提供与电话号码有关的地理信息 |
|||
*/ |
|||
private static PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder |
|||
.getInstance(); |
|||
|
|||
/** |
|||
* 中国大陆区区号 |
|||
*/ |
|||
private final static int COUNTRY_CODE = 86; |
|||
|
|||
/** |
|||
* 根据手机号 判断手机号是否有效 |
|||
* |
|||
* @param phoneNumber 手机号码 |
|||
* @return true-有效 false-无效 |
|||
*/ |
|||
public static boolean checkPhoneNumber(String phoneNumber) { |
|||
long phone = Long.parseLong(phoneNumber); |
|||
|
|||
PhoneNumber pn = new PhoneNumber(); |
|||
pn.setCountryCode(COUNTRY_CODE); |
|||
pn.setNationalNumber(phone); |
|||
|
|||
return phoneNumberUtil.isValidNumber(pn); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 根据手机号 判断手机运营商 |
|||
* |
|||
* @param phoneNumber 手机号码 |
|||
* @return 如:广东省广州市移动 |
|||
*/ |
|||
public static String getCarrier(String phoneNumber) { |
|||
|
|||
long phone = Long.parseLong(phoneNumber); |
|||
|
|||
PhoneNumber pn = new PhoneNumber(); |
|||
pn.setCountryCode(COUNTRY_CODE); |
|||
pn.setNationalNumber(phone); |
|||
// 返回结果只有英文,自己转成成中文
|
|||
String carrierEn = carrierMapper.getNameForNumber(pn, Locale.ENGLISH); |
|||
String carrierZh = ""; |
|||
switch (carrierEn) { |
|||
case "China Mobile": |
|||
carrierZh += "移动"; |
|||
break; |
|||
case "China Unicom": |
|||
carrierZh += "联通"; |
|||
break; |
|||
case "China Telecom": |
|||
carrierZh += "电信"; |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
return carrierZh; |
|||
} |
|||
|
|||
/** |
|||
* 根据手机号 获取手机归属地 |
|||
* |
|||
* @param phoneNumber 手机号码 |
|||
* @return 如:广东省广州市 |
|||
*/ |
|||
public static String getGeo(String phoneNumber) { |
|||
long phone = Long.parseLong(phoneNumber); |
|||
|
|||
PhoneNumber pn = new PhoneNumber(); |
|||
pn.setCountryCode(COUNTRY_CODE); |
|||
pn.setNationalNumber(phone); |
|||
return geocoder.getDescriptionForNumber(pn, Locale.CHINESE); |
|||
} |
|||
|
|||
/** |
|||
* 根据手机号 获取手机信息模型 |
|||
* |
|||
* <pre> |
|||
* 若返回值为null,则说明该号码无效 |
|||
* </pre> |
|||
* |
|||
* @param phoneNumber 手机号码 |
|||
* @return 手机信息模型PhoneModel |
|||
*/ |
|||
public static PhoneDto getPhoneDto(String phoneNumber) { |
|||
if (checkPhoneNumber(phoneNumber)) { |
|||
String geo = getGeo(phoneNumber); |
|||
PhoneDto phoneDto = new PhoneDto(); |
|||
String carrier = getCarrier(phoneNumber); |
|||
phoneDto.setCarrier(carrier); |
|||
// 直辖市
|
|||
for (String val : MUNICIPALITY) { |
|||
if (geo.equals(val)) { |
|||
phoneDto.setProvinceName(val.replace("市", "")); |
|||
phoneDto.setCityName(val); |
|||
return phoneDto; |
|||
} |
|||
} |
|||
// 自治区
|
|||
for (String val : AUTONOMOUS_REGION) { |
|||
if (geo.startsWith(val)) { |
|||
phoneDto.setProvinceName(val); |
|||
phoneDto.setCityName(geo.replace(val, "")); |
|||
return phoneDto; |
|||
} |
|||
} |
|||
|
|||
// 其它
|
|||
String[] splitArr = geo.split("省"); |
|||
if (splitArr != null && splitArr.length == 2) { |
|||
phoneDto.setProvinceName(splitArr[0]); |
|||
phoneDto.setCityName(splitArr[1]); |
|||
return phoneDto; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static void main(String[] args) { |
|||
PhoneDto phoneDto = PhoneUtil.getPhoneDto("13701001254"); |
|||
if (phoneDto != null) { |
|||
System.out.println(phoneDto.getProvinceName()); |
|||
System.out.println(phoneDto.getCityName()); |
|||
System.out.println(phoneDto.getCarrier()); |
|||
} else { |
|||
System.err.println("该号码无效"); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
<?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> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<version>1.0.0</version> |
|||
<artifactId>epdc-commons-tools-wx-ma</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.binarywang</groupId> |
|||
<artifactId>weixin-java-miniapp</artifactId> |
|||
<version>3.6.0</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
</project> |
|||
@ -1,13 +0,0 @@ |
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wanggongfeng |
|||
* @date 2020/5/26 15:40 |
|||
*/ |
|||
@Data |
|||
public class TemplateData { |
|||
//keyword1:信息1,keyword2:信息2,keyword3:信息3,keyword4:信息4,keyword5:参数5
|
|||
private String value;//,,依次排下去
|
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
/** |
|||
* 获取AccessToken |
|||
* @author wanggongfeng |
|||
* @date 2020/5/27 14:31 |
|||
*/ |
|||
public class WxAccessTokenBean { |
|||
private String access_token; |
|||
private int expires_in = -1; |
|||
|
|||
public String getAccess_token() { |
|||
return access_token; |
|||
} |
|||
|
|||
public void setAccess_token(String access_token) { |
|||
this.access_token = access_token; |
|||
} |
|||
|
|||
public int getExpires_in() { |
|||
return expires_in; |
|||
} |
|||
|
|||
public void setExpires_in(int expires_in) { |
|||
this.expires_in = expires_in; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "WxAccessTokenBean{" + |
|||
"access_token='" + access_token + '\'' + |
|||
", expires_in=" + expires_in + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author wanggongfeng |
|||
* @date 2020/5/26 15:39 |
|||
*/ |
|||
@Data |
|||
public class WxMssVo { |
|||
private String touser;//用户openid
|
|||
private String template_id;//模版id
|
|||
private String page = "pages/index/index";//默认跳到小程序首页
|
|||
private String miniprogram_state;// 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
|||
private String lang = "zh_CN";// 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
|
|||
private Map<String, TemplateData> data;//推送文字
|
|||
} |
|||
@ -1,63 +0,0 @@ |
|||
package com.elink.esua.epdc.utils; |
|||
|
|||
import cn.binarywang.wx.miniapp.api.WxMaService; |
|||
import com.elink.esua.epdc.wx.ma.WxMaConfig; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 获取小程序业务工具 |
|||
* |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 13:29 |
|||
*/ |
|||
@Component |
|||
public class WxMaServiceUtils { |
|||
|
|||
@Value("${wx.ma.appId.normal}") |
|||
private String APPID_NORMAL; |
|||
|
|||
@Value("${wx.ma.appId.work}") |
|||
private String APPID_WORK; |
|||
|
|||
@Value("${wx.ma.appId.analysis}") |
|||
private String APPID_ANALYSIS; |
|||
|
|||
/** |
|||
* 获取党群e家 普通居民端配置 |
|||
* |
|||
* @return cn.binarywang.wx.miniapp.api.WxMaService |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 16:09 |
|||
*/ |
|||
public final WxMaService normalWxMaService() { |
|||
final WxMaService wxMaService = WxMaConfig.getMaService(APPID_NORMAL); |
|||
return wxMaService; |
|||
} |
|||
|
|||
/** |
|||
* 获取党群e家 工作端配置 |
|||
* |
|||
* @return cn.binarywang.wx.miniapp.api.WxMaService |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 16:10 |
|||
*/ |
|||
public final WxMaService workWxMaService() { |
|||
final WxMaService wxMaService = WxMaConfig.getMaService(APPID_WORK); |
|||
return wxMaService; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* 获取党群e家 数据分析端配置 |
|||
* |
|||
* @params [] |
|||
* @return cn.binarywang.wx.miniapp.api.WxMaService |
|||
* @author liuchuang |
|||
* @since 2020/2/12 10:44 |
|||
*/ |
|||
public final WxMaService analysisWxMaService() { |
|||
final WxMaService wxMaService = WxMaConfig.getMaService(APPID_ANALYSIS); |
|||
return wxMaService; |
|||
} |
|||
} |
|||
@ -1,148 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.ma; |
|||
|
|||
import cn.binarywang.wx.miniapp.api.WxMaService; |
|||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
|||
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage; |
|||
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; |
|||
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; |
|||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; |
|||
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler; |
|||
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter; |
|||
import com.google.common.collect.Lists; |
|||
import com.google.common.collect.Maps; |
|||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; |
|||
import me.chanjar.weixin.common.error.WxErrorException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.io.File; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* @author <a href="https://github.com/binarywang">Binary Wang</a> |
|||
*/ |
|||
@Configuration |
|||
@EnableConfigurationProperties(WxMaProperties.class) |
|||
public class WxMaConfig { |
|||
|
|||
private WxMaProperties properties; |
|||
|
|||
private static Map<String, WxMaMessageRouter> routers = Maps.newHashMap(); |
|||
private static Map<String, WxMaService> maServices = Maps.newHashMap(); |
|||
|
|||
@Autowired |
|||
public WxMaConfig(WxMaProperties properties) { |
|||
this.properties = properties; |
|||
} |
|||
|
|||
public static WxMaService getMaService(String appid) { |
|||
WxMaService wxService = maServices.get(appid); |
|||
if (wxService == null) { |
|||
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid)); |
|||
} |
|||
|
|||
return wxService; |
|||
} |
|||
|
|||
public static WxMaMessageRouter getRouter(String appid) { |
|||
return routers.get(appid); |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
List<WxMaProperties.Config> configs = this.properties.getConfigs(); |
|||
if (configs == null) { |
|||
throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!"); |
|||
} |
|||
|
|||
maServices = configs.stream() |
|||
.map(a -> { |
|||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
|||
config.setAppid(a.getAppid()); |
|||
config.setSecret(a.getSecret()); |
|||
config.setToken(a.getToken()); |
|||
config.setAesKey(a.getAesKey()); |
|||
config.setMsgDataFormat(a.getMsgDataFormat()); |
|||
|
|||
WxMaService service = new WxMaServiceImpl(); |
|||
service.setWxMaConfig(config); |
|||
routers.put(a.getAppid(), this.newRouter(service)); |
|||
return service; |
|||
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a)); |
|||
} |
|||
|
|||
private WxMaMessageRouter newRouter(WxMaService service) { |
|||
final WxMaMessageRouter router = new WxMaMessageRouter(service); |
|||
router |
|||
.rule().handler(logHandler).next() |
|||
.rule().async(false).content("模板").handler(templateMsgHandler).end() |
|||
.rule().async(false).content("文本").handler(textHandler).end() |
|||
.rule().async(false).content("图片").handler(picHandler).end() |
|||
.rule().async(false).content("二维码").handler(qrcodeHandler).end(); |
|||
return router; |
|||
} |
|||
|
|||
private final WxMaMessageHandler templateMsgHandler = (wxMessage, context, service, sessionManager) -> { |
|||
service.getMsgService().sendTemplateMsg(WxMaTemplateMessage.builder() |
|||
.templateId("此处更换为自己的模板id") |
|||
.formId("自己替换可用的formid") |
|||
.data(Lists.newArrayList( |
|||
new WxMaTemplateData("keyword1", "339208499", "#173177"))) |
|||
.toUser(wxMessage.getFromUser()) |
|||
.build()); |
|||
return null; |
|||
}; |
|||
|
|||
private final WxMaMessageHandler logHandler = (wxMessage, context, service, sessionManager) -> { |
|||
System.out.println("收到消息:" + wxMessage.toString()); |
|||
service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("收到信息为:" + wxMessage.toJson()) |
|||
.toUser(wxMessage.getFromUser()).build()); |
|||
return null; |
|||
}; |
|||
|
|||
private final WxMaMessageHandler textHandler = (wxMessage, context, service, sessionManager) -> { |
|||
service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("回复文本消息") |
|||
.toUser(wxMessage.getFromUser()).build()); |
|||
return null; |
|||
}; |
|||
|
|||
private final WxMaMessageHandler picHandler = (wxMessage, context, service, sessionManager) -> { |
|||
try { |
|||
WxMediaUploadResult uploadResult = service.getMediaService() |
|||
.uploadMedia("image", "png", |
|||
ClassLoader.getSystemResourceAsStream("tmp.png")); |
|||
service.getMsgService().sendKefuMsg( |
|||
WxMaKefuMessage |
|||
.newImageBuilder() |
|||
.mediaId(uploadResult.getMediaId()) |
|||
.toUser(wxMessage.getFromUser()) |
|||
.build()); |
|||
} catch (WxErrorException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
|
|||
private final WxMaMessageHandler qrcodeHandler = (wxMessage, context, service, sessionManager) -> { |
|||
try { |
|||
final File file = service.getQrcodeService().createQrcode("123", 430); |
|||
WxMediaUploadResult uploadResult = service.getMediaService().uploadMedia("image", file); |
|||
service.getMsgService().sendKefuMsg( |
|||
WxMaKefuMessage |
|||
.newImageBuilder() |
|||
.mediaId(uploadResult.getMediaId()) |
|||
.toUser(wxMessage.getFromUser()) |
|||
.build()); |
|||
} catch (WxErrorException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
return null; |
|||
}; |
|||
|
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.ma; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 微信小程序框架配置类 |
|||
* |
|||
* @author rongchao |
|||
* @Date 19-5-13 |
|||
*/ |
|||
@Data |
|||
@ConfigurationProperties(prefix = "wx.ma") |
|||
public class WxMaProperties { |
|||
|
|||
private List<Config> configs; |
|||
|
|||
@Data |
|||
public static class Config { |
|||
/** |
|||
* 设置微信小程序的appid |
|||
*/ |
|||
private String appid; |
|||
|
|||
/** |
|||
* 设置微信小程序的Secret |
|||
*/ |
|||
private String secret; |
|||
|
|||
/** |
|||
* 设置微信小程序消息服务器配置的token |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 设置微信小程序消息服务器配置的EncodingAESKey |
|||
*/ |
|||
private String aesKey; |
|||
|
|||
/** |
|||
* 消息格式,XML或者JSON |
|||
*/ |
|||
private String msgDataFormat; |
|||
} |
|||
|
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
# EditorConfig: http://editorconfig.org/ |
|||
|
|||
root = true |
|||
|
|||
[*] |
|||
indent_style = space |
|||
indent_size = 4 |
|||
end_of_line = lf |
|||
charset = utf-8 |
|||
trim_trailing_whitespace = true |
|||
insert_final_newline = true |
|||
|
|||
[*.md] |
|||
trim_trailing_whitespace = false |
|||
@ -1,13 +0,0 @@ |
|||
language: java |
|||
jdk: |
|||
- openjdk8 |
|||
|
|||
script: "mvn clean package -Dmaven.test.skip=true" |
|||
|
|||
branches: |
|||
only: |
|||
- master |
|||
|
|||
notifications: |
|||
email: |
|||
- binarywang@vip.qq.com |
|||
@ -1,58 +0,0 @@ |
|||
[](https://gitee.com/binary/weixin-java-mp-demo-springboot) |
|||
[](https://github.com/binarywang/weixin-java-mp-demo-springboot) |
|||
[](https://travis-ci.org/binarywang/weixin-java-mp-demo-springboot) |
|||
----------------------- |
|||
|
|||
### 本Demo基于Spring Boot构建,实现微信公众号后端开发功能。 |
|||
### 本项目为WxJava的Demo演示程序,更多Demo请[查阅此处](https://github.com/Wechat-Group/WxJava/blob/master/demo.md)。 |
|||
#### 如有问题请[【在此提问】](https://github.com/binarywang/weixin-java-mp-demo-springboot/issues),谢谢配合。 |
|||
|
|||
<table border="0"> |
|||
<tbody> |
|||
<tr> |
|||
<td align="left" valign="middle"> |
|||
<a href="http://mp.weixin.qq.com/mp/homepage?__biz=MzI3MzAwMzk4OA==&hid=1&sn=f31af3bf562b116b061c9ab4edf70b61&scene=18#wechat_redirect" target="_blank"> |
|||
<img height="120" src="https://gitee.com/binary/weixin-java-tools/raw/master/images/qrcodes/mp.png"> |
|||
</a> |
|||
</td> |
|||
<td align="center" valign="middle"> |
|||
<a href="https://cloud.tencent.com/redirect.php?redirect=1014&cps_key=a4c06ffe004dbcda44036daa1bf8f876&from=console" target="_blank"> |
|||
<img height="120" src="https://gitee.com/binary/weixin-java-tools/raw/master/images/banners/tcloud.jpg"> |
|||
</a> |
|||
</td> |
|||
<td align="right" valign="middle"> |
|||
<a href="https://coding.net/?utm_source=WxJava" target="_blank"> |
|||
<img height="120" src="https://gitee.com/binary/weixin-java-tools/raw/master/images/banners/coding.jpg"> |
|||
</a> |
|||
</td> |
|||
<td align="center" valign="middle"> |
|||
<a href="https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=7makzf5h" target="_blank"> |
|||
<img height="120" src="https://gitee.com/binary/weixin-java-tools/raw/master/images/banners/aliyun.jpg"> |
|||
</a> |
|||
</td> |
|||
</tr> |
|||
</tbody> |
|||
</table> |
|||
|
|||
## 使用步骤: |
|||
1. 请注意,本demo为简化代码编译时加入了lombok支持,如果不了解lombok的话,请先学习下相关知识,比如可以阅读[此文章](https://mp.weixin.qq.com/s/cUc-bUcprycADfNepnSwZQ); |
|||
1. 另外,新手遇到问题,请务必先阅读[【开发文档首页】](https://github.com/Wechat-Group/WxJava/wiki)的常见问题部分,可以少走很多弯路,节省不少时间。 |
|||
1. 配置:复制 `/src/main/resources/application.yml.template` 或修改其扩展名生成 `application.yml` 文件,根据自己需要填写相关配置(需要注意的是:yml文件内的属性冒号后面的文字之前需要加空格,可参考已有配置,否则属性会设置不成功); |
|||
2. 主要配置说明如下: |
|||
``` |
|||
wx: |
|||
mp: |
|||
configs: |
|||
- appId: 1111 (一个公众号的appid) |
|||
secret: 1111(公众号的appsecret) |
|||
token: 111 (接口配置里的Token值) |
|||
aesKey: 111 (接口配置里的EncodingAESKey值) |
|||
- appId: 2222 (另一个公众号的appid,以下同上) |
|||
secret: 1111 |
|||
token: 111 |
|||
aesKey: 111 |
|||
``` |
|||
3. 运行Java程序:`WxMpDemoApplication`; |
|||
4. 配置微信公众号中的接口地址:http://公网可访问域名/wx/portal/xxxxx (注意,xxxxx为对应公众号的appid值); |
|||
5. 根据自己需要修改各个handler的实现,加入自己的业务逻辑。 |
|||
|
|||
@ -1,60 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" |
|||
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.esua.epdc</groupId> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
|
|||
<version>1.0.0</version> |
|||
<artifactId>epdc-commons-tools-wx-mp</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<!-- <name>Wechat mp demo with Spring Boot and WxJava</name>--> |
|||
<!-- <description>基于 WxJava 和 Spring Boot 实现的微信公众号后端开发演示项目</description>--> |
|||
|
|||
<properties> |
|||
<weixin-java-mp.version>3.6.0</weixin-java-mp.version> |
|||
<maven.compiler.source>1.8</maven.compiler.source> |
|||
<maven.compiler.target>1.8</maven.compiler.target> |
|||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> |
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|||
<project.build.locales>zh_CN</project.build.locales> |
|||
<docker.image.prefix>wechat-mp-demo</docker.image.prefix> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.github.binarywang</groupId> |
|||
<artifactId>weixin-java-mp</artifactId> |
|||
<version>${weixin-java-mp.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<scope>compile</scope> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure-processor</artifactId> |
|||
<scope>compile</scope> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
</dependencies> |
|||
</project> |
|||
@ -1,17 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.builder; |
|||
|
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
public abstract class AbstractBuilder { |
|||
protected final Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
public abstract WxMpXmlOutMessage build(String content, |
|||
WxMpXmlMessage wxMessage, WxMpService service); |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.builder; |
|||
|
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
public class ImageBuilder extends AbstractBuilder { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, |
|||
WxMpService service) { |
|||
|
|||
WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId(content) |
|||
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) |
|||
.build(); |
|||
|
|||
return m; |
|||
} |
|||
|
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.builder; |
|||
|
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
public class TextBuilder extends AbstractBuilder { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, |
|||
WxMpService service) { |
|||
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content) |
|||
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) |
|||
.build(); |
|||
return m; |
|||
} |
|||
|
|||
} |
|||
@ -1,113 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.config; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.handler.*; |
|||
import lombok.AllArgsConstructor; |
|||
import me.chanjar.weixin.mp.api.WxMpMessageRouter; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
|||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import static me.chanjar.weixin.common.api.WxConsts.EventType; |
|||
import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE; |
|||
import static me.chanjar.weixin.common.api.WxConsts.EventType.UNSUBSCRIBE; |
|||
import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.CLICK; |
|||
import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.VIEW; |
|||
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; |
|||
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType.EVENT; |
|||
import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.*; |
|||
import static me.chanjar.weixin.mp.constant.WxMpEventConstants.POI_CHECK_NOTIFY; |
|||
|
|||
/** |
|||
* wechat mp configuration |
|||
* |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@AllArgsConstructor |
|||
@Configuration |
|||
@EnableConfigurationProperties(WxMpProperties.class) |
|||
public class WxMpConfiguration { |
|||
private final LogHandler logHandler; |
|||
private final NullHandler nullHandler; |
|||
private final KfSessionHandler kfSessionHandler; |
|||
private final StoreCheckNotifyHandler storeCheckNotifyHandler; |
|||
private final LocationHandler locationHandler; |
|||
private final MenuHandler menuHandler; |
|||
private final MsgHandler msgHandler; |
|||
private final UnsubscribeHandler unsubscribeHandler; |
|||
private final SubscribeHandler subscribeHandler; |
|||
private final ScanHandler scanHandler; |
|||
private final WxMpProperties properties; |
|||
|
|||
@Bean |
|||
public WxMpService wxMpService() { |
|||
// 代码里 getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!!
|
|||
final List<WxMpProperties.MpConfig> configs = this.properties.getConfigs(); |
|||
if (configs == null) { |
|||
throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!"); |
|||
} |
|||
|
|||
WxMpService service = new WxMpServiceImpl(); |
|||
service.setMultiConfigStorages(configs |
|||
.stream().map(a -> { |
|||
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl(); |
|||
configStorage.setAppId(a.getAppId()); |
|||
configStorage.setSecret(a.getSecret()); |
|||
configStorage.setToken(a.getToken()); |
|||
configStorage.setAesKey(a.getAesKey()); |
|||
return configStorage; |
|||
}).collect(Collectors.toMap(WxMpDefaultConfigImpl::getAppId, a -> a, (o, n) -> o))); |
|||
return service; |
|||
} |
|||
|
|||
@Bean |
|||
public WxMpMessageRouter messageRouter(WxMpService wxMpService) { |
|||
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService); |
|||
|
|||
// 记录所有事件的日志 (异步执行)
|
|||
newRouter.rule().handler(this.logHandler).next(); |
|||
|
|||
// 接收客服会话管理事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION) |
|||
.handler(this.kfSessionHandler).end(); |
|||
newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION) |
|||
.handler(this.kfSessionHandler).end(); |
|||
newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION) |
|||
.handler(this.kfSessionHandler).end(); |
|||
|
|||
// 门店审核事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(POI_CHECK_NOTIFY).handler(this.storeCheckNotifyHandler).end(); |
|||
|
|||
// 自定义菜单事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(CLICK).handler(this.menuHandler).end(); |
|||
|
|||
// 点击菜单连接事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(VIEW).handler(this.nullHandler).end(); |
|||
|
|||
// 关注事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end(); |
|||
|
|||
// 取消关注事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end(); |
|||
|
|||
// 上报地理位置事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(EventType.LOCATION).handler(this.locationHandler).end(); |
|||
|
|||
// 接收地理位置消息
|
|||
newRouter.rule().async(false).msgType(XmlMsgType.LOCATION).handler(this.locationHandler).end(); |
|||
|
|||
// 扫码事件
|
|||
newRouter.rule().async(false).msgType(EVENT).event(EventType.SCAN).handler(this.scanHandler).end(); |
|||
|
|||
// 默认
|
|||
newRouter.rule().async(false).handler(this.msgHandler).end(); |
|||
|
|||
return newRouter; |
|||
} |
|||
|
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.config; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.utils.JsonUtils; |
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* wechat mp properties |
|||
* |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Data |
|||
@ConfigurationProperties(prefix = "wx.mp") |
|||
public class WxMpProperties { |
|||
private List<MpConfig> configs; |
|||
|
|||
@Data |
|||
public static class MpConfig { |
|||
/** |
|||
* 设置微信公众号的appid |
|||
*/ |
|||
private String appId; |
|||
|
|||
/** |
|||
* 设置微信公众号的app secret |
|||
*/ |
|||
private String secret; |
|||
|
|||
/** |
|||
* 设置微信公众号的token |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 设置微信公众号的EncodingAESKey |
|||
*/ |
|||
private String aesKey; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return JsonUtils.toJson(this); |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.mp.api.WxMpMessageHandler; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
public abstract class AbstractHandler implements WxMpMessageHandler { |
|||
protected Logger logger = LoggerFactory.getLogger(getClass()); |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class KfSessionHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
//TODO 对会话做处理
|
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.builder.TextBuilder; |
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class LocationHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
if (wxMessage.getMsgType().equals(XmlMsgType.LOCATION)) { |
|||
//TODO 接收处理用户发送的地理位置消息
|
|||
try { |
|||
String content = "感谢反馈,您的的地理位置已收到!"; |
|||
return new TextBuilder().build(content, wxMessage, null); |
|||
} catch (Exception e) { |
|||
this.logger.error("位置消息接收处理失败", e); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
//上报地理位置事件
|
|||
this.logger.info("上报地理位置,纬度 : {},经度 : {},精度 : {}", |
|||
wxMessage.getLatitude(), wxMessage.getLongitude(), String.valueOf(wxMessage.getPrecision())); |
|||
|
|||
//TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用
|
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.utils.JsonUtils; |
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class LogHandler extends AbstractHandler { |
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
this.logger.info("\n接收到请求消息,内容:{}", JsonUtils.toJson(wxMessage)); |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class MenuHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService weixinService, |
|||
WxSessionManager sessionManager) { |
|||
|
|||
String msg = String.format("type:%s, event:%s, key:%s", |
|||
wxMessage.getMsgType(), wxMessage.getEvent(), |
|||
wxMessage.getEventKey()); |
|||
if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) { |
|||
return null; |
|||
} |
|||
|
|||
return WxMpXmlOutMessage.TEXT().content(msg) |
|||
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) |
|||
.build(); |
|||
} |
|||
|
|||
} |
|||
@ -1,52 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.builder.TextBuilder; |
|||
import com.elink.esua.epdc.wx.mp.utils.JsonUtils; |
|||
import me.chanjar.weixin.common.error.WxErrorException; |
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class MsgHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService weixinService, |
|||
WxSessionManager sessionManager) { |
|||
|
|||
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) { |
|||
//TODO 可以选择将消息保存到本地
|
|||
} |
|||
|
|||
//当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
|
|||
try { |
|||
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服") |
|||
&& weixinService.getKefuService().kfOnlineList() |
|||
.getKfOnlineList().size() > 0) { |
|||
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE() |
|||
.fromUser(wxMessage.getToUser()) |
|||
.toUser(wxMessage.getFromUser()).build(); |
|||
} |
|||
} catch (WxErrorException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
//TODO 组装回复消息
|
|||
String content = "收到信息内容:" + JsonUtils.toJson(wxMessage); |
|||
|
|||
return new TextBuilder().build(content, wxMessage, weixinService); |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class NullHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import me.chanjar.weixin.common.error.WxErrorException; |
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class ScanHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, |
|||
WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException { |
|||
// 扫码事件处理
|
|||
return null; |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 门店审核事件处理 |
|||
* |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class StoreCheckNotifyHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
// TODO 处理门店审核事件
|
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,71 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import com.elink.esua.epdc.wx.mp.builder.TextBuilder; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import me.chanjar.weixin.common.error.WxErrorException; |
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import me.chanjar.weixin.mp.bean.result.WxMpUser; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class SubscribeHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService weixinService, |
|||
WxSessionManager sessionManager) throws WxErrorException { |
|||
|
|||
this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser()); |
|||
|
|||
// 获取微信用户基本信息
|
|||
try { |
|||
WxMpUser userWxInfo = weixinService.getUserService() |
|||
.userInfo(wxMessage.getFromUser(), null); |
|||
if (userWxInfo != null) { |
|||
// TODO 可以添加关注用户到本地数据库
|
|||
} |
|||
} catch (WxErrorException e) { |
|||
if (e.getError().getErrorCode() == 48001) { |
|||
this.logger.info("该公众号没有获取用户信息权限!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
WxMpXmlOutMessage responseResult = null; |
|||
try { |
|||
responseResult = this.handleSpecial(wxMessage); |
|||
} catch (Exception e) { |
|||
this.logger.error(e.getMessage(), e); |
|||
} |
|||
|
|||
if (responseResult != null) { |
|||
return responseResult; |
|||
} |
|||
|
|||
try { |
|||
return new TextBuilder().build("感谢关注", wxMessage, weixinService); |
|||
} catch (Exception e) { |
|||
this.logger.error(e.getMessage(), e); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 处理特殊请求,比如如果是扫码进来的,可以做相应处理 |
|||
*/ |
|||
private WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage) |
|||
throws Exception { |
|||
//TODO
|
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.handler; |
|||
|
|||
import me.chanjar.weixin.common.session.WxSessionManager; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
@Component |
|||
public class UnsubscribeHandler extends AbstractHandler { |
|||
|
|||
@Override |
|||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, |
|||
Map<String, Object> context, WxMpService wxMpService, |
|||
WxSessionManager sessionManager) { |
|||
String openId = wxMessage.getFromUser(); |
|||
this.logger.info("取消关注用户 OPENID: " + openId); |
|||
// TODO 可以更新本地数据库为取消关注状态
|
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
package com.elink.esua.epdc.wx.mp.utils; |
|||
|
|||
import com.google.gson.Gson; |
|||
import com.google.gson.GsonBuilder; |
|||
|
|||
/** |
|||
* @author Binary Wang(https://github.com/binarywang)
|
|||
*/ |
|||
public class JsonUtils { |
|||
public static String toJson(Object obj) { |
|||
Gson gson = new GsonBuilder() |
|||
.setPrettyPrinting() |
|||
.create(); |
|||
return gson.toJson(obj); |
|||
} |
|||
} |
|||
@ -1,121 +0,0 @@ |
|||
<?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> |
|||
|
|||
<parent> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
|
|||
<artifactId>epdc-commons-tools</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<properties> |
|||
<hibernate.validator.version>6.0.12.Final</hibernate.validator.version> |
|||
<commons.lang.version>3.7</commons.lang.version> |
|||
<commons.fileupload.version>1.3.3</commons.fileupload.version> |
|||
<commons.io.version>2.6</commons.io.version> |
|||
<hutool.version>4.1.8</hutool.version> |
|||
<easypoi.version>3.1.0</easypoi.version> |
|||
<joda.time.version>2.9.9</joda.time.version> |
|||
<fastjson.version>1.2.59</fastjson.version> |
|||
<jsoup.version>1.11.3</jsoup.version> |
|||
<lombok.version>1.18.4</lombok.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-aop</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-openfeign</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-data-redis</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.fasterxml.jackson.core</groupId> |
|||
<artifactId>jackson-databind</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.hibernate</groupId> |
|||
<artifactId>hibernate-validator</artifactId> |
|||
<version>${hibernate.validator.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.commons</groupId> |
|||
<artifactId>commons-lang3</artifactId> |
|||
<version>${commons.lang.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>commons-fileupload</groupId> |
|||
<artifactId>commons-fileupload</artifactId> |
|||
<version>${commons.fileupload.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>commons-io</groupId> |
|||
<artifactId>commons-io</artifactId> |
|||
<version>${commons.io.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>cn.hutool</groupId> |
|||
<artifactId>hutool-all</artifactId> |
|||
<version>${hutool.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>cn.afterturn</groupId> |
|||
<artifactId>easypoi-base</artifactId> |
|||
<version>${easypoi.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>cn.afterturn</groupId> |
|||
<artifactId>easypoi-web</artifactId> |
|||
<version>${easypoi.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>joda-time</groupId> |
|||
<artifactId>joda-time</artifactId> |
|||
<version>${joda.time.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
<version>${fastjson.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.jsoup</groupId> |
|||
<artifactId>jsoup</artifactId> |
|||
<version>${jsoup.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<version>${lombok.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>net.coobird</groupId> |
|||
<artifactId>thumbnailator</artifactId> |
|||
<version>0.4.8</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -1,24 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 操作日志注解 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface LogOperation { |
|||
String value() default ""; |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.annotation; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* 登录用户信息 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Target(ElementType.PARAMETER) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface LoginUser { |
|||
|
|||
} |
|||
@ -1,126 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.aspect; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.elink.esua.epdc.commons.tools.annotation.LogOperation; |
|||
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|||
import com.elink.esua.epdc.commons.tools.security.user.UserDetail; |
|||
import com.elink.esua.epdc.commons.tools.utils.HttpContextUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.IpUtils; |
|||
import com.elink.esua.epdc.commons.tools.annotation.LogOperation; |
|||
import com.elink.esua.epdc.commons.tools.config.ModuleConfig; |
|||
import com.elink.esua.epdc.commons.tools.log.SysLogOperation; |
|||
import com.elink.esua.epdc.commons.tools.log.enums.LogTypeEnum; |
|||
import com.elink.esua.epdc.commons.tools.log.enums.OperationStatusEnum; |
|||
import com.elink.esua.epdc.commons.tools.log.producer.LogProducer; |
|||
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|||
import com.elink.esua.epdc.commons.tools.security.user.UserDetail; |
|||
import com.elink.esua.epdc.commons.tools.utils.HttpContextUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.IpUtils; |
|||
import org.aspectj.lang.ProceedingJoinPoint; |
|||
import org.aspectj.lang.annotation.Around; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.lang.reflect.Method; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 操作日志,切面处理类 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
public class LogOperationAspect { |
|||
@Autowired |
|||
private ModuleConfig moduleConfig; |
|||
@Autowired |
|||
private LogProducer logProducer; |
|||
|
|||
@Pointcut("@annotation(com.elink.esua.epdc.commons.tools.annotation.LogOperation)") |
|||
public void logPointCut() { |
|||
|
|||
} |
|||
|
|||
@Around("logPointCut()") |
|||
public Object around(ProceedingJoinPoint point) throws Throwable { |
|||
long beginTime = System.currentTimeMillis(); |
|||
try { |
|||
//执行方法
|
|||
Object result = point.proceed(); |
|||
|
|||
//执行时长(毫秒)
|
|||
long time = System.currentTimeMillis() - beginTime; |
|||
//保存日志
|
|||
saveLog(point, time, OperationStatusEnum.SUCCESS.value()); |
|||
|
|||
return result; |
|||
}catch(Exception e) { |
|||
//执行时长(毫秒)
|
|||
long time = System.currentTimeMillis() - beginTime; |
|||
//保存日志
|
|||
saveLog(point, time, OperationStatusEnum.FAIL.value()); |
|||
|
|||
throw e; |
|||
} |
|||
} |
|||
|
|||
|
|||
private void saveLog(ProceedingJoinPoint joinPoint, long time, Integer status) { |
|||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
|||
Method method = signature.getMethod(); |
|||
|
|||
SysLogOperation log = new SysLogOperation(); |
|||
LogOperation annotation = method.getAnnotation(LogOperation.class); |
|||
if(annotation != null){ |
|||
//注解上的描述
|
|||
log.setOperation(annotation.value()); |
|||
} |
|||
|
|||
//登录用户信息
|
|||
UserDetail user = SecurityUser.getUser(); |
|||
if(user != null){ |
|||
log.setCreator(user.getId()); |
|||
log.setCreatorName(user.getUsername()); |
|||
} |
|||
|
|||
log.setType(LogTypeEnum.OPERATION.value()); |
|||
log.setModule(moduleConfig.getName()); |
|||
log.setStatus(status); |
|||
log.setRequestTime((int)time); |
|||
log.setCreateDate(new Date()); |
|||
|
|||
//请求相关信息
|
|||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); |
|||
log.setIp(IpUtils.getIpAddr(request)); |
|||
log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); |
|||
log.setRequestUri(request.getRequestURI()); |
|||
log.setRequestMethod(request.getMethod()); |
|||
|
|||
//请求参数
|
|||
Object[] args = joinPoint.getArgs(); |
|||
try{ |
|||
String params = JSON.toJSONString(args[0]); |
|||
log.setRequestParams(params); |
|||
}catch (Exception e){ |
|||
|
|||
} |
|||
|
|||
//保存到Redis队列里
|
|||
logProducer.saveLog(log); |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.config; |
|||
|
|||
/** |
|||
* 模块配置信息 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface ModuleConfig { |
|||
/** |
|||
* 获取模块名称 |
|||
*/ |
|||
String getName(); |
|||
} |
|||
@ -1,111 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* 常量 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface Constant { |
|||
/** |
|||
* 成功 |
|||
*/ |
|||
int SUCCESS = 1; |
|||
/** |
|||
* 失败 |
|||
*/ |
|||
int FAIL = 0; |
|||
/** |
|||
* OK |
|||
*/ |
|||
String OK = "OK"; |
|||
/** |
|||
* 用户标识 |
|||
*/ |
|||
String USER_KEY = "userId"; |
|||
/** |
|||
* 菜单根节点标识 |
|||
*/ |
|||
Long MENU_ROOT = 0L; |
|||
/** |
|||
* 部门根节点标识 |
|||
*/ |
|||
Long DEPT_ROOT = 0L; |
|||
/** |
|||
* 分类根节点标识 |
|||
*/ |
|||
Long CATEGORY_ROOT = 0L; |
|||
/** |
|||
* 数据字典根节点标识 |
|||
*/ |
|||
Long DICT_ROOT = 0L; |
|||
/** |
|||
* 升序 |
|||
*/ |
|||
String ASC = "asc"; |
|||
/** |
|||
* 降序 |
|||
*/ |
|||
String DESC = "desc"; |
|||
/** |
|||
* 删除字段名 |
|||
*/ |
|||
String DEL_FLAG = "del_flag"; |
|||
/** |
|||
* 创建时间字段名 |
|||
*/ |
|||
String CREATE_DATE = "create_date"; |
|||
|
|||
/** |
|||
* 数据权限过滤 |
|||
*/ |
|||
String SQL_FILTER = "sqlFilter"; |
|||
/** |
|||
* 当前页码 |
|||
*/ |
|||
String PAGE = "page"; |
|||
/** |
|||
* 每页显示记录数 |
|||
*/ |
|||
String LIMIT = "limit"; |
|||
/** |
|||
* 排序字段 |
|||
*/ |
|||
String ORDER_FIELD = "orderField"; |
|||
/** |
|||
* 排序方式 |
|||
*/ |
|||
String ORDER = "order"; |
|||
/** |
|||
* token header |
|||
*/ |
|||
String TOKEN_HEADER = "token"; |
|||
/** |
|||
* authorization header |
|||
*/ |
|||
String AUTHORIZATION_HEADER = "authorization"; |
|||
/** |
|||
* APP用户标识 |
|||
*/ |
|||
String APP_USER_KEY = "appUserId"; |
|||
/** |
|||
* 移动端用户标识 |
|||
*/ |
|||
String APP_USER_FLAG = "APP_USER"; |
|||
/** |
|||
* 版本控制用 |
|||
*/ |
|||
String VERSION_CONTROL = "/{version}"; |
|||
/** |
|||
* 移动端接口标识 |
|||
*/ |
|||
String EPDC_APP = "epdc-app/"; |
|||
} |
|||
@ -1,54 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
|
|||
/** |
|||
* 常用字段常量 |
|||
* |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/8/20 10:11 |
|||
*/ |
|||
public interface FieldConstant { |
|||
|
|||
String ID = "ID"; |
|||
String ID_HUMP = "id"; |
|||
|
|||
String REVISION = "REVISION"; |
|||
String REVISION_HUMP = "revision"; |
|||
|
|||
String CREATED_BY = "CREATED_BY"; |
|||
String CREATED_BY_HUMP = "createdBy"; |
|||
|
|||
String CREATED_TIME = "CREATED_TIME"; |
|||
String CREATED_TIME_HUMP = "createdTime"; |
|||
|
|||
String UPDATED_BY = "UPDATED_BY"; |
|||
String UPDATED_BY_HUMP = "updatedBy"; |
|||
|
|||
String UPDATED_TIME = "UPDATED_TIME"; |
|||
String UPDATED_TIME_HUMP = "updatedTime"; |
|||
|
|||
String DEL_FLAG = "DEL_FLAG"; |
|||
String DEL_FLAG_HUMP = "delFlag"; |
|||
|
|||
String NAME = "NAME"; |
|||
String NAME_HUMP = "name"; |
|||
|
|||
String MOBILE = "MOBILE"; |
|||
String MOBILE_HUMP = "mobile"; |
|||
|
|||
String STATE = "STATE"; |
|||
String STATE_HUMP = "state"; |
|||
|
|||
String STREET_ID = "STREET_ID"; |
|||
String STREET_ID_HUMP = "streetId"; |
|||
|
|||
String COMMUNITY_ID = "COMMUNITY_ID"; |
|||
String COMMUNITY_ID_HUMP = "communityId"; |
|||
|
|||
String GRID_ID = "GRID_ID"; |
|||
String GRID_ID_HUMP = "gridId"; |
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* Nacos配置中心相关常量 |
|||
* |
|||
* @author rongchao |
|||
* @Date 20-1-15 |
|||
*/ |
|||
public interface NacosConfigConstant { |
|||
|
|||
String CONFIG_GROUP = "EPDC_CONFIG_GROUP"; |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* 常用数字常量 |
|||
* |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/8/19 10:28 |
|||
*/ |
|||
public interface NumConstant { |
|||
|
|||
int TWO_NEG = -2; |
|||
int ONE_NEG = -1; |
|||
int ZERO = 0; |
|||
int ONE = 1; |
|||
int TWO = 2; |
|||
int THREE = 3; |
|||
int FOUR = 4; |
|||
int SIX = 6; |
|||
int SEVEN = 7; |
|||
int EIGHT = 8; |
|||
int NINE = 9; |
|||
int TEN = 10; |
|||
int ELEVEN = 11; |
|||
int TWELVE = 12; |
|||
|
|||
int FIFTEEN = 15; |
|||
int TWENTY = 20; |
|||
int THIRTY = 30; |
|||
int FORTY = 40; |
|||
int FIFTY = 50; |
|||
int SIXTY = 60; |
|||
int ONE_HUNDRED = 100; |
|||
|
|||
long ZERO_L = 0L; |
|||
long ONE_L = 1L; |
|||
long TWO_L = 2L; |
|||
long THREE_L = 3L; |
|||
long FOUR_L = 4L; |
|||
|
|||
String ZERO_STR = "0"; |
|||
String ONE_STR = "1"; |
|||
String TWO_STR = "2"; |
|||
String THREE_STR = "3"; |
|||
String FOUR_STR = "4"; |
|||
String FIVE_STR = "5"; |
|||
|
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* 机构类型 |
|||
* @Author LC |
|||
* @Date 2019/9/16 10:30 |
|||
*/ |
|||
public interface OrganizationTypeConstant { |
|||
|
|||
/** |
|||
* 区党委 |
|||
*/ |
|||
String ORG_TYPE_DISTRICT_PARTY = "district_party"; |
|||
/** |
|||
* 区直部门 |
|||
*/ |
|||
String ORG_TYPE_DISTRICT_DEPT = "district_dept"; |
|||
/** |
|||
* 街道党工委 |
|||
*/ |
|||
String ORG_TYPE_STREET_PARTY = "street_party"; |
|||
/** |
|||
* 街道部门 |
|||
*/ |
|||
String ORG_TYPE_STREET_DEPT = "street_dept"; |
|||
/** |
|||
* 社区党工委 |
|||
*/ |
|||
String ORG_TYPE_COMMUNITY_PARTY = "community_party"; |
|||
/** |
|||
* 网格党支部 |
|||
*/ |
|||
String ORG_TYPE_GRID_PARTY = "grid_party"; |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* @Auther: yinzuomei |
|||
* @Date: 2019/12/16 19:38 |
|||
* @Description: 积分用 |
|||
*/ |
|||
public interface PointsConstant { |
|||
/** |
|||
* 手动调整积分编码 |
|||
*/ |
|||
String ruleCode ="hand_regulation"; |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* |
|||
* RocketMq 常量类 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2020/3/6 20:52 |
|||
*/ |
|||
public interface RocketMqConstant { |
|||
|
|||
/** |
|||
* 组织机构信息修改-消息topic |
|||
*/ |
|||
String MQ_TOPIC_ORGANIZATION = "organizationTopic"; |
|||
|
|||
/** |
|||
* 组织机构信息修改-消息tag |
|||
*/ |
|||
String MQ_TAG_ORGANIZATION = "organizationTag"; |
|||
|
|||
/** |
|||
* 分类信息修改-消息topic |
|||
*/ |
|||
String MQ_TOPIC_CATEGORY = "categoryTopic"; |
|||
|
|||
/** |
|||
* 分类信息修改-消息tag |
|||
*/ |
|||
String MQ_TAG_CATEGORY = "categoryTag"; |
|||
} |
|||
@ -1,111 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
/** |
|||
* 微服务名称常量 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface ServiceConstant { |
|||
/** |
|||
* 系统服务 |
|||
*/ |
|||
String EPDC_ADMIN_SERVER = "epdc-admin-server"; |
|||
/** |
|||
* 授权服务 |
|||
*/ |
|||
String EPDC_AUTH_SERVER = "epdc-auth-server"; |
|||
/** |
|||
* 路由 |
|||
*/ |
|||
String EPDC_GATEWAY_SERVER = "epdc-gateway-server"; |
|||
/** |
|||
* 任务模块 |
|||
*/ |
|||
String EPDC_JOB_SERVER = "epdc-job-server"; |
|||
/** |
|||
* 消息通知模块 |
|||
*/ |
|||
String EPDC_MESSAGE_SERVER = "epdc-message-server"; |
|||
/** |
|||
* 文件对象模块 |
|||
*/ |
|||
String EPDC_OSS_SERVER = "epdc-oss-server"; |
|||
/** |
|||
* 爱心互助模块 |
|||
*/ |
|||
String EPDC_HEART_SERVER = "epdc-heart-server"; |
|||
/** |
|||
* 友邻社群模块 |
|||
*/ |
|||
String EPDC_GROUP_SERVER = "epdc-group-server"; |
|||
/** |
|||
* 新闻公告模块 |
|||
*/ |
|||
String EPDC_NEWS_SERVER = "epdc-news-server"; |
|||
/** |
|||
* 党群议事模块 |
|||
*/ |
|||
String EPDC_EVENTS_SERVER = "epdc-events-server"; |
|||
/** |
|||
* 生活服务模块 |
|||
*/ |
|||
String EPDC_SERVICES_SERVER = "epdc-services-server"; |
|||
/** |
|||
* 移动端接口模块 |
|||
*/ |
|||
String EPDC_APP_SERVER = "epdc-app-server"; |
|||
/** |
|||
* APP用户模块 |
|||
*/ |
|||
String EPDC_USER_SERVER = "epdc-user-server"; |
|||
/** |
|||
* DEMO服务 |
|||
*/ |
|||
String EPDC_DEMO_SERVER = "epdc-demo-server"; |
|||
/** |
|||
* websocket服务 |
|||
*/ |
|||
String EPDC_WEBSOCKET_SERVER = "epdc-websocket-server"; |
|||
/** |
|||
* 绩效考核模块 |
|||
*/ |
|||
String EPDC_KPI_SERVER = "epdc-kpi-server"; |
|||
|
|||
/** |
|||
* 定制功能模块 |
|||
*/ |
|||
String EPDC_CUSTOM_SERVER = "epdc-custom-server"; |
|||
|
|||
/** |
|||
* 数据分析模块 |
|||
*/ |
|||
String EPDC_ANALYSIS_SERVER = "epdc-analysis-server"; |
|||
|
|||
/** |
|||
* 工作日志模块 |
|||
*/ |
|||
String EPDC_WORK_RECORD_SERVER = "epdc-work-record-server"; |
|||
/** |
|||
* 积分模块 |
|||
*/ |
|||
String EPDC_POINTS_SERVER = "epdc-points-server"; |
|||
|
|||
/** |
|||
* 开放接口模块 |
|||
*/ |
|||
String EPDC_API_SERVER = "epdc-api-server"; |
|||
|
|||
/** |
|||
* 数据分析模块 |
|||
*/ |
|||
String EPDC_CLOUD_ANALYSIS_SERVER = "epdc-cloud-analysis-server"; |
|||
} |
|||
@ -1,50 +0,0 @@ |
|||
package com.elink.esua.epdc.commons.tools.constant; |
|||
|
|||
import org.apache.commons.codec.CharEncoding; |
|||
import org.springframework.http.MediaType; |
|||
|
|||
|
|||
/** |
|||
* 字符串常量 |
|||
* |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/12/13 11:19 |
|||
*/ |
|||
public interface StrConstant { |
|||
|
|||
String UTF_8 = CharEncoding.UTF_8; |
|||
|
|||
String ISO_8859_1 = CharEncoding.ISO_8859_1; |
|||
|
|||
String JAVASCRIPT = "javascript"; |
|||
|
|||
String APPLICATION_JSON_UTF8_VALUE = MediaType.APPLICATION_JSON_UTF8_VALUE; |
|||
|
|||
String EXCEL_SUFFIX_2003 = ".xls"; |
|||
|
|||
String EXCEL_SUFFIX_2007 = ".xlsx"; |
|||
|
|||
/** |
|||
* 连字符号、短杠 |
|||
*/ |
|||
String HYPHEN = "-"; |
|||
|
|||
/** |
|||
* 英文逗号 |
|||
*/ |
|||
String COMMA = ","; |
|||
|
|||
/** |
|||
* 冒号 |
|||
*/ |
|||
String COLON = ":"; |
|||
|
|||
/** |
|||
* 问号 |
|||
*/ |
|||
String QUESTION_MARK = "?"; |
|||
/** |
|||
* 星号 |
|||
*/ |
|||
String ASTERISK = "*"; |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue