Commit 1f23c68a authored by 李丛阳's avatar 李丛阳

完善 idEntity

parent f1cb4d43
......@@ -102,8 +102,12 @@ public class CodeServiceImpl extends BaseService implements CodeService {
//column
rs = (ResultSet) dbmd.getColumns(null, codeSchema.getDbName(), table.toLowerCase(), null);
dbmd.getPrimaryKeys(null, null, tables[0].toLowerCase());
boolean flag = false;
while (rs.next()) {
model = new DbColumnModel();
/* 根据 CREATE_BY 判断是否存在7个字段 */
if("CREATE_BY".equals(rs.getString("COLUMN_NAME").toUpperCase()))
flag = true;
model.copyColumnFromSqlResult(rs);
models.add(model);
}
......@@ -117,6 +121,7 @@ public class CodeServiceImpl extends BaseService implements CodeService {
}
}
}
tableModel.setIdEntity(flag);
//table -> column
tableModel.setColumnModels(models);
tableModels.add(tableModel);
......@@ -252,7 +257,10 @@ public class CodeServiceImpl extends BaseService implements CodeService {
try {
out = new FileWriter(file);
//fileList.add(file);
temp = freeMarkerConfiguration.getTemplate("codeftl" + File.separator + suffix.toLowerCase()+".ftl");
if(suffix.equals("Entity") && !dbTableModel.isIdEntity())
temp = freeMarkerConfiguration.getTemplate("codeftl" + File.separator + suffix.toLowerCase() + "NotCommon" +".ftl");
else
temp = freeMarkerConfiguration.getTemplate("codeftl" + File.separator + suffix.toLowerCase()+".ftl");
temp.process(root, out);
}catch (Exception e){
log.error(e.getMessage());
......
......@@ -34,6 +34,8 @@ public class DbTableModel implements Serializable{
private String entityName;
private boolean isIdEntity; //是否都存在 create_by update_by .. 7个字段
public String getEntityName() {
StringBuffer simpleEntity = new StringBuffer();
boolean upPower = true;
......
package org.rcisoft.core.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.rcisoft.core.util.IdGen;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.io.Serializable;
/**
* Created with family.
* author: cy
* Date: 16/6/2
* Time: 上午9:15
* description: id entity
*/
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
@Data
public abstract class IdNotDataEntity<T> implements Serializable {
private static final long serialVersionUID = 2L;
@Id
protected String businessId; // 编号
@Transient
protected String token;
/**
* 通用设置ID
*/
public void setCommonBusinessId(){
this.setBusinessId(IdGen.uuid());
}
}
\ No newline at end of file
package org.rcisoft.business.${table.entityName?lower_case}.entity;
import lombok.*;
import org.rcisoft.core.entity.IdNotDataEntity;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Created with ${author} on ${.now}.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "${table.tableName}")
public class ${table.entityName} extends IdNotDataEntity<${table.entityName}> {
<#list table.columnModels as item>
<#if item.columnNameLowerCamel!='businessId'>
private ${item.javaType} ${item.columnNameLowerCamel};
</#if>
</#list>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment