|
@@ -1,21 +1,31 @@
|
|
|
package cn.com.qmth.scancentral.service.impl;
|
|
|
|
|
|
import cn.com.qmth.scancentral.bean.ImportUserDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.User;
|
|
|
import cn.com.qmth.scancentral.dao.UserDao;
|
|
|
import cn.com.qmth.scancentral.entity.UserEntity;
|
|
|
import cn.com.qmth.scancentral.enums.Role;
|
|
|
import cn.com.qmth.scancentral.service.SessionService;
|
|
|
import cn.com.qmth.scancentral.service.UserService;
|
|
|
+import cn.com.qmth.scancentral.util.PageUtil;
|
|
|
import cn.com.qmth.scancentral.vo.AuditorVo;
|
|
|
import cn.com.qmth.scancentral.vo.CreateCountVo;
|
|
|
import cn.com.qmth.scancentral.vo.UpdateCountVo;
|
|
|
-import cn.com.qmth.scancentral.vo.UserVo;
|
|
|
+import cn.com.qmth.scancentral.vo.user.UserEdit;
|
|
|
+import cn.com.qmth.scancentral.vo.user.UserQuery;
|
|
|
+import cn.com.qmth.scancentral.vo.user.UserVo;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.boot.core.collection.PageResult;
|
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -27,6 +37,8 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private SessionService sessionService;
|
|
|
|
|
@@ -137,13 +149,80 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
|
|
|
@Override
|
|
|
public List<UserVo> findAdmin() {
|
|
|
- List<UserVo> list = new ArrayList<UserVo>();
|
|
|
+ List<UserVo> list = new ArrayList<>();
|
|
|
List<UserEntity> users = this.findByRole(Role.AUDITOR, Role.SCHOOL_ADMIN, Role.SCAN_ADMIN);
|
|
|
for (UserEntity user : users) {
|
|
|
- UserVo vo = new UserVo(user);
|
|
|
- vo.setOnline(sessionService.checkAuditorOnline(user.getLoginName()));
|
|
|
+ UserVo vo = new UserVo();
|
|
|
+ vo.setId(user.getId());
|
|
|
+ vo.setLoginName(user.getLoginName());
|
|
|
+ vo.setRole(user.getRole());
|
|
|
+ vo.setRoleName(user.getRole().getName());
|
|
|
+ vo.setEnable(user.getEnable());
|
|
|
list.add(vo);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<UserVo> findUserPage(UserQuery query, User user) {
|
|
|
+ IPage<UserVo> iPage = baseMapper.pageUser(new Page<>(query.getPageNumber(), query.getPageSize()), query);
|
|
|
+ iPage.getRecords().forEach(vo -> {
|
|
|
+ vo.setRoleName(vo.getRole().getName());
|
|
|
+ });
|
|
|
+ return PageUtil.of(iPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long saveUser(UserEdit user) {
|
|
|
+ if (StringUtils.isBlank(user.getLoginName())) {
|
|
|
+ throw new ParameterException("账号不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.length(user.getLoginName()) > 50) {
|
|
|
+ throw new ParameterException("账号50字以内");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(user.getPassword())) {
|
|
|
+ throw new ParameterException("密码不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.length(user.getPassword()) > 50) {
|
|
|
+ throw new ParameterException("密码50字以内");
|
|
|
+ }
|
|
|
+ if (user.getRole() == null) {
|
|
|
+ throw new ParameterException("角色不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user.getId() != null) {
|
|
|
+ // 修改
|
|
|
+ UserEntity userEntity = this.getById(user.getId());
|
|
|
+ if (userEntity == null) {
|
|
|
+ throw new ParameterException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(UserEntity::getUpdateTime, System.currentTimeMillis());
|
|
|
+ updateWrapper.set(UserEntity::getUpdaterId, user.getOperateUserId());
|
|
|
+ updateWrapper.set(UserEntity::getPassword, user.getPassword());
|
|
|
+ updateWrapper.eq(UserEntity::getId, user.getId());
|
|
|
+ this.update(updateWrapper);
|
|
|
+
|
|
|
+ return user.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增
|
|
|
+ UserEntity userEntity = new UserEntity();
|
|
|
+ userEntity.setRole(user.getRole());
|
|
|
+ userEntity.setLoginName(user.getLoginName());
|
|
|
+ userEntity.setName(user.getLoginName());
|
|
|
+ userEntity.setPassword(user.getPassword());
|
|
|
+ userEntity.setEnable(true);
|
|
|
+ userEntity.setCreatorId(user.getOperateUserId());
|
|
|
+ userEntity.setUpdaterId(user.getOperateUserId());
|
|
|
+ userEntity.setCreateTime(System.currentTimeMillis());
|
|
|
+ userEntity.setUpdateTime(System.currentTimeMillis());
|
|
|
+
|
|
|
+ this.save(userEntity);
|
|
|
+ log.warn("新增用户成功! userId:{}", userEntity.getId());
|
|
|
+
|
|
|
+ return userEntity.getId();
|
|
|
+ }
|
|
|
+
|
|
|
}
|