shiqian пре 4 година
родитељ
комит
e6a7a28672

+ 61 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java

@@ -0,0 +1,61 @@
+package com.boman.web.core.service.common;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.common.redis.RedisKey;
+import com.boman.common.redis.service.RedisService;
+import com.boman.gen.domain.GenTable;
+import com.boman.web.core.service.TableServiceCmdService;
+import com.boman.web.core.service.select.IBaseSelectService;
+import com.boman.web.core.utils.IdUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+import java.util.List;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+
+/**
+ * @author shiqian
+ * @date 2021年04月15日 16:31
+ **/
+@Service
+public class CommonServiceImpl implements ICommonService {
+
+    @Resource
+    private IBaseSelectService selectService;
+    @Resource
+    private RedisService redisService;
+    @Resource
+    private TableServiceCmdService cmdService;
+
+    /**
+     * 功能描述: 根据表名和id查找
+     *
+     * @param tableName tableName
+     * @param id        id
+     * @return JSONObject
+     */
+    @Override
+    public JSONObject getById(String tableName, Long id) {
+        requireNonNull(tableName, "tableName is empty");
+        requireNonNull(id, "id is empty");
+
+        GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
+        String pkName = IdUtils.getPkName(genTable.getColumns());
+        return selectService.selectById(tableName, pkName, id);
+    }
+
+    /**
+     * 功能描述: 根据condition进行查找
+     *
+     * @param tableName tableName
+     * @param condition condition
+     * @return java.util.List<com.alibaba.fastjson.JSONObject>
+     */
+    @Override
+    public List<JSONObject> getByMap(String tableName, JSONObject condition) {
+        requireNonNull(tableName, "tableName is empty");
+        return selectService.getByMap(tableName, condition);
+    }
+}

+ 31 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java

@@ -0,0 +1,31 @@
+package com.boman.web.core.service.common;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @date 2021年04月15日 16:31
+ **/
+public interface ICommonService {
+
+    /**
+     * 功能描述: 根据表名和id查找
+     *
+     * @param tableName tableName
+     * @param id        id
+     * @return JSONObject
+     */
+    JSONObject getById(String tableName, Long id);
+
+
+    /**
+     * 功能描述: 根据condition进行查找
+     *
+     * @param tableName tableName
+     * @param condition condition
+     * @return java.util.List<com.alibaba.fastjson.JSONObject>
+     */
+    List<JSONObject> getByMap(String tableName, JSONObject condition);
+}