|
@@ -21,8 +21,8 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@Service
|
|
|
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
|
|
@@ -47,20 +47,77 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void saveUser(LoginUser user, UserSaveReq req) {
|
|
|
- checkUser(req);
|
|
|
-
|
|
|
- UserEntity userEntity = new UserEntity();
|
|
|
- userEntity.setOrgId(user.getOrgId());
|
|
|
- BeanUtils.copyProperties(req, userEntity);
|
|
|
-
|
|
|
- if (req.getId() == null) {
|
|
|
- userEntity.setEnable(Boolean.TRUE);
|
|
|
- userEntity.setPassword(DigestUtils.sha256Hex(Constants.DEFAULT_PASSWORD).toUpperCase());
|
|
|
- this.save(userEntity);
|
|
|
- } else {
|
|
|
- this.updateById(userEntity);
|
|
|
+ public UserVO info(Long id) {
|
|
|
+ UserEntity user = this.getById(id);
|
|
|
+ if (user == null) {
|
|
|
+ log.warn("当前用户不存在!userId:{}", id);
|
|
|
+ throw new StatusException("当前用户不存在");
|
|
|
}
|
|
|
+
|
|
|
+ UserVO vo = new UserVO();
|
|
|
+ vo.setId(user.getId());
|
|
|
+ vo.setLoginName(user.getLoginName());
|
|
|
+ vo.setName(user.getName());
|
|
|
+ vo.setMobile(user.getMobile());
|
|
|
+ vo.setEnable(user.getEnable());
|
|
|
+ vo.setRoleCode(user.getRole().name());
|
|
|
+ vo.setRoleName(user.getRole().getTitle());
|
|
|
+ vo.setCategoryId(user.getCategoryId());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void saveUser(LoginUser loginUser, UserSaveReq req) {
|
|
|
+ if (StringUtils.isBlank(req.getLoginName())) {
|
|
|
+ throw new StatusException("登录名不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(req.getName())) {
|
|
|
+ throw new StatusException("用户名不能为空");
|
|
|
+ }
|
|
|
+ if (req.getRoleCode() == null) {
|
|
|
+ throw new StatusException("请选择角色");
|
|
|
+ }
|
|
|
+ if (Role.TEACHING == req.getRoleCode() && req.getCategoryId() == null) {
|
|
|
+ throw new StatusException("请选择所属教学点");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (req.getId() != null) {
|
|
|
+ UserEntity existUser = this.getById(req.getId());
|
|
|
+ if (existUser == null) {
|
|
|
+ log.warn("当前用户不存在!userId:{}", req.getId());
|
|
|
+ throw new StatusException("当前用户不存在");
|
|
|
+ }
|
|
|
+ existUser.setRole(req.getRoleCode());
|
|
|
+ existUser.setName(req.getName());
|
|
|
+ existUser.setMobile(req.getMobile());
|
|
|
+ existUser.setCategoryId(req.getCategoryId());
|
|
|
+ existUser.setUpdateTime(System.currentTimeMillis());
|
|
|
+
|
|
|
+ this.saveOrUpdate(existUser);
|
|
|
+ log.warn("修改用户!userId:{}", existUser.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserEntity existUser = this.findUserByLoginName(loginUser.getOrgId(), req.getLoginName());
|
|
|
+ if (existUser != null) {
|
|
|
+ throw new StatusException("登录账号已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserEntity newUser = new UserEntity();
|
|
|
+ newUser.setOrgId(loginUser.getOrgId());
|
|
|
+ newUser.setRole(req.getRoleCode());
|
|
|
+ newUser.setLoginName(req.getLoginName());
|
|
|
+ newUser.setName(req.getName());
|
|
|
+ newUser.setMobile(req.getMobile());
|
|
|
+ newUser.setCategoryId(req.getCategoryId());
|
|
|
+ newUser.setEnable(Boolean.TRUE);
|
|
|
+ newUser.setFirstLogin(Boolean.TRUE);
|
|
|
+ newUser.setCreateTime(System.currentTimeMillis());
|
|
|
+ newUser.setUpdateTime(System.currentTimeMillis());
|
|
|
+ newUser.setPassword(DigestUtils.sha256Hex(Constants.DEFAULT_PASSWORD).toUpperCase());
|
|
|
+ this.save(newUser);
|
|
|
+ log.warn("新增用户!userId:{}", newUser.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -86,19 +143,4 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
log.warn("更新用户状态!userId:{} enable:{}", id, enable);
|
|
|
}
|
|
|
|
|
|
- private void checkUser(UserSaveReq req) {
|
|
|
- if (req.getRole() == null) {
|
|
|
- throw new StatusException("请选择角色");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(req.getLoginName())) {
|
|
|
- throw new StatusException("登录账号不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(req.getName())) {
|
|
|
- throw new StatusException("用户名称不能为空");
|
|
|
- }
|
|
|
- if (req.getRole().equals(Role.TEACHING) && req.getCategoryId() == null) {
|
|
|
- throw new StatusException("请选择所属教学点");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|