|
@@ -3,7 +3,6 @@ package com.boman.system.common;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.boman.common.core.utils.SecurityUtils;
|
|
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
@@ -25,10 +24,8 @@ import java.sql.Timestamp;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
|
|
|
|
-import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
|
|
|
|
-import static com.boman.system.common.FormDataConstant.CONDITION;
|
|
|
|
-import static com.boman.system.common.FormDataConstant.SHOW_DATA;
|
|
|
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
|
+import static com.boman.system.common.FormDataConstant.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author shiqian
|
|
* @author shiqian
|
|
@@ -48,6 +45,8 @@ public class TableServiceCmdService {
|
|
private IBaseSelectService selectService;
|
|
private IBaseSelectService selectService;
|
|
@Resource
|
|
@Resource
|
|
private IBaseSubmitService submitService;
|
|
private IBaseSubmitService submitService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IBaseUpdateService updateService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
|
@@ -60,6 +59,7 @@ public class TableServiceCmdService {
|
|
}
|
|
}
|
|
|
|
|
|
public final AjaxResult objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
public final AjaxResult objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
|
+ AjaxResult result = AjaxResult.success();
|
|
BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
// 拿到pkName和maxId
|
|
// 拿到pkName和maxId
|
|
@@ -71,15 +71,33 @@ public class TableServiceCmdService {
|
|
List<String> allColumnNameList = columns.stream()
|
|
List<String> allColumnNameList = columns.stream()
|
|
.map(GenTableColumn::getColumnName)
|
|
.map(GenTableColumn::getColumnName)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
|
|
|
|
- RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), allColumnNameList);
|
|
|
|
- if (RowResult.checkSuccess(rowResult)) {
|
|
|
|
- LOGGER.info("保存成功,封装到数据库的数据为: {}", JSON.toJSONString(rowResult.getData()));
|
|
|
|
- } else {
|
|
|
|
- LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
|
|
|
|
|
|
+
|
|
|
|
+ // 新增
|
|
|
|
+ if (ObjectUtils.ltZero(baseTableDTO.getObjId())) {
|
|
|
|
+ Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
|
|
|
|
+ RowResult rowResult = saveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0), allColumnNameList);
|
|
|
|
+ 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 AjaxResult.success(rowResult);
|
|
|
|
|
|
+ return result;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -202,7 +220,7 @@ public class TableServiceCmdService {
|
|
// long string collection 暂时只作此三种类型判断
|
|
// long string collection 暂时只作此三种类型判断
|
|
if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
|
|
if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
|
|
// columnType 作为判断需不需要转义的一个标准,防止索引失效
|
|
// columnType 作为判断需不需要转义的一个标准,防止索引失效
|
|
- result.put(key, packValue(String.valueOf(value), column.getQueryType(), column.getColumnType()));
|
|
|
|
|
|
+ result.put(key, Lists.newArrayList(String.valueOf(value), column.getQueryType(), column.getColumnType()));
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -362,4 +380,20 @@ public class TableServiceCmdService {
|
|
return requireNonNull(genTable);
|
|
return requireNonNull(genTable);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 反提交接口, 更改的字段类型和字段值都是一致的
|
|
|
|
+ * {
|
|
|
|
+ * "table": "sys_config",
|
|
|
|
+ * }
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * @param condition condition
|
|
|
|
+ * @return com.boman.common.core.web.domain.AjaxResult
|
|
|
|
+ */
|
|
|
|
+ public AjaxResult getByTableName(BaseTableSaveDTO condition) {
|
|
|
|
+// requiredNonNull(condition.getTable(), "表名为空");
|
|
|
|
+ GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
|
+ return AjaxResult.success(genTable);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|