diff options
| author | zhangshuai <[email protected]> | 2024-07-30 16:02:32 +0800 |
|---|---|---|
| committer | zhangshuai <[email protected]> | 2024-07-30 16:02:32 +0800 |
| commit | 6b78f8e61a3ee800d52e9df47b95033c88c1e326 (patch) | |
| tree | 2c971199e9f21c6bba1dff441d306d85c57654d7 | |
| parent | b5af3de27d8b549e7dbed70463e78a7fd8114e68 (diff) | |
feat: ASW-18 application 接口开发
12 files changed, 275 insertions, 0 deletions
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 14c410a..0233989 100644 --- a/src/main/java/net/geedge/asw/common/util/RCode.java +++ b/src/main/java/net/geedge/asw/common/util/RCode.java @@ -22,6 +22,13 @@ public enum RCode { // Application APP_ID_CANNOT_EMPTY(201001, "application id cannot be empty"), + APP_NAME_CANNOT_EMPTY(201002, "application name cannot be empty"), + APP_LONGNAME_CANNOT_EMPTY(201003, "application longName cannot be empty"), + APP_PROPERTIES_CANNOT_EMPTY(201004, "application properties cannot be empty"), + APP_SURROGATES_CANNOT_EMPTY(201005, "application surrogates cannot be empty"), + APP_DESCRIPTION_CANNOT_EMPTY(201006, "application surrogates cannot be empty"), + APP_DUPLICATE_RECORD(201007, "application duplicate record"), + APP_NOT_EXIST(201008, "application does not exist"), // Package 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 new file mode 100644 index 0000000..ba95e7f --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java @@ -0,0 +1,70 @@ +package net.geedge.asw.module.app.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +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.ApplicationEntity; +import net.geedge.asw.module.app.service.IApplicationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/api/v1/application") +public class ApplicationController { + + @Autowired + private IApplicationService applicationService; + + @GetMapping("/{id}") + public R detail(@PathVariable("id") String id) { + ApplicationEntity entity = applicationService.getById(id); + return R.ok().putData("record", entity); + } + + @GetMapping + public R list(@RequestParam Map<String, Object> params) { + T.VerifyUtil.is(params).notNull() + .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + Page page = applicationService.queryList(params); + return R.ok(page); + } + + @PostMapping + public R add(@RequestBody ApplicationEntity entity) { + T.VerifyUtil.is(entity).notNull() + .and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) + .and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY) + .and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) + .and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) + .and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) + .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + + ApplicationEntity applicationEntity = applicationService.saveApplication(entity); + return R.ok().putData("id", applicationEntity.getId()); + } + + @PutMapping + public R update(@RequestBody ApplicationEntity entity) { + T.VerifyUtil.is(entity).notNull() + .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) + .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) + .and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY) + .and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) + .and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) + .and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) + .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + + ApplicationEntity applicationEntity = applicationService.updateApplication(entity); + return R.ok().putData("id", applicationEntity.getId()); + } + + @DeleteMapping + public R delete(String[] ids) { + T.VerifyUtil.is(ids).notEmpty(); + applicationService.removeApplication(T.ListUtil.of(ids)); + return R.ok(); + } +} diff --git a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java b/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java index 8e85f33..f1c6954 100644 --- a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java +++ b/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java @@ -1,10 +1,15 @@ package net.geedge.asw.module.app.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import net.geedge.asw.module.app.entity.ApplicationEntity; import org.apache.ibatis.annotations.Mapper; +import java.util.List; +import java.util.Map; + @Mapper public interface ApplicationDao extends BaseMapper<ApplicationEntity>{ + List<ApplicationEntity> queryList(Page page, Map<String, Object> params); } diff --git a/src/main/java/net/geedge/asw/module/app/dao/ApplicationLogDao.java b/src/main/java/net/geedge/asw/module/app/dao/ApplicationLogDao.java new file mode 100644 index 0000000..0756d96 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/dao/ApplicationLogDao.java @@ -0,0 +1,9 @@ +package net.geedge.asw.module.app.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import net.geedge.asw.module.app.entity.ApplicationLogEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ApplicationLogDao extends BaseMapper<ApplicationLogEntity> { +} 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 51fccf0..fc62f68 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 @@ -23,5 +23,6 @@ public class ApplicationEntity { private String updateUserId; private String workspaceId; + private Integer opVersion; }
\ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/app/entity/ApplicationLogEntity.java b/src/main/java/net/geedge/asw/module/app/entity/ApplicationLogEntity.java new file mode 100644 index 0000000..48415aa --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/entity/ApplicationLogEntity.java @@ -0,0 +1,26 @@ +package net.geedge.asw.module.app.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("application_log") +public class ApplicationLogEntity { + @TableId(type = IdType.ASSIGN_UUID) + private String id; + private String name; + private String longName; + private String properties; + private String description; + private String surrogates; + + private Long createTimestamp; + private Long updateTimestamp; + private String createUserId; + private String updateUserId; + + private String workspaceId; + private Integer opVersion; +} diff --git a/src/main/java/net/geedge/asw/module/app/service/IApplicationLogService.java b/src/main/java/net/geedge/asw/module/app/service/IApplicationLogService.java new file mode 100644 index 0000000..9d8bcd4 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/service/IApplicationLogService.java @@ -0,0 +1,7 @@ +package net.geedge.asw.module.app.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import net.geedge.asw.module.app.entity.ApplicationLogEntity; + +public interface IApplicationLogService extends IService<ApplicationLogEntity> { +} diff --git a/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java b/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java index 05d29cd..5aa6f29 100644 --- a/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java +++ b/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java @@ -1,8 +1,20 @@ package net.geedge.asw.module.app.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import net.geedge.asw.module.app.entity.ApplicationEntity; +import java.util.List; +import java.util.Map; + public interface IApplicationService extends IService<ApplicationEntity>{ + Page queryList(Map<String, Object> params); + + ApplicationEntity saveApplication(ApplicationEntity entity); + + ApplicationEntity updateApplication(ApplicationEntity entity); + + void removeApplication(List<String> ids); + } diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationLogServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationLogServiceImpl.java new file mode 100644 index 0000000..c1daa16 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationLogServiceImpl.java @@ -0,0 +1,11 @@ +package net.geedge.asw.module.app.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.module.app.dao.ApplicationLogDao; +import net.geedge.asw.module.app.entity.ApplicationLogEntity; +import net.geedge.asw.module.app.service.IApplicationLogService; +import org.springframework.stereotype.Service; + +@Service +public class ApplicationLogServiceImpl extends ServiceImpl<ApplicationLogDao, ApplicationLogEntity> implements IApplicationLogService { +} 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 91a1d71..ec46f11 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 @@ -1,13 +1,83 @@ package net.geedge.asw.module.app.service.impl; +import cn.dev33.satoken.stp.StpUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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.RCode; +import net.geedge.asw.common.util.T; import net.geedge.asw.module.app.dao.ApplicationDao; import net.geedge.asw.module.app.entity.ApplicationEntity; +import net.geedge.asw.module.app.entity.ApplicationLogEntity; +import net.geedge.asw.module.app.service.IApplicationLogService; import net.geedge.asw.module.app.service.IApplicationService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Map; + @Service public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, ApplicationEntity> implements IApplicationService { + @Autowired + private IApplicationLogService applicationLogService; + + @Override + public Page queryList(Map<String, Object> params) { + Page page = T.PageUtil.getPage(params); + List<ApplicationEntity> packageList = this.getBaseMapper().queryList(page, params); + page.setRecords(packageList); + return page; + } + + @Override + public ApplicationEntity saveApplication(ApplicationEntity entity) { + ApplicationEntity one = this.getOne(new LambdaQueryWrapper<ApplicationEntity>() + .eq(ApplicationEntity::getWorkspaceId, entity.getWorkspaceId()) + .eq(ApplicationEntity::getName, entity.getName())); + if (T.ObjectUtil.isNotNull(one)) { + throw ASWException.builder().rcode(RCode.APP_DUPLICATE_RECORD).build(); + } + + entity.setCreateTimestamp(System.currentTimeMillis()); + entity.setUpdateTimestamp(System.currentTimeMillis()); + entity.setCreateUserId(StpUtil.getLoginIdAsString()); + entity.setUpdateUserId(StpUtil.getLoginIdAsString()); + + // save + this.save(entity); + return entity; + } + + @Override + public ApplicationEntity updateApplication(ApplicationEntity entity) { + ApplicationEntity one = this.getOne(new LambdaQueryWrapper<ApplicationEntity>() + .eq(ApplicationEntity::getWorkspaceId, entity.getWorkspaceId()) + .eq(ApplicationEntity::getId, entity.getId())); + if (T.ObjectUtil.isNull(one)) { + throw ASWException.builder().rcode(RCode.APP_NOT_EXIST).build(); + } + + entity.setUpdateTimestamp(System.currentTimeMillis()); + entity.setUpdateUserId(StpUtil.getLoginIdAsString()); + entity.setOpVersion(one.getOpVersion() + 1); + + // update + this.updateById(entity); + + // save log + ApplicationLogEntity applicationLogEntity = T.BeanUtil.toBean(one, ApplicationLogEntity.class); + applicationLogService.save(applicationLogEntity); + + return entity; + } + @Override + public void removeApplication(List<String> ids) { + // remove + this.removeBatchByIds(ids); + applicationLogService.removeBatchByIds(ids); + } } diff --git a/src/main/resources/db/mapper/app/ApplicationMapper.xml b/src/main/resources/db/mapper/app/ApplicationMapper.xml new file mode 100644 index 0000000..9396a10 --- /dev/null +++ b/src/main/resources/db/mapper/app/ApplicationMapper.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.ApplicationDao"> + + + <select id="queryList" resultType="net.geedge.asw.module.app.entity.ApplicationEntity"> + SELECT + app.* + FROM + application app + <where> + <if test="params.ids != null and params.ids != ''"> + app.id in + <foreach item="id" collection="params.ids.split(',')" separator="," open="(" close=")"> + #{id} + </foreach> + </if> + + <if test="params.q != null and params.q != ''"> + AND ( locate(#{params.q}, app.name) OR locate(#{params.q}, app.description) ) + </if> + <if test="params.workspaceId != null and params.workspaceId != ''"> + AND app.workspace_id = #{params.workspaceId} + </if> + </where> + + GROUP BY + app.id + <if test="params.orderBy == null or params.orderBy == ''"> + ORDER BY app.id + </if> + </select> + +</mapper>
\ No newline at end of file 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 e5a47c4..d758c74 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 @@ -248,12 +248,34 @@ CREATE TABLE `application` ( `create_user_id` varchar(64) NOT NULL COMMENT '创建人', `update_user_id` varchar(64) NOT NULL COMMENT '更新人', `workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '工作空间ID', + `op_version` int(10) NOT NULL DEFAULT 1 COMMENT '版本号', PRIMARY KEY (`id`) USING BTREE, KEY `idx_name` (`name`) USING BTREE, KEY `idx_long_name` (`long_name`) USING BTREE, KEY `idx_workspace_id` (`workspace_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +/** + * 新增 application_log 表 + */ +DROP TABLE IF EXISTS `application_log`; +CREATE TABLE `application_log` ( + `id` varchar(64) NOT NULL COMMENT '主键', + `name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称', + `long_name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用全称', + `properties` text NOT NULL DEFAULT '' COMMENT '应用数据', + `description` text NOT NULL DEFAULT '' COMMENT '描述信息', + `surrogates` text NOT NULL DEFAULT '' COMMENT '', + `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', + `update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳', + `create_user_id` varchar(64) NOT NULL COMMENT '创建人', + `update_user_id` varchar(64) NOT NULL COMMENT '更新人', + `workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '工作空间ID', + `op_version` int(10) NOT NULL DEFAULT 1 COMMENT '版本号', + UNIQUE INDEX `index_id_version` (`id`, `op_version`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + /** * 新增 package 表 */ |
