package com.moral.api.pojo.form.organization; 
 | 
  
 | 
import com.fasterxml.jackson.annotation.JsonFormat; 
 | 
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.format.annotation.DateTimeFormat; 
 | 
import org.springframework.util.ObjectUtils; 
 | 
  
 | 
import java.util.Date; 
 | 
  
 | 
/** 
 | 
 * @ClassName OrganizationUpdateForm 
 | 
 * @Description TODO 
 | 
 * @Author 陈凯裕 
 | 
 * @Date 2021/3/24 8:43 
 | 
 * @Version TODO 
 | 
 **/ 
 | 
@Data 
 | 
public class OrganizationUpdateForm { 
 | 
  
 | 
    private Integer organizationId; 
 | 
  
 | 
    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; 
 | 
  
 | 
    @DateTimeFormat(pattern = "yyyy-MM-dd") 
 | 
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") 
 | 
    private Date expireTime; 
 | 
  
 | 
    public boolean valid() { 
 | 
        if (ObjectUtils.isEmpty(organizationId)) 
 | 
            return false; 
 | 
        if ( 
 | 
                ObjectUtils.isEmpty(parentId) && 
 | 
                        ObjectUtils.isEmpty(name) && 
 | 
                        ObjectUtils.isEmpty(provinceCode) && 
 | 
                        ObjectUtils.isEmpty(cityCode) && 
 | 
                        ObjectUtils.isEmpty(areaCode) && 
 | 
                        ObjectUtils.isEmpty(locationLevelCode) && 
 | 
                        ObjectUtils.isEmpty(address) && 
 | 
                        phone==null && 
 | 
                        email==null && 
 | 
                        wechat==null && 
 | 
                        ObjectUtils.isEmpty(expireTime) 
 | 
                ) 
 | 
            return false; 
 | 
        return true; 
 | 
    } 
 | 
  
 | 
    public Organization formConvertEntity() { 
 | 
        Organization organization = new Organization(); 
 | 
        organization.setId(organizationId); 
 | 
        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); 
 | 
        organization.setExpireTime(expireTime); 
 | 
  
 | 
        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 (!ObjectUtils.isEmpty(expireTime)) { 
 | 
            Date currentDate = new Date(); 
 | 
            if (DateUtils.compareDateStr(expireTime, 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; 
 | 
    } 
 | 
} 
 |