|
@@ -74,43 +74,77 @@ public class TableServiceCmdService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
|
- private BaseTableDTO packTableDTO(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
|
- BaseTableDTO baseTableDTO = new BaseTableDTO();
|
|
|
|
- baseTableDTO.setFixedData(baseTableSaveDTO.getFixedData());
|
|
|
|
- baseTableDTO.setObjId(baseTableSaveDTO.getObjId());
|
|
|
|
- baseTableDTO.setTable(baseTableSaveDTO.getTable());
|
|
|
|
- return baseTableDTO;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public final AjaxResult objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
|
|
|
+// private BaseTableDTO packTableDTO(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
|
+// BaseTableDTO baseTableDTO = new BaseTableDTO();
|
|
|
|
+// baseTableDTO.setFixedData(baseTableSaveDTO.getFixedData());
|
|
|
|
+// baseTableDTO.setObjId(baseTableSaveDTO.getObjId());
|
|
|
|
+// baseTableDTO.setTable(baseTableSaveDTO.getTable());
|
|
|
|
+// return baseTableDTO;
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// public final AjaxResult objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
|
+// AjaxResult result = AjaxResult.success();
|
|
|
|
+// BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
|
|
+// TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
|
|
+// // 拿到pkName和maxId
|
|
|
|
+// List<GenTableColumn> columns = context.getTable().getColumns();
|
|
|
|
+// String pkName = IdUtils.getPkName(columns);
|
|
|
|
+// requireNonNull(pkName, "主键名称为空");
|
|
|
|
+//
|
|
|
|
+// // 新增
|
|
|
|
+// if (ObjectUtils.ltZero(baseTableDTO.getObjId())) {
|
|
|
|
+// Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
|
|
|
|
+// RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), columns);
|
|
|
|
+// if (RowResult.checkSuccess(rowResult)) {
|
|
|
|
+// LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
|
|
+// } else {
|
|
|
|
+// LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
|
|
|
|
+// result = AjaxResult.error();
|
|
|
|
+// }
|
|
|
|
+// }else {
|
|
|
|
+// JSONObject commitData = context.getRows().get(0).getCommitData();
|
|
|
|
+//
|
|
|
|
+// // 编辑
|
|
|
|
+// int effective = updateService.updateByIdList(context, pkName
|
|
|
|
+// , Collections.singletonList(baseTableDTO.getObjId()), commitData);
|
|
|
|
+// if (effective > 0) {
|
|
|
|
+// LOGGER.info("修改成功,封装到数据库的数据为: {}", JSON.toJSONString(context.getRows().get(0).getCommitData()));
|
|
|
|
+// } else {
|
|
|
|
+// LOGGER.error("修改失败,前台传来的原始数据为: {}", JSON.toJSONString(context.getRows().get(0).getCommitData()));
|
|
|
|
+// result = AjaxResult.error();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// return result;
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ public final AjaxResult objectSave(BaseTableSaveDTO dto) {
|
|
AjaxResult result = AjaxResult.success();
|
|
AjaxResult result = AjaxResult.success();
|
|
- BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
|
|
- TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
|
|
|
|
+
|
|
|
|
+ TableContext context = TableContext.createContext(dto);
|
|
// 拿到pkName和maxId
|
|
// 拿到pkName和maxId
|
|
- List<GenTableColumn> columns = context.getTable().getColumns();
|
|
|
|
- String pkName = IdUtils.getPkName(columns);
|
|
|
|
- requireNonNull(pkName, "主键名称为空");
|
|
|
|
-
|
|
|
|
- // 新增
|
|
|
|
- if (ObjectUtils.ltZero(baseTableDTO.getObjId())) {
|
|
|
|
- Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
|
|
|
|
- RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), columns);
|
|
|
|
|
|
+ List<GenTableColumn> columns = context.getColumns();
|
|
|
|
+ String pkName = context.getPkName();
|
|
|
|
+ JSONObject commitData = context.getCommitData();
|
|
|
|
+
|
|
|
|
+ // 新增 todo 判断是否有修改时间和修改人,需要抽取公告方法
|
|
|
|
+ if (ActionType.INSERT.equals(context.getActionType())) {
|
|
|
|
+ Long maxId = IdUtils.getMaxId(dto.getTable(), pkName);
|
|
|
|
+ RowResult rowResult = saveService.insertRow(context.getTableName(), pkName, maxId, commitData, columns);
|
|
if (RowResult.checkSuccess(rowResult)) {
|
|
if (RowResult.checkSuccess(rowResult)) {
|
|
LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
} else {
|
|
} else {
|
|
- LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
|
|
|
|
|
|
+ LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(dto));
|
|
result = AjaxResult.error();
|
|
result = AjaxResult.error();
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
- JSONObject commitData = context.getRows().get(0).getCommitData();
|
|
|
|
-
|
|
|
|
|
|
+ } else {
|
|
// 编辑
|
|
// 编辑
|
|
- int effective = updateService.updateByIdList(context, pkName
|
|
|
|
- , Collections.singletonList(baseTableDTO.getObjId()), commitData);
|
|
|
|
|
|
+ int effective = updateService.updateByIdList(context, pkName, Collections.singletonList(context.getId()), commitData, columns);
|
|
if (effective > 0) {
|
|
if (effective > 0) {
|
|
- LOGGER.info("修改成功,封装到数据库的数据为: {}", JSON.toJSONString(context.getRows().get(0).getCommitData()));
|
|
|
|
|
|
+ LOGGER.info("修改成功,封装到数据库的数据为: {}", JSON.toJSONString(commitData));
|
|
} else {
|
|
} else {
|
|
- LOGGER.error("修改失败,前台传来的原始数据为: {}", JSON.toJSONString(context.getRows().get(0).getCommitData()));
|
|
|
|
|
|
+ LOGGER.error("修改失败,前台传来的原始数据为: {}", JSON.toJSONString(commitData));
|
|
result = AjaxResult.error();
|
|
result = AjaxResult.error();
|
|
}
|
|
}
|
|
}
|
|
}
|