Commit 820d4d73 authored by yanzg's avatar yanzg

修改实例化关系

parent 3ef1b5b3
......@@ -296,6 +296,10 @@ public class DaoConst {
* 根据字段添加统计
*/
public static final int FIELD_ADD_GROUP = 8;
/**
* 根据字段替换统计
*/
public static final int FIELD_REPLACE_GROUP = 9;
/**
* SQL语句类型-普通语句
......
......@@ -4,6 +4,7 @@ package com.yanzuoguang.dao.impl;
* 累加接口
*
* @param <T>
* @author 颜佐光
*/
public interface GroupAdd<T extends GroupAdd> {
/***
......
......@@ -119,6 +119,15 @@ public class TableSqlCache {
this.table.addGroupSql(this, tableWhereField, addField);
}
/**
* 生成GroupSQL语句
*
* @param tableWhereField
* @param addField
*/
public void addGroup(TableFieldString tableWhereField, TableFieldString replaceField, TableFieldString addField) {
this.table.addGroupSql(this, tableWhereField, replaceField, addField);
}
/**
* 生成GroupSQL语句
......
......@@ -258,9 +258,11 @@ public class TableStruct {
* @return 获取统计纬度列
*/
public List<TableFieldVo> getGroupLatitudeFields() {
List<TableFieldVo> commonField = getFieldActionList(DaoConst.FIELD_COMMON,
DaoConst.FIELD_ADD_GROUP, DaoConst.FIELD_MD5);
return commonField;
return getFieldActionList(DaoConst.FIELD_COMMON,
DaoConst.FIELD_ADD_GROUP,
DaoConst.FIELD_REPLACE_GROUP,
DaoConst.FIELD_MD5
);
}
/**
......@@ -424,8 +426,9 @@ public class TableStruct {
*/
private void initAddGroup(TableSqlCache table) {
List<TableFieldVo> addGroupField = getFieldActionList(DaoConst.FIELD_ADD_GROUP);
List<TableFieldVo> replaceGroupField = getFieldActionList(DaoConst.FIELD_REPLACE_GROUP);
List<TableFieldVo> commonField = this.getGroupLatitudeFields();
this.addGroupSql(table, commonField, addGroupField);
this.addGroupSql(table, commonField, replaceGroupField, addGroupField);
}
/**
......@@ -724,8 +727,10 @@ public class TableStruct {
*/
private List<TableFieldVo> getFieldString(TableFieldString fieldFrom) {
List<TableFieldVo> list = new ArrayList<>();
for (String fieldName : fieldFrom.getFields()) {
list.add(this.getField(fieldName));
if (fieldFrom != null) {
for (String fieldName : fieldFrom.getFields()) {
list.add(this.getField(fieldName));
}
}
return list;
}
......@@ -759,10 +764,10 @@ public class TableStruct {
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
* @param addFields 需要增加的值的字段
*/
public void addGroupSql(TableSqlCache sqlTableData, TableFieldString whereFields, TableFieldString updateFields) {
addGroupSql(sqlTableData, getFieldString(whereFields), getFieldString(updateFields));
public void addGroupSql(TableSqlCache sqlTableData, TableFieldString whereFields, TableFieldString addFields) {
addGroupSql(sqlTableData, whereFields, null, addFields);
}
/**
......@@ -770,16 +775,37 @@ public class TableStruct {
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
* @param addFields 需要增加的值的字段
*/
private void addGroupSql(TableSqlCache sqlTableData, List<TableFieldVo> whereFields, List<TableFieldVo> updateFields) {
public void addGroupSql(TableSqlCache sqlTableData, TableFieldString whereFields, TableFieldString replaceFields, TableFieldString addFields) {
addGroupSql(sqlTableData, getFieldString(whereFields), getFieldString(replaceFields), getFieldString(addFields));
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param replaceFields WHERE字段
* @param addFields 需要增加的值的字段
*/
private void addGroupSql(TableSqlCache sqlTableData, List<TableFieldVo> whereFields, List<TableFieldVo> replaceFields, List<TableFieldVo> addFields) {
List<TableFieldVo> prmaryKey = this.getFieldActionList(DaoConst.FIELD_PRIMARY);
// 生成统计加载SQL语句
SqlData sqlLoad = this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_QUERY, DaoConst.SQL_LOAD,
StringHelper.EMPTY, new ArrayList<>(), whereFields);
sqlLoad.addParaConst(DaoConst.CODE_FIELD_DEFAULT_NAME, DaoConst.CODE_FIELD, DaoConst.CODE_FIELD_DEFAULT);
// 生成统计累加SQL语句
SqlData sqlGroupAdd = this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.SQL_UPDATE,
DaoConst.CODE_GROUP_ADD, updateFields, prmaryKey);
if (updateFields.isEmpty()) {
DaoConst.CODE_GROUP_ADD, addFields, prmaryKey);
// 生成覆盖值
if (replaceFields != null) {
for (TableFieldVo field : replaceFields) {
sqlGroupAdd.addPara(field.inputName, DaoConst.CODE_FIELD, String.format("a.%s=?", field.name));
}
}
// 当没有字段时,直接修改主键
if (addFields.isEmpty()) {
sqlGroupAdd.addCode(DaoConst.CODE_FIELD, String.format("%s=%s", prmaryKey.get(0).inputName, prmaryKey.get(0).inputName));
}
sqlTableData.add(sqlLoad);
......@@ -856,8 +882,8 @@ public class TableStruct {
tos.add(from);
mapFrom.put(key, from);
} else {
T histor = mapFrom.get(key);
histor.add(from);
T history = mapFrom.get(key);
history.add(from);
}
}
......
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.impl.SqlData;
import com.yanzuoguang.dao.impl.TableSqlCache;
import com.yanzuoguang.dao.impl.TableStruct;
import com.yanzuoguang.db.impl.DbPrintSql;
import com.yanzuoguang.util.helper.JsonHelper;
import org.junit.Test;
public class TestDbPrintSql {
@Test
public void test(){
public void test() {
DbPrintSql printSql = new DbPrintSql();
String stringSql = printSql.getStringSql("select * from where id = ? AND name = ? and removeFlag = 0 ", "1");
System.out.println(stringSql);
}
@Test
public void testTableStruct() {
TableSqlCache cache = new TableSqlCache();
TableStruct table = new TableStruct("test", TestTableGroupVo.class);
table.init(cache);
SqlData sqlData = cache.getNameCache().get(DaoConst.GROUP_ADD);
System.out.println(JsonHelper.serialize(sqlData, true));
}
}
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.TableAnnotation;
@TableAnnotation("db_time")
public class TestTableGroupVo {
@TableAnnotation("id")
private String id;
@TableAnnotation("createDate")
private String createDate;
@TableAnnotation(value = "total", type = DaoConst.FIELD_REPLACE_GROUP)
private int total;
@TableAnnotation(value = "has", type = DaoConst.FIELD_ADD_GROUP)
private int has;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getHas() {
return has;
}
public void setHas(int has) {
this.has = has;
}
}
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