| | |
| | | package com.moral.api.pojo.form.user; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.pojo.dto.user.UserDTO; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.RegexUtils; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @ClassName UserInsertForm |
| | | * @Description TODO |
| | | * @Author 陈凯裕 |
| | | * @Date 2021/3/22 14:05 |
| | | * @Date 2021/5/6 10:35 |
| | | * @Version TODO |
| | | **/ |
| | | @Data |
| | | public class UserInsertForm { |
| | | |
| | | private String account; |
| | | |
| | | private String password; |
| | | |
| | | private String userName; |
| | | |
| | | private Integer organizationId; |
| | | |
| | | private String email; |
| | | |
| | | private String mobile; |
| | | |
| | | private String wechat; |
| | | |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
| | | private Date expireTime; |
| | | |
| | | |
| | | public boolean valid() { |
| | | if ( |
| | | ObjectUtils.isEmpty(account) || |
| | | ObjectUtils.isEmpty(password) || |
| | | ObjectUtils.isEmpty(userName) || |
| | | ObjectUtils.isEmpty(organizationId) || |
| | | ObjectUtils.isEmpty(expireTime) |
| | | ) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | public UserDTO paramValid() { |
| | | UserDTO dto = new UserDTO(); |
| | | //判断账号是否符合条件 |
| | | if (!RegexUtils.checkAccount(account)) { |
| | | dto.setCode(ResponseCodeEnum.ACCOUNT_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.ACCOUNT_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | //判断用户名是否符合条件 |
| | | if(!RegexUtils.checkChinese(userName)||userName.contains(" ")){ |
| | | dto.setCode(ResponseCodeEnum.USERNAME_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.USERNAME_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | //判断密码是否符合条件 |
| | | if (!RegexUtils.checkPassword(AESUtils.decrypt(password))) { |
| | | dto.setCode(ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | //判断手机号是否符合条件 |
| | | if (!ObjectUtils.isEmpty(mobile)) { |
| | | if (!RegexUtils.checkMobile(mobile)) { |
| | | dto.setCode(ResponseCodeEnum.MOBILE_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.MOBILE_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | } |
| | | //判断邮箱是否符合条件 |
| | | if (!ObjectUtils.isEmpty(email)) { |
| | | if (!RegexUtils.checkEmail(email)) { |
| | | dto.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | } |
| | | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return dto; |
| | | } |
| | | |
| | | public User formConvertEntity() { |
| | | User user = new User(); |
| | | user.setAccount(account); |
| | | user.setPassword(MD5Utils.saltMD5(AESUtils.decrypt(password))); |
| | | user.setUserName(userName); |
| | | user.setOrganizationId(organizationId); |
| | | user.setEmail(email); |
| | | user.setMobile(mobile); |
| | | user.setWechat(wechat); |
| | | user.setExpireTime(expireTime); |
| | | user.setIsAdmin(true); |
| | | return user; |
| | | } |
| | | } |
| | | |