|
@@ -3,6 +3,7 @@ package com.boman.system.common;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
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.obj.ObjectUtils;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
@@ -12,9 +13,7 @@ import com.boman.gen.controller.MyController;
|
|
|
import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
import com.boman.system.mapper.StandardlyMapper;
|
|
|
-import com.boman.system.service.IBaseDeleteService;
|
|
|
-import com.boman.system.service.IBaseSaveService;
|
|
|
-import com.boman.system.service.IBaseSelectService;
|
|
|
+import com.boman.system.service.*;
|
|
|
import com.boman.system.utils.IdUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.slf4j.Logger;
|
|
@@ -22,10 +21,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
|
|
@@ -49,6 +46,8 @@ public class TableServiceCmdService {
|
|
|
private RedisService redisService;
|
|
|
@Resource
|
|
|
private IBaseSelectService selectService;
|
|
|
+ @Resource
|
|
|
+ private IBaseSubmitService submitService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
@@ -66,7 +65,7 @@ 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()
|
|
@@ -97,7 +96,7 @@ public class TableServiceCmdService {
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
- RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName));
|
|
|
+ RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"));
|
|
|
LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
return AjaxResult.success(rowResult);
|
|
|
}
|
|
@@ -121,7 +120,7 @@ public class TableServiceCmdService {
|
|
|
JSONObject jsonObject= new JSONObject();
|
|
|
jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
|
|
|
|
- RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName), jsonObject);
|
|
|
+ RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"), jsonObject);
|
|
|
LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
return AjaxResult.success(rowResult);
|
|
|
}
|
|
@@ -176,7 +175,7 @@ public class TableServiceCmdService {
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
JSONObject fixedData = dto.getFixedData();
|
|
|
- requireNonNull(fixedData);
|
|
|
+ fixedData = ObjectUtils.ifNullSetEmpty(fixedData);
|
|
|
Long id = fixedData.getLong(FormDataConstant.ID);
|
|
|
requireNonNull(id);
|
|
|
|
|
@@ -287,6 +286,77 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 表单提交接口
|
|
|
+ *
|
|
|
+ * @param condition condition
|
|
|
+ * @param isSubmit 提交true, 反提交false
|
|
|
+ * @return com.boman.common.core.web.domain.AjaxResult
|
|
|
+ */
|
|
|
+ public AjaxResult objectSubmit(BaseTableSaveDTO condition, boolean isSubmit) {
|
|
|
+ GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
+ List<JSONObject> commitData = condition.getCommitData();
|
|
|
+ requireNonNull(commitData, "啥都不提交, 调什么接口??");
|
|
|
+
|
|
|
+ String tableName = requireNonNull(genTable.getTableName());
|
|
|
+ String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
+
|
|
|
+ // 先去查出之前的状态
|
|
|
+ List<Long> idList = commitData.stream().map(jsonObject -> jsonObject.getLong(FormDataConstant.ID))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ JSONArray showData = new JSONArray();
|
|
|
+ showData.add(FormDataConstant.STATUS);
|
|
|
+ showData.add(pkName);
|
|
|
+ List<JSONObject> beforeList = selectService.selectByIdList(tableName, pkName, idList, showData);
|
|
|
+ requireNonNull(beforeList);
|
|
|
+
|
|
|
+ // 符合条件的需要提交的
|
|
|
+ List<JSONObject> needCommitList = Lists.newArrayListWithCapacity(16);
|
|
|
+ // 不符合条件的需要提交的
|
|
|
+ List<JSONObject> notNeedCommitList = Lists.newArrayListWithCapacity(16);
|
|
|
+ Iterator<JSONObject> iterator = beforeList.iterator();
|
|
|
+ while (iterator.hasNext()){
|
|
|
+ JSONObject next = iterator.next();
|
|
|
+ String dbStatus = next.getString(FormDataConstant.STATUS);
|
|
|
+ // 只能是未提交的状态下,才能调用提交
|
|
|
+ if (isSubmit) {
|
|
|
+ if (!SubmitConstant.NOT_SUBMIT.equals(dbStatus)) {
|
|
|
+ next.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
|
+ notNeedCommitList.add(next);
|
|
|
+ iterator.remove();
|
|
|
+ } else {
|
|
|
+ needCommitList.add(next);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 只有在已提交的情况下才能反提交
|
|
|
+ if (!SubmitConstant.SUBMITTED.equals(dbStatus)) {
|
|
|
+ next.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.NOT_ALLOWED);
|
|
|
+ notNeedCommitList.add(next);
|
|
|
+ iterator.remove();
|
|
|
+ } else {
|
|
|
+ needCommitList.add(next);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (JSONObject jsonObject : needCommitList) {
|
|
|
+ jsonObject.put(SubmitConstant.SUBMIT_USERID, SecurityUtils.getUserId());
|
|
|
+ jsonObject.put(SubmitConstant.SUBMIT_TIME, new Timestamp(System.currentTimeMillis()));
|
|
|
+// jsonObject.put(SubmitConstant.REMARK, "unknown");
|
|
|
+ int effective = submitService.handlerSubmit(tableName, pkName, jsonObject, jsonObject.getLong(FormDataConstant.ID));
|
|
|
+ if (effective > 0) {
|
|
|
+ jsonObject.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.SUCCESS);
|
|
|
+ } else {
|
|
|
+ jsonObject.put(SubmitConstant.SUBMIT_RESULT, SubmitConstant.FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ needCommitList.addAll(notNeedCommitList);
|
|
|
+ return AjaxResult.success(needCommitList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // todo redis中未找到,要去查数据库,然后再塞进去
|
|
|
private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName){
|
|
|
GenTable genTable = redisService.getCacheObject(redisKeyPrefix + requireNonNull(tableName));
|
|
|
return requireNonNull(genTable);
|