|
@@ -18,15 +18,17 @@ import com.boman.system.utils.IdUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.net.URI;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
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.common.core.utils.obj.ObjectUtils.*;
|
|
|
import static com.boman.system.common.FormDataConstant.CONDITION;
|
|
|
import static com.boman.system.common.FormDataConstant.SHOW_DATA;
|
|
|
|
|
@@ -48,6 +50,8 @@ public class TableServiceCmdService {
|
|
|
private IBaseSelectService selectService;
|
|
|
@Resource
|
|
|
private IBaseSubmitService submitService;
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
@@ -65,7 +69,8 @@ public class TableServiceCmdService {
|
|
|
// 拿到pkName和maxId
|
|
|
List<GenTableColumn> columns = context.getTable().getColumns();
|
|
|
String pkName = IdUtils.getPkName(columns);
|
|
|
- requireNonNull(pkName, "主键名称为空");;
|
|
|
+ requireNonNull(pkName, "主键名称为空");
|
|
|
+ ;
|
|
|
|
|
|
//
|
|
|
List<String> allColumnNameList = columns.stream()
|
|
@@ -117,7 +122,7 @@ public class TableServiceCmdService {
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
- JSONObject jsonObject= new JSONObject();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
|
|
|
|
RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"), jsonObject);
|
|
@@ -137,15 +142,15 @@ public class TableServiceCmdService {
|
|
|
// 拿到每个字段对应的查询类型,=、 like、 >、 <
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
JSONObject fixedData = dto.getFixedData();
|
|
|
- fixedData = ObjectUtils.ifNullSetEmpty(fixedData);
|
|
|
+ fixedData = ifNullSetEmpty(fixedData);
|
|
|
|
|
|
// 查询条件
|
|
|
- JSONObject condition = ObjectUtils.ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
|
+ JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
// 封装好以后的查询条件
|
|
|
- JSONObject packCondition = ObjectUtils.ifNullSetEmpty(packColCondition(columns, condition));
|
|
|
+ JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
|
|
|
// 需要返回到前台的列
|
|
|
- JSONArray showData = ObjectUtils.ifNullSetEmpty(fixedData.getJSONArray(SHOW_DATA));
|
|
|
+ JSONArray showData = ifNullSetEmpty(fixedData.getJSONArray(SHOW_DATA));
|
|
|
JSONObject rows = new JSONObject();
|
|
|
int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
|
|
|
rows.put(FormDataConstant.PAGE_TOTAL, total);
|
|
@@ -160,7 +165,7 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(rows);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* 功能描述: 获取单表单数据
|
|
|
*
|
|
|
* @param dto condition
|
|
@@ -175,7 +180,7 @@ public class TableServiceCmdService {
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
JSONObject fixedData = dto.getFixedData();
|
|
|
- fixedData = ObjectUtils.ifNullSetEmpty(fixedData);
|
|
|
+ fixedData = ifNullSetEmpty(fixedData);
|
|
|
Long id = fixedData.getLong(FormDataConstant.ID);
|
|
|
requireNonNull(id);
|
|
|
|
|
@@ -186,7 +191,7 @@ public class TableServiceCmdService {
|
|
|
|
|
|
/**
|
|
|
* 功能描述: 封装成查询条件 key: 列名, value:查询条件_查询类别
|
|
|
- * eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
|
|
|
+ * eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
|
|
|
*
|
|
|
* @param columns columns
|
|
|
* @return com.alibaba.fastjson.JSONObject
|
|
@@ -215,10 +220,10 @@ public class TableServiceCmdService {
|
|
|
* 功能描述: 获取表单查询字段、按钮、表头
|
|
|
* 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
|
* 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
|
|
|
- *
|
|
|
- * eg:{
|
|
|
- * "table": "sys_config",
|
|
|
- * }
|
|
|
+ * <p>
|
|
|
+ * eg:{
|
|
|
+ * "table": "sys_config",
|
|
|
+ * }
|
|
|
*
|
|
|
* @param condition condition
|
|
|
* @return com.boman.common.core.web.domain.AjaxResult
|
|
@@ -315,7 +320,7 @@ public class TableServiceCmdService {
|
|
|
// 不符合条件的需要提交的
|
|
|
List<JSONObject> notNeedCommitList = Lists.newArrayListWithCapacity(16);
|
|
|
Iterator<JSONObject> iterator = beforeList.iterator();
|
|
|
- while (iterator.hasNext()){
|
|
|
+ while (iterator.hasNext()) {
|
|
|
JSONObject next = iterator.next();
|
|
|
String dbStatus = next.getString(FormDataConstant.STATUS);
|
|
|
// 只能是未提交的状态下,才能调用提交
|
|
@@ -356,10 +361,52 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否定制
|
|
|
+ * 判断是否需要转发到定制接口
|
|
|
+ * @param tableName 表明
|
|
|
+ * @param result 结果
|
|
|
+ * @param action 动作
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public List<JSONObject> isCustomized(String tableName, List<JSONObject> result, String action) {
|
|
|
+ requireNonNull(tableName);
|
|
|
+ requireNonNull(action);
|
|
|
+ if (result != null && result.size() > 0){
|
|
|
+ //获取到服务名称
|
|
|
+ String triggerName = getTriggerName(tableName, action);
|
|
|
+ requireNonNull(triggerName);
|
|
|
+ //组织请求 acos + RestTemplate
|
|
|
+ return restTemplate.postForObject("http://" + triggerName, result, List.class);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是什么action
|
|
|
+ * @param tableName 表明
|
|
|
+ * @param action 动作
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getTriggerName(String tableName, String action){
|
|
|
+ GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
|
|
|
+ requireNonNull(genTable);
|
|
|
+ if (action.equals(TriggerActionConstant.ACTION_CREATE)){
|
|
|
+ return genTable.getTriggerCreate();
|
|
|
+ }else if (action.equals(TriggerActionConstant.ACTION_RETRIEVE)){
|
|
|
+ return genTable.getTriggerRetrieve();
|
|
|
+ }else if (action.equals(TriggerActionConstant.ACTION_UPDATE)){
|
|
|
+ return genTable.getTriggerUpdate();
|
|
|
+ }else if (action.equals(TriggerActionConstant.ACTION_DELETE)){
|
|
|
+ return genTable.getTriggerDelete();
|
|
|
+ }else if (action.equals(TriggerActionConstant.ACTION_SUBMIT)){
|
|
|
+ return genTable.getTriggerSubmit();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
// todo redis中未找到,要去查数据库,然后再塞进去
|
|
|
- private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName){
|
|
|
+ private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
|
|
|
GenTable genTable = redisService.getCacheObject(redisKeyPrefix + requireNonNull(tableName));
|
|
|
return requireNonNull(genTable);
|
|
|
}
|
|
|
-
|
|
|
}
|