From 33e5346e4e96368e1972553c710193a79d8f7fe6 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 4 Jan 2023 11:47:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9A=A7=E9=81=93=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/enums/NumEnum.java | 38 ++++ .../controller/TunnelInfoController.java | 179 ++++++++++++++++++ .../modules/tunnel/entity/TunnelInfo.java | 76 ++++++++ .../tunnel/mapper/TunnelInfoMapper.java | 14 ++ .../tunnel/mapper/xml/TunnelInfoMapper.xml | 5 + .../tunnel/service/TunnelInfoService.java | 14 ++ .../service/impl/TunnelInfoServiceImpl.java | 20 ++ 7 files changed, 346 insertions(+) create mode 100644 src/main/java/cc/niushuai/bastionserver/common/constant/enums/NumEnum.java create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/controller/TunnelInfoController.java create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/entity/TunnelInfo.java create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/TunnelInfoMapper.java create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/xml/TunnelInfoMapper.xml create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/TunnelInfoService.java create mode 100644 src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/impl/TunnelInfoServiceImpl.java diff --git a/src/main/java/cc/niushuai/bastionserver/common/constant/enums/NumEnum.java b/src/main/java/cc/niushuai/bastionserver/common/constant/enums/NumEnum.java new file mode 100644 index 0000000..7850ecd --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/common/constant/enums/NumEnum.java @@ -0,0 +1,38 @@ +package cc.niushuai.bastionserver.common.constant.enums; + +/** + * 0-9 枚举 + * + * @author niushuai233 + * @date 2023/1/4 11:43 + */ +public enum NumEnum { + ZERO(0, "0"), + ONE(1, "1"), + TWO(2, "2"), + THREE(3, "3"), + FOUR(4, "4"), + FIVE(5, "5"), + SIX(6, "6"), + SEVEN(7, "7"), + EIGHT(8, "8"), + NINE(9, "9"), + ; + + private Integer iCode; + private String sCode; + + NumEnum(Integer iCode, String sCode) { + this.iCode = iCode; + this.sCode = sCode; + } + + public Integer getICode() { + return iCode; + } + + public String getSCode() { + return sCode; + } +} + diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/controller/TunnelInfoController.java b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/controller/TunnelInfoController.java new file mode 100644 index 0000000..15b5ec1 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/controller/TunnelInfoController.java @@ -0,0 +1,179 @@ +package cc.niushuai.bastionserver.modules.tunnel.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.constant.enums.NumEnum; +import cc.niushuai.bastionserver.common.system.query.QueryGenerator; +import cc.niushuai.bastionserver.modules.tunnel.entity.ServerInfo; +import cc.niushuai.bastionserver.modules.tunnel.entity.TunnelInfo; +import cc.niushuai.bastionserver.modules.tunnel.service.ServerInfoService; +import cc.niushuai.bastionserver.modules.tunnel.service.TunnelInfoService; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 隧道信息 + * + * @author: niushuai233 + * @date: 2023-01-04 10:20:26 + */ +@Slf4j +@Api(tags = "隧道信息") +@RestController +@RequestMapping("/tunnel/tunnelInfo") +public class TunnelInfoController extends BaseController { + + @Resource + private ServerInfoService serverInfoService; + + /** + * 分页列表查询 + * + * @param tunnelInfo + * @param pageNo + * @param pageSize + * @param req + * @return + */ + @AutoLog(value = "隧道信息-分页列表查询") + @ApiOperation(value = "隧道信息-分页列表查询", notes = "隧道信息-分页列表查询") + @GetMapping(value = "/page") + public Result queryPageList(TunnelInfo tunnelInfo, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(tunnelInfo, req.getParameterMap()); + Page page = new Page(pageNo, pageSize); + IPage pageList = service.page(page, queryWrapper); + + fillServerInfo(pageList.getRecords()); + + return Result.OK(pageList); + } + + private void fillServerInfo(List records) { + if (CollUtil.isNotEmpty(records)) { + // 列表并组装map + Map serverMap = serverInfoService + .list(new LambdaQueryWrapper().eq(ServerInfo::getStatus, NumEnum.ZERO.getICode())) + .stream().collect(Collectors.toMap(ServerInfo::getId, ServerInfo::getName)); + for (TunnelInfo record : records) { + // 赋值 + record.setServerName(serverMap.get(record.getServerId())); + } + } + } + + /** + * 添加 + * + * @param tunnelInfo + * @return + */ + @AutoLog(value = "隧道信息-添加") + @ApiOperation(value = "隧道信息-添加", notes = "隧道信息-添加") + @PostMapping(value = "/add") + public Result add(@RequestBody TunnelInfo tunnelInfo) { + exists(tunnelInfo, TunnelInfo::getServerId, TunnelInfo::getRemotePort); + service.save(tunnelInfo); + return Result.OK("添加成功!"); + } + + /** + * 编辑 + * + * @param tunnelInfo + * @return + */ + @AutoLog(value = "隧道信息-编辑") + @ApiOperation(value = "隧道信息-编辑", notes = "隧道信息-编辑") + @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result edit(@RequestBody TunnelInfo tunnelInfo) { + exists(TunnelInfo::getId, tunnelInfo, TunnelInfo::getServerId, TunnelInfo::getRemotePort); + service.updateById(tunnelInfo); + 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) { + service.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.service.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) { + TunnelInfo tunnelInfo = service.getById(id); + return Result.OK(tunnelInfo); + } + + /** + * 导出excel + * + * @param request + * @param tunnelInfo + */ + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, TunnelInfo tunnelInfo) { + return super.exportXls(request, tunnelInfo, TunnelInfo.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, TunnelInfo.class); + } + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/entity/TunnelInfo.java b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/entity/TunnelInfo.java new file mode 100644 index 0000000..d889926 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/entity/TunnelInfo.java @@ -0,0 +1,76 @@ +package cc.niushuai.bastionserver.modules.tunnel.entity; + +import cc.niushuai.bastionserver.common.base.entity.BaseEntity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +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; + +/** + * 隧道信息 + * + * @author: niushuai233 + * @date: 2023-01-04 10:20:26 + */ +@Data +@TableName("bas_tunnel_info") +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "bas_tunnel_info对象", description = "隧道信息") +public class TunnelInfo extends BaseEntity { + + /** + * 关联服务器id + */ + @Excel(name = "关联服务器id", width = 15) + @ApiModelProperty(value = "关联服务器id") + private String serverId; + + /** + * 服务器名称 + */ + @ApiModelProperty(value = "服务器名称") + @TableField(exist = false) + private String serverName; + + /** + * 隧道名称 + */ + @Excel(name = "隧道名称", width = 15) + @ApiModelProperty(value = "隧道名称") + private String name; + /** + * 本地端口 + */ + @Excel(name = "本地端口", width = 15) + @ApiModelProperty(value = "本地端口") + private Integer localPort; + /** + * 远程端口 + */ + @Excel(name = "远程端口", width = 15) + @ApiModelProperty(value = "远程端口") + private Integer remotePort; + /** + * 状态 0禁用 1启用 + */ + @Excel(name = "状态 0禁用 1启用 ", width = 15) + @ApiModelProperty(value = "状态 0禁用 1启用 ") + private Integer status; + /** + * 备注 + */ + @Excel(name = "备注", width = 15) + @ApiModelProperty(value = "备注") + private String remark; + /** + * 是否删除 0否 1是 默认否 + */ + @Excel(name = "是否删除 0否 1是 默认否", width = 15) + @ApiModelProperty(value = "是否删除 0否 1是 默认否") + private Integer deleted; +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/TunnelInfoMapper.java b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/TunnelInfoMapper.java new file mode 100644 index 0000000..a5b5352 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/TunnelInfoMapper.java @@ -0,0 +1,14 @@ +package cc.niushuai.bastionserver.modules.tunnel.mapper; + +import cc.niushuai.bastionserver.modules.tunnel.entity.TunnelInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 隧道信息 + * + * @author: niushuai233 + * @date: 2023-01-04 10:20:26 + */ +public interface TunnelInfoMapper extends BaseMapper { + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/xml/TunnelInfoMapper.xml b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/xml/TunnelInfoMapper.xml new file mode 100644 index 0000000..9008918 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/mapper/xml/TunnelInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/TunnelInfoService.java b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/TunnelInfoService.java new file mode 100644 index 0000000..39aeff5 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/TunnelInfoService.java @@ -0,0 +1,14 @@ +package cc.niushuai.bastionserver.modules.tunnel.service; + +import cc.niushuai.bastionserver.common.base.service.BaseService; +import cc.niushuai.bastionserver.modules.tunnel.entity.TunnelInfo; + +/** + * 隧道信息 + * + * @author: niushuai233 + * @date: 2023-01-04 10:20:26 + */ +public interface TunnelInfoService extends BaseService { + +} diff --git a/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/impl/TunnelInfoServiceImpl.java b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/impl/TunnelInfoServiceImpl.java new file mode 100644 index 0000000..7c9c6c7 --- /dev/null +++ b/src/main/java/cc/niushuai/bastionserver/modules/tunnel/service/impl/TunnelInfoServiceImpl.java @@ -0,0 +1,20 @@ +package cc.niushuai.bastionserver.modules.tunnel.service.impl; + +import cc.niushuai.bastionserver.common.base.service.impl.BaseServiceImpl; +import cc.niushuai.bastionserver.modules.tunnel.entity.TunnelInfo; +import cc.niushuai.bastionserver.modules.tunnel.mapper.TunnelInfoMapper; +import cc.niushuai.bastionserver.modules.tunnel.service.TunnelInfoService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * 隧道信息 + * + * @author: niushuai233 + * @date: 2023-01-04 10:20:26 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class TunnelInfoServiceImpl extends BaseServiceImpl implements TunnelInfoService { + +}