Showing
78 changed files
with
4077 additions
and
18 deletions
server/common-dao/src/main/java/com/fedex/connect/common/dao/log/UserLoginInfoMapper.java
0 → 100644
| 1 | +package com.fedex.connect.common.dao.log; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.log.UserLoginInfo; | ||
| 4 | +import com.fedex.connect.common.model.log.UserLoginInfoExample; | ||
| 5 | +import java.util.List; | ||
| 6 | +import org.apache.ibatis.annotations.Param; | ||
| 7 | + | ||
| 8 | +public interface UserLoginInfoMapper { | ||
| 9 | + long countByExample(UserLoginInfoExample example); | ||
| 10 | + | ||
| 11 | + int deleteByExample(UserLoginInfoExample example); | ||
| 12 | + | ||
| 13 | + int deleteByPrimaryKey(Long id); | ||
| 14 | + | ||
| 15 | + int insert(UserLoginInfo record); | ||
| 16 | + | ||
| 17 | + int insertSelective(UserLoginInfo record); | ||
| 18 | + | ||
| 19 | + List<UserLoginInfo> selectByExample(UserLoginInfoExample example); | ||
| 20 | + | ||
| 21 | + UserLoginInfo selectByPrimaryKey(Long id); | ||
| 22 | + | ||
| 23 | + int updateByExampleSelective(@Param("record") UserLoginInfo record, @Param("example") UserLoginInfoExample example); | ||
| 24 | + | ||
| 25 | + int updateByExample(@Param("record") UserLoginInfo record, @Param("example") UserLoginInfoExample example); | ||
| 26 | + | ||
| 27 | + int updateByPrimaryKeySelective(UserLoginInfo record); | ||
| 28 | + | ||
| 29 | + int updateByPrimaryKey(UserLoginInfo record); | ||
| 30 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
server/common-dao/src/main/java/com/fedex/connect/common/dao/log/package-info.java
deleted
100644 → 0
| 1 | -package com.fedex.connect.common.dao.log; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +package com.fedex.connect.common.dao.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 4 | +import com.fedex.connect.common.model.sys.RedisSlabExample; | ||
| 5 | +import org.apache.ibatis.annotations.Param; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +public interface RedisSlabMapper { | ||
| 10 | + long countByExample(RedisSlabExample example); | ||
| 11 | + | ||
| 12 | + int deleteByExample(RedisSlabExample example); | ||
| 13 | + | ||
| 14 | + int deleteByPrimaryKey(Long id); | ||
| 15 | + | ||
| 16 | + int insert(RedisSlab record); | ||
| 17 | + | ||
| 18 | + int insertSelective(RedisSlab record); | ||
| 19 | + | ||
| 20 | + List<RedisSlab> selectByExample(RedisSlabExample example); | ||
| 21 | + | ||
| 22 | + RedisSlab selectByPrimaryKey(Long id); | ||
| 23 | + | ||
| 24 | + int updateByExampleSelective(@Param("record") RedisSlab record, @Param("example") RedisSlabExample example); | ||
| 25 | + | ||
| 26 | + int updateByExample(@Param("record") RedisSlab record, @Param("example") RedisSlabExample example); | ||
| 27 | + | ||
| 28 | + int updateByPrimaryKeySelective(RedisSlab record); | ||
| 29 | + | ||
| 30 | + int updateByPrimaryKey(RedisSlab record); | ||
| 31 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
server/common-dao/src/main/java/com/fedex/connect/common/mapper/log/UserLoginInfoMapper.xml
0 → 100644
This diff is collapsed. Click to expand it.
server/common-dao/src/main/java/com/fedex/connect/common/mapper/log/package-info.java
deleted
100644 → 0
| 1 | -package com.fedex.connect.common.mapper.log; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
| 1 | +package com.fedex.connect.common.model.log; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.Date; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * DESC: 用户登录日志表 | ||
| 8 | + * TABLE: T_LOG_USER_LOGIN_INFO | ||
| 9 | + */ | ||
| 10 | +public class UserLoginInfo implements Serializable { | ||
| 11 | + /** | ||
| 12 | + * ID,主键自增 | ||
| 13 | + */ | ||
| 14 | + private Long id; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 操作人用户ID,关联用户表ID | ||
| 18 | + */ | ||
| 19 | + private Long userId; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 操作类型ID。 | ||
| 23 | +关联数据字典表。指定字典目录CODE:USER_LOGIN_TYPE | ||
| 24 | + */ | ||
| 25 | + private Long operTypeId; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 操作类型名称(登录、退出、修改密码、FCL登录注册,、停用、启用) | ||
| 29 | + */ | ||
| 30 | + private String operTypeName; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 操作描述 | ||
| 34 | + */ | ||
| 35 | + private String operDesc; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 操作IP | ||
| 39 | + */ | ||
| 40 | + private String ip; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 创建时间 | ||
| 44 | + */ | ||
| 45 | + private Date createTime; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 创建人ID,关联用户表ID | ||
| 49 | + */ | ||
| 50 | + private Long createUserId; | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 创建人名称 | ||
| 54 | + */ | ||
| 55 | + private String createUserName; | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 修改时间 | ||
| 59 | + */ | ||
| 60 | + private Date modifyTime; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 修改人ID,关联用户表ID | ||
| 64 | + */ | ||
| 65 | + private Long modifyUserId; | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 修改人名称 | ||
| 69 | + */ | ||
| 70 | + private String modifyUserName; | ||
| 71 | + | ||
| 72 | + private static final long serialVersionUID = 1L; | ||
| 73 | + | ||
| 74 | + public Long getId() { | ||
| 75 | + return id; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void setId(Long id) { | ||
| 79 | + this.id = id; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public Long getUserId() { | ||
| 83 | + return userId; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public void setUserId(Long userId) { | ||
| 87 | + this.userId = userId; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public Long getOperTypeId() { | ||
| 91 | + return operTypeId; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public void setOperTypeId(Long operTypeId) { | ||
| 95 | + this.operTypeId = operTypeId; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public String getOperTypeName() { | ||
| 99 | + return operTypeName; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public void setOperTypeName(String operTypeName) { | ||
| 103 | + this.operTypeName = operTypeName == null ? null : operTypeName.trim(); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public String getOperDesc() { | ||
| 107 | + return operDesc; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void setOperDesc(String operDesc) { | ||
| 111 | + this.operDesc = operDesc == null ? null : operDesc.trim(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public String getIp() { | ||
| 115 | + return ip; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public void setIp(String ip) { | ||
| 119 | + this.ip = ip == null ? null : ip.trim(); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public Date getCreateTime() { | ||
| 123 | + return createTime; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public void setCreateTime(Date createTime) { | ||
| 127 | + this.createTime = createTime; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public Long getCreateUserId() { | ||
| 131 | + return createUserId; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public void setCreateUserId(Long createUserId) { | ||
| 135 | + this.createUserId = createUserId; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public String getCreateUserName() { | ||
| 139 | + return createUserName; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public void setCreateUserName(String createUserName) { | ||
| 143 | + this.createUserName = createUserName == null ? null : createUserName.trim(); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public Date getModifyTime() { | ||
| 147 | + return modifyTime; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + public void setModifyTime(Date modifyTime) { | ||
| 151 | + this.modifyTime = modifyTime; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + public Long getModifyUserId() { | ||
| 155 | + return modifyUserId; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public void setModifyUserId(Long modifyUserId) { | ||
| 159 | + this.modifyUserId = modifyUserId; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + public String getModifyUserName() { | ||
| 163 | + return modifyUserName; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public void setModifyUserName(String modifyUserName) { | ||
| 167 | + this.modifyUserName = modifyUserName == null ? null : modifyUserName.trim(); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public String toString() { | ||
| 172 | + StringBuilder sb = new StringBuilder(); | ||
| 173 | + sb.append(getClass().getSimpleName()); | ||
| 174 | + sb.append(" ["); | ||
| 175 | + sb.append("Hash = ").append(hashCode()); | ||
| 176 | + sb.append(", id=").append(id); | ||
| 177 | + sb.append(", userId=").append(userId); | ||
| 178 | + sb.append(", operTypeId=").append(operTypeId); | ||
| 179 | + sb.append(", operTypeName=").append(operTypeName); | ||
| 180 | + sb.append(", operDesc=").append(operDesc); | ||
| 181 | + sb.append(", ip=").append(ip); | ||
| 182 | + sb.append(", createTime=").append(createTime); | ||
| 183 | + sb.append(", createUserId=").append(createUserId); | ||
| 184 | + sb.append(", createUserName=").append(createUserName); | ||
| 185 | + sb.append(", modifyTime=").append(modifyTime); | ||
| 186 | + sb.append(", modifyUserId=").append(modifyUserId); | ||
| 187 | + sb.append(", modifyUserName=").append(modifyUserName); | ||
| 188 | + sb.append(", serialVersionUID=").append(serialVersionUID); | ||
| 189 | + sb.append("]"); | ||
| 190 | + return sb.toString(); | ||
| 191 | + } | ||
| 192 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
server/common-dao/src/main/java/com/fedex/connect/common/model/log/UserLoginInfoExample.java
0 → 100644
This diff is collapsed. Click to expand it.
server/common-dao/src/main/java/com/fedex/connect/common/model/log/package-info.java
deleted
100644 → 0
| 1 | -package com.fedex.connect.common.model.log; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +package com.fedex.connect.common.model.sys; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.Date; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * DESC: 用户登录信息token表 | ||
| 8 | + * TABLE: T_SYS_REDIS_SLAB | ||
| 9 | + */ | ||
| 10 | +public class RedisSlab implements Serializable { | ||
| 11 | + /** | ||
| 12 | + * ID,自动增加 | ||
| 13 | + */ | ||
| 14 | + private Long id; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * Redis key | ||
| 18 | + */ | ||
| 19 | + private String redisKey; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * Redis信息 | ||
| 23 | + */ | ||
| 24 | + private String redisMsg; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 有效时长 | ||
| 28 | + */ | ||
| 29 | + private Long validDuration; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 失效时间 | ||
| 33 | + */ | ||
| 34 | + private Date disTime; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 创建时间 | ||
| 38 | + */ | ||
| 39 | + private Date createTime; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 创建人ID,关联用户表ID | ||
| 43 | + */ | ||
| 44 | + private Long createUserId; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 创建人名称 | ||
| 48 | + */ | ||
| 49 | + private String createUserName; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 修改时间 | ||
| 53 | + */ | ||
| 54 | + private Date modifyTime; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 修改人ID,关联用户表ID | ||
| 58 | + */ | ||
| 59 | + private Long modifyUserId; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 修改人名称 | ||
| 63 | + */ | ||
| 64 | + private String modifyUserName; | ||
| 65 | + | ||
| 66 | + private static final long serialVersionUID = 1L; | ||
| 67 | + | ||
| 68 | + public Long getId() { | ||
| 69 | + return id; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setId(Long id) { | ||
| 73 | + this.id = id; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public String getRedisKey() { | ||
| 77 | + return redisKey; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setRedisKey(String redisKey) { | ||
| 81 | + this.redisKey = redisKey == null ? null : redisKey.trim(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public String getRedisMsg() { | ||
| 85 | + return redisMsg; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setRedisMsg(String redisMsg) { | ||
| 89 | + this.redisMsg = redisMsg == null ? null : redisMsg.trim(); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public Long getValidDuration() { | ||
| 93 | + return validDuration; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setValidDuration(Long validDuration) { | ||
| 97 | + this.validDuration = validDuration; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public Date getDisTime() { | ||
| 101 | + return disTime; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setDisTime(Date disTime) { | ||
| 105 | + this.disTime = disTime; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public Date getCreateTime() { | ||
| 109 | + return createTime; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setCreateTime(Date createTime) { | ||
| 113 | + this.createTime = createTime; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public Long getCreateUserId() { | ||
| 117 | + return createUserId; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public void setCreateUserId(Long createUserId) { | ||
| 121 | + this.createUserId = createUserId; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public String getCreateUserName() { | ||
| 125 | + return createUserName; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setCreateUserName(String createUserName) { | ||
| 129 | + this.createUserName = createUserName == null ? null : createUserName.trim(); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public Date getModifyTime() { | ||
| 133 | + return modifyTime; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public void setModifyTime(Date modifyTime) { | ||
| 137 | + this.modifyTime = modifyTime; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public Long getModifyUserId() { | ||
| 141 | + return modifyUserId; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setModifyUserId(Long modifyUserId) { | ||
| 145 | + this.modifyUserId = modifyUserId; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public String getModifyUserName() { | ||
| 149 | + return modifyUserName; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setModifyUserName(String modifyUserName) { | ||
| 153 | + this.modifyUserName = modifyUserName == null ? null : modifyUserName.trim(); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public String toString() { | ||
| 158 | + StringBuilder sb = new StringBuilder(); | ||
| 159 | + sb.append(getClass().getSimpleName()); | ||
| 160 | + sb.append(" ["); | ||
| 161 | + sb.append("Hash = ").append(hashCode()); | ||
| 162 | + sb.append(", id=").append(id); | ||
| 163 | + sb.append(", redisKey=").append(redisKey); | ||
| 164 | + sb.append(", redisMsg=").append(redisMsg); | ||
| 165 | + sb.append(", validDuration=").append(validDuration); | ||
| 166 | + sb.append(", disTime=").append(disTime); | ||
| 167 | + sb.append(", createTime=").append(createTime); | ||
| 168 | + sb.append(", createUserId=").append(createUserId); | ||
| 169 | + sb.append(", createUserName=").append(createUserName); | ||
| 170 | + sb.append(", modifyTime=").append(modifyTime); | ||
| 171 | + sb.append(", modifyUserId=").append(modifyUserId); | ||
| 172 | + sb.append(", modifyUserName=").append(modifyUserName); | ||
| 173 | + sb.append(", serialVersionUID=").append(serialVersionUID); | ||
| 174 | + sb.append("]"); | ||
| 175 | + return sb.toString(); | ||
| 176 | + } | ||
| 177 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
| ... | @@ -40,7 +40,7 @@ | ... | @@ -40,7 +40,7 @@ |
| 40 | sys:系统 系统相关表,例如kafka表 | 40 | sys:系统 系统相关表,例如kafka表 |
| 41 | log: 日志 日志记录表,例如邮件发送日志表 | 41 | log: 日志 日志记录表,例如邮件发送日志表 |
| 42 | --> | 42 | --> |
| 43 | - <javaModelGenerator targetPackage="com.fedex.connect.common.model.base" targetProject="src/main/java"> | 43 | + <javaModelGenerator targetPackage="com.fedex.connect.common.model.sys" targetProject="src/main/java"> |
| 44 | <!---enableSubPackages:如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性--> | 44 | <!---enableSubPackages:如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性--> |
| 45 | <property name="enableSubPackages" value="false"/> | 45 | <property name="enableSubPackages" value="false"/> |
| 46 | <!--该属性只对MyBatis3有效,如果true就会使用构造方法入参,如果false就会使用setter方式。默认为false--> | 46 | <!--该属性只对MyBatis3有效,如果true就会使用构造方法入参,如果false就会使用setter方式。默认为false--> |
| ... | @@ -52,13 +52,13 @@ | ... | @@ -52,13 +52,13 @@ |
| 52 | </javaModelGenerator> | 52 | </javaModelGenerator> |
| 53 | 53 | ||
| 54 | <!-- 生成映射文件*.xml的位置--> | 54 | <!-- 生成映射文件*.xml的位置--> |
| 55 | - <sqlMapGenerator targetPackage="mapper.base" targetProject="src/main/java/com/fedex/connect/common"> | 55 | + <sqlMapGenerator targetPackage="mapper.sys" targetProject="src/main/java/com/fedex/connect/common"> |
| 56 | <!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false--> | 56 | <!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false--> |
| 57 | <property name="enableSubPackages" value="false"/> | 57 | <property name="enableSubPackages" value="false"/> |
| 58 | </sqlMapGenerator> | 58 | </sqlMapGenerator> |
| 59 | 59 | ||
| 60 | <!-- 生成DAO的包名和位置 --> | 60 | <!-- 生成DAO的包名和位置 --> |
| 61 | - <javaClientGenerator type="XMLMAPPER" targetPackage="com.fedex.connect.common.dao.base" targetProject="src/main/java"> | 61 | + <javaClientGenerator type="XMLMAPPER" targetPackage="com.fedex.connect.common.dao.sys" targetProject="src/main/java"> |
| 62 | <!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false--> | 62 | <!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false--> |
| 63 | <property name="enableSubPackages" value="false"/> | 63 | <property name="enableSubPackages" value="false"/> |
| 64 | </javaClientGenerator> | 64 | </javaClientGenerator> |
| ... | @@ -73,6 +73,13 @@ | ... | @@ -73,6 +73,13 @@ |
| 73 | generatedKey 指定KEY,Oracle需要指定序列。 | 73 | generatedKey 指定KEY,Oracle需要指定序列。 |
| 74 | sqlStatement 指定序列名称 | 74 | sqlStatement 指定序列名称 |
| 75 | --> | 75 | --> |
| 76 | + | ||
| 77 | + <table tableName="T_SYS_REDIS_SLAB" domainObjectName="redisSlab" | ||
| 78 | + enableCountByExample="true" enableUpdateByExample="true" | ||
| 79 | + enableDeleteByExample="true" enableSelectByExample="true" | ||
| 80 | + selectByExampleQueryId="true"> | ||
| 81 | + <generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_REDIS_SLAB.NEXTVAL FROM DUAL" /> | ||
| 82 | + </table> | ||
| 76 | <!-- <table tableName="T_KAFKA_TEMPORARY_STORAGE" domainObjectName="KafkaTemporaryStorage"--> | 83 | <!-- <table tableName="T_KAFKA_TEMPORARY_STORAGE" domainObjectName="KafkaTemporaryStorage"--> |
| 77 | <!-- enableCountByExample="true" enableUpdateByExample="true"--> | 84 | <!-- enableCountByExample="true" enableUpdateByExample="true"--> |
| 78 | <!-- enableDeleteByExample="true" enableSelectByExample="true"--> | 85 | <!-- enableDeleteByExample="true" enableSelectByExample="true"--> |
| ... | @@ -123,18 +130,18 @@ | ... | @@ -123,18 +130,18 @@ |
| 123 | <!-- </table>--> | 130 | <!-- </table>--> |
| 124 | 131 | ||
| 125 | 132 | ||
| 126 | - <table tableName="T_BI_DICTIONARY_ENTRIES" domainObjectName="DictionaryEntries" | 133 | +<!-- <table tableName="T_BI_DICTIONARY_ENTRIES" domainObjectName="DictionaryEntries"--> |
| 127 | - enableCountByExample="true" enableUpdateByExample="true" | 134 | +<!-- enableCountByExample="true" enableUpdateByExample="true"--> |
| 128 | - enableDeleteByExample="true" enableSelectByExample="true" | 135 | +<!-- enableDeleteByExample="true" enableSelectByExample="true"--> |
| 129 | - selectByExampleQueryId="true"> | 136 | +<!-- selectByExampleQueryId="true">--> |
| 130 | - <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BI_DICTIONARY_ENTRIES.NEXTVAL FROM DUAL" /> | 137 | +<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BI_DICTIONARY_ENTRIES.NEXTVAL FROM DUAL" />--> |
| 131 | - </table> | 138 | +<!-- </table>--> |
| 132 | - <table tableName="T_BI_DICTIONARY" domainObjectName="Dictionary" | 139 | +<!-- <table tableName="T_BI_DICTIONARY" domainObjectName="Dictionary"--> |
| 133 | - enableCountByExample="true" enableUpdateByExample="true" | 140 | +<!-- enableCountByExample="true" enableUpdateByExample="true"--> |
| 134 | - enableDeleteByExample="true" enableSelectByExample="true" | 141 | +<!-- enableDeleteByExample="true" enableSelectByExample="true"--> |
| 135 | - selectByExampleQueryId="true"> | 142 | +<!-- selectByExampleQueryId="true">--> |
| 136 | - <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BI_DICTIONARY.NEXTVAL FROM DUAL" /> | 143 | +<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BI_DICTIONARY.NEXTVAL FROM DUAL" />--> |
| 137 | - </table> | 144 | +<!-- </table>--> |
| 138 | 145 | ||
| 139 | 146 | ||
| 140 | <!-- <table tableName="T_TASK_MANAGEMENT" domainObjectName="TaskManagement"--> | 147 | <!-- <table tableName="T_TASK_MANAGEMENT" domainObjectName="TaskManagement"--> | ... | ... |
| 1 | +package com.fedex.connect.common.dependencies.arithmetic; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 密钥的长度 | ||
| 5 | + */ | ||
| 6 | +public enum AESType { | ||
| 7 | + AES_128(128), | ||
| 8 | + AES_192(192), | ||
| 9 | + AES_256(256); | ||
| 10 | + | ||
| 11 | + public int value; | ||
| 12 | + | ||
| 13 | + private AESType(int value) { | ||
| 14 | + this.value = value; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public int getValue() { | ||
| 18 | + return value; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setValue(int value) { | ||
| 22 | + this.value = value; | ||
| 23 | + } | ||
| 24 | +} |
This diff is collapsed. Click to expand it.
| 1 | +package com.fedex.connect.common.dependencies.arithmetic; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * | ||
| 5 | + */ | ||
| 6 | +public class EncodeType { | ||
| 7 | + /** | ||
| 8 | + 算法/模式/填充 字节加密后数据长度 不满16字节加密后长度 | ||
| 9 | + AES/CBC/NoPadding 16 不支持 | ||
| 10 | + AES/CBC/PKCS5Padding 32 16 | ||
| 11 | + AES/CBC/ISO10126Padding 32 16 | ||
| 12 | + AES/CFB/NoPadding 16 原始数据长度 | ||
| 13 | + AES/CFB/PKCS5Padding 32 16 | ||
| 14 | + AES/CFB/ISO10126Padding 32 16 | ||
| 15 | + AES/ECB/NoPadding 16 不支持 | ||
| 16 | + AES/ECB/PKCS5Padding 32 16 | ||
| 17 | + AES/ECB/ISO10126Padding 32 16 | ||
| 18 | + AES/OFB/NoPadding 16 原始数据长度 | ||
| 19 | + AES/OFB/PKCS5Padding 32 16 | ||
| 20 | + AES/OFB/ISO10126Padding 32 16 | ||
| 21 | + AES/PCBC/NoPadding 16 不支持 | ||
| 22 | + AES/PCBC/PKCS5Padding 32 16 | ||
| 23 | + AES/PCBC/ISO10126Padding 32 16 | ||
| 24 | + */ | ||
| 25 | + //默认为 AES_CBC_PKCS5PADDING | ||
| 26 | + public final static String AES_DEFAULT = "AES"; | ||
| 27 | + public final static String AES_CBC_NOPADDING = "AES/CBC/NoPadding"; | ||
| 28 | + public final static String AES_CBC_PKCS5PADDING = "AES/CBC/PKCS5Padding"; | ||
| 29 | + public final static String AES_CBC_ISO10126PADDING = "AES/CBC/ISO10126Padding"; | ||
| 30 | + public final static String AES_CFB_NOPADDING = "AES/CFB/NoPadding"; | ||
| 31 | + public final static String AES_CFB_PKCS5PADDING = "AES/CFB/PKCS5Padding"; | ||
| 32 | + public final static String AES_CFB_ISO10126PADDING = "AES/CFB/ISO10126Padding"; | ||
| 33 | + public final static String AES_ECB_NOPADDING = "AES/ECB/NoPadding"; | ||
| 34 | + public final static String AES_ECB_PKCS5PADDING = "AES/ECB/PKCS5Padding"; | ||
| 35 | + public final static String AES_ECB_ISO10126PADDING = "AES/ECB/ISO10126Padding"; | ||
| 36 | + public final static String AES_OFB_NOPADDING = "AES/OFB/NoPadding"; | ||
| 37 | + public final static String AES_OFB_PKCS5PADDING = "AES/OFB/PKCS5Padding"; | ||
| 38 | + public final static String AES_OFB_ISO10126PADDING = "AES/OFB/ISO10126Padding"; | ||
| 39 | + public final static String AES_PCBC_NOPADDING = "AES/PCBC/NoPadding"; | ||
| 40 | + public final static String AES_PCBC_PKCS5PADDING = "AES/PCBC/PKCS5Padding"; | ||
| 41 | + public final static String AES_PCBC_ISO10126PADDING = "AES/PCBC/ISO10126Padding"; | ||
| 42 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication; | ||
| 2 | + | ||
| 3 | +import org.springframework.security.crypto.password.PasswordEncoder; | ||
| 4 | +import org.springframework.security.crypto.password.StandardPasswordEncoder; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Administrator | ||
| 8 | + */ | ||
| 9 | +public class EncryptProvider { | ||
| 10 | + | ||
| 11 | + //加密密钥 | ||
| 12 | + private static final PasswordEncoder ENCODER = new StandardPasswordEncoder("exportTw"); | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * Spring-security-crypto加密方式 | ||
| 16 | + * | ||
| 17 | + * @param pwd 需要加密的密码 | ||
| 18 | + */ | ||
| 19 | + public static String encrypt(String pwd) { | ||
| 20 | + return ENCODER.encode(pwd); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 校验原密码和加密后的密码是否一致 | ||
| 25 | + * | ||
| 26 | + * @param pwd 原密码 | ||
| 27 | + * @param encodedPassword 加密后的密码 | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + public static boolean match(String pwd, String encodedPassword) { | ||
| 31 | + return ENCODER.matches(pwd, encodedPassword); | ||
| 32 | + } | ||
| 33 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication; | ||
| 2 | + | ||
| 3 | +import org.springframework.security.core.AuthenticationException; | ||
| 4 | +import org.springframework.security.web.authentication.AuthenticationFailureHandler; | ||
| 5 | +import org.springframework.security.web.util.UrlUtils; | ||
| 6 | +import org.springframework.util.Assert; | ||
| 7 | + | ||
| 8 | +import javax.servlet.ServletException; | ||
| 9 | +import javax.servlet.http.HttpServletRequest; | ||
| 10 | +import javax.servlet.http.HttpServletResponse; | ||
| 11 | +import java.io.IOException; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 登录失败处理器 | ||
| 16 | + * @author Administrator | ||
| 17 | + */ | ||
| 18 | +public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { | ||
| 19 | + private final String forwardUrl; | ||
| 20 | + | ||
| 21 | + public MyAuthenticationFailureHandler(String forwardUrl) { | ||
| 22 | + Assert.isTrue(UrlUtils.isValidRedirectUrl(forwardUrl), () -> { | ||
| 23 | + return "'" + forwardUrl + "' is not a valid forward URL"; | ||
| 24 | + }); | ||
| 25 | + this.forwardUrl = forwardUrl; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { | ||
| 30 | + request.setAttribute("SPRING_SECURITY_LAST_EXCEPTION", exception); | ||
| 31 | + response.sendRedirect(forwardUrl); | ||
| 32 | + } | ||
| 33 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication; | ||
| 2 | + | ||
| 3 | +import org.springframework.security.core.Authentication; | ||
| 4 | +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; | ||
| 5 | + | ||
| 6 | +import javax.servlet.ServletException; | ||
| 7 | +import javax.servlet.http.HttpServletRequest; | ||
| 8 | +import javax.servlet.http.HttpServletResponse; | ||
| 9 | +import java.io.IOException; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 自定义认证成功处理器 | ||
| 13 | + * @author Administrator | ||
| 14 | + */ | ||
| 15 | +public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler { | ||
| 16 | + | ||
| 17 | + private final String forwardUrl; | ||
| 18 | + | ||
| 19 | + public MyAuthenticationSuccessHandler(String forwardUrl) { | ||
| 20 | + this.forwardUrl = forwardUrl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { | ||
| 25 | + httpServletResponse.sendRedirect(forwardUrl); | ||
| 26 | + } | ||
| 27 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 读取配置文件 | ||
| 8 | + * @author Administrator | ||
| 9 | + */ | ||
| 10 | +@ConfigurationProperties(prefix = "export.jwt") | ||
| 11 | +public class SecurityConstants { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 定义鉴权使用常量 | ||
| 15 | + */ | ||
| 16 | + public static final String TOKEN_HEADER = "Authorization"; | ||
| 17 | + | ||
| 18 | + public static final String REFLUSH_TOKEN= "ReflushToken"; | ||
| 19 | + | ||
| 20 | + public static final String TOKEN_PREFIX = "Bearer "; | ||
| 21 | + | ||
| 22 | + public static final String TOKEN_TYPE = "JWT"; | ||
| 23 | + | ||
| 24 | + public static final String ROLE_CLAIMS = "rol"; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public static long expire_1H; | ||
| 28 | + | ||
| 29 | + public static long expire_1D; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * JWT 的 秘钥 | ||
| 33 | + */ | ||
| 34 | + public static String securitykey; | ||
| 35 | + | ||
| 36 | + public static String[] urlWhiteList; | ||
| 37 | + public static String[] uriWhiteList; | ||
| 38 | + | ||
| 39 | + public static long getExpire_1H() { | ||
| 40 | + return expire_1H; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setExpire_1H(long expire_1H) { | ||
| 44 | + SecurityConstants.expire_1H = expire_1H; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static long getExpire_1D() { | ||
| 48 | + return expire_1D; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setExpire_1D(long expire_1D) { | ||
| 52 | + SecurityConstants.expire_1D = expire_1D; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static String getSecuritykey() { | ||
| 56 | + return securitykey; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setSecuritykey(String securitykey) { | ||
| 60 | + SecurityConstants.securitykey = securitykey; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static String[] getUrlWhiteList() { | ||
| 64 | + return urlWhiteList; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setUrlWhiteList(String[] urlWhiteList) { | ||
| 68 | + SecurityConstants.urlWhiteList = urlWhiteList; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public static String[] getUriWhiteList() { | ||
| 72 | + return uriWhiteList; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setUriWhiteList(String[] uriWhiteList) { | ||
| 76 | + SecurityConstants.uriWhiteList = uriWhiteList; | ||
| 77 | + } | ||
| 78 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication; | ||
| 2 | + | ||
| 3 | +import com.fedex.export.authentication.exception.JwtAccessDeniedHandler; | ||
| 4 | +import com.fedex.export.authentication.exception.JwtAuthenticationEntryPoint; | ||
| 5 | +import com.fedex.export.authentication.filter.JwtAuthorizationFilter; | ||
| 6 | +import org.springframework.context.annotation.Bean; | ||
| 7 | +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
| 8 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| 9 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| 10 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| 11 | +import org.springframework.security.config.http.SessionCreationPolicy; | ||
| 12 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * Spring-Security 配置 | ||
| 17 | + * @author Administrator | ||
| 18 | + */ | ||
| 19 | +@EnableWebSecurity | ||
| 20 | +@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
| 21 | +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 配置安全过滤器 | ||
| 25 | + * @param http | ||
| 26 | + * @throws Exception | ||
| 27 | + */ | ||
| 28 | + @Override | ||
| 29 | + protected void configure(HttpSecurity http) throws Exception { | ||
| 30 | + //放行白名单(这个配置会比读取配置文件优先进行,别问我怎么知道的) | ||
| 31 | + String[] whiteList = {"/icleartw/login.html","/icleartw/auth/login","/icleartw/auth/addUser", | ||
| 32 | + "/icleartw/oss/ossLogin", "/icleartw/sysUser/logout","/icleartw/auth/getUser","/icleartw/static/*", | ||
| 33 | + "/icleartw/swagger-ui.html","/icleartw/swagger-resources","/icleartw/webjars","/icleartw/swagger-ui/*", "/icleartw/v2/api-docs","/**"}; | ||
| 34 | + | ||
| 35 | + //formLogin配置登录页面和成功/失败的响应 | ||
| 36 | + http.formLogin() | ||
| 37 | + .loginPage("/icleartw/login.html").permitAll() | ||
| 38 | + //.successHandler(new MyAuthenticationSuccessHandler("/main")) | ||
| 39 | + //.failureHandler(new MyAuthenticationFailureHandler("/403.html")) | ||
| 40 | + .and() | ||
| 41 | + //authorizeRequests方法配置访问控制规则 | ||
| 42 | + .authorizeRequests() | ||
| 43 | + .antMatchers(whiteList).permitAll() | ||
| 44 | + .anyRequest().authenticated() //其他未定义的 URL 需要进行身份认证才能访问 | ||
| 45 | + //添加JWT | ||
| 46 | + .and() | ||
| 47 | + //配置过滤器 | ||
| 48 | + .addFilter(new JwtAuthorizationFilter(super.authenticationManager())) | ||
| 49 | + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) //禁用Session | ||
| 50 | + .and().exceptionHandling() | ||
| 51 | + .authenticationEntryPoint(new JwtAuthenticationEntryPoint()) //拒绝访问处理 | ||
| 52 | + .accessDeniedHandler(new JwtAccessDeniedHandler()) //无权访问处理 | ||
| 53 | + .and().logout().permitAll() | ||
| 54 | + .and().csrf().disable(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + @Bean | ||
| 59 | + public BCryptPasswordEncoder bCryptPasswordEncoder() { | ||
| 60 | + //添加BC加密算法 | ||
| 61 | + return new BCryptPasswordEncoder(); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication.exception; | ||
| 2 | + | ||
| 3 | +import com.fedex.export.common.i18n.LocaleMessageUtil; | ||
| 4 | +import com.fedex.export.common.util.SpringBeanUtil; | ||
| 5 | +import com.fedex.export.data.vo.JsonResult; | ||
| 6 | +import com.google.gson.Gson; | ||
| 7 | +import org.springframework.security.access.AccessDeniedException; | ||
| 8 | +import org.springframework.security.web.access.AccessDeniedHandler; | ||
| 9 | + | ||
| 10 | +import javax.servlet.http.HttpServletRequest; | ||
| 11 | +import javax.servlet.http.HttpServletResponse; | ||
| 12 | +import java.io.IOException; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @author Administrator | ||
| 16 | + * | ||
| 17 | + */ | ||
| 18 | +public class JwtAccessDeniedHandler implements AccessDeniedHandler { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 没有访问权限:当用户通过认证,但没有足够的权限对指定资源操作,返回403 | ||
| 22 | + */ | ||
| 23 | + @Override | ||
| 24 | + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException { | ||
| 25 | + response.setCharacterEncoding("UTF-8"); | ||
| 26 | + response.setContentType("application/json"); | ||
| 27 | + JsonResult result = new JsonResult(); | ||
| 28 | + result.setCode(HttpServletResponse.SC_FORBIDDEN); | ||
| 29 | + //使用context手动注入 | ||
| 30 | + LocaleMessageUtil localeMessageUtil = SpringBeanUtil.getBean(LocaleMessageUtil.class); | ||
| 31 | + result.setMsg(localeMessageUtil.getMessage("auth_exc_no_auth")); | ||
| 32 | + Gson gson = new Gson(); | ||
| 33 | + response.getWriter().println(gson.toJson(result)); | ||
| 34 | + response.getWriter().flush(); | ||
| 35 | + } | ||
| 36 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication.exception; | ||
| 2 | + | ||
| 3 | +import com.fedex.export.common.i18n.LocaleMessageUtil; | ||
| 4 | +import com.fedex.export.common.util.SpringBeanUtil; | ||
| 5 | +import com.fedex.export.data.vo.JsonResult; | ||
| 6 | +import com.google.gson.Gson; | ||
| 7 | +import org.springframework.security.core.AuthenticationException; | ||
| 8 | +import org.springframework.security.web.AuthenticationEntryPoint; | ||
| 9 | + | ||
| 10 | +import javax.servlet.http.HttpServletRequest; | ||
| 11 | +import javax.servlet.http.HttpServletResponse; | ||
| 12 | +import java.io.IOException; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 拒绝访问:当用户没有通过认证,返回401 | ||
| 17 | + * @author Administrator | ||
| 18 | + */ | ||
| 19 | +public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public void commence(HttpServletRequest request, | ||
| 23 | + HttpServletResponse response, | ||
| 24 | + AuthenticationException authException) throws IOException { | ||
| 25 | + | ||
| 26 | + response.setCharacterEncoding("UTF-8"); | ||
| 27 | + response.setContentType("application/json"); | ||
| 28 | + JsonResult result = new JsonResult(); | ||
| 29 | + result.setCode(HttpServletResponse.SC_UNAUTHORIZED); | ||
| 30 | + //使用context手动注入 | ||
| 31 | + LocaleMessageUtil localeMessageUtil = SpringBeanUtil.getBean(LocaleMessageUtil.class); | ||
| 32 | + result.setMsg(localeMessageUtil.getMessage("auth_exc_no_pass_auth")); | ||
| 33 | + Gson gson = new Gson(); | ||
| 34 | + response.getWriter().println(gson.toJson(result)); | ||
| 35 | + response.getWriter().flush(); | ||
| 36 | + | ||
| 37 | + } | ||
| 38 | +} |
| 1 | +package com.fedex.connect.common.dependencies.authentication.filter; | ||
| 2 | + | ||
| 3 | +import com.fedex.export.authentication.SecurityConstants; | ||
| 4 | +import com.fedex.export.common.contants.RedisConstants; | ||
| 5 | +import com.fedex.export.common.i18n.LocaleMessageUtil; | ||
| 6 | +import com.fedex.export.common.util.JsonUtils; | ||
| 7 | +import com.fedex.export.common.util.JwtTokenUtils; | ||
| 8 | +import com.fedex.export.common.util.SpringBeanUtil; | ||
| 9 | +import com.fedex.export.common.util.Utils; | ||
| 10 | +import com.fedex.export.repository.entity.RedisSlab; | ||
| 11 | +import com.fedex.export.service.system.RedisUtilService; | ||
| 12 | +import io.jsonwebtoken.Claims; | ||
| 13 | +import io.jsonwebtoken.ExpiredJwtException; | ||
| 14 | +import org.apache.commons.lang3.StringUtils; | ||
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 17 | +import org.springframework.security.authentication.AuthenticationManager; | ||
| 18 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| 19 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 20 | +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; | ||
| 21 | + | ||
| 22 | +import javax.servlet.FilterChain; | ||
| 23 | +import javax.servlet.ServletException; | ||
| 24 | +import javax.servlet.ServletOutputStream; | ||
| 25 | +import javax.servlet.http.HttpServletRequest; | ||
| 26 | +import javax.servlet.http.HttpServletResponse; | ||
| 27 | +import java.io.IOException; | ||
| 28 | +import java.util.*; | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Spring Security实际 上是基于Filter实现的 | ||
| 33 | + * 写一个过滤器,继承BasicAuthenticationFilter | ||
| 34 | + * @author EDY | ||
| 35 | + */ | ||
| 36 | +public class JwtAuthorizationFilter extends BasicAuthenticationFilter { | ||
| 37 | + | ||
| 38 | + private Logger logger = LoggerFactory.getLogger(JwtAuthorizationFilter.class); | ||
| 39 | + | ||
| 40 | + public JwtAuthorizationFilter(AuthenticationManager authenticationManager) { | ||
| 41 | + super(authenticationManager); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + protected void doFilterInternal(HttpServletRequest request, | ||
| 46 | + HttpServletResponse response, | ||
| 47 | + FilterChain chain) throws IOException, ServletException { | ||
| 48 | + | ||
| 49 | + String token = request.getHeader(SecurityConstants.TOKEN_HEADER); | ||
| 50 | + response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); | ||
| 51 | + response.setHeader("Access-Control-Allow-Credentials", "true"); | ||
| 52 | + response.setHeader("Access-Control-Allow-Methods", "POST"); | ||
| 53 | + response.setHeader("Access-Control-Max-Age", "3600"); | ||
| 54 | + response.setHeader("Access-Control-Allow-Headers", "x-requested-with, authorization, Content-Type, Authorization, credential, X-XSRF-TOKEN,Token,userName,client,OBLIX_UID"); | ||
| 55 | + response.setHeader("Access-Control-Expose-Headers", "Token"); | ||
| 56 | + | ||
| 57 | + //放行白名单 | ||
| 58 | + List<String> urlWhiteList = Arrays.asList(SecurityConstants.urlWhiteList); | ||
| 59 | + List<String> uriWhiteList = Arrays.asList(SecurityConstants.uriWhiteList); | ||
| 60 | + | ||
| 61 | + //返回请求行中的资源名部分 | ||
| 62 | + String requestUri = request.getRequestURI(); | ||
| 63 | + //返回客户端发出请求完整URL | ||
| 64 | + String reqeustUrl = request.getRequestURL().toString(); | ||
| 65 | + logger.info("------------- FROM NETWORK :{}", requestUri); | ||
| 66 | + if (reqeustUrl.indexOf("/sysUser/logout") > 0) { | ||
| 67 | + //退出登录接口,不验token | ||
| 68 | + chain.doFilter(request, response); | ||
| 69 | + return; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + //使用context手动注入 | ||
| 73 | + LocaleMessageUtil localeMessageUtil = SpringBeanUtil.getBean(LocaleMessageUtil.class); | ||
| 74 | + RedisUtilService redisUtilService = SpringBeanUtil.getBean(RedisUtilService.class); | ||
| 75 | + | ||
| 76 | + if (token == null || !token.startsWith(SecurityConstants.TOKEN_PREFIX)) { | ||
| 77 | + SecurityContextHolder.clearContext(); | ||
| 78 | + | ||
| 79 | + if(Utils.listOf(urlWhiteList).stream().filter(Objects::nonNull).anyMatch(urlW -> reqeustUrl.indexOf(urlW) > 0) | ||
| 80 | + || Utils.listOf(uriWhiteList).stream().filter(Objects::nonNull).anyMatch(uriW -> requestUri.equals(uriW)) | ||
| 81 | + || Utils.listOf(uriWhiteList).stream().filter(Objects::nonNull).filter(u -> u.indexOf("*") > 0).anyMatch(uriW -> requestUri.startsWith(uriW.replace("*",""))) | ||
| 82 | + || "/".equals(requestUri) | ||
| 83 | + || "OPTIONS".equals(request.getMethod())){ | ||
| 84 | + logger.info("--------------- 登录白名单无需验证"); | ||
| 85 | + chain.doFilter(request, response); | ||
| 86 | + return; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + Map<String, Object> result = new HashMap<>(); | ||
| 90 | + result.put("code", 301); | ||
| 91 | + result.put("msg", localeMessageUtil.getMessage("auth_filter_user_error")); | ||
| 92 | + logger.info("CODE_301 requestURL:{} ,reason:{}" , request.getRequestURL()," 非白名单url路径登录"); | ||
| 93 | + ServletOutputStream out = response.getOutputStream(); | ||
| 94 | + out.write(JsonUtils.mapToJson(result).getBytes()); | ||
| 95 | + out.flush(); | ||
| 96 | + return; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + UsernamePasswordAuthenticationToken authentication = null; | ||
| 100 | + //判断accessToken是否过期 | ||
| 101 | + String tokenValue = token.replace(SecurityConstants.TOKEN_PREFIX, ""); | ||
| 102 | + | ||
| 103 | + try { | ||
| 104 | + Date expiredTime = JwtTokenUtils.getAccessTokenExpiredTime(tokenValue); | ||
| 105 | + logger.debug("TOKEN 过期时间为 :{}", expiredTime); | ||
| 106 | + String id = JwtTokenUtils.getId(tokenValue); | ||
| 107 | + String redisKey = RedisConstants.REDIS_KEY_TOKEN + id; | ||
| 108 | + RedisSlab redisSlab = redisUtilService.get(redisKey); | ||
| 109 | + String tokenRedis = redisSlab != null ? Optional.ofNullable(redisSlab.getRedisMsg()).orElse(null): null; | ||
| 110 | + /*String tokenRedis = redisUtilService.get(redisKey);*/ | ||
| 111 | + if (StringUtils.isEmpty(tokenRedis)) { | ||
| 112 | + //redis没有,超过8小时,踢出去 | ||
| 113 | + Map<String, Object> result = new HashMap<>(); | ||
| 114 | + result.put("code", 301); | ||
| 115 | + result.put("msg", localeMessageUtil.getMessage("auth_filter_timeout")); | ||
| 116 | + logger.info("CODE_301 requestURL:{} ,reason:{}" , request.getRequestURL() ,"tokenRedis is empty"); | ||
| 117 | + ServletOutputStream out = response.getOutputStream(); | ||
| 118 | + out.write(JsonUtils.mapToJson(result).getBytes()); | ||
| 119 | + out.flush(); | ||
| 120 | + return; | ||
| 121 | + } | ||
| 122 | + /*//更新token | ||
| 123 | + String tokenRedisValue = tokenRedis.replace(SecurityConstants.TOKEN_PREFIX, ""); | ||
| 124 | + String userName = JwtTokenUtils.getUserName(tokenRedisValue); | ||
| 125 | + List<String> role = JwtTokenUtils.getRoleList(tokenRedisValue); | ||
| 126 | + //返回前端的新token | ||
| 127 | + String newToken = JwtTokenUtils.createReflushToken(userName, id, role); | ||
| 128 | + logger.info("REFRESH TOKEN "); | ||
| 129 | + response.setHeader("Token", newToken);*/ | ||
| 130 | + } catch (ExpiredJwtException ee) { | ||
| 131 | + //已经过期了,直接踢 | ||
| 132 | + logger.info("CODE_301 requestURL:{},reason:{}" , request.getRequestURL(),"ExpiredJwtException ",ee); | ||
| 133 | + Claims claims = ee.getClaims(); | ||
| 134 | + String id = claims.getId(); | ||
| 135 | + Map<String, Object> result = new HashMap<>(); | ||
| 136 | + result.put("code", 301); | ||
| 137 | + result.put("msg", localeMessageUtil.getMessage("auth_filter_stale_dated")); | ||
| 138 | + ServletOutputStream out = response.getOutputStream(); | ||
| 139 | + out.write(JsonUtils.mapToJson(result).getBytes()); | ||
| 140 | + out.flush(); | ||
| 141 | + return; | ||
| 142 | + } catch (Exception e) { | ||
| 143 | + logger.error("*********************token 异常 : *******************************", e); | ||
| 144 | + Map<String, Object> result = new HashMap<>(); | ||
| 145 | + result.put("code", 301); | ||
| 146 | + result.put("msg", localeMessageUtil.getMessage("auth_filter_user_error")); | ||
| 147 | + ServletOutputStream out = response.getOutputStream(); | ||
| 148 | + out.write(JsonUtils.mapToJson(result).getBytes()); | ||
| 149 | + out.flush(); | ||
| 150 | + return; | ||
| 151 | + } | ||
| 152 | + authentication = JwtTokenUtils.getAuthentication(tokenValue); | ||
| 153 | + SecurityContextHolder.getContext().setAuthentication(authentication); | ||
| 154 | + chain.doFilter(request, response); | ||
| 155 | + return; | ||
| 156 | + } | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | + |
| 1 | +package com.fedex.connect.common.dependencies.config; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 5 | +import com.fedex.connect.common.dependencies.util.Utils; | ||
| 6 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | +import org.slf4j.LoggerFactory; | ||
| 9 | +import org.springframework.boot.CommandLineRunner; | ||
| 10 | +import org.springframework.core.annotation.Order; | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | +import org.springframework.util.CollectionUtils; | ||
| 13 | + | ||
| 14 | +import java.util.*; | ||
| 15 | +import java.util.stream.Collectors; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 预先数据的加载 | ||
| 19 | + * 有兴趣了解搜索:CommandLineRunner详解 | ||
| 20 | + * @author EDY | ||
| 21 | + */ | ||
| 22 | +@Component | ||
| 23 | +@Order(1) | ||
| 24 | +public class CacheSystem implements CommandLineRunner { | ||
| 25 | + | ||
| 26 | + private static final Logger log = LoggerFactory.getLogger(CacheSystem.class); | ||
| 27 | + | ||
| 28 | + // 从 DictionaryProvider 获取字典数据 | ||
| 29 | + List<DictionaryEntries> dictionaryData = DictionaryProvider.getDictionaryData(); | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + // 静态缓存数据 | ||
| 33 | + public static List<DictionaryEntries> dictionaryListAll = new ArrayList<>(); | ||
| 34 | + public static Map<String, List<DictionaryEntries>> dictionaryMap = new HashMap<>(); | ||
| 35 | + public static Map<String, String> declarationTypeMap = new HashMap<>(); | ||
| 36 | + public static Map<String, String> deliveryStatusMap = new HashMap<>(); | ||
| 37 | + public static Map<String, String> operStatusMap = new HashMap<>(); | ||
| 38 | + public static List<DictionaryEntries> currencyCdList = new ArrayList<>(); | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void run(String... args) { | ||
| 42 | + if (dictionaryData == null) { | ||
| 43 | + log.warn("SysDictionaryService not set, skipping cache initialization."); | ||
| 44 | + return; | ||
| 45 | + } | ||
| 46 | + log.info("System init load to cache in memory start"); | ||
| 47 | + try{ | ||
| 48 | + CacheSystem.dictionaryListAll = dictionaryData; | ||
| 49 | + if (CollectionUtils.isEmpty(CacheSystem.dictionaryListAll)){ | ||
| 50 | + return; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + CacheSystem.dictionaryMap = Utils.listOf(CacheSystem.dictionaryListAll).stream().filter(Objects::nonNull) | ||
| 54 | + .collect(Collectors.groupingBy(DictionaryEntries::getDictCode)); | ||
| 55 | + | ||
| 56 | + List<DictionaryEntries> declarationTypeList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_CUSTOMS_DECLARATION_TYPE_CODE); | ||
| 57 | + CacheSystem.declarationTypeMap = Utils.listOf(declarationTypeList).stream() | ||
| 58 | + .collect(Collectors.toMap(DictionaryEntries::getCode, DictionaryEntries::getEnglishName)); | ||
| 59 | + | ||
| 60 | + List<DictionaryEntries> deliveryStatusList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_DELIVERY_STATUS_CODE); | ||
| 61 | + CacheSystem.deliveryStatusMap = Utils.listOf(deliveryStatusList).stream() | ||
| 62 | + .collect(Collectors.toMap(DictionaryEntries::getCode, DictionaryEntries::getEnglishName)); | ||
| 63 | + | ||
| 64 | + List<DictionaryEntries> operStatusList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_OPER_STATUS_CODE); | ||
| 65 | + CacheSystem.operStatusMap = Utils.listOf(operStatusList).stream() | ||
| 66 | + .collect(Collectors.toMap(DictionaryEntries::getCode, DictionaryEntries::getEnglishName)); | ||
| 67 | + | ||
| 68 | + CacheSystem.currencyCdList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_CURRENCY_CD_CODE); | ||
| 69 | + } catch (Exception e){ | ||
| 70 | + log.error("load cache error:{}",e); | ||
| 71 | + } log.info("System init load to cache in memory end"); | ||
| 72 | + } | ||
| 73 | +} | ||
| 74 | + |
| 1 | +package com.fedex.connect.common.dependencies.config; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 4 | + | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +public class DictionaryProvider { | ||
| 8 | + // 用于存储字典数据的静态列表 | ||
| 9 | + private static List<DictionaryEntries> dictionaryData; | ||
| 10 | + | ||
| 11 | + // 设置字典数据的方法 | ||
| 12 | + public static void setDictionaryData(List<DictionaryEntries> data) { | ||
| 13 | + dictionaryData = data; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + // 获取字典数据的方法 | ||
| 17 | + public static List<DictionaryEntries> getDictionaryData() { | ||
| 18 | + return dictionaryData; | ||
| 19 | + } | ||
| 20 | +} |
| 1 | +package com.fedex.connect.common.dependencies.contants; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * 定义数据库同样常量 | ||
| 6 | + */ | ||
| 7 | +public class DatabaseConstants { | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * 定义通用状态常量。 | ||
| 11 | + * 1:有效[true]。0:无效[false] | ||
| 12 | + */ | ||
| 13 | + public static final Long GLOBAL_STATUS_VALID = 1L; | ||
| 14 | + public static final Long GLOBAL_STATUS_DEL = 0L; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 定义操作状态常量 | ||
| 18 | + * 1: 已提交 2:正在录入 | ||
| 19 | + */ | ||
| 20 | + public static final Long GLOBAL_OPER_STATUS_SAVE = 1L; | ||
| 21 | + public static final Long GLOBAL_OPER_STATUS_DRAFT = 2L; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 定义申报信息提单状态 | ||
| 25 | + * 0:未发送 (冗余) | ||
| 26 | + * 1:已发送(异步成功状态) | ||
| 27 | + * 2:已接收。(回执成功状态) | ||
| 28 | + * 3:发送失败。(提交后异步发送失败状态。定时任务补偿机制读取此状态数据) | ||
| 29 | + * 4:接收失败。 | ||
| 30 | + * (4-1:3次重发邮件都失败。 | ||
| 31 | + * 4-2:回执3次重试读取仍失败为此状态。 | ||
| 32 | + * 4-3:超过1小时为此状态。 | ||
| 33 | + * 4-4:3次匹配不到为此状态。 | ||
| 34 | + * 4-5:其他失败) | ||
| 35 | + */ | ||
| 36 | + public static final Long DELIVERY_STATUS_UNSENT = 0L; | ||
| 37 | + public static final Long DELIVERY_STATUS_SENT = 1L; | ||
| 38 | + public static final Long DELIVERY_STATUS_RECEIVE = 2L; | ||
| 39 | + public static final Long DELIVERY_STATUS_SENT_FAIL = 3L; | ||
| 40 | + public static final Long DELIVERY_STATUS_RECEIVE_FAIL = 4L; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 定义文件来源常量 | ||
| 44 | + * 1:上传。2:系统生成。3:图案商标 | ||
| 45 | + */ | ||
| 46 | + public static final Long FILE_SOURCE_UPDATE = 1L; | ||
| 47 | + public static final Long FILE_SOURCE_SYS_CREATE = 2L; | ||
| 48 | + public static final Long FILE_SOURCE_SYS_BRAND = 3L; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 定义信息录入状态 | ||
| 52 | + * 1:已校验过数据。2:数据未校验 | ||
| 53 | + */ | ||
| 54 | + public static final Long DECLARE_CHECK = 1L; | ||
| 55 | + public static final Long DECLARE_SAVE = 2L; | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 定义邮件发送状态 | ||
| 59 | + * (0:未发送。1:发送成功。2:发送失败) | ||
| 60 | + */ | ||
| 61 | + public static final Long MAIL_SEND_UNSENT = 0L; | ||
| 62 | + public static final Long MAIL_SEND_SUCC = 1L; | ||
| 63 | + public static final Long MAIL_SEND_FAIL = 2L; | ||
| 64 | + | ||
| 65 | + public static final Long USER_SOURCE_TW = 1L; | ||
| 66 | + public static final Long USER_SOURCE_FCL = 2L; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 定义用户操作类型常量 | ||
| 70 | + * 1:登录 2:退出 3:修改密码4:FCL登录注册。5:停用,6:启用 | ||
| 71 | + */ | ||
| 72 | + public static final Long USER_OPER_LOGIN = 1L; | ||
| 73 | + public static final Long USER_OPER_LOGOUT = 2L; | ||
| 74 | + public static final Long USER_OPER_UPD_PWD = 3L; | ||
| 75 | + public static final Long USER_OPER_FCL_REGISTER = 4L; | ||
| 76 | + public static final Long USER_OPER_STOP = 5L; | ||
| 77 | + public static final Long USER_OPER_INIT = 6L; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 定义申报信息文件生成选择常量 | ||
| 81 | + * 1: 立即制作 2:使用已制作 | ||
| 82 | + */ | ||
| 83 | + public static final Long FILE_SELECT_MAKE = 1L; | ||
| 84 | + public static final Long FILE_SELECT_EXISTS = 2L; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 菜单类型 | ||
| 88 | + * M:主菜单 C:分支菜单 B:按钮 | ||
| 89 | + */ | ||
| 90 | + public static final String SYS_MENU_TYPE_MAIN = "M"; | ||
| 91 | + public static final String SYS_MENU_TYPE_BRANCH = "C"; | ||
| 92 | + public static final String SYS_MENU_TYPE_BUTTON = "B"; | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 用户类型 | ||
| 96 | + * 在线申报平台账号 | ||
| 97 | + */ | ||
| 98 | + public static final String DICT_USER_GOOUP_CODE = "user_type"; | ||
| 99 | + public static final String DICT_USER_DEFAULT_CODE = "default"; | ||
| 100 | + public static final String DICT_USER_FEDEX_CODE = "fedex"; | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 角色类型 | ||
| 104 | + * admin | ||
| 105 | + */ | ||
| 106 | + public static final String DICT_ROLE_GOOUP_CODE = "role_type"; | ||
| 107 | + public static final String DICT_ROLE_DEFAULT_CODE = "admin"; | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * 报关类别 | ||
| 111 | + */ | ||
| 112 | + public static final String DICT_CUSTOMS_DECLARATION_TYPE_CODE = "customs_declaration_type"; | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 报关类别 -> 其它 | ||
| 116 | + */ | ||
| 117 | + public static final String DICT_CUSTOMS_DECLARATION_TYPE_CODE_OTHER = "OTHER"; | ||
| 118 | + | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 出口统计方式 | ||
| 122 | + */ | ||
| 123 | + public static final String DICT_EXPORT_STATISTICS_METHOD_CODE = "export_statistics_method"; | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * 币种 | ||
| 127 | + */ | ||
| 128 | + public static final String DICT_CURRENCY_CD_CODE = "currency_cd"; | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 商标 | ||
| 132 | + */ | ||
| 133 | + public static final String DICT_BRAND_CODE = "brand"; | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 产证 | ||
| 137 | + */ | ||
| 138 | + public static final String DICT_PROPERTY_CERTIFICATE_CODE = "property_certificate"; | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * ECFA产证 | ||
| 142 | + */ | ||
| 143 | + public static final String DICT_ECFA_PROPERTY_CERTIFICATE_CODE = "ecfa_property_certificate"; | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 申请 | ||
| 147 | + */ | ||
| 148 | + public static final String DICT_APPLY_FOR_CODE = "apply_for"; | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 提单状态 | ||
| 152 | + */ | ||
| 153 | + public static final String DICT_DELIVERY_STATUS_CODE = "delivery_status"; | ||
| 154 | + | ||
| 155 | + /** | ||
| 156 | + * 操作状态 | ||
| 157 | + */ | ||
| 158 | + public static final String DICT_OPER_STATUS_CODE = "oper_status"; | ||
| 159 | + | ||
| 160 | + /** | ||
| 161 | + * 提单状态 | ||
| 162 | + */ | ||
| 163 | + public static final String DICT_FILE_SOURCE_CODE = "file_source"; | ||
| 164 | + | ||
| 165 | + /** | ||
| 166 | + * 提单状态 | ||
| 167 | + */ | ||
| 168 | + public static final String DICT_LOGIN_TYPE_CODE = "login_type"; | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 邮件发送状态 | ||
| 172 | + */ | ||
| 173 | + public static final String DICT_MAIL_SEND_STATUS_CODE = "mail_send_status"; | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * 任务默认节点 | ||
| 177 | + */ | ||
| 178 | + public static final Long TASK_DEFAULT_NODE = 1L; | ||
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * 任务默认执行类型 | ||
| 182 | + */ | ||
| 183 | + public static final Long TASK_EXEC_TYPE = 1L; | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 任务类型。 | ||
| 187 | + * 1:执行程序操作(增删改查)数据。 | ||
| 188 | + * 2:邮件发送。 | ||
| 189 | + * 3:读取消息系统数据(MQ、Kafka、redis等) | ||
| 190 | + * 4:写入消息系统数据(MQ、Kafka、redis等) | ||
| 191 | + * 5:请求外部系统获取数据。 | ||
| 192 | + * 6:推送数据到外部系统。 | ||
| 193 | + */ | ||
| 194 | + public static final Long TASK_TYPE_EXEC = 1L; | ||
| 195 | + public static final Long TASK_TYPE_MAIL = 2L; | ||
| 196 | + public static final Long TASK_TYPE_READ_MQ = 3L; | ||
| 197 | + public static final Long TASK_TYPE_WRITE_MQ = 4L; | ||
| 198 | + public static final Long TASK_TYPE_READ_SERVER = 5L; | ||
| 199 | + public static final Long TASK_TYPE_WRITE_SERVER = 6L; | ||
| 200 | + | ||
| 201 | + /** | ||
| 202 | + * 任务状态 | ||
| 203 | + * 0:待执行(初始状态)。 | ||
| 204 | + * 1:执行成功。 | ||
| 205 | + * 2:执行中待获取结果。 | ||
| 206 | + * 3:执行失败 | ||
| 207 | + */ | ||
| 208 | + public static final Long TASK_STATUS_INIT = 0L; | ||
| 209 | + public static final Long TASK_STATUS_SUCC = 1L; | ||
| 210 | + public static final Long TASK_STATUS_IN_EXEC = 2L; | ||
| 211 | + public static final Long TASK_STATUS_FAIL = 3L; | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * 申报信息在任务管理中的分组CODE | ||
| 215 | + */ | ||
| 216 | + public static final String TASK_GROUP_CODE_DECLARE = "DECLARE_INFO"; | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * 重置密码在邮件日志里面的分组 | ||
| 220 | + */ | ||
| 221 | + public static final String MAIL_GROUP_CODE_RESETPWD = "RESULT_PASSWORD"; | ||
| 222 | + | ||
| 223 | + public static final String FCL_PREFIX = "FCL"; | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 有无商标 | ||
| 227 | + * 1:无商标 | ||
| 228 | + */ | ||
| 229 | + public static final Long BRAND_NO = 1L; | ||
| 230 | + | ||
| 231 | + /** | ||
| 232 | + * 是否为电子冲退税报单 | ||
| 233 | + * 0:否 | ||
| 234 | + * 1:是 | ||
| 235 | + */ | ||
| 236 | + public static final Long TAX_FLAG_NO = 0L; | ||
| 237 | + public static final Long TAX_FLAG_YES = 1L; | ||
| 238 | + | ||
| 239 | + /** | ||
| 240 | + * 定义保存操作步骤 | ||
| 241 | + * 1:申报信息 2:核检信息 3:文件上传 | ||
| 242 | + */ | ||
| 243 | + public static final Long DEC_SAVE_INFO = 1L; | ||
| 244 | + public static final Long DEC_SAVE_CHECK_INFO = 2L; | ||
| 245 | + public static final Long DEC_SAVE_FILE = 3L; | ||
| 246 | + | ||
| 247 | + /** | ||
| 248 | + * 报关类别 | ||
| 249 | + */ | ||
| 250 | + public static final String DT_G5 = "G5"; | ||
| 251 | + public static final String DT_G3 = "G3"; | ||
| 252 | + public static final String DT_B9 = "B9"; | ||
| 253 | + public static final String DT_B8 = "B8"; | ||
| 254 | + public static final String DT_D5 = "D5"; | ||
| 255 | + public static final String DT_F5 = "F5"; | ||
| 256 | + | ||
| 257 | + /** | ||
| 258 | + * 出口统计方式 | ||
| 259 | + */ | ||
| 260 | + public static final String ESM_02 = "02"; | ||
| 261 | + public static final String ESM_81 = "81"; | ||
| 262 | + public static final String ESM_04 = "04"; | ||
| 263 | + public static final String ESM_82 = "82"; | ||
| 264 | + public static final String ESM_9E = "9E"; //del | ||
| 265 | + public static final String ESM_9L = "9L"; | ||
| 266 | + public static final String ESM_91 = "91"; | ||
| 267 | + public static final String ESM_9S = "9S"; | ||
| 268 | + public static final String ESM_94 = "94"; | ||
| 269 | + public static final String ESM_92 = "92"; | ||
| 270 | + public static final String ESM_9M = "9M"; | ||
| 271 | + public static final String ESM_96 = "96"; | ||
| 272 | + public static final String ESM_53 = "53"; | ||
| 273 | + public static final String ESM_OTHER = "OTHER"; | ||
| 274 | + | ||
| 275 | + /** | ||
| 276 | + * 产证 | ||
| 277 | + */ | ||
| 278 | + public static final String PC_NO = "pc_no"; | ||
| 279 | + public static final String PC_YES = "pc_yes"; | ||
| 280 | + public static final String PC_RANDOM = "pc_random"; | ||
| 281 | + public static final String PC_NI_RANDOM = "pc_niRandom"; | ||
| 282 | + | ||
| 283 | + /** | ||
| 284 | + * ECFA产证 | ||
| 285 | + */ | ||
| 286 | + public static final String ECFA_NO = "ecfa_no"; | ||
| 287 | + public static final String ECFA_YES = "ecfa_yes"; | ||
| 288 | + public static final String ECFA_APPLY = "ecfa_apply"; | ||
| 289 | + | ||
| 290 | + /** | ||
| 291 | + * 申请 | ||
| 292 | + */ | ||
| 293 | + public static final String AF_CT = "ct"; | ||
| 294 | + public static final String AF_TN = "tn"; | ||
| 295 | + public static final String AF_CK = "ck"; | ||
| 296 | + | ||
| 297 | + /** | ||
| 298 | + * 提单失败类型 | ||
| 299 | + * 1:超时失败(提单状态=4,超时情况。提示联系清关部门) | ||
| 300 | + * 2:三次发送邮件失败(提单状态=4,三次重发邮件失败。显示操作:重发) | ||
| 301 | + * 3:读取回执为失败(提单状态=4,读取失败,重试次数耗尽。浮框显示FAILED_MSG失败原因。) | ||
| 302 | + * 4:其他情况失败(3次匹配。其他情况等。显示:联系清关部门) | ||
| 303 | + */ | ||
| 304 | + public static final Long RECEIPT_FAIL_TYPE_TIMEOUT = 1L; | ||
| 305 | + public static final Long RECEIPT_FAIL_TYPE_RESEND = 2L; | ||
| 306 | + public static final Long RECEIPT_FAIL_TYPE_RECEIPT = 3L; | ||
| 307 | + public static final Long RECEIPT_FAIL_TYPE_OTHER = 4L; | ||
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * 获取系统配置参数中邮件人员信息配置 | ||
| 311 | + */ | ||
| 312 | + public static final String SEND_MAIL_GROUP_DECLARE = "DECLARE_SEND_MAIL"; | ||
| 313 | + public static final String SEND_MAIL_GROUP_RESETPWD = "RESETPWD_SEND_MAIL"; | ||
| 314 | + | ||
| 315 | + public static final String MAIL_FROM = "FROM"; | ||
| 316 | + public static final String MAIL_PWD = "PWD"; | ||
| 317 | + public static final String MAIL_TO = "TO"; | ||
| 318 | + public static final String MAIL_CC = "CC"; | ||
| 319 | + | ||
| 320 | + /** | ||
| 321 | + * VIP清关组 | ||
| 322 | + */ | ||
| 323 | + public static final Long VIP_CC_TYPE = 1L; | ||
| 324 | + public static final Long VIP_CC_LIST_TYPE_WHITE = 1L; | ||
| 325 | + public static final Long VIP_CC_LIST_TYPE_BLACK = 2L; | ||
| 326 | + public static final String VIP_CC_ADD_CC_MAIL = "ADD_CC_MAIL"; | ||
| 327 | + | ||
| 328 | +} |
| 1 | +package com.fedex.connect.common.dependencies.contants; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Redis使用常量。鉴权和redis都使用 | ||
| 5 | + */ | ||
| 6 | +public class RedisConstants { | ||
| 7 | + | ||
| 8 | + public static final String REDIS_KEY_TOKEN = "tw_user:token:"; | ||
| 9 | + | ||
| 10 | + public static final int REDIS_EXPIRE_TIME_2H = 7200; | ||
| 11 | + public static final int REDIS_EXPIRE_TIME_8H = 28800; | ||
| 12 | + public static final int REDIS_EXPRIE_TIME_1D = 86400; | ||
| 13 | + public static final int REDIS_EXPRIE_TIME_1W = 604800; | ||
| 14 | +} |
| 1 | +package com.fedex.connect.common.dependencies.enums; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * @author erry | ||
| 6 | + */ | ||
| 7 | + | ||
| 8 | +public enum ResponseCode { | ||
| 9 | + /** | ||
| 10 | + * 200=操作成功 | ||
| 11 | + * 201=操作失败 | ||
| 12 | + * 202=API接口请求异常 | ||
| 13 | + * 203=后台程序发生异常 | ||
| 14 | + * 204=请求方式错误 | ||
| 15 | + * 205=api接口请求错误 | ||
| 16 | + * 206=api接口请求结果为空 | ||
| 17 | + * 207=系统异常! | ||
| 18 | + * | ||
| 19 | + * 301=登录身份异常 | ||
| 20 | + * 302=登录已过期 | ||
| 21 | + * 303=用户不存在 | ||
| 22 | + * 304=用户已禁用,不能登录! | ||
| 23 | + * 305=登录token过期,请重新登录! | ||
| 24 | + * 306=该角色下有用户存在,是否确认删除? | ||
| 25 | + * | ||
| 26 | + * 601=数据被占用 | ||
| 27 | + * 602=记录已存在,请勿重复添加 | ||
| 28 | + * 603=导出数据量过大,请不要超过10W条 | ||
| 29 | + * | ||
| 30 | + * 604=请求参数为空 | ||
| 31 | + * 605=ID为空 | ||
| 32 | + * 606=数据不存在 | ||
| 33 | + * 607=请求参数值不合理 | ||
| 34 | + */ | ||
| 35 | + SUCCESS_CODE(200,"enum_res_code_200"), | ||
| 36 | + FAIL_CODE(201,"enum_res_code_201"), | ||
| 37 | + API_EXCEPTION(202, "enum_res_code_202"), | ||
| 38 | + PROGRAM_ERROR(203,"enum_res_code_203"), | ||
| 39 | + METHOD_EXCEPTION_CODE(204, "enum_res_code_204"), | ||
| 40 | + HTTP_CLIENT_ERROR(205, "enum_res_code_205"), | ||
| 41 | + HTTP_CLIENT_EMPTY(206, "enum_res_code_206"), | ||
| 42 | + SYSTEM_EXECEPTION_CODE(207,"enum_res_code_207"), | ||
| 43 | + | ||
| 44 | + TOKEN_FORMAT_ERROR(301, "enum_res_code_301"), | ||
| 45 | + TOKEN_EXPIRE(302, "enum_res_code_302"), | ||
| 46 | + USER_IS_NULL(303, "enum_res_code_303"), | ||
| 47 | + USER_DISABLED(304, "enum_res_code_304"), | ||
| 48 | + OVERDUE_TOKEN_CODE(305,"enum_res_code_305"), | ||
| 49 | + ROLE_CONFIRM_DEL(306, "enum_res_code_306"), | ||
| 50 | + | ||
| 51 | + INSERT_EXCEPITON(601,"enum_res_code_601"), | ||
| 52 | + RECORD_EXIST(602, "enum_res_code_602"), | ||
| 53 | + EXPORT_TOO_LARGE(603, "enum_res_code_603"), | ||
| 54 | + | ||
| 55 | + REQUEST_PARAM_NULL(604, "enum_res_code_604"), | ||
| 56 | + REQUEST_ID_NULL(605, "enum_res_code_605"), | ||
| 57 | + REQUEST_OBJECT_NULL(606, "enum_res_code_606"), | ||
| 58 | + REQUEST_PARAM_UNREASONABLE(606, "enum_res_code_607"); | ||
| 59 | + | ||
| 60 | + private Integer code; | ||
| 61 | + private String msg; | ||
| 62 | + | ||
| 63 | + ResponseCode(Integer code, String msg) { | ||
| 64 | + this.code = code; | ||
| 65 | + this.msg = msg; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public Integer getCode() { | ||
| 69 | + return code; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + | ||
| 73 | + public String getMsg() { | ||
| 74 | + return msg; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | +} |
| 1 | +package com.fedex.connect.common.dependencies.i18n; | ||
| 2 | + | ||
| 3 | +import org.springframework.context.MessageSourceResolvable; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author EDY | ||
| 9 | + */ | ||
| 10 | +public class DefaultMessageSourceResolvable implements MessageSourceResolvable, Serializable { | ||
| 11 | + | ||
| 12 | + private final String[] codes; | ||
| 13 | + | ||
| 14 | + private final Object[] arguments; | ||
| 15 | + | ||
| 16 | + private final String defaultMessage; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 创建一个新的DefaultMessageSourceResolvable. | ||
| 21 | + * @param code 用来解析消息的码 | ||
| 22 | + */ | ||
| 23 | + public DefaultMessageSourceResolvable(String code) { | ||
| 24 | + this(new String[] {code}, null, null); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 创建一个新的DefaultMessageSourceResolvable. | ||
| 29 | + * @param codes 用来解析消息的码 | ||
| 30 | + */ | ||
| 31 | + public DefaultMessageSourceResolvable(String[] codes) { | ||
| 32 | + this(codes, null, null); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 创建一个新的DefaultMessageSourceResolvable. | ||
| 37 | + * @param codes 用来解析消息的码 | ||
| 38 | + * @param defaultMessage 用来解析消息的默认消息 | ||
| 39 | + */ | ||
| 40 | + public DefaultMessageSourceResolvable(String[] codes, String defaultMessage) { | ||
| 41 | + this(codes, null, defaultMessage); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 创建一个新的DefaultMessageSourceResolvable. | ||
| 46 | + * @param codes 用来解析消息的码 | ||
| 47 | + * @param arguments 用来解析消息的参数数组 | ||
| 48 | + */ | ||
| 49 | + public DefaultMessageSourceResolvable(String[] codes, Object[] arguments) { | ||
| 50 | + this(codes, arguments, null); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 创建一个新的DefaultMessageSourceResolvable. | ||
| 55 | + * @param codes 用来解析消息的码 | ||
| 56 | + * @param arguments 用来解析消息的参数数组 | ||
| 57 | + * @param defaultMessage 用来解析消息的默认消息 | ||
| 58 | + */ | ||
| 59 | + public DefaultMessageSourceResolvable( | ||
| 60 | + String[] codes,Object[] arguments, String defaultMessage) { | ||
| 61 | + | ||
| 62 | + this.codes = codes; | ||
| 63 | + this.arguments = arguments; | ||
| 64 | + this.defaultMessage = defaultMessage; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Copy constructor: Create a new instance from another resolvable. | ||
| 69 | + * @param resolvable the resolvable to copy from | ||
| 70 | + */ | ||
| 71 | + public DefaultMessageSourceResolvable(MessageSourceResolvable resolvable) { | ||
| 72 | + this(resolvable.getCodes(), resolvable.getArguments(), resolvable.getDefaultMessage()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Return the default code of this resolvable, that is, | ||
| 78 | + * the last one in the codes array. | ||
| 79 | + */ | ||
| 80 | + public String getCode() { | ||
| 81 | + return (this.codes != null && this.codes.length > 0 ? this.codes[this.codes.length - 1] : null); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public String[] getCodes() { | ||
| 86 | + return this.codes; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public Object[] getArguments() { | ||
| 91 | + return this.arguments; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public String getDefaultMessage() { | ||
| 96 | + return this.defaultMessage; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 表示指定默认的消息是否需要获取,来替换占位符and/or MessageFormat | ||
| 101 | + * return true:如果默认的消息可能包含参数占位符 | ||
| 102 | + * return false:如果它明确没有包含占位符或者自定义逃逸并且当前可以被简单暴露 | ||
| 103 | + * @see #getDefaultMessage() | ||
| 104 | + * @see #getArguments() | ||
| 105 | + */ | ||
| 106 | + public boolean shouldRenderDefaultMessage() { | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | +} |
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/i18n/I18nConfig.java
0 → 100644
| 1 | +package com.fedex.connect.common.dependencies.i18n; | ||
| 2 | + | ||
| 3 | +import org.springframework.context.annotation.Bean; | ||
| 4 | +import org.springframework.context.annotation.Configuration; | ||
| 5 | +import org.springframework.web.servlet.LocaleResolver; | ||
| 6 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| 7 | + | ||
| 8 | +@Configuration | ||
| 9 | +public class I18nConfig implements WebMvcConfigurer { | ||
| 10 | + | ||
| 11 | + @Bean | ||
| 12 | + public LocaleResolver localeResolver() { | ||
| 13 | + return new MessageLocaleResolver(); | ||
| 14 | + } | ||
| 15 | +} |
| 1 | +package com.fedex.connect.common.dependencies.i18n; | ||
| 2 | + | ||
| 3 | +import org.springframework.context.MessageSource; | ||
| 4 | +import org.springframework.context.MessageSourceResolvable; | ||
| 5 | +import org.springframework.context.i18n.LocaleContextHolder; | ||
| 6 | +import org.springframework.stereotype.Component; | ||
| 7 | + | ||
| 8 | +import javax.annotation.Resource; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 根据语言编码查询内容 | ||
| 12 | + */ | ||
| 13 | +@Component | ||
| 14 | +public class LocaleMessageUtil { | ||
| 15 | + | ||
| 16 | + @Resource | ||
| 17 | + private MessageSource messageSource; | ||
| 18 | + | ||
| 19 | + public LocaleMessageUtil() { | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + public String getMessage(String code) { | ||
| 24 | + return this.getConnectorMessage(code, null); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public String getMessage(String code,String defaultMessage) { | ||
| 28 | + return this.getConnectorMessage(code, null, defaultMessage); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getMessage(String code, Object[] args) { | ||
| 32 | + return this.getConnectorMessage(code, args); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public String getMessage(String code, Object[] args,String defaultMessage) { | ||
| 36 | + return this.getConnectorMessage(code, args,defaultMessage); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 解析code对应的信息进行返回,如果对应的code不能被解析则抛出异常NoSuchMessageException | ||
| 41 | + * @param code 需要进行解析的code,对应资源文件中的一个属性名 | ||
| 42 | + * @param args 需要用来替换code对应的信息中包含参数的内容,如:{0},{1,date},{2,time} | ||
| 43 | + * @return | ||
| 44 | + */ | ||
| 45 | + private String getConnectorMessage(String code, Object[] args){ | ||
| 46 | + return this.messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 解析code对应的信息进行返回,如果对应的code不能被解析则返回默认信息defaultMessage。 | ||
| 51 | + * @param code 需要进行解析的code,对应资源文件中的一个属性名 | ||
| 52 | + * @param args 需要用来替换code对应的信息中包含参数的内容,如:{0},{1,date},{2,time} | ||
| 53 | + * @param defaultMessage 当对应code对应的信息不存在时需要返回的默认值 | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + private String getConnectorMessage(String code, Object[] args, String defaultMessage){ | ||
| 57 | + return this.messageSource.getMessage(code, args, defaultMessage, LocaleContextHolder.getLocale()); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 根据封装对象,获取 | ||
| 62 | + * @param resolvable 封装对象 | ||
| 63 | + * @return | ||
| 64 | + */ | ||
| 65 | + private String getConnectorMessage(MessageSourceResolvable resolvable){ | ||
| 66 | + return this.messageSource.getMessage(resolvable, LocaleContextHolder.getLocale()); | ||
| 67 | + } | ||
| 68 | +} |
| 1 | +package com.fedex.connect.common.dependencies.i18n; | ||
| 2 | + | ||
| 3 | +import org.apache.commons.lang3.StringUtils; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | +import org.springframework.beans.factory.annotation.Value; | ||
| 7 | +import org.springframework.web.servlet.LocaleResolver; | ||
| 8 | + | ||
| 9 | +import javax.servlet.http.HttpServletRequest; | ||
| 10 | +import javax.servlet.http.HttpServletResponse; | ||
| 11 | +import java.util.Locale; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 根据请求头中携带的请求语言内容,生成会话,解析内容 | ||
| 15 | + * @author EDY | ||
| 16 | + */ | ||
| 17 | +public class MessageLocaleResolver implements LocaleResolver { | ||
| 18 | + | ||
| 19 | + @Value("${export.language}") | ||
| 20 | + private String exportTwLanguage; | ||
| 21 | + | ||
| 22 | + /*private static final String I18N_LANGUAGE = "i18n_language"; | ||
| 23 | + private static final String I18N_LANGUAGE_SESSION = "i18n_language_session";*/ | ||
| 24 | + | ||
| 25 | + private Logger logger = LoggerFactory.getLogger(MessageLocaleResolver.class); | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public Locale resolveLocale(HttpServletRequest request) { | ||
| 29 | + Locale locale; | ||
| 30 | + // String language = request.getParameter("I18N_LANGUAGE"); | ||
| 31 | + if (StringUtils.isNotEmpty(exportTwLanguage)) { | ||
| 32 | + //获取知道配置文件中的语言为: exportTwLanguage; | ||
| 33 | + locale = new Locale(exportTwLanguage); | ||
| 34 | + /*//将国际化语言保存到session | ||
| 35 | + HttpSession session = req.getSession(); | ||
| 36 | + session.setAttribute(I18N_LANGUAGE_SESSION, locale);*/ | ||
| 37 | + } else { | ||
| 38 | + //如果没有带国际化参数,则判断session有没有保存,有保存,则使用保存的,也就是之前设置的,避免之后的请求不带国际化参数造成语言显示不对 | ||
| 39 | + /*HttpSession session = req.getSession(); | ||
| 40 | + Locale localeInSession = (Locale) session.getAttribute(I18N_LANGUAGE_SESSION);*/ | ||
| 41 | + //读取不到指定语言文件,采用默认中文。即默认的message.properties | ||
| 42 | + locale = Locale.getDefault(); | ||
| 43 | + } | ||
| 44 | + return locale; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) { | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | +} |
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/BytesUtils.java
0 → 100644
| 1 | +package com.fedex.connect.common.dependencies.util; | ||
| 2 | + | ||
| 3 | +import org.apache.commons.codec.binary.Base64; | ||
| 4 | +import org.apache.commons.lang3.StringUtils; | ||
| 5 | + | ||
| 6 | +import java.nio.charset.StandardCharsets; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 类型转换 | ||
| 10 | + */ | ||
| 11 | +public class BytesUtils { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 获取字符串UTF-8的字节数 | ||
| 15 | + * @param str | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + public static int getStrUTF8ByteLength(String str){ | ||
| 19 | + if (StringUtils.isBlank(str)){ | ||
| 20 | + return 0; | ||
| 21 | + } | ||
| 22 | + return str.getBytes(StandardCharsets.UTF_8).length; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 字符串转换成十六进制字符串 | ||
| 27 | + */ | ||
| 28 | + public static String str2HexStr(String str) { | ||
| 29 | + char[] chars = "0123456789ABCDEF".toCharArray(); | ||
| 30 | + StringBuilder sb = new StringBuilder(""); | ||
| 31 | + byte[] bs = str.getBytes(); | ||
| 32 | + int bit; | ||
| 33 | + for (int i = 0; i < bs.length; i++) { | ||
| 34 | + bit = (bs[i] & 0x0f0) >> 4; | ||
| 35 | + sb.append(chars[bit]); | ||
| 36 | + bit = bs[i] & 0x0f; | ||
| 37 | + sb.append(chars[bit]); | ||
| 38 | + } | ||
| 39 | + return sb.toString(); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 十六进制字符串转换为 byte[] | ||
| 44 | + * | ||
| 45 | + * @param hexString the hex string | ||
| 46 | + * @return byte[] | ||
| 47 | + */ | ||
| 48 | + public static byte[] hexStringToBytes(String hexString) { | ||
| 49 | + if (hexString == null || hexString.equals("")) { | ||
| 50 | + return null; | ||
| 51 | + } | ||
| 52 | + hexString = hexString.toUpperCase(); | ||
| 53 | + int length = hexString.length() / 2; | ||
| 54 | + char[] hexChars = hexString.toCharArray(); | ||
| 55 | + byte[] d = new byte[length]; | ||
| 56 | + for (int i = 0; i < length; i++) { | ||
| 57 | + int pos = i * 2; | ||
| 58 | + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); | ||
| 59 | + } | ||
| 60 | + return d; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * char to byte | ||
| 65 | + * | ||
| 66 | + * @param c char | ||
| 67 | + * @return byte | ||
| 68 | + */ | ||
| 69 | + private static byte charToByte(char c) { | ||
| 70 | + return (byte) "0123456789ABCDEF".indexOf(c); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 数组转换成十六进制字符串 | ||
| 75 | + * | ||
| 76 | + * @param bArray byte[] | ||
| 77 | + * @return HexString | ||
| 78 | + */ | ||
| 79 | + public static final String bytesToHexString(byte[] bArray) { | ||
| 80 | + if (bArray == null || bArray.length == 0) { | ||
| 81 | + return null; | ||
| 82 | + } | ||
| 83 | + StringBuffer sb = new StringBuffer(bArray.length); | ||
| 84 | + String sTemp; | ||
| 85 | + for (int i = 0; i < bArray.length; i++) { | ||
| 86 | + sTemp = Integer.toHexString(0xFF & bArray[i]); | ||
| 87 | + if (sTemp.length() < 2) { | ||
| 88 | + sb.append(0); | ||
| 89 | + } | ||
| 90 | + sb.append(sTemp.toUpperCase()); | ||
| 91 | + } | ||
| 92 | + return sb.toString(); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 十六进制字符串转换成字符串 | ||
| 97 | + * | ||
| 98 | + * @param hexStr | ||
| 99 | + * @return String | ||
| 100 | + */ | ||
| 101 | + public static String hexStr2Str(String hexStr) { | ||
| 102 | + String str = "0123456789ABCDEF"; | ||
| 103 | + char[] hexs = hexStr.toCharArray(); | ||
| 104 | + byte[] bytes = new byte[hexStr.length() / 2]; | ||
| 105 | + int n; | ||
| 106 | + for (int i = 0; i < bytes.length; i++) { | ||
| 107 | + n = str.indexOf(hexs[2 * i]) * 16; | ||
| 108 | + n += str.indexOf(hexs[2 * i + 1]); | ||
| 109 | + bytes[i] = (byte) (n & 0xff); | ||
| 110 | + } | ||
| 111 | + return new String(bytes); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * @param hexString String str = "000AB" | ||
| 116 | + * @return | ||
| 117 | + */ | ||
| 118 | + public static int hexString2Int(String hexString) { | ||
| 119 | + Integer num = Integer.valueOf(hexString, 16); | ||
| 120 | + return num; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * 把byte转为字符串的bit | ||
| 125 | + */ | ||
| 126 | + public static String byteToBitString(byte b) { | ||
| 127 | + return "" | ||
| 128 | + + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) | ||
| 129 | + + (byte) ((b >> 5) & 0x1) + (byte) ((b >> 4) & 0x1) | ||
| 130 | + + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1) | ||
| 131 | + + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * 把byte转为字符串数组的bit | ||
| 136 | + */ | ||
| 137 | + public static String[] byteToBitStrings(byte b) { | ||
| 138 | + String[] bit = new String[8]; | ||
| 139 | + bit[0] = "" + (byte) ((b >> 7) & 0x1); | ||
| 140 | + bit[1] = "" + (byte) ((b >> 6) & 0x1); | ||
| 141 | + bit[2] = "" + (byte) ((b >> 5) & 0x1); | ||
| 142 | + bit[3] = "" + (byte) ((b >> 4) & 0x1); | ||
| 143 | + bit[4] = "" + (byte) ((b >> 3) & 0x1); | ||
| 144 | + bit[5] = "" + (byte) ((b >> 2) & 0x1); | ||
| 145 | + bit[6] = "" + (byte) ((b >> 1) & 0x1); | ||
| 146 | + bit[7] = "" + (byte) ((b >> 0) & 0x1); | ||
| 147 | + return bit; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + //base64字符串转byte[] | ||
| 151 | + public static byte[] base64String2ByteFun(String base64Str) { | ||
| 152 | + return Base64.decodeBase64(base64Str); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + //byte[]转base64 | ||
| 156 | + public static String byte2Base64StringFun(byte[] b) { | ||
| 157 | + return Base64.encodeBase64String(b); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public static void main(String[] args) { | ||
| 161 | + String hexString = "3A60432A5C01211F291E0F4E0C132825"; | ||
| 162 | + byte[] result = hexStringToBytes(hexString); | ||
| 163 | + System.out.println(new String(result)); | ||
| 164 | + System.out.println(bytesToHexString(result)); | ||
| 165 | + } | ||
| 166 | +} |
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/DateUtil.java
0 → 100644
This diff is collapsed. Click to expand it.
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/GsonUtils.java
0 → 100644
| 1 | +package com.fedex.connect.common.dependencies.util; | ||
| 2 | + | ||
| 3 | +import com.google.gson.*; | ||
| 4 | +import com.google.gson.reflect.TypeToken; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | +import java.util.Map; | ||
| 9 | + | ||
| 10 | +public class GsonUtils { | ||
| 11 | + | ||
| 12 | + private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); | ||
| 13 | + | ||
| 14 | + public static String toJsonString(Object object) { | ||
| 15 | + return object == null ? null : gson.toJson(object); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 转成json | ||
| 20 | + */ | ||
| 21 | + public static String beanToString(Object object) { | ||
| 22 | + String gsonString = null; | ||
| 23 | + if (gson != null) { | ||
| 24 | + gsonString = gson.toJson(object); | ||
| 25 | + } | ||
| 26 | + return gsonString; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 转成bean | ||
| 31 | + */ | ||
| 32 | + public static <T> T stringToBean(String gsonString, Class<T> cls) { | ||
| 33 | + T t = null; | ||
| 34 | + if (gson != null) { | ||
| 35 | + t = gson.fromJson(gsonString, cls); | ||
| 36 | + } | ||
| 37 | + return t; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 转成list | ||
| 42 | + */ | ||
| 43 | + public static <T> List<T> stringToList(String gsonString, Class<T> cls) { | ||
| 44 | + List<T> list = new ArrayList<>(); | ||
| 45 | + if (gson != null) { | ||
| 46 | + JsonArray array = new JsonParser().parse(gsonString).getAsJsonArray(); | ||
| 47 | + for (final JsonElement elem : array) { | ||
| 48 | + list.add(gson.fromJson(elem, cls)); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + return list; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 转成list, 有可能造成类型擦除 | ||
| 56 | + */ | ||
| 57 | + public static <T> ArrayList<T> stringToList(String gsonString) { | ||
| 58 | + ArrayList<T> list = null; | ||
| 59 | + if (gson != null) { | ||
| 60 | + list = gson.fromJson(gsonString, new TypeToken<ArrayList<T>>() { | ||
| 61 | + }.getType()); | ||
| 62 | + } | ||
| 63 | + return list; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * 转成map的 | ||
| 68 | + */ | ||
| 69 | + public static <T> Map<String, T> stringToMaps(String gsonString, Class<T> cls) { | ||
| 70 | + Map<String, T> map = null; | ||
| 71 | + if (gson != null) { | ||
| 72 | + map = gson.fromJson(gsonString, new TypeToken<Map<String, T>>() { | ||
| 73 | + }.getType()); | ||
| 74 | + } | ||
| 75 | + return map; | ||
| 76 | + } | ||
| 77 | +} |
| 1 | +package com.fedex.connect.common.dependencies.util; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.authentication.SecurityConstants; | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.RedisConstants; | ||
| 5 | +import com.fedex.export.data.dto.SecurityUserDetails; | ||
| 6 | +import com.fedex.export.repository.dao.SysUserMapperExt; | ||
| 7 | +import com.fedex.export.repository.entity.SysUser; | ||
| 8 | +import io.jsonwebtoken.Claims; | ||
| 9 | +import io.jsonwebtoken.Jwts; | ||
| 10 | +import io.jsonwebtoken.SignatureAlgorithm; | ||
| 11 | +import io.jsonwebtoken.security.Keys; | ||
| 12 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| 13 | +import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| 14 | + | ||
| 15 | +import javax.crypto.SecretKey; | ||
| 16 | +import javax.xml.bind.DatatypeConverter; | ||
| 17 | +import java.util.ArrayList; | ||
| 18 | +import java.util.Arrays; | ||
| 19 | +import java.util.Date; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.stream.Collectors; | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * @author Administrator | ||
| 26 | + */ | ||
| 27 | +public class JwtTokenUtils { | ||
| 28 | + | ||
| 29 | + private static final SysUserMapperExt sysUserMapper = com.fedex.export.common.util.SpringBeanUtil.getBean(SysUserMapperExt.class); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 生成足够的安全随机密钥,以适合符合规范的签名 | ||
| 33 | + */ | ||
| 34 | + private static final byte[] API_KEY_SECRET_BYTES = DatatypeConverter.parseBase64Binary(SecurityConstants.getSecuritykey()); | ||
| 35 | + | ||
| 36 | + private static final SecretKey SECRET_KEY = Keys.hmacShaKeyFor(API_KEY_SECRET_BYTES); | ||
| 37 | + | ||
| 38 | + public static String createAccessToken(String username, String id, List<String> roles, boolean isRememberMe) { | ||
| 39 | + long expiration = isRememberMe ? SecurityConstants.getExpire_1D() : RedisConstants.REDIS_EXPIRE_TIME_8H; | ||
| 40 | + final Date createdDate = new Date(); | ||
| 41 | + final Date expirationDate = new Date(createdDate.getTime() + expiration * 1000); | ||
| 42 | + String tokenPrefix = Jwts.builder() | ||
| 43 | + .setHeaderParam("type", SecurityConstants.TOKEN_TYPE) | ||
| 44 | + .signWith(SECRET_KEY, SignatureAlgorithm.HS256) | ||
| 45 | + .claim(SecurityConstants.ROLE_CLAIMS, String.join(",", roles)) | ||
| 46 | + .setId(id) | ||
| 47 | + .setIssuer("EXPORT_TW") //证书发行者 | ||
| 48 | + .setIssuedAt(createdDate) | ||
| 49 | + .setSubject(username) | ||
| 50 | + .setExpiration(expirationDate) | ||
| 51 | + .compact(); | ||
| 52 | + return SecurityConstants.TOKEN_PREFIX + tokenPrefix; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static String createReflushToken(String username, String id, List<String> roles) { | ||
| 56 | + //默认保留1小时 | ||
| 57 | + long expiration = 3600L; | ||
| 58 | + Date createdDate = new Date(); | ||
| 59 | + Date expirationDate = new Date(createdDate.getTime() + expiration * 1000); | ||
| 60 | + String tokenPrefix = Jwts.builder() | ||
| 61 | + .setHeaderParam("type", SecurityConstants.TOKEN_TYPE) | ||
| 62 | + .signWith(SECRET_KEY, SignatureAlgorithm.HS256) | ||
| 63 | + .claim(SecurityConstants.ROLE_CLAIMS, String.join(",", roles)) | ||
| 64 | + .setId(id) | ||
| 65 | + .setIssuer("EXPORT_TW") | ||
| 66 | + .setIssuedAt(createdDate) | ||
| 67 | + .setSubject(username) | ||
| 68 | + .setExpiration(expirationDate) | ||
| 69 | + .compact(); | ||
| 70 | + return SecurityConstants.TOKEN_PREFIX + tokenPrefix; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 从token中获取用户id | ||
| 76 | + * @param token | ||
| 77 | + * @return | ||
| 78 | + */ | ||
| 79 | + public static String getId(String token) { | ||
| 80 | + Claims claims = getClaims(token); | ||
| 81 | + return claims.getId(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 从token中获取用户id | ||
| 86 | + * @param token | ||
| 87 | + * @return | ||
| 88 | + */ | ||
| 89 | + public static String getUserName(String token) { | ||
| 90 | + Claims claims = getClaims(token); | ||
| 91 | + return claims.getSubject(); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 获取token的过期时间 | ||
| 96 | + * @param token | ||
| 97 | + * @return | ||
| 98 | + */ | ||
| 99 | + public static Date getAccessTokenExpiredTime(String token){ | ||
| 100 | + Claims claims = getClaims(token); | ||
| 101 | + return claims.getExpiration(); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * 从token中获取权限 | ||
| 106 | + * @param token | ||
| 107 | + * @return | ||
| 108 | + */ | ||
| 109 | + public static UsernamePasswordAuthenticationToken getAuthentication(String token) { | ||
| 110 | + Claims claims = getClaims(token); | ||
| 111 | + List<SimpleGrantedAuthority> authorities = getAuthorities(claims); | ||
| 112 | + String userName = claims.getSubject(); | ||
| 113 | + String id = claims.getId(); | ||
| 114 | + | ||
| 115 | + SecurityUserDetails userDetails = new SecurityUserDetails(); | ||
| 116 | + userDetails.setId(Long.parseLong(id)); | ||
| 117 | + userDetails.setUsername(userName); | ||
| 118 | + SysUser user = sysUserMapper.findOne(Long.parseLong(id)); | ||
| 119 | + userDetails.setUser(user); | ||
| 120 | + | ||
| 121 | + return new UsernamePasswordAuthenticationToken(userDetails, token, authorities); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + private static List<SimpleGrantedAuthority> getAuthorities(Claims claims) { | ||
| 125 | + String role = (String) claims.get(SecurityConstants.ROLE_CLAIMS); | ||
| 126 | + if (!"".equals(role)) { | ||
| 127 | + return Arrays.stream(role.split(",")) | ||
| 128 | + .map(SimpleGrantedAuthority::new) | ||
| 129 | + .collect(Collectors.toList()); | ||
| 130 | + }else { | ||
| 131 | + return new ArrayList<>(); | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + private static Claims getClaims(String token) { | ||
| 136 | + return Jwts.parser() | ||
| 137 | + .setSigningKey(SECRET_KEY) | ||
| 138 | + .parseClaimsJws(token) | ||
| 139 | + .getBody(); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public static List<String> getRoleList(String token){ | ||
| 143 | + Claims claims = getClaims(token); | ||
| 144 | + String roleStr = (String) claims.get(SecurityConstants.ROLE_CLAIMS); | ||
| 145 | + return Arrays.asList(roleStr.split(",")); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | +} |
This diff is collapsed. Click to expand it.
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/Utils.java
0 → 100644
This diff is collapsed. Click to expand it.
| ... | @@ -51,6 +51,12 @@ | ... | @@ -51,6 +51,12 @@ |
| 51 | <version>12.2.0.1</version> | 51 | <version>12.2.0.1</version> |
| 52 | <scope>${install.scope}</scope> | 52 | <scope>${install.scope}</scope> |
| 53 | </dependency> | 53 | </dependency> |
| 54 | + <dependency> | ||
| 55 | + <groupId>com.fedex.connect</groupId> | ||
| 56 | + <artifactId>common-dependencies</artifactId> | ||
| 57 | + <version>1.0.0</version> | ||
| 58 | + <scope>compile</scope> | ||
| 59 | + </dependency> | ||
| 54 | </dependencies> | 60 | </dependencies> |
| 55 | 61 | ||
| 56 | <profiles> | 62 | <profiles> | ... | ... |
server/manager-server/src/main/java/com/fedex/connect/manager/common/enums/FCLSessionInfoEnum.java
0 → 100644
| 1 | +package com.fedex.connect.manager.common.enums; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * FCL登录Session信息 | ||
| 8 | + */ | ||
| 9 | +public enum FCLSessionInfoEnum { | ||
| 10 | + | ||
| 11 | + FDX_LOGIN("fdx_login","FCL登录SESSION信息"), | ||
| 12 | + FCL_UUID("fcl_uuid","FCL-UUID信息"), | ||
| 13 | + FCL_CONTACTNAME("fcl_contactname","FCL联系人信息"); | ||
| 14 | + | ||
| 15 | + FCLSessionInfoEnum(String code, String name){ | ||
| 16 | + this.code = code; | ||
| 17 | + this.name = name; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + private String code; | ||
| 21 | + private String name; | ||
| 22 | + public String getCode() { | ||
| 23 | + return code; | ||
| 24 | + } | ||
| 25 | + public String getName() { | ||
| 26 | + return name; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public static List<String> getCodeList() { | ||
| 30 | + List<String> codeList = new ArrayList<>(); | ||
| 31 | + for(FCLSessionInfoEnum fclSessionInfoEnum : FCLSessionInfoEnum.values()){ | ||
| 32 | + codeList.add(fclSessionInfoEnum.getCode()); | ||
| 33 | + } | ||
| 34 | + return codeList; | ||
| 35 | + } | ||
| 36 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/config/PropertiesConfig.java
0 → 100644
| 1 | +package com.fedex.connect.manager.config; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | +import org.springframework.beans.factory.annotation.Value; | ||
| 5 | +import org.springframework.context.annotation.Configuration; | ||
| 6 | + | ||
| 7 | +@Data | ||
| 8 | +@Configuration | ||
| 9 | +public class PropertiesConfig { | ||
| 10 | + @Value("${fcl.login.url}") | ||
| 11 | + private String fclLoginUrl; | ||
| 12 | + | ||
| 13 | + @Value("${fcl.twidx.url}") | ||
| 14 | + private String twIdxUrl; | ||
| 15 | + | ||
| 16 | + @Value("${fcl.login.redjrectLogin}") | ||
| 17 | + private String redjrectLogin; | ||
| 18 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/controller/AbstractEtController.java
0 → 100644
| 1 | +package com.fedex.connect.manager.controller; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; | ||
| 5 | +import com.fedex.connect.manager.config.PropertiesConfig; | ||
| 6 | +import com.fedex.connect.manager.controller.log.ILogLoginService; | ||
| 7 | +import com.fedex.connect.manager.data.vo.JsonResult; | ||
| 8 | +import com.fedex.connect.manager.service.system.ISysAuthService; | ||
| 9 | +import com.fedex.connect.manager.service.system.ISysUserService; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.http.HttpHeaders; | ||
| 12 | +import org.springframework.http.HttpStatus; | ||
| 13 | +import org.springframework.http.ResponseEntity; | ||
| 14 | +import org.springframework.util.MultiValueMap; | ||
| 15 | + | ||
| 16 | +import javax.annotation.Resource; | ||
| 17 | +import java.net.URI; | ||
| 18 | +import java.util.Objects; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @author EDY | ||
| 22 | + */ | ||
| 23 | +public class AbstractEtController { | ||
| 24 | + | ||
| 25 | + @Resource | ||
| 26 | + protected LocaleMessageUtil localeMessageUtil; | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + protected PropertiesConfig propertiesConfig; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + protected ISysUserService sysUserService; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + protected ISysAuthService sysAuthService; | ||
| 36 | + | ||
| 37 | + @Autowired | ||
| 38 | + protected ILogLoginService logLoginService; | ||
| 39 | + | ||
| 40 | + public <T> ResponseEntity<T> seeOther(String url) { | ||
| 41 | + HttpHeaders httpHeaders = new HttpHeaders(); | ||
| 42 | + httpHeaders.setLocation(URI.create(url)); | ||
| 43 | + return result(HttpStatus.SEE_OTHER, httpHeaders); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public <T> ResponseEntity<T> temporaryRedirect(String url) { | ||
| 47 | + HttpHeaders httpHeaders = new HttpHeaders(); | ||
| 48 | + httpHeaders.setLocation(URI.create(url)); | ||
| 49 | + return result(HttpStatus.TEMPORARY_REDIRECT, httpHeaders); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public <T> ResponseEntity<T> permanentRedirect(String url) { | ||
| 53 | + HttpHeaders httpHeaders = new HttpHeaders(); | ||
| 54 | + httpHeaders.setLocation(URI.create(url)); | ||
| 55 | + return result(HttpStatus.PERMANENT_REDIRECT, httpHeaders); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public <T> ResponseEntity<T> result(HttpStatus status, T data) { | ||
| 59 | + return new ResponseEntity<>(data, status); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public <T> ResponseEntity<T> result(HttpStatus status, HttpHeaders headers) { | ||
| 63 | + return new ResponseEntity<>(headers, status); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public <T> ResponseEntity<T> ok(T data) { | ||
| 67 | + return new ResponseEntity<>(data, HttpStatus.OK); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public <T> ResponseEntity<T> ok(MultiValueMap<String, String> headers, T data) { | ||
| 71 | + return new ResponseEntity<>(data, headers, HttpStatus.OK); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public <T> ResponseEntity<T> error(HttpStatus code) { | ||
| 75 | + return new ResponseEntity<>(code); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + public <T> ResponseEntity<T> error(HttpStatus code, MultiValueMap<String, String> headers) { | ||
| 80 | + return new ResponseEntity<>(headers, code); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 通过自定义的错误码,转换为对应的HttpStatus | ||
| 86 | + * @param response | ||
| 87 | + * @return | ||
| 88 | + */ | ||
| 89 | + public HttpStatus errorMappingStatus(JsonResult response) { | ||
| 90 | + if (Objects.isNull(response)) { | ||
| 91 | + return HttpStatus.BAD_REQUEST; //400 | ||
| 92 | + } | ||
| 93 | + return HttpStatus.BAD_REQUEST; //400 | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 判定是否返回成功 | ||
| 99 | + * @param responseEntity | ||
| 100 | + * @param <T> | ||
| 101 | + * @return | ||
| 102 | + */ | ||
| 103 | + public <T> boolean isSuccess(ResponseEntity<JsonResult<T>> responseEntity) { | ||
| 104 | + return responseEntity != null && responseEntity.getBody() != null && responseEntity.getBody().isSuccess(); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 判定是否返回成功 | ||
| 109 | + * @param response | ||
| 110 | + * @param <T> | ||
| 111 | + * @return | ||
| 112 | + */ | ||
| 113 | + public <T> boolean isSuccess(JsonResult<T> response) { | ||
| 114 | + return response != null && response.isSuccess(); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | +} |
| 1 | +package com.fedex.connect.manager.controller.log.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.manager.controller.log.ILogLoginService; | ||
| 4 | +import com.fedex.connect.manager.data.dto.LogLoginDto; | ||
| 5 | +import com.fedex.connect.manager.data.model.LogShowModel; | ||
| 6 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | +import org.slf4j.LoggerFactory; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | +import org.springframework.transaction.annotation.Transactional; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 日志相关service | ||
| 14 | + * @author EDY | ||
| 15 | + */ | ||
| 16 | +@Service | ||
| 17 | +public class LogLoginServiceImpl extends AbstractEtService implements ILogLoginService { | ||
| 18 | + | ||
| 19 | + private Logger logger = LoggerFactory.getLogger(LogLoginServiceImpl.class); | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 保存登录日志 | ||
| 24 | + * @param dto | ||
| 25 | + * @return | ||
| 26 | + */ | ||
| 27 | + @Transactional(rollbackFor = Exception.class) | ||
| 28 | + public int saveLoginLog(LogLoginDto dto){ | ||
| 29 | + try{ | ||
| 30 | + return userLoginLogRepository.insert(LogLoginDto.dtoToDao(dto)); | ||
| 31 | + } catch (Exception e){ | ||
| 32 | + logger.error(LogShowModel.showException("Exception",e)); | ||
| 33 | + throw e; | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | +} |
| 1 | +package com.fedex.connect.manager.controller.system; | ||
| 2 | + | ||
| 3 | +import javax.servlet.http.HttpServletRequest; | ||
| 4 | +import javax.servlet.http.HttpServletResponse; | ||
| 5 | + | ||
| 6 | +public interface ISysAuthController { | ||
| 7 | + void wlgnLogin(HttpServletRequest request, HttpServletResponse res); | ||
| 8 | + | ||
| 9 | + void wlgnForward(HttpServletRequest request, HttpServletResponse res); | ||
| 10 | +} |
| 1 | +package com.fedex.connect.manager.controller.system.impl; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 5 | +import com.fedex.connect.common.dependencies.util.GsonUtils; | ||
| 6 | +import com.fedex.connect.common.dependencies.util.StringExtUtil; | ||
| 7 | +import com.fedex.connect.common.dependencies.util.Utils; | ||
| 8 | +import com.fedex.connect.common.model.sys.User; | ||
| 9 | +import com.fedex.connect.manager.common.enums.FCLSessionInfoEnum; | ||
| 10 | +import com.fedex.connect.manager.controller.AbstractEtController; | ||
| 11 | +import com.fedex.connect.manager.controller.system.ISysAuthController; | ||
| 12 | +import com.fedex.connect.manager.data.dto.LogLoginDto; | ||
| 13 | +import com.fedex.connect.manager.data.dto.LoginRequest; | ||
| 14 | +import com.fedex.connect.manager.data.dto.SysUserDto; | ||
| 15 | +import com.fedex.connect.manager.data.vo.JsonResult; | ||
| 16 | +import com.google.gson.JsonObject; | ||
| 17 | +import io.swagger.annotations.Api; | ||
| 18 | +import io.swagger.annotations.ApiOperation; | ||
| 19 | +import org.apache.commons.lang3.StringUtils; | ||
| 20 | +import org.slf4j.Logger; | ||
| 21 | +import org.slf4j.LoggerFactory; | ||
| 22 | +import org.springframework.beans.factory.annotation.Value; | ||
| 23 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 24 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 25 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 26 | +import org.springframework.web.bind.annotation.RestController; | ||
| 27 | + | ||
| 28 | +import javax.servlet.http.Cookie; | ||
| 29 | +import javax.servlet.http.HttpServletRequest; | ||
| 30 | +import javax.servlet.http.HttpServletResponse; | ||
| 31 | +import javax.servlet.http.HttpSession; | ||
| 32 | +import java.io.IOException; | ||
| 33 | +import java.util.*; | ||
| 34 | + | ||
| 35 | +@RestController | ||
| 36 | +@RequestMapping(value = "/auth", name = "权鉴操作相关请求") | ||
| 37 | +@Api(value="SysAuthController",tags={"用户相关请求(无需token)"}) | ||
| 38 | +public class SysAuthControllerImpl extends AbstractEtController implements ISysAuthController { | ||
| 39 | + | ||
| 40 | + private static final Logger logger = LoggerFactory.getLogger(SysAuthControllerImpl.class); | ||
| 41 | + | ||
| 42 | + @Value("${fcl.interface.logurl}") | ||
| 43 | + private String fclIndexLoginUrl; | ||
| 44 | + | ||
| 45 | + @PostMapping("/init") | ||
| 46 | + @ApiOperation(value = "初始化进入首页获取FCL登录地址") | ||
| 47 | + public JsonResult init(){ | ||
| 48 | + return JsonResult.succ(fclIndexLoginUrl); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + @RequestMapping(value = "/wlgnForward") | ||
| 53 | + @ApiOperation(value = "FCL中转Cookie地址") | ||
| 54 | + public void wlgnForward(HttpServletRequest request, HttpServletResponse res){ | ||
| 55 | + printRequestInfo(request); | ||
| 56 | + try { | ||
| 57 | + boolean equals = true; | ||
| 58 | + if (!equals){ | ||
| 59 | + return; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + Cookie[] cookies = request.getCookies(); | ||
| 63 | + if (Utils.isEmpty(cookies)){ | ||
| 64 | + return; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + List<String> saveKeyList = FCLSessionInfoEnum.getCodeList(); | ||
| 68 | + List<String> cookiesList = new ArrayList(); | ||
| 69 | + for (int i = 0, max = cookies.length; i < max; i++) { | ||
| 70 | + Cookie cookie = cookies[i]; | ||
| 71 | + if(saveKeyList.contains(cookie.getName())){ | ||
| 72 | + cookiesList.add("'"+cookie.getName()+"':'"+cookie.getValue()+"'"); | ||
| 73 | + if(cookiesList.size() == saveKeyList.size()){ | ||
| 74 | + break; | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + if (cookiesList.size() > 0 && cookiesList.size() == saveKeyList.size()){ | ||
| 80 | + JsonObject jsonObject = GsonUtils.stringToBean("{"+String.join(",",cookiesList)+"}",JsonObject.class); | ||
| 81 | + //set cookie by fcl_key | ||
| 82 | + JsonResult tokenResult = sysAuthService.createFclToken(jsonObject); | ||
| 83 | + if (tokenResult.isSuccess()){ | ||
| 84 | + String fcl_token_key = String.valueOf(tokenResult.getData()); | ||
| 85 | + String redirectUrl = String.format("%s?token=%s", propertiesConfig.getFclLoginUrl(), fcl_token_key); | ||
| 86 | + res.sendRedirect(redirectUrl); | ||
| 87 | + } | ||
| 88 | + }else { | ||
| 89 | + res.sendRedirect(propertiesConfig.getTwIdxUrl()); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + } catch (IOException e) { | ||
| 93 | + logger.error(e.getMessage(),e); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @GetMapping(value = "/wlgnLogin") | ||
| 98 | + @ApiOperation(value = "FCL登录") | ||
| 99 | + public void wlgnLogin(HttpServletRequest request, HttpServletResponse res) { | ||
| 100 | + logger.info("wlgnLogin____________________start"); | ||
| 101 | + | ||
| 102 | + String fcl_token_key = request.getParameter("token"); | ||
| 103 | + if (StringUtils.isBlank(fcl_token_key)){ | ||
| 104 | + return; | ||
| 105 | + } | ||
| 106 | + JsonObject jsonObject = sysAuthService.getFclToken(fcl_token_key); | ||
| 107 | + String fcl_uuid = jsonObject.get(FCLSessionInfoEnum.FCL_UUID.getCode()).getAsString(); | ||
| 108 | + String fcl_contactname = jsonObject.get(FCLSessionInfoEnum.FCL_CONTACTNAME.getCode()).getAsString().replaceAll("\"",""); | ||
| 109 | + | ||
| 110 | + User loginUser = sysUserService.findUserByFcl(fcl_uuid); | ||
| 111 | + if (loginUser == null){ | ||
| 112 | + //如果用户不存在,则创建FCL用户信息 | ||
| 113 | + SysUserDto dto = new SysUserDto(fcl_uuid, fcl_contactname); | ||
| 114 | + loginUser = sysUserService.save(dto); | ||
| 115 | + } else { | ||
| 116 | + //首先对用户中的姓名进行解密 | ||
| 117 | + if (StringUtils.isNotBlank(loginUser.getUserName())){ | ||
| 118 | + String decode_userName = loginUser.getUserName(); | ||
| 119 | + if (StringUtils.isNotBlank(decode_userName)){ | ||
| 120 | + loginUser.setUserName(decode_userName); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + //如果名称和原来不一样,则更新 | ||
| 124 | + | ||
| 125 | + if(StringUtils.isNotBlank(fcl_contactname) && !fcl_contactname.equals(loginUser.getUserName())){ | ||
| 126 | + String encode_fcl_contactname = StringUtils.trimToEmpty(fcl_contactname); | ||
| 127 | + if (StringUtils.isNotBlank(encode_fcl_contactname)){ | ||
| 128 | + loginUser.setUserName(encode_fcl_contactname); | ||
| 129 | + } else { | ||
| 130 | + loginUser.setUserName(StringUtils.trimToEmpty(fcl_contactname)); | ||
| 131 | + } | ||
| 132 | + loginUser.setUpdateTime(new Date()); | ||
| 133 | + sysUserService.update(loginUser); | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + //创建token | ||
| 138 | + LoginRequest loginRequest = new LoginRequest(); | ||
| 139 | + loginRequest.setRememberMe(true); | ||
| 140 | + JsonResult tokenResult = sysAuthService.createAccessToken(loginRequest, loginUser); | ||
| 141 | + | ||
| 142 | + //记录日志 | ||
| 143 | + LogLoginDto dto = new LogLoginDto(loginUser.getId(), DatabaseConstants.USER_OPER_FCL_REGISTER, | ||
| 144 | + localeMessageUtil.getMessage("auth_login_desc")); | ||
| 145 | + logLoginService.saveLoginLog(dto); | ||
| 146 | + | ||
| 147 | + try{ | ||
| 148 | + if (tokenResult.isSuccess()){ | ||
| 149 | + String redirectUrl = String.format("%s?token=%s&uid=%s", propertiesConfig.getRedjrectLogin(), tokenResult.getData(), loginUser.getId()); | ||
| 150 | + res.sendRedirect(redirectUrl); | ||
| 151 | + logger.info("wlgnLogin____________________finish"); | ||
| 152 | + }else { | ||
| 153 | + res.sendRedirect(propertiesConfig.getTwIdxUrl()); | ||
| 154 | + } | ||
| 155 | + } catch (IOException e) { | ||
| 156 | + logger.error("FCL客户登录初始化 | 发生异常 | 异常如下:",e); | ||
| 157 | + throw new RuntimeException(e); | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + private void printRequestInfo(HttpServletRequest request) { | ||
| 162 | + logger.info("wlgnForward____________________headerNames"); | ||
| 163 | + Enumeration<String> headerNames = request.getHeaderNames(); | ||
| 164 | + if(Objects.nonNull(headerNames)) { | ||
| 165 | + while (headerNames.hasMoreElements()) { | ||
| 166 | + String s = headerNames.nextElement(); | ||
| 167 | + String header = request.getHeader(s); | ||
| 168 | + logger.info(s + ":" + header); | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + logger.info("wlgnForward____________________parameterNames"); | ||
| 172 | + Enumeration<String> parameterNames = request.getParameterNames(); | ||
| 173 | + if(Objects.nonNull(parameterNames)){ | ||
| 174 | + | ||
| 175 | + while(parameterNames.hasMoreElements()){ | ||
| 176 | + String s = parameterNames.nextElement(); | ||
| 177 | + String parameter = request.getHeader(s); | ||
| 178 | + logger.info(s+":"+parameter); | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + logger.info("wlgnForward____________________parameterMap"); | ||
| 183 | + Map<String, String[]> parameterMap = request.getParameterMap(); | ||
| 184 | + if(Objects.nonNull(parameterMap)) { | ||
| 185 | + Set<String> strings = parameterMap.keySet(); | ||
| 186 | + Iterator<String> iterator = strings.iterator(); | ||
| 187 | + while (iterator.hasNext()) { | ||
| 188 | + String next = iterator.next(); | ||
| 189 | + String[] strings1 = parameterMap.get(next); | ||
| 190 | + logger.info(next + ":" + StringExtUtil.convertArrayToString(strings1, ",")); | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + logger.info("wlgnForward____________________cookies"); | ||
| 195 | + Cookie[] cookies = request.getCookies(); | ||
| 196 | + if(Objects.nonNull(cookies)) { | ||
| 197 | + for (int i = 0, max = cookies.length; i < max; i++) { | ||
| 198 | + Cookie cookie = cookies[i]; | ||
| 199 | + logger.info(cookie.getName() + ":" + cookie.getValue()); | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + logger.info("wlgnForward____________________Session"); | ||
| 204 | + HttpSession session = request.getSession(); | ||
| 205 | + Enumeration<String> attributeNames = session.getAttributeNames(); | ||
| 206 | + while(attributeNames.hasMoreElements()){ | ||
| 207 | + String s = attributeNames.nextElement(); | ||
| 208 | + String parameter = (String)request.getAttribute(s); | ||
| 209 | + logger.info(s+":"+parameter); | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | +} |
| 1 | +package com.fedex.connect.manager.dao.base; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dao.base.DictionaryEntriesMapper; | ||
| 4 | +import com.fedex.connect.common.dao.log.UserLoginInfoMapper; | ||
| 5 | +import com.fedex.connect.common.dao.sys.RedisSlabMapper; | ||
| 6 | +import com.fedex.connect.common.dao.sys.RoleMapper; | ||
| 7 | +import com.fedex.connect.common.dao.sys.UserMapper; | ||
| 8 | +import com.fedex.connect.common.dao.sys.UserRoleMapper; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | + | ||
| 11 | +public class BaseDao { | ||
| 12 | + @Autowired | ||
| 13 | + public UserLoginInfoMapper userLoginInfoMapper; | ||
| 14 | + @Autowired | ||
| 15 | + public RedisSlabMapper redisSlabMapper; | ||
| 16 | + @Autowired | ||
| 17 | + public RoleMapper roleMapper; | ||
| 18 | + @Autowired | ||
| 19 | + public UserRoleMapper userRoleMapper; | ||
| 20 | + @Autowired | ||
| 21 | + public UserMapper userMapper; | ||
| 22 | + @Autowired | ||
| 23 | + public DictionaryEntriesMapper dictionaryEntriesMapper; | ||
| 24 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.log.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.log.UserLoginInfo; | ||
| 4 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 5 | +import com.fedex.connect.manager.dao.repository.log.IUserLoginLogRepository; | ||
| 6 | +import org.springframework.stereotype.Repository; | ||
| 7 | + | ||
| 8 | +@Repository | ||
| 9 | +public class UserLoginLogRepositoryImpl extends BaseDao implements IUserLoginLogRepository { | ||
| 10 | + | ||
| 11 | + @Override | ||
| 12 | + public int insert(UserLoginInfo userLoginInfo) { | ||
| 13 | + return userLoginInfoMapper.insert(userLoginInfo); | ||
| 14 | + } | ||
| 15 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 4 | +import com.fedex.connect.common.model.base.DictionaryEntriesExample; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +public interface IDictionaryEntriesRepository { | ||
| 9 | + List<DictionaryEntries> selectByExample(DictionaryEntriesExample example); | ||
| 10 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 4 | +import com.fedex.connect.common.model.sys.RedisSlabExample; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +public interface IRedisSlabRepository { | ||
| 9 | + int insert(RedisSlab record); | ||
| 10 | + | ||
| 11 | + List<RedisSlab> selectByExample(RedisSlabExample example); | ||
| 12 | + | ||
| 13 | + int deleteByPrimaryKey(Long id); | ||
| 14 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.Role; | ||
| 4 | +import com.fedex.connect.common.model.sys.RoleExample; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +public interface IRoleRepository { | ||
| 9 | + List<Role> selectByExample(RoleExample example); | ||
| 10 | + | ||
| 11 | + Role selectByPrimaryKey(Long id); | ||
| 12 | + | ||
| 13 | + int insert(Role record); | ||
| 14 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.User; | ||
| 4 | +import com.fedex.connect.common.model.sys.UserExample; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +public interface IUserRepository { | ||
| 9 | + List<User> selectByExample(UserExample example); | ||
| 10 | + | ||
| 11 | + int insert(User record); | ||
| 12 | + | ||
| 13 | + int updateByPrimaryKeySelective(User record); | ||
| 14 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.UserRole; | ||
| 4 | +import com.fedex.connect.common.model.sys.UserRoleExample; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +public interface IUserRoleRepository { | ||
| 9 | + List<UserRole> selectByExample(UserRoleExample example); | ||
| 10 | + | ||
| 11 | + int insert(UserRole record); | ||
| 12 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 4 | +import com.fedex.connect.common.model.base.DictionaryEntriesExample; | ||
| 5 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 6 | +import com.fedex.connect.manager.dao.repository.sys.IDictionaryEntriesRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public class DictionaryEntriesImpl extends BaseDao implements IDictionaryEntriesRepository { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public List<DictionaryEntries> selectByExample(DictionaryEntriesExample example) { | ||
| 16 | + return dictionaryEntriesMapper.selectByExample(example); | ||
| 17 | + } | ||
| 18 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 4 | +import com.fedex.connect.common.model.sys.RedisSlabExample; | ||
| 5 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 6 | +import com.fedex.connect.manager.dao.repository.sys.IRedisSlabRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public class RedisSlabRepositoryImpl extends BaseDao implements IRedisSlabRepository { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public int insert(RedisSlab record) { | ||
| 16 | + return redisSlabMapper.insert(record); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public List<RedisSlab> selectByExample(RedisSlabExample example) { | ||
| 21 | + return redisSlabMapper.selectByExample(example); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public int deleteByPrimaryKey(Long id) { | ||
| 26 | + return redisSlabMapper.deleteByPrimaryKey(id); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.Role; | ||
| 4 | +import com.fedex.connect.common.model.sys.RoleExample; | ||
| 5 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 6 | +import com.fedex.connect.manager.dao.repository.sys.IRoleRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public class RoleRepositoryImpl extends BaseDao implements IRoleRepository { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public List<Role> selectByExample(RoleExample example) { | ||
| 16 | + return roleMapper.selectByExample(example); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public Role selectByPrimaryKey(Long id) { | ||
| 21 | + return roleMapper.selectByPrimaryKey(id); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public int insert(Role record) { | ||
| 26 | + return roleMapper.insert(record); | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.User; | ||
| 4 | +import com.fedex.connect.common.model.sys.UserExample; | ||
| 5 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 6 | +import com.fedex.connect.manager.dao.repository.sys.IUserRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public class UserRepositoryImpl extends BaseDao implements IUserRepository { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public List<User> selectByExample(UserExample example) { | ||
| 16 | + return userMapper.selectByExample(example); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public int insert(User record) { | ||
| 21 | + return userMapper.insert(record); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public int updateByPrimaryKeySelective(User record) { | ||
| 26 | + return userMapper.updateByPrimaryKeySelective(record); | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package com.fedex.connect.manager.dao.repository.sys.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.UserRole; | ||
| 4 | +import com.fedex.connect.common.model.sys.UserRoleExample; | ||
| 5 | +import com.fedex.connect.manager.dao.base.BaseDao; | ||
| 6 | +import com.fedex.connect.manager.dao.repository.sys.IUserRoleRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public class UserRoleRepositoryImpl extends BaseDao implements IUserRoleRepository { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public List<UserRole> selectByExample(UserRoleExample example) { | ||
| 16 | + return userRoleMapper.selectByExample(example); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public int insert(UserRole record) { | ||
| 21 | + return userRoleMapper.insert(record); | ||
| 22 | + } | ||
| 23 | +} |
| 1 | +package com.fedex.connect.manager.data.bo; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.util.DateUtil; | ||
| 4 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 5 | + | ||
| 6 | +import java.util.Date; | ||
| 7 | + | ||
| 8 | +public class RedisSlabBo { | ||
| 9 | + | ||
| 10 | + public static RedisSlab toDao(String key, String value, int validDuration){ | ||
| 11 | + RedisSlab dao = new RedisSlab(); | ||
| 12 | + dao.setRedisKey(key); | ||
| 13 | + dao.setRedisMsg(value); | ||
| 14 | + dao.setValidDuration(validDuration != 0 ? Long.valueOf(validDuration) : 0L); | ||
| 15 | + dao.setDisTime(DateUtil.getHoursAgoTime(validDuration)); | ||
| 16 | + dao.setCreateTime(new Date()); | ||
| 17 | + return dao; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * ID自增 | ||
| 23 | + */ | ||
| 24 | + private Long id; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Redis key | ||
| 28 | + */ | ||
| 29 | + private String redisKey; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Redis信息 | ||
| 33 | + */ | ||
| 34 | + private String redisMsg; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 有效时长 | ||
| 38 | + */ | ||
| 39 | + private Long validDuration; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 失效时间 | ||
| 43 | + */ | ||
| 44 | + private Date disTime; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 创建时间 | ||
| 48 | + */ | ||
| 49 | + private Date createTime; | ||
| 50 | + | ||
| 51 | + public Long getId() { | ||
| 52 | + return id; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setId(Long id) { | ||
| 56 | + this.id = id; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public String getRedisKey() { | ||
| 60 | + return redisKey; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setRedisKey(String redisKey) { | ||
| 64 | + this.redisKey = redisKey; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getRedisMsg() { | ||
| 68 | + return redisMsg; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setRedisMsg(String redisMsg) { | ||
| 72 | + this.redisMsg = redisMsg; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public Long getValidDuration() { | ||
| 76 | + return validDuration; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setValidDuration(Long validDuration) { | ||
| 80 | + this.validDuration = validDuration; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public Date getDisTime() { | ||
| 84 | + return disTime; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setDisTime(Date disTime) { | ||
| 88 | + this.disTime = disTime; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public Date getCreateTime() { | ||
| 92 | + return createTime; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setCreateTime(Date createTime) { | ||
| 96 | + this.createTime = createTime; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public RedisSlabBo() { | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public RedisSlabBo(Long id, String redisKey, String redisMsg, Long validDuration, Date disTime, Date createTime) { | ||
| 103 | + this.id = id; | ||
| 104 | + this.redisKey = redisKey; | ||
| 105 | + this.redisMsg = redisMsg; | ||
| 106 | + this.validDuration = validDuration; | ||
| 107 | + this.disTime = disTime; | ||
| 108 | + this.createTime = createTime; | ||
| 109 | + } | ||
| 110 | +} |
| 1 | +package com.fedex.connect.manager.data.dto; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.log.UserLoginInfo; | ||
| 4 | + | ||
| 5 | +import java.net.InetAddress; | ||
| 6 | +import java.net.UnknownHostException; | ||
| 7 | +import java.util.Date; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Dto对象用于记录登录操作日志 | ||
| 11 | + * 不建议继承:含义不同,不要混淆 | ||
| 12 | + * 不建议反射:数据量上来反射copy很慢。set最快 | ||
| 13 | + * dao 转dto 看业务是否需要了。 | ||
| 14 | + */ | ||
| 15 | +public class LogLoginDto { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 重载构造函数 | ||
| 19 | + */ | ||
| 20 | + public LogLoginDto(Long userId, Long operType, String operDesc){ | ||
| 21 | + this.userId = userId; | ||
| 22 | + this.operTime = new Date(); | ||
| 23 | + this.operType = operType; | ||
| 24 | + this.operDesc = operDesc; | ||
| 25 | + try{ | ||
| 26 | + this.ip = InetAddress.getLocalHost().getHostAddress(); | ||
| 27 | + } catch (UnknownHostException e){ | ||
| 28 | + this.ip = "127.0.01"; | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * dto转dao | ||
| 34 | + * @param dto | ||
| 35 | + * @return | ||
| 36 | + */ | ||
| 37 | + public static UserLoginInfo dtoToDao(LogLoginDto dto){ | ||
| 38 | + UserLoginInfo log = new UserLoginInfo(); | ||
| 39 | + if (dto == null){ | ||
| 40 | + return log; | ||
| 41 | + } | ||
| 42 | + if (dto.getId() != null && dto.getId() != 0){ | ||
| 43 | + log.setId(dto.getId()); | ||
| 44 | + } | ||
| 45 | + log.setUserId(dto.getUserId()); | ||
| 46 | + log.setOperDesc(dto.getOperDesc()); | ||
| 47 | + log.setIp(dto.getIp()); | ||
| 48 | + return log; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + //InetAddress.getLocalHost().getHostAddress() | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * ID | ||
| 56 | + */ | ||
| 57 | + private Long id; | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 用户id | ||
| 61 | + */ | ||
| 62 | + private Long userId; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * 操作时间 | ||
| 66 | + */ | ||
| 67 | + private Date operTime; | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 操作类型 | ||
| 71 | + 1:登录 2:退出 3:修改密码4:FCL登录注册 | ||
| 72 | + */ | ||
| 73 | + private Long operType; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 操作描述 | ||
| 77 | + */ | ||
| 78 | + private String operDesc; | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * IP | ||
| 82 | + */ | ||
| 83 | + private String ip; | ||
| 84 | + | ||
| 85 | + public Long getId() { | ||
| 86 | + return id; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public void setId(Long id) { | ||
| 90 | + this.id = id; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public Long getUserId() { | ||
| 94 | + return userId; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setUserId(Long userId) { | ||
| 98 | + this.userId = userId; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public Date getOperTime() { | ||
| 102 | + return operTime; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setOperTime(Date operTime) { | ||
| 106 | + this.operTime = operTime; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public Long getOperType() { | ||
| 110 | + return operType; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public void setOperType(Long operType) { | ||
| 114 | + this.operType = operType; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public String getOperDesc() { | ||
| 118 | + return operDesc; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setOperDesc(String operDesc) { | ||
| 122 | + this.operDesc = operDesc; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public String getIp() { | ||
| 126 | + return ip; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public void setIp(String ip) { | ||
| 130 | + this.ip = ip; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public LogLoginDto() { | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public LogLoginDto(Long id, Long userId, Date operTime, Long operType, String operDesc, String ip) { | ||
| 137 | + this.id = id; | ||
| 138 | + this.userId = userId; | ||
| 139 | + this.operTime = operTime; | ||
| 140 | + this.operType = operType; | ||
| 141 | + this.operDesc = operDesc; | ||
| 142 | + this.ip = ip; | ||
| 143 | + } | ||
| 144 | +} |
| 1 | +package com.fedex.connect.manager.data.dto; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dependencies.enums.ResponseCode; | ||
| 5 | +import com.fedex.connect.common.dependencies.util.Utils; | ||
| 6 | +import com.fedex.connect.manager.data.vo.JsonResult; | ||
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 8 | + | ||
| 9 | +import java.io.Serializable; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 用户登录请求DTO | ||
| 14 | + * @author Administrator | ||
| 15 | + */ | ||
| 16 | +public class LoginRequest implements Serializable { | ||
| 17 | + | ||
| 18 | + public static LoginRequest dataProcessing(LoginRequest dto){ | ||
| 19 | + dto.setAccNo(Utils.trim(dto.getAccNo())); | ||
| 20 | + dto.setPassword(Utils.trim(dto.getPassword())); | ||
| 21 | + return dto; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 验证用户登录信息 | ||
| 26 | + * @param dto | ||
| 27 | + * @return | ||
| 28 | + */ | ||
| 29 | + public static JsonResult validate(LoginRequest dto){ | ||
| 30 | + if (dto == null){ | ||
| 31 | + JsonResult.fail(ResponseCode.REQUEST_PARAM_NULL.getMsg()); | ||
| 32 | + } | ||
| 33 | + if (StringUtils.isBlank(dto.getAccNo())){ | ||
| 34 | + JsonResult.fail("auth_login_accno_null"); | ||
| 35 | + } | ||
| 36 | + if (StringUtils.isBlank(dto.getPassword())){ | ||
| 37 | + JsonResult.fail("auth_login_pwd_null"); | ||
| 38 | + } | ||
| 39 | + return JsonResult.succ(null); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 用户账号 | ||
| 44 | + */ | ||
| 45 | + private String accNo; | ||
| 46 | + /** | ||
| 47 | + * 用户密码 | ||
| 48 | + */ | ||
| 49 | + private String password; | ||
| 50 | + /** | ||
| 51 | + * 记住用户号 | ||
| 52 | + */ | ||
| 53 | + private Boolean rememberMe; | ||
| 54 | + | ||
| 55 | + public String getAccNo() { | ||
| 56 | + return accNo; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setAccNo(String accNo) { | ||
| 60 | + this.accNo = accNo; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getPassword() { | ||
| 64 | + return password; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setPassword(String password) { | ||
| 68 | + this.password = password; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public Boolean getRememberMe() { | ||
| 72 | + return rememberMe; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setRememberMe(Boolean rememberMe) { | ||
| 76 | + this.rememberMe = rememberMe; | ||
| 77 | + } | ||
| 78 | +} |
This diff is collapsed. Click to expand it.
server/manager-server/src/main/java/com/fedex/connect/manager/data/model/LogShowModel.java
0 → 100644
| 1 | +package com.fedex.connect.manager.data.model; | ||
| 2 | + | ||
| 3 | +import com.google.gson.Gson; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 用于打印日志的Model。 | ||
| 7 | + * 为了将来打印的日志,转换语言 | ||
| 8 | + * @author EDY | ||
| 9 | + */ | ||
| 10 | +public class LogShowModel { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 方法 | ||
| 14 | + */ | ||
| 15 | + private String method; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 参数 | ||
| 19 | + */ | ||
| 20 | + private Object param; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 返回 | ||
| 24 | + */ | ||
| 25 | + private Object result; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 异常 | ||
| 29 | + */ | ||
| 30 | + private Exception e; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 错误 | ||
| 34 | + */ | ||
| 35 | + private String msg; | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + public static String showRequest(String methodName, Object param){ | ||
| 39 | + LogShowModel lsm = new LogShowModel(); | ||
| 40 | + lsm.setMethod(methodName); | ||
| 41 | + lsm.setParam(param); | ||
| 42 | + return lsm.toString(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public static String showResponse(String methodName, Object result){ | ||
| 46 | + LogShowModel lsm = new LogShowModel(); | ||
| 47 | + lsm.setMethod(methodName); | ||
| 48 | + lsm.setResult(result); | ||
| 49 | + return lsm.toString(); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static String showException(String methodName, Exception e){ | ||
| 53 | + LogShowModel lsm = new LogShowModel(); | ||
| 54 | + lsm.setMethod(methodName); | ||
| 55 | + lsm.setE(e); | ||
| 56 | + return lsm.toString(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public static String showMsg(String methodName, String msg){ | ||
| 60 | + LogShowModel lsm = new LogShowModel(); | ||
| 61 | + lsm.setMethod(methodName); | ||
| 62 | + lsm.setMsg(msg); | ||
| 63 | + return lsm.toString(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public String toString() { | ||
| 68 | + Gson gson = new Gson(); | ||
| 69 | + StringBuilder show = new StringBuilder("方法:" + method); | ||
| 70 | + if (param != null){ | ||
| 71 | + show.append(",请求参数:"+gson.toJson(param)); | ||
| 72 | + } | ||
| 73 | + if (result != null){ | ||
| 74 | + show.append(",响应:"+gson.toJson(result)); | ||
| 75 | + } | ||
| 76 | + if (e != null){ | ||
| 77 | + show.append(",异常:"+ e.toString()); | ||
| 78 | + } | ||
| 79 | + if (msg != null){ | ||
| 80 | + show.append(","+ msg); | ||
| 81 | + } | ||
| 82 | + return show.toString(); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public LogShowModel(String method, Object param, Object result, Exception e, String msg) { | ||
| 86 | + this.method = method; | ||
| 87 | + this.param = param; | ||
| 88 | + this.result = result; | ||
| 89 | + this.e = e; | ||
| 90 | + this.msg = msg; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public LogShowModel() { | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getMethod() { | ||
| 97 | + return method; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setMethod(String method) { | ||
| 101 | + this.method = method; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public Object getParam() { | ||
| 105 | + return param; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setParam(Object param) { | ||
| 109 | + this.param = param; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public Object getResult() { | ||
| 113 | + return result; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setResult(Object result) { | ||
| 117 | + this.result = result; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public Exception getE() { | ||
| 121 | + return e; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setE(Exception e) { | ||
| 125 | + this.e = e; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public String getMsg() { | ||
| 129 | + return msg; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public void setMsg(String msg) { | ||
| 133 | + this.msg = msg; | ||
| 134 | + } | ||
| 135 | +} |
| 1 | +package com.fedex.connect.manager.data.vo; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.enums.ResponseCode; | ||
| 4 | + | ||
| 5 | +import javax.servlet.http.HttpServletResponse; | ||
| 6 | + | ||
| 7 | +public class JsonResult<T> { | ||
| 8 | + | ||
| 9 | + private int code = HttpServletResponse.SC_BAD_REQUEST;; | ||
| 10 | + private String msg; | ||
| 11 | + private boolean success; | ||
| 12 | + private T data; | ||
| 13 | + | ||
| 14 | + public int getCode() { | ||
| 15 | + return code; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public void setCode(int code) { | ||
| 19 | + this.code = code; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public String getMsg() { | ||
| 23 | + return msg; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public void setMsg(String msg) { | ||
| 27 | + this.msg = msg; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public boolean isSuccess() { | ||
| 31 | + return success; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void setSuccess(boolean success) { | ||
| 35 | + this.success = success; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public T getData() { | ||
| 39 | + return data; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setData(T data) { | ||
| 43 | + this.data = data; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public static JsonResult succ(Object data,String message) { | ||
| 47 | + return succ(ResponseCode.SUCCESS_CODE.getCode(), message, data); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public static JsonResult succ(Object data) { | ||
| 51 | + return succ(ResponseCode.SUCCESS_CODE.getCode(), "SUCCESS", data); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public static JsonResult succ(int code, String msg, Object data) { | ||
| 55 | + JsonResult r = new JsonResult(); | ||
| 56 | + r.setCode(code); | ||
| 57 | + r.setMsg(msg); | ||
| 58 | + r.setSuccess(true); | ||
| 59 | + r.setData(data); | ||
| 60 | + return r; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static JsonResult fail(String msg) { | ||
| 64 | + return fail(ResponseCode.FAIL_CODE.getCode(), msg,null); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public static JsonResult fail(int code, String msg,Object data) { | ||
| 68 | + JsonResult r = new JsonResult(); | ||
| 69 | + r.setCode(code); | ||
| 70 | + r.setMsg(msg); | ||
| 71 | + r.setSuccess(false); | ||
| 72 | + r.setData(data); | ||
| 73 | + return r; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public static JsonResult fail(ResponseCode resultCode) { | ||
| 77 | + return fail(resultCode.getCode(), resultCode.getMsg(), null); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public static JsonResult fail(ResponseCode resultCode, Object data) { | ||
| 81 | + return fail(resultCode.getCode(), resultCode.getMsg(), data); | ||
| 82 | + } | ||
| 83 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/service/AbstractEtService.java
0 → 100644
| 1 | +package com.fedex.connect.manager.service; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dao.log.UserLoginInfoMapper; | ||
| 5 | +import com.fedex.connect.common.dao.sys.RoleMapper; | ||
| 6 | +import com.fedex.connect.common.dao.sys.UserMapper; | ||
| 7 | +import com.fedex.connect.common.dao.sys.UserRoleMapper; | ||
| 8 | +import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; | ||
| 9 | +import com.fedex.connect.manager.dao.repository.log.IUserLoginLogRepository; | ||
| 10 | +import com.fedex.connect.manager.dao.repository.sys.*; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | + | ||
| 15 | +public class AbstractEtService { | ||
| 16 | + | ||
| 17 | + @Resource | ||
| 18 | + protected LocaleMessageUtil localeMessageUtil; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * repository | ||
| 22 | + */ | ||
| 23 | + @Autowired | ||
| 24 | + public IUserLoginLogRepository userLoginLogRepository; | ||
| 25 | + @Autowired | ||
| 26 | + public IRedisSlabRepository redisSlabRepository; | ||
| 27 | + @Autowired | ||
| 28 | + public IRoleRepository roleRepository; | ||
| 29 | + @Autowired | ||
| 30 | + public IUserRoleRepository userRoleRepository; | ||
| 31 | + @Autowired | ||
| 32 | + public IUserRepository userRepository; | ||
| 33 | + @Autowired | ||
| 34 | + public IDictionaryEntriesRepository dictionaryEntriesRepository; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Mapper--------------------------------------------- | ||
| 38 | + */ | ||
| 39 | + @Autowired | ||
| 40 | + protected UserMapper userMapper; | ||
| 41 | + | ||
| 42 | + @Autowired | ||
| 43 | + protected UserRoleMapper userRoleMapper; | ||
| 44 | + | ||
| 45 | + @Autowired | ||
| 46 | + protected RoleMapper roleMapper; | ||
| 47 | + | ||
| 48 | + @Autowired | ||
| 49 | + protected UserLoginInfoMapper userLoginInfoMapper; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * MapperExt--------------------------------------------- | ||
| 53 | + */ | ||
| 54 | + | ||
| 55 | +} |
| 1 | +package com.fedex.connect.manager.service.base.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.config.DictionaryProvider; | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 5 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 6 | +import com.fedex.connect.common.model.base.DictionaryEntriesExample; | ||
| 7 | +import com.fedex.connect.manager.data.model.LogShowModel; | ||
| 8 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 9 | +import com.fedex.connect.manager.service.base.IInitDictionaryEntriesService; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.core.annotation.Order; | ||
| 13 | +import org.springframework.stereotype.Component; | ||
| 14 | + | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 17 | +@Component | ||
| 18 | +@Order(value = 1) | ||
| 19 | +public class InitInitDictionaryEntriesServiceImpl extends AbstractEtService implements IInitDictionaryEntriesService { | ||
| 20 | + | ||
| 21 | + private static Logger log = LoggerFactory.getLogger(InitInitDictionaryEntriesServiceImpl.class); | ||
| 22 | + | ||
| 23 | + public List<DictionaryEntries> findAll() { | ||
| 24 | + try{ | ||
| 25 | + DictionaryEntriesExample example = new DictionaryEntriesExample(); | ||
| 26 | + DictionaryEntriesExample.Criteria criteria = example.createCriteria(); | ||
| 27 | + criteria.andStatusEqualTo(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 28 | + example.setOrderByClause("CREATE_TIME DESC"); | ||
| 29 | + return dictionaryEntriesRepository.selectByExample(example); | ||
| 30 | + } catch (Exception e){ | ||
| 31 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + public void initializeDictionary() { | ||
| 38 | + List<DictionaryEntries> data = findAll(); // 获取字典数据 | ||
| 39 | + DictionaryProvider.setDictionaryData(data); // 将数据设置到字典提供者中 | ||
| 40 | + } | ||
| 41 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/service/system/IRedisUtilService.java
0 → 100644
| 1 | +package com.fedex.connect.manager.service.system; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 4 | + | ||
| 5 | +public interface IRedisUtilService { | ||
| 6 | + Boolean set(String key, String value,int expireTimeH); | ||
| 7 | + | ||
| 8 | + Boolean set(String key, String value); | ||
| 9 | + | ||
| 10 | + RedisSlab get(String key, String value); | ||
| 11 | + | ||
| 12 | + RedisSlab get(String key); | ||
| 13 | + | ||
| 14 | + <T> T get(String key, Class<T> clazz); | ||
| 15 | + | ||
| 16 | + int del(String key); | ||
| 17 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/service/system/ISysAuthService.java
0 → 100644
| 1 | +package com.fedex.connect.manager.service.system; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.User; | ||
| 4 | +import com.fedex.connect.manager.data.dto.LoginRequest; | ||
| 5 | +import com.fedex.connect.manager.data.vo.JsonResult; | ||
| 6 | +import com.google.gson.JsonObject; | ||
| 7 | + | ||
| 8 | +public interface ISysAuthService { | ||
| 9 | + JsonResult createAccessToken(LoginRequest loginRequest, User user); | ||
| 10 | + | ||
| 11 | + JsonResult createFclToken(JsonObject token); | ||
| 12 | + | ||
| 13 | + JsonObject getFclToken(String tokenKey); | ||
| 14 | +} |
server/manager-server/src/main/java/com/fedex/connect/manager/service/system/ISysUserService.java
0 → 100644
| 1 | +package com.fedex.connect.manager.service.system; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.sys.User; | ||
| 4 | +import com.fedex.connect.manager.data.dto.SysUserDto; | ||
| 5 | + | ||
| 6 | +public interface ISysUserService { | ||
| 7 | + User findUserByFcl(String fclUuid); | ||
| 8 | + | ||
| 9 | + User save(SysUserDto dto); | ||
| 10 | + | ||
| 11 | + int update(User dao); | ||
| 12 | +} |
| 1 | +package com.fedex.connect.manager.service.system.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.util.GsonUtils; | ||
| 4 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 5 | +import com.fedex.connect.common.model.sys.RedisSlabExample; | ||
| 6 | +import com.fedex.connect.manager.data.bo.RedisSlabBo; | ||
| 7 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 8 | +import com.fedex.connect.manager.service.system.IRedisUtilService; | ||
| 9 | +import com.google.gson.Gson; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | +import org.springframework.transaction.annotation.Transactional; | ||
| 14 | +import org.springframework.util.CollectionUtils; | ||
| 15 | + | ||
| 16 | +import java.util.Optional; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +@Service | ||
| 20 | +public class RedisUtilServiceImpl extends AbstractEtService implements IRedisUtilService { | ||
| 21 | + | ||
| 22 | + private static Logger logger = LoggerFactory.getLogger(RedisUtilServiceImpl.class); | ||
| 23 | + | ||
| 24 | + @Transactional(rollbackFor = Exception.class) | ||
| 25 | + public Boolean set(String key, String value,int expireTimeH) { | ||
| 26 | + RedisSlab dao = RedisSlabBo.toDao(key,value, expireTimeH); | ||
| 27 | + | ||
| 28 | + RedisSlab redisSlab = get(key); | ||
| 29 | + if (redisSlab != null){ | ||
| 30 | + del(key); | ||
| 31 | + } | ||
| 32 | + try { | ||
| 33 | + int ct = redisSlabRepository.insert(dao); | ||
| 34 | + if (ct > 0) { | ||
| 35 | + return true; | ||
| 36 | + } | ||
| 37 | + return false; | ||
| 38 | + } catch (Exception e) { | ||
| 39 | + logger.error("REDIS SLAB 异常 [SET]: " + e); | ||
| 40 | + throw e; | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public Boolean set(String key, String value) { | ||
| 45 | + return set(key,value, 1); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public RedisSlab get(String key,String value){ | ||
| 49 | + try { | ||
| 50 | + RedisSlabExample example = new RedisSlabExample(); | ||
| 51 | + RedisSlabExample.Criteria criteria = example.createCriteria(); | ||
| 52 | + criteria.andRedisKeyEqualTo(key); | ||
| 53 | + criteria.andRedisMsgEqualTo(value); | ||
| 54 | + return CollectionUtils.firstElement(redisSlabRepository.selectByExample(example)); | ||
| 55 | + }catch (Exception e){ | ||
| 56 | + logger.error("REDIS SLAB 异常 [GET]: " + e); | ||
| 57 | + throw e; | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public RedisSlab get(String key){ | ||
| 62 | + try { | ||
| 63 | + RedisSlabExample example = new RedisSlabExample(); | ||
| 64 | + RedisSlabExample.Criteria criteria = example.createCriteria(); | ||
| 65 | + criteria.andRedisKeyEqualTo(key); | ||
| 66 | + return CollectionUtils.firstElement(redisSlabRepository.selectByExample(example)); | ||
| 67 | + }catch (Exception e){ | ||
| 68 | + logger.error("REDIS SLAB 异常 [GET]: " + e); | ||
| 69 | + throw e; | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public <T> T get(String key, Class<T> clazz) { | ||
| 74 | + try { | ||
| 75 | + RedisSlab redisSlab = get(key); | ||
| 76 | + String str = redisSlab != null ? Optional.ofNullable(redisSlab.getRedisMsg()).orElse(null): null; | ||
| 77 | + T t = GsonUtils.stringToBean(str, clazz); | ||
| 78 | + return t; | ||
| 79 | + }catch (Exception e){ | ||
| 80 | + logger.error("REDIS SLAB 异常 [GET]: " + e); | ||
| 81 | + throw e; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Transactional(rollbackFor = Exception.class) | ||
| 86 | + public int del(String key){ | ||
| 87 | + try { | ||
| 88 | + logger.info("del db redis key:{}",key); | ||
| 89 | + RedisSlab redisSlab = get(key); | ||
| 90 | + logger.info("del db redis key get info:{}", new Gson().toJson(redisSlab)); | ||
| 91 | + if (redisSlab != null){ | ||
| 92 | + logger.info("get info not null"); | ||
| 93 | + int delct = redisSlabRepository.deleteByPrimaryKey(redisSlab.getId()); | ||
| 94 | + logger.info("redisSlabRepository.deleteByPrimaryKey result :{}", delct); | ||
| 95 | + return delct; | ||
| 96 | + } | ||
| 97 | + return 0; | ||
| 98 | + }catch (Exception e){ | ||
| 99 | + logger.error("REDIS SLAB 异常 [DEL]: " + e); | ||
| 100 | + throw e; | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | +} |
| 1 | +package com.fedex.connect.manager.service.system.impl; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 5 | +import com.fedex.connect.common.dependencies.contants.RedisConstants; | ||
| 6 | +import com.fedex.connect.common.dependencies.enums.ResponseCode; | ||
| 7 | +import com.fedex.connect.common.dependencies.util.GsonUtils; | ||
| 8 | +import com.fedex.connect.common.dependencies.util.JwtTokenUtils; | ||
| 9 | +import com.fedex.connect.common.model.sys.RedisSlab; | ||
| 10 | +import com.fedex.connect.common.model.sys.Role; | ||
| 11 | +import com.fedex.connect.common.model.sys.User; | ||
| 12 | +import com.fedex.connect.manager.data.dto.LoginRequest; | ||
| 13 | +import com.fedex.connect.manager.data.vo.JsonResult; | ||
| 14 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 15 | +import com.fedex.connect.manager.service.system.IRedisUtilService; | ||
| 16 | +import com.fedex.connect.manager.service.system.ISysAuthService; | ||
| 17 | +import com.google.gson.JsonObject; | ||
| 18 | +import org.slf4j.Logger; | ||
| 19 | +import org.slf4j.LoggerFactory; | ||
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 21 | +import org.springframework.stereotype.Service; | ||
| 22 | + | ||
| 23 | +import java.util.ArrayList; | ||
| 24 | +import java.util.List; | ||
| 25 | +import java.util.Optional; | ||
| 26 | +import java.util.UUID; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * 处理用户相关Service | ||
| 30 | + * 包括创建用户token,用户的角色设置,角色的菜单设置 | ||
| 31 | + * @author EDY | ||
| 32 | + */ | ||
| 33 | +@Service | ||
| 34 | +public class SysAuthServiceImpl extends AbstractEtService implements ISysAuthService { | ||
| 35 | + | ||
| 36 | + private Logger logger = LoggerFactory.getLogger(SysAuthServiceImpl.class); | ||
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + private SysRoleServiceImpl sysRoleInfoService; | ||
| 40 | + | ||
| 41 | + @Autowired | ||
| 42 | + private IRedisUtilService redisUtilService; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 根据用户登录信息创建token | ||
| 46 | + * @param loginRequest | ||
| 47 | + * @param user | ||
| 48 | + * @return | ||
| 49 | + */ | ||
| 50 | + public JsonResult createAccessToken(LoginRequest loginRequest, User user) { | ||
| 51 | + //2、创建token | ||
| 52 | + List<String> roleCodeList = new ArrayList<>(); | ||
| 53 | + Role roleInfo = sysRoleInfoService.findRoleByUserId(user.getId()); | ||
| 54 | + if (roleInfo != null && roleInfo.getStatus() != null | ||
| 55 | + && DatabaseConstants.GLOBAL_STATUS_VALID.equals(roleInfo)){ | ||
| 56 | + roleCodeList.add("ROLE_" + roleInfo.getCode() + roleInfo.getCode()); | ||
| 57 | + }else{ | ||
| 58 | + roleCodeList.add("ROLE_" + UUID.randomUUID().toString()); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + //存进redis的token,8小时有效期 | ||
| 62 | + String token = JwtTokenUtils.createAccessToken(user.getAccNo(), user.getId().toString(), roleCodeList, loginRequest.getRememberMe()); | ||
| 63 | + try { | ||
| 64 | + int redisExpireTime = loginRequest.getRememberMe() ? 8 : 2; | ||
| 65 | + redisUtilService.set(RedisConstants.REDIS_KEY_TOKEN + user.getId(), token, redisExpireTime); | ||
| 66 | + } catch (NullPointerException e) { | ||
| 67 | + logger.error("***************** redis 异常:{} *********************", e); | ||
| 68 | + return JsonResult.fail(ResponseCode.SYSTEM_EXECEPTION_CODE.getCode(), localeMessageUtil.getMessage("service_auth_token_reeids"), null); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + return JsonResult.succ(token); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 根据用户登录信息创建token | ||
| 77 | + * @param token token信息 | ||
| 78 | + * @return token key | ||
| 79 | + */ | ||
| 80 | + public JsonResult createFclToken(JsonObject token) { | ||
| 81 | + String tokenKey = DatabaseConstants.FCL_PREFIX + UUID.randomUUID(); | ||
| 82 | + try { | ||
| 83 | + /*redisUtilService.set(RedisConstants.REDIS_KEY_TOKEN + tokenKey, GsonUtils.beanToString(token), RedisConstants.REDIS_EXPRIE_TIME_1W);*/ | ||
| 84 | + redisUtilService.set(RedisConstants.REDIS_KEY_TOKEN + tokenKey, GsonUtils.beanToString(token), 1); | ||
| 85 | + } catch (NullPointerException e) { | ||
| 86 | + logger.error("***************** redis 异常:{} *********************", e); | ||
| 87 | + return JsonResult.fail(ResponseCode.SYSTEM_EXECEPTION_CODE.getCode(), localeMessageUtil.getMessage("service_auth_token_reeids"), null); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + return JsonResult.succ(tokenKey); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 根据token key 获取token | ||
| 95 | + * @param tokenKey tokenkey | ||
| 96 | + * @return token | ||
| 97 | + */ | ||
| 98 | + public JsonObject getFclToken(String tokenKey) { | ||
| 99 | + RedisSlab redisSlab = redisUtilService.get(RedisConstants.REDIS_KEY_TOKEN + tokenKey); | ||
| 100 | + String token = redisSlab != null ? Optional.ofNullable(redisSlab.getRedisMsg()).orElse(null): null; | ||
| 101 | + //清除登录记录 | ||
| 102 | + if (token != null){ | ||
| 103 | + redisUtilService.del(RedisConstants.REDIS_KEY_TOKEN + tokenKey); | ||
| 104 | + } | ||
| 105 | + return GsonUtils.stringToBean(token, JsonObject.class); | ||
| 106 | + } | ||
| 107 | +} |
| 1 | +package com.fedex.connect.manager.service.system.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.config.CacheSystem; | ||
| 4 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 5 | +import com.fedex.connect.common.dependencies.util.Utils; | ||
| 6 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 7 | +import com.fedex.connect.common.model.sys.Role; | ||
| 8 | +import com.fedex.connect.common.model.sys.RoleExample; | ||
| 9 | +import com.fedex.connect.common.model.sys.UserRole; | ||
| 10 | +import com.fedex.connect.common.model.sys.UserRoleExample; | ||
| 11 | +import com.fedex.connect.manager.data.model.LogShowModel; | ||
| 12 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 13 | +import com.fedex.connect.manager.service.system.ISysRoleService; | ||
| 14 | +import org.slf4j.Logger; | ||
| 15 | +import org.slf4j.LoggerFactory; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | +import org.springframework.transaction.annotation.Transactional; | ||
| 18 | + | ||
| 19 | +import java.util.Date; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Map; | ||
| 22 | +import java.util.Objects; | ||
| 23 | +import java.util.stream.Collectors; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 处理角色相关Service | ||
| 27 | + * @author EDY | ||
| 28 | + */ | ||
| 29 | +@Service | ||
| 30 | +public class SysRoleServiceImpl extends AbstractEtService implements ISysRoleService { | ||
| 31 | + | ||
| 32 | + private static Logger log = LoggerFactory.getLogger(SysRoleServiceImpl.class); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 根据用户ID获取用户角色 | ||
| 36 | + * @param userId | ||
| 37 | + * @return | ||
| 38 | + */ | ||
| 39 | + public Role findRoleByUserId(Long userId){ | ||
| 40 | + try{ | ||
| 41 | + UserRole userRole = findUserRoleByUserId(userId); | ||
| 42 | + if (userRole == null || userRole.getRoleId() == null || userRole.getRoleId() == 0){ | ||
| 43 | + return null; | ||
| 44 | + } | ||
| 45 | + return findById(userRole.getRoleId()); | ||
| 46 | + } catch (Exception e){ | ||
| 47 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 48 | + return null; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 根据用户ID获取用户角色对应关系(一个用户只允许存在一个角色) | ||
| 54 | + * @param userId | ||
| 55 | + * @return | ||
| 56 | + */ | ||
| 57 | + public UserRole findUserRoleByUserId(Long userId){ | ||
| 58 | + try{ | ||
| 59 | + UserRoleExample example = new UserRoleExample(); | ||
| 60 | + UserRoleExample.Criteria criteria = example.createCriteria(); | ||
| 61 | + criteria.andStatusEqualTo(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 62 | + criteria.andUserIdEqualTo(userId); | ||
| 63 | + example.setOrderByClause("CREATE_TIME DESC"); | ||
| 64 | + return Utils.first(userRoleRepository.selectByExample(example)); | ||
| 65 | + } catch (Exception e){ | ||
| 66 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 67 | + return null; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 根据ID获取角色对象 | ||
| 73 | + * @param id | ||
| 74 | + * @return | ||
| 75 | + */ | ||
| 76 | + public Role findById(Long id){ | ||
| 77 | + try{ | ||
| 78 | + return roleRepository.selectByPrimaryKey(id); | ||
| 79 | + } catch (Exception e){ | ||
| 80 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 81 | + return null; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 根据code获取角色信息(当前阶段,如果不存在,则创建默认角色) | ||
| 87 | + * @param roleCode | ||
| 88 | + * @return | ||
| 89 | + */ | ||
| 90 | + public Role findRoleByCode(String roleCode){ | ||
| 91 | + try{ | ||
| 92 | + RoleExample example = new RoleExample(); | ||
| 93 | + RoleExample.Criteria criteria = example.createCriteria(); | ||
| 94 | + criteria.andStatusEqualTo(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 95 | + criteria.andCodeEqualTo(roleCode); | ||
| 96 | + List<Role> roleInfoList = roleRepository.selectByExample(example); | ||
| 97 | + | ||
| 98 | + //如果不存在,创建默认角色 | ||
| 99 | + if (roleInfoList == null || roleInfoList.isEmpty()){ | ||
| 100 | + Role defaultRole = new Role(); | ||
| 101 | + defaultRole.setCode(DatabaseConstants.DICT_ROLE_DEFAULT_CODE); | ||
| 102 | + defaultRole.setName(DatabaseConstants.DICT_ROLE_DEFAULT_CODE.toUpperCase()); | ||
| 103 | + defaultRole.setRoleDesc(DatabaseConstants.DICT_ROLE_DEFAULT_CODE.toUpperCase()); | ||
| 104 | + | ||
| 105 | + //从数据字典获取角色类型 | ||
| 106 | + List<DictionaryEntries> userTypeList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_ROLE_GOOUP_CODE); | ||
| 107 | + if (userTypeList != null && !userTypeList.isEmpty()){ | ||
| 108 | + Map<String,DictionaryEntries> userTypeDictMap = Utils.listOf(userTypeList).stream().filter(Objects::nonNull) | ||
| 109 | + .collect(Collectors.toMap(DictionaryEntries::getCode, d -> d)); | ||
| 110 | + DictionaryEntries dictionary = userTypeDictMap.get(DatabaseConstants.DICT_ROLE_DEFAULT_CODE); | ||
| 111 | + defaultRole.setTypeId(dictionary == null ? 0 : dictionary.getId()); | ||
| 112 | + } else { | ||
| 113 | + defaultRole.setTypeId(0L); | ||
| 114 | + } | ||
| 115 | + defaultRole.setStatus(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 116 | + defaultRole.setCreateTime(new Date()); | ||
| 117 | + save(defaultRole); | ||
| 118 | + | ||
| 119 | + return defaultRole; | ||
| 120 | + } else { | ||
| 121 | + return roleInfoList.get(0); | ||
| 122 | + } | ||
| 123 | + } catch (Exception e){ | ||
| 124 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 125 | + return null; | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * 保存角色 | ||
| 131 | + * @param dao | ||
| 132 | + * @return | ||
| 133 | + */ | ||
| 134 | + @Transactional(rollbackFor = Exception.class) | ||
| 135 | + public int save(Role dao){ | ||
| 136 | + try{ | ||
| 137 | + return roleRepository.insert(dao); | ||
| 138 | + } catch (Exception e){ | ||
| 139 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 140 | + throw e; | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | +} |
| 1 | +package com.fedex.connect.manager.service.system.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 4 | +import com.fedex.connect.common.model.sys.UserRole; | ||
| 5 | +import com.fedex.connect.manager.data.model.LogShowModel; | ||
| 6 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 7 | +import com.fedex.connect.manager.service.system.ISysUserRoleService; | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.transaction.annotation.Transactional; | ||
| 12 | + | ||
| 13 | +import java.util.Date; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 处理用户角色Service | ||
| 17 | + * @author EDY | ||
| 18 | + */ | ||
| 19 | +@Service | ||
| 20 | +public class SysUserRoleServiceImpl extends AbstractEtService implements ISysUserRoleService { | ||
| 21 | + | ||
| 22 | + private static Logger log = LoggerFactory.getLogger(SysUserRoleServiceImpl.class); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 保存用户角色关系 | ||
| 26 | + * @param userId | ||
| 27 | + * @param roleId | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + @Transactional(rollbackFor = Exception.class) | ||
| 31 | + public int save(Long userId,Long roleId){ | ||
| 32 | + try{ | ||
| 33 | + UserRole userRole = new UserRole(); | ||
| 34 | + userRole.setUserId(userId); | ||
| 35 | + userRole.setRoleId(roleId); | ||
| 36 | + userRole.setStatus(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 37 | + userRole.setCreateTime(new Date()); | ||
| 38 | + userRole.setUpdateTime(new Date()); | ||
| 39 | + return userRoleRepository.insert(userRole); | ||
| 40 | + } catch (Exception e){ | ||
| 41 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 42 | + throw e; | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | +} |
| 1 | +package com.fedex.connect.manager.service.system.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.arithmetic.AESUtil; | ||
| 4 | +import com.fedex.connect.common.dependencies.authentication.EncryptProvider; | ||
| 5 | +import com.fedex.connect.common.dependencies.config.CacheSystem; | ||
| 6 | +import com.fedex.connect.common.dependencies.contants.DatabaseConstants; | ||
| 7 | +import com.fedex.connect.common.dependencies.util.Utils; | ||
| 8 | +import com.fedex.connect.common.model.base.DictionaryEntries; | ||
| 9 | +import com.fedex.connect.common.model.sys.Role; | ||
| 10 | +import com.fedex.connect.common.model.sys.User; | ||
| 11 | +import com.fedex.connect.common.model.sys.UserExample; | ||
| 12 | +import com.fedex.connect.manager.data.dto.SysUserDto; | ||
| 13 | +import com.fedex.connect.manager.data.model.LogShowModel; | ||
| 14 | +import com.fedex.connect.manager.service.AbstractEtService; | ||
| 15 | +import com.fedex.connect.manager.service.system.ISysRoleService; | ||
| 16 | +import com.fedex.connect.manager.service.system.ISysUserRoleService; | ||
| 17 | +import com.fedex.connect.manager.service.system.ISysUserService; | ||
| 18 | +import org.apache.commons.lang3.StringUtils; | ||
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 21 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 22 | +import org.springframework.beans.factory.annotation.Value; | ||
| 23 | +import org.springframework.stereotype.Service; | ||
| 24 | +import org.springframework.transaction.annotation.Transactional; | ||
| 25 | + | ||
| 26 | +import java.util.List; | ||
| 27 | +import java.util.Map; | ||
| 28 | +import java.util.Objects; | ||
| 29 | +import java.util.stream.Collectors; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * 用户相关操作 | ||
| 33 | + */ | ||
| 34 | +@Service | ||
| 35 | +public class SysUserServiceImpl extends AbstractEtService implements ISysUserService { | ||
| 36 | + | ||
| 37 | + private static Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); | ||
| 38 | + | ||
| 39 | + @Autowired | ||
| 40 | + private ISysRoleService sysRoleService; | ||
| 41 | + | ||
| 42 | + @Autowired | ||
| 43 | + private ISysUserRoleService sysUserRoleService; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 邮件过期时间 | ||
| 47 | + */ | ||
| 48 | + @Value("${export.emailActiveTime}") | ||
| 49 | + private String emailActiveTime ; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 根据FCL查询FCL用户信息 | ||
| 53 | + * @param fclUuid | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + public User findUserByFcl(String fclUuid){ | ||
| 57 | + try{ | ||
| 58 | + String fcl_pwd = DatabaseConstants.FCL_PREFIX + "_" + fclUuid + "_pwd"; | ||
| 59 | + | ||
| 60 | + UserExample example = new UserExample(); | ||
| 61 | + UserExample.Criteria criteria = example.createCriteria(); | ||
| 62 | + criteria.andStatusEqualTo(DatabaseConstants.GLOBAL_STATUS_VALID); | ||
| 63 | + criteria.andUserSourceEqualTo(DatabaseConstants.USER_SOURCE_FCL); | ||
| 64 | + criteria.andAccNoEqualTo(fclUuid); | ||
| 65 | + //criteria.andFedexAccNoEqualTo(fclUuid); | ||
| 66 | + example.setOrderByClause("ID DESC"); | ||
| 67 | + | ||
| 68 | + //根据账号 Fedex账户,备注查询用户信息 | ||
| 69 | + List<User> userList = userRepository.selectByExample(example); | ||
| 70 | + //查询出来的用户信息进行密码匹配 | ||
| 71 | + List<User> resultUserList = Utils.listOf(userList).stream().filter(Objects::nonNull) | ||
| 72 | + .filter(u -> EncryptProvider.match(fcl_pwd, u.getPassword())) | ||
| 73 | + .collect(Collectors.toList()); | ||
| 74 | + //返回匹配出来第一个账户信息 | ||
| 75 | + return Utils.first(resultUserList); | ||
| 76 | + } catch (Exception e){ | ||
| 77 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 保存 | ||
| 84 | + * @param dto | ||
| 85 | + * @return | ||
| 86 | + */ | ||
| 87 | + public User save(SysUserDto dto){ | ||
| 88 | + try{ | ||
| 89 | + User user = SysUserDto.dtoToDao(dto); | ||
| 90 | + //从数据字典获取用户类型 | ||
| 91 | + List<DictionaryEntries> userTypeList = CacheSystem.dictionaryMap.get(DatabaseConstants.DICT_USER_GOOUP_CODE); | ||
| 92 | + if (Utils.isNotEmpty(userTypeList)){ | ||
| 93 | + //从数据字典中获取用户类型 | ||
| 94 | + Map<String,DictionaryEntries> userTypeDictMap = Utils.listOf(userTypeList).stream().filter(Objects::nonNull) | ||
| 95 | + .collect(Collectors.toMap(DictionaryEntries::getCode, d -> d)); | ||
| 96 | + DictionaryEntries dictionary = userTypeDictMap.get(dto.getTypeCode()); | ||
| 97 | + user.setTypeId(dictionary == null ? 0 : dictionary.getId()); | ||
| 98 | + } else{ | ||
| 99 | + user.setTypeId(0L); | ||
| 100 | + } | ||
| 101 | + //对新增账户的密码进行加密 | ||
| 102 | + user.setPassword(EncryptProvider.encrypt(user.getPassword())); | ||
| 103 | + //对手机号进行可逆加密 | ||
| 104 | + if (!StringUtils.isBlank(user.getPhone())){ | ||
| 105 | + user.setPhone(AESUtil.encode_default(user.getPhone())); | ||
| 106 | + } | ||
| 107 | + //对用户姓名进行可逆加密 | ||
| 108 | + if (StringUtils.isNotBlank(user.getUserName())){ | ||
| 109 | + user.setUserName(user.getUserName()); | ||
| 110 | + } | ||
| 111 | + int saveUserCt = saveSysUser(user); | ||
| 112 | + | ||
| 113 | + //当前阶段,权限采用默认权限 | ||
| 114 | + if (saveUserCt > 0){ | ||
| 115 | + Role roleInfo = sysRoleService.findRoleByCode(DatabaseConstants.DICT_ROLE_DEFAULT_CODE); | ||
| 116 | + //创建用户角色对应关系 | ||
| 117 | + sysUserRoleService.save(user.getId(), roleInfo.getId()); | ||
| 118 | + } | ||
| 119 | + return user; | ||
| 120 | + } catch (Exception e){ | ||
| 121 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Transactional(rollbackFor = Exception.class) | ||
| 127 | + public int saveSysUser(User user){ | ||
| 128 | + try{ | ||
| 129 | + return userRepository.insert(user); | ||
| 130 | + } catch (Exception e){ | ||
| 131 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 132 | + throw e; | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * 修改 | ||
| 138 | + * @param dao | ||
| 139 | + * @return | ||
| 140 | + */ | ||
| 141 | + @Transactional(rollbackFor = Exception.class) | ||
| 142 | + public int update(User dao){ | ||
| 143 | + try{ | ||
| 144 | + return userRepository.updateByPrimaryKeySelective(dao); | ||
| 145 | + } catch (Exception e){ | ||
| 146 | + log.error(LogShowModel.showException("Exception",e)); | ||
| 147 | + throw e; | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + | ||
| 152 | +} |
-
Please register or login to post a comment