Explorar o código

objSave雏形

shiqian %!s(int64=4) %!d(string=hai) anos
pai
achega
4891f97a6d

+ 8 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/StringUtils.java

@@ -52,6 +52,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
         return !isEmpty(coll);
     }
 
+    public static String requireNonNull(String input){
+        if (null == input || input.isEmpty()) {
+            throw new IllegalArgumentException("字符串为空");
+        }
+
+        return input;
+    }
+
     /**
      * * 判断一个对象数组是否为空
      * 

+ 27 - 6
boman-common/boman-common-redis/src/main/java/com/boman/common/redis/service/RedisService.java

@@ -1,11 +1,9 @@
 package com.boman.common.redis.service;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.HashOperations;
@@ -231,4 +229,27 @@ public class RedisService
     {
         return redisTemplate.keys(pattern);
     }
-}
+
+    /**
+     * 功能描述: 是否存在key
+     *
+     * @param key key
+     * @return 存在返回true, 不存在返回false
+     */
+    public boolean exists(String key) {
+        return redisTemplate.countExistingKeys(Collections.singleton(key)) >= 1;
+    }
+
+    /**
+     * 功能描述: increment
+     *
+     * @param key       key
+     * @param increment 增量
+     * @return long 增加以后的值
+     */
+
+    public long increment(String key, long... increment) {
+        return redisTemplate.opsForValue().increment(key, ArrayUtils.isEmpty(increment) ? 1L : increment[0]);
+    }
+
+}

+ 0 - 493
boman-modules/boman-system/src/main/java/com/boman/system/common/BaseSaveService.java

@@ -1,493 +0,0 @@
-package com.boman.system.common;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.boman.system.mapper.StandardlyMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.sql.Timestamp;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author shiqian
- * @description
- * @date 2021年03月22日 11:25
- **/
-@Component("baseSaveService-one")
-public class BaseSaveService {
-    private static final Logger LOGGER = LoggerFactory.getLogger(TableService.class);
-
-
-    @Resource
-    StoredProcedureService storedProcedureService;
-    @Autowired
-    private StandardlyMapper mapper;
-
-    public RowResult insertRow(TableServiceContext context, MainTableRecord row, Timestamp currentTime) {
-
-        // todo
-        Long id =/* insertMtable(context, row, currentTime)*/0L;
-        BusinessResult businessResult = new BusinessResult(id);
-        List<BusinessResult.Error> errorList = new LinkedList<>();
-        int successCount = 0;
-        Iterator var8 = row.getSubTables().values().iterator();
-
-        while(true) {
-            while(true) {
-                SubTableRecord itemTable;
-                JSONArray joItem;
-                do {
-                    do {
-                        if (!var8.hasNext()) {
-                            businessResult.setErrors(errorList);
-//                            GenTable table = context.getTable();
-                             // todo
-                            // storedProcedureService.storedProcedure(table.getHasTrigAc(), table.getTrigAc(), id, 0L, table.getName());
-                            if (errorList.size() > 0) {
-                                return RowResult.error(Resources.getMessage("新增成功" + successCount + "条,新增失败:" + errorList.size() + "条", /*context.getLocale() */null, new Object[0]), businessResult);
-                            }
-
-                            return RowResult.ok(Resources.getMessage("新增成功", /*context.getLocale() */null, new Object[0]), businessResult);
-                        }
-
-                        itemTable = (SubTableRecord)var8.next();
-                        joItem = itemTable.getCommitDatas();
-                    } while(joItem == null);
-                } while(joItem.size() <= 0);
-
-                String fkKey = /*itemTable.getFKColumnName()*/null;
-                if (!context.isInsertBacth()) {
-                    for(int i = 0; i < joItem.size(); ++i) {
-                        JSONObject insertKeys = joItem.getJSONObject(i);
-                        insertKeys.put(fkKey, id);
-                        BusinessResult.Error error = insertStable(itemTable.getRealTableName(), insertKeys, context, currentTime, itemTable.getTable());
-                        if (error != null) {
-                            errorList.add(error);
-                        } else {
-                            ++successCount;
-                        }
-                    }
-                } else {
-//                    BusinessResult.Error error = this.insertStableBatch(itemTable.getRealTableName(), joItem, context, currentTime, fkKey, id);
-//                    if (error != null) {
-//                        errorList.add(error);
-//                    } else {
-//                        ++successCount;
-//                    }
-                }
-            }
-        }
-    }
-
-//    private BusinessResult.Error insertStableBatch(String tableName, JSONArray joItem, TableServiceContext context, Timestamp currentTime, String fkKey, long fkId) {
-//
-//        BusinessResult.Error error = null;
-//
-//        try {
-//            //100条每次
-//            int pageSize = 100;
-//            int count = joItem.size();
-//            int page = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
-//            Table table = context.getTable();
-//            for (int n = 0; n < page; n++) {
-//                //起始位置
-//                int index = (n * pageSize);
-//                //每页行数是否大于剩余行数
-//                if (pageSize > count - index) {
-//                    //设置成总数量
-//                    pageSize = count - index;
-//                }
-//                //数组每次从0开始
-//                JSONObject[] insertKeysList = new JSONObject[pageSize];
-//                for (int i = 0; i < pageSize; i++) {
-//                    JSONObject insertKeys = joItem.getJSONObject(index + i);
-//                    insertKeys.put(fkKey, fkId);
-//                    // 新增明细表
-//                    User currentUser = context.getUser();
-//                    if (!insertKeys.containsKey("ID")
-//                            || insertKeys.getLong("ID") == null || insertKeys.getLong("ID") <= 0L) {
-//                        long id = ModelUtil.getSequence(tableName).longValue();
-//                        insertKeys.put("ID", id);
-//                    }
-//                    if (null != currentUser) {
-//                        if (null != table.getColumn("AD_CLIENT_ID")) {
-////                            if (!insertKeys.containsKey("AD_CLIENT_ID") || Validator.isNull(insertKeys.getLong("AD_CLIENT_ID"))) {
-////                                insertKeys.put("AD_CLIENT_ID", Long.valueOf(currentUser.getAdClientId()).longValue());
-////                            }
-//                        }
-//                        if (null != table.getColumn("CID")) {
-////                            if (!insertKeys.containsKey("CID") || Validator.isNull(insertKeys.getLong("CID"))) {
-////                                insertKeys.put("CID", Long.valueOf(currentUser.getCid()).longValue());
-////                            }
-//                        }
-//                        if (null != table.getColumn("AD_ORG_ID")) {
-//                            //insertKeys.put("AD_ORG_ID", Long.valueOf(currentUser.getAdOrgId()).longValue());
-//                        }
-//                        if (null != table.getColumn("OWNERNAME")) {
-//                            insertKeys.put("OWNERNAME", currentUser.getName());
-//                        }
-//                        if (null != table.getColumn("MODIFIERNAME")) {
-//                            insertKeys.put("MODIFIERNAME", currentUser.getName());
-//                        }
-//                        if (null != table.getColumn("CREATENAME")) {
-//                            insertKeys.put("CREATENAME", currentUser.getName());
-//                        }
-//                        if (null != table.getColumn("MODIFYNAME")) {
-//                            insertKeys.put("MODIFYNAME", currentUser.getName());
-//                        }
-//                        if (null != table.getColumn("CREATEID")) {
-//                            insertKeys.put("CREATEID", currentUser.getId());
-//                        }
-//                        if (null != table.getColumn("MODIFYID")) {
-//                            insertKeys.put("MODIFYID", currentUser.getId());
-//                        }
-//                    }
-//                    if (null != table.getColumn("MODIFIEDDATE")) {
-//                        insertKeys.put("MODIFIEDDATE", currentTime);
-//                    }
-//                    if (null != table.getColumn("CREATIONDATE")) {
-//                        insertKeys.put("CREATIONDATE", currentTime);
-//                    }
-//                    if (null != table.getColumn("MODIFYTIME")) {
-//                        insertKeys.put("MODIFYTIME", currentTime);
-//                    }
-//                    if (null != table.getColumn("CREATETIME")) {
-//                        insertKeys.put("CREATETIME", currentTime);
-//                    }
-//                    if (null != table.getColumn("STATUS")) {
-//                        insertKeys.put("STATUS", 1);
-//                    }
-//                    if (null != table.getColumn("ISACTIVE") && !insertKeys.containsKey("ISACTIVE")) {
-//                        insertKeys.put("ISACTIVE", table.getColumn("ISDEL").getDefaultValue());
-//                    }
-//                    if (null != table.getColumn("ISDEL") && !insertKeys.containsKey("ISDEL")) {
-//                        insertKeys.put("ISDEL", table.getColumn("ISDEL").getDefaultValue());
-//                    }
-////                    if (null != currentUser) {
-////                        if (!insertKeys.containsKey("AD_CLIENT_ID") || Validator.isNull(insertKeys.getLong("AD_CLIENT_ID"))) {
-////                            insertKeys.put("AD_CLIENT_ID", Long.valueOf(currentUser.getAdClientId()).longValue());
-////                        }
-////                        insertKeys.put("AD_ORG_ID", Long.valueOf(currentUser.getAdOrgId()).longValue());
-////                        //外键关联字段
-////                        insertKeys.put("MODIFIERID", currentUser.getId().longValue());
-////                        insertKeys.put("OWNERID", currentUser.getId().longValue());
-////                        insertKeys.put("OWNERNAME", currentUser.getName());
-////                        insertKeys.put("MODIFIERNAME", currentUser.getName());
-////                    }
-////                    insertKeys.put("MODIFIEDDATE", currentTime);
-////                    insertKeys.put("CREATIONDATE", currentTime);
-////                    if (!insertKeys.containsKey("isactive") && !insertKeys.containsKey("ISACTIVE")) {
-////                        insertKeys.put("ISACTIVE", "Y");//默认可用
-////                    }
-//                    //
-//                    insertKeysList[i] = insertKeys;
-//                }
-//
-//                int ret = mapper.inserts(tableName, insertKeysList, null);
-//                if (ret <= 0) {
-//                    throw new NDSException(Resources.getMessage("明细批量新增失败!", /*context.getLocale() */null));
-//                }
-//            }
-//
-//        } catch (NDSException e) {
-//            // 将错误信息存入dataArrayJson中
-//            error = getData(e);
-//        }
-//
-//        return error;
-//    }
-
-    /**
-     * 获取明细表新增错误信息并插入dataJson
-     *
-     * @param e 异常信息
-     * @return JSONObject
-     */
-//    private BusinessResult.Error getData(NDSException e) {
-//        return getData(e, 0L);
-//    }
-
-    /**
-     * 获取明细表更新错误信息并插入dataJson
-     *
-     * @param e      异常信息
-     * @param itemId 明细ID
-     * @return JSONObject
-     */
-//    private BusinessResult.Error getData(NDSException e, Long itemId) {
-//        return new BusinessResult.Error(itemId, -1, e.getMessage());
-//    }
-
-//    /**
-//     * 新增主表
-//     *
-//     * @return Long
-//     */
-//    private Long insertMtable(TableServiceContext context, MainTableRecord row, Timestamp currentTime) {
-//        // 新增主表
-//        //设置单号
-//        handlerSequenceNumber(context, row);
-//        //设置默认值
-//        handlerDefaultValue(context, row);
-//        //
-//        User currentUser = context.getUser();
-//        Long id = row.getCommitData().getLong("ID");
-//        if (id == null || id <= 0L) {
-//            id = ModelUtil.getSequence(row.getMainData().getRealTableName());
-//        }
-//        row.getCommitData().put("ID", id);
-//        row.setId(id);
-//        Table table = context.getTable();
-//        //List<Column> allColumns = table.getAllColumns();
-//        if (null != currentUser) {
-////            if (null != table.getColumn("AD_CLIENT_ID")) {
-////                if (!row.getCommitData().containsKey("AD_CLIENT_ID") || Validator.isNull(row.getCommitData().getLong("AD_CLIENT_ID"))) {
-////                    row.getCommitData().put("AD_CLIENT_ID", Long.valueOf(currentUser.getAdClientId()).longValue());
-////                }
-////            }
-//            if (null != table.getColumn("CID")) {
-////                if (!row.getCommitData().containsKey("CID") || Validator.isNull(row.getCommitData().getLong("CID"))) {
-////                    row.getCommitData().put("CID", Long.valueOf(currentUser.getCid()).longValue());
-////                }
-//            }
-//            if (null != table.getColumn("AD_ORG_ID")) {
-//                //row.getCommitData().put("AD_ORG_ID", Long.valueOf(currentUser.getAdOrgId()).longValue());
-//            }
-//            if (null != table.getColumn("OWNERNAME")) {
-//                row.getCommitData().put("OWNERNAME", currentUser.getName());
-//            }
-//            if (null != table.getColumn("MODIFIERNAME")) {
-//                row.getCommitData().put("MODIFIERNAME", currentUser.getName());
-//            }
-//            if (null != table.getColumn("CREATENAME")) {
-//                row.getCommitData().put("CREATENAME", currentUser.getName());
-//            }
-//            if (null != table.getColumn("MODIFYNAME")) {
-//                row.getCommitData().put("MODIFYNAME", currentUser.getName());
-//            }
-//            if (null != table.getColumn("CREATEID")) {
-//                row.getCommitData().put("CREATEID", currentUser.getId());
-//            }
-//            if (null != table.getColumn("MODIFYID")) {
-//                row.getCommitData().put("MODIFYID", currentUser.getId());
-//            }
-//
-//        }
-//        if (null != table.getColumn("MODIFIEDDATE")) {
-//            row.getCommitData().put("MODIFIEDDATE", currentTime);
-//        }
-//        if (null != table.getColumn("CREATIONDATE")) {
-//            row.getCommitData().put("CREATIONDATE", currentTime);
-//        }
-//        if (null != table.getColumn("MODIFYTIME")) {
-//            row.getCommitData().put("MODIFYTIME", currentTime);
-//        }
-//        if (null != table.getColumn("CREATETIME")) {
-//            row.getCommitData().put("CREATETIME", currentTime);
-//        }
-//        if (null != table.getColumn("STATUS")) {
-//            row.getCommitData().put("STATUS", 1);
-//        }
-//        if (null != table.getColumn("ISACTIVE") && !row.getCommitData().containsKey("ISACTIVE")) {
-//            row.getCommitData().put("ISACTIVE", "Y");
-//        }
-//        if (null != table.getColumn("ISDEL") && !row.getCommitData().containsKey("ISDEL")) {
-//            row.getCommitData().put("ISDEL", table.getColumn("ISDEL").getDefaultValue());
-//        }
-//
-//        JSONObject commitData = row.getCommitData();
-//        try {
-//            int ret = mapper.insert(context.getRealTableName(), commitData);
-//            if (ret <= 0) {
-//                throw new NDSException(Resources.getMessage("主表新增失败!", /*context.getLocale() */null));
-//            } else {
-//                //新增成功后 调用存储过程 AC-- wmc
-//                storedProcedureService.storedProcedure(table.getHasTrigAc(), table.getTrigAc(), id, 1L, table.getName());
-//            }
-//        } catch (Exception e) {
-//            LOGGER.error(commitData.toJSONString());
-//            throw e;
-//        }
-//
-//        return id;
-//    }
-
-//    private JSONObject handlerSequenceNumber(TableServiceContext context, MainTableRecord row) {
-//
-//        JSONObject jo = row.getCommitData();
-//        if (jo == null || jo.size() <= 0) {
-//            throw new NDSException("没有主表数据需要新增");
-//        }
-//
-//        Table table = context.getTable();
-//
-//        // 判断主表是否存在序列生成器
-//        ArrayList columns = table.getAllColumns();
-//        for (int i = 0; i < columns.size(); i++) {
-//            Column column = (Column) columns.get(i);
-//            if (column != null) {
-//                //赋值方式
-//                String obtainManner = column.getObtainManner();
-//                //赋值方式是否是【单据编号】
-//                if (!"sheetNo".equals(obtainManner)) {
-//                    continue;
-//                }
-//                //生成规则
-//                String sequenceHead = column.getSequenceHead();
-//                if (sequenceHead == null || "".equals(sequenceHead)) {
-//                    continue;
-//                }
-//                //按照规则生成编号
-//                String sequenceNumber = Optional.ofNullable(row.getCommitData().getString(column.getName()))
-//                        .orElse(ModelUtil.generateSerialNumber(sequenceHead, row.getCommitData(), /*context.getLocale() */null));
-//                jo.put(column.getName(), sequenceNumber);
-//            }
-//        }
-//
-//        return jo;
-//    }
-
-    /**
-     * 新增子表
-     *
-     * @return JSONObject
-     */
-    private BusinessResult.Error insertStable(String tableName, JSONObject insertKeys, TableServiceContext context, Timestamp currentTime, Table table) {
-        /*BusinessResult.Error error = null;
-        try {
-            // 新增明细表
-            // todo 设置默认值
-            //handlerDefaultValue(context, insertKeys);
-            User currentUser = context.getUser();
-            //Table table = context.getTable();
-            if (!insertKeys.containsKey("ID")
-                    || insertKeys.getLong("ID") == null || insertKeys.getLong("ID") <= 0L) {
-                long id = ModelUtil.getSequence(tableName).longValue();
-                insertKeys.put("ID", id);
-            }
-
-            if (null != currentUser) {
-                if (null != table.getColumn("AD_CLIENT_ID")) {
-//                    if (!insertKeys.containsKey("AD_CLIENT_ID") || Validator.isNull(insertKeys.getLong("AD_CLIENT_ID"))) {
-//                        insertKeys.put("AD_CLIENT_ID", Long.valueOf(currentUser.getAdClientId()).longValue());
-//                    }
-                }
-                if (null != table.getColumn("CID")) {
-//                    if (!insertKeys.containsKey("CID") || Validator.isNull(insertKeys.getLong("CID"))) {
-//                        insertKeys.put("CID", Long.valueOf(currentUser.getCid()).longValue());
-//                    }
-                }
-                if (null != table.getColumn("AD_ORG_ID")) {
-                    //insertKeys.put("AD_ORG_ID", Long.valueOf(currentUser.getAdOrgId()).longValue());
-                }
-                if (null != table.getColumn("OWNERNAME")) {
-                    insertKeys.put("OWNERNAME", currentUser.getName());
-                }
-                if (null != table.getColumn("MODIFIERNAME")) {
-                    insertKeys.put("MODIFIERNAME", currentUser.getName());
-                }
-                if (null != table.getColumn("CREATENAME")) {
-                    insertKeys.put("CREATENAME", currentUser.getName());
-                }
-                if (null != table.getColumn("MODIFYNAME")) {
-                    insertKeys.put("MODIFYNAME", currentUser.getName());
-                }
-                if (null != table.getColumn("CREATEID")) {
-                    insertKeys.put("CREATEID", currentUser.getId());
-                }
-                if (null != table.getColumn("MODIFYID")) {
-                    insertKeys.put("MODIFYID", currentUser.getId());
-                }
-            }
-
-            if (null != table.getColumn("MODIFIEDDATE")) {
-                insertKeys.put("MODIFIEDDATE", currentTime);
-            }
-            if (null != table.getColumn("CREATIONDATE")) {
-                insertKeys.put("CREATIONDATE", currentTime);
-            }
-            if (null != table.getColumn("MODIFYTIME")) {
-                insertKeys.put("MODIFYTIME", currentTime);
-            }
-            if (null != table.getColumn("CREATETIME")) {
-                insertKeys.put("CREATETIME", currentTime);
-            }
-            if (null != table.getColumn("STATUS")) {
-                insertKeys.put("STATUS", 1);
-            }
-            if (null != table.getColumn("ISACTIVE") && !insertKeys.containsKey("ISACTIVE")) {
-                insertKeys.put("ISACTIVE", table.getColumn("ISDEL").getDefaultValue());
-            }
-            if (null != table.getColumn("ISDEL") && !insertKeys.containsKey("ISDEL")) {
-                insertKeys.put("ISDEL", table.getColumn("ISDEL").getDefaultValue());
-            }
-//            if (null != currentUser) {
-//                if (!insertKeys.containsKey("AD_CLIENT_ID") || Validator.isNull(insertKeys.getLong("AD_CLIENT_ID"))) {
-//                    insertKeys.put("AD_CLIENT_ID", Long.valueOf(currentUser.getAdClientId()).longValue());
-//                }
-//                insertKeys.put("AD_ORG_ID", Long.valueOf(currentUser.getAdOrgId()).longValue());
-//                //外键关联字段
-//                insertKeys.put("MODIFIERID", currentUser.getId().longValue());
-//                insertKeys.put("OWNERID", currentUser.getId().longValue());
-//                insertKeys.put("OWNERNAME", currentUser.getName());
-//                insertKeys.put("MODIFIERNAME", currentUser.getName());
-//            }
-
-//            insertKeys.put("MODIFIEDDATE", currentTime);
-//            insertKeys.put("CREATIONDATE", currentTime);
-//            if (!insertKeys.containsKey("isactive") && !insertKeys.containsKey("ISACTIVE")) {
-//                insertKeys.put("ISACTIVE", "Y");//默认可用
-//            }
-
-            int ret = mapper.insert(tableName, insertKeys);
-
-            if (ret <= 0) {
-                throw new IllegalArgumentException(Resources.getMessage("明细新增失败!", *//*context.getLocale() *//*null));
-            }else {
-                // todo 新增成功  调用明细的新增存储过程
-                // storedProcedureService.storedProcedure(table.getHasTrigAc(), table.getTrigAc(), insertKeys.getLong("ID"), 1L, table.getName());
-            }
-        } catch (RuntimeException e) {
-            // 将错误信息存入dataArrayJson中
-//            error = getData(e);
-        }
-
-        return error;*/
-        return null;
-    }
-
-//    private void handlerDefaultValue(TableServiceContext context, MainTableRecord row) {
-//        JSONObject jo = row.getCommitData();
-//        handlerDefaultValue(context, jo);
-//
-//    }
-
-//    private void handlerDefaultValue(TableServiceContext context, JSONObject jo) {
-//
-//        if (jo == null || jo.size() <= 0) {
-//            throw new NDSException("没有主表数据需要新增");
-//        }
-//
-//        Table table = context.getTable();
-//
-//        //增加界面不显示字段默认值传入,识别第6位
-//        ArrayList columns = table.getColumns(new int[]{6}, false, 0, true);
-//
-//        columns.forEach(item -> {
-//            String val = ((Column) item).getDefaultValue();
-//            //if(val.contains("$")){
-//            val = QueryUtils.replaceVariables(val, context.getUser());
-//            //}
-//            jo.put(((Column) item).getName(), val);
-//        });
-//
-//    }
-
-
-}

+ 1 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/BaseTableService.java

@@ -1,5 +1,6 @@
 package com.boman.system.common;
 
+import com.boman.system.service.impl.BaseSaveService;
 import lombok.Getter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;

+ 6 - 6
boman-modules/boman-system/src/main/java/com/boman/system/common/RowRecord.java

@@ -45,12 +45,12 @@ public class RowRecord {
         if (fixedData == null) {
             fixedData = new JSONObject();
         }
-        if (!fixedData.containsKey("ID") || fixedData.getLong("ID") == null || fixedData.getLong("ID") <= 0) {
-            fixedData.put("ID", this.id);
-        }else{
-            //modify by nathan 导入修改
-            this.id = fixedData.getLong("ID");
-        }
+//        if (!fixedData.containsKey("ID") || fixedData.getLong("ID") == null || fixedData.getLong("ID") <= 0) {
+//            fixedData.put("ID", this.id);
+//        }else{
+//            //modify by nathan 导入修改
+//            this.id = fixedData.getLong("ID");
+//        }
 
         action = (this.id == null || this.id <= 0) ? DbRowAction.INSERT : DbRowAction.UPDATE;
         fixedData.forEach((fieldName, fieldValue)->{

+ 18 - 182
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java

@@ -1,25 +1,24 @@
 package com.boman.system.common;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.boman.gen.domain.GenTable;
+import com.boman.common.core.utils.SpringUtils;
+import com.boman.common.core.utils.StringUtils;
+import com.boman.gen.domain.GenTableColumn;
+import com.boman.system.service.impl.BaseSaveService;
+import com.boman.system.utils.IdUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
-import java.lang.reflect.Method;
-import java.util.Collection;
+import java.util.List;
 
 /**
  * @author shiqian
  * @description
  * @date 2021年03月22日 09:51
  **/
-@Component("tableServiceCmdService-one")
+@Component
 public class TableServiceCmdService {
 
     @Autowired
@@ -35,184 +34,21 @@ public class TableServiceCmdService {
         return execute(baseTableDTO, actionName);
     }
 
-    public final ValueHolder execute(BaseTableDTO baseTableDTO, String actionName) throws Exception {
+    public final ValueHolder execute(BaseTableDTO baseTableDTO, String actionName) {
         TableServiceContext context = TableServiceContext.createFrom(baseTableDTO, actionName);
+        BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
+        // 拿到pkName和maxId
+        List<GenTableColumn> columns = context.getTable().getColumns();
+        String pkName = IdUtils.getPkName(columns);
+        StringUtils.requireNonNull(pkName);
+        Long maxId = IdUtils.getMaxId(baseTableDTO.getTable(), pkName);
+        RowResult rowResult = baseSaveService.insertRow(context.getRealTableName(), pkName, maxId, context.getRows().get(0));
 
-        TableService service = getServiceByBusinessName(context.getTable());
-
-        service.configure(context);
-//        try {
-        executeAction(context, service);
-
-
-        return buildResult(context);
-//        } catch (Exception e) {
-//            LOGGER.error(e.getMessage(), e);
-//            LOGGER.error(Arrays.toString(e.getStackTrace()));
-//            return buildErrorResult(context, e);
-//        }
-
-//        return null;
-    }
-
-    public TableService getServiceByBusinessName(GenTable table){
-       return ApplicationContextHandle.getBean(table.getBusinessName() + "Service", TableService.class);
-    }
-
-//    protected TableServiceContext buildContext(BaseTableDTO baseTableDTO,String actionName) {
-//        return TableServiceContext.createFrom(baseTableDTO,actionName);
-//    }
-
-//    private TableService getServiceByTable(TableServiceContext context) {
-//        String tableName = context.getTableName();
-//        TableService service = null;
-//        try {
-//            service = ApplicationContextHandle.getBean(tableName + "Service", TableService.class);
-//        } catch (Exception e) {
-//            LOGGER.debug(e.getMessage());
-//        }
-////        if (service == null) {
-////            service = ApplicationContextHandle.getBean("defaultTableService-one");
-////            if (service == null) {
-////                throw new NDSException("defaultTableService 初始化失败!");
-////            }
-////        }
-//
-//        return service;
-//    }
-
-    private void executeAction(TableServiceContext context, TableService service) throws Exception {
-        Collection<Filter> filters = context.getFilters();
-        for (MainTableRecord row : context.getRows()) {
-//            ValidationResults validateResults = validate(context, row);
-//            if (validateResults.isOk()) {
-//                executeActionOnRow(context, service, row);
-//            } else {
-//                row.setResult(validateResults.toRowResult(row));
-//            }
-            executeActionOnRow(context, service, row);
-        }
-    }
-
-    private ValidationResults validate(TableServiceContext context, MainTableRecord row) {
-        Collection<Validator> validators = context.getValidators();
-        ValidationResults result = new ValidationResults();
-        for (Validator validator : validators) {
-            try {
-                validator.validate(context, row);
-            } catch (Exception e) {
-//                result.addError(e);
-            }
-        }
-        return result;
-    }
-
-//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
-//    public void executeActionOnRow(TableServiceContext context, MainTableRecord row) throws Exception {
-//        try {
-//            Method customAction = null;
-//            Class serviceClazz = service.getClass();
-//            String actionName = context.getActionName();
-//            try {
-//                if (serviceClazz != DefaultTableService.class) {
-//                    customAction = serviceClazz.getMethod(actionName, TableServiceContext.class, MainTableRecord.class);
-//                }
-//            } catch (Exception e) {
-//                LOGGER.warn(String.format("试图在类%s中查找%s方法失败!", serviceClazz, actionName));
-//            }
-//            if (customAction != null) {
-//                LOGGER.debug(String.format("调用类%s的%s方法.", serviceClazz, actionName));
-//                row.setResult((RowResult) customAction.invoke(service, context, row));
-//            } else {
-//                LOGGER.debug(String.format("调用类%s的executeAction方法.", serviceClazz));
-//                row.setResult(service.executeAction(context, row));
-//            }
-//
-//            for (Filter filter : filters) {
-//                filter.after(context, row);
-//            }
-//        } catch (Exception e) {
-//            for (Filter filter : filters) {
-//                if (filter instanceof ExceptionFilter) {
-//                    ExceptionFilter tempFilter = (ExceptionFilter) filter;
-//                    RowResult exceptionHandleResult = tempFilter.handleException(context, row, e);
-//                    if (exceptionHandleResult != null) {
-//                        row.setResult(exceptionHandleResult);
-//                        return;
-//                    }
-//                }
-//            }
-//            //该异常没人处理了
-//            throw e;
-//        }
-//    }
-
-    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
-    public void executeActionOnRow(TableServiceContext context, TableService service, MainTableRecord row) throws Exception {
-        try {
-            Method customAction = null;
-            Class serviceClazz = service.getClass();
-            String actionName = context.getActionName();
-            try {
-//                if (serviceClazz != DefaultTableService.class) {
-                customAction = serviceClazz.getMethod(actionName, TableServiceContext.class, MainTableRecord.class);
-//                }
-            } catch (Exception e) {
-                LOGGER.warn(String.format("试图在类%s中查找%s方法失败!", serviceClazz, actionName));
-            }
-            if (customAction != null) {
-                LOGGER.debug(String.format("调用类%s的%s方法.", serviceClazz, actionName));
-                row.setResult((RowResult) customAction.invoke(service, context, row));
-            } else {
-                LOGGER.debug(String.format("调用类%s的executeAction方法.", serviceClazz));
-                row.setResult(service.executeAction(context, row));
-            }
-        } catch (Exception e) {
-//            for (Filter filter : filters) {
-//                if (filter instanceof ExceptionFilter) {
-//                    ExceptionFilter tempFilter = (ExceptionFilter) filter;
-//                    RowResult exceptionHandleResult = tempFilter.handleException(context, row, e);
-//                    if (exceptionHandleResult != null) {
-//                        row.setResult(exceptionHandleResult);
-//                        return;
-//                    }
-//                }
-//            }
-            //该异常没人处理了
-            throw e;
-        }
-    }
-
-    private ValueHolder buildResult(TableServiceContext context) {
         ValueHolder valueHolder = new ValueHolder();
-        boolean code = context.getRows().stream().noneMatch(v -> -1 == v.getResult().getCode());
-        long errorSize = context.getRows().stream().filter(v -> -1 == v.getResult().getCode()).count();
-
-        if (context.getRows().size() == 1) {
-            return context.getRows().get(0).getResult().toValueHolder();
-        } else if (code) {
-            valueHolder.setCode(ResultCode.SUCCESS);
-            valueHolder.setMessage("操作成功" + context.getRows().size() + "条!");
-        } else {
-            valueHolder.setCode(ResultCode.FAIL);
-            valueHolder.setMessage("操作成功" + (context.getRows().size() - errorSize) + "条!,操作失败" + errorSize + "条!");
-            JSONArray datas = new JSONArray();
-            context.getRows().stream().filter(v -> -1 == v.getResult().getCode()).forEach(
-                    rowPostData -> {
-                        JSONObject row = new JSONObject();
-                        row.put("objid", rowPostData.getId());
-                        row.put("message", rowPostData.getResult().getMessage());
-                        datas.add(row);
-                    }
-            );
-
-            valueHolder.setData(datas);
-        }
-
+        valueHolder.setCode(ResultCode.SUCCESS);
+        valueHolder.setMessage("操作成功" + ((JSONObject) rowResult.getData()).getInteger("successCnt") + "条!");
+        valueHolder.setData(rowResult);
         return valueHolder;
     }
 
-    private ValueHolder buildErrorResult(TableServiceContext context, Exception e) {
-        return new ValueHolder(ResultCode.FAIL,/* ExceptionUtil.getMessage(e)*/e.getMessage());
-    }
 }

+ 4 - 3
boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjSaveController.java

@@ -5,8 +5,10 @@ import com.boman.system.common.TableServiceCmdService;
 import com.boman.system.common.ValueHolder;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 
 /**
@@ -19,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
 public class ObjSaveController {
 
     @Autowired
-    @Qualifier("tableServiceCmdService-one")
     private TableServiceCmdService tableServiceCmdService;
 
     @ApiOperation(value = "单对象保存")

+ 11 - 1
boman-modules/boman-system/src/main/java/com/boman/system/mapper/StandardlyMapper.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.jdbc.SQL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import java.util.*;
@@ -17,6 +19,9 @@ import java.util.function.Consumer;
 @Mapper
 @Component
 public interface StandardlyMapper {
+
+    Logger LOGGER = LoggerFactory.getLogger(StandardlyMapper.class);
+
     @UpdateProvider(
             type = StandardlyMapper.SqlProvider.class,
             method = "update"
@@ -75,6 +80,9 @@ public interface StandardlyMapper {
     @Select("select id from ${tableName} where ${akColumnName} = #{akColumnValue}")
     Long selectIdByAkColumn(@Param("tableName") String tableName, @Param("akColumnName") String akColumnName, @Param("akColumnValue") String akColumnValue);
 
+    @Select("select max(${pkName}) from ${tableName}")
+    Long selectMaxId(@Param("tableName") String tableName, @Param("pkName") String pkName);
+
     public static class SqlProvider {
         static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
 
@@ -215,7 +223,9 @@ public interface StandardlyMapper {
                     sql.VALUES(key, "#{model." + key + "}");
                 }
 
-                return sql.toString();
+                String sqlStr = sql.toString();
+                LOGGER.info("新增拼接的sql语句为: {}", sqlStr);
+                return sqlStr;
             }
         }
 

+ 63 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/BaseSaveService.java

@@ -0,0 +1,63 @@
+package com.boman.system.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.system.common.MainTableRecord;
+import com.boman.system.common.RowResult;
+import com.boman.system.common.TableService;
+import com.boman.system.common.TableServiceContext;
+import com.boman.system.mapper.StandardlyMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.sql.Timestamp;
+
+/**
+ * @author shiqian
+ * @description
+ * @date 2021年03月22日 11:25
+ **/
+@Component
+public class BaseSaveService {
+    private static final Logger LOGGER = LoggerFactory.getLogger(TableService.class);
+
+
+    //    @Resource
+//    StoredProcedureService storedProcedureService;
+    @Autowired
+    private StandardlyMapper mapper;
+
+    public RowResult insertRow(TableServiceContext context, MainTableRecord row, Timestamp currentTime) {
+        JSONObject commitData = row.getMainData().getCommitData();
+        commitData.put("CREATE_TIME", currentTime);
+        commitData.put("CREATE_BY", "张三");
+        commitData.put("UPDATE_BY", "张三");
+        commitData.put("UPDATE_TIME", currentTime);
+        int ret = mapper.insert(context.getRealTableName(), commitData);
+        if (ret > 0) {
+            commitData.put("successCnt", ret);
+            return RowResult.ok("保存成功", commitData);
+        }
+
+        return RowResult.error("失败");
+    }
+
+    public RowResult insertRow(String tableName, String pkName, Long maxId, MainTableRecord row) {
+        JSONObject commitData = row.getMainData().getCommitData();
+        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
+        commitData.put("CREATE_TIME", currentTime);
+        commitData.put("CREATE_BY", "张三");
+        commitData.put("UPDATE_BY", "张三");
+        commitData.put("UPDATE_TIME", currentTime);
+        commitData.put(pkName.toUpperCase(), maxId);
+        int ret = mapper.insert(tableName, commitData);
+        if (ret > 0) {
+            commitData.put("successCnt", ret);
+            return RowResult.ok("保存成功", commitData);
+        }
+
+        return RowResult.error("失败");
+    }
+
+}

+ 53 - 0
boman-modules/boman-system/src/main/java/com/boman/system/utils/IdUtils.java

@@ -0,0 +1,53 @@
+package com.boman.system.utils;
+
+import com.boman.common.core.utils.SpringUtils;
+import com.boman.common.redis.service.RedisService;
+import com.boman.gen.domain.GenTableColumn;
+import com.boman.system.mapper.StandardlyMapper;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @description
+ * @date 2021年03月23日 16:04
+ **/
+public class IdUtils {
+
+
+    public static Long getMaxId(String tableName, String pkName) {
+        RedisService redisService = SpringUtils.getBean(RedisService.class);
+        String sequencesKey = "SEQ:" + tableName.toUpperCase();
+        boolean isExist = redisService.exists(sequencesKey);
+        if (isExist) {
+            return redisService.increment(sequencesKey);
+        }
+
+        // 查数据库
+        StandardlyMapper mapper = SpringUtils.getBean(StandardlyMapper.class);
+        Long maxId = mapper.selectMaxId(tableName, pkName);
+        if (null == maxId || maxId <= 0) {
+            redisService.setCacheObject(sequencesKey, 1L);
+        } else {
+            redisService.increment(sequencesKey, ++maxId);
+        }
+
+        return maxId;
+    }
+
+    public static String getPkName(List<GenTableColumn> columnList) {
+        if (CollectionUtils.isEmpty(columnList)) {
+            throw new IllegalArgumentException("获取主键失败");
+        }
+
+        for (GenTableColumn tableColumn : columnList) {
+            if ("1".equalsIgnoreCase(tableColumn.getIsPk())) {
+                return tableColumn.getColumnName();
+            }
+        }
+
+        throw new IllegalArgumentException("获取主键失败");
+    }
+
+}