diff --git a/src/main/java/cc/niushuai/bastionserver/config/mybatis/MybatisPlusSaasConfig.java b/src/main/java/cc/niushuai/bastionserver/config/mybatis/MybatisPlusSaasConfig.java index 7d4c8ba..d2f559e 100644 --- a/src/main/java/cc/niushuai/bastionserver/config/mybatis/MybatisPlusSaasConfig.java +++ b/src/main/java/cc/niushuai/bastionserver/config/mybatis/MybatisPlusSaasConfig.java @@ -37,6 +37,8 @@ public class MybatisPlusSaasConfig { static { TENANT_TABLE.add("demo"); + TENANT_TABLE.add("bas_server_info"); + TENANT_TABLE.add("bas_tunnel_info"); // //角色、菜单、部门 // tenantTable.add("sys_role"); diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/controller/ServerInfoController.java b/src/main/java/cc/niushuai/bastionserver/modules/server/controller/ServerInfoController.java new file mode 100644 index 0000000..38757de --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/controller/ServerInfoController.java @@ -0,0 +1,158 @@ +package cc.niushuai.bastionserver.modules.server.controller; + +import cc.niushuai.bastionserver.common.api.vo.Result; +import cc.niushuai.bastionserver.common.aspect.annotation.AutoLog; +import cc.niushuai.bastionserver.common.base.controller.BaseController; +import cc.niushuai.bastionserver.common.system.query.QueryGenerator; +import cc.niushuai.bastionserver.modules.server.entity.ServerInfo; +import cc.niushuai.bastionserver.modules.server.service.ServerInfoService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; + +/** + * 服务器信息 + * + * @author: niushuai233 + * @date: 2023-01-03 16:20:46 + */ +@Slf4j +@Api(tags = "服务器信息") +@RestController +@RequestMapping("/server/serverInfo") +public class ServerInfoController extends BaseController { + + @Resource + private ServerInfoService serverInfoService; + + /** + * 分页列表查询 + * + * @param serverInfo + * @param pageNo + * @param pageSize + * @param req + * @return + */ + @AutoLog(value = "服务器信息-分页列表查询") + @ApiOperation(value = "服务器信息-分页列表查询", notes = "服务器信息-分页列表查询") + @GetMapping(value = "/list") + public Result queryPageList(ServerInfo serverInfo, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(serverInfo, req.getParameterMap()); + Page page = new Page(pageNo, pageSize); + IPage pageList = serverInfoService.page(page, queryWrapper); + return Result.OK(pageList); + } + + /** + * 添加 + * + * @param serverInfo + * @return + */ + @AutoLog(value = "服务器信息-添加") + @ApiOperation(value = "服务器信息-添加", notes = "服务器信息-添加") + @PostMapping(value = "/add") + public Result add(@RequestBody ServerInfo serverInfo) { + + exists(serverInfo, ServerInfo::getId, ServerInfo::getIp); + + serverInfoService.save(serverInfo); + return Result.OK("添加成功!"); + } + + + /** + * 编辑 + * + * @param serverInfo + * @return + */ + @AutoLog(value = "服务器信息-编辑") + @ApiOperation(value = "服务器信息-编辑", notes = "服务器信息-编辑") + @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result edit(@RequestBody ServerInfo serverInfo) { + exists(serverInfo, ServerInfo::getId, ServerInfo::getIp); + serverInfoService.updateById(serverInfo); + return Result.OK("编辑成功!"); + } + + /** + * 通过id删除 + * + * @param id + * @return + */ + @AutoLog(value = "服务器信息-通过id删除") + @ApiOperation(value = "服务器信息-通过id删除", notes = "服务器信息-通过id删除") + @DeleteMapping(value = "/delete") + public Result delete(@RequestParam(name = "id", required = true) String id) { + serverInfoService.removeById(id); + return Result.OK("删除成功!"); + } + + /** + * 批量删除 + * + * @param ids + * @return + */ + @AutoLog(value = "服务器信息-批量删除") + @ApiOperation(value = "服务器信息-批量删除", notes = "服务器信息-批量删除") + @DeleteMapping(value = "/deleteBatch") + public Result deleteBatch(@RequestParam(name = "ids", required = true) String ids) { + this.serverInfoService.removeByIds(Arrays.asList(ids.split(","))); + return Result.OK("批量删除成功!"); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ + @AutoLog(value = "服务器信息-通过id查询") + @ApiOperation(value = "服务器信息-通过id查询", notes = "服务器信息-通过id查询") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name = "id", required = true) String id) { + ServerInfo serverInfo = serverInfoService.getById(id); + return Result.OK(serverInfo); + } + + /** + * 导出excel + * + * @param request + * @param serverInfo + */ + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, ServerInfo serverInfo) { + return super.exportXls(request, serverInfo, ServerInfo.class, "服务器信息"); + } + + /** + * 通过excel导入数据 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) + public Result importExcel(HttpServletRequest request, HttpServletResponse response) { + return super.importExcel(request, response, ServerInfo.class); + } + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/entity/ServerInfo.java b/src/main/java/cc/niushuai/bastionserver/modules/server/entity/ServerInfo.java new file mode 100644 index 0000000..d35b62c --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/entity/ServerInfo.java @@ -0,0 +1,88 @@ +package cc.niushuai.bastionserver.modules.server.entity; + +import cc.niushuai.bastionserver.common.base.entity.BaseEntity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * 服务器信息 + * + * @author: niushuai233 + * @date: 2023-01-03 16:20:46 + */ +@Data +@TableName("bas_server_info") +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "bas_server_info对象", description = "服务器信息") +public class ServerInfo extends BaseEntity { + + /** + * 企业id + */ + @Excel(name = "企业id", width = 15) + @ApiModelProperty(value = "企业id") + private String tenantId; + /** + * 服务器名称 + */ + @Excel(name = "服务器名称", width = 15) + @ApiModelProperty(value = "服务器名称") + private String name; + /** + * ip或域名 + */ + @Excel(name = "ip或域名", width = 15) + @ApiModelProperty(value = "ip或域名") + private String ip; + /** + * ssh端口号 1-65535 + */ + @Excel(name = "ssh端口号 1-65535", width = 15) + @ApiModelProperty(value = "ssh端口号 1-65535") + private Integer port; + /** + * 用户名 加密 + */ + @Excel(name = "用户名 加密", width = 15) + @ApiModelProperty(value = "用户名 加密") + private String user; + /** + * 密码 加密 + */ + @Excel(name = "密码 加密", width = 15) + @ApiModelProperty(value = "密码 加密") + private String password; + /** + * 备注 + */ + @Excel(name = "备注", width = 15) + @ApiModelProperty(value = "备注") + private String remark; + + /** + * 状态 0禁用 1启用 + */ + @Excel(name = "状态", width = 15) + @ApiModelProperty(value = "状态") + private Integer status; + + /** + * 是否删除 0否 1是 默认否 + */ + @ApiModelProperty(value = "是否删除 0否 1是 默认否") + @TableLogic + private Integer deleted; +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/ServerInfoMapper.java b/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/ServerInfoMapper.java new file mode 100644 index 0000000..e3584f5 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/ServerInfoMapper.java @@ -0,0 +1,14 @@ +package cc.niushuai.bastionserver.modules.server.mapper; + +import cc.niushuai.bastionserver.modules.server.entity.ServerInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 服务器信息 + * + * @author: niushuai233 + * @date: 2023-01-03 16:20:46 + */ +public interface ServerInfoMapper extends BaseMapper { + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/xml/ServerInfoMapper.xml b/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/xml/ServerInfoMapper.xml new file mode 100644 index 0000000..4321599 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/mapper/xml/ServerInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/service/ServerInfoService.java b/src/main/java/cc/niushuai/bastionserver/modules/server/service/ServerInfoService.java new file mode 100644 index 0000000..990f9ef --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/service/ServerInfoService.java @@ -0,0 +1,14 @@ +package cc.niushuai.bastionserver.modules.server.service; + +import cc.niushuai.bastionserver.common.base.service.BaseService; +import cc.niushuai.bastionserver.modules.server.entity.ServerInfo; + +/** + * 服务器信息 + * + * @author: niushuai233 + * @date: 2023-01-03 16:20:46 + */ +public interface ServerInfoService extends BaseService { + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/server/service/impl/ServerInfoServiceImpl.java b/src/main/java/cc/niushuai/bastionserver/modules/server/service/impl/ServerInfoServiceImpl.java new file mode 100644 index 0000000..2e245fa --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/server/service/impl/ServerInfoServiceImpl.java @@ -0,0 +1,20 @@ +package cc.niushuai.bastionserver.modules.server.service.impl; + +import cc.niushuai.bastionserver.common.base.service.impl.BaseServiceImpl; +import cc.niushuai.bastionserver.modules.server.entity.ServerInfo; +import cc.niushuai.bastionserver.modules.server.mapper.ServerInfoMapper; +import cc.niushuai.bastionserver.modules.server.service.ServerInfoService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * 服务器信息 + * + * @author: niushuai233 + * @date: 2023-01-03 16:20:46 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class ServerInfoServiceImpl extends BaseServiceImpl implements ServerInfoService { + +}