com.invms.x.entities.basis.FileEntity Maven / Gradle / Ivy
The newest version!
package com.invms.x.entities.basis;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.invms.x.builders.ArgsBuilder;
import com.invms.x.builders.QueryBuilder;
import com.invms.x.filters.EntityFilter;
import com.invms.x.filters.FieldFilter;
import com.invms.x.filters.FileFilter;
import com.invms.x.models.basis.FileModel;
import com.invms.x.utils.ComUtils;
import com.invms.x.utils.XUtils;
@FieldFilter(markOnly = true)
@EntityFilter(viewEnable = true, code = FileEntity.BASE_CODE, name = "文件", sortIndex = FileEntity.BASE_SORT_INDEX, sortOptions = "sortName:'sortIndex',sortOrder:'asc'", parentCode = IBasisEntity.BASE_CODE)
@Table(name = "t_" + FileEntity.BASE_CODE, indexes = { @Index(name = "i_file_code", columnList = "c_code"), @Index(name = "i_file_category", columnList = "c_category"), @Index(name = "i_file_sort_index", columnList = "c_sort_index"), @Index(name = "i_file_deleted", columnList = "c_deleted") })
@Entity
public class FileEntity extends BaseBinaryEntity implements Serializable {
private static final long serialVersionUID = -7648387655438244777L;
public static final String BASE_CODE = IBasisEntity.BASE_CODE + "_file";
public static final long BASE_SORT_INDEX = IBasisEntity.BASE_SORT_INDEX + 9500;
public static void setQueryBuilder(Class> resultClass, String queryMethod, QueryBuilder queryBuilder) {
StringBuilder stringBuilder = new StringBuilder();
if (resultClass != null && FileModel.class.isAssignableFrom(resultClass)) {
stringBuilder.append("select new " + resultClass.getName());
stringBuilder.append("(t.id, t.code, t.name, t.category");
stringBuilder.append(", t.userId, t.bufferFile, t.binaryData");
stringBuilder.append(", t.hierarchy, t.parentId, t.remark, t.sortIndex");
stringBuilder.append(", t.updateUser, t.updateTime, t.insertUser, t.insertTime, t.deleted");
stringBuilder.append(", tParent.code, tParent.name, tUser.code, tUser.name)");
stringBuilder.append(" from FileEntity t");
}
switch (queryMethod) {
case EntityFilter.METHOD_INSERT:
case EntityFilter.METHOD_UPDATE:
case EntityFilter.METHOD_DELETE:
case EntityFilter.METHOD_CLEAR:
break;
case EntityFilter.METHOD_COUNT:
case EntityFilter.METHOD_EXIST:
case EntityFilter.METHOD_SINGLE:
case EntityFilter.METHOD_RANGE:
case EntityFilter.METHOD_PAGINATE:
stringBuilder.append(" left join t.parent tParent");
stringBuilder.append(" left join t.user tUser");
break;
}
queryBuilder.setQuery(stringBuilder.toString());
}
public static void setArgsBuilder(String queryMethod, ArgsBuilder argsBuilder) throws Exception {
switch (queryMethod) {
case EntityFilter.METHOD_INSERT:
case EntityFilter.METHOD_UPDATE:
case EntityFilter.METHOD_DELETE:
break;
case EntityFilter.METHOD_CLEAR:
case EntityFilter.METHOD_COUNT:
case EntityFilter.METHOD_EXIST:
case EntityFilter.METHOD_SINGLE:
case EntityFilter.METHOD_RANGE:
case EntityFilter.METHOD_PAGINATE:
if (ComUtils.empty(argsBuilder.getValue(String.class, "userId_equal"))) {
argsBuilder.setValue("userId_null", true);
}
break;
}
}
public static FileEntity fromFilter(FileFilter filter, FileEntity entity) throws Exception {
if (entity == null) {
entity = new FileEntity();
}
if (!ComUtils.empty(filter.code())) {
entity.setCode(filter.code());
}
if (!ComUtils.empty(filter.name())) {
entity.setName(filter.name());
}
if (!ComUtils.empty(filter.category())) {
entity.setCategory(filter.category());
}
if (!ComUtils.empty(filter.bufferFile())) {
entity.setBufferFile(filter.bufferFile());
}
if (!ComUtils.empty(filter.binaryData())) {
entity.setBinaryData(filter.binaryData());
}
if (!ComUtils.empty(filter.remark())) {
entity.setRemark(filter.remark());
}
if (filter.sortIndex() != 0) {
entity.setSortIndex(filter.sortIndex());
}
entity.setDeleted(filter.deleted());
return entity;
}
@FieldFilter(code = BASE_CODE + "_id", name = "文件主键", dataType = FieldFilter.DATA_TYPE_STRING, outputEnable = true, sortIndex = BASE_SORT_INDEX + 1, parentCode = BASE_CODE)
@Id
@Column(name = "p_id", length = 32, nullable = false)
protected String id;
@FieldFilter(code = BASE_CODE + "_userId", name = "用户主键", category = "所属用户", dataType = FieldFilter.DATA_TYPE_FOREIGN, inputEnable = true, outputEnable = true, sortIndex = BASE_SORT_INDEX + 88, parentCode = BASE_CODE)
@Column(name = "f_user_id", length = 32)
protected String userId;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "f_user_id", foreignKey = @ForeignKey(name = "i_file_user_id"), insertable = false, updatable = false)
private UserEntity user;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "f_parent_id", foreignKey = @ForeignKey(name = "i_file_parent_id"), insertable = false, updatable = false)
private FileEntity parent;
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public FileEntity() {
id = XUtils.buildId();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy