|
@@ -1,23 +1,22 @@
|
|
|
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.admin.entity.vo.RankVo;
|
|
|
import com.gis.admin.mapper.SysBaseMapper;
|
|
|
import com.gis.admin.service.IntegralService;
|
|
|
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.constant.TypeCode;
|
|
|
-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;
|
|
@@ -25,14 +24,15 @@ 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.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 java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
@@ -42,10 +42,8 @@ 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;
|
|
|
|
|
|
@Autowired
|
|
|
SysRoleService sysRoleService;
|
|
@@ -56,9 +54,15 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Autowired
|
|
|
IntegralService integralService;
|
|
|
|
|
|
+ @Qualifier("IBaseService")
|
|
|
+ @Autowired
|
|
|
+ IBaseService iBaseService;
|
|
|
+
|
|
|
@Autowired
|
|
|
SysBaseMapper sysBaseMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
|
|
/**重置密码redis key*/
|
|
|
final static String RESET_PASSWORD_KEY = "reset_password_";
|
|
@@ -66,14 +70,10 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
// 目前是12h
|
|
|
private static Integer LEVEL_EXPIRE = 1000 * 60 * 60 * 12;
|
|
|
|
|
|
- @Override
|
|
|
- public IBaseMapper<SysUserEntity, Long> getBaseMapper() {
|
|
|
- return this.entityMapper;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public SysUserEntity findByUserName(String userName) {
|
|
|
- return entityMapper.findByUserName(userName);
|
|
|
+ return baseMapper.findByUserName(userName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -91,14 +91,14 @@ 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("用户不存在");
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(entity);
|
|
|
+ this.updateById(entity);
|
|
|
|
|
|
// 更新密码
|
|
|
String oldPassword = param.getOldPassword();
|
|
@@ -127,7 +127,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();
|
|
|
Set<String> roleKeys = sysRoleService.findRoleKeyByUserId(id);
|
|
@@ -137,22 +138,62 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
}
|
|
|
entity.setIsDelete(1);
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(entity);
|
|
|
+ this.updateById(entity);
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+// }
|
|
|
+@Override
|
|
|
+public Result<SysUserEntity> search(UserPageDateDto param) {
|
|
|
+ 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("'");
|
|
|
}
|
|
|
|
|
|
+ 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(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long roleId = param.getRoleId();
|
|
|
+ if (roleId != null) {
|
|
|
+ sql.append(" and c.id=").append(roleId);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 = baseMapper.search(sql.toString(), page);
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
private void updatePassword(PasswordDto param) {
|
|
|
- SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+// SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+ SysUserEntity user = this.findByUserName(iBaseService.getUserName());
|
|
|
|
|
|
// 验证原密码
|
|
|
Boolean isBoolean = PasswordUtils.decrypt(user.getPassword(), param.getOldPassword(), PasswordUtils.getStaticSalt());
|
|
@@ -163,7 +204,7 @@ 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
|
|
@@ -173,7 +214,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();
|
|
@@ -193,12 +235,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);
|
|
@@ -207,14 +249,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("用户不存在");
|
|
@@ -229,7 +271,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
user.setIsEnabled(isEnabled);
|
|
|
user.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(user);
|
|
|
+ this.updateById(user);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -259,21 +301,24 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
sysRoleService.saveUserRole(userId, Long.valueOf("2"));
|
|
|
|
|
|
// 保存操作日志
|
|
|
- logService.save(new LogEntity(userId,"用户注册","新增用户", request.getRemoteAddr()));
|
|
|
+// 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
|
|
|
public Result<SysUserEntity> detail(Long id) {
|
|
|
|
|
|
- SysUserEntity user = entityMapper.detailMapper(id);
|
|
|
+ SysUserEntity user = baseMapper.detailMapper(id);
|
|
|
// 获取用户积分
|
|
|
Integer grade = integralService.totalGrade(id);
|
|
|
Integer gradeToday = integralService.totalGradeToday(id);
|
|
@@ -293,7 +338,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Override
|
|
|
public Result retrievePassword(ResetPasswordDto param) {
|
|
|
String userName = param.getUserName();
|
|
|
- SysUserEntity entity = entityMapper.findByUserName(param.getUserName());
|
|
|
+ SysUserEntity entity = baseMapper.findByUserName(param.getUserName());
|
|
|
if (entity == null) {
|
|
|
return Result.success(false);
|
|
|
}
|
|
@@ -313,7 +358,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Override
|
|
|
public Result updatePwdByWeb(PasswordDto param) {
|
|
|
String userName = param.getUserName();
|
|
|
- SysUserEntity entity = entityMapper.findByUserName(userName);
|
|
|
+ SysUserEntity entity = baseMapper.findByUserName(userName);
|
|
|
if (entity == null) {
|
|
|
return Result.failure(MsgCode.e3001, "对象不存在");
|
|
|
}
|
|
@@ -336,7 +381,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
long entTime = System.currentTimeMillis();
|
|
|
long onlineTime = (entTime - startTime) / 1000;
|
|
|
log.info("此次登录在线时长:{}", onlineTime);
|
|
|
- entityMapper.updateOnlineTime(userId, onlineTime);
|
|
|
+ baseMapper.updateOnlineTime(userId, onlineTime);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -356,7 +401,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
if (grade >= rankVo.getExp()){
|
|
|
// 有效期12小时
|
|
|
redisUtil.set(redisKey, grade+"", LEVEL_EXPIRE);
|
|
|
- entityMapper.updateLevel(userId, rankVo.getLevel());
|
|
|
+ baseMapper.updateLevel(userId, rankVo.getLevel());
|
|
|
break;
|
|
|
}
|
|
|
}
|