feat: ASW-59 application 新增接口调整;增加 href 属性

This commit is contained in:
shizhendong
2024-09-05 11:24:05 +08:00
parent 0f4c12b38e
commit bec7e90774
9 changed files with 282 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package net.geedge.asw.module.app.controller; package net.geedge.asw.module.app.controller;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse; 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.R;
import net.geedge.asw.common.util.RCode; import net.geedge.asw.common.util.RCode;
import net.geedge.asw.common.util.T; import net.geedge.asw.common.util.T;
import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity; import net.geedge.asw.module.app.entity.*;
import net.geedge.asw.module.app.entity.ApplicationEntity; import net.geedge.asw.module.app.service.*;
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.workspace.entity.WorkspaceEntity; import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
import net.geedge.asw.module.workspace.service.IWorkspaceService; import net.geedge.asw.module.workspace.service.IWorkspaceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -31,6 +28,8 @@ import java.util.stream.Collectors;
@RequestMapping("/api/v1/application") @RequestMapping("/api/v1/application")
public class ApplicationController { public class ApplicationController {
private static final Log log = Log.get();
@Autowired @Autowired
private IWorkspaceService workspaceService; private IWorkspaceService workspaceService;
@@ -43,6 +42,9 @@ public class ApplicationController {
@Autowired @Autowired
private IApplicationNoteService noteService; private IApplicationNoteService noteService;
@Autowired
private IApplicationHrefService hrefService;
@Autowired @Autowired
private IApplicationAttachmentService attachmentService; private IApplicationAttachmentService attachmentService;
@@ -66,14 +68,53 @@ public class ApplicationController {
} }
@PostMapping @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() T.VerifyUtil.is(entity).notNull()
.and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) .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); .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
// save application
ApplicationEntity applicationEntity = applicationService.saveApplication(entity); 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()); 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") @PostMapping("/import")
public R importApplication(@RequestParam String workspaceId, public R importApplication(@RequestParam String workspaceId,
@RequestParam(defaultValue = "tsg2402") String format, @RequestParam(defaultValue = "tsg2402") String format,

View File

@@ -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);
}

View File

@@ -60,4 +60,8 @@ public class ApplicationEntity {
@TableField(exist = false) @TableField(exist = false)
private List<ApplicationAttachmentEntity> attatchments; private List<ApplicationAttachmentEntity> attatchments;
@TableField(exist = false)
private List<ApplicationHrefEntity> hrefs;
} }

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -42,6 +42,9 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
@Autowired @Autowired
private IApplicationNoteService noteService; private IApplicationNoteService noteService;
@Autowired
private IApplicationHrefService hrefService;
@Autowired @Autowired
private IApplicationAttachmentService attachmentService; private IApplicationAttachmentService attachmentService;
@@ -71,6 +74,10 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
attachmentEntityList.stream().forEach(x -> x.setPath(null)); attachmentEntityList.stream().forEach(x -> x.setPath(null));
app.setAttatchments(attachmentEntityList); 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 createUser = userService.getById(app.getCreateUserId());
SysUserEntity updateUser = userService.getById(app.getUpdateUserId()); SysUserEntity updateUser = userService.getById(app.getUpdateUserId());
app.setCreateUser(createUser); app.setCreateUser(createUser);
@@ -206,6 +213,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
signatureService.remove(new LambdaQueryWrapper<ApplicationSignatureEntity>().in(ApplicationSignatureEntity::getApplicationId, ids)); signatureService.remove(new LambdaQueryWrapper<ApplicationSignatureEntity>().in(ApplicationSignatureEntity::getApplicationId, ids));
noteService.remove(new LambdaQueryWrapper<ApplicationNoteEntity>().in(ApplicationNoteEntity::getApplicationId, ids)); noteService.remove(new LambdaQueryWrapper<ApplicationNoteEntity>().in(ApplicationNoteEntity::getApplicationId, ids));
attachmentService.remove(new LambdaQueryWrapper<ApplicationAttachmentEntity>().in(ApplicationAttachmentEntity::getApplicationId, ids)); attachmentService.remove(new LambdaQueryWrapper<ApplicationAttachmentEntity>().in(ApplicationAttachmentEntity::getApplicationId, ids));
hrefService.remove(new LambdaQueryWrapper<ApplicationHrefEntity>().in(ApplicationHrefEntity::getApplicationId, ids));
} }
@Override @Override

View File

@@ -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>

View File

@@ -255,11 +255,11 @@ CREATE TABLE `application` (
`id` varchar(64) NOT NULL COMMENT '主键', `id` varchar(64) NOT NULL COMMENT '主键',
`name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称',
`tags` TEXT 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 '网站', `website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站',
`provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者', `provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者',
`status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done', `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 '描述信息', `description` text NOT NULL DEFAULT '' COMMENT '描述信息',
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
`update_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 '主键', `id` varchar(64) NOT NULL COMMENT '主键',
`name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称',
`tags` TEXT 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 '网站', `website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站',
`provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者', `provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者',
`status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done', `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 '描述信息', `description` text NOT NULL DEFAULT '' COMMENT '描述信息',
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
`update_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 PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) 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 表 * 新增 package 表
*/ */