| @@ -1,323 +1,344 @@ | |||||
| package com.ruoyi.system.api.domain; | package com.ruoyi.system.api.domain; | ||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import javax.validation.constraints.*; | |||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||||
| import com.ruoyi.common.core.annotation.Excel; | import com.ruoyi.common.core.annotation.Excel; | ||||
| import com.ruoyi.common.core.annotation.Excel.ColumnType; | import com.ruoyi.common.core.annotation.Excel.ColumnType; | ||||
| import com.ruoyi.common.core.annotation.Excel.Type; | import com.ruoyi.common.core.annotation.Excel.Type; | ||||
| import com.ruoyi.common.core.annotation.Excels; | import com.ruoyi.common.core.annotation.Excels; | ||||
| import com.ruoyi.common.core.web.domain.BaseEntity; | import com.ruoyi.common.core.web.domain.BaseEntity; | ||||
| import com.ruoyi.common.core.xss.Xss; | import com.ruoyi.common.core.xss.Xss; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||||
| import javax.validation.constraints.Email; | |||||
| import javax.validation.constraints.NotBlank; | |||||
| import javax.validation.constraints.Size; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | /** | ||||
| * 用户对象 sys_user | * 用户对象 sys_user | ||||
| * | |||||
| * | |||||
| * @author ruoyi | * @author ruoyi | ||||
| */ | */ | ||||
| public class SysUser extends BaseEntity | |||||
| { | |||||
| public class SysUser extends BaseEntity { | |||||
| private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
| /** 用户ID */ | |||||
| /** | |||||
| * 用户ID | |||||
| */ | |||||
| @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") | @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") | ||||
| private Long userId; | private Long userId; | ||||
| /** 部门ID */ | |||||
| /** | |||||
| * 部门ID | |||||
| */ | |||||
| @Excel(name = "部门编号", type = Type.IMPORT) | @Excel(name = "部门编号", type = Type.IMPORT) | ||||
| private Long deptId; | private Long deptId; | ||||
| /** 用户账号 */ | |||||
| /** | |||||
| * 用户账号 | |||||
| */ | |||||
| @Excel(name = "登录名称") | @Excel(name = "登录名称") | ||||
| private String userName; | private String userName; | ||||
| /** 用户昵称 */ | |||||
| /** | |||||
| * 用户昵称 | |||||
| */ | |||||
| @Excel(name = "用户名称") | @Excel(name = "用户名称") | ||||
| private String nickName; | private String nickName; | ||||
| /** 用户邮箱 */ | |||||
| /** | |||||
| * 用户邮箱 | |||||
| */ | |||||
| @Excel(name = "用户邮箱") | @Excel(name = "用户邮箱") | ||||
| private String email; | private String email; | ||||
| /** 手机号码 */ | |||||
| /** | |||||
| * 手机号码 | |||||
| */ | |||||
| @Excel(name = "手机号码") | @Excel(name = "手机号码") | ||||
| private String phonenumber; | private String phonenumber; | ||||
| /** 用户性别 */ | |||||
| /** | |||||
| * 用户性别 | |||||
| */ | |||||
| @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知") | @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知") | ||||
| private String sex; | private String sex; | ||||
| /** 用户头像 */ | |||||
| /** | |||||
| * 用户头像 | |||||
| */ | |||||
| private String avatar; | private String avatar; | ||||
| /** 密码 */ | |||||
| /** | |||||
| * 密码 | |||||
| */ | |||||
| private String password; | private String password; | ||||
| /** 帐号状态(0正常 1停用) */ | |||||
| /** | |||||
| * 帐号状态(0正常 1停用) | |||||
| */ | |||||
| @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") | @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") | ||||
| private String status; | private String status; | ||||
| /** 删除标志(0代表存在 2代表删除) */ | |||||
| /** | |||||
| * 删除标志(0代表存在 2代表删除) | |||||
| */ | |||||
| private String delFlag; | private String delFlag; | ||||
| /** 最后登录IP */ | |||||
| /** | |||||
| * 最后登录IP | |||||
| */ | |||||
| @Excel(name = "最后登录IP", type = Type.EXPORT) | @Excel(name = "最后登录IP", type = Type.EXPORT) | ||||
| private String loginIp; | private String loginIp; | ||||
| /** 最后登录时间 */ | |||||
| /** | |||||
| * 最后登录时间 | |||||
| */ | |||||
| @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) | @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) | ||||
| private Date loginDate; | private Date loginDate; | ||||
| /** 部门对象 */ | |||||
| /** | |||||
| * 部门对象 | |||||
| */ | |||||
| @Excels({ | @Excels({ | ||||
| @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), | |||||
| @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) | |||||
| @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), | |||||
| @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) | |||||
| }) | }) | ||||
| private SysDept dept; | private SysDept dept; | ||||
| /** 角色对象 */ | |||||
| /** | |||||
| * 角色对象 | |||||
| */ | |||||
| private List<SysRole> roles; | private List<SysRole> roles; | ||||
| /** 角色组 */ | |||||
| /** | |||||
| * 角色组 | |||||
| */ | |||||
| private Long[] roleIds; | private Long[] roleIds; | ||||
| /** 岗位组 */ | |||||
| /** | |||||
| * 岗位组 | |||||
| */ | |||||
| private Long[] postIds; | private Long[] postIds; | ||||
| /** 角色ID */ | |||||
| /** | |||||
| * 角色ID | |||||
| */ | |||||
| private Long roleId; | private Long roleId; | ||||
| public SysUser() | |||||
| { | |||||
| private String gitLinkUsername; | |||||
| private String gitLinkPassword; | |||||
| public SysUser() { | |||||
| } | } | ||||
| public SysUser(Long userId) | |||||
| { | |||||
| public SysUser(Long userId) { | |||||
| this.userId = userId; | this.userId = userId; | ||||
| } | } | ||||
| public Long getUserId() | |||||
| { | |||||
| public Long getUserId() { | |||||
| return userId; | return userId; | ||||
| } | } | ||||
| public void setUserId(Long userId) | |||||
| { | |||||
| public void setUserId(Long userId) { | |||||
| this.userId = userId; | this.userId = userId; | ||||
| } | } | ||||
| public boolean isAdmin() | |||||
| { | |||||
| public boolean isAdmin() { | |||||
| return isAdmin(this.userId); | return isAdmin(this.userId); | ||||
| } | } | ||||
| public static boolean isAdmin(Long userId) | |||||
| { | |||||
| public static boolean isAdmin(Long userId) { | |||||
| return userId != null && 1L == userId; | return userId != null && 1L == userId; | ||||
| } | } | ||||
| public Long getDeptId() | |||||
| { | |||||
| public Long getDeptId() { | |||||
| return deptId; | return deptId; | ||||
| } | } | ||||
| public void setDeptId(Long deptId) | |||||
| { | |||||
| public void setDeptId(Long deptId) { | |||||
| this.deptId = deptId; | this.deptId = deptId; | ||||
| } | } | ||||
| @Xss(message = "用户昵称不能包含脚本字符") | @Xss(message = "用户昵称不能包含脚本字符") | ||||
| @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符") | @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符") | ||||
| public String getNickName() | |||||
| { | |||||
| public String getNickName() { | |||||
| return nickName; | return nickName; | ||||
| } | } | ||||
| public void setNickName(String nickName) | |||||
| { | |||||
| public void setNickName(String nickName) { | |||||
| this.nickName = nickName; | this.nickName = nickName; | ||||
| } | } | ||||
| @Xss(message = "用户账号不能包含脚本字符") | @Xss(message = "用户账号不能包含脚本字符") | ||||
| @NotBlank(message = "用户账号不能为空") | @NotBlank(message = "用户账号不能为空") | ||||
| @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符") | @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符") | ||||
| public String getUserName() | |||||
| { | |||||
| public String getUserName() { | |||||
| return userName; | return userName; | ||||
| } | } | ||||
| public void setUserName(String userName) | |||||
| { | |||||
| public void setUserName(String userName) { | |||||
| this.userName = userName; | this.userName = userName; | ||||
| } | } | ||||
| @Email(message = "邮箱格式不正确") | @Email(message = "邮箱格式不正确") | ||||
| @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") | @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") | ||||
| public String getEmail() | |||||
| { | |||||
| public String getEmail() { | |||||
| return email; | return email; | ||||
| } | } | ||||
| public void setEmail(String email) | |||||
| { | |||||
| public void setEmail(String email) { | |||||
| this.email = email; | this.email = email; | ||||
| } | } | ||||
| @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符") | @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符") | ||||
| public String getPhonenumber() | |||||
| { | |||||
| public String getPhonenumber() { | |||||
| return phonenumber; | return phonenumber; | ||||
| } | } | ||||
| public void setPhonenumber(String phonenumber) | |||||
| { | |||||
| public void setPhonenumber(String phonenumber) { | |||||
| this.phonenumber = phonenumber; | this.phonenumber = phonenumber; | ||||
| } | } | ||||
| public String getSex() | |||||
| { | |||||
| public String getSex() { | |||||
| return sex; | return sex; | ||||
| } | } | ||||
| public void setSex(String sex) | |||||
| { | |||||
| public void setSex(String sex) { | |||||
| this.sex = sex; | this.sex = sex; | ||||
| } | } | ||||
| public String getAvatar() | |||||
| { | |||||
| public String getAvatar() { | |||||
| return avatar; | return avatar; | ||||
| } | } | ||||
| public void setAvatar(String avatar) | |||||
| { | |||||
| public void setAvatar(String avatar) { | |||||
| this.avatar = avatar; | this.avatar = avatar; | ||||
| } | } | ||||
| public String getPassword() | |||||
| { | |||||
| public String getPassword() { | |||||
| return password; | return password; | ||||
| } | } | ||||
| public void setPassword(String password) | |||||
| { | |||||
| public void setPassword(String password) { | |||||
| this.password = password; | this.password = password; | ||||
| } | } | ||||
| public String getStatus() | |||||
| { | |||||
| public String getStatus() { | |||||
| return status; | return status; | ||||
| } | } | ||||
| public void setStatus(String status) | |||||
| { | |||||
| public void setStatus(String status) { | |||||
| this.status = status; | this.status = status; | ||||
| } | } | ||||
| public String getDelFlag() | |||||
| { | |||||
| public String getDelFlag() { | |||||
| return delFlag; | return delFlag; | ||||
| } | } | ||||
| public void setDelFlag(String delFlag) | |||||
| { | |||||
| public void setDelFlag(String delFlag) { | |||||
| this.delFlag = delFlag; | this.delFlag = delFlag; | ||||
| } | } | ||||
| public String getLoginIp() | |||||
| { | |||||
| public String getLoginIp() { | |||||
| return loginIp; | return loginIp; | ||||
| } | } | ||||
| public void setLoginIp(String loginIp) | |||||
| { | |||||
| public void setLoginIp(String loginIp) { | |||||
| this.loginIp = loginIp; | this.loginIp = loginIp; | ||||
| } | } | ||||
| public Date getLoginDate() | |||||
| { | |||||
| public Date getLoginDate() { | |||||
| return loginDate; | return loginDate; | ||||
| } | } | ||||
| public void setLoginDate(Date loginDate) | |||||
| { | |||||
| public void setLoginDate(Date loginDate) { | |||||
| this.loginDate = loginDate; | this.loginDate = loginDate; | ||||
| } | } | ||||
| public SysDept getDept() | |||||
| { | |||||
| public SysDept getDept() { | |||||
| return dept; | return dept; | ||||
| } | } | ||||
| public void setDept(SysDept dept) | |||||
| { | |||||
| public void setDept(SysDept dept) { | |||||
| this.dept = dept; | this.dept = dept; | ||||
| } | } | ||||
| public List<SysRole> getRoles() | |||||
| { | |||||
| public List<SysRole> getRoles() { | |||||
| return roles; | return roles; | ||||
| } | } | ||||
| public void setRoles(List<SysRole> roles) | |||||
| { | |||||
| public void setRoles(List<SysRole> roles) { | |||||
| this.roles = roles; | this.roles = roles; | ||||
| } | } | ||||
| public Long[] getRoleIds() | |||||
| { | |||||
| public Long[] getRoleIds() { | |||||
| return roleIds; | return roleIds; | ||||
| } | } | ||||
| public void setRoleIds(Long[] roleIds) | |||||
| { | |||||
| public void setRoleIds(Long[] roleIds) { | |||||
| this.roleIds = roleIds; | this.roleIds = roleIds; | ||||
| } | } | ||||
| public Long[] getPostIds() | |||||
| { | |||||
| public Long[] getPostIds() { | |||||
| return postIds; | return postIds; | ||||
| } | } | ||||
| public void setPostIds(Long[] postIds) | |||||
| { | |||||
| public void setPostIds(Long[] postIds) { | |||||
| this.postIds = postIds; | this.postIds = postIds; | ||||
| } | } | ||||
| public Long getRoleId() | |||||
| { | |||||
| public Long getRoleId() { | |||||
| return roleId; | return roleId; | ||||
| } | } | ||||
| public void setRoleId(Long roleId) | |||||
| { | |||||
| public void setRoleId(Long roleId) { | |||||
| this.roleId = roleId; | this.roleId = roleId; | ||||
| } | } | ||||
| public void setGitLinkUsername(String gitLinkUsername) { | |||||
| this.gitLinkUsername = gitLinkUsername; | |||||
| } | |||||
| public String getGitLinkUsername() { | |||||
| return gitLinkUsername; | |||||
| } | |||||
| public void setGitLinkPassword(String gitLinkPassword) { | |||||
| this.gitLinkPassword = gitLinkPassword; | |||||
| } | |||||
| public String getGitLinkPassword() { | |||||
| return gitLinkPassword; | |||||
| } | |||||
| @Override | @Override | ||||
| public String toString() { | public String toString() { | ||||
| return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | |||||
| .append("userId", getUserId()) | |||||
| .append("deptId", getDeptId()) | |||||
| .append("userName", getUserName()) | |||||
| .append("nickName", getNickName()) | |||||
| .append("email", getEmail()) | |||||
| .append("phonenumber", getPhonenumber()) | |||||
| .append("sex", getSex()) | |||||
| .append("avatar", getAvatar()) | |||||
| .append("password", getPassword()) | |||||
| .append("status", getStatus()) | |||||
| .append("delFlag", getDelFlag()) | |||||
| .append("loginIp", getLoginIp()) | |||||
| .append("loginDate", getLoginDate()) | |||||
| .append("createBy", getCreateBy()) | |||||
| .append("createTime", getCreateTime()) | |||||
| .append("updateBy", getUpdateBy()) | |||||
| .append("updateTime", getUpdateTime()) | |||||
| .append("remark", getRemark()) | |||||
| .append("dept", getDept()) | |||||
| .toString(); | |||||
| return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | |||||
| .append("userId", getUserId()) | |||||
| .append("deptId", getDeptId()) | |||||
| .append("userName", getUserName()) | |||||
| .append("nickName", getNickName()) | |||||
| .append("email", getEmail()) | |||||
| .append("phonenumber", getPhonenumber()) | |||||
| .append("sex", getSex()) | |||||
| .append("avatar", getAvatar()) | |||||
| .append("password", getPassword()) | |||||
| .append("status", getStatus()) | |||||
| .append("delFlag", getDelFlag()) | |||||
| .append("loginIp", getLoginIp()) | |||||
| .append("loginDate", getLoginDate()) | |||||
| .append("createBy", getCreateBy()) | |||||
| .append("createTime", getCreateTime()) | |||||
| .append("updateBy", getUpdateBy()) | |||||
| .append("updateTime", getUpdateTime()) | |||||
| .append("remark", getRemark()) | |||||
| .append("dept", getDept()) | |||||
| .append("gitLinkUsername", getGitLinkUsername()) | |||||
| .append("gitLinkPassword", getGitLinkPassword()) | |||||
| .toString(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -5,6 +5,17 @@ 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 Code_Repo_Pub = 1; // 代码仓库可见性-公开 | |||||
| public final static int Code_Repo_Pri = 0; // 代码仓库可见性-私有 | |||||
| public final static int State_valid = 1; // 有效 | public final static int State_valid = 1; // 有效 | ||||
| public final static int State_invalid = 0; // 无效 | public final static int State_invalid = 0; // 无效 | ||||
| public final static int Used_State_used = 1; // 已占用 | |||||
| public final static int Used_State_unused = 0; // 未占用 | |||||
| public final static String Computing_Resource_CPU = "CPU"; // 计算资源_CPU | |||||
| public final static String Computing_Resource_GPU = "GPU"; // 计算资源_GPU | |||||
| } | } | ||||
| @@ -5,10 +5,10 @@ import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.platform.domain.CodeConfig; | import com.ruoyi.platform.domain.CodeConfig; | ||||
| import com.ruoyi.platform.service.CodeConfigService; | import com.ruoyi.platform.service.CodeConfigService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| @@ -22,19 +22,25 @@ public class CodeConfigController extends BaseController { | |||||
| /** | /** | ||||
| * 分页查询 | * 分页查询 | ||||
| * | |||||
| * @param codeConfig 筛选条件 | * @param codeConfig 筛选条件 | ||||
| * @param page 页数 | |||||
| * @param size 每页大小 | |||||
| * @param page 页数 | |||||
| * @param size 每页大小 | |||||
| * @return 查询结果 | * @return 查询结果 | ||||
| */ | */ | ||||
| @GetMapping | @GetMapping | ||||
| public GenericsAjaxResult<Page<CodeConfig>> queryByPage(CodeConfig codeConfig, int page, int size) { | |||||
| PageRequest pageRequest = PageRequest.of(page,size); | |||||
| public GenericsAjaxResult<Page<CodeConfig>> queryByPage(@RequestParam("page") int page, | |||||
| @RequestParam("size") int size, | |||||
| @RequestParam(value = "code_repo_name", required = false) String codeRepoName) { | |||||
| PageRequest pageRequest = PageRequest.of(page, size); | |||||
| CodeConfig codeConfig = new CodeConfig(); | |||||
| codeConfig.setCodeRepoName(codeRepoName); | |||||
| return genericsSuccess(this.codeConfigService.queryByPage(codeConfig, pageRequest)); | return genericsSuccess(this.codeConfigService.queryByPage(codeConfig, pageRequest)); | ||||
| } | } | ||||
| /** | /** | ||||
| * 通过主键查询单条数据 | * 通过主键查询单条数据 | ||||
| * | |||||
| * @param id | * @param id | ||||
| * @return 单条数据 | * @return 单条数据 | ||||
| */ | */ | ||||
| @@ -45,17 +51,17 @@ public class CodeConfigController extends BaseController { | |||||
| @PostMapping | @PostMapping | ||||
| public GenericsAjaxResult<CodeConfig> add(@RequestBody CodeConfig codeConfig){ | |||||
| public GenericsAjaxResult<CodeConfig> add(@RequestBody CodeConfig codeConfig) { | |||||
| return genericsSuccess(this.codeConfigService.insert(codeConfig)); | return genericsSuccess(this.codeConfigService.insert(codeConfig)); | ||||
| } | } | ||||
| @PutMapping | @PutMapping | ||||
| public GenericsAjaxResult<CodeConfig> update(@RequestBody CodeConfig codeConfig){ | |||||
| public GenericsAjaxResult<CodeConfig> update(@RequestBody CodeConfig codeConfig) { | |||||
| return genericsSuccess(this.codeConfigService.update(codeConfig)); | return genericsSuccess(this.codeConfigService.update(codeConfig)); | ||||
| } | } | ||||
| @DeleteMapping("{id}") | @DeleteMapping("{id}") | ||||
| public GenericsAjaxResult<String> delete(@PathVariable("id") Long id){ | |||||
| public GenericsAjaxResult<String> delete(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(this.codeConfigService.removeById(id)); | return genericsSuccess(this.codeConfigService.removeById(id)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -15,42 +15,43 @@ public class CodeConfig implements Serializable { | |||||
| private Long id; | private Long id; | ||||
| @ApiModelProperty(value = "代码仓库名称") | |||||
| @ApiModelProperty(name = "code_repo_name",value = "代码仓库名称") | |||||
| private String codeRepoName; | private String codeRepoName; | ||||
| @ApiModelProperty(value = "代码仓库可见性(1-公开,0-私有)") | |||||
| @ApiModelProperty(name = "code_repo_vis", value = "代码仓库可见性(1-公开,0-私有)") | |||||
| private Integer codeRepoVis; | private Integer codeRepoVis; | ||||
| @ApiModelProperty(value = "Git地址") | |||||
| @ApiModelProperty(name = "git_url", value = "Git地址") | |||||
| private String gitUrl; | private String gitUrl; | ||||
| @ApiModelProperty(value = "代码分支/Tag") | |||||
| @ApiModelProperty(name = "git_branch", value = "代码分支/Tag") | |||||
| private String gitBranch; | private String gitBranch; | ||||
| @ApiModelProperty(value = "验证方式(0-用户名密码,1-SSH-Key)") | |||||
| @ApiModelProperty(name = "verify_mode", value = "验证方式(0-用户名密码,1-SSH-Key)") | |||||
| private Integer verifyMode; | private Integer verifyMode; | ||||
| @ApiModelProperty(value = "Git用户名") | |||||
| @ApiModelProperty(name = "git_user_name", value = "Git用户名") | |||||
| private String gitUserName; | private String gitUserName; | ||||
| @ApiModelProperty(value = "Git密码") | |||||
| @ApiModelProperty(name = "git_password", value = "Git密码") | |||||
| private String gitPassword; | private String gitPassword; | ||||
| @ApiModelProperty(name = "ssh_key",value = "SSH Key") | |||||
| private String sshKey; | |||||
| @ApiModelProperty(name = "create_by", value = "创建者") | |||||
| private String createBy; | private String createBy; | ||||
| /** | |||||
| * 创建时间 | |||||
| */ | |||||
| @ApiModelProperty(name = "create_time", value = "创建时间") | |||||
| private Date createTime; | private Date createTime; | ||||
| /** | |||||
| * 更新者 | |||||
| */ | |||||
| @ApiModelProperty(name = "update_by", value = "更新者") | |||||
| private String updateBy; | private String updateBy; | ||||
| /** | |||||
| * 更新时间 | |||||
| */ | |||||
| @ApiModelProperty(name = "update_time", value = "更新时间") | |||||
| private Date updateTime; | private Date updateTime; | ||||
| /** | |||||
| * 状态,0失效1生效 | |||||
| */ | |||||
| @ApiModelProperty(name = "state", value = "状态,0失效1生效") | |||||
| private Integer state; | private Integer state; | ||||
| } | } | ||||
| @@ -46,7 +46,11 @@ private Integer id; | |||||
| @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | ||||
| private Integer state; | private Integer state; | ||||
| @ApiModelProperty(value = "占用情况(1-占用,0-未占用)") | |||||
| private Integer usedState; | |||||
| @ApiModelProperty(value = "节点") | |||||
| private String node; | |||||
| public Integer getId() { | public Integer getId() { | ||||
| return id; | return id; | ||||
| @@ -122,5 +126,20 @@ private Integer id; | |||||
| this.state = state; | this.state = state; | ||||
| } | } | ||||
| public Integer getUsedState() { | |||||
| return usedState; | |||||
| } | |||||
| public void setUsedState(Integer usedState) { | |||||
| this.usedState = usedState; | |||||
| } | |||||
| public String getNode() { | |||||
| return node; | |||||
| } | |||||
| public void setNode(String node) { | |||||
| this.node = node; | |||||
| } | |||||
| } | } | ||||
| @@ -73,6 +73,8 @@ public interface ComputingResourceDao { | |||||
| */ | */ | ||||
| int update(@Param("computingResource") ComputingResource computingResource); | int update(@Param("computingResource") ComputingResource computingResource); | ||||
| int updateUsedStateByNode(@Param("node")String node, @Param("usedState") Integer usedState); | |||||
| /** | /** | ||||
| * 通过主键删除数据 | * 通过主键删除数据 | ||||
| * | * | ||||
| @@ -49,9 +49,16 @@ public class CodeConfigServiceImpl implements CodeConfigService { | |||||
| @Override | @Override | ||||
| public CodeConfig update(CodeConfig codeConfig) { | public CodeConfig update(CodeConfig codeConfig) { | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| codeConfig.setUpdateBy(loginUser.getUsername()); | codeConfig.setUpdateBy(loginUser.getUsername()); | ||||
| codeConfig.setUpdateTime(new Date()); | |||||
| if (codeConfig.getCodeRepoVis().equals(Constant.Code_Repo_Pub)) { | |||||
| codeConfig.setVerifyMode(null); | |||||
| codeConfig.setGitUserName(null); | |||||
| codeConfig.setGitPassword(null); | |||||
| codeConfig.setSshKey(null); | |||||
| } | |||||
| this.codeConfigDao.update(codeConfig); | this.codeConfigDao.update(codeConfig); | ||||
| return this.codeConfigDao.queryById(codeConfig.getId()); | return this.codeConfigDao.queryById(codeConfig.getId()); | ||||
| } | } | ||||
| @@ -2,8 +2,10 @@ package com.ruoyi.platform.service.impl; | |||||
| import com.ruoyi.common.redis.service.RedisService; | import com.ruoyi.common.redis.service.RedisService; | ||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.constant.Constant; | |||||
| import com.ruoyi.platform.domain.DevEnvironment; | import com.ruoyi.platform.domain.DevEnvironment; | ||||
| import com.ruoyi.platform.domain.PodStatus; | import com.ruoyi.platform.domain.PodStatus; | ||||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | |||||
| import com.ruoyi.platform.mapper.DevEnvironmentDao; | import com.ruoyi.platform.mapper.DevEnvironmentDao; | ||||
| import com.ruoyi.platform.service.DevEnvironmentService; | import com.ruoyi.platform.service.DevEnvironmentService; | ||||
| import com.ruoyi.platform.service.JupyterService; | import com.ruoyi.platform.service.JupyterService; | ||||
| @@ -54,6 +56,9 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Resource | @Resource | ||||
| private DevEnvironmentDao devEnvironmentDao; | private DevEnvironmentDao devEnvironmentDao; | ||||
| @Resource | |||||
| private ComputingResourceDao computingResourceDao; | |||||
| @Resource | @Resource | ||||
| @Lazy | @Lazy | ||||
| private DevEnvironmentService devEnvironmentService; | private DevEnvironmentService devEnvironmentService; | ||||
| @@ -70,7 +75,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String podName = loginUser.getUsername().toLowerCase() + "-editor-pod"; | String podName = loginUser.getUsername().toLowerCase() + "-editor-pod"; | ||||
| String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | ||||
| V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage,storageClassName); | |||||
| V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | |||||
| Integer podPort = k8sClientUtil.createPod(podName, namespace, port, mountPath, pvc, image); | Integer podPort = k8sClientUtil.createPod(podName, namespace, port, mountPath, pvc, image); | ||||
| return masterIp + ":" + podPort; | return masterIp + ":" + podPort; | ||||
| @@ -79,7 +84,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Override | @Override | ||||
| public String runJupyterService(Integer id) throws Exception { | public String runJupyterService(Integer id) throws Exception { | ||||
| DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | ||||
| if(devEnvironment == null){ | |||||
| if (devEnvironment == null) { | |||||
| throw new Exception("开发环境配置不存在"); | throw new Exception("开发环境配置不存在"); | ||||
| } | } | ||||
| @@ -92,7 +97,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| //构造pod名称 | //构造pod名称 | ||||
| String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + id; | |||||
| String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; | |||||
| String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | String pvcName = loginUser.getUsername().toLowerCase() + "-editor-pvc"; | ||||
| //新建编辑器的pvc | //新建编辑器的pvc | ||||
| V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | V1PersistentVolumeClaim pvc = k8sClientUtil.createPvc(namespace, pvcName, storage, storageClassName); | ||||
| @@ -100,13 +105,13 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| //TODO 设置镜像可配置,这里先用默认镜像启动pod | //TODO 设置镜像可配置,这里先用默认镜像启动pod | ||||
| // 调用修改后的 createPod 方法,传入额外的参数 | // 调用修改后的 createPod 方法,传入额外的参数 | ||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment.getImage(), minioPvcName, datasetPath, modelPath); | |||||
| Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, devEnvironment, minioPvcName, datasetPath, modelPath); | |||||
| String url = masterIp + ":" + podPort; | String url = masterIp + ":" + podPort; | ||||
| redisService.setCacheObject(podName,masterIp + ":" + podPort); | |||||
| redisService.setCacheObject(podName, masterIp + ":" + podPort); | |||||
| devEnvironment.setStatus("Pending"); | devEnvironment.setStatus("Pending"); | ||||
| devEnvironment.setUrl(url); | devEnvironment.setUrl(url); | ||||
| this.devEnvironmentService.update(devEnvironment); | this.devEnvironmentService.update(devEnvironment); | ||||
| return url ; | |||||
| return url; | |||||
| } | } | ||||
| @@ -114,18 +119,23 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Override | @Override | ||||
| public String stopJupyterService(Integer id) throws Exception { | public String stopJupyterService(Integer id) throws Exception { | ||||
| DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | DevEnvironment devEnvironment = this.devEnvironmentDao.queryById(id); | ||||
| if (devEnvironment==null){ | |||||
| if (devEnvironment == null) { | |||||
| throw new Exception("开发环境配置不存在"); | throw new Exception("开发环境配置不存在"); | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| //构造pod和svc名称 | //构造pod和svc名称 | ||||
| String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + id; | |||||
| String svcName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id + "-svc"; | |||||
| String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id; | |||||
| String svcName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id + "-svc"; | |||||
| //得到pod | //得到pod | ||||
| V1Pod pod = k8sClientUtil.getNSPodList(namespace, podName); | V1Pod pod = k8sClientUtil.getNSPodList(namespace, podName); | ||||
| if(pod == null){ | |||||
| if (pod == null) { | |||||
| return "pod不存在!"; | return "pod不存在!"; | ||||
| } | } | ||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| computingResourceDao.updateUsedStateByNode(pod.getSpec().getNodeName(), Constant.Used_State_unused); | |||||
| } | |||||
| // 使用 Kubernetes API 删除 Pod | // 使用 Kubernetes API 删除 Pod | ||||
| String deleteResult = k8sClientUtil.deletePod(podName, namespace); | String deleteResult = k8sClientUtil.deletePod(podName, namespace); | ||||
| // 删除service | // 删除service | ||||
| @@ -142,11 +152,11 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| String status = PodStatus.Terminated.getName(); | String status = PodStatus.Terminated.getName(); | ||||
| PodStatusVo JupyterStatusVo = new PodStatusVo(); | PodStatusVo JupyterStatusVo = new PodStatusVo(); | ||||
| JupyterStatusVo.setStatus(status); | JupyterStatusVo.setStatus(status); | ||||
| if (devEnvironment==null){ | |||||
| if (devEnvironment == null) { | |||||
| return JupyterStatusVo; | return JupyterStatusVo; | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + devEnvironment.getId(); | |||||
| String podName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + devEnvironment.getId(); | |||||
| try { | try { | ||||
| // 查询相应pod状态 | // 查询相应pod状态 | ||||
| @@ -172,7 +182,7 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Override | @Override | ||||
| public void upload(InputStream inputStream) { | public void upload(InputStream inputStream) { | ||||
| try { | try { | ||||
| minioUtil.uploadObject("platform-data","/pytorch/testupload4008208820",inputStream); | |||||
| minioUtil.uploadObject("platform-data", "/pytorch/testupload4008208820", inputStream); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| e.printStackTrace(); | e.printStackTrace(); | ||||
| } | } | ||||
| @@ -187,7 +197,4 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,25 +1,25 @@ | |||||
| package com.ruoyi.platform.utils; | package com.ruoyi.platform.utils; | ||||
| import com.alibaba.nacos.shaded.com.google.gson.reflect.TypeToken; | |||||
| import com.ruoyi.platform.constant.Constant; | |||||
| import com.ruoyi.platform.domain.DevEnvironment; | |||||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | |||||
| import io.kubernetes.client.Exec; | import io.kubernetes.client.Exec; | ||||
| import io.kubernetes.client.custom.IntOrString; | import io.kubernetes.client.custom.IntOrString; | ||||
| import io.kubernetes.client.custom.Quantity; | import io.kubernetes.client.custom.Quantity; | ||||
| import io.kubernetes.client.openapi.ApiClient; | import io.kubernetes.client.openapi.ApiClient; | ||||
| import io.kubernetes.client.openapi.ApiException; | import io.kubernetes.client.openapi.ApiException; | ||||
| import io.kubernetes.client.openapi.ApiResponse; | |||||
| import io.kubernetes.client.openapi.apis.CoreV1Api; | import io.kubernetes.client.openapi.apis.CoreV1Api; | ||||
| import io.kubernetes.client.openapi.models.*; | import io.kubernetes.client.openapi.models.*; | ||||
| import io.kubernetes.client.util.ClientBuilder; | import io.kubernetes.client.util.ClientBuilder; | ||||
| import io.kubernetes.client.util.Watch; | |||||
| import io.kubernetes.client.util.credentials.AccessTokenAuthentication; | import io.kubernetes.client.util.credentials.AccessTokenAuthentication; | ||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
| import org.apache.poi.ss.formula.functions.T; | |||||
| import org.json.JSONObject; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| import javax.annotation.PostConstruct; | |||||
| import javax.annotation.Resource; | |||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
| import java.util.*; | import java.util.*; | ||||
| @@ -40,6 +40,9 @@ public class K8sClientUtil { | |||||
| */ | */ | ||||
| private static ApiClient apiClient; | private static ApiClient apiClient; | ||||
| @Resource | |||||
| private ComputingResourceDao computingResourceDao; | |||||
| /** | /** | ||||
| * 构建集群POD内通过SA访问的客户端 | * 构建集群POD内通过SA访问的客户端 | ||||
| * loading the in-cluster config, including: | * loading the in-cluster config, including: | ||||
| @@ -133,11 +136,11 @@ public class K8sClientUtil { | |||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| log.error("获取 SVC 异常:", e); | log.error("获取 SVC 异常:", e); | ||||
| } | } | ||||
| if (v1ServiceList!=null) { | |||||
| if (v1ServiceList != null) { | |||||
| for (V1Service svc : v1ServiceList.getItems()) { | for (V1Service svc : v1ServiceList.getItems()) { | ||||
| if (StringUtils.equals(svc.getMetadata().getName(), serviceName)) { | if (StringUtils.equals(svc.getMetadata().getName(), serviceName)) { | ||||
| // SVC 已存在 | // SVC 已存在 | ||||
| return svc; | |||||
| return svc; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -177,22 +180,22 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 创建k8s PVC | * 创建k8s PVC | ||||
| * | * | ||||
| * @param namespace 命名空间 | |||||
| * @param pvcName 服务名称 | |||||
| * @param namespace 命名空间 | |||||
| * @param pvcName 服务名称 | |||||
| * @return 创建成功的service对象 | * @return 创建成功的service对象 | ||||
| */ | */ | ||||
| public V1PersistentVolumeClaim createPvc(String namespace, String pvcName ,String storage, String storageClassName){ | |||||
| public V1PersistentVolumeClaim createPvc(String namespace, String pvcName, String storage, String storageClassName) { | |||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| V1PersistentVolumeClaimList pvcList = null; | V1PersistentVolumeClaimList pvcList = null; | ||||
| try { | try { | ||||
| pvcList = api.listNamespacedPersistentVolumeClaim(namespace, null,null, null, null, null,null,null, null, null, null); | |||||
| pvcList = api.listNamespacedPersistentVolumeClaim(namespace, null, null, null, null, null, null, null, null, null, null); | |||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| log.error("获取 PVC 异常:", e); | log.error("获取 PVC 异常:", e); | ||||
| } | } | ||||
| if (pvcList!=null) { | |||||
| if (pvcList != null) { | |||||
| for (V1PersistentVolumeClaim pvc1 : pvcList.getItems()) { | for (V1PersistentVolumeClaim pvc1 : pvcList.getItems()) { | ||||
| if (StringUtils.equals(pvc1.getMetadata().getName(),pvcName)) { | |||||
| if (StringUtils.equals(pvc1.getMetadata().getName(), pvcName)) { | |||||
| // PVC 已存在 | // PVC 已存在 | ||||
| return pvc1; | return pvc1; | ||||
| } | } | ||||
| @@ -227,16 +230,17 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 创建k8s 临时POD | * 创建k8s 临时POD | ||||
| * | |||||
| * @param podName pod name | * @param podName pod name | ||||
| * @param namespace 命名空间 | |||||
| * @param port port | |||||
| * @param namespace 命名空间 | |||||
| * @param port port | |||||
| * @param mountPath 映射路径 | * @param mountPath 映射路径 | ||||
| * @param pvc 存储 | |||||
| * @param image 镜像 | |||||
| * @param pvc 存储 | |||||
| * @param image 镜像 | |||||
| * @return 创建成功的pod,的nodePort端口 | * @return 创建成功的pod,的nodePort端口 | ||||
| */ | */ | ||||
| public Integer createPod(String podName, String namespace, Integer port ,String mountPath, V1PersistentVolumeClaim pvc, String image){ | |||||
| public Integer createPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image) { | |||||
| Map<String, String> selector = new LinkedHashMap<String, String>(); | Map<String, String> selector = new LinkedHashMap<String, String>(); | ||||
| selector.put("k8s-jupyter", podName); | selector.put("k8s-jupyter", podName); | ||||
| @@ -248,7 +252,7 @@ public class K8sClientUtil { | |||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| log.error("获取 POD 异常:", e); | log.error("获取 POD 异常:", e); | ||||
| } | } | ||||
| if (v1PodList!=null) { | |||||
| if (v1PodList != null) { | |||||
| for (V1Pod pod1 : v1PodList.getItems()) { | for (V1Pod pod1 : v1PodList.getItems()) { | ||||
| if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { | if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { | ||||
| // PVC 已存在 | // PVC 已存在 | ||||
| @@ -296,17 +300,18 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 创建k8s 临时POD | * 创建k8s 临时POD | ||||
| * | |||||
| * @param podName pod name | * @param podName pod name | ||||
| * @param namespace 命名空间 | |||||
| * @param port port | |||||
| * @param namespace 命名空间 | |||||
| * @param port port | |||||
| * @param mountPath 映射路径 | * @param mountPath 映射路径 | ||||
| * @param subPath pvc子路径 | |||||
| * @param pvcName 存储名 | |||||
| * @param image 镜像 | |||||
| * @param subPath pvc子路径 | |||||
| * @param pvcName 存储名 | |||||
| * @param image 镜像 | |||||
| * @return 创建成功的pod,的nodePort端口 | * @return 创建成功的pod,的nodePort端口 | ||||
| */ | */ | ||||
| public Integer createPodWithSubPath(String podName, String namespace, Integer port ,String mountPath,String subPath,String pvcName, String image){ | |||||
| public Integer createPodWithSubPath(String podName, String namespace, Integer port, String mountPath, String subPath, String pvcName, String image) { | |||||
| Map<String, String> selector = new LinkedHashMap<String, String>(); | Map<String, String> selector = new LinkedHashMap<String, String>(); | ||||
| selector.put("k8s-jupyter", podName); | selector.put("k8s-jupyter", podName); | ||||
| @@ -318,7 +323,7 @@ public class K8sClientUtil { | |||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| log.error("获取 POD 异常:", e); | log.error("获取 POD 异常:", e); | ||||
| } | } | ||||
| if (v1PodList!=null) { | |||||
| if (v1PodList != null) { | |||||
| for (V1Pod pod1 : v1PodList.getItems()) { | for (V1Pod pod1 : v1PodList.getItems()) { | ||||
| if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { | if (StringUtils.equals(pod1.getMetadata().getName(), podName)) { | ||||
| // PVC 已存在 | // PVC 已存在 | ||||
| @@ -376,47 +381,48 @@ public class K8sClientUtil { | |||||
| } | } | ||||
| // 创建配置好的Pod | // 创建配置好的Pod | ||||
| public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, String image, String dataPvcName, String datasetPath, String modelPath) { | |||||
| public Integer createConfiguredPod(String podName, String namespace, Integer port, String mountPath, V1PersistentVolumeClaim pvc, DevEnvironment devEnvironment, String dataPvcName, String datasetPath, String modelPath) { | |||||
| //设置选择节点,pod反亲和性 | //设置选择节点,pod反亲和性 | ||||
| Map<String, String> selector = new LinkedHashMap<>(); | Map<String, String> selector = new LinkedHashMap<>(); | ||||
| selector.put("k8s-jupyter", "CPU-GPU"); | |||||
| Map<String, String> nodeSelector = new LinkedHashMap<>(); | Map<String, String> nodeSelector = new LinkedHashMap<>(); | ||||
| nodeSelector.put("resource-type", "CPU-GPU"); | |||||
| V1Affinity v1Affinity = new V1Affinity(); | |||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| selector.put("k8s-jupyter", "CPU-GPU"); | |||||
| nodeSelector.put("resource-type", "CPU-GPU"); | |||||
| V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() | |||||
| .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); | |||||
| V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() | |||||
| .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); | |||||
| V1LabelSelector labelSelector = new V1LabelSelector() | |||||
| .matchExpressions(Collections.singletonList(labelSelectorRequirement)); | |||||
| V1LabelSelector labelSelector = new V1LabelSelector() | |||||
| .matchExpressions(Collections.singletonList(labelSelectorRequirement)); | |||||
| V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() | |||||
| .labelSelector(labelSelector) | |||||
| .namespaces(Collections.singletonList(namespace)) | |||||
| .topologyKey("kubernetes.io/hostname"); | |||||
| V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() | |||||
| .labelSelector(labelSelector) | |||||
| .namespaces(Collections.singletonList(namespace)) | |||||
| .topologyKey("kubernetes.io/hostname"); | |||||
| V1PodAffinity podAffinity = new V1PodAffinity() | |||||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); | |||||
| V1PodAffinity podAffinity = new V1PodAffinity() | |||||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); | |||||
| V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() | |||||
| .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); | |||||
| V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() | |||||
| .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); | |||||
| V1LabelSelector antiLabelSelector = new V1LabelSelector() | |||||
| .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); | |||||
| V1LabelSelector antiLabelSelector = new V1LabelSelector() | |||||
| .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); | |||||
| V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() | |||||
| .labelSelector(antiLabelSelector) | |||||
| .namespaces(Collections.singletonList(namespace)) | |||||
| .topologyKey("kubernetes.io/hostname"); | |||||
| V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() | |||||
| .labelSelector(antiLabelSelector) | |||||
| .namespaces(Collections.singletonList(namespace)) | |||||
| .topologyKey("kubernetes.io/hostname"); | |||||
| // V1WeightedPodAffinityTerm weightedPodAffinityTerm = new V1WeightedPodAffinityTerm().weight(100).podAffinityTerm(podAffinityTerm); | |||||
| V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() | |||||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); | |||||
| V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() | |||||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); | |||||
| V1Affinity v1Affinity = new V1Affinity() | |||||
| .podAffinity(podAffinity) | |||||
| .podAntiAffinity(podAntiAffinity); | |||||
| v1Affinity.podAffinity(podAffinity).podAntiAffinity(podAntiAffinity); | |||||
| } else { | |||||
| selector.put("k8s-jupyter", "CPU"); | |||||
| } | |||||
| // 创建Pod | // 创建Pod | ||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| @@ -449,6 +455,26 @@ public class K8sClientUtil { | |||||
| volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | ||||
| //配置资源 | |||||
| JSONObject standardJson = new JSONObject(devEnvironment.getStandard()); | |||||
| JSONObject valueJson = (JSONObject) standardJson.get("value"); | |||||
| int cpu = (int) valueJson.get("cpu"); | |||||
| String memory = (String) valueJson.get("memory"); | |||||
| memory = memory.substring(0, memory.length() - 1).concat("i"); | |||||
| int gpu = (int) valueJson.get("gpu"); | |||||
| HashMap<String, Quantity> limitMap = new HashMap<>(); | |||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(gpu))); | |||||
| } | |||||
| limitMap.put("cpu", new Quantity(String.valueOf(cpu))); | |||||
| limitMap.put("memory", new Quantity(memory)); | |||||
| limitMap.put("ephemeral-storage", new Quantity("100Gi")); | |||||
| V1ResourceRequirements v1ResourceRequirements = new V1ResourceRequirements(); | |||||
| v1ResourceRequirements.setRequests(limitMap); | |||||
| v1ResourceRequirements.setLimits(limitMap); | |||||
| V1Pod pod = new V1PodBuilder() | V1Pod pod = new V1PodBuilder() | ||||
| .withNewMetadata() | .withNewMetadata() | ||||
| .withName(podName) | .withName(podName) | ||||
| @@ -457,9 +483,10 @@ public class K8sClientUtil { | |||||
| .withNewSpec() | .withNewSpec() | ||||
| .addNewContainer() | .addNewContainer() | ||||
| .withName(podName) | .withName(podName) | ||||
| .withImage(image) | |||||
| .withImage(devEnvironment.getImage()) | |||||
| .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) | .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) | ||||
| .withVolumeMounts(volumeMounts) | .withVolumeMounts(volumeMounts) | ||||
| .withResources(v1ResourceRequirements) | |||||
| .endContainer() | .endContainer() | ||||
| .withVolumes(volumes) | .withVolumes(volumes) | ||||
| .withNodeSelector(nodeSelector) | .withNodeSelector(nodeSelector) | ||||
| @@ -469,6 +496,10 @@ public class K8sClientUtil { | |||||
| try { | try { | ||||
| pod = api.createNamespacedPod(namespace, pod, null, null, null); | pod = api.createNamespacedPod(namespace, pod, null, null, null); | ||||
| String nodeName = getNodeName(podName, namespace); | |||||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||||
| computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); | |||||
| } | |||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| log.error("创建pod异常:" + e.getResponseBody(), e); | log.error("创建pod异常:" + e.getResponseBody(), e); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -480,14 +511,12 @@ public class K8sClientUtil { | |||||
| } | } | ||||
| /** | /** | ||||
| * 根据获取namespace,deploymentName的Pod Name | * 根据获取namespace,deploymentName的Pod Name | ||||
| * | * | ||||
| * @return podList | * @return podList | ||||
| */ | */ | ||||
| public V1Pod getNSPodList(String namespace,String deploymentName) throws Exception { | |||||
| public V1Pod getNSPodList(String namespace, String deploymentName) throws Exception { | |||||
| // new a CoreV1Api | // new a CoreV1Api | ||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| V1PodList v1PodList = null; | V1PodList v1PodList = null; | ||||
| @@ -508,12 +537,12 @@ public class K8sClientUtil { | |||||
| return null; | return null; | ||||
| } | } | ||||
| public String executeCommand(V1Pod item, String command) { | |||||
| public String executeCommand(V1Pod item, String command) { | |||||
| try { | try { | ||||
| // 创建API实例 | // 创建API实例 | ||||
| // 创建Exec实例 | // 创建Exec实例 | ||||
| Exec exec = new Exec(apiClient); | Exec exec = new Exec(apiClient); | ||||
| String[] cmd = { "/bin/sh", "-c", command}; | |||||
| String[] cmd = {"/bin/sh", "-c", command}; | |||||
| Process proc = exec.exec(item, cmd, false); | Process proc = exec.exec(item, cmd, false); | ||||
| // 读取输出 | // 读取输出 | ||||
| BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); | BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); | ||||
| @@ -538,10 +567,11 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 根据Pod的名称和Namespace查询Pod的状态 | * 根据Pod的名称和Namespace查询Pod的状态 | ||||
| * @param podName Pod的名称 | |||||
| * | |||||
| * @param podName Pod的名称 | |||||
| * @param namespace Pod所在的Namespace | * @param namespace Pod所在的Namespace | ||||
| */ | */ | ||||
| public String getPodStatus(String podName, String namespace) throws Exception { | |||||
| public String getPodStatus(String podName, String namespace) throws Exception { | |||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); | V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); | ||||
| return pod.getStatus().getPhase(); | return pod.getStatus().getPhase(); | ||||
| @@ -549,14 +579,15 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 根据Pod的名称和Namespace查询Pod的容器信息 | * 根据Pod的名称和Namespace查询Pod的容器信息 | ||||
| * @param podName Pod的名称 | |||||
| * | |||||
| * @param podName Pod的名称 | |||||
| * @param namespace Pod所在的Namespace | * @param namespace Pod所在的Namespace | ||||
| */ | */ | ||||
| public String getPodContainerId(String podName, String namespace) throws Exception { | public String getPodContainerId(String podName, String namespace) throws Exception { | ||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); | V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); | ||||
| if(pod.getStatus().getContainerStatuses().size() !=1){ | |||||
| if (pod.getStatus().getContainerStatuses().size() != 1) { | |||||
| throw new RuntimeException("容器错误"); | throw new RuntimeException("容器错误"); | ||||
| } | } | ||||
| String containerId = pod.getStatus().getContainerStatuses().get(0).getContainerID().split("//")[1]; | String containerId = pod.getStatus().getContainerStatuses().get(0).getContainerID().split("//")[1]; | ||||
| @@ -569,10 +600,16 @@ public class K8sClientUtil { | |||||
| return pod.getStatus().getHostIP(); | return pod.getStatus().getHostIP(); | ||||
| } | } | ||||
| public String getPodLogs(String podName,String namespace,String container,int line) { | |||||
| public String getNodeName(String podName, String namespace) throws Exception { | |||||
| CoreV1Api api = new CoreV1Api(apiClient); | |||||
| V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); | |||||
| return pod.getSpec().getNodeName(); | |||||
| } | |||||
| public String getPodLogs(String podName, String namespace, String container, int line) { | |||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| try { | try { | ||||
| String log = api.readNamespacedPodLog(podName, namespace, StringUtils.isEmpty(container)?null:container, null, null, null, null,null, null, line, null); | |||||
| String log = api.readNamespacedPodLog(podName, namespace, StringUtils.isEmpty(container) ? null : container, null, null, null, null, null, null, line, null); | |||||
| return log; | return log; | ||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| throw new RuntimeException("获取Pod日志异常", e); | throw new RuntimeException("获取Pod日志异常", e); | ||||
| @@ -581,7 +618,7 @@ public class K8sClientUtil { | |||||
| } | } | ||||
| public V1Pod createPodWithEnv(String podName,String namespace,String proxyUrl ,String mountPath,String pvcName, String image){ | |||||
| public V1Pod createPodWithEnv(String podName, String namespace, String proxyUrl, String mountPath, String pvcName, String image) { | |||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| V1PodList v1PodList = null; | V1PodList v1PodList = null; | ||||
| V1Pod pod = new V1PodBuilder() | V1Pod pod = new V1PodBuilder() | ||||
| @@ -625,7 +662,7 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 删除 Pod | * 删除 Pod | ||||
| * | * | ||||
| * @param podName Pod 名称 | |||||
| * @param podName Pod 名称 | |||||
| * @param namespace 命名空间 | * @param namespace 命名空间 | ||||
| * @throws ApiException 异常 | * @throws ApiException 异常 | ||||
| */ | */ | ||||
| @@ -644,7 +681,7 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 删除 Service | * 删除 Service | ||||
| * | * | ||||
| * @param svcName Service 名称 | |||||
| * @param svcName Service 名称 | |||||
| * @param namespace 命名空间 | * @param namespace 命名空间 | ||||
| * @throws ApiException 异常 | * @throws ApiException 异常 | ||||
| */ | */ | ||||
| @@ -663,7 +700,7 @@ public class K8sClientUtil { | |||||
| /** | /** | ||||
| * 检查 Pod 是否存在 | * 检查 Pod 是否存在 | ||||
| * | * | ||||
| * @param podName Pod 名称 | |||||
| * @param podName Pod 名称 | |||||
| * @param namespace 命名空间 | * @param namespace 命名空间 | ||||
| * @return 是否存在 | * @return 是否存在 | ||||
| * @throws ApiException 异常 | * @throws ApiException 异常 | ||||
| @@ -671,7 +708,7 @@ public class K8sClientUtil { | |||||
| public boolean checkPodExists(String podName, String namespace) throws ApiException { | public boolean checkPodExists(String podName, String namespace) throws ApiException { | ||||
| CoreV1Api api = new CoreV1Api(apiClient); | CoreV1Api api = new CoreV1Api(apiClient); | ||||
| try { | try { | ||||
| api.readNamespacedPod(podName, namespace, null,false,false); | |||||
| api.readNamespacedPod(podName, namespace, null, false, false); | |||||
| return true; | return true; | ||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| if (e.getCode() == 404) { | if (e.getCode() == 404) { | ||||
| @@ -3,8 +3,9 @@ | |||||
| <mapper namespace="com.ruoyi.platform.mapper.CodeConfigDao"> | <mapper namespace="com.ruoyi.platform.mapper.CodeConfigDao"> | ||||
| <insert id="insert"> | <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 into code_config(code_repo_name, code_repo_vis, git_url, git_branch, verify_mode, git_user_name, git_password,ssh_key, create_by, create_time, update_by, update_time) | |||||
| values(#{codeConfig.codeRepoName}, #{codeConfig.codeRepoVis}, #{codeConfig.gitUrl}, #{codeConfig.gitBranch}, #{codeConfig.verifyMode}, #{codeConfig.gitUserName}, #{codeConfig.gitPassword}, | |||||
| #{codeConfig.sshKey}, #{codeConfig.createBy}, #{codeConfig.createTime}, #{codeConfig.updateBy}, #{codeConfig.updateTime}) | |||||
| </insert> | </insert> | ||||
| <update id="update"> | <update id="update"> | ||||
| @@ -22,12 +23,10 @@ | |||||
| <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''"> | <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''"> | ||||
| git_branch = #{codeConfig.gitBranch}, | git_branch = #{codeConfig.gitBranch}, | ||||
| </if> | </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> | |||||
| verify_mode = #{codeConfig.verifyMode}, | |||||
| git_user_name = #{codeConfig.gitUserName}, | |||||
| git_password = #{codeConfig.gitPassword}, | |||||
| ssh_key = #{codeConfig.sshKey}, | |||||
| <if test="codeConfig.createBy != null and codeConfig.createBy != ''"> | <if test="codeConfig.createBy != null and codeConfig.createBy != ''"> | ||||
| create_by = #{codeConfig.createBy}, | create_by = #{codeConfig.createBy}, | ||||
| </if> | </if> | ||||
| @@ -37,12 +36,10 @@ | |||||
| <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''"> | <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''"> | ||||
| update_by = #{codeConfig.updateBy}, | update_by = #{codeConfig.updateBy}, | ||||
| </if> | </if> | ||||
| <if test="codeConfig.updateTime != null"> | |||||
| update_time = #{codeConfig.updateTime}, | |||||
| </if> | |||||
| <if test="codeConfig.state != null"> | <if test="codeConfig.state != null"> | ||||
| state = #{codeConfig.state}, | state = #{codeConfig.state}, | ||||
| </if> | </if> | ||||
| update_time = sysdate() | |||||
| </set> | </set> | ||||
| where id = #{codeConfig.id} | where id = #{codeConfig.id} | ||||
| </update> | </update> | ||||
| @@ -74,7 +71,7 @@ | |||||
| and id = #{codeConfig.id} | and id = #{codeConfig.id} | ||||
| </if> | </if> | ||||
| <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''"> | <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''"> | ||||
| and code_repo_name = #{codeConfig.codeRepoName} | |||||
| and code_repo_name LIKE CONCAT('%', #{codeConfig.codeRepoName}, '%') | |||||
| </if> | </if> | ||||
| <if test="codeConfig.codeRepoVis != null"> | <if test="codeConfig.codeRepoVis != null"> | ||||
| and code_repo_vis = #{codeConfig.codeRepoVis} | and code_repo_vis = #{codeConfig.codeRepoVis} | ||||
| @@ -156,6 +156,10 @@ computing_resource = values(computing_resource)standard = values(standard)descri | |||||
| where id = #{computingResource.id} | where id = #{computingResource.id} | ||||
| </update> | </update> | ||||
| <update id="updateUsedStateByNode"> | |||||
| update computing_resource set used_state = #{usedState} where node = #{node} | |||||
| </update> | |||||
| <!--通过主键删除--> | <!--通过主键删除--> | ||||
| <delete id="deleteById"> | <delete id="deleteById"> | ||||
| delete from computing_resource where id = #{id} | delete from computing_resource where id = #{id} | ||||
| @@ -1,22 +1,5 @@ | |||||
| package com.ruoyi.system.controller; | package com.ruoyi.system.controller; | ||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| import java.util.Set; | |||||
| import java.util.stream.Collectors; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import org.apache.commons.lang3.ArrayUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.validation.annotation.Validated; | |||||
| import org.springframework.web.bind.annotation.DeleteMapping; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.PathVariable; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.PutMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import com.ruoyi.common.core.domain.R; | import com.ruoyi.common.core.domain.R; | ||||
| import com.ruoyi.common.core.utils.StringUtils; | import com.ruoyi.common.core.utils.StringUtils; | ||||
| import com.ruoyi.common.core.utils.poi.ExcelUtil; | import com.ruoyi.common.core.utils.poi.ExcelUtil; | ||||
| @@ -32,22 +15,27 @@ import com.ruoyi.system.api.domain.SysDept; | |||||
| import com.ruoyi.system.api.domain.SysRole; | import com.ruoyi.system.api.domain.SysRole; | ||||
| import com.ruoyi.system.api.domain.SysUser; | import com.ruoyi.system.api.domain.SysUser; | ||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import com.ruoyi.system.service.ISysConfigService; | |||||
| import com.ruoyi.system.service.ISysDeptService; | |||||
| import com.ruoyi.system.service.ISysPermissionService; | |||||
| import com.ruoyi.system.service.ISysPostService; | |||||
| import com.ruoyi.system.service.ISysRoleService; | |||||
| import com.ruoyi.system.service.ISysUserService; | |||||
| import com.ruoyi.system.service.*; | |||||
| import org.apache.commons.lang3.ArrayUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.validation.annotation.Validated; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| import java.util.Set; | |||||
| import java.util.stream.Collectors; | |||||
| /** | /** | ||||
| * 用户信息 | * 用户信息 | ||||
| * | |||||
| * | |||||
| * @author ruoyi | * @author ruoyi | ||||
| */ | */ | ||||
| @RestController | @RestController | ||||
| @RequestMapping("/user") | @RequestMapping("/user") | ||||
| public class SysUserController extends BaseController | |||||
| { | |||||
| public class SysUserController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private ISysUserService userService; | private ISysUserService userService; | ||||
| @@ -71,8 +59,7 @@ public class SysUserController extends BaseController | |||||
| */ | */ | ||||
| @RequiresPermissions("system:user:list") | @RequiresPermissions("system:user:list") | ||||
| @GetMapping("/list") | @GetMapping("/list") | ||||
| public TableDataInfo list(SysUser user) | |||||
| { | |||||
| public TableDataInfo list(SysUser user) { | |||||
| startPage(); | startPage(); | ||||
| List<SysUser> list = userService.selectUserList(user); | List<SysUser> list = userService.selectUserList(user); | ||||
| return getDataTable(list); | return getDataTable(list); | ||||
| @@ -81,8 +68,7 @@ public class SysUserController extends BaseController | |||||
| @Log(title = "用户管理", businessType = BusinessType.EXPORT) | @Log(title = "用户管理", businessType = BusinessType.EXPORT) | ||||
| @RequiresPermissions("system:user:export") | @RequiresPermissions("system:user:export") | ||||
| @PostMapping("/export") | @PostMapping("/export") | ||||
| public void export(HttpServletResponse response, SysUser user) | |||||
| { | |||||
| public void export(HttpServletResponse response, SysUser user) { | |||||
| List<SysUser> list = userService.selectUserList(user); | List<SysUser> list = userService.selectUserList(user); | ||||
| ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ||||
| util.exportExcel(response, list, "用户数据"); | util.exportExcel(response, list, "用户数据"); | ||||
| @@ -91,8 +77,7 @@ public class SysUserController extends BaseController | |||||
| @Log(title = "用户管理", businessType = BusinessType.IMPORT) | @Log(title = "用户管理", businessType = BusinessType.IMPORT) | ||||
| @RequiresPermissions("system:user:import") | @RequiresPermissions("system:user:import") | ||||
| @PostMapping("/importData") | @PostMapping("/importData") | ||||
| public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception | |||||
| { | |||||
| public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { | |||||
| ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ||||
| List<SysUser> userList = util.importExcel(file.getInputStream()); | List<SysUser> userList = util.importExcel(file.getInputStream()); | ||||
| String operName = SecurityUtils.getUsername(); | String operName = SecurityUtils.getUsername(); | ||||
| @@ -101,8 +86,7 @@ public class SysUserController extends BaseController | |||||
| } | } | ||||
| @PostMapping("/importTemplate") | @PostMapping("/importTemplate") | ||||
| public void importTemplate(HttpServletResponse response) throws IOException | |||||
| { | |||||
| public void importTemplate(HttpServletResponse response) throws IOException { | |||||
| ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | ||||
| util.importTemplateExcel(response, "用户数据"); | util.importTemplateExcel(response, "用户数据"); | ||||
| } | } | ||||
| @@ -112,11 +96,9 @@ public class SysUserController extends BaseController | |||||
| */ | */ | ||||
| @InnerAuth | @InnerAuth | ||||
| @GetMapping("/info/{username}") | @GetMapping("/info/{username}") | ||||
| public R<LoginUser> info(@PathVariable("username") String username) | |||||
| { | |||||
| public R<LoginUser> info(@PathVariable("username") String username) { | |||||
| SysUser sysUser = userService.selectUserByUserName(username); | SysUser sysUser = userService.selectUserByUserName(username); | ||||
| if (StringUtils.isNull(sysUser)) | |||||
| { | |||||
| if (StringUtils.isNull(sysUser)) { | |||||
| return R.fail("用户名或密码错误"); | return R.fail("用户名或密码错误"); | ||||
| } | } | ||||
| // 角色集合 | // 角色集合 | ||||
| @@ -135,15 +117,12 @@ public class SysUserController extends BaseController | |||||
| */ | */ | ||||
| @InnerAuth | @InnerAuth | ||||
| @PostMapping("/register") | @PostMapping("/register") | ||||
| public R<Boolean> register(@RequestBody SysUser sysUser) | |||||
| { | |||||
| public R<Boolean> register(@RequestBody SysUser sysUser) { | |||||
| String username = sysUser.getUserName(); | String username = sysUser.getUserName(); | ||||
| if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) | |||||
| { | |||||
| if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) { | |||||
| return R.fail("当前系统没有开启注册功能!"); | return R.fail("当前系统没有开启注册功能!"); | ||||
| } | } | ||||
| if (!userService.checkUserNameUnique(sysUser)) | |||||
| { | |||||
| if (!userService.checkUserNameUnique(sysUser)) { | |||||
| return R.fail("保存用户'" + username + "'失败,注册账号已存在"); | return R.fail("保存用户'" + username + "'失败,注册账号已存在"); | ||||
| } | } | ||||
| return R.ok(userService.registerUser(sysUser)); | return R.ok(userService.registerUser(sysUser)); | ||||
| @@ -151,12 +130,11 @@ public class SysUserController extends BaseController | |||||
| /** | /** | ||||
| * 获取用户信息 | * 获取用户信息 | ||||
| * | |||||
| * | |||||
| * @return 用户信息 | * @return 用户信息 | ||||
| */ | */ | ||||
| @GetMapping("getInfo") | @GetMapping("getInfo") | ||||
| public AjaxResult getInfo() | |||||
| { | |||||
| public AjaxResult getInfo() { | |||||
| SysUser user = userService.selectUserById(SecurityUtils.getUserId()); | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); | ||||
| // 角色集合 | // 角色集合 | ||||
| Set<String> roles = permissionService.getRolePermission(user); | Set<String> roles = permissionService.getRolePermission(user); | ||||
| @@ -173,16 +151,14 @@ public class SysUserController extends BaseController | |||||
| * 根据用户编号获取详细信息 | * 根据用户编号获取详细信息 | ||||
| */ | */ | ||||
| @RequiresPermissions("system:user:query") | @RequiresPermissions("system:user:query") | ||||
| @GetMapping(value = { "/", "/{userId}" }) | |||||
| public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) | |||||
| { | |||||
| @GetMapping(value = {"/", "/{userId}"}) | |||||
| public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) { | |||||
| userService.checkUserDataScope(userId); | userService.checkUserDataScope(userId); | ||||
| AjaxResult ajax = AjaxResult.success(); | AjaxResult ajax = AjaxResult.success(); | ||||
| List<SysRole> roles = roleService.selectRoleAll(); | List<SysRole> roles = roleService.selectRoleAll(); | ||||
| ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); | ||||
| ajax.put("posts", postService.selectPostAll()); | ajax.put("posts", postService.selectPostAll()); | ||||
| if (StringUtils.isNotNull(userId)) | |||||
| { | |||||
| if (StringUtils.isNotNull(userId)) { | |||||
| SysUser sysUser = userService.selectUserById(userId); | SysUser sysUser = userService.selectUserById(userId); | ||||
| ajax.put(AjaxResult.DATA_TAG, sysUser); | ajax.put(AjaxResult.DATA_TAG, sysUser); | ||||
| ajax.put("postIds", postService.selectPostListByUserId(userId)); | ajax.put("postIds", postService.selectPostListByUserId(userId)); | ||||
| @@ -197,22 +173,19 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:add") | @RequiresPermissions("system:user:add") | ||||
| @Log(title = "用户管理", businessType = BusinessType.INSERT) | @Log(title = "用户管理", businessType = BusinessType.INSERT) | ||||
| @PostMapping | @PostMapping | ||||
| public AjaxResult add(@Validated @RequestBody SysUser user) | |||||
| { | |||||
| if (!userService.checkUserNameUnique(user)) | |||||
| { | |||||
| public AjaxResult add(@Validated @RequestBody SysUser user) { | |||||
| if (!userService.checkUserNameUnique(user)) { | |||||
| return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); | return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); | ||||
| } | |||||
| else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) | |||||
| { | |||||
| } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { | |||||
| return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); | return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); | ||||
| } | |||||
| else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) | |||||
| { | |||||
| } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { | |||||
| return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | ||||
| } else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) { | |||||
| return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在"); | |||||
| } | } | ||||
| user.setCreateBy(SecurityUtils.getUsername()); | user.setCreateBy(SecurityUtils.getUsername()); | ||||
| user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | ||||
| user.setGitLinkPassword(SecurityUtils.encryptPassword(user.getGitLinkPassword())); | |||||
| return toAjax(userService.insertUser(user)); | return toAjax(userService.insertUser(user)); | ||||
| } | } | ||||
| @@ -222,23 +195,25 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:edit") | @RequiresPermissions("system:user:edit") | ||||
| @Log(title = "用户管理", businessType = BusinessType.UPDATE) | @Log(title = "用户管理", businessType = BusinessType.UPDATE) | ||||
| @PutMapping | @PutMapping | ||||
| public AjaxResult edit(@Validated @RequestBody SysUser user) | |||||
| { | |||||
| public AjaxResult edit(@Validated @RequestBody SysUser user) { | |||||
| userService.checkUserAllowed(user); | userService.checkUserAllowed(user); | ||||
| userService.checkUserDataScope(user.getUserId()); | userService.checkUserDataScope(user.getUserId()); | ||||
| if (!userService.checkUserNameUnique(user)) | |||||
| { | |||||
| if (!userService.checkUserNameUnique(user)) { | |||||
| return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); | return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); | ||||
| } | |||||
| else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) | |||||
| { | |||||
| } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { | |||||
| return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); | return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); | ||||
| } | |||||
| else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) | |||||
| { | |||||
| } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { | |||||
| return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | ||||
| } else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) { | |||||
| return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在"); | |||||
| } | } | ||||
| user.setUpdateBy(SecurityUtils.getUsername()); | user.setUpdateBy(SecurityUtils.getUsername()); | ||||
| if(StringUtils.isNotEmpty(user.getPassword())){ | |||||
| user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | |||||
| } | |||||
| if(StringUtils.isNotEmpty(user.getGitLinkPassword())){ | |||||
| user.setGitLinkPassword(SecurityUtils.encryptPassword(user.getGitLinkPassword())); | |||||
| } | |||||
| return toAjax(userService.updateUser(user)); | return toAjax(userService.updateUser(user)); | ||||
| } | } | ||||
| @@ -248,10 +223,8 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:remove") | @RequiresPermissions("system:user:remove") | ||||
| @Log(title = "用户管理", businessType = BusinessType.DELETE) | @Log(title = "用户管理", businessType = BusinessType.DELETE) | ||||
| @DeleteMapping("/{userIds}") | @DeleteMapping("/{userIds}") | ||||
| public AjaxResult remove(@PathVariable Long[] userIds) | |||||
| { | |||||
| if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) | |||||
| { | |||||
| public AjaxResult remove(@PathVariable Long[] userIds) { | |||||
| if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) { | |||||
| return error("当前用户不能删除"); | return error("当前用户不能删除"); | ||||
| } | } | ||||
| return toAjax(userService.deleteUserByIds(userIds)); | return toAjax(userService.deleteUserByIds(userIds)); | ||||
| @@ -263,8 +236,7 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:edit") | @RequiresPermissions("system:user:edit") | ||||
| @Log(title = "用户管理", businessType = BusinessType.UPDATE) | @Log(title = "用户管理", businessType = BusinessType.UPDATE) | ||||
| @PutMapping("/resetPwd") | @PutMapping("/resetPwd") | ||||
| public AjaxResult resetPwd(@RequestBody SysUser user) | |||||
| { | |||||
| public AjaxResult resetPwd(@RequestBody SysUser user) { | |||||
| userService.checkUserAllowed(user); | userService.checkUserAllowed(user); | ||||
| userService.checkUserDataScope(user.getUserId()); | userService.checkUserDataScope(user.getUserId()); | ||||
| user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | ||||
| @@ -278,8 +250,7 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:edit") | @RequiresPermissions("system:user:edit") | ||||
| @Log(title = "用户管理", businessType = BusinessType.UPDATE) | @Log(title = "用户管理", businessType = BusinessType.UPDATE) | ||||
| @PutMapping("/changeStatus") | @PutMapping("/changeStatus") | ||||
| public AjaxResult changeStatus(@RequestBody SysUser user) | |||||
| { | |||||
| public AjaxResult changeStatus(@RequestBody SysUser user) { | |||||
| userService.checkUserAllowed(user); | userService.checkUserAllowed(user); | ||||
| userService.checkUserDataScope(user.getUserId()); | userService.checkUserDataScope(user.getUserId()); | ||||
| user.setUpdateBy(SecurityUtils.getUsername()); | user.setUpdateBy(SecurityUtils.getUsername()); | ||||
| @@ -291,8 +262,7 @@ public class SysUserController extends BaseController | |||||
| */ | */ | ||||
| @RequiresPermissions("system:user:query") | @RequiresPermissions("system:user:query") | ||||
| @GetMapping("/authRole/{userId}") | @GetMapping("/authRole/{userId}") | ||||
| public AjaxResult authRole(@PathVariable("userId") Long userId) | |||||
| { | |||||
| public AjaxResult authRole(@PathVariable("userId") Long userId) { | |||||
| AjaxResult ajax = AjaxResult.success(); | AjaxResult ajax = AjaxResult.success(); | ||||
| SysUser user = userService.selectUserById(userId); | SysUser user = userService.selectUserById(userId); | ||||
| List<SysRole> roles = roleService.selectRolesByUserId(userId); | List<SysRole> roles = roleService.selectRolesByUserId(userId); | ||||
| @@ -307,8 +277,7 @@ public class SysUserController extends BaseController | |||||
| @RequiresPermissions("system:user:edit") | @RequiresPermissions("system:user:edit") | ||||
| @Log(title = "用户管理", businessType = BusinessType.GRANT) | @Log(title = "用户管理", businessType = BusinessType.GRANT) | ||||
| @PutMapping("/authRole") | @PutMapping("/authRole") | ||||
| public AjaxResult insertAuthRole(Long userId, Long[] roleIds) | |||||
| { | |||||
| public AjaxResult insertAuthRole(Long userId, Long[] roleIds) { | |||||
| userService.checkUserDataScope(userId); | userService.checkUserDataScope(userId); | ||||
| userService.insertUserAuth(userId, roleIds); | userService.insertUserAuth(userId, roleIds); | ||||
| return success(); | return success(); | ||||
| @@ -319,8 +288,7 @@ public class SysUserController extends BaseController | |||||
| */ | */ | ||||
| @RequiresPermissions("system:user:list") | @RequiresPermissions("system:user:list") | ||||
| @GetMapping("/deptTree") | @GetMapping("/deptTree") | ||||
| public AjaxResult deptTree(SysDept dept) | |||||
| { | |||||
| public AjaxResult deptTree(SysDept dept) { | |||||
| return success(deptService.selectDeptTreeList(dept)); | return success(deptService.selectDeptTreeList(dept)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -124,4 +124,6 @@ public interface SysUserMapper | |||||
| * @return 结果 | * @return 结果 | ||||
| */ | */ | ||||
| public SysUser checkEmailUnique(String email); | public SysUser checkEmailUnique(String email); | ||||
| public SysUser checktGitLinkUsernameUnique(String gitLinkUsername); | |||||
| } | } | ||||
| @@ -90,6 +90,8 @@ public interface ISysUserService | |||||
| */ | */ | ||||
| public boolean checkEmailUnique(SysUser user); | public boolean checkEmailUnique(SysUser user); | ||||
| public boolean checktGitLinkUsernameUnique(SysUser user); | |||||
| /** | /** | ||||
| * 校验用户是否允许操作 | * 校验用户是否允许操作 | ||||
| * | * | ||||
| @@ -212,6 +212,17 @@ public class SysUserServiceImpl implements ISysUserService | |||||
| return UserConstants.UNIQUE; | return UserConstants.UNIQUE; | ||||
| } | } | ||||
| @Override | |||||
| public boolean checktGitLinkUsernameUnique(SysUser user) { | |||||
| Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); | |||||
| SysUser info = userMapper.checktGitLinkUsernameUnique(user.getGitLinkUsername()); | |||||
| if(StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) | |||||
| { | |||||
| return UserConstants.NOT_UNIQUE; | |||||
| } | |||||
| return UserConstants.UNIQUE; | |||||
| } | |||||
| /** | /** | ||||
| * 校验用户是否允许操作 | * 校验用户是否允许操作 | ||||
| * | * | ||||
| @@ -47,43 +47,74 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="selectUserVo"> | <sql id="selectUserVo"> | ||||
| select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, | |||||
| d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, | |||||
| r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status | |||||
| select u.user_id, | |||||
| u.dept_id, | |||||
| u.user_name, | |||||
| u.nick_name, | |||||
| u.email, | |||||
| u.avatar, | |||||
| u.phonenumber, | |||||
| u.password, | |||||
| u.git_link_username, | |||||
| u.git_link_password, | |||||
| u.sex, | |||||
| u.status, | |||||
| u.del_flag, | |||||
| u.login_ip, | |||||
| u.login_date, | |||||
| u.create_by, | |||||
| u.create_time, | |||||
| u.remark, | |||||
| d.dept_id, | |||||
| d.parent_id, | |||||
| d.ancestors, | |||||
| d.dept_name, | |||||
| d.order_num, | |||||
| d.leader, | |||||
| d.status as dept_status, | |||||
| r.role_id, | |||||
| r.role_name, | |||||
| r.role_key, | |||||
| r.role_sort, | |||||
| r.data_scope, | |||||
| r.status as role_status | |||||
| from sys_user u | from sys_user u | ||||
| left join sys_dept d on u.dept_id = d.dept_id | |||||
| left join sys_user_role ur on u.user_id = ur.user_id | |||||
| left join sys_role r on r.role_id = ur.role_id | |||||
| left join sys_dept d on u.dept_id = d.dept_id | |||||
| left join sys_user_role ur on u.user_id = ur.user_id | |||||
| left join sys_role r on r.role_id = ur.role_id | |||||
| </sql> | </sql> | ||||
| <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | ||||
| select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u | |||||
| left join sys_dept d on u.dept_id = d.dept_id | |||||
| where u.del_flag = '0' | |||||
| <if test="userId != null and userId != 0"> | |||||
| AND u.user_id = #{userId} | |||||
| </if> | |||||
| <if test="userName != null and userName != ''"> | |||||
| AND u.user_name like concat('%', #{userName}, '%') | |||||
| </if> | |||||
| <if test="status != null and status != ''"> | |||||
| AND u.status = #{status} | |||||
| </if> | |||||
| <if test="phonenumber != null and phonenumber != ''"> | |||||
| AND u.phonenumber like concat('%', #{phonenumber}, '%') | |||||
| </if> | |||||
| <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | |||||
| AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | |||||
| </if> | |||||
| <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | |||||
| AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | |||||
| </if> | |||||
| <if test="deptId != null and deptId != 0"> | |||||
| AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) )) | |||||
| </if> | |||||
| <!-- 数据范围过滤 --> | |||||
| ${params.dataScope} | |||||
| </select> | |||||
| select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.git_link_username, | |||||
| u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader | |||||
| from sys_user u | |||||
| left join sys_dept d on u.dept_id = d.dept_id | |||||
| where u.del_flag = '0' | |||||
| <if test="userId != null and userId != 0"> | |||||
| AND u.user_id = #{userId} | |||||
| </if> | |||||
| <if test="userName != null and userName != ''"> | |||||
| AND u.user_name like concat('%', #{userName}, '%') | |||||
| </if> | |||||
| <if test="status != null and status != ''"> | |||||
| AND u.status = #{status} | |||||
| </if> | |||||
| <if test="phonenumber != null and phonenumber != ''"> | |||||
| AND u.phonenumber like concat('%', #{phonenumber}, '%') | |||||
| </if> | |||||
| <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | |||||
| AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | |||||
| </if> | |||||
| <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | |||||
| AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | |||||
| </if> | |||||
| <if test="deptId != null and deptId != 0"> | |||||
| AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, | |||||
| ancestors) )) | |||||
| </if> | |||||
| <!-- 数据范围过滤 --> | |||||
| ${params.dataScope} | |||||
| </select> | |||||
| <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> | <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> | ||||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time | select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time | ||||
| @@ -141,8 +172,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
| <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult"> | <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult"> | ||||
| select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1 | select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1 | ||||
| </select> | </select> | ||||
| <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> | |||||
| <select id="checktGitLinkUsernameUnique" resultType="com.ruoyi.system.api.domain.SysUser"> | |||||
| select user_id, git_link_username | |||||
| from sys_user | |||||
| where git_link_username = #{gitLinkUsername} | |||||
| and del_flag = '0' limit 1 | |||||
| </select> | |||||
| <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> | |||||
| insert into sys_user( | insert into sys_user( | ||||
| <if test="userId != null and userId != 0">user_id,</if> | <if test="userId != null and userId != 0">user_id,</if> | ||||
| <if test="deptId != null and deptId != 0">dept_id,</if> | <if test="deptId != null and deptId != 0">dept_id,</if> | ||||
| @@ -190,6 +228,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
| <if test="loginDate != null">login_date = #{loginDate},</if> | <if test="loginDate != null">login_date = #{loginDate},</if> | ||||
| <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | ||||
| <if test="remark != null">remark = #{remark},</if> | <if test="remark != null">remark = #{remark},</if> | ||||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username = #{gitLinkUsername},</if> | |||||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> | |||||
| update_time = sysdate() | update_time = sysdate() | ||||
| </set> | </set> | ||||
| where user_id = #{userId} | where user_id = #{userId} | ||||