kaiyu
2021-03-25 3b72f1f4dd46191857583a166d5b67722c6b118e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.moral.api.pojo.form.account;
 
import com.moral.api.pojo.dto.account.AccountInsertDTO;
import com.moral.api.pojo.dto.account.AccountUpdateDTO;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.AESUtils;
import com.moral.util.RegexUtils;
import lombok.Data;
import org.springframework.util.ObjectUtils;
 
import java.util.List;
 
/**
 * @ClassName AccountUpdateRequest
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/3/15 15:34
 * @Version TODO
 **/
@Data
public class AccountUpdateForm {
 
    private Integer accountId;
 
    private String userName;
 
    private String password;
 
    private String email;
 
    private String mobile;
 
    private String wechat;
 
    private List<Integer> roleIds;
 
    public boolean valid() {
        if(ObjectUtils.isEmpty(accountId))
            return false;
        if(
                ObjectUtils.isEmpty(userName)&&
                ObjectUtils.isEmpty(password)&&
                ObjectUtils.isEmpty(email)&&
                ObjectUtils.isEmpty(mobile)&&
                ObjectUtils.isEmpty(wechat)&&
                ObjectUtils.isEmpty(roleIds)
                )
            return false;
        return true;
    }
 
    public AccountUpdateDTO paramValid() {
        AccountUpdateDTO dto = new AccountUpdateDTO();
        //判断手机号是否符合条件
        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;
            }
        }
        //判断密码是否符合规则
        if (!ObjectUtils.isEmpty(password)){
            if(!RegexUtils.checkPassword(AESUtils.decrypt(password))){
                dto.setCode(ResponseCodeEnum.PASSWORD_INVALID.getCode());
                dto.setMsg(ResponseCodeEnum.PASSWORD_INVALID.getMsg());
                return dto;
            }
        }
            dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        return dto;
    }
 
}