From bec7e907742f4caeefcccad57f97572a6a7d16d7 Mon Sep 17 00:00:00 2001 From: shizhendong Date: Thu, 5 Sep 2024 11:24:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ASW-59=20application=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4=EF=BC=9B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20href=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/ApplicationController.java | 102 ++++++++++++++++-- .../module/app/dao/ApplicationHrefDao.java | 15 +++ .../module/app/entity/ApplicationEntity.java | 4 + .../app/entity/ApplicationHrefEntity.java | 30 ++++++ .../app/service/IApplicationHrefService.java | 17 +++ .../impl/ApplicationHrefServiceImpl.java | 62 +++++++++++ .../service/impl/ApplicationServiceImpl.java | 8 ++ .../db/mapper/app/ApplicationHrefMapper.xml | 35 ++++++ .../db/migration/V1.0.01__INIT_TABLES.sql | 24 ++++- 9 files changed, 282 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/geedge/asw/module/app/dao/ApplicationHrefDao.java create mode 100644 src/main/java/net/geedge/asw/module/app/entity/ApplicationHrefEntity.java create mode 100644 src/main/java/net/geedge/asw/module/app/service/IApplicationHrefService.java create mode 100644 src/main/java/net/geedge/asw/module/app/service/impl/ApplicationHrefServiceImpl.java create mode 100644 src/main/resources/db/mapper/app/ApplicationHrefMapper.xml diff --git a/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java b/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java index 10ef8bb..b0a1eed 100644 --- a/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java +++ b/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java @@ -1,6 +1,7 @@ package net.geedge.asw.module.app.controller; import cn.hutool.json.JSONObject; +import cn.hutool.log.Log; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.servlet.http.HttpServletResponse; @@ -8,21 +9,17 @@ import net.geedge.asw.common.util.ASWException; import net.geedge.asw.common.util.R; import net.geedge.asw.common.util.RCode; import net.geedge.asw.common.util.T; -import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity; -import net.geedge.asw.module.app.entity.ApplicationEntity; -import net.geedge.asw.module.app.entity.ApplicationNoteEntity; -import net.geedge.asw.module.app.entity.ApplicationSignatureEntity; -import net.geedge.asw.module.app.service.IApplicationAttachmentService; -import net.geedge.asw.module.app.service.IApplicationNoteService; -import net.geedge.asw.module.app.service.IApplicationService; -import net.geedge.asw.module.app.service.IApplicationSignatureService; +import net.geedge.asw.module.app.entity.*; +import net.geedge.asw.module.app.service.*; import net.geedge.asw.module.workspace.entity.WorkspaceEntity; import net.geedge.asw.module.workspace.service.IWorkspaceService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -31,6 +28,8 @@ import java.util.stream.Collectors; @RequestMapping("/api/v1/application") public class ApplicationController { + private static final Log log = Log.get(); + @Autowired private IWorkspaceService workspaceService; @@ -43,6 +42,9 @@ public class ApplicationController { @Autowired private IApplicationNoteService noteService; + @Autowired + private IApplicationHrefService hrefService; + @Autowired private IApplicationAttachmentService attachmentService; @@ -66,14 +68,53 @@ public class ApplicationController { } @PostMapping - public R add(@RequestBody ApplicationEntity entity) { + @Transactional(rollbackFor = Exception.class) + public R add(@RequestParam(required = true) String basic, + @RequestParam(required = false) String signature, + @RequestParam(required = false) String note, + @RequestParam(required = false) String hrefs, + @RequestParam(required = false, value = "files") List fileList) { + // validate + ApplicationEntity entity; + try { + entity = T.JSONUtil.toBean(basic, ApplicationEntity.class); + + if (T.StrUtil.isNotEmpty(signature)) { + ApplicationSignatureEntity signatureEntity = T.JSONUtil.toBean(signature, ApplicationSignatureEntity.class); + entity.setSignature(signatureEntity); + } + + if (T.StrUtil.isNotEmpty(note)) { + ApplicationNoteEntity noteEntity = T.JSONUtil.toBean(note, ApplicationNoteEntity.class); + entity.setNote(noteEntity); + } + + if (T.StrUtil.isNotEmpty(hrefs)) { + T.JSONUtil.toList(hrefs, ApplicationHrefEntity.class); + } + } catch (Exception e) { + log.error(e, "[add] [param format error]"); + throw new ASWException(RCode.ERROR); + } + T.VerifyUtil.is(entity).notNull() .and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) - //.and(entity.getSignature()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) - //.and(entity.getNote()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + // save application ApplicationEntity applicationEntity = applicationService.saveApplication(entity); + + // save attachment + fileList = T.CollUtil.defaultIfEmpty(fileList, new ArrayList<>()); + for (MultipartFile file : fileList) { + attachmentService.saveAttachment(file.getResource(), applicationEntity.getId()); + } + + // save href + if (T.StrUtil.isNotEmpty(hrefs)) { + List hrefList = T.JSONUtil.toList(hrefs, ApplicationHrefEntity.class); + hrefService.updateBatchHref(applicationEntity.getId(), hrefList); + } return R.ok().putData("id", applicationEntity.getId()); } @@ -190,6 +231,45 @@ public class ApplicationController { } + // application href + @GetMapping("/{applicationId}/href") + public R queryHref(@PathVariable String applicationId) { + List entityList = hrefService.queryList(applicationId); + return R.ok().putData("records", entityList); + } + + @RequestMapping(value = "/{applicationId}/href", method = {RequestMethod.POST, RequestMethod.PUT}) + public R updateBatchHref(@PathVariable String applicationId, @RequestBody List hrefList) { + // validate + ApplicationEntity application = applicationService.getById(applicationId); + T.VerifyUtil.is(application).notNull(RCode.APP_NOT_EXIST); + + for (ApplicationHrefEntity href : hrefList) { + T.VerifyUtil.is(href).notNull() + .and(href.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) + .and(href.getUrl()).notEmpty(RCode.PARAM_CANNOT_EMPTY); + + href.setApplicationId(applicationId); + } + + // save or update batch + List entityList = hrefService.updateBatchHref(hrefList); + List> records = entityList.stream() + .map(entity -> Map.of("id", entity.getId())) + .collect(Collectors.toList()); + return R.ok().putData("records", records); + } + + @DeleteMapping("/{applicationId}/href") + public R deleteHref(@PathVariable String applicationId, @RequestParam String[] ids) { + // remove + hrefService.remove(new LambdaQueryWrapper() + .eq(ApplicationHrefEntity::getApplicationId, applicationId) + .in(ApplicationHrefEntity::getId, T.ListUtil.of(ids))); + return R.ok(); + } + + @PostMapping("/import") public R importApplication(@RequestParam String workspaceId, @RequestParam(defaultValue = "tsg2402") String format, diff --git a/src/main/java/net/geedge/asw/module/app/dao/ApplicationHrefDao.java b/src/main/java/net/geedge/asw/module/app/dao/ApplicationHrefDao.java new file mode 100644 index 0000000..a7b2f03 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/dao/ApplicationHrefDao.java @@ -0,0 +1,15 @@ +package net.geedge.asw.module.app.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import net.geedge.asw.module.app.entity.ApplicationHrefEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ApplicationHrefDao extends BaseMapper { + + List queryList(@Param("applicationId") String applicationId); + +} diff --git a/src/main/java/net/geedge/asw/module/app/entity/ApplicationEntity.java b/src/main/java/net/geedge/asw/module/app/entity/ApplicationEntity.java index 0b62f21..b2adfae 100644 --- a/src/main/java/net/geedge/asw/module/app/entity/ApplicationEntity.java +++ b/src/main/java/net/geedge/asw/module/app/entity/ApplicationEntity.java @@ -60,4 +60,8 @@ public class ApplicationEntity { @TableField(exist = false) private List attatchments; + + @TableField(exist = false) + private List hrefs; + } \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/app/entity/ApplicationHrefEntity.java b/src/main/java/net/geedge/asw/module/app/entity/ApplicationHrefEntity.java new file mode 100644 index 0000000..148851a --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/entity/ApplicationHrefEntity.java @@ -0,0 +1,30 @@ +package net.geedge.asw.module.app.entity; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import net.geedge.asw.module.sys.entity.SysUserEntity; + +import java.io.Serializable; + +@Data +@TableName(value = "application_href", autoResultMap = true) +public class ApplicationHrefEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(type = IdType.ASSIGN_UUID) + private String id; + private String applicationId; + private String name; + private String url; + + @TableField(updateStrategy = FieldStrategy.NEVER) + private Long createTimestamp; + + @TableField(updateStrategy = FieldStrategy.NEVER) + private String createUserId; + + @TableField(exist = false) + private SysUserEntity createUser; + +} \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/app/service/IApplicationHrefService.java b/src/main/java/net/geedge/asw/module/app/service/IApplicationHrefService.java new file mode 100644 index 0000000..98d8779 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/service/IApplicationHrefService.java @@ -0,0 +1,17 @@ +package net.geedge.asw.module.app.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import net.geedge.asw.module.app.entity.ApplicationHrefEntity; + +import java.util.List; + +public interface IApplicationHrefService extends IService { + + List queryList(String applicationId); + + List updateBatchHref(List hrefList); + + List updateBatchHref(String applicationId, List hrefList); + + +} diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationHrefServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationHrefServiceImpl.java new file mode 100644 index 0000000..82b5245 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationHrefServiceImpl.java @@ -0,0 +1,62 @@ +package net.geedge.asw.module.app.service.impl; + +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.log.Log; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.common.util.ASWException; +import net.geedge.asw.common.util.RCode; +import net.geedge.asw.common.util.T; +import net.geedge.asw.module.app.dao.ApplicationHrefDao; +import net.geedge.asw.module.app.entity.ApplicationHrefEntity; +import net.geedge.asw.module.app.service.IApplicationHrefService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +public class ApplicationHrefServiceImpl extends ServiceImpl implements IApplicationHrefService { + + private static final Log log = Log.get(); + + @Override + public List queryList(String applicationId) { + return this.getBaseMapper().queryList(applicationId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public List updateBatchHref(List hrefList) { + for (ApplicationHrefEntity entity : hrefList) { + + // validate + ApplicationHrefEntity one = this.getOne(new LambdaQueryWrapper() + .eq(ApplicationHrefEntity::getApplicationId, entity.getApplicationId()) + .eq(ApplicationHrefEntity::getName, entity.getName()) + .ne(T.ObjectUtil.isNotEmpty(entity.getId()), ApplicationHrefEntity::getId, entity.getId())); + if (T.ObjectUtil.isNotNull(one)) { + throw ASWException.builder().rcode(RCode.SYS_DUPLICATE_RECORD).build(); + } + + entity.setCreateTimestamp(System.currentTimeMillis()); + entity.setCreateUserId(StpUtil.getLoginIdAsString()); + } + + // update batch + if (T.CollUtil.isNotEmpty(hrefList)) { + this.saveOrUpdateBatch(hrefList); + } + + return hrefList; + } + + @Override + public List updateBatchHref(String applicationId, List hrefList) { + for (ApplicationHrefEntity entity : hrefList) { + entity.setApplicationId(applicationId); + } + return this.updateBatchHref(hrefList); + } + +} \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java index 6ed60a6..8dd0385 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java @@ -42,6 +42,9 @@ public class ApplicationServiceImpl extends ServiceImpl x.setPath(null)); app.setAttatchments(attachmentEntityList); + List hrefEntityList = hrefService.list(new LambdaQueryWrapper() + .eq(ApplicationHrefEntity::getApplicationId, app.getId())); + app.setHrefs(hrefEntityList); + SysUserEntity createUser = userService.getById(app.getCreateUserId()); SysUserEntity updateUser = userService.getById(app.getUpdateUserId()); app.setCreateUser(createUser); @@ -206,6 +213,7 @@ public class ApplicationServiceImpl extends ServiceImpl().in(ApplicationSignatureEntity::getApplicationId, ids)); noteService.remove(new LambdaQueryWrapper().in(ApplicationNoteEntity::getApplicationId, ids)); attachmentService.remove(new LambdaQueryWrapper().in(ApplicationAttachmentEntity::getApplicationId, ids)); + hrefService.remove(new LambdaQueryWrapper().in(ApplicationHrefEntity::getApplicationId, ids)); } @Override diff --git a/src/main/resources/db/mapper/app/ApplicationHrefMapper.xml b/src/main/resources/db/mapper/app/ApplicationHrefMapper.xml new file mode 100644 index 0000000..402099d --- /dev/null +++ b/src/main/resources/db/mapper/app/ApplicationHrefMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql index 466161d..7ab3bb8 100644 --- a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql +++ b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql @@ -255,11 +255,11 @@ CREATE TABLE `application` ( `id` varchar(64) NOT NULL COMMENT '主键', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称', `tags` TEXT NOT NULL DEFAULT '' COMMENT '标签', - `package_name` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '包名', + `package_name` VARCHAR(512) NOT NULL DEFAULT '{}' COMMENT '包名', `website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站', `provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者', `status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done', - `properties` VARCHAR(4096) NOT NULL DEFAULT '' COMMENT '属性', + `properties` VARCHAR(4096) NOT NULL DEFAULT '{}' COMMENT '属性', `description` text NOT NULL DEFAULT '' COMMENT '描述信息', `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', `update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳', @@ -281,11 +281,11 @@ CREATE TABLE `application_log` ( `id` varchar(64) NOT NULL COMMENT '主键', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称', `tags` TEXT NOT NULL DEFAULT '' COMMENT '标签', - `package_name` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '包名', + `package_name` VARCHAR(512) NOT NULL DEFAULT '{}' COMMENT '包名', `website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站', `provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者', `status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done', - `properties` VARCHAR(4096) NOT NULL DEFAULT '' COMMENT '属性', + `properties` VARCHAR(4096) NOT NULL DEFAULT '{}' COMMENT '属性', `description` text NOT NULL DEFAULT '' COMMENT '描述信息', `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', `update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳', @@ -338,6 +338,22 @@ CREATE TABLE `application_attachment` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +/** + * 新增 application_href 表 + */ +DROP TABLE IF EXISTS `application_href`; +CREATE TABLE `application_href` ( + `id` VARCHAR(64) NOT NULL COMMENT '主键', + `application_id` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '应用id', + `name` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '名称', + `url` VARCHAR(512) NOT NULL DEFAULT '' COMMENT 'url地址', + `create_timestamp` BIGINT(20) NOT NULL COMMENT '创建时间戳', + `create_user_id` VARCHAR(64) NOT NULL COMMENT '创建人id', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_name` (`name`) USING BTREE, + KEY `idx_application_id` (`application_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + /** * 新增 package 表 */