Prechádzať zdrojové kódy

Merge branch 'dev' of gitee.com:Gd-Lianjy/magic-api into dev

Lianjy 4 rokov pred
rodič
commit
6b256bf810

+ 0 - 5
magic-api/pom.xml

@@ -67,10 +67,5 @@
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-compress</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.jeecgframework</groupId>
-            <artifactId>autopoi-web</artifactId>
-            <scope>provided</scope>
-        </dependency>
     </dependencies>
 </project>

+ 30 - 3
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java

@@ -157,20 +157,47 @@ public class NamedTable {
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
 	public Object save() {
-		return this.save(null);
+		return this.save(null,false);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("各项列和值") Map<String, Object> data) {
+	public Object save(@Comment("各项列和值") Map<String, Object> data, @Comment("是否根据id查询有没有数据") boolean beforeQuery) {
 		if (StringUtils.isBlank(this.primary)) {
 			throw new MagicAPIException("请设置主键");
 		}
-		if (StringUtils.isNotBlank(Objects.toString(this.columns.get(this.primary), "")) || (data != null && StringUtils.isNotBlank(Objects.toString(data.get(this.primary), "")))) {
+		String primaryValue = Objects.toString(this.columns.get(this.primary), "");
+		if(StringUtils.isBlank(primaryValue) && data != null){
+			primaryValue = Objects.toString(data.get(this.primary), "");
+		}
+		if(beforeQuery){
+			if(StringUtils.isNotBlank(primaryValue)){
+				List<Object> params = new ArrayList<>();
+				params.add(primaryValue);
+				Map<String, Object> oneMap = sqlModule.selectOne(new BoundSql("select count(1) count from " + this.tableName + " where " + this.primary + " = ?", params, sqlModule));
+				Integer count = new Integer(oneMap.get("count").toString());
+				if(count == 0){
+					return insert(data);
+				}
+				return update(data);
+			} else {
+				return insert(data);
+			}
+		}
+		if (StringUtils.isNotBlank(primaryValue)) {
 			return update(data);
 		}
 		return insert(data);
 	}
 
+	@Comment("保存到表中,当主键有值时则修改,否则插入")
+	public Object save(boolean beforeQuery) {
+		return this.save(null, beforeQuery);
+	}
+
+	@Comment("保存到表中,当主键有值时则修改,否则插入")
+	public Object save(@Comment("各项列和值") Map<String, Object> data) {
+		return this.save(data, false);
+	}
 
 	@Comment("执行`select`查询")
 	public List<Map<String, Object>> select() {

+ 15 - 0
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/Where.java

@@ -350,11 +350,21 @@ public class Where {
 		return namedTable.save();
 	}
 
+	@Comment("保存到表中,当主键有值时则修改,否则插入")
+	public Object save(@Comment("是否根据id查询有没有数据") boolean beforeQuery) {
+		return namedTable.save(beforeQuery);
+	}
+
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
 	public Object save(@Comment("各项列和值") Map<String, Object> data) {
 		return namedTable.save(data);
 	}
 
+	@Comment("保存到表中,当主键有值时则修改,否则插入")
+	public Object save(@Comment("各项列和值") Map<String, Object> data, @Comment("是否根据id查询有没有数据") boolean beforeQuery) {
+		return namedTable.save(data, beforeQuery);
+	}
+
 	@Comment("执行插入语句,返回主键")
 	public Object insert() {
 		return namedTable.insert();
@@ -370,6 +380,11 @@ public class Where {
 		return namedTable.update();
 	}
 
+	@Comment("执行delete语句")
+	public int delete() {
+		return namedTable.delete();
+	}
+
 	@Comment("执行update语句")
 	public int update(@Comment("各项列和值") Map<String, Object> data) {
 		return namedTable.update(data);

+ 7 - 13
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java

@@ -509,7 +509,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 		Set<ApiInfo> apiInfos = new HashSet<>();
 		Set<FunctionInfo> functionInfos = new HashSet<>();
 		// 检查上传资源中是否有冲突
-		isTrue(readPaths(groups, apiPaths, functionPaths, apiInfos, functionInfos, "/", root), UPLOAD_PATH_CONFLICT);
+		readPaths(groups, apiPaths, functionPaths, apiInfos, functionInfos, "/", root);
 		Resource item = root.getResource(Constants.GROUP_METABASE);
 		if (item.exists()) {
 			Group group = groupServiceProvider.readGroup(item);
@@ -752,7 +752,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 		}
 	}
 
-	private boolean readPaths(Set<Group> groups, Set<String> apiPaths, Set<String> functionPaths, Set<ApiInfo> apiInfos, Set<FunctionInfo> functionInfos, String parentPath, Resource root) {
+	private void readPaths(Set<Group> groups, Set<String> apiPaths, Set<String> functionPaths, Set<ApiInfo> apiInfos, Set<FunctionInfo> functionInfos, String parentPath, Resource root) {
 		Resource resource = root.getResource(Constants.GROUP_METABASE);
 		String path = "";
 		if (resource.exists()) {
@@ -761,27 +761,21 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 			path = Objects.toString(group.getPath(), "");
 			boolean isApi = Constants.GROUP_TYPE_API.equals(group.getType());
 			for (Resource file : root.files(".ms")) {
-				boolean conflict;
 				if (isApi) {
 					ApiInfo info = apiServiceProvider.deserialize(file.read());
 					apiInfos.add(info);
-					conflict = !apiPaths.add(Objects.toString(info.getMethod(), "GET") + ":" + PathUtils.replaceSlash(parentPath + "/" + path + "/" + info.getPath()));
+					String apiPath = Objects.toString(info.getMethod(), "GET") + ":" + PathUtils.replaceSlash(parentPath + "/" + path + "/" + info.getPath());
+					isTrue(apiPaths.add(apiPath), UPLOAD_PATH_CONFLICT.format(apiPath));
 				} else {
 					FunctionInfo info = functionServiceProvider.deserialize(file.read());
 					functionInfos.add(info);
-					conflict = !functionPaths.add(PathUtils.replaceSlash(parentPath + "/" + path + "/" + info.getPath()));
-				}
-				if (conflict) {
-					return false;
+					String functionPath = PathUtils.replaceSlash(parentPath + "/" + path + "/" + info.getPath());
+					isTrue(functionPaths.add(functionPath), UPLOAD_PATH_CONFLICT.format(functionPath));
 				}
 			}
 		}
 		for (Resource directory : root.dirs()) {
-			if (!readPaths(groups, apiPaths, functionPaths, apiInfos, functionInfos, PathUtils.replaceSlash(parentPath + "/" + path), directory)) {
-				return false;
-			}
+			readPaths(groups, apiPaths, functionPaths, apiInfos, functionInfos, PathUtils.replaceSlash(parentPath + "/" + path), directory);
 		}
-		return true;
 	}
-
 }

+ 0 - 6
pom.xml

@@ -37,7 +37,6 @@
         <commons-beanutils.version>1.9.4</commons-beanutils.version>
         <swagger.version>2.9.2</swagger.version>
         <fastjson.version>1.2.75</fastjson.version>
-        <autopoi-web.version>1.2.4</autopoi-web.version>
         <spring-boot-starter-log4j.version>1.3.8.RELEASE</spring-boot-starter-log4j.version>
         <java.version>1.8</java.version>
         <maven.compiler.source>1.8</maven.compiler.source>
@@ -103,11 +102,6 @@
                 <artifactId>springfox-swagger2</artifactId>
                 <version>${swagger.version}</version>
             </dependency>
-            <dependency>
-                <groupId>org.jeecgframework</groupId>
-                <artifactId>autopoi-web</artifactId>
-                <version>${autopoi-web.version}</version>
-            </dependency>
         </dependencies>
     </dependencyManagement>
     <build>