Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
8fb5fd4c
Commit
8fb5fd4c
authored
Dec 12, 2017
by
YangZhaoJun1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整接口
parent
2ade57d6
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
479 additions
and
78 deletions
+479
-78
BLessonController.java
...cisoft/business/blesson/controller/BLessonController.java
+4
-0
BStudentRepository.java
...org/rcisoft/business/bstudent/dao/BStudentRepository.java
+4
-4
BStudentServiceImpl.java
...t/business/bstudent/service/impl/BStudentServiceImpl.java
+43
-35
BTeacherServiceImpl.java
...t/business/bteacher/service/impl/BTeacherServiceImpl.java
+42
-34
MvcConfig.java
src/main/java/org/rcisoft/config/MvcConfig.java
+2
-1
UserConstant.java
src/main/java/org/rcisoft/core/constant/UserConstant.java
+12
-0
UserSexEnum.java
src/main/java/org/rcisoft/core/enums/UserSexEnum.java
+20
-0
ResultCode.java
src/main/java/org/rcisoft/core/result/ResultCode.java
+2
-1
DecryptDBPasswordUtility.java
.../java/org/rcisoft/core/util/DecryptDBPasswordUtility.java
+199
-0
RegexValidateUtil.java
src/main/java/org/rcisoft/core/util/RegexValidateUtil.java
+53
-0
UserUtil.java
src/main/java/org/rcisoft/core/util/UserUtil.java
+0
-1
SysUserMapper.java
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
+25
-0
SysUser.java
src/main/java/org/rcisoft/sys/user/entity/SysUser.java
+44
-0
SysUserService.java
...ain/java/org/rcisoft/sys/user/service/SysUserService.java
+4
-0
SysUserServiceImpl.java
...org/rcisoft/sys/user/service/impl/SysUserServiceImpl.java
+23
-0
BClassMapper.xml
.../resources/mapper/business/bclass/mapper/BClassMapper.xml
+2
-2
UserMapper.xml
src/main/resources/mapper/sys/user/mapper/UserMapper.xml
+0
-0
No files found.
src/main/java/org/rcisoft/business/blesson/controller/BLessonController.java
View file @
8fb5fd4c
...
...
@@ -97,6 +97,7 @@ public class BLessonController extends PaginationController<BLesson> {
@PostMapping
(
value
=
"picImport"
)
@PreAuthorize
(
"hasRole('ROLE_1001')"
)
public
Result
picImport
(
MultipartFile
importFile
,
String
code
)
throws
Exception
{
Result
result
=
new
Result
();
String
path
=
global
.
getBASE_UPLOAD_SERVER_LOCATION
();
String
course_logo_path
=
global
.
getIMAGE_LOCATION
()+
global
.
getCOURCE_LOGO_LOCATION
();
boolean
type
=
false
;
...
...
@@ -118,6 +119,9 @@ public class BLessonController extends PaginationController<BLesson> {
MessageConstant
.
MESSAGE_ALERT_ERROR
,
bLessonService
.
selectOne
(
code
));
}
else
{
/* result.setErrorMessage((ResultServiceEnums.UPLOAD_FILE_ERROR).getMessage(),null);
return result;*/
throw
new
ServiceException
(
ResultServiceEnums
.
UPLOAD_FILE_ERROR
);
}
}
...
...
src/main/java/org/rcisoft/business/bstudent/dao/BStudentRepository.java
View file @
8fb5fd4c
...
...
@@ -44,11 +44,11 @@ public interface BStudentRepository extends BaseMapper<BStudent> {
"FROM\n"
+
"\tb_student b\n"
+
"LEFT JOIN s_user u ON b.`code` = u.login_name\n"
+
" where b.del_flag != 1"
+
"<if test=\"name!=null
\">and u.`name` like #{name}
</if>"
+
"<if test=\"code!=null
\">and b.`code` like #{code}
</if></script>"
)
" where b.del_flag != 1
"
+
"<if test=\"name!=null
and name != ''\">and u.`name` like CONCAT('%',#{name},'%')
</if>"
+
"<if test=\"code!=null
and code != ''\">and b.`code` like CONCAT('%',#{code},'%')
</if></script>"
)
@ResultMap
(
value
=
"BaseResultMap"
)
List
<
BStudent
>
queryBStudents
(
Map
<
String
,
Object
>
param
);
List
<
BStudent
>
queryBStudents
(
BStudent
param
);
@Select
(
"<script>SELECT\n"
+
"\tt3.`code`,t4.`name`\n"
+
...
...
src/main/java/org/rcisoft/business/bstudent/service/impl/BStudentServiceImpl.java
View file @
8fb5fd4c
This diff is collapsed.
Click to expand it.
src/main/java/org/rcisoft/business/bteacher/service/impl/BTeacherServiceImpl.java
View file @
8fb5fd4c
package
org
.
rcisoft
.
business
.
bteacher
.
service
.
impl
;
import
com.alibaba.druid.util.StringUtils
;
import
com.alibaba.fastjson.JSON
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.rcisoft.business.bsl.dao.BSlRepository
;
...
...
@@ -9,12 +10,16 @@ import org.rcisoft.business.bteacher.service.BTeacherService;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.aop.PageUtil
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.constant.UserConstant
;
import
org.rcisoft.core.entity.DataEntity
;
import
org.rcisoft.core.enums.UserSexEnum
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.core.util.ExcelUtil
;
import
org.rcisoft.core.util.RegexValidateUtil
;
import
org.rcisoft.core.util.UserUtil
;
import
org.rcisoft.sys.user.dao.SysUserMapper
;
import
org.rcisoft.sys.user.entity.SysUser
;
import
org.rcisoft.sys.user.entity.UserRole
;
import
org.rcisoft.sys.user.service.SysUserService
;
...
...
@@ -40,8 +45,8 @@ import java.util.Map;
public
class
BTeacherServiceImpl
implements
BTeacherService
{
@Autowired
private
BTeacherRepository
bTeacherRepository
;
/*
@Autowired
private
UserRepository userRepository;*/
@Autowired
private
SysUserMapper
sysUserMapper
;
@Autowired
private
SysUserService
userService
;
/*@Autowired
...
...
@@ -98,40 +103,39 @@ public class BTeacherServiceImpl implements BTeacherService {
}
//判断2:MySQL数据库中是否存在该用户;
/*User user1 =new
User();
SysUser
user1
=
new
Sys
User
();
user1
.
setLoginName
(
value
[
0
]);
if (
userRepository
.selectOne(user1) != null) {
if
(
sysUserMapper
.
selectOne
(
user1
)
!=
null
)
{
//该用户已存在,记入codeRepeat中
valuesRepeat
.
add
(
value
[
0
]);
continue
;
}
*/
}
//判断3:邮箱是否存在、格式是否正确;
/*User user2 = new
User();
SysUser
user2
=
new
Sys
User
();
user2
.
setEmail
(
value
[
3
]);
boolean
nullEmail
=
StringUtils
.
isEmpty
(
value
[
3
]);
boolean
emailCheck
=
RegexValidateUtil
.
checkEmail
(
value
[
3
]);
boolean emailRepeat =
userRepository
.selectOne(user2)!=null;
boolean
emailRepeat
=
sysUserMapper
.
selectOne
(
user2
)!=
null
;
if
(
nullEmail
||!
emailCheck
||
emailRepeat
){
valuesEmailExist
.
add
(
value
[
3
]);
continue
;
}
*/
}
//合法:通过了三次判断,证明可建立该用户
valuesOK
.
add
(
value
);
/*
if (value[2].equals("女"))
if
(
value
[
2
].
equals
(
"女"
))
value
[
2
]
=
UserSexEnum
.
WOMEN
.
getCode
();
else
value
[
2
]
=
UserSexEnum
.
MAN
.
getCode
();
//1. 添加user
User user = new
User(value[0], UserConstant.INITIAL_PASSWORD, value[1], value[2]); //学号,密码,姓名,性别;
SysUser
user
=
new
Sys
User
(
value
[
0
],
UserConstant
.
INITIAL_PASSWORD
,
value
[
1
],
value
[
2
]);
//学号,密码,姓名,性别;
user
.
setEmail
(
value
[
3
]);
user.setCommonBusinessId();
UserUtils.setCurrentPersistOperation(user);
UserUtil
.
setCurrentPersistOperation
(
user
);
//2 创建gitlab账户
GitUser gitUser = new GitUser();
/*
GitUser gitUser = new GitUser();
gitUser.setUsername(global.getGIT_LAB_STU_PREFIX()+value[0]);
gitUser.setName(value[1]);
gitUser.setPassword(value[0]);
...
...
@@ -140,34 +144,34 @@ public class BTeacherServiceImpl implements BTeacherService {
//3. 将gitlab账户信息保存进user里
user.setGitLabId(accountDTO.getId());
user.setGitLabUsername(accountDTO.getUsername());
user.setGitLabImpressionToken(accountDTO.getImpersonationToken());
user.setHeadPic(global.getDEFAULT_STUDENT_LOCATION());
*/
user.setGitLabImpressionToken(accountDTO.getImpersonationToken());
*/
user
.
setHeadPic
(
global
.
getDEFAULT_STUDENT_LOCATION
());
//4.添加用户权限
/*
UserRole userRole = new UserRole(user.getBusinessId(), "cccccccc");
userRole.setCommonBusinessId();
*/
UserRole
userRole
=
new
UserRole
(
user
.
getBusinessId
(),
"cccccccc"
);
userRole
.
setCommonBusinessId
();
//创建完Gitlab账户后,将完整的User信息和UserRole计入users和userRoles中等待插入数据库
BTeacher
bTeacher
=
new
BTeacher
(
value
[
0
]);
/*
UserUtil.setCurrentPersistOperation(bTeacher);
UserUtil
.
setCurrentPersistOperation
(
bTeacher
);
if
(!
teachers
.
contains
(
bTeacher
))
{
teachers
.
add
(
bTeacher
);
users
.
add
(
user
);
userRoles
.
add
(
userRole
);
}
*/
}
}
String
result
=
""
;
/*
if (teachers.size()>0){
if
(
teachers
.
size
()>
0
){
int
line1
=
bTeacherRepository
.
insertList
(
teachers
);
int line2 =
userRepository
.insertList(users);
int line3 =
userRepository
.insertUserRoleList(userRoles);
int
line2
=
sysUserMapper
.
insertList
(
users
);
int
line3
=
sysUserMapper
.
insertUserRoleList
(
userRoles
);
if
(
line1
!=
line2
||
line1
!=
teachers
.
size
()
||
line2
!=
users
.
size
()
||
line1
!=
line3
||
line3
!=
userRoles
.
size
())
{
throw
new
ServiceException
(
ResultServiceEnums
.
EXCEL_IMPORT_DB_INSERT_ERROR
);
}
else
{
result
+=
"成功导入"
+
users
.
size
()+
"名教师。"
;
}
}
*/
}
if
(
valuesRepeat
.
size
()>
0
){
result
+=
"以下教师的工号存在重复:"
+
JSON
.
toJSONString
(
valuesRepeat
)+
"。"
;
...
...
@@ -195,6 +199,10 @@ public class BTeacherServiceImpl implements BTeacherService {
//throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL);
return
new
PersistModel
(
1
,
(
ResultServiceEnums
.
TEACHER_HAS_SL
).
getMessage
());
}
BTeacher
bTeacher
=
new
BTeacher
();
bTeacher
.
setBusinessId
(
id
);
BTeacher
teacher
=
bTeacherRepository
.
selectOne
(
bTeacher
);
sysUserMapper
.
deleteByPrimaryKey
(
teacher
.
getCode
());
int
line
=
bTeacherRepository
.
deleteByPrimaryKey
(
id
);
return
new
PersistModel
(
line
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
);
}
...
...
@@ -211,16 +219,16 @@ public class BTeacherServiceImpl implements BTeacherService {
int
line
=
0
;
BeanUtils
.
copyProperties
((
DataEntity
)
model
,
(
DataEntity
)
user
);
if
(
model
.
getBusinessId
()
==
null
)
{
/*if (userRepository.selectOne(new
User(model.getCode())) != null)
if
(
sysUserMapper
.
selectOne
(
new
Sys
User
(
model
.
getCode
()))
!=
null
)
throw
new
ServiceException
(
ResultServiceEnums
.
TEACHER_EXISTS
);
User user1 = new
User();
SysUser
user1
=
new
Sys
User
();
user1
.
setEmail
(
model
.
getEmail
());
if(
userRepository
.selectOne(user1)!=null)
if
(
sysUserMapper
.
selectOne
(
user1
)!=
null
)
throw
new
ServiceException
(
ResultServiceEnums
.
EMAIL_EXISTS
);
//1添加用户
user
.
setHeadPic
(
global
.
getDEFAULT_TEACHER_LOCATION
());
//1.1 创建git lab账户
GitUser gitUser = new GitUser();
/*
GitUser gitUser = new GitUser();
gitUser.setName(user.getName());
gitUser.setUsername(global.getGIT_LAB_TEA_PREFIX()+user.getLoginName());
gitUser.setPassword(user.getLoginName());
...
...
@@ -229,27 +237,27 @@ public class BTeacherServiceImpl implements BTeacherService {
//1.2 将git lab账户信息保存进user里
user.setGitLabId(accountDTO.getId());
user.setGitLabUsername(accountDTO.getUsername());
user.setGitLabImpressionToken(accountDTO.getImpersonationToken());
userService.persistUser(user);
*/
user.setGitLabImpressionToken(accountDTO.getImpersonationToken());
*/
userService
.
persistUser
(
user
);
//2添加用户权限
UserRole
userRole
=
new
UserRole
(
user
.
getBusinessId
(),
"bbbbbbbb"
);
userRole
.
setCommonBusinessId
();
//int line1 = userRepository
.insertUserRole(userRole);
int
line1
=
sysUserMapper
.
insertUserRole
(
userRole
);
//添加教师
UserUtil
.
setCurrentPersistOperation
(
model
);
line
=
bTeacherRepository
.
insertSelective
(
model
);
/*
if (line1 != line)
throw new ServiceException(ResultServiceEnums.INSERT_ERROR);
*/
if
(
line1
!=
line
)
throw
new
ServiceException
(
ResultServiceEnums
.
INSERT_ERROR
);
}
else
{
UserUtil
.
setCurrentMergeOperation
(
model
);
line
=
bTeacherRepository
.
updateByPrimaryKeySelective
(
model
);
/*String uid = userRepository
.selectUserIdByStuOrTeaId(model.getBusinessId(), "b_teacher");
String
uid
=
sysUserMapper
.
selectUserIdByStuOrTeaId
(
model
.
getBusinessId
(),
"b_teacher"
);
if
(
uid
==
null
)
throw
new
ServiceException
(
ResultServiceEnums
.
STUDENT_NOT_EXISTS
);
userService.updateUser(user,uid,line);
*/
userService
.
updateUser
(
user
,
uid
,
line
);
}
return
new
PersistModel
(
line
);
}
...
...
src/main/java/org/rcisoft/config/MvcConfig.java
View file @
8fb5fd4c
...
...
@@ -81,7 +81,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
if
(
handler
instanceof
HandlerMethod
)
{
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
if
(
e
instanceof
ServiceException
)
{
//业务失败的异常,如“账号或密码错误”
result
=
ResultGenerator
.
genFailResult
(
e
.
getMessage
());
result
.
setCode
(
ResultCode
.
SERVICE_ERROR
).
setMessage
(
e
.
getMessage
());
//result = ResultGenerator.genFailResult(e.getMessage());
log
.
info
(
e
.
getMessage
());
}
else
if
(
e
instanceof
AuthenticationException
)
{
if
(
e
instanceof
BadCredentialsException
)
...
...
src/main/java/org/rcisoft/core/constant/UserConstant.java
0 → 100644
View file @
8fb5fd4c
package
org
.
rcisoft
.
core
.
constant
;
import
org.rcisoft.core.util.DecryptDBPasswordUtility
;
/**
* Created by gaowenfeng on 2017/7/31.
*/
public
class
UserConstant
{
public
static
final
String
INITIAL_PASSWORD
=
DecryptDBPasswordUtility
.
encryptNoException
(
"123456"
)
;
public
static
final
String
DEL_FLAG
=
"1"
;
}
src/main/java/org/rcisoft/core/enums/UserSexEnum.java
0 → 100644
View file @
8fb5fd4c
package
org
.
rcisoft
.
core
.
enums
;
/**
* Created by gaowenfeng on 2017/7/31.
*/
public
enum
UserSexEnum
{
MAN
(
"0"
),
WOMEN
(
"1"
);
private
String
code
;
UserSexEnum
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getCode
()
{
return
code
;
}
}
src/main/java/org/rcisoft/core/result/ResultCode.java
View file @
8fb5fd4c
...
...
@@ -8,7 +8,8 @@ public enum ResultCode {
FAIL
(
400
),
//失败
UNAUTHORIZED
(
401
),
//未认证(签名错误)
NOT_FOUND
(
404
),
//接口不存在
INTERNAL_SERVER_ERROR
(
500
);
//服务器内部错误
INTERNAL_SERVER_ERROR
(
500
),
//服务器内部错误
SERVICE_ERROR
(
999
);
//自定义异常
public
int
code
;
...
...
src/main/java/org/rcisoft/core/util/DecryptDBPasswordUtility.java
0 → 100644
View file @
8fb5fd4c
package
org
.
rcisoft
.
core
.
util
;
import
com.alibaba.druid.util.Base64
;
import
com.alibaba.druid.util.JdbcUtils
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
javax.crypto.Cipher
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileInputStream
;
import
java.security.*
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateFactory
;
import
java.security.interfaces.RSAPrivateKey
;
import
java.security.interfaces.RSAPublicKey
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.RSAPrivateKeySpec
;
import
java.security.spec.RSAPublicKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
/**
*
* @ProjectName:family
* @Description: 加密、解密数据库密码执行类
* @Copyright: Copyright (c) 2016
* @author: cy
* @date 2016年5月22日
*/
public
class
DecryptDBPasswordUtility
{
private
static
final
String
DEFAULT_PRIVATE_KEY_STRING
=
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAocbCrurZGbC5GArEHKlAfDSZi7gFBnd4yxOt0rwTqKBFzGyhtQLu5PRKjEiOXVa95aeIIBJ6OhC2f8FjqFUpawIDAQABAkAPejKaBYHrwUqUEEOe8lpnB6lBAsQIUFnQI/vXU4MV+MhIzW0BLVZCiarIQqUXeOhThVWXKFt8GxCykrrUsQ6BAiEA4vMVxEHBovz1di3aozzFvSMdsjTcYRRo82hS5Ru2/OECIQC2fAPoXixVTVY7bNMeuxCP4954ZkXp7fEPDINCjcQDywIgcc8XLkkPcs3Jxk7uYofaXaPbg39wuJpEmzPIxi3k0OECIGubmdpOnin3HuCP/bbjbJLNNoUdGiEmFL5hDI4UdwAdAiEAtcAwbm08bKN7pwwvyqaCBC//VnEWaq39DCzxr+Z2EIk="
;
public
static
final
String
DEFAULT_PUBLIC_KEY_STRING
=
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKHGwq7q2RmwuRgKxBypQHw0mYu4BQZ3eMsTrdK8E6igRcxsobUC7uT0SoxIjl1WveWniCASejoQtn/BY6hVKWsCAwEAAQ=="
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
password
=
"root"
;
String
decryptPassword
=
"P0yOB2GZpjo3ufAFp6K0eiJhoe2HJdenIV7ostZaSklUBpD9DN5Ffm/GZcsjc2GPnzYn2y/oHUKcqrMglgEf9Q=="
;
// String[] arr = genKeyPair(512);
// System.out.println("privateKey:" + arr[0]);
// System.out.println("publicKey:" + arr[1]);
System
.
out
.
println
(
"encrypt-password:"
+
encrypt
(
DEFAULT_PRIVATE_KEY_STRING
,
password
));
System
.
out
.
println
(
"decrypt-password:"
+
decrypt
(
DEFAULT_PUBLIC_KEY_STRING
,
decryptPassword
));
}
public
static
String
decrypt
(
String
cipherText
)
throws
Exception
{
return
decrypt
((
String
)
null
,
cipherText
);
}
public
static
String
decrypt
(
String
publicKeyText
,
String
cipherText
)
throws
Exception
{
PublicKey
publicKey
=
getPublicKey
(
publicKeyText
);
return
decrypt
(
publicKey
,
cipherText
);
}
public
static
PublicKey
getPublicKeyByX509
(
String
x509File
)
{
if
((
x509File
==
null
)
||
(
x509File
.
length
()
==
0
))
{
return
getPublicKey
(
null
);
}
FileInputStream
in
=
null
;
try
{
in
=
new
FileInputStream
(
x509File
);
CertificateFactory
factory
=
CertificateFactory
.
getInstance
(
"X.509"
);
Certificate
cer
=
factory
.
generateCertificate
(
in
);
return
cer
.
getPublicKey
();
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
"Failed to get public key"
,
e
);
}
finally
{
JdbcUtils
.
close
(
in
);
}
}
public
static
PublicKey
getPublicKey
(
String
publicKeyText
)
{
if
((
publicKeyText
==
null
)
||
(
publicKeyText
.
length
()
==
0
))
{
publicKeyText
=
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKHGwq7q2RmwuRgKxBypQHw0mYu4BQZ3eMsTrdK8E6igRcxsobUC7uT0SoxIjl1WveWniCASejoQtn/BY6hVKWsCAwEAAQ=="
;
}
try
{
byte
[]
publicKeyBytes
=
Base64
.
base64ToByteArray
(
publicKeyText
);
X509EncodedKeySpec
x509KeySpec
=
new
X509EncodedKeySpec
(
publicKeyBytes
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
return
keyFactory
.
generatePublic
(
x509KeySpec
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
"Failed to get public key"
,
e
);
}
}
public
static
PublicKey
getPublicKeyByPublicKeyFile
(
String
publicKeyFile
)
{
if
((
publicKeyFile
==
null
)
||
(
publicKeyFile
.
length
()
==
0
))
{
return
getPublicKey
(
null
);
}
FileInputStream
in
=
null
;
try
{
in
=
new
FileInputStream
(
publicKeyFile
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
int
len
=
0
;
byte
[]
b
=
new
byte
[
64
];
while
((
len
=
in
.
read
(
b
))
!=
-
1
)
{
out
.
write
(
b
,
0
,
len
);
}
byte
[]
publicKeyBytes
=
out
.
toByteArray
();
X509EncodedKeySpec
spec
=
new
X509EncodedKeySpec
(
publicKeyBytes
);
KeyFactory
factory
=
KeyFactory
.
getInstance
(
"RSA"
);
return
factory
.
generatePublic
(
spec
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
"Failed to get public key"
,
e
);
}
finally
{
JdbcUtils
.
close
(
in
);
}
}
public
static
String
decrypt
(
PublicKey
publicKey
,
String
cipherText
)
throws
Exception
{
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA"
);
try
{
cipher
.
init
(
2
,
publicKey
);
}
catch
(
InvalidKeyException
e
)
{
RSAPublicKey
rsaPublicKey
=
(
RSAPublicKey
)
publicKey
;
RSAPrivateKeySpec
spec
=
new
RSAPrivateKeySpec
(
rsaPublicKey
.
getModulus
(),
rsaPublicKey
.
getPublicExponent
());
Key
fakePrivateKey
=
KeyFactory
.
getInstance
(
"RSA"
).
generatePrivate
(
spec
);
cipher
=
Cipher
.
getInstance
(
"RSA"
);
cipher
.
init
(
2
,
fakePrivateKey
);
}
if
((
cipherText
==
null
)
||
(
cipherText
.
length
()
==
0
))
{
return
cipherText
;
}
byte
[]
cipherBytes
=
Base64
.
base64ToByteArray
(
cipherText
);
byte
[]
plainBytes
=
cipher
.
doFinal
(
cipherBytes
);
return
new
String
(
plainBytes
);
}
public
static
String
encrypt
(
String
plainText
)
throws
Exception
{
return
encrypt
((
String
)
null
,
plainText
);
}
public
static
String
encryptNoException
(
String
plainText
)
{
try
{
return
encrypt
((
String
)
null
,
plainText
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
ServiceException
(
ResultServiceEnums
.
PASSWORD_ENCODE
);
}
}
public
static
String
encrypt
(
String
key
,
String
plainText
)
throws
Exception
{
if
(
key
==
null
)
{
key
=
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAocbCrurZGbC5GArEHKlAfDSZi7gFBnd4yxOt0rwTqKBFzGyhtQLu5PRKjEiOXVa95aeIIBJ6OhC2f8FjqFUpawIDAQABAkAPejKaBYHrwUqUEEOe8lpnB6lBAsQIUFnQI/vXU4MV+MhIzW0BLVZCiarIQqUXeOhThVWXKFt8GxCykrrUsQ6BAiEA4vMVxEHBovz1di3aozzFvSMdsjTcYRRo82hS5Ru2/OECIQC2fAPoXixVTVY7bNMeuxCP4954ZkXp7fEPDINCjcQDywIgcc8XLkkPcs3Jxk7uYofaXaPbg39wuJpEmzPIxi3k0OECIGubmdpOnin3HuCP/bbjbJLNNoUdGiEmFL5hDI4UdwAdAiEAtcAwbm08bKN7pwwvyqaCBC//VnEWaq39DCzxr+Z2EIk="
;
}
byte
[]
keyBytes
=
Base64
.
base64ToByteArray
(
key
);
return
encrypt
(
keyBytes
,
plainText
);
}
public
static
String
encrypt
(
byte
[]
keyBytes
,
String
plainText
)
throws
Exception
{
PKCS8EncodedKeySpec
spec
=
new
PKCS8EncodedKeySpec
(
keyBytes
);
KeyFactory
factory
=
KeyFactory
.
getInstance
(
"RSA"
);
PrivateKey
privateKey
=
factory
.
generatePrivate
(
spec
);
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA"
);
try
{
cipher
.
init
(
1
,
privateKey
);
}
catch
(
InvalidKeyException
e
)
{
RSAPrivateKey
rsaPrivateKey
=
(
RSAPrivateKey
)
privateKey
;
RSAPublicKeySpec
publicKeySpec
=
new
RSAPublicKeySpec
(
rsaPrivateKey
.
getModulus
(),
rsaPrivateKey
.
getPrivateExponent
());
Key
fakePublicKey
=
KeyFactory
.
getInstance
(
"RSA"
).
generatePublic
(
publicKeySpec
);
cipher
=
Cipher
.
getInstance
(
"RSA"
);
cipher
.
init
(
1
,
fakePublicKey
);
}
byte
[]
encryptedBytes
=
cipher
.
doFinal
(
plainText
.
getBytes
(
"UTF-8"
));
String
encryptedString
=
Base64
.
byteArrayToBase64
(
encryptedBytes
);
return
encryptedString
;
}
public
static
byte
[][]
genKeyPairBytes
(
int
keySize
)
throws
NoSuchAlgorithmException
{
byte
[][]
keyPairBytes
=
new
byte
[
2
][];
KeyPairGenerator
gen
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
gen
.
initialize
(
keySize
,
new
SecureRandom
());
KeyPair
pair
=
gen
.
generateKeyPair
();
keyPairBytes
[
0
]
=
pair
.
getPrivate
().
getEncoded
();
keyPairBytes
[
1
]
=
pair
.
getPublic
().
getEncoded
();
return
keyPairBytes
;
}
public
static
String
[]
genKeyPair
(
int
keySize
)
throws
NoSuchAlgorithmException
{
byte
[][]
keyPairBytes
=
genKeyPairBytes
(
keySize
);
String
[]
keyPairs
=
new
String
[
2
];
keyPairs
[
0
]
=
Base64
.
byteArrayToBase64
(
keyPairBytes
[
0
]);
keyPairs
[
1
]
=
Base64
.
byteArrayToBase64
(
keyPairBytes
[
1
]);
return
keyPairs
;
}
}
src/main/java/org/rcisoft/core/util/RegexValidateUtil.java
0 → 100644
View file @
8fb5fd4c
package
org
.
rcisoft
.
core
.
util
;
/**
* Created by gaowenfeng on 2017/9/8.
*/
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 使用正则表达式验证输入格式
* @author liuxing
*
*/
public
class
RegexValidateUtil
{
// public static void main(String[] args) {
// System.out.println(checkEmail("14_8@qw.df"));
// System.out.println(checkMobileNumber("071-3534452"));
// }
/**
* 验证邮箱
* @param email
* @return
*/
public
static
boolean
checkEmail
(
String
email
){
boolean
flag
=
false
;
try
{
String
check
=
"^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"
;
Pattern
regex
=
Pattern
.
compile
(
check
);
Matcher
matcher
=
regex
.
matcher
(
email
);
flag
=
matcher
.
matches
();
}
catch
(
Exception
e
){
flag
=
false
;
}
return
flag
;
}
/**
* 验证手机号码
* @param mobileNumber
* @return
*/
public
static
boolean
checkMobileNumber
(
String
mobileNumber
){
boolean
flag
=
false
;
try
{
Pattern
regex
=
Pattern
.
compile
(
"^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$"
);
Matcher
matcher
=
regex
.
matcher
(
mobileNumber
);
flag
=
matcher
.
matches
();
}
catch
(
Exception
e
){
flag
=
false
;
}
return
flag
;
}
}
\ No newline at end of file
src/main/java/org/rcisoft/core/util/UserUtil.java
View file @
8fb5fd4c
...
...
@@ -35,7 +35,6 @@ public class UserUtil {
/**
* 获取登录人 business_id
* @param prop
* @return
*/
public
static
String
getAuthenBusinessId
(){
...
...
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
View file @
8fb5fd4c
package
org
.
rcisoft
.
sys
.
user
.
dao
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.ResultMap
;
import
org.apache.ibatis.annotations.Select
;
import
org.rcisoft.core.base.BaseMapper
;
import
org.rcisoft.sys.user.entity.SysUser
;
import
org.rcisoft.sys.user.entity.UserRole
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -18,4 +22,25 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@ResultMap
(
value
=
"BaseResultMap"
)
List
<
SysUser
>
queryUserByName
(
String
username
);
@Insert
(
"<script>INSERT INTO s_user"
+
"(create_date,update_date,create_by,update_by,remarks,del_flag,flag,business_id,login_name,password,name,sex,git_lab_id,git_lab_username,git_lab_impression_token,head_pic,email)VALUES"
+
"<foreach collection=\"list\" item=\"item\" separator=\",\">"
+
"( #{item.createDate},#{item.updateDate},#{item.createBy},#{item.updateBy},#{item.remarks},#{item.delFlag},#{item.flag},#{item.businessId},#{item.loginName},#{item.password},#{item.name},#{item.sex},#{item.gitLabId},#{item.gitLabUsername},#{item.gitLabImpressionToken},#{item.headPic},#{item.email})"
+
"</foreach></script>"
)
int
insertList
(
List
<
SysUser
>
users
);
@Insert
(
"<script>INSERT INTO s_r_user_role"
+
"(business_id,user_id,role_id)VALUES"
+
"<foreach collection=\"list\" item=\"item\" separator=\",\">"
+
"(#{item.businessId},#{item.userId},#{item.roleId})"
+
"</foreach></script>"
)
int
insertUserRoleList
(
List
<
UserRole
>
users
);
@Insert
(
"INSERT INTO s_r_user_role"
+
"(business_id,user_id,role_id)VALUES"
+
"(#{businessId},#{userId},#{roleId})"
)
int
insertUserRole
(
UserRole
userRole
);
@Select
(
"SELECT u.business_id from s_user u left join ${tab} s on u.login_name = s.code where s.business_id = #{id}"
)
String
selectUserIdByStuOrTeaId
(
@Param
(
"id"
)
String
id
,
@Param
(
"tab"
)
String
table
);
}
src/main/java/org/rcisoft/sys/user/entity/SysUser.java
View file @
8fb5fd4c
...
...
@@ -8,11 +8,13 @@ import lombok.NoArgsConstructor;
import
org.rcisoft.core.entity.IdEntity
;
import
org.rcisoft.sys.role.entity.SysRole
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.util.StringUtils
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
...
...
@@ -35,6 +37,48 @@ public class SysUser extends IdEntity<SysUser> {
/** 用户名 */
private
String
name
;
private
String
email
;
// 邮箱
private
String
phone
;
// 电话
private
String
sex
;
private
String
headPic
;
//头像
private
String
gitLabId
;
//gitLab账号id
private
String
gitLabUsername
;
//gitLab账号
private
String
gitLabImpressionToken
;
//gitLab账号模拟令牌
private
Date
loginDate
;
// 最后登陆日期
public
SysUser
(
String
loginName
){
this
.
loginName
=
loginName
;
}
public
SysUser
(
String
loginName
,
String
password
,
String
name
,
String
sex
)
{
this
.
loginName
=
loginName
;
this
.
password
=
password
;
this
.
name
=
name
;
this
.
sex
=
sex
;
}
public
boolean
isEmpty
(){
boolean
loginNameIsEmpty
=
StringUtils
.
isEmpty
(
loginName
);
boolean
passwordIsEmpty
=
StringUtils
.
isEmpty
(
password
);
boolean
nameIsEmpty
=
StringUtils
.
isEmpty
(
name
);
boolean
emailIsEmpty
=
StringUtils
.
isEmpty
(
email
);
boolean
phoneIsEmpty
=
StringUtils
.
isEmpty
(
phone
);
boolean
headPicIsEmpty
=
StringUtils
.
isEmpty
(
headPic
);
if
(
loginNameIsEmpty
&&
passwordIsEmpty
&&
nameIsEmpty
&&
emailIsEmpty
&&
phoneIsEmpty
&&
headPicIsEmpty
)
return
true
;
else
return
false
;
}
@Transient
...
...
src/main/java/org/rcisoft/sys/user/service/SysUserService.java
View file @
8fb5fd4c
...
...
@@ -8,4 +8,8 @@ public interface SysUserService {
PersistModel
addUser
(
SysUser
user
);
PersistModel
persistUser
(
SysUser
user
);
void
updateUser
(
SysUser
user
,
String
uid
,
int
line
);
}
src/main/java/org/rcisoft/sys/user/service/impl/SysUserServiceImpl.java
View file @
8fb5fd4c
package
org
.
rcisoft
.
sys
.
user
.
service
.
impl
;
import
org.rcisoft.core.constant.UserConstant
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.sys.user.dao.SysUserMapper
;
import
org.rcisoft.sys.user.entity.SysUser
;
import
org.rcisoft.sys.user.service.SysUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
...
...
@@ -21,4 +25,23 @@ public class SysUserServiceImpl implements SysUserService {
int
line
=
sysUserMapper
.
insertSelective
(
user
);
return
new
PersistModel
(
line
);
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
persistUser
(
SysUser
user
)
{
user
.
setCommonBusinessId
();
user
.
setPassword
(
UserConstant
.
INITIAL_PASSWORD
);
int
line
=
sysUserMapper
.
insertSelective
(
user
);
return
new
PersistModel
(
line
);
}
@Override
public
void
updateUser
(
SysUser
user
,
String
uid
,
int
line
)
{
if
(!
user
.
isEmpty
()){
user
.
setBusinessId
(
uid
);
int
l1
=
sysUserMapper
.
updateByPrimaryKeySelective
(
user
);
if
(
l1
!=
line
)
throw
new
ServiceException
(
ResultServiceEnums
.
UPDATE_ERROR
);
}
}
}
src/main/resources/mapper/business/bclass/mapper/BClassMapper.xml
View file @
8fb5fd4c
...
...
@@ -17,9 +17,9 @@
<select
id=
"queryBClasss"
resultMap=
"BaseResultMap"
>
SELECT * FROM b_class b
WHERE b.del_flag != '1'
WHERE b.del_flag != '1'
and flag = 1
<if
test=
"className!=null and className != ''"
>
AND
b.class_name LIKE CONCAT('%',#{className},'%') OR b.code LIKE CONCAT('%',#{className},'%'
)
AND
(b.class_name LIKE CONCAT('%',#{className},'%') OR b.code LIKE CONCAT('%',#{className},'%')
)
</if>
<if
test=
"studentNum!=null and studentNum != ''"
>
AND b.student_num = #{studentNum}
...
...
src/main/resources/mapper/sys/user/UserMapper.xml
→
src/main/resources/mapper/sys/user/
mapper/
UserMapper.xml
View file @
8fb5fd4c
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment