-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from SonicCloudOrg/dev/2.0.0-alpha2
feat: script manager
- Loading branch information
Showing
9 changed files
with
301 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...ver-controller/src/main/java/org/cloud/sonic/controller/controller/ScriptsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/ScriptsMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
53 changes: 53 additions & 0 deletions
53
sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Scripts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
36 changes: 36 additions & 0 deletions
36
sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/ScriptsDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
15 changes: 15 additions & 0 deletions
15
...c-server-controller/src/main/java/org/cloud/sonic/controller/services/ScriptsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...controller/src/main/java/org/cloud/sonic/controller/services/impl/ScriptsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
sonic-server-controller/src/main/resources/mapping/ScriptsMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |