Commit f6cf7806 by fsn

添加用户和修改用户的数据传输bean修改

parent 7cde7d54
...@@ -15,6 +15,8 @@ import com.stylefeng.guns.core.shiro.ShiroKit; ...@@ -15,6 +15,8 @@ import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser; import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.UserMgrDao; import com.stylefeng.guns.modular.system.dao.UserMgrDao;
import com.stylefeng.guns.modular.system.factory.UserFactory;
import com.stylefeng.guns.modular.system.transfer.UserDto;
import com.stylefeng.guns.modular.system.warpper.UserWarpper; import com.stylefeng.guns.modular.system.warpper.UserWarpper;
import com.stylefeng.guns.persistence.dao.UserMapper; import com.stylefeng.guns.persistence.dao.UserMapper;
import com.stylefeng.guns.persistence.model.User; import com.stylefeng.guns.persistence.model.User;
...@@ -160,7 +162,7 @@ public class UserMgrController extends BaseController { ...@@ -160,7 +162,7 @@ public class UserMgrController extends BaseController {
@BussinessLog("添加管理员") @BussinessLog("添加管理员")
@Permission(Const.ADMIN_NAME) @Permission(Const.ADMIN_NAME)
@ResponseBody @ResponseBody
public Tip add(@Valid User user, BindingResult result) { public Tip add(@Valid UserDto user, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
} }
...@@ -176,7 +178,8 @@ public class UserMgrController extends BaseController { ...@@ -176,7 +178,8 @@ public class UserMgrController extends BaseController {
user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt())); user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt()));
user.setStatus(ManagerStatus.OK.getCode()); user.setStatus(ManagerStatus.OK.getCode());
user.setCreatetime(new Date()); user.setCreatetime(new Date());
this.userMapper.insert(user);
this.userMapper.insert(UserFactory.createUser(user));
return SUCCESS_TIP; return SUCCESS_TIP;
} }
...@@ -189,17 +192,17 @@ public class UserMgrController extends BaseController { ...@@ -189,17 +192,17 @@ public class UserMgrController extends BaseController {
@BussinessLog("修改管理员") @BussinessLog("修改管理员")
@Permission(Const.ADMIN_NAME) @Permission(Const.ADMIN_NAME)
@ResponseBody @ResponseBody
public Tip edit(@Valid User user, BindingResult result) throws NoPermissionException { public Tip edit(@Valid UserDto user, BindingResult result) throws NoPermissionException {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL); throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
} }
if (ShiroKit.hasRole(Const.ADMIN_NAME)) { if (ShiroKit.hasRole(Const.ADMIN_NAME)) {
this.userMapper.updateById(user); this.userMapper.updateById(UserFactory.createUser(user));
return SUCCESS_TIP; return SUCCESS_TIP;
} else { } else {
ShiroUser shiroUser = ShiroKit.getUser(); ShiroUser shiroUser = ShiroKit.getUser();
if (shiroUser.getId() == user.getId()) { if (shiroUser.getId() == user.getId()) {
this.userMapper.updateById(user); this.userMapper.updateById(UserFactory.createUser(user));
return SUCCESS_TIP; return SUCCESS_TIP;
} else { } else {
throw new AuthenticationException(); throw new AuthenticationException();
......
package com.stylefeng.guns.modular.system.factory;
import com.stylefeng.guns.modular.system.transfer.UserDto;
import com.stylefeng.guns.persistence.model.User;
import org.springframework.beans.BeanUtils;
/**
* 用户创建工厂
*
* @author fengshuonan
* @date 2017-05-05 22:43
*/
public class UserFactory {
public static User createUser(UserDto userDto){
if(userDto == null){
return null;
}else{
User user = new User();
BeanUtils.copyProperties(userDto,user);
return user;
}
}
}
package com.stylefeng.guns.modular.system.transfer;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 用户传输bean
*
* @author stylefeng
* @Date 2017/5/5 22:40
*/
public class UserDto{
private Integer id;
private String account;
private String password;
private String salt;
private String name;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
private Integer sex;
private String email;
private String phone;
private String roleid;
private Integer deptid;
private Integer status;
private Date createtime;
private Integer version;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getRoleid() {
return roleid;
}
public void setRoleid(String roleid) {
this.roleid = roleid;
}
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment