From 95e950ecd05bf23f1266aac9db0063dbc505304e Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Tue, 15 Oct 2024 14:06:03 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix:ASW-99=20=E4=BF=AE=E5=A4=8D=20package?= =?UTF-8?q?=20=E4=B8=8A=E4=BC=A0=E7=BC=BA=E5=B0=91=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E6=A0=BC=E5=BC=8F=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/geedge/asw/common/util/Constants.java | 5 +- .../net/geedge/asw/common/util/RCode.java | 1 + .../app/service/impl/PackageServiceImpl.java | 99 ++++++++++++------- .../resources/db/migration/R__AZ_sys_i18n.sql | 3 + 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/geedge/asw/common/util/Constants.java b/src/main/java/net/geedge/asw/common/util/Constants.java index f81bab1..2fe4f98 100644 --- a/src/main/java/net/geedge/asw/common/util/Constants.java +++ b/src/main/java/net/geedge/asw/common/util/Constants.java @@ -104,7 +104,10 @@ public class Constants { public static final Map ENV_TERMINAL_WEBSOCKET_SESSION = T.MapUtil.newHashMap(); - + /** + * Android package type + */ + public static final List ANDROID_PACKAGE_TYPE_LIST = T.ListUtil.of("xapk", "apk"); public static final String EMPTY_FILE_MD5 = "d41d8cd98f00b204e9800998ecf8427e"; } diff --git a/src/main/java/net/geedge/asw/common/util/RCode.java b/src/main/java/net/geedge/asw/common/util/RCode.java index a93bcac..6b717f2 100644 --- a/src/main/java/net/geedge/asw/common/util/RCode.java +++ b/src/main/java/net/geedge/asw/common/util/RCode.java @@ -55,6 +55,7 @@ public enum RCode { // Package PACKAGE_ID_CANNOT_EMPTY(202001, "package id cannot be empty"), PACKAGE_DESCRIPTION_CANNOT_EMPTY(202002, "package description cannot be empty"), + PACKAGE_FILE_TYPE_ERROR(202003, "package invalid file"), // Runner diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java index d4a0ea5..3f4f2a2 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java @@ -1,9 +1,12 @@ package net.geedge.asw.module.app.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.log.Log; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.common.util.ASWException; +import net.geedge.asw.common.util.Constants; import net.geedge.asw.common.util.RCode; import net.geedge.asw.common.util.T; import net.geedge.asw.module.app.dao.PackageDao; @@ -22,10 +25,14 @@ import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.BufferedReader; import java.io.File; -import java.nio.file.Path; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; @Service public class PackageServiceImpl extends ServiceImpl implements IPackageService { @@ -64,48 +71,72 @@ public class PackageServiceImpl extends ServiceImpl i } @Override + @Transactional(rollbackFor = Exception.class) public PackageEntity savePackage(String workspaceId, String description, Resource fileResource) { + + String pkgId = T.StrUtil.uuid(); + String filename = fileResource.getFilename(); + String suffix = T.FileUtil.extName(filename); + suffix = T.StrUtil.emptyToDefault(suffix, "apk"); + if (!Constants.ANDROID_PACKAGE_TYPE_LIST.contains(suffix)) { + throw new ASWException(RCode.PACKAGE_FILE_TYPE_ERROR); + } + String saveFileName = pkgId + "." + suffix; + File destination = T.FileUtil.file(PkgConstant.APK_FILES_DIR, saveFileName); PackageEntity entity = new PackageEntity(); + ApkUtil apkUtil = new ApkUtil(); + //apkUtil.setAaptToolPath(Path.of(T.WebPathUtil.getRootPath(), "lib", "aapt").toString()); + apkUtil.setAaptToolPath("D:\\Desktop\\asw\\aapt.exe"); try { - String pkgId = T.StrUtil.uuid(); - entity.setId(pkgId); - entity.setName(fileResource.getFilename()); - entity.setDescription(T.StrUtil.emptyToDefault(description, "")); - - // 默认安卓 - entity.setPlatform(PkgConstant.Platform.ANDROID.getValue()); - - entity.setWorkspaceId(workspaceId); - entity.setCreateUserId(StpUtil.getLoginIdAsString()); - entity.setUpdateUserId(StpUtil.getLoginIdAsString()); - entity.setCreateTimestamp(System.currentTimeMillis()); - entity.setUpdateTimestamp(System.currentTimeMillis()); - - byte[] bytes = fileResource.getInputStream().readAllBytes(); - entity.setSize((long) bytes.length); - - // path - String fileExtName = T.StrUtil.emptyToDefault(T.FileUtil.extName(fileResource.getFilename()), "pcap"); - String saveFileName = pkgId + "." + fileExtName; - File destination = T.FileUtil.file(PkgConstant.APK_FILES_DIR, saveFileName); FileUtils.copyInputStreamToFile(fileResource.getInputStream(), destination); - entity.setPath(destination.getPath()); - - // parse - try { - ApkUtil apkUtil = new ApkUtil(); - apkUtil.setAaptToolPath(Path.of(T.WebPathUtil.getRootPath(), "lib", "aapt").toString()); - ApkInfo apkInfo = apkUtil.parseApk(entity.getPath()); + if (suffix.equals("apk")) { + // parse + ApkInfo apkInfo = apkUtil.parseApk(destination.getPath()); + if (T.ObjectUtil.isNull(apkInfo)) { + throw new ASWException(RCode.PACKAGE_FILE_TYPE_ERROR); + } entity.setVersion(apkInfo.getVersionName()); entity.setIdentifier(apkInfo.getPackageName()); - } catch (Exception e) { - log.error(e, "[savePackage] [parse error] [file: {}]", fileResource.getFilename()); + } else { + ZipFile zipFile = new ZipFile(destination); + ZipEntry entry = zipFile.getEntry("manifest.json"); + InputStream inputStream = zipFile.getInputStream(entry); + StringBuilder manifestJson = new StringBuilder(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = reader.readLine()) != null) { + manifestJson.append(line).append("\n"); + } + Map manifest = T.JSONUtil.toBean(manifestJson.toString(), Map.class); + ZipEntry packageFile = zipFile.getEntry(T.StrUtil.concat(true,T.MapUtil.getStr(manifest, "package_name"),".apk")); + File temp = T.FileUtil.file(Constants.TEMP_PATH, packageFile.getName()); + FileUtil.writeBytes(zipFile.getInputStream(packageFile).readAllBytes(), temp); + ApkInfo apkInfo = apkUtil.parseApk(temp.getPath()); + String versionName = apkInfo.getVersionName(); + String packageName = apkInfo.getPackageName(); + if (!T.BooleanUtil.and(versionName.equals(T.MapUtil.getStr(manifest, "version_name")), packageName.equals(T.MapUtil.getStr(manifest, "package_name")))){ + throw new ASWException(RCode.PACKAGE_FILE_TYPE_ERROR); + } + entity.setVersion(versionName); + entity.setIdentifier(packageName); } - - this.save(entity); } catch (Exception e) { - log.error(e, "[savePackage] [error] [file: {}]", fileResource.getFilename()); + log.error(e, "[savePackage] [save package error] [file: {}]", fileResource.getFilename()); + FileUtil.del(destination); + throw new ASWException(RCode.PACKAGE_FILE_TYPE_ERROR); } + entity.setId(pkgId); + entity.setName(fileResource.getFilename()); + entity.setDescription(T.StrUtil.emptyToDefault(description, "")); + entity.setPlatform(PkgConstant.Platform.ANDROID.getValue()); + entity.setWorkspaceId(workspaceId); + entity.setCreateUserId(StpUtil.getLoginIdAsString()); + entity.setUpdateUserId(StpUtil.getLoginIdAsString()); + entity.setCreateTimestamp(System.currentTimeMillis()); + entity.setUpdateTimestamp(System.currentTimeMillis()); + entity.setSize(destination.length()); + entity.setPath(destination.getPath()); + this.save(entity); return entity; } diff --git a/src/main/resources/db/migration/R__AZ_sys_i18n.sql b/src/main/resources/db/migration/R__AZ_sys_i18n.sql index 886415b..28ca0ee 100644 --- a/src/main/resources/db/migration/R__AZ_sys_i18n.sql +++ b/src/main/resources/db/migration/R__AZ_sys_i18n.sql @@ -139,5 +139,8 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (231, '302002', 'PLAYBOOK_NAME_DUPLICATE', '剧本名称重复', 'zh', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (232, '601005', 'ENVIRONMENT_ID_CANNOT_EMPTY', 'environment id cannot be empty', 'en', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (233, '601005', 'ENVIRONMENT_ID_CANNOT_EMPTY', '环境 id 不能为空', 'zh', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (234, '202003', 'PACKAGE_FILE_TYPE_ERROR', 'package invalid file', 'en', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (235, '202003', 'PACKAGE_FILE_TYPE_ERROR', '无效安装包文件', 'zh', '', 'admin', 1724030366000); + SET FOREIGN_KEY_CHECKS = 1; From 59e01f71e5b0373e543d1e5b8f8174f2c9988938 Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Tue, 15 Oct 2024 14:11:12 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix:ASW-99=20=E8=B0=83=E6=95=B4=20aapt=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asw/module/app/service/impl/PackageServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java index 3f4f2a2..bcaa267 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java @@ -29,6 +29,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; @@ -85,8 +86,7 @@ public class PackageServiceImpl extends ServiceImpl i File destination = T.FileUtil.file(PkgConstant.APK_FILES_DIR, saveFileName); PackageEntity entity = new PackageEntity(); ApkUtil apkUtil = new ApkUtil(); - //apkUtil.setAaptToolPath(Path.of(T.WebPathUtil.getRootPath(), "lib", "aapt").toString()); - apkUtil.setAaptToolPath("D:\\Desktop\\asw\\aapt.exe"); + apkUtil.setAaptToolPath(Path.of(T.WebPathUtil.getRootPath(), "lib", "aapt").toString()); try { FileUtils.copyInputStreamToFile(fileResource.getInputStream(), destination); if (suffix.equals("apk")) { From 24d928d7ba7dd46b21d58cd42f36aad67c7a0c3f Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Tue, 15 Oct 2024 16:06:27 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:ASW-99=20=E8=B0=83=E6=95=B4=20xapk=20?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/impl/PackageServiceImpl.java | 28 ++---------- .../geedge/asw/module/app/util/ApkUtil.java | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java index bcaa267..9f862fa 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java @@ -25,15 +25,10 @@ import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.BufferedReader; import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; import java.nio.file.Path; import java.util.List; import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; @Service public class PackageServiceImpl extends ServiceImpl implements IPackageService { @@ -98,27 +93,12 @@ public class PackageServiceImpl extends ServiceImpl i entity.setVersion(apkInfo.getVersionName()); entity.setIdentifier(apkInfo.getPackageName()); } else { - ZipFile zipFile = new ZipFile(destination); - ZipEntry entry = zipFile.getEntry("manifest.json"); - InputStream inputStream = zipFile.getInputStream(entry); - StringBuilder manifestJson = new StringBuilder(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = reader.readLine()) != null) { - manifestJson.append(line).append("\n"); - } - Map manifest = T.JSONUtil.toBean(manifestJson.toString(), Map.class); - ZipEntry packageFile = zipFile.getEntry(T.StrUtil.concat(true,T.MapUtil.getStr(manifest, "package_name"),".apk")); - File temp = T.FileUtil.file(Constants.TEMP_PATH, packageFile.getName()); - FileUtil.writeBytes(zipFile.getInputStream(packageFile).readAllBytes(), temp); - ApkInfo apkInfo = apkUtil.parseApk(temp.getPath()); - String versionName = apkInfo.getVersionName(); - String packageName = apkInfo.getPackageName(); - if (!T.BooleanUtil.and(versionName.equals(T.MapUtil.getStr(manifest, "version_name")), packageName.equals(T.MapUtil.getStr(manifest, "package_name")))){ + ApkInfo apkInfo = apkUtil.parseXapk(destination.getPath()); + if (T.ObjectUtil.isNull(apkInfo)) { throw new ASWException(RCode.PACKAGE_FILE_TYPE_ERROR); } - entity.setVersion(versionName); - entity.setIdentifier(packageName); + entity.setVersion(apkInfo.getSdkVersion()); + entity.setIdentifier(apkInfo.getPackageName()); } } catch (Exception e) { log.error(e, "[savePackage] [save package error] [file: {}]", fileResource.getFilename()); diff --git a/src/main/java/net/geedge/asw/module/app/util/ApkUtil.java b/src/main/java/net/geedge/asw/module/app/util/ApkUtil.java index 1d34e79..b969591 100644 --- a/src/main/java/net/geedge/asw/module/app/util/ApkUtil.java +++ b/src/main/java/net/geedge/asw/module/app/util/ApkUtil.java @@ -1,9 +1,14 @@ package net.geedge.asw.module.app.util; +import cn.hutool.core.io.FileUtil; import cn.hutool.log.Log; +import net.geedge.asw.common.util.Constants; import net.geedge.asw.common.util.T; import java.io.*; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; public class ApkUtil { @@ -60,6 +65,9 @@ public class ApkUtil { while ((temp = bufferedReader.readLine()) != null) { setApkInfoProperty(apkInfo, temp); } + if (T.StrUtil.isBlank(apkInfo.getPackageName()) || T.StrUtil.isBlank(apkInfo.getVersionName())) { + return null; + } return apkInfo; } catch (IOException e) { log.error(e, "[parseApk] [error] [path: {}]", apkPath); @@ -73,6 +81,43 @@ public class ApkUtil { } } + public ApkInfo parseXapk(String xapkPath) { + InputStream inputStream = null; + BufferedReader reader = null; + File tempFile = null; + try { + ZipFile zipFile = new ZipFile(T.FileUtil.file(xapkPath)); + ZipEntry entry = zipFile.getEntry("manifest.json"); + inputStream = zipFile.getInputStream(entry); + StringBuilder manifestJson = new StringBuilder(); + reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = reader.readLine()) != null) { + manifestJson.append(line).append("\n"); + } + Map manifest = T.JSONUtil.toBean(manifestJson.toString(), Map.class); + ZipEntry packageFile = zipFile.getEntry(T.StrUtil.concat(true, T.MapUtil.getStr(manifest, "package_name"), ".apk")); + tempFile = T.FileUtil.file(Constants.TEMP_PATH, packageFile.getName()); + FileUtil.writeBytes(zipFile.getInputStream(packageFile).readAllBytes(), tempFile); + ApkInfo apkInfo = this.parseApk(tempFile.getPath()); + if (apkInfo == null) { + return null; + } + if (!T.BooleanUtil.and(apkInfo.getVersionName().equals(T.MapUtil.getStr(manifest, "version_name")), + apkInfo.getPackageName().equals(T.MapUtil.getStr(manifest, "package_name")))) { + return null; + } + return apkInfo; + } catch (Exception e) { + log.error(e, "[parseXapk] [error] [path: {}]", xapkPath); + return null; + } finally { + T.FileUtil.del(tempFile); + T.IoUtil.close(inputStream); + T.IoUtil.close(reader); + } + } + private void setApkInfoProperty(ApkInfo apkInfo, String source) { if (source.startsWith(APPLICATION)) { String[] rs = source.split("( icon=')|'"); From 524e9f8880a33f1440370cf5fc6092ead7a16c45 Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Thu, 17 Oct 2024 10:02:29 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=E5=BC=80=E5=90=AFjob=20=E8=8F=9C?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/db/migration/R__AZ_sys_menu.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/db/migration/R__AZ_sys_menu.sql b/src/main/resources/db/migration/R__AZ_sys_menu.sql index 5dae931..93b5013 100644 --- a/src/main/resources/db/migration/R__AZ_sys_menu.sql +++ b/src/main/resources/db/migration/R__AZ_sys_menu.sql @@ -29,7 +29,7 @@ INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, ` INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('4003', 'package_delete', 'buttons.delete', '4000', 'button', '', '', '', 3, 1722478572000, 1); INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('4004', 'package_download', 'buttons.download', '4000', 'button', '', '', '', 4, 1722478572000, 1); -INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('5000', 'jobs', 'overall.jobs', '0', 'menu', '', '/jobs', 'asw-icon icon-Jobs', 4, 1722478572000, 0); +INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('5000', 'jobs', 'overall.jobs', '0', 'menu', '', '/jobs', 'asw-icon icon-Jobs', 4, 1722478572000, 1); INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('5001', 'job_view', 'buttons.view', '5000', 'button', '', '', '', 1, 1722478572000, 1); INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('5002', 'job_add', 'buttons.add', '5000', 'button', '', '', '', 2, 1722478572000, 1); INSERT INTO `sys_menu` (`id`, `name`, `i18n`, `pid`, `type`, `perms`, `route`, `icon`, `order`, `create_timestamp`, `state`) VALUES ('5003', 'job_delete', 'buttons.delete', '5000', 'button', '', '', '', 3, 1722478572000, 1); From 705f8c7c71890a1cef93b26d800d840622e99de3 Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Fri, 18 Oct 2024 17:54:28 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:ASW-107=20=E4=BF=AE=E5=A4=8D=20member?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=97=B6=20member=20=E8=A2=AB=E6=B8=85?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WorkspaceMemberServiceImpl.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java b/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java index 161d904..f80a5e3 100644 --- a/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java @@ -2,6 +2,7 @@ package net.geedge.asw.module.workspace.service.impl; import cn.dev33.satoken.stp.StpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import net.geedge.asw.common.util.ASWException; import net.geedge.asw.common.util.RCode; @@ -50,9 +51,22 @@ public class WorkspaceMemberServiceImpl extends ServiceImpl updateMember(String workspaceId, List memberList) { - validateInfo(workspaceId, memberList); - workspaceMemberService.remove(new LambdaQueryWrapper().eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId)); - workspaceMemberService.saveBatch(memberList); + List list = this.list(new LambdaQueryWrapper().eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId)); + List userIds = list.stream().map(x -> x.getUserId()).toList(); + for (WorkspaceMemberEntity member : memberList) { + String userId = member.getUserId(); + if (!userIds.contains(userId)) { + this.update(new LambdaUpdateWrapper() + .eq(WorkspaceMemberEntity::getUserId, userId) + .eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId) + .set(WorkspaceMemberEntity::getRoleId, member.getRoleId())); + }else { + member.setWorkspaceId(workspaceId); + member.setCreateTimestamp(System.currentTimeMillis()); + member.setCreateUserId(StpUtil.getLoginIdAsString()); + this.save(member); + } + } Map params = T.MapUtil.builder("workspaceId", workspaceId).build(); List memberEntityList = workspaceMemberService.queryList(params); return memberEntityList; From 661af68cbf9787fffddf034e0b4bfb21625407b8 Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Fri, 18 Oct 2024 17:56:06 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20member=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=20member=20=E8=A2=AB=E6=B8=85?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workspace/service/impl/WorkspaceMemberServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java b/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java index f80a5e3..2b05fc9 100644 --- a/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/workspace/service/impl/WorkspaceMemberServiceImpl.java @@ -55,7 +55,7 @@ public class WorkspaceMemberServiceImpl extends ServiceImpl userIds = list.stream().map(x -> x.getUserId()).toList(); for (WorkspaceMemberEntity member : memberList) { String userId = member.getUserId(); - if (!userIds.contains(userId)) { + if (userIds.contains(userId)) { this.update(new LambdaUpdateWrapper() .eq(WorkspaceMemberEntity::getUserId, userId) .eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId) From fe0a344ec40c090328ec22b8b79e3b09e855c2e2 Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Mon, 21 Oct 2024 14:37:52 +0800 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=20job=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20workspaceId=20=E4=B8=BApath=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/geedge/asw/module/runner/controller/JobController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/geedge/asw/module/runner/controller/JobController.java b/src/main/java/net/geedge/asw/module/runner/controller/JobController.java index 8e1771e..f0f886d 100644 --- a/src/main/java/net/geedge/asw/module/runner/controller/JobController.java +++ b/src/main/java/net/geedge/asw/module/runner/controller/JobController.java @@ -32,7 +32,8 @@ public class JobController { public R list(@PathVariable("workspaceId") String workspaceId, @RequestParam Map params) { T.VerifyUtil.is(params).notNull() - .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + params.put("workspaceId", workspaceId); Page page = jobService.queryList(params); return R.ok(page); }