fix: application 接口 添加 properties 属性

This commit is contained in:
zhangshuai
2024-08-26 16:58:53 +08:00
parent 8e835e4ea3
commit 46e2b0632f
8 changed files with 25 additions and 81 deletions

View File

@@ -44,6 +44,7 @@ public enum RCode {
APP_SIGNATURE_NOT_EXIST(201013, "application signature does not exist"),
APP_NOTE_CONTENT_CANNOT_EMPTY(201014, "application note content cannot be empty"),
APP_ATTACHMENT_NOT_EXIST(201015, "application attachment does not exist"),
APP_PROPERTIES_FORMAT_ERROR(201016, "application properties format error"),

View File

@@ -4,8 +4,6 @@ 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 org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
@@ -14,13 +12,4 @@ import java.util.Map;
public interface ApplicationDao extends BaseMapper<ApplicationEntity>{
List<ApplicationEntity> queryList(Page page, Map<String, Object> params);
@Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version}")
ApplicationEntity queryByApplicationAndLog(String id, String version);
List<ApplicationEntity> queryLogList(String id);
List<ApplicationEntity> compare(@Param("params") Map<String, Object> params);
}

View File

@@ -4,13 +4,14 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import net.geedge.asw.module.sys.entity.SysUserEntity;
import java.util.List;
@Data
@TableName("application")
@TableName(value = "application", autoResultMap = true)
public class ApplicationEntity {
@TableId(type = IdType.ASSIGN_UUID)
@@ -26,6 +27,9 @@ public class ApplicationEntity {
private String provider;
@TableField(typeHandler = JacksonTypeHandler.class)
private Object properties;
private String status;
private String description;

View File

@@ -4,13 +4,13 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import net.geedge.asw.module.sys.entity.SysUserEntity;
import java.util.List;
@Data
@TableName("application_log")
@TableName(value = "application_log", autoResultMap = true)
public class ApplicationLogEntity {
@TableId(type = IdType.ASSIGN_UUID)
@@ -26,7 +26,8 @@ public class ApplicationLogEntity {
private String provider;
private String status;
@TableField(typeHandler = JacksonTypeHandler.class)
private String properties;
private String description;

View File

@@ -1,53 +1,33 @@
package net.geedge.asw.module.app.service.impl;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.log.Log;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
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 jakarta.annotation.Resource;
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.*;
import net.geedge.asw.module.app.service.*;
import net.geedge.asw.module.feign.client.KibanaClient;
import net.geedge.asw.module.runner.entity.PcapEntity;
import net.geedge.asw.module.runner.service.IPcapService;
import net.geedge.asw.module.sys.entity.SysUserEntity;
import net.geedge.asw.module.sys.service.ISysUserService;
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.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, ApplicationEntity> implements IApplicationService {
private static final Log log = Log.get();
@Value("${kibana.url:127.0.0.1:5601}")
private String kibanaUrl;
@Autowired
private IApplicationLogService applicationLogService;
@Autowired
private IWorkspaceService workspaceService;
@Autowired
private IPcapService pcapService;
@Autowired
private ISysUserService userService;
@@ -61,8 +41,6 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
@Autowired
private ApplicationAttachmentService attachmentService;
@Resource
private KibanaClient kibanaClient;
@Override
public ApplicationEntity detail(String id, String workspaceId) {
@@ -139,6 +117,11 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
throw ASWException.builder().rcode(RCode.APP_NOTE_CONTENT_CANNOT_EMPTY).build();
}*/
// properties
if (T.ObjectUtil.isNotEmpty(entity.getProperties()) && !T.JSONUtil.isTypeJSON(entity.getProperties().toString())) {
throw ASWException.builder().rcode(RCode.APP_PROPERTIES_FORMAT_ERROR).build();
}
}
@Override
@@ -233,6 +216,11 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
entity.setPackageName("{}");
}
// properties
if (T.ObjectUtil.isNotEmpty(entity.getProperties()) && !T.JSONUtil.isTypeJSON(entity.getProperties().toString())) {
throw ASWException.builder().rcode(RCode.APP_PROPERTIES_FORMAT_ERROR).build();
}
entity.setUpdateTimestamp(System.currentTimeMillis());
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
entity.setOpVersion(one.getOpVersion() + 1);

View File

@@ -10,6 +10,7 @@
<result property="website" column="website"/>
<result property="provider" column="provider"/>
<result property="status" column="status"/>
<result property="properties" column="properties" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
<result property="description" column="description"/>
<result property="createTimestamp" column="create_timestamp"/>
<result property="updateTimestamp" column="update_timestamp"/>
@@ -59,48 +60,4 @@
</if>
</select>
<select id="queryLogList" resultMap="appResult">
SELECT
app.*,
cu.id as cu_id,
cu.name as cu_name,
uu.id as uu_id,
uu.id as uu_name
FROM
(select * from application union select * from application_log) app
left join sys_user cu on app.create_user_id = cu.id
left join sys_user uu on app.update_user_id = uu.id
<where>
<if test="id != null and id != ''">
AND app.id = #{id}
</if>
</where>
ORDER BY app.op_version DESC
</select>
<select id="compare" resultMap="appResult">
SELECT
app.*,
cu.id as cu_id,
cu.name as cu_name,
uu.id as uu_id,
uu.id as uu_name
FROM
(select * from application union select * from application_log ) app
left join sys_user cu on app.create_user_id = cu.id
left join sys_user uu on app.update_user_id = uu.id
<where>
<if test="params.versions != null and params.versions != ''">
AND app.op_version in
<foreach item="version" collection="params.versions" separator="," open="(" close=")">
#{version}
</foreach>
</if>
<if test="params.id != null and params.id != ''">
AND app.id = #{params.id}
</if>
</where>
</select>
</mapper>

View File

@@ -115,5 +115,7 @@ 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 (187, '201014', 'APP_NOTE_CONTENT_CANNOT_EMPTY', '应用说明内容不能为空', 'zh', '', 'admin', 1724030366000);
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (189, '201015', 'APP_ATTACHMENT_NOT_EXIST', 'application attachment does not exist', 'en', '', 'admin', 1724030366000);
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (191, '201015', 'APP_ATTACHMENT_NOT_EXIST', '应用附件不存在', 'zh', '', 'admin', 1724030366000);
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (193, '201016', 'APP_PROPERTIES_FORMAT_ERROR', 'application properties format error', 'en', '', 'admin', 1724030366000);
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (195, '201016', 'APP_PROPERTIES_FORMAT_ERROR', '应用属性格式错误', 'zh', '', 'admin', 1724030366000);
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -256,6 +256,7 @@ CREATE TABLE `application` (
`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 '属性',
`description` text NOT NULL DEFAULT '' COMMENT '描述信息',
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
`update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳',
@@ -281,6 +282,7 @@ CREATE TABLE `application_log` (
`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 '属性',
`description` text NOT NULL DEFAULT '' COMMENT '描述信息',
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
`update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳',