|
@@ -11,6 +11,7 @@ import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.exam.domain.ExamBefore;
|
|
|
import com.zhongzheng.modules.system.domain.SysPost;
|
|
|
import com.zhongzheng.modules.system.domain.SysUserPost;
|
|
|
import com.zhongzheng.modules.system.domain.SysUserRole;
|
|
@@ -213,6 +214,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public int insertUser(SysUser user) {
|
|
|
+ validEntityBeforeSave(user);
|
|
|
// 新增用户信息
|
|
|
user.setCode(ServletUtils.getEncoded("ZH"));
|
|
|
int rows = baseMapper.insert(user);
|
|
@@ -232,6 +234,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public int updateUser(SysUser user) {
|
|
|
+ validEntityBeforeSave(user);
|
|
|
// 新增用户与角色管理
|
|
|
if (!user.getStatus().equals(-1)) {
|
|
|
insertUserRole(user);
|
|
@@ -243,6 +246,28 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return baseMapper.updateById(user);
|
|
|
}
|
|
|
|
|
|
+ private void validEntityBeforeSave(SysUser entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ if(checkNameUnique(entity)){
|
|
|
+ throw new CustomException("账号名称重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkNameUnique(SysUser entity) {
|
|
|
+ SysUser info = getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getUserName,entity.getUserName()).ne(SysUser::getStatus,-1).last("limit 1"));
|
|
|
+ if (Validator.isNotNull(info)) {
|
|
|
+ if(Validator.isNotEmpty(entity.getUserId())){
|
|
|
+ if(entity.getUserId().longValue() != info.getUserId().longValue()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改用户状态
|
|
|
*
|