summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2024-09-05 11:24:05 +0800
committershizhendong <[email protected]>2024-09-05 11:24:05 +0800
commitbec7e907742f4caeefcccad57f97572a6a7d16d7 (patch)
treeacf809ca713c5ebe773db711efe86be7501316b2
parent0f4c12b38ed296c6acc9544013556aee1b65c4f8 (diff)
feat: ASW-59 application 新增接口调整;增加 href 属性
-rw-r--r--src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java102
-rw-r--r--src/main/java/net/geedge/asw/module/app/dao/ApplicationHrefDao.java15
-rw-r--r--src/main/java/net/geedge/asw/module/app/entity/ApplicationEntity.java4
-rw-r--r--src/main/java/net/geedge/asw/module/app/entity/ApplicationHrefEntity.java30
-rw-r--r--src/main/java/net/geedge/asw/module/app/service/IApplicationHrefService.java17
-rw-r--r--src/main/java/net/geedge/asw/module/app/service/impl/ApplicationHrefServiceImpl.java62
-rw-r--r--src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java8
-rw-r--r--src/main/resources/db/mapper/app/ApplicationHrefMapper.xml35
-rw-r--r--src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql24
9 files changed, 282 insertions, 15 deletions
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;
@@ -44,6 +43,9 @@ public class ApplicationController {
private IApplicationNoteService noteService;
@Autowired
+ private IApplicationHrefService hrefService;
+
+ @Autowired
private IApplicationAttachmentService attachmentService;
@GetMapping("/{id}")
@@ -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<MultipartFile> 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<ApplicationHrefEntity> 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<ApplicationHrefEntity> 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<ApplicationHrefEntity> 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<ApplicationHrefEntity> entityList = hrefService.updateBatchHref(hrefList);
+ List<Map<String, String>> 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<ApplicationHrefEntity>()
+ .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<ApplicationHrefEntity> {
+
+ List<ApplicationHrefEntity> 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<ApplicationAttachmentEntity> attatchments;
+
+ @TableField(exist = false)
+ private List<ApplicationHrefEntity> 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<ApplicationHrefEntity> {
+
+ List<ApplicationHrefEntity> queryList(String applicationId);
+
+ List<ApplicationHrefEntity> updateBatchHref(List<ApplicationHrefEntity> hrefList);
+
+ List<ApplicationHrefEntity> updateBatchHref(String applicationId, List<ApplicationHrefEntity> 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<ApplicationHrefDao, ApplicationHrefEntity> implements IApplicationHrefService {
+
+ private static final Log log = Log.get();
+
+ @Override
+ public List<ApplicationHrefEntity> queryList(String applicationId) {
+ return this.getBaseMapper().queryList(applicationId);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public List<ApplicationHrefEntity> updateBatchHref(List<ApplicationHrefEntity> hrefList) {
+ for (ApplicationHrefEntity entity : hrefList) {
+
+ // validate
+ ApplicationHrefEntity one = this.getOne(new LambdaQueryWrapper<ApplicationHrefEntity>()
+ .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<ApplicationHrefEntity> updateBatchHref(String applicationId, List<ApplicationHrefEntity> 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
@@ -43,6 +43,9 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
private IApplicationNoteService noteService;
@Autowired
+ private IApplicationHrefService hrefService;
+
+ @Autowired
private IApplicationAttachmentService attachmentService;
@Autowired
@@ -71,6 +74,10 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
attachmentEntityList.stream().forEach(x -> x.setPath(null));
app.setAttatchments(attachmentEntityList);
+ List<ApplicationHrefEntity> hrefEntityList = hrefService.list(new LambdaQueryWrapper<ApplicationHrefEntity>()
+ .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<ApplicationDao, Applicat
signatureService.remove(new LambdaQueryWrapper<ApplicationSignatureEntity>().in(ApplicationSignatureEntity::getApplicationId, ids));
noteService.remove(new LambdaQueryWrapper<ApplicationNoteEntity>().in(ApplicationNoteEntity::getApplicationId, ids));
attachmentService.remove(new LambdaQueryWrapper<ApplicationAttachmentEntity>().in(ApplicationAttachmentEntity::getApplicationId, ids));
+ hrefService.remove(new LambdaQueryWrapper<ApplicationHrefEntity>().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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="net.geedge.asw.module.app.dao.ApplicationHrefDao">
+
+ <!-- 通用查询映射结果 -->
+ <resultMap id="resultMap" type="net.geedge.asw.module.app.entity.ApplicationHrefEntity">
+ <id column="id" property="id"/>
+ <result column="application_id" property="applicationId"/>
+ <result column="name" property="name"/>
+ <result column="url" property="url"/>
+ <result column="create_timestamp" property="createTimestamp"/>
+ <result column="create_user_id" property="createUserId"/>
+
+ <association property="createUser" columnPrefix="cu_" javaType="net.geedge.asw.module.sys.entity.SysUserEntity">
+ <id property="id" column="id"/>
+ <result property="name" column="name"/>
+ <result property="userName" column="user_name"/>
+ </association>
+
+ </resultMap>
+
+ <select id="queryList" resultMap="resultMap">
+ SELECT
+ href.*,
+ cu.id AS cu_id,
+ cu.NAME AS cu_name,
+ cu.user_name AS cu_user_name
+ FROM
+ application_href href
+ LEFT JOIN sys_user cu ON href.create_user_id = cu.id
+ WHERE
+ href.application_id = #{applicationId}
+ </select>
+
+</mapper>
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 '更新时间戳',
@@ -339,6 +339,22 @@ CREATE TABLE `application_attachment` (
) 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 表
*/
DROP TABLE IF EXISTS `package`;