|
@@ -1,38 +1,33 @@
|
|
|
package com.gis.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+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.gis.admin.entity.dto.ResetPasswordDto;
|
|
|
import com.gis.admin.entity.po.SysRoleEntity;
|
|
|
-import com.gis.common.base.aop.WebControllerLog;
|
|
|
-import com.gis.common.base.entity.dto.PageDto;
|
|
|
import com.gis.common.base.entity.dto.UserPageDateDto;
|
|
|
-import com.gis.common.base.entity.po.LogEntity;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
-import com.gis.common.base.mapper.IBaseMapper;
|
|
|
+import com.gis.common.base.service.IBaseService;
|
|
|
import com.gis.common.base.service.LogService;
|
|
|
-import com.gis.common.base.service.impl.IBaseServiceImpl;
|
|
|
import com.gis.common.constant.MsgCode;
|
|
|
-import com.gis.common.util.Base64Converter;
|
|
|
-import com.gis.common.util.JwtUtil;
|
|
|
-import com.gis.common.util.PasswordUtils;
|
|
|
-import com.gis.common.util.Result;
|
|
|
+import com.gis.common.util.*;
|
|
|
import com.gis.admin.entity.dto.PasswordDto;
|
|
|
import com.gis.admin.entity.dto.UserDto;
|
|
|
-import com.gis.admin.entity.dto.RegisterDto;
|
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
|
import com.gis.admin.mapper.SysUserMapper;
|
|
|
import com.gis.admin.service.SysRoleService;
|
|
|
import com.gis.admin.service.SysUserService;
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.RandomUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import tk.mybatis.mapper.entity.Condition;
|
|
|
|
|
|
-import javax.validation.constraints.NotBlank;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
@@ -42,7 +37,7 @@ import java.util.Set;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> implements SysUserService {
|
|
|
+public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity> implements SysUserService {
|
|
|
|
|
|
@Autowired
|
|
|
private SysUserMapper entityMapper;
|
|
@@ -53,13 +48,18 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Autowired
|
|
|
LogService logService;
|
|
|
|
|
|
+ @Qualifier("IBaseService")
|
|
|
+ @Autowired
|
|
|
+ IBaseService iBaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
/**重置密码redis key*/
|
|
|
final static String RESET_PASSWORD_KEY = "reset:password:";
|
|
|
|
|
|
- @Override
|
|
|
- public IBaseMapper<SysUserEntity, Long> getBaseMapper() {
|
|
|
- return this.entityMapper;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public SysUserEntity findByUserName(String userName) {
|
|
@@ -81,7 +81,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
this.save(entity);
|
|
|
id = entity.getId();
|
|
|
} else {
|
|
|
- entity = this.findById(id);
|
|
|
+ entity = this.getById(id);
|
|
|
if (entity == null) {
|
|
|
log.error("用户不存在: {}", id);
|
|
|
return Result.failure("用户不存在");
|
|
@@ -91,17 +91,8 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(entity);
|
|
|
-
|
|
|
- // 更新密码
|
|
|
-// String oldPassword = param.getOldPassword();
|
|
|
-// String newPassword = param.getNewPassword();
|
|
|
-// if (oldPassword !=null && newPassword != null) {
|
|
|
-// PasswordDto dto = new PasswordDto();
|
|
|
-// dto.setOldPassword(oldPassword);
|
|
|
-// dto.setNewPassword(newPassword);
|
|
|
-// updatePassword(dto);
|
|
|
-// }
|
|
|
+ this.updateById(entity);
|
|
|
+
|
|
|
|
|
|
// 每次修改,删除用户角色表信息,重新添加, 系统管理员不能修改
|
|
|
if (userId!=1){
|
|
@@ -122,7 +113,8 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Override
|
|
|
public Result removes(String ids) {
|
|
|
|
|
|
- List<SysUserEntity> entityList = this.findByIds(ids);
|
|
|
+// List<SysUserEntity> entityList = this.findByIds(ids);
|
|
|
+ List<SysUserEntity> entityList = this.listByIds(Arrays.asList(ids));
|
|
|
for (SysUserEntity entity: entityList) {
|
|
|
Long id = entity.getId();
|
|
|
|
|
@@ -137,7 +129,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
}
|
|
|
entity.setIsDelete(1);
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(entity);
|
|
|
+ this.updateById(entity);
|
|
|
|
|
|
// 删除用户角色表的用户id, 不删除角色统计人数会有误
|
|
|
entityMapper.deleteUserRoleByUserId(id);
|
|
@@ -146,29 +138,54 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+// @Override
|
|
|
+// public Result<SysUserEntity> search(UserPageDateDto param) {
|
|
|
+// startPage(param);
|
|
|
+// PageInfo<SysUserEntity> page = new PageInfo<>(entityMapper.search(param));
|
|
|
+// return Result.success(page);
|
|
|
+// }
|
|
|
+
|
|
|
@Override
|
|
|
public Result<SysUserEntity> search(UserPageDateDto param) {
|
|
|
- startPage(param);
|
|
|
- PageInfo<SysUserEntity> page = new PageInfo<>(entityMapper.search(param));
|
|
|
- return Result.success(page);
|
|
|
- }
|
|
|
-
|
|
|
+ BaseUtil.startPage(param);
|
|
|
+
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+ sql.append("select a.*, c.role_name as roleName, c.id as roleId from sys_user a");
|
|
|
+ sql.append(" left join sys_user_role b on b.user_id=a.id");
|
|
|
+ sql.append(" left join sys_role c on c.id=b.role_id");
|
|
|
+ sql.append(" where a.is_delete=0 ");
|
|
|
+
|
|
|
+ String startTime = param.getStartTime();
|
|
|
+ String endTime = param.getEndTime();
|
|
|
+ if (StringUtils.isNotBlank(startTime) || StringUtils.isNotBlank(endTime)){
|
|
|
+ sql.append(" and a.create_time >= ").append("'").append(startTime).append("'");
|
|
|
+ sql.append(" and a.create_time <= ").append("'").append(endTime).append("'");
|
|
|
+ }
|
|
|
|
|
|
- private void updatePassword(PasswordDto param) {
|
|
|
- SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+ String searchKey = param.getSearchKey();
|
|
|
+ if (!StringUtils.isAllBlank(searchKey)) {
|
|
|
+ searchKey = StringUtils.trim(searchKey);
|
|
|
+ sql.append(" and (");
|
|
|
+ sql.append( "a.real_name like '%").append(searchKey).append("%'");
|
|
|
+// sql.append( " or a.unit like '%").append(searchKey).append("%'");
|
|
|
+ sql.append(")");
|
|
|
+ }
|
|
|
|
|
|
- // 验证原密码
|
|
|
- Boolean isBoolean = PasswordUtils.decrypt(user.getPassword(), param.getOldPassword(), PasswordUtils.getStaticSalt());
|
|
|
- if (!isBoolean) {
|
|
|
- log.error("原始密码错误");
|
|
|
- throw new BaseRuntimeException("原始密码错误");
|
|
|
+ Long roleId = param.getRoleId();
|
|
|
+ if (roleId != null) {
|
|
|
+ sql.append(" and c.id=").append(roleId);
|
|
|
}
|
|
|
|
|
|
- user.setPassword(PasswordUtils.encrypt(user.getUserName(), param.getNewPassword(), PasswordUtils.getStaticSalt()));
|
|
|
- user.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(user);
|
|
|
+ sql.append(" order by a.create_time desc");
|
|
|
+// log.info("sql: {}", sql.toString());
|
|
|
+
|
|
|
+ IPage<SysUserEntity> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
+ IPage<SysUserEntity> result = entityMapper.search(sql.toString(), page);
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Result updatePwd(PasswordDto param){
|
|
|
|
|
@@ -177,7 +194,8 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
String oldPassword = Base64Converter.decodePassword(param.getOldPassword());
|
|
|
param.setNewPassword(newPassword);
|
|
|
param.setOldPassword(oldPassword);
|
|
|
- SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+// SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+ SysUserEntity user = this.findByUserName(iBaseService.getUserName());
|
|
|
|
|
|
updatePwd(param, user, true);
|
|
|
return Result.success();
|
|
@@ -198,12 +216,12 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
user.setPassword(PasswordUtils.encrypt(user.getUserName(), param.getNewPassword(), PasswordUtils.getStaticSalt()));
|
|
|
user.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(user);
|
|
|
+ this.updateById(user);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result resetPass(Long id) {
|
|
|
- SysUserEntity user = this.findById(id);
|
|
|
+ SysUserEntity user = this.getById(id);
|
|
|
|
|
|
if (user == null) {
|
|
|
log.error("用户不存在: {}", id);
|
|
@@ -212,14 +230,14 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
user.setPassword(PasswordUtils.encrypt(user.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
user.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(user);
|
|
|
+ this.updateById(user);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result editStatus(Long id, Integer isEnabled) {
|
|
|
|
|
|
- SysUserEntity user = this.findById(id);
|
|
|
+ SysUserEntity user = this.getById(id);
|
|
|
if (user == null) {
|
|
|
log.error("用户不存在: {}", id);
|
|
|
return Result.failure("用户不存在");
|
|
@@ -234,45 +252,48 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
user.setIsEnabled(isEnabled);
|
|
|
user.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(user);
|
|
|
+ this.updateById(user);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Result register(RegisterDto param) {
|
|
|
- if (!param.getPassword().equals(param.getVerifyPassword())) {
|
|
|
- log.error("确认密码不一致");
|
|
|
- return Result.failure("确认密码不一致");
|
|
|
- }
|
|
|
-
|
|
|
- SysUserEntity entity = this.findByUserName(param.getUserName());
|
|
|
- if (entity != null) {
|
|
|
- log.error("该身份码已注册: {}", param.getUserName());
|
|
|
- return Result.failure("该身份码已注册");
|
|
|
- }
|
|
|
-
|
|
|
- entity = new SysUserEntity();
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
-
|
|
|
- entity.setPassword(PasswordUtils.encrypt(param.getUserName(), param.getPassword(), PasswordUtils.getStaticSalt()));
|
|
|
- // 默认启用
|
|
|
- entity.setIsEnabled(1);
|
|
|
- this.save(entity);
|
|
|
-
|
|
|
- // 设置默认角色, 2:sys_visitor游客角色
|
|
|
- Long userId = entity.getId();
|
|
|
- sysRoleService.saveUserRole(userId, Long.valueOf("2"));
|
|
|
-
|
|
|
- // 保存操作日志
|
|
|
- logService.save(new LogEntity(userId,"用户注册","新增用户", request.getRemoteAddr()));
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
+// @Override
|
|
|
+// public Result register(RegisterDto param) {
|
|
|
+// if (!param.getPassword().equals(param.getVerifyPassword())) {
|
|
|
+// log.error("确认密码不一致");
|
|
|
+// return Result.failure("确认密码不一致");
|
|
|
+// }
|
|
|
+//
|
|
|
+// SysUserEntity entity = this.findByUserName(param.getUserName());
|
|
|
+// if (entity != null) {
|
|
|
+// log.error("该身份码已注册: {}", param.getUserName());
|
|
|
+// return Result.failure("该身份码已注册");
|
|
|
+// }
|
|
|
+//
|
|
|
+// entity = new SysUserEntity();
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+//
|
|
|
+// entity.setPassword(PasswordUtils.encrypt(param.getUserName(), param.getPassword(), PasswordUtils.getStaticSalt()));
|
|
|
+// // 默认启用
|
|
|
+// entity.setIsEnabled(1);
|
|
|
+// this.save(entity);
|
|
|
+//
|
|
|
+// // 设置默认角色, 2:sys_visitor游客角色
|
|
|
+// Long userId = entity.getId();
|
|
|
+// sysRoleService.saveUserRole(userId, Long.valueOf("2"));
|
|
|
+//
|
|
|
+// // 保存操作日志
|
|
|
+// logService.save(new LogEntity(userId,"用户注册","新增用户", request.getRemoteAddr()));
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public Result getRole() {
|
|
|
- Condition condition = new Condition(SysRoleEntity.class);
|
|
|
- condition.and().andEqualTo("isEnabled", 1);
|
|
|
- return Result.success(sysRoleService.findAll(condition));
|
|
|
+// Condition condition = new Condition(SysRoleEntity.class);
|
|
|
+// condition.and().andEqualTo("isEnabled", 1);
|
|
|
+// return Result.success(sysRoleService.findAll(condition));
|
|
|
+ LambdaQueryWrapper<SysRoleEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysRoleEntity::getIsEnabled, 1);
|
|
|
+ return Result.success(sysRoleService.list(wrapper));
|
|
|
}
|
|
|
|
|
|
@Override
|