| @@ -4,4 +4,7 @@ public class Constant { | |||||
| public final static int Image_Type_Pub = 1; // 公共镜像 | public final static int Image_Type_Pub = 1; // 公共镜像 | ||||
| public final static int Image_Type_Pri = 0; // 私有镜像 | public final static int Image_Type_Pri = 0; // 私有镜像 | ||||
| public final static int State_valid = 1; // 有效 | |||||
| public final static int State_invalid = 0; // 无效 | |||||
| } | } | ||||
| @@ -0,0 +1,61 @@ | |||||
| package com.ruoyi.platform.controller.codeConfig; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | |||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.platform.domain.CodeConfig; | |||||
| import com.ruoyi.platform.service.CodeConfigService; | |||||
| import io.swagger.annotations.Api; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.PageRequest; | |||||
| import org.springframework.http.ResponseEntity; | |||||
| import javax.annotation.Resource; | |||||
| @RestController | |||||
| @RequestMapping("codeConfig") | |||||
| @Api("代码配置") | |||||
| public class CodeConfigController extends BaseController { | |||||
| @Resource | |||||
| private CodeConfigService codeConfigService; | |||||
| /** | |||||
| * 分页查询 | |||||
| * @param codeConfig 筛选条件 | |||||
| * @param page 页数 | |||||
| * @param size 每页大小 | |||||
| * @return 查询结果 | |||||
| */ | |||||
| @GetMapping | |||||
| public GenericsAjaxResult<Page<CodeConfig>> queryByPage(CodeConfig codeConfig, int page, int size) { | |||||
| PageRequest pageRequest = PageRequest.of(page,size); | |||||
| return genericsSuccess(this.codeConfigService.queryByPage(codeConfig, pageRequest)); | |||||
| } | |||||
| /** | |||||
| * 通过主键查询单条数据 | |||||
| * @param id | |||||
| * @return 单条数据 | |||||
| */ | |||||
| @GetMapping("{id}") | |||||
| public ResponseEntity<CodeConfig> queryById(@PathVariable("id") Long id) { | |||||
| return ResponseEntity.ok(this.codeConfigService.queryById(id)); | |||||
| } | |||||
| @PostMapping | |||||
| public GenericsAjaxResult<CodeConfig> add(@RequestBody CodeConfig codeConfig){ | |||||
| return genericsSuccess(this.codeConfigService.insert(codeConfig)); | |||||
| } | |||||
| @PutMapping | |||||
| public GenericsAjaxResult<CodeConfig> update(@RequestBody CodeConfig codeConfig){ | |||||
| return genericsSuccess(this.codeConfigService.update(codeConfig)); | |||||
| } | |||||
| @DeleteMapping("{id}") | |||||
| public GenericsAjaxResult<String> delete(@PathVariable("id") Long id){ | |||||
| return genericsSuccess(this.codeConfigService.removeById(id)); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,56 @@ | |||||
| package com.ruoyi.platform.domain; | |||||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||||
| import io.swagger.annotations.ApiModelProperty; | |||||
| import lombok.Data; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| @Data | |||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||||
| public class CodeConfig implements Serializable { | |||||
| private Long id; | |||||
| @ApiModelProperty(value = "代码仓库名称") | |||||
| private String codeRepoName; | |||||
| @ApiModelProperty(value = "代码仓库可见性(1-公开,0-私有)") | |||||
| private Integer codeRepoVis; | |||||
| @ApiModelProperty(value = "Git地址") | |||||
| private String gitUrl; | |||||
| @ApiModelProperty(value = "代码分支/Tag") | |||||
| private String gitBranch; | |||||
| @ApiModelProperty(value = "验证方式(0-用户名密码,1-SSH-Key)") | |||||
| private Integer verifyMode; | |||||
| @ApiModelProperty(value = "Git用户名") | |||||
| private String gitUserName; | |||||
| @ApiModelProperty(value = "Git密码") | |||||
| private String gitPassword; | |||||
| private String createBy; | |||||
| /** | |||||
| * 创建时间 | |||||
| */ | |||||
| private Date createTime; | |||||
| /** | |||||
| * 更新者 | |||||
| */ | |||||
| private String updateBy; | |||||
| /** | |||||
| * 更新时间 | |||||
| */ | |||||
| private Date updateTime; | |||||
| /** | |||||
| * 状态,0失效1生效 | |||||
| */ | |||||
| private Integer state; | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| package com.ruoyi.platform.mapper; | |||||
| import com.ruoyi.platform.domain.CodeConfig; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import java.util.List; | |||||
| public interface CodeConfigDao { | |||||
| long count(@Param("codeConfig") CodeConfig codeConfig); | |||||
| List<CodeConfig> queryAllByLimit(@Param("codeConfig") CodeConfig codeConfig, @Param("pageable") Pageable pageable); | |||||
| CodeConfig queryById(Long id); | |||||
| int insert(@Param("codeConfig") CodeConfig codeConfig); | |||||
| int update(@Param("codeConfig") CodeConfig codeConfig); | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| package com.ruoyi.platform.service; | |||||
| import com.ruoyi.platform.domain.CodeConfig; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.PageRequest; | |||||
| public interface CodeConfigService { | |||||
| Page<CodeConfig> queryByPage(CodeConfig codeConfig, PageRequest pageRequest); | |||||
| CodeConfig queryById(Long id); | |||||
| CodeConfig insert(CodeConfig codeConfig); | |||||
| CodeConfig update(CodeConfig codeConfig); | |||||
| String removeById(Long id); | |||||
| } | |||||
| @@ -0,0 +1,74 @@ | |||||
| package com.ruoyi.platform.service.impl; | |||||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||||
| import com.ruoyi.platform.constant.Constant; | |||||
| import com.ruoyi.platform.domain.CodeConfig; | |||||
| import com.ruoyi.platform.mapper.CodeConfigDao; | |||||
| import com.ruoyi.platform.service.CodeConfigService; | |||||
| import com.ruoyi.system.api.model.LoginUser; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.PageImpl; | |||||
| import org.springframework.data.domain.PageRequest; | |||||
| import org.springframework.stereotype.Service; | |||||
| import javax.annotation.Resource; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| @Service("codeConfigService") | |||||
| public class CodeConfigServiceImpl implements CodeConfigService { | |||||
| @Resource | |||||
| private CodeConfigDao codeConfigDao; | |||||
| @Override | |||||
| public Page<CodeConfig> queryByPage(CodeConfig codeConfig, PageRequest pageRequest) { | |||||
| long total = this.codeConfigDao.count(codeConfig); | |||||
| List<CodeConfig> codeConfigList = this.codeConfigDao.queryAllByLimit(codeConfig, pageRequest); | |||||
| return new PageImpl<>(codeConfigList, pageRequest, total); | |||||
| } | |||||
| @Override | |||||
| public CodeConfig queryById(Long id) { | |||||
| return this.codeConfigDao.queryById(id); | |||||
| } | |||||
| @Override | |||||
| public CodeConfig insert(CodeConfig codeConfig) { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| codeConfig.setCreateBy(loginUser.getUsername()); | |||||
| codeConfig.setUpdateBy(loginUser.getUsername()); | |||||
| codeConfig.setCreateTime(new Date()); | |||||
| codeConfig.setUpdateTime(new Date()); | |||||
| this.codeConfigDao.insert(codeConfig); | |||||
| return codeConfig; | |||||
| } | |||||
| @Override | |||||
| public CodeConfig update(CodeConfig codeConfig) { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| codeConfig.setUpdateBy(loginUser.getUsername()); | |||||
| codeConfig.setUpdateTime(new Date()); | |||||
| this.codeConfigDao.update(codeConfig); | |||||
| return this.codeConfigDao.queryById(codeConfig.getId()); | |||||
| } | |||||
| @Override | |||||
| public String removeById(Long id) { | |||||
| CodeConfig codeConfig = this.codeConfigDao.queryById(id); | |||||
| if (codeConfig == null) { | |||||
| return "代码配置不存在"; | |||||
| } | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||||
| String username = loginUser.getUsername(); | |||||
| String createBy = codeConfig.getCreateBy(); | |||||
| if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { | |||||
| return "无权限删除该代码配置"; | |||||
| } | |||||
| codeConfig.setState(Constant.State_invalid); | |||||
| return this.codeConfigDao.update(codeConfig) > 0 ? "删除成功" : "删除失败"; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,108 @@ | |||||
| <?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="com.ruoyi.platform.mapper.CodeConfigDao"> | |||||
| <insert id="insert"> | |||||
| insert into code_config(code_repo_name, code_repo_vis, git_url, git_branch, verify_mode, git_user_name, git_password, create_by, create_time, update_by, update_time) | |||||
| values(#{codeConfig.codeRepoName}, #{codeConfig.codeRepoVis}, #{codeConfig.gitUrl}, #{codeConfig.gitBranch}, #{codeConfig.verifyMode}, #{codeConfig.gitUserName}, #{codeConfig.gitPassword}, #{codeConfig.createBy}, #{codeConfig.createTime}, #{codeConfig.updateBy}, #{codeConfig.updateTime}) | |||||
| </insert> | |||||
| <update id="update"> | |||||
| update code_config | |||||
| <set> | |||||
| <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''"> | |||||
| code_repo_name = #{codeConfig.codeRepoName}, | |||||
| </if> | |||||
| <if test="codeConfig.codeRepoVis != null"> | |||||
| code_repo_vis = #{codeConfig.codeRepoVis}, | |||||
| </if> | |||||
| <if test="codeConfig.gitUrl != null"> | |||||
| git_url = #{codeConfig.gitUrl}, | |||||
| </if> | |||||
| <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''"> | |||||
| git_branch = #{codeConfig.gitBranch}, | |||||
| </if> | |||||
| <if test="codeConfig.verifyMode != null"> | |||||
| verify_mode = #{codeConfig.verifyMode}, | |||||
| </if> | |||||
| <if test="codeConfig.gitUserName != null and codeConfig.gitUserName != ''"> | |||||
| git_user_name = #{codeConfig.gitUserName}, | |||||
| </if> | |||||
| <if test="codeConfig.createBy != null and codeConfig.createBy != ''"> | |||||
| create_by = #{codeConfig.createBy}, | |||||
| </if> | |||||
| <if test="codeConfig.createTime != null"> | |||||
| create_time = #{codeConfig.createTime}, | |||||
| </if> | |||||
| <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''"> | |||||
| update_by = #{codeConfig.updateBy}, | |||||
| </if> | |||||
| <if test="codeConfig.updateTime != null"> | |||||
| update_time = #{codeConfig.updateTime}, | |||||
| </if> | |||||
| <if test="codeConfig.state != null"> | |||||
| state = #{codeConfig.state}, | |||||
| </if> | |||||
| </set> | |||||
| where id = #{codeConfig.id} | |||||
| </update> | |||||
| <select id="count" resultType="java.lang.Long"> | |||||
| select count(1) | |||||
| from code_config | |||||
| <include refid="common_condition"></include> | |||||
| </select> | |||||
| <select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.CodeConfig"> | |||||
| select * from code_config | |||||
| <include refid="common_condition"></include> | |||||
| limit #{pageable.offset}, #{pageable.pageSize} | |||||
| </select> | |||||
| <select id="queryById" resultType="com.ruoyi.platform.domain.CodeConfig"> | |||||
| select * | |||||
| from code_config | |||||
| where id = #{id} | |||||
| and state = 1 | |||||
| </select> | |||||
| <sql id="common_condition"> | |||||
| <where> | |||||
| state = 1 | |||||
| <if test="codeConfig.id != null"> | |||||
| and id = #{codeConfig.id} | |||||
| </if> | |||||
| <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''"> | |||||
| and code_repo_name = #{codeConfig.codeRepoName} | |||||
| </if> | |||||
| <if test="codeConfig.codeRepoVis != null"> | |||||
| and code_repo_vis = #{codeConfig.codeRepoVis} | |||||
| </if> | |||||
| <if test="codeConfig.gitUrl != null"> | |||||
| and git_url = #{codeConfig.gitUrl} | |||||
| </if> | |||||
| <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''"> | |||||
| and git_branch = #{codeConfig.gitBranch} | |||||
| </if> | |||||
| <if test="codeConfig.verifyMode != null"> | |||||
| and verify_mode = #{codeConfig.verifyMode} | |||||
| </if> | |||||
| <if test="codeConfig.gitUserName != null and codeConfig.gitUserName != ''"> | |||||
| and git_user_name = #{codeConfig.gitUserName} | |||||
| </if> | |||||
| <if test="codeConfig.createBy != null and codeConfig.createBy != ''"> | |||||
| and create_by = #{codeConfig.createBy} | |||||
| </if> | |||||
| <if test="codeConfig.createTime != null"> | |||||
| and create_time = #{codeConfig.createTime} | |||||
| </if> | |||||
| <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''"> | |||||
| and update_by = #{codeConfig.updateBy} | |||||
| </if> | |||||
| <if test="codeConfig.updateTime != null"> | |||||
| and update_time = #{codeConfig.updateTime} | |||||
| </if> | |||||
| </where> | |||||
| </sql> | |||||
| </mapper> | |||||