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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.moral.api.pojo.form.organization;
 
import com.moral.api.entity.Organization;
import com.moral.api.pojo.dto.organization.OrganizationDTO;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.DateUtils;
import com.moral.util.RegexUtils;
import lombok.Data;
import org.springframework.util.ObjectUtils;
 
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * @ClassName OrganizationInsertForm
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/3/22 14:12
 * @Version TODO
 **/
@Data
public class OrganizationInsertForm {
 
    private Integer parentId;
 
    private String name;
 
    private Integer provinceCode;
 
    private String provinceName;
 
    private Integer cityCode;
 
    private String cityName;
 
    private Integer areaCode;
 
    private String areaName;
 
    private Integer locationLevelCode;
 
    private String locationLevelName;
 
    private String address;
 
    private String phone;
 
    private String email;
 
    private String wechat;
 
    private String expireTime;
 
    public boolean valid() {
        if (
                ObjectUtils.isEmpty(name) ||
                        ObjectUtils.isEmpty(provinceCode) ||
                        ObjectUtils.isEmpty(provinceName) ||
                        ObjectUtils.isEmpty(locationLevelCode) ||
                        ObjectUtils.isEmpty(locationLevelName)||
                        ObjectUtils.isEmpty(address) ||
                        ObjectUtils.isEmpty(expireTime)
                )
            return false;
        return true;
    }
 
    public Organization formConvertEntity() {
        Organization organization = new Organization();
        organization.setParentId(parentId);
        organization.setName(name);
        organization.setProvinceCode(provinceCode);
        organization.setProvinceName(provinceName);
        organization.setCityCode(cityCode);
        organization.setCityName(cityName);
        organization.setAreaCode(areaCode);
        organization.setAreaName(areaName);
        organization.setLocationLevelCode(locationLevelCode);
        organization.setLocationLevelName(locationLevelName);
        organization.setAddress(address);
        organization.setPhone(phone);
        organization.setEmail(email);
        organization.setWechat(wechat);
        Date expireTimeDate = DateUtils.getDate(expireTime + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
        organization.setExpireTime(expireTimeDate);
        return organization;
    }
 
    public OrganizationDTO paramValid() {
        OrganizationDTO dto = new OrganizationDTO();
        //判断电话号是否符合条件
        if (!ObjectUtils.isEmpty(phone)) {
            if (!RegexUtils.checkMobile(phone) && !RegexUtils.checkPhone(phone)) {
                dto.setCode(ResponseCodeEnum.PHONE_INVALID.getCode());
                dto.setMsg(ResponseCodeEnum.PHONE_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 (!RegexUtils.checkDate(expireTime)) {
            dto.setCode(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode());
            dto.setMsg(ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg());
            return dto;
        }
        //判断过期时间是否小于当前时间
        Date expireDate = DateUtils.getDate(expireTime, "yyyy-MM-dd");
        Date currentDate = new Date();
        if (DateUtils.compareDateStr(expireDate, currentDate) >= 0) {
            dto.setCode(ResponseCodeEnum.TIME_INVALID.getCode());
            dto.setMsg(ResponseCodeEnum.TIME_INVALID.getMsg());
            return dto;
        }
        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        return dto;
    }
}