com.sccl.attech.modules.sys.entity.Office.java Source code

Java tutorial

Introduction

Here is the source code for com.sccl.attech.modules.sys.entity.Office.java

Source

/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/sccl/attech">attech</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.sccl.attech.modules.sys.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.sccl.attech.common.persistence.IdEntity;
import com.sccl.attech.common.utils.excel.annotation.ExcelField;
import com.sccl.attech.modules.message.entity.SmsReceiver;
import com.sccl.attech.modules.message.entity.SmsRecords;
import com.sccl.attech.modules.message.entity.SmsTariff;
import com.sccl.attech.modules.sys.utils.DictUtils;

/**
 * Entity
 * @author sccl
 * @version 2013-05-15
 */
@Entity
@Table(name = "sys_office")
@DynamicInsert
@DynamicUpdate
public class Office extends IdEntity<Office> {

    private static final long serialVersionUID = 1L;
    private Office parent; // ?
    private String parentIds; // ?
    private Area area; // 
    private String code; // ?
    private String name; // ??
    private String shortName;//??
    private String type; // 1?23?
    private String grade; // 1234
    private String address; // ??
    private String zipCode; // ?
    private String master; // 
    private String phone; // ?
    private String fax; // 
    private String email; // 

    private String industry;//
    private Integer sort; //??  
    private Integer level; //

    private String outId; //ID

    private List<User> userList = Lists.newArrayList(); // 
    private List<SmsRecords> recordsList = Lists.newArrayList();//??  ??
    private List<SmsRecords> smsRecords = Lists.newArrayList();//  ??
    private List<SmsReceiver> receiversList = Lists.newArrayList(); //??  
    private List<SmsReceiver> smsReceivers = Lists.newArrayList(); //?  
    private List<SmsTariff> smsTariffs = Lists.newArrayList();//?

    private String typeName; //??
    private String parentId; // Id
    private String parentName;
    private String areaId; //id
    private String areaName; //??
    private String label;

    private String roleIds; //?
    private String roleNames;//??

    private Dict dict;//??
    private String companyId;//?Id
    private String roleType;//

    @Transient
    public String getCompanyId() {
        return companyId;
    }

    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }

    @Transient
    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    @Transient
    @JsonIgnore
    public Dict getDict() {
        return dict;
    }

    public void setDict(Dict dict) {
        this.dict = dict;
    }

    private List<Office> children;//??

    public Office() {
        super();
    }

    public Office(String id) {
        this();
        this.id = id;
    }

    public String getOutId() {
        return outId;
    }

    public void setOutId(String outId) {
        this.outId = outId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @JsonIgnore
    @ExcelField(title = "", align = 2, sort = 30)
    public Office getParent() {
        return parent;
    }

    public void setParent(Office parent) {
        this.parent = parent;
    }

    @Length(min = 1, max = 255)
    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

    @ManyToOne
    @JoinColumn(name = "area_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @JsonIgnore
    @ExcelField(title = "", align = 2, sort = 35)
    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    @Length(min = 1, max = 100)
    @ExcelField(title = "??", align = 2, sort = 40)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(min = 1, max = 1)
    @ExcelField(title = "", align = 2, sort = 50)
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Length(min = 1, max = 1)
    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    @Length(min = 0, max = 255)
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Length(min = 0, max = 100)
    public String getZipCode() {
        return zipCode;
    }

    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }

    @Length(min = 0, max = 100)
    public String getMaster() {
        return master;
    }

    public void setMaster(String master) {
        this.master = master;
    }

    @Length(min = 0, max = 200)
    @ExcelField(title = "??", align = 2, sort = 50)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Length(min = 0, max = 200)
    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    @Length(min = 0, max = 200)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Length(min = 0, max = 100)
    public String getShortName() {
        return shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    @Length(min = 0, max = 100)
    @ExcelField(title = "?", align = 2, sort = 45)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @OneToMany(mappedBy = "office", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    @OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<SmsRecords> getRecordsList() {
        return recordsList;
    }

    public void setRecordsList(List<SmsRecords> recordsList) {
        this.recordsList = recordsList;
    }

    @OneToMany(mappedBy = "office", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<SmsRecords> getSmsRecords() {
        return smsRecords;
    }

    public void setSmsRecords(List<SmsRecords> smsRecords) {
        this.smsRecords = smsRecords;
    }

    @OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<SmsReceiver> getReceiversList() {
        return receiversList;
    }

    public void setReceiversList(List<SmsReceiver> receiversList) {
        this.receiversList = receiversList;
    }

    @OneToMany(mappedBy = "office", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<SmsReceiver> getSmsReceivers() {
        return smsReceivers;
    }

    public void setSmsReceivers(List<SmsReceiver> smsReceivers) {
        this.smsReceivers = smsReceivers;
    }

    @OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "id")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    public List<SmsTariff> getSmsTariffs() {
        return smsTariffs;
    }

    public void setSmsTariffs(List<SmsTariff> smsTariffs) {
        this.smsTariffs = smsTariffs;
    }

    @Transient
    public static void sortList(List<Office> list, List<Office> sourcelist, String parentId) {
        for (int i = 0; i < sourcelist.size(); i++) {
            Office e = sourcelist.get(i);
            if (e.getParent() != null && e.getParent().getId() != null && e.getParent().getId().equals(parentId)) {
                list.add(e);
                // ??, ??
                for (int j = 0; j < sourcelist.size(); j++) {
                    Office child = sourcelist.get(j);
                    if (child.getParent() != null && child.getParent().getId() != null
                            && child.getParent().getId().equals(e.getId())) {
                        sortList(list, sourcelist, e.getId());
                        break;
                    }
                }
            }
        }
    }

    @Length(min = 0, max = 100)
    public String getIndustry() {
        return industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    @Column(name = "\"level\"")
    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    @Transient
    public boolean isRoot() {
        return isRoot(this.id);
    }

    @Transient
    public static boolean isRoot(String id) {
        return id != null && id.equals("1");
    }

    @Transient
    public String getTypeName() {
        return DictUtils.getDictLabel(type, "sys_office_type", "");
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    @Transient
    public String getParentId() {
        if (StringUtils.isBlank(this.parentId)) {
            if (parent != null) {
                return parent.getId();
            }
        }
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Transient
    public String getParentName() {
        if (StringUtils.isBlank(this.parentName)) {
            if (parent != null) {
                return parent.getName();
            }
        }
        return this.parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    @Transient
    public String getAreaId() {
        if (StringUtils.isBlank(this.areaId)) {
            if (area != null) {
                return area.getId();
            }
        }
        return areaId;
    }

    public void setAreaId(String areaId) {
        this.areaId = areaId;
    }

    @Transient
    public String getAreaName() {
        if (StringUtils.isBlank(this.areaName)) {
            if (area != null) {
                return area.getName();
            }
        }
        return this.areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    @Transient
    public String getLabel() {
        return shortName;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    private String hasChildren;

    @Transient
    public String getHasChildren() {
        return hasChildren;
    }

    public void setHasChildren(String hasChildren) {
        this.hasChildren = hasChildren;
    }

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy(value = "code")
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public List<Office> getChildren() {
        return children;
    }

    public void setChildren(List<Office> children) {
        this.children = children;
    }

    @Transient
    public String getRoleIds() {
        if (StringUtils.isEmpty(roleIds)) {
            roleIds = master;
        }
        return roleIds;
    }

    public void setRoleIds(String roleIds) {
        this.roleIds = roleIds;
    }

    @Transient
    public String getRoleNames() {
        return roleNames;
    }

    public void setRoleNames(String roleNames) {
        this.roleNames = roleNames;
    }

}