Commit 8fb5fd4c authored by YangZhaoJun1's avatar YangZhaoJun1

调整接口

parent 2ade57d6
...@@ -97,6 +97,7 @@ public class BLessonController extends PaginationController<BLesson> { ...@@ -97,6 +97,7 @@ public class BLessonController extends PaginationController<BLesson> {
@PostMapping(value = "picImport") @PostMapping(value = "picImport")
@PreAuthorize("hasRole('ROLE_1001')") @PreAuthorize("hasRole('ROLE_1001')")
public Result picImport(MultipartFile importFile,String code) throws Exception { public Result picImport(MultipartFile importFile,String code) throws Exception {
Result result = new Result();
String path = global.getBASE_UPLOAD_SERVER_LOCATION(); String path = global.getBASE_UPLOAD_SERVER_LOCATION();
String course_logo_path =global.getIMAGE_LOCATION()+global.getCOURCE_LOGO_LOCATION(); String course_logo_path =global.getIMAGE_LOCATION()+global.getCOURCE_LOGO_LOCATION();
boolean type = false; boolean type = false;
...@@ -118,6 +119,9 @@ public class BLessonController extends PaginationController<BLesson> { ...@@ -118,6 +119,9 @@ public class BLessonController extends PaginationController<BLesson> {
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
bLessonService.selectOne(code)); bLessonService.selectOne(code));
}else{ }else{
/* result.setErrorMessage((ResultServiceEnums.UPLOAD_FILE_ERROR).getMessage(),null);
return result;*/
throw new ServiceException(ResultServiceEnums.UPLOAD_FILE_ERROR); throw new ServiceException(ResultServiceEnums.UPLOAD_FILE_ERROR);
} }
} }
......
...@@ -44,11 +44,11 @@ public interface BStudentRepository extends BaseMapper<BStudent> { ...@@ -44,11 +44,11 @@ public interface BStudentRepository extends BaseMapper<BStudent> {
"FROM\n" + "FROM\n" +
"\tb_student b\n" + "\tb_student b\n" +
"LEFT JOIN s_user u ON b.`code` = u.login_name\n" + "LEFT JOIN s_user u ON b.`code` = u.login_name\n" +
" where b.del_flag != 1"+ " where b.del_flag != 1 "+
"<if test=\"name!=null\">and u.`name` like #{name}</if>"+ "<if test=\"name!=null and name != ''\">and u.`name` like CONCAT('%',#{name},'%') </if>"+
"<if test=\"code!=null\">and b.`code` like #{code}</if></script>") "<if test=\"code!=null and code != ''\">and b.`code` like CONCAT('%',#{code},'%') </if></script>")
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
List<BStudent> queryBStudents(Map<String, Object> param); List<BStudent> queryBStudents(BStudent param);
@Select("<script>SELECT\n" + @Select("<script>SELECT\n" +
"\tt3.`code`,t4.`name`\n" + "\tt3.`code`,t4.`name`\n" +
......
package org.rcisoft.business.bteacher.service.impl; package org.rcisoft.business.bteacher.service.impl;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.bsl.dao.BSlRepository; import org.rcisoft.business.bsl.dao.BSlRepository;
...@@ -9,12 +10,16 @@ import org.rcisoft.business.bteacher.service.BTeacherService; ...@@ -9,12 +10,16 @@ import org.rcisoft.business.bteacher.service.BTeacherService;
import org.rcisoft.common.component.Global; import org.rcisoft.common.component.Global;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.constant.UserConstant;
import org.rcisoft.core.entity.DataEntity; import org.rcisoft.core.entity.DataEntity;
import org.rcisoft.core.enums.UserSexEnum;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.ExcelUtil; import org.rcisoft.core.util.ExcelUtil;
import org.rcisoft.core.util.RegexValidateUtil;
import org.rcisoft.core.util.UserUtil; 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.SysUser;
import org.rcisoft.sys.user.entity.UserRole; import org.rcisoft.sys.user.entity.UserRole;
import org.rcisoft.sys.user.service.SysUserService; import org.rcisoft.sys.user.service.SysUserService;
...@@ -40,8 +45,8 @@ import java.util.Map; ...@@ -40,8 +45,8 @@ import java.util.Map;
public class BTeacherServiceImpl implements BTeacherService { public class BTeacherServiceImpl implements BTeacherService {
@Autowired @Autowired
private BTeacherRepository bTeacherRepository; private BTeacherRepository bTeacherRepository;
/*@Autowired @Autowired
private UserRepository userRepository;*/ private SysUserMapper sysUserMapper;
@Autowired @Autowired
private SysUserService userService; private SysUserService userService;
/*@Autowired /*@Autowired
...@@ -98,40 +103,39 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -98,40 +103,39 @@ public class BTeacherServiceImpl implements BTeacherService {
} }
//判断2:MySQL数据库中是否存在该用户; //判断2:MySQL数据库中是否存在该用户;
/*User user1 =new User(); SysUser user1 =new SysUser();
user1.setLoginName(value[0]); user1.setLoginName(value[0]);
if (userRepository.selectOne(user1) != null) { if (sysUserMapper.selectOne(user1) != null) {
//该用户已存在,记入codeRepeat中 //该用户已存在,记入codeRepeat中
valuesRepeat.add(value[0]); valuesRepeat.add(value[0]);
continue; continue;
}*/ }
//判断3:邮箱是否存在、格式是否正确; //判断3:邮箱是否存在、格式是否正确;
/*User user2 = new User(); SysUser user2 = new SysUser();
user2.setEmail(value[3]); user2.setEmail(value[3]);
boolean nullEmail = StringUtils.isEmpty(value[3]); boolean nullEmail = StringUtils.isEmpty(value[3]);
boolean emailCheck = RegexValidateUtil.checkEmail(value[3]); boolean emailCheck = RegexValidateUtil.checkEmail(value[3]);
boolean emailRepeat = userRepository.selectOne(user2)!=null; boolean emailRepeat = sysUserMapper.selectOne(user2)!=null;
if(nullEmail||!emailCheck||emailRepeat){ if(nullEmail||!emailCheck||emailRepeat){
valuesEmailExist.add(value[3]); valuesEmailExist.add(value[3]);
continue; continue;
}*/ }
//合法:通过了三次判断,证明可建立该用户 //合法:通过了三次判断,证明可建立该用户
valuesOK.add(value); valuesOK.add(value);
/* if (value[2].equals("女")) if (value[2].equals("女"))
value[2] = UserSexEnum.WOMEN.getCode(); value[2] = UserSexEnum.WOMEN.getCode();
else else
value[2] = UserSexEnum.MAN.getCode(); value[2] = UserSexEnum.MAN.getCode();
//1. 添加user //1. 添加user
User user = new User(value[0], UserConstant.INITIAL_PASSWORD, value[1], value[2]); //学号,密码,姓名,性别; SysUser user = new SysUser(value[0], UserConstant.INITIAL_PASSWORD, value[1], value[2]); //学号,密码,姓名,性别;
user.setEmail(value[3]); user.setEmail(value[3]);
user.setCommonBusinessId(); UserUtil.setCurrentPersistOperation(user);
UserUtils.setCurrentPersistOperation(user);
//2 创建gitlab账户 //2 创建gitlab账户
GitUser gitUser = new GitUser(); /*GitUser gitUser = new GitUser();
gitUser.setUsername(global.getGIT_LAB_STU_PREFIX()+value[0]); gitUser.setUsername(global.getGIT_LAB_STU_PREFIX()+value[0]);
gitUser.setName(value[1]); gitUser.setName(value[1]);
gitUser.setPassword(value[0]); gitUser.setPassword(value[0]);
...@@ -140,34 +144,34 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -140,34 +144,34 @@ public class BTeacherServiceImpl implements BTeacherService {
//3. 将gitlab账户信息保存进user里 //3. 将gitlab账户信息保存进user里
user.setGitLabId(accountDTO.getId()); user.setGitLabId(accountDTO.getId());
user.setGitLabUsername(accountDTO.getUsername()); user.setGitLabUsername(accountDTO.getUsername());
user.setGitLabImpressionToken(accountDTO.getImpersonationToken()); user.setGitLabImpressionToken(accountDTO.getImpersonationToken());*/
user.setHeadPic(global.getDEFAULT_STUDENT_LOCATION());*/ user.setHeadPic(global.getDEFAULT_STUDENT_LOCATION());
//4.添加用户权限 //4.添加用户权限
/*UserRole userRole = new UserRole(user.getBusinessId(), "cccccccc"); UserRole userRole = new UserRole(user.getBusinessId(), "cccccccc");
userRole.setCommonBusinessId();*/ userRole.setCommonBusinessId();
//创建完Gitlab账户后,将完整的User信息和UserRole计入users和userRoles中等待插入数据库 //创建完Gitlab账户后,将完整的User信息和UserRole计入users和userRoles中等待插入数据库
BTeacher bTeacher= new BTeacher(value[0]); BTeacher bTeacher= new BTeacher(value[0]);
/*UserUtil.setCurrentPersistOperation(bTeacher); UserUtil.setCurrentPersistOperation(bTeacher);
if (!teachers.contains(bTeacher)) { if (!teachers.contains(bTeacher)) {
teachers.add(bTeacher); teachers.add(bTeacher);
users.add(user); users.add(user);
userRoles.add(userRole); userRoles.add(userRole);
}*/ }
} }
String result = ""; String result = "";
/*if (teachers.size()>0){ if (teachers.size()>0){
int line1 = bTeacherRepository.insertList(teachers); int line1 = bTeacherRepository.insertList(teachers);
int line2 = userRepository.insertList(users); int line2 = sysUserMapper.insertList(users);
int line3 = userRepository.insertUserRoleList(userRoles); int line3 = sysUserMapper.insertUserRoleList(userRoles);
if (line1 != line2 || line1 != teachers.size() || line2 != users.size() || line1 != line3 || line3 != userRoles.size()) { if (line1 != line2 || line1 != teachers.size() || line2 != users.size() || line1 != line3 || line3 != userRoles.size()) {
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR); throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR);
}else{ }else{
result+="成功导入"+users.size()+"名教师。"; result+="成功导入"+users.size()+"名教师。";
} }
}*/ }
if(valuesRepeat.size()>0){ if(valuesRepeat.size()>0){
result+="以下教师的工号存在重复:"+ JSON.toJSONString(valuesRepeat)+"。"; result+="以下教师的工号存在重复:"+ JSON.toJSONString(valuesRepeat)+"。";
...@@ -195,6 +199,10 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -195,6 +199,10 @@ public class BTeacherServiceImpl implements BTeacherService {
//throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL); //throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL);
return new PersistModel(1, (ResultServiceEnums.TEACHER_HAS_SL).getMessage()); 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); int line = bTeacherRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
} }
...@@ -211,16 +219,16 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -211,16 +219,16 @@ public class BTeacherServiceImpl implements BTeacherService {
int line = 0; int line = 0;
BeanUtils.copyProperties((DataEntity) model, (DataEntity) user); BeanUtils.copyProperties((DataEntity) model, (DataEntity) user);
if (model.getBusinessId() == null) { if (model.getBusinessId() == null) {
/*if (userRepository.selectOne(new User(model.getCode())) != null) if (sysUserMapper.selectOne(new SysUser(model.getCode())) != null)
throw new ServiceException(ResultServiceEnums.TEACHER_EXISTS); throw new ServiceException(ResultServiceEnums.TEACHER_EXISTS);
User user1 = new User(); SysUser user1 = new SysUser();
user1.setEmail(model.getEmail()); user1.setEmail(model.getEmail());
if(userRepository.selectOne(user1)!=null) if(sysUserMapper.selectOne(user1)!=null)
throw new ServiceException(ResultServiceEnums.EMAIL_EXISTS); throw new ServiceException(ResultServiceEnums.EMAIL_EXISTS);
//1添加用户 //1添加用户
user.setHeadPic(global.getDEFAULT_TEACHER_LOCATION()); user.setHeadPic(global.getDEFAULT_TEACHER_LOCATION());
//1.1 创建git lab账户 //1.1 创建git lab账户
GitUser gitUser = new GitUser(); /*GitUser gitUser = new GitUser();
gitUser.setName(user.getName()); gitUser.setName(user.getName());
gitUser.setUsername(global.getGIT_LAB_TEA_PREFIX()+user.getLoginName()); gitUser.setUsername(global.getGIT_LAB_TEA_PREFIX()+user.getLoginName());
gitUser.setPassword(user.getLoginName()); gitUser.setPassword(user.getLoginName());
...@@ -229,27 +237,27 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -229,27 +237,27 @@ public class BTeacherServiceImpl implements BTeacherService {
//1.2 将git lab账户信息保存进user里 //1.2 将git lab账户信息保存进user里
user.setGitLabId(accountDTO.getId()); user.setGitLabId(accountDTO.getId());
user.setGitLabUsername(accountDTO.getUsername()); user.setGitLabUsername(accountDTO.getUsername());
user.setGitLabImpressionToken(accountDTO.getImpersonationToken()); user.setGitLabImpressionToken(accountDTO.getImpersonationToken());*/
userService.persistUser(user);*/ userService.persistUser(user);
//2添加用户权限 //2添加用户权限
UserRole userRole = new UserRole(user.getBusinessId(), "bbbbbbbb"); UserRole userRole = new UserRole(user.getBusinessId(), "bbbbbbbb");
userRole.setCommonBusinessId(); userRole.setCommonBusinessId();
//int line1 = userRepository.insertUserRole(userRole); int line1 = sysUserMapper.insertUserRole(userRole);
//添加教师 //添加教师
UserUtil.setCurrentPersistOperation(model); UserUtil.setCurrentPersistOperation(model);
line = bTeacherRepository.insertSelective(model); line = bTeacherRepository.insertSelective(model);
/* if (line1 != line) if (line1 != line)
throw new ServiceException(ResultServiceEnums.INSERT_ERROR);*/ throw new ServiceException(ResultServiceEnums.INSERT_ERROR);
} else { } else {
UserUtil.setCurrentMergeOperation(model); UserUtil.setCurrentMergeOperation(model);
line = bTeacherRepository.updateByPrimaryKeySelective(model); line = bTeacherRepository.updateByPrimaryKeySelective(model);
/*String uid = userRepository.selectUserIdByStuOrTeaId(model.getBusinessId(), "b_teacher"); String uid = sysUserMapper.selectUserIdByStuOrTeaId(model.getBusinessId(), "b_teacher");
if (uid == null) if (uid == null)
throw new ServiceException(ResultServiceEnums.STUDENT_NOT_EXISTS); throw new ServiceException(ResultServiceEnums.STUDENT_NOT_EXISTS);
userService.updateUser(user,uid,line);*/ userService.updateUser(user,uid,line);
} }
return new PersistModel(line); return new PersistModel(line);
} }
......
...@@ -81,7 +81,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -81,7 +81,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
if (handler instanceof HandlerMethod) { if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误” 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()); log.info(e.getMessage());
} else if (e instanceof AuthenticationException) { } else if (e instanceof AuthenticationException) {
if (e instanceof BadCredentialsException) if (e instanceof BadCredentialsException)
......
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";
}
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;
}
}
...@@ -8,7 +8,8 @@ public enum ResultCode { ...@@ -8,7 +8,8 @@ public enum ResultCode {
FAIL(400),//失败 FAIL(400),//失败
UNAUTHORIZED(401),//未认证(签名错误) UNAUTHORIZED(401),//未认证(签名错误)
NOT_FOUND(404),//接口不存在 NOT_FOUND(404),//接口不存在
INTERNAL_SERVER_ERROR(500);//服务器内部错误 INTERNAL_SERVER_ERROR(500),//服务器内部错误
SERVICE_ERROR(999);//自定义异常
public int code; public int code;
......
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;
}
}
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
...@@ -35,7 +35,6 @@ public class UserUtil { ...@@ -35,7 +35,6 @@ public class UserUtil {
/** /**
* 获取登录人 business_id * 获取登录人 business_id
* @param prop
* @return * @return
*/ */
public static String getAuthenBusinessId(){ public static String getAuthenBusinessId(){
......
package org.rcisoft.sys.user.dao; 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.ResultMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.sys.user.entity.SysUser; import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.entity.UserRole;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -18,4 +22,25 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -18,4 +22,25 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@ResultMap(value = "BaseResultMap") @ResultMap(value = "BaseResultMap")
List<SysUser> queryUserByName(String username); 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);
} }
...@@ -8,11 +8,13 @@ import lombok.NoArgsConstructor; ...@@ -8,11 +8,13 @@ import lombok.NoArgsConstructor;
import org.rcisoft.core.entity.IdEntity; import org.rcisoft.core.entity.IdEntity;
import org.rcisoft.sys.role.entity.SysRole; import org.rcisoft.sys.role.entity.SysRole;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.StringUtils;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -35,6 +37,48 @@ public class SysUser extends IdEntity<SysUser> { ...@@ -35,6 +37,48 @@ public class SysUser extends IdEntity<SysUser> {
/** 用户名 */ /** 用户名 */
private String name; 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 @Transient
......
...@@ -8,4 +8,8 @@ public interface SysUserService { ...@@ -8,4 +8,8 @@ public interface SysUserService {
PersistModel addUser(SysUser user); PersistModel addUser(SysUser user);
PersistModel persistUser(SysUser user);
void updateUser(SysUser user, String uid, int line);
} }
package org.rcisoft.sys.user.service.impl; 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.model.PersistModel;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.sys.user.dao.SysUserMapper; import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.entity.SysUser; import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.service.SysUserService; import org.rcisoft.sys.user.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
...@@ -21,4 +25,23 @@ public class SysUserServiceImpl implements SysUserService { ...@@ -21,4 +25,23 @@ public class SysUserServiceImpl implements SysUserService {
int line = sysUserMapper.insertSelective(user); int line = sysUserMapper.insertSelective(user);
return new PersistModel(line); 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);
}
}
} }
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
<select id="queryBClasss" resultMap="BaseResultMap"> <select id="queryBClasss" resultMap="BaseResultMap">
SELECT * FROM b_class b SELECT * FROM b_class b
WHERE b.del_flag != '1' WHERE b.del_flag != '1' and flag = 1
<if test="className!=null and className != ''"> <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>
<if test="studentNum!=null and studentNum != ''"> <if test="studentNum!=null and studentNum != ''">
AND b.student_num = #{studentNum} AND b.student_num = #{studentNum}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment