|
@@ -48,13 +48,11 @@ import cn.com.qmth.mps.vo.user.UserVo;
|
|
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
|
|
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
|
|
private static final String defPassWd = "123456";
|
|
private static final String defPassWd = "123456";
|
|
|
|
|
|
- private static final String[] EXCEL_HEADER = new String[] { "姓名", "登录名", "角色", "科目" };
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserCourseRelationService userCourseRelationService;
|
|
private UserCourseRelationService userCourseRelationService;
|
|
@Autowired
|
|
@Autowired
|
|
private SchoolService schoolService;
|
|
private SchoolService schoolService;
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public UserEntity getByLoginName(String phone) {
|
|
public UserEntity getByLoginName(String phone) {
|
|
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
|
|
@@ -122,13 +120,14 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public List<String> importUser(Long schoolId,User user, MultipartFile file) {
|
|
|
|
|
|
+ public List<String> importUser(Long schoolId, User user, MultipartFile file) {
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(schoolId)) {
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(schoolId)) {
|
|
throw new StatusException("非法操作");
|
|
throw new StatusException("非法操作");
|
|
}
|
|
}
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
try {
|
|
try {
|
|
- List<DataMap> lineList = ExcelReader.create(ExcelType.XLSX, inputStream, 4).getDataMapList();
|
|
|
|
|
|
+ inputStream = file.getInputStream();
|
|
|
|
+ List<DataMap> lineList = ExcelReader.create(ExcelType.XLSX, inputStream, 0).getDataMapList();
|
|
if (CollectionUtils.isEmpty(lineList)) {
|
|
if (CollectionUtils.isEmpty(lineList)) {
|
|
throw new StatusException("Excel无内容");
|
|
throw new StatusException("Excel无内容");
|
|
}
|
|
}
|
|
@@ -139,12 +138,6 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
List<UserDomain> userList = new ArrayList<>();
|
|
List<UserDomain> userList = new ArrayList<>();
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
DataMap line = lineList.get(i);
|
|
DataMap line = lineList.get(i);
|
|
- if (0 == i) {
|
|
|
|
- if (headerError(line)) {
|
|
|
|
- throw new StatusException("Excel表头错误");
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
|
|
StringBuilder msg = new StringBuilder();
|
|
StringBuilder msg = new StringBuilder();
|
|
|
|
|
|
@@ -178,7 +171,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
impuser.setRole(Role.getByName(role));
|
|
impuser.setRole(Role.getByName(role));
|
|
|
|
|
|
String coursecodes = trimAndNullIfBlank(line.getValue(3));
|
|
String coursecodes = trimAndNullIfBlank(line.getValue(3));
|
|
- if(StringUtils.isNotBlank(coursecodes)) {
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(coursecodes)) {
|
|
impuser.setCourse(Arrays.asList(coursecodes.split(",")));
|
|
impuser.setCourse(Arrays.asList(coursecodes.split(",")));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -207,10 +200,12 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
}
|
|
}
|
|
return failRecords;
|
|
return failRecords;
|
|
|
|
+ } catch (StatusException e) {
|
|
|
|
+ throw e;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- throw new StatusException("系统错误",e);
|
|
|
|
|
|
+ throw new StatusException("系统错误", e);
|
|
} finally {
|
|
} finally {
|
|
- if(inputStream!=null) {
|
|
|
|
|
|
+ if (inputStream != null) {
|
|
try {
|
|
try {
|
|
inputStream.close();
|
|
inputStream.close();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -218,31 +213,18 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- private boolean headerError(DataMap header) {
|
|
|
|
- if (EXCEL_HEADER.length != header.size()) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- for (int i = 0; i < EXCEL_HEADER.length; i++) {
|
|
|
|
- if (null == header.getValue(i)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- if (!EXCEL_HEADER[i].equals(header.getValue(i).trim())) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
private String trimAndNullIfBlank(String s) {
|
|
private String trimAndNullIfBlank(String s) {
|
|
if (StringUtils.isBlank(s)) {
|
|
if (StringUtils.isBlank(s)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
return s.trim();
|
|
return s.trim();
|
|
}
|
|
}
|
|
|
|
+
|
|
private String newError(int lineNum, String msg) {
|
|
private String newError(int lineNum, String msg) {
|
|
return "第" + lineNum + "行" + msg;
|
|
return "第" + lineNum + "行" + msg;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public PageResult<UserVo> page(UserQuery query, User user) {
|
|
public PageResult<UserVo> page(UserQuery query, User user) {
|
|
if (query.getSchoolId() == null) {
|
|
if (query.getSchoolId() == null) {
|
|
@@ -257,11 +239,11 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public UserVo info(Long id) {
|
|
public UserVo info(Long id) {
|
|
- UserEntity ue=this.getById(id);
|
|
|
|
|
|
+ UserEntity ue = this.getById(id);
|
|
if (ue == null) {
|
|
if (ue == null) {
|
|
throw new StatusException("未找到用户信息");
|
|
throw new StatusException("未找到用户信息");
|
|
}
|
|
}
|
|
- UserVo vo=new UserVo();
|
|
|
|
|
|
+ UserVo vo = new UserVo();
|
|
vo.setEnable(ue.getEnable());
|
|
vo.setEnable(ue.getEnable());
|
|
vo.setId(ue.getId());
|
|
vo.setId(ue.getId());
|
|
vo.setRoleId(ue.getRoleId());
|
|
vo.setRoleId(ue.getRoleId());
|
|
@@ -269,7 +251,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
vo.setName(ue.getName());
|
|
vo.setName(ue.getName());
|
|
vo.setSchoolId(ue.getSchoolId());
|
|
vo.setSchoolId(ue.getSchoolId());
|
|
vo.setSchoolName(schoolService.getById(ue.getSchoolId()).getName());
|
|
vo.setSchoolName(schoolService.getById(ue.getSchoolId()).getName());
|
|
- if(vo.getRoleId().equals(Role.SECTION_LEADER.getId())) {
|
|
|
|
|
|
+ if (vo.getRoleId().equals(Role.SECTION_LEADER.getId())) {
|
|
vo.setCourseCodes(userCourseRelationService.getCourseCodes(vo.getId()));
|
|
vo.setCourseCodes(userCourseRelationService.getCourseCodes(vo.getId()));
|
|
}
|
|
}
|
|
return vo;
|
|
return vo;
|
|
@@ -295,7 +277,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
String realPassword = StringEscapeUtils.unescapeJava(password);
|
|
String realPassword = StringEscapeUtils.unescapeJava(password);
|
|
byte[] bytes = SHA256.encode(realPassword);
|
|
byte[] bytes = SHA256.encode(realPassword);
|
|
String encodePassword = ByteUtil.toHexAscii(bytes);
|
|
String encodePassword = ByteUtil.toHexAscii(bytes);
|
|
- UserEntity ue=this.getById(userId);
|
|
|
|
|
|
+ UserEntity ue = this.getById(userId);
|
|
if (ue == null) {
|
|
if (ue == null) {
|
|
throw new StatusException("未找到用户信息");
|
|
throw new StatusException("未找到用户信息");
|
|
}
|
|
}
|
|
@@ -305,8 +287,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public void resetPass(Long schoolId,List<Long> ids, User accessUser) {
|
|
|
|
- String pw=ByteUtil.toHexAscii(SHA256.encode(defPassWd));
|
|
|
|
|
|
+ public void resetPass(Long schoolId, List<Long> ids, User accessUser) {
|
|
|
|
+ String pw = ByteUtil.toHexAscii(SHA256.encode(defPassWd));
|
|
UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
|
|
UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
|
|
LambdaUpdateWrapper<UserEntity> lw = wrapper.lambda();
|
|
LambdaUpdateWrapper<UserEntity> lw = wrapper.lambda();
|
|
lw.set(UserEntity::getPassword, pw);
|
|
lw.set(UserEntity::getPassword, pw);
|