From b88eb14d8f1ad9717a08cb3e8500b7bfe0b50473 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Fri, 7 Oct 2022 02:05:47 +0800 Subject: [PATCH 1/4] feat: new script template --- .../controller/mapper/ScriptsMapper.java | 14 +++++ .../controller/models/domain/Scripts.java | 53 +++++++++++++++++++ .../controller/models/dto/ScriptsDTO.java | 36 +++++++++++++ .../main/resources/mapping/ScriptsMapper.xml | 5 ++ 4 files changed, 108 insertions(+) create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/ScriptsMapper.java create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Scripts.java create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/ScriptsDTO.java create mode 100644 sonic-server-controller/src/main/resources/mapping/ScriptsMapper.xml diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/ScriptsMapper.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/ScriptsMapper.java new file mode 100644 index 00000000..f3ed9ac7 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/ScriptsMapper.java @@ -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 { +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Scripts.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Scripts.java new file mode 100644 index 00000000..613053e7 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Scripts.java @@ -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 { + @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; +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/ScriptsDTO.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/ScriptsDTO.java new file mode 100644 index 00000000..4cba7643 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/ScriptsDTO.java @@ -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 { + @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; +} diff --git a/sonic-server-controller/src/main/resources/mapping/ScriptsMapper.xml b/sonic-server-controller/src/main/resources/mapping/ScriptsMapper.xml new file mode 100644 index 00000000..fed42c16 --- /dev/null +++ b/sonic-server-controller/src/main/resources/mapping/ScriptsMapper.xml @@ -0,0 +1,5 @@ + + + + + From d7f30ec9a07b8da5c1be069243d63685fe9d2ce8 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Fri, 7 Oct 2022 15:16:55 +0800 Subject: [PATCH 2/4] feat: new script template --- .../controller/ScriptsController.java | 96 +++++++++++++++++++ .../controller/services/ScriptsService.java | 15 +++ .../services/impl/ProjectsServiceImpl.java | 33 +++++-- .../services/impl/ScriptsServiceImpl.java | 58 +++++++++++ 4 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/ScriptsController.java create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/ScriptsService.java create mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/ScriptsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/ScriptsController.java new file mode 100644 index 00000000..1bcc72ca --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/ScriptsController.java @@ -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> findAll(@RequestParam(name = "projectId") int projectId, + @RequestParam(name = "name", required = false) String name, + @RequestParam(name = "page") int page, + @RequestParam(name = "pageSize") int pageSize) { + Page 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 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 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 save(@Validated @RequestBody ScriptsDTO scriptsDTO) { + scriptsService.save(scriptsDTO.convertTo()); + return new RespModel<>(RespEnum.UPDATE_OK); + } + +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/ScriptsService.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/ScriptsService.java new file mode 100644 index 00000000..4518e87c --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/ScriptsService.java @@ -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 { + boolean delete(int id); + + Page findByProjectId(int projectId, String name, Page pageable); + + Scripts findById(int id); + + boolean deleteByProjectId(int projectId); +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ProjectsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ProjectsServiceImpl.java index 0c7c2c13..3f686e56 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ProjectsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ProjectsServiceImpl.java @@ -36,16 +36,28 @@ @Service public class ProjectsServiceImpl extends SonicServiceImpl 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) { @@ -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(); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java new file mode 100644 index 00000000..1eb05a25 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java @@ -0,0 +1,58 @@ +/* + * 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; +import org.springframework.util.StringUtils; + +@Service +public class ScriptsServiceImpl extends SonicServiceImpl implements ScriptsService { + @Autowired + private ScriptsMapper scriptsMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(int id) { + return scriptsMapper.deleteById(id) > 0; + } + + @Override + public Page findByProjectId(int projectId, String name, Page pageable) { + return lambdaQuery().eq(Scripts::getProjectId, projectId) + .eq(!StringUtils.isEmpty(name), 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().eq(Scripts::getProjectId, projectId)) > 0; + } +} From d6d05cfce859ff3f68ee68285361ed8528da5915 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Fri, 7 Oct 2022 17:30:18 +0800 Subject: [PATCH 3/4] feat: update script template --- .../sonic/controller/services/impl/ScriptsServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java index 1eb05a25..484c47ce 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java @@ -41,7 +41,7 @@ public boolean delete(int id) { @Override public Page findByProjectId(int projectId, String name, Page pageable) { return lambdaQuery().eq(Scripts::getProjectId, projectId) - .eq(!StringUtils.isEmpty(name), Scripts::getName, name) + .like((name != null && name.length() > 0), Scripts::getName, name) .orderByDesc(Scripts::getId) .page(pageable); } From c1b56f343c8a8330c8a174f166332c07c04810f0 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Sat, 8 Oct 2022 20:21:25 +0800 Subject: [PATCH 4/4] feat: alpha2 done --- .env | 4 ++-- .../sonic/controller/services/impl/ScriptsServiceImpl.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 5e9bac80..32843214 100644 --- a/.env +++ b/.env @@ -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 # @@ -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 \ No newline at end of file diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java index 484c47ce..ecb56175 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; @Service public class ScriptsServiceImpl extends SonicServiceImpl implements ScriptsService {