Skip to content

Commit

Permalink
Merge pull request #265 from SonicCloudOrg/dev/2.0.0-alpha2
Browse files Browse the repository at this point in the history
feat: script manager
  • Loading branch information
ZhouYixun authored Oct 8, 2022
2 parents 4129400 + c1b56f3 commit 509eee8
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MYSQL_HOST=192.168.1.1
MYSQL_PORT=3306
MYSQL_DATABASE=sonic
MYSQL_USERNAME=root
MYSQL_PASSWORD=Sonic!@123
MYSQL_PASSWORD=sonic

################
# User Config #
Expand All @@ -35,5 +35,5 @@ LDAP_USER_ID=cn
LDAP_BASE_DN=ou=users
LDAP_BASE=ou=system
LDAP_USERNAME=uid=admin,ou=system
LDAP_PASSWORD=Sonic!@#123
LDAP_PASSWORD=sonic
LDAP_URL=ldap://192.168.1.1:10389
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) [SonicCloudOrg] Sonic Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cloud.sonic.controller.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.cloud.sonic.common.config.WebAspect;
import org.cloud.sonic.common.http.RespEnum;
import org.cloud.sonic.common.http.RespModel;
import org.cloud.sonic.controller.models.base.CommentPage;
import org.cloud.sonic.controller.models.domain.Scripts;
import org.cloud.sonic.controller.models.dto.ScriptsDTO;
import org.cloud.sonic.controller.services.ScriptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "脚本模板管理相关")
@RestController
@RequestMapping("/scripts")
public class ScriptsController {
@Autowired
private ScriptsService scriptsService;

@WebAspect
@ApiOperation(value = "查找脚本模板列表", notes = "查找对应项目id的脚本列表")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "projectId", value = "项目id", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "name", value = "名称", dataTypeClass = String.class),
@ApiImplicitParam(name = "page", value = "页码", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "pageSize", value = "页数据大小", dataTypeClass = Integer.class)
})
@GetMapping("/list")
public RespModel<CommentPage<Scripts>> findAll(@RequestParam(name = "projectId") int projectId,
@RequestParam(name = "name", required = false) String name,
@RequestParam(name = "page") int page,
@RequestParam(name = "pageSize") int pageSize) {
Page<Scripts> pageable = new Page<>(page, pageSize);
return new RespModel<>(
RespEnum.SEARCH_OK,
CommentPage.convertFrom(scriptsService
.findByProjectId(projectId, name, pageable))
);
}

@WebAspect
@ApiOperation(value = "查找脚本详情", notes = "查找对应id的对应脚本详细信息")
@ApiImplicitParam(name = "id", value = "id", dataTypeClass = Integer.class)
@GetMapping
public RespModel<Scripts> findById(@RequestParam(name = "id") int id) {
Scripts scripts = scriptsService.findById(id);
if (scripts != null) {
return new RespModel<>(RespEnum.SEARCH_OK, scripts);
} else {
return new RespModel<>(RespEnum.ID_NOT_FOUND);
}
}

@WebAspect
@ApiOperation(value = "删除脚本模板", notes = "删除对应id")
@ApiImplicitParam(name = "id", value = "id", dataTypeClass = Integer.class)
@DeleteMapping
public RespModel<String> delete(@RequestParam(name = "id") int id) {
if (scriptsService.delete(id)) {
return new RespModel<>(RespEnum.DELETE_OK);
} else {
return new RespModel<>(RespEnum.DELETE_FAIL);
}
}

@WebAspect
@ApiOperation(value = "更新脚本信息", notes = "新增或更新对应的脚本信息")
@PutMapping
public RespModel<String> save(@Validated @RequestBody ScriptsDTO scriptsDTO) {
scriptsService.save(scriptsDTO.convertTo());
return new RespModel<>(RespEnum.UPDATE_OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cloud.sonic.controller.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.cloud.sonic.controller.models.domain.Scripts;

/**
* Mapper 接口
*
* @author Eason
*/
@Mapper
public interface ScriptsMapper extends BaseMapper<Scripts> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.cloud.sonic.controller.models.domain;

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.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlCharsetConstant;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlEngineConstant;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.cloud.sonic.controller.models.base.TypeConverter;
import org.cloud.sonic.controller.models.dto.ScriptsDTO;

import java.io.Serializable;

@ApiModel(value = "Scripts对象", description = "")
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("scripts")
@TableComment("scripts表")
@TableCharset(MySqlCharsetConstant.DEFAULT)
@TableEngine(MySqlEngineConstant.InnoDB)
public class Scripts implements Serializable, TypeConverter<Scripts, ScriptsDTO> {
@TableId(value = "id", type = IdType.AUTO)
@IsAutoIncrement
private Integer id;

@TableField
@Column(value = "project_id", isNull = false, comment = "所属项目id")
@Index(value = "IDX_PROJECT_ID", columns = {"project_id"})
private Integer projectId;

@TableField
@Column(isNull = false, comment = "name")
private String name;

@TableField
@Column(isNull = false, comment = "language")
private String scriptLanguage;

@TableField
@Column(type = MySqlTypeConstant.LONGTEXT, isNull = false, comment = "content")
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cloud.sonic.controller.models.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.cloud.sonic.controller.models.base.TypeConverter;
import org.cloud.sonic.controller.models.domain.Scripts;

import java.io.Serializable;

@ApiModel("脚本模板模型")
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ScriptsDTO implements Serializable, TypeConverter<ScriptsDTO, Scripts> {
@ApiModelProperty(value = "id", example = "1")
Integer id;

@ApiModelProperty(value = "项目id", example = "1")
Integer projectId;

@ApiModelProperty(value = "模板名称", example = "脚本模板A")
String name;

@ApiModelProperty(value = "语言", example = "Java")
String scriptLanguage;

@ApiModelProperty(value = "脚本内容", example = "println Hello world")
String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.cloud.sonic.controller.services;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.cloud.sonic.controller.models.domain.Scripts;

public interface ScriptsService extends IService<Scripts> {
boolean delete(int id);

Page<Scripts> findByProjectId(int projectId, String name, Page<Scripts> pageable);

Scripts findById(int id);

boolean deleteByProjectId(int projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,28 @@
@Service
public class ProjectsServiceImpl extends SonicServiceImpl<ProjectsMapper, Projects> implements ProjectsService {

@Autowired private ElementsService elementsService;
@Autowired private GlobalParamsService globalParamsService;
@Autowired private ModulesService modulesService;
@Autowired private VersionsService versionsService;
@Autowired private PublicStepsService publicStepsService;
@Autowired private ResultsService resultsService;
@Autowired private ResultDetailService resultDetailService;
@Autowired private StepsService stepsService;
@Autowired private TestSuitesService testSuitesService;
@Autowired private TestCasesService testCasesService;
@Autowired
private ElementsService elementsService;
@Autowired
private GlobalParamsService globalParamsService;
@Autowired
private ModulesService modulesService;
@Autowired
private VersionsService versionsService;
@Autowired
private PublicStepsService publicStepsService;
@Autowired
private ResultsService resultsService;
@Autowired
private ResultDetailService resultDetailService;
@Autowired
private StepsService stepsService;
@Autowired
private TestSuitesService testSuitesService;
@Autowired
private TestCasesService testCasesService;
@Autowired
private ScriptsService scriptsService;

@Override
public Projects findById(int id) {
Expand Down Expand Up @@ -74,6 +86,7 @@ public void delete(int id) throws SonicException {
}
resultsService.deleteByProjectId(id);
versionsService.deleteByProjectId(id);
scriptsService.deleteByProjectId(id);
baseMapper.deleteById(id);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) [SonicCloudOrg] Sonic Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cloud.sonic.controller.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.cloud.sonic.controller.mapper.ScriptsMapper;
import org.cloud.sonic.controller.models.domain.Scripts;
import org.cloud.sonic.controller.services.ScriptsService;
import org.cloud.sonic.controller.services.impl.base.SonicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ScriptsServiceImpl extends SonicServiceImpl<ScriptsMapper, Scripts> implements ScriptsService {
@Autowired
private ScriptsMapper scriptsMapper;

@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(int id) {
return scriptsMapper.deleteById(id) > 0;
}

@Override
public Page<Scripts> findByProjectId(int projectId, String name, Page<Scripts> pageable) {
return lambdaQuery().eq(Scripts::getProjectId, projectId)
.like((name != null && name.length() > 0), Scripts::getName, name)
.orderByDesc(Scripts::getId)
.page(pageable);
}

@Override
public Scripts findById(int id) {
return scriptsMapper.selectById(id);
}

@Override
public boolean deleteByProjectId(int projectId) {
return baseMapper.delete(new LambdaQueryWrapper<Scripts>().eq(Scripts::getProjectId, projectId)) > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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="org.cloud.sonic.controller.mapper.ScriptsMapper">

</mapper>

0 comments on commit 509eee8

Please sign in to comment.