7 changed files with 346 additions and 0 deletions
			
			
		| @ -0,0 +1,38 @@@@ -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; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -0,0 +1,179 @@@@ -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<TunnelInfo, TunnelInfoService> { | ||||
| 
 | ||||
|     @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<TunnelInfo> queryWrapper = QueryGenerator.initQueryWrapper(tunnelInfo, req.getParameterMap()); | ||||
|         Page<TunnelInfo> page = new Page<TunnelInfo>(pageNo, pageSize); | ||||
|         IPage<TunnelInfo> pageList = service.page(page, queryWrapper); | ||||
| 
 | ||||
|         fillServerInfo(pageList.getRecords()); | ||||
| 
 | ||||
|         return Result.OK(pageList); | ||||
|     } | ||||
| 
 | ||||
|     private void fillServerInfo(List<TunnelInfo> records) { | ||||
|         if (CollUtil.isNotEmpty(records)) { | ||||
|             // 列表并组装map
 | ||||
|             Map<String, String> serverMap = serverInfoService | ||||
|                     .list(new LambdaQueryWrapper<ServerInfo>().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); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,76 @@@@ -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; | ||||
| } | ||||
| @ -0,0 +1,14 @@@@ -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<TunnelInfo> { | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,5 @@@@ -0,0 +1,5 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="cc.niushuai.bastionserver.modules.tunnel.mapper.TunnelInfoMapper"> | ||||
| 
 | ||||
| </mapper> | ||||
| @ -0,0 +1,14 @@@@ -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<TunnelInfo> { | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,20 @@@@ -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<TunnelInfoMapper, TunnelInfo> implements TunnelInfoService { | ||||
| 
 | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue