Commit e007f8e7 authored by yanzg's avatar yanzg

修改保存历史记录

parent 7371b706
......@@ -9,7 +9,6 @@ import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.*;
import org.omg.CORBA.StringHolder;
import java.util.*;
......@@ -868,7 +867,16 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
} catch (Exception ex) {
throw new RuntimeException("创建对象" + cls.getName() + "出错", ex);
}
ObjectHelper.writeWithFrom(from, request);
TableStruct tableStruct = this.table.getTable();
// 写入历史版本号
TableFieldVo version = tableStruct.getVersion();
if (version != null) {
Object hisVersion = ObjectHelper.get(from, version.inputName);
ObjectHelper.writeWithFrom(from, request);
ObjectHelper.set(from, version.inputName, hisVersion);
} else {
ObjectHelper.writeWithFrom(from, request);
}
return this.create(from);
} else {
ObjectHelper.writeWithFrom(from, request);
......@@ -884,7 +892,18 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @return 保存成功,返回保存的ID,保存失败,返回空值
*/
public <T extends Object> String saveWith(Class<T> cls, String sqlName, Object request) {
T from = this.queryFirst(cls, sqlName, request);
if (request instanceof InitDao) {
((InitDao) request).init();
}
TableStruct tableStruct = this.table.getTable();
// 获取所有条件字段
MapRow condition = new MapRow();
List<TableFieldVo> fields = tableStruct.getFields(DaoConst.FIELD_SAVE_WITH);
for (TableFieldVo field : fields) {
condition.put(field.inputName, ObjectHelper.get(request, field.inputName));
}
// 查询历史数据
T from = this.queryFirst(cls, sqlName, condition);
return saveFromCreate(cls, from, request);
}
......
......@@ -373,6 +373,16 @@ public class TableStruct {
return null;
}
/**
* 获取某一列
*
* @param fieldType 字段类型
* @return 获取到的字段
*/
public List<TableFieldVo> getFields(int fieldType) {
return getFieldActionList(fieldType);
}
/**
* 通过表结构自动生成SQL语句
*
......
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