| package com.dsh.guns.modular.system.factory; | 
|   | 
| import com.dsh.guns.modular.system.model.User; | 
| import com.dsh.guns.modular.system.transfer.UserDto; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.util.StringUtils; | 
|   | 
| /** | 
|  * 用户创建工厂 | 
|  * | 
|  * @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; | 
|         } | 
|     } | 
|   | 
|     public static User editUser(UserDto newUser, User oldUser) { | 
|         if (newUser == null || oldUser == null) { | 
|             return oldUser; | 
|         } else { | 
|             if (!StringUtils.isEmpty(newUser.getAvatar())) { | 
|                 oldUser.setAvatar(newUser.getAvatar()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getName())) { | 
|                 oldUser.setName(newUser.getName()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getBirthday())) { | 
|                 oldUser.setBirthday(newUser.getBirthday()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getDeptid())) { | 
|                 oldUser.setDeptid(newUser.getDeptid()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getSex())) { | 
|                 oldUser.setSex(newUser.getSex()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getEmail())) { | 
|                 oldUser.setEmail(newUser.getEmail()); | 
|             } | 
|             if (!StringUtils.isEmpty(newUser.getPhone())) { | 
|                 oldUser.setPhone(newUser.getPhone()); | 
|             } | 
|             return oldUser; | 
|         } | 
|     } | 
| } |