创建用户,不允许相同帐号,且不允许修改帐号

This commit is contained in:
shuzheng 2017-05-12 14:46:06 +08:00
parent ea9afdb02b
commit 0b16ae4d4b
6 changed files with 25 additions and 12 deletions

View File

@ -10,5 +10,6 @@ import com.zheng.upms.dao.model.UpmsUserExample;
*/ */
public interface UpmsUserService extends BaseService<UpmsUser, UpmsUserExample> { public interface UpmsUserService extends BaseService<UpmsUser, UpmsUserExample> {
UpmsUser insert2(UpmsUser upmsUser); UpmsUser createUser(UpmsUser upmsUser);
} }

View File

@ -12,7 +12,8 @@ import com.zheng.upms.dao.model.UpmsUserExample;
public class UpmsUserServiceMock extends BaseServiceMock<UpmsUserMapper, UpmsUser, UpmsUserExample> implements UpmsUserService { public class UpmsUserServiceMock extends BaseServiceMock<UpmsUserMapper, UpmsUser, UpmsUserExample> implements UpmsUserService {
@Override @Override
public UpmsUser insert2(UpmsUser upmsUser) { public UpmsUser createUser(UpmsUser upmsUser) {
return null; return null;
} }
} }

View File

@ -27,8 +27,16 @@ public class UpmsUserServiceImpl extends BaseServiceImpl<UpmsUserMapper, UpmsUse
UpmsUserMapper upmsUserMapper; UpmsUserMapper upmsUserMapper;
@Override @Override
public UpmsUser insert2(UpmsUser upmsUser) { public UpmsUser createUser(UpmsUser upmsUser) {
UpmsUserExample upmsUserExample = new UpmsUserExample();
upmsUserExample.createCriteria()
.andUsernameEqualTo(upmsUser.getUsername());
long count = upmsUserMapper.countByExample(upmsUserExample);
if (count > 0) {
return null;
}
upmsUserMapper.insert(upmsUser); upmsUserMapper.insert(upmsUser);
return upmsUser; return upmsUser;
} }
} }

View File

@ -1,7 +1,6 @@
package com.zheng.upms.server.controller.manage; package com.zheng.upms.server.controller.manage;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.unbiz.fluentvalidator.ComplexResult; import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator; import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors; import com.baidu.unbiz.fluentvalidator.ResultCollectors;
@ -16,7 +15,6 @@ import com.zheng.upms.rpc.api.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,7 +24,10 @@ import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* 用户controller * 用户controller
@ -189,10 +190,12 @@ public class UpmsUserController extends BaseController {
upmsUser.setSalt(salt); upmsUser.setSalt(salt);
upmsUser.setPassword(MD5Util.MD5(upmsUser.getPassword() + upmsUser.getSalt())); upmsUser.setPassword(MD5Util.MD5(upmsUser.getPassword() + upmsUser.getSalt()));
upmsUser.setCtime(time); upmsUser.setCtime(time);
int count = upmsUserService.insertSelective(upmsUser); upmsUser = upmsUserService.createUser(upmsUser);
//upmsUser = upmsUserService.insert2(upmsUser); if (null == upmsUser) {
//_log.info("新增用户主键userId={}", upmsUser.getUserId()); return new UpmsResult(UpmsResultConstant.FAILED, "帐号名已存在!");
return new UpmsResult(UpmsResultConstant.SUCCESS, count); }
_log.info("新增用户主键userId={}", upmsUser.getUserId());
return new UpmsResult(UpmsResultConstant.SUCCESS, 1);
} }
@ApiOperation(value = "删除用户") @ApiOperation(value = "删除用户")

View File

@ -96,7 +96,7 @@ function createSubmit() {
animation: 'rotateX', animation: 'rotateX',
closeAnimation: 'rotateX', closeAnimation: 'rotateX',
title: false, title: false,
content: result.data.errorMsg, content: result.data.errorMsg || result.data,
buttons: { buttons: {
confirm: { confirm: {
text: '确认', text: '确认',

View File

@ -10,7 +10,7 @@
<form id="updateForm" method="post"> <form id="updateForm" method="post">
<div class="form-group"> <div class="form-group">
<label for="username">帐号</label> <label for="username">帐号</label>
<input id="username" type="text" class="form-control" name="username" maxlength="20" value="${user.username}"> <input id="username" type="text" class="form-control" name="username" maxlength="20" value="${user.username}" readonly>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="realname">姓名</label> <label for="realname">姓名</label>