交换机-交换端口级联更新

This commit is contained in:
tangpeng 2019-06-14 10:51:18 +08:00
parent defc83aedb
commit 3fc72d6842
8 changed files with 704 additions and 605 deletions

View File

@ -1,85 +1,87 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增交换机模板')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-tmplSwitch-add">
<div class="form-group">
<label class="col-sm-3 control-label">交换机品牌:</label>
<div class="col-sm-8">
<input id="switchBrand" name="switchBrand" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机型号:</label>
<div class="col-sm-8">
<input id="switchType" name="switchType" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" class="form-control" type="text">
</div>
</div>
<div class="form-group" th:with="type=${@dict.getType('dict_port_type')}">
<div class="col-sm-6" th:each="dict : ${type}">
<div class="col-md-12">
<div class="form-group">
<label class="col-sm-3 control-label" th:text="${dict.dictLabel}"></label>
<div class="col-sm-9">
<input type="number" value="" th:name="${dict.dictCode}" class="form-control switchPort"
placeholder="单位(个)">
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
var prefix = ctx + "template/tmplSwitch"
$("#form-tmplSwitch-add").validate({
onkeyup: false,
rules: {
switchBrand: {
required: true,
minlength: 2,
maxlength: 20
},
switchType: {
required: true,
minlength: 2,
maxlength: 20
},
powerNum: {
required: true,
minlength: 1,
maxlength: 2
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $('#form-tmplSwitch-add').serializeArray();
var params = [];
$(".switchPort").each(function () {
params.push({"id": $(this).attr("name"), "value": $(this).val()});
});
var obj = {
"name": "foreignKeyInfo",
"value": JSON.stringify(params)
};
data.push(obj);
$.operate.save(prefix + "/add", data);
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增交换机模板')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-tmplSwitch-add">
<div class="form-group">
<label class="col-sm-3 control-label">交换机品牌:</label>
<div class="col-sm-8">
<input id="switchBrand" name="switchBrand" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机型号:</label>
<div class="col-sm-8">
<input id="switchType" name="switchType" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" class="form-control" type="text">
</div>
</div>
<!--端口类型字典-->
<div class="form-group" th:with="type=${@dict.getType('dict_port_type')}">
<div class="col-sm-6" th:each="dict : ${type}">
<div class="col-md-12">
<div class="form-group">
<label class="col-sm-6 control-label" th:text="${dict.dictLabel}"></label>
<div class="col-sm-5">
<input type="number" min="0" max="100" th:id="${dict.dictCode}"
class="form-control switchPort"
placeholder="单位(个)">
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
var prefix = ctx + "template/tmplSwitch"
$("#form-tmplSwitch-add").validate({
onkeyup: false,
rules: {
switchBrand: {
required: true,
minlength: 2,
maxlength: 20
},
switchType: {
required: true,
minlength: 2,
maxlength: 20
},
powerNum: {
required: true,
minlength: 1,
maxlength: 2
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $('#form-tmplSwitch-add').serializeArray();
var params = [];
$(".switchPort").each(function () {
params.push({"id": $(this).attr("id"), "value": $(this).val()});
});
var obj = {
"name": "foreignKeyInfo",
"value": JSON.stringify(params)
};
data.push(obj);
$.operate.save(prefix + "/add", data);
}
}
</script>
</body>
</html>

View File

@ -1,62 +1,98 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改交换机模板')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-tmplSwitch-edit" th:object="${tmplSwitch}">
<input id="switchId" name="switchId" th:field="*{switchId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label">交换机品牌:</label>
<div class="col-sm-8">
<input id="switchBrand" name="switchBrand" th:field="*{switchBrand}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机型号:</label>
<div class="col-sm-8">
<input id="switchType" name="switchType" th:field="*{switchType}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" th:field="*{powerNum}" class="form-control" type="text">
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
var prefix = ctx + "template/tmplSwitch";
$("#form-tmplSwitch-edit").validate({
onkeyup: false,
rules: {
switchBrand: {
required: true,
minlength: 2,
maxlength: 20
},
switchType: {
required: true,
minlength: 2,
maxlength: 20
},
powerNum: {
required: true,
minlength: 1,
maxlength: 2
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-tmplSwitch-edit').serialize());
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('修改交换机模板')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-tmplSwitch-edit" th:object="${tmplSwitch}">
<input id="switchId" name="switchId" th:field="*{switchId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label">交换机品牌:</label>
<div class="col-sm-8">
<input id="switchBrand" name="switchBrand" th:field="*{switchBrand}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机型号:</label>
<div class="col-sm-8">
<input id="switchType" name="switchType" th:field="*{switchType}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">交换机电源数量:</label>
<div class="col-sm-8">
<input id="powerNum" name="powerNum" th:field="*{powerNum}" class="form-control" type="text">
</div>
</div>
<!--端口类型字典-->
<div class="form-group" th:with="type=${@dict.getType('dict_port_type')}">
<div class="col-sm-6" th:each="dict : ${type}">
<div class="col-md-12">
<div class="form-group">
<label class="col-sm-6 control-label" th:text="${dict.dictLabel}"></label>
<div class="col-sm-5">
<input type="number" min="0" max="100" th:id="${dict.dictCode}"
class="form-control switchPort"
placeholder="单位(个)">
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" th:inline="javascript">
var prefix = ctx + "template/tmplSwitch";
$("#form-tmplSwitch-edit").validate({
onkeyup: false,
rules: {
switchBrand: {
required: true,
minlength: 2,
maxlength: 20
},
switchType: {
required: true,
minlength: 2,
maxlength: 20
},
powerNum: {
required: true,
minlength: 1,
maxlength: 2
},
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $('#form-tmplSwitch-edit').serializeArray();
var params = [];
$(".switchPort").each(function () {
params.push({"id": $(this).attr("id"), "value": $(this).val()});
});
var obj = {
"name": "foreignKeyInfo",
"value": JSON.stringify(params)
};
data.push(obj);
$.operate.save(prefix + "/edit", data);
}
}
/*
* 修改时手动回显SwitchPortNum
*/
$(function () {
var switchPorts = [[${tmplSwitch}]].switchPorts;
$.each(switchPorts, function (index, port) {
$("#" + port.switchPortType).val(port.switchPortNum);
});
});
</script>
</body>
</html>

View File

@ -1,106 +1,129 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('交换机模板列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
交换机品牌:<input type="text" name="switchBrand"/>
</li>
<li>
交换机型号:<input type="text" name="switchType"/>
</li>
<li>
交换机电源数量:<input type="text" name="powerNum"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:tmplSwitch:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="template:tmplSwitch:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="template:tmplSwitch:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:tmplSwitch:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('template:tmplSwitch:edit')}]];
var removeFlag = [[${@permission.hasPermi('template:tmplSwitch:remove')}]];
var prefix = ctx + "template/tmplSwitch";
$(function() {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "交换机模板",
showExport: true,
columns: [{
checkbox: true
},
{
field : 'switchId',
title : '交换机模板编号',
visible: false
},
{
field : 'switchBrand',
title : '交换机品牌',
sortable: true
},
{
field : 'switchType',
title : '交换机型号',
sortable: true
},
{
field : 'powerNum',
title : '交换机电源数量',
sortable: true
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.switchId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.switchId + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
}]
};
$.table.init(options);
});
</script>
</body>
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('交换机模板列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
交换机品牌:<input type="text" name="switchBrand"/>
</li>
<li>
交换机型号:<input type="text" name="switchType"/>
</li>
<li>
交换机电源数量:<input type="text" name="powerNum"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:tmplSwitch:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
shiro:hasPermission="template:tmplSwitch:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
shiro:hasPermission="template:tmplSwitch:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:tmplSwitch:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('template:tmplSwitch:edit')}]];
var removeFlag = [[${@permission.hasPermi('template:tmplSwitch:remove')}]];
var prefix = ctx + "template/tmplSwitch";
$(function () {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "交换机模板",
showExport: true,
columns: [{
checkbox: true
},
{
field: 'switchId',
title: '交换机模板编号',
visible: false,
align: 'center'
},
{
field: 'switchBrand',
title: '交换机品牌',
sortable: true,
align: 'center'
},
{
field: 'switchType',
title: '交换机型号',
sortable: true,
align: 'center'
},
{
field: 'powerNum',
title: '交换机电源数量',
sortable: true,
align: 'center'
}
]
};
$.each([[${@dict.getType('dict_port_type')}]], function (index, dict) {
options.columns.push({
field: dict.dictCode,
title: dict.dictLabel+"(个)",
align: 'center',
formatter: function (value, row, index) {
$.each(row.switchPorts, function (index, switchPort) {
if (switchPort.switchPortType == dict.dictCode) {
value = switchPort.switchPortNum;
}
});
return value;
}
});
});
options.columns.push({
title: '操作',
align: 'center',
formatter: function (value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.switchId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.switchId + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
})
$.table.init(options);
});
</script>
</body>
</html>

View File

@ -4,10 +4,9 @@ import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* Entity基类

View File

@ -1,89 +1,91 @@
package com.ruoyi.template.domain;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.List;
/**
* 交换机模板表 tmpl_switch
*
* @author TP
* @date 2019-06-12
*/
public class TmplSwitch extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 交换机模板编号
*/
private Integer switchId;
/**
* 交换机品牌
*/
private String switchBrand;
/**
* 交换机型号
*/
private String switchType;
/**
* 交换机电源数量
*/
private Integer powerNum;
/**
* 交换机端口类型
*/
private List<TmplSwitchPort> switchPorts;
public void setSwitchId(Integer switchId) {
this.switchId = switchId;
}
public Integer getSwitchId() {
return switchId;
}
public void setSwitchBrand(String switchBrand) {
this.switchBrand = switchBrand;
}
public String getSwitchBrand() {
return switchBrand;
}
public void setSwitchType(String switchType) {
this.switchType = switchType;
}
public String getSwitchType() {
return switchType;
}
public void setPowerNum(Integer powerNum) {
this.powerNum = powerNum;
}
public Integer getPowerNum() {
return powerNum;
}
public List<TmplSwitchPort> getSwitchPorts() {
return switchPorts;
}
public void setSwitchPorts(List<TmplSwitchPort> switchPorts) {
this.switchPorts = switchPorts;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("switchId", getSwitchId())
.append("switchBrand", getSwitchBrand())
.append("switchType", getSwitchType())
.append("powerNum", getPowerNum())
.append("switchPorts", getSwitchPorts())
.toString();
}
}
package com.ruoyi.template.domain;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.List;
/**
* 交换机模板表 tmpl_switch
*
* @author TP
* @date 2019-06-12
*/
public class TmplSwitch extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 交换机模板编号
*/
private Integer switchId;
/**
* 交换机品牌
*/
private String switchBrand;
/**
* 交换机型号
*/
private String switchType;
/**
* 交换机电源数量
*/
private Integer powerNum;
/**
* 交换机端口类型
*/
private List<TmplSwitchPort> switchPorts;
public Integer getSwitchId() {
return switchId;
}
public void setSwitchId(Integer switchId) {
this.switchId = switchId;
}
public String getSwitchBrand() {
return switchBrand;
}
public void setSwitchBrand(String switchBrand) {
this.switchBrand = switchBrand;
}
public String getSwitchType() {
return switchType;
}
public void setSwitchType(String switchType) {
this.switchType = switchType;
}
public Integer getPowerNum() {
return powerNum;
}
public void setPowerNum(Integer powerNum) {
this.powerNum = powerNum;
}
public List<TmplSwitchPort> getSwitchPorts() {
return switchPorts;
}
public void setSwitchPorts(List<TmplSwitchPort> switchPorts) {
this.switchPorts = switchPorts;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("switchId", getSwitchId())
.append("switchBrand", getSwitchBrand())
.append("switchType", getSwitchType())
.append("powerNum", getPowerNum())
.append("switchPorts", getSwitchPorts())
.toString();
}
}

View File

@ -1,71 +1,88 @@
package com.ruoyi.template.mapper;
import com.ruoyi.template.domain.TmplSwitchPort;
import java.util.List;
/**
* 交换机端口类型 数据层
*
* @author TP
* @date 2019-06-12
*/
public interface TmplSwitchPortMapper
{
/**
* 查询交换机端口类型信息
*
* @param switchPortId 交换机端口类型ID
* @return 交换机端口类型信息
*/
public TmplSwitchPort selectTmplSwitchPortById(Integer switchPortId);
/**
* 查询交换机端口类型列表
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 交换机端口类型集合
*/
public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort);
/**
* 新增交换机端口类型
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 结果
*/
public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/**
* 修改交换机端口类型
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 结果
*/
public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/**
* 删除交换机端口类型
*
* @param switchPortId 交换机端口类型ID
* @return 结果
*/
public int deleteTmplSwitchPortById(Integer switchPortId);
/**
* 批量删除交换机端口类型
*
* @param switchPortIds 需要删除的数据ID
* @return 结果
*/
public int deleteTmplSwitchPortByIds(String[] switchPortIds);
/**
* 批量新增交换机端口信息
*
* @param tmplSwitchPortList 交换机端口列表
* @return 结果
*/
public int batchTmplSwitchPort(List<TmplSwitchPort> tmplSwitchPortList);
package com.ruoyi.template.mapper;
import com.ruoyi.template.domain.TmplSwitchPort;
import java.util.List;
/**
* 交换机端口类型 数据层
*
* @author TP
* @date 2019-06-12
*/
public interface TmplSwitchPortMapper {
/**
* 查询交换机端口类型信息
*
* @param switchPortId 交换机端口类型ID
* @return 交换机端口类型信息
*/
public TmplSwitchPort selectTmplSwitchPortById(Integer switchPortId);
/**
* * 查询交换机端口类型信息
*
* @param switchId 交换机ID
* @param switchPortType 交换机端口类型
* @return 交换机端口类型信息
*/
public TmplSwitchPort selectBySwitchIdAndPortType(Integer switchId, Integer switchPortType);
/**
* 查询交换机端口类型列表
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 交换机端口类型集合
*/
public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort);
/**
* 新增交换机端口类型
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 结果
*/
public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/**
* 修改交换机端口类型
*
* @param tmplSwitchPort 交换机端口类型信息
* @return 结果
*/
public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/**
* 删除交换机端口类型
*
* @param switchPortId 交换机端口类型ID
* @return 结果
*/
public int deleteTmplSwitchPortById(Integer switchPortId);
/**
* 通过交换机ID批量删除交换机端口类型
*
* @param switchId 交换机ID
* @return 结果
*/
public int deleteTmplSwitchPortBySwitchId(Integer switchId);
/**
* 批量删除交换机端口类型
*
* @param switchPortIds 需要删除的数据ID
* @return 结果
*/
public int deleteTmplSwitchPortByIds(String[] switchPortIds);
/**
* 批量新增交换机端口信息
*
* @param tmplSwitchPortList 交换机端口列表
* @return 结果
*/
public int batchTmplSwitchPort(List<TmplSwitchPort> tmplSwitchPortList);
}

View File

@ -1,116 +1,125 @@
package com.ruoyi.template.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.template.domain.TmplSwitch;
import com.ruoyi.template.domain.TmplSwitchPort;
import com.ruoyi.template.mapper.TmplSwitchMapper;
import com.ruoyi.template.mapper.TmplSwitchPortMapper;
import com.ruoyi.template.service.ITmplSwitchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* 交换机模板 服务层实现
*
* @author TP
* @date 2019-06-12
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class TmplSwitchServiceImpl implements ITmplSwitchService {
@Autowired
private TmplSwitchMapper tmplSwitchMapper;
@Autowired
private TmplSwitchPortMapper tmplSwitchPortMapper;
@Autowired
private SysDictDataMapper sysDictDataMapper;
/**
* 查询交换机模板信息
*
* @param switchId 交换机模板ID
* @return 交换机模板信息
*/
@Override
public TmplSwitch selectTmplSwitchById(Integer switchId) {
return tmplSwitchMapper.selectTmplSwitchById(switchId);
}
/**
* 查询交换机模板列表
*
* @param tmplSwitch 交换机模板信息
* @return 交换机模板集合
*/
@Override
public List<TmplSwitch> selectTmplSwitchList(TmplSwitch tmplSwitch) {
return tmplSwitchMapper.selectTmplSwitchList(tmplSwitch);
}
/**
* 新增交换机模板
*
* @param tmplSwitch 交换机模板信息
* @return 结果
*/
@Override
public int insertTmplSwitch(TmplSwitch tmplSwitch) {
JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo());
int affectRow = tmplSwitchMapper.insertTmplSwitch(tmplSwitch);
if (affectRow > 0) {
List<TmplSwitchPort> list = new ArrayList<>();
jsonArray.forEach((i) -> {
JSONObject jsonObject = (JSONObject) i;
String valueStr = jsonObject.getString("value");
int num = 0;
if (StringUtils.isNotBlank(valueStr) && (num = Convert.toInt(valueStr)) > 0) {
SysDictData dictData = sysDictDataMapper
.selectDictDataById(Convert.toLong(jsonObject.getString("id")));
TmplSwitchPort tmplSwitchPort = new TmplSwitchPort();
tmplSwitchPort.setSwitchId(tmplSwitch.getSwitchId());
tmplSwitchPort.setSwitchPortType(Convert.toInt(dictData.getDictCode()));
tmplSwitchPort.setSwitchPortNum(num);
list.add(tmplSwitchPort);
}
});
int switchPorts = list.size() > 0 ? tmplSwitchPortMapper.batchTmplSwitchPort(list) : 0;
if (switchPorts == 0) {
throw new BusinessException("至少输入一个端口数量");
}
}
return affectRow;
}
/**
* 修改交换机模板
*
* @param tmplSwitch 交换机模板信息
* @return 结果
*/
@Override
public int updateTmplSwitch(TmplSwitch tmplSwitch) {
return tmplSwitchMapper.updateTmplSwitch(tmplSwitch);
}
/**
* 删除交换机模板对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteTmplSwitchByIds(String ids) {
return tmplSwitchMapper.deleteTmplSwitchByIds(Convert.toStrArray(ids));
}
}
package com.ruoyi.template.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.template.domain.TmplSwitch;
import com.ruoyi.template.domain.TmplSwitchPort;
import com.ruoyi.template.mapper.TmplSwitchMapper;
import com.ruoyi.template.mapper.TmplSwitchPortMapper;
import com.ruoyi.template.service.ITmplSwitchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* 交换机模板 服务层实现
*
* @author TP
* @date 2019-06-12
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class TmplSwitchServiceImpl implements ITmplSwitchService {
@Autowired
private TmplSwitchMapper tmplSwitchMapper;
@Autowired
private TmplSwitchPortMapper tmplSwitchPortMapper;
@Autowired
private SysDictDataMapper sysDictDataMapper;
/**
* 查询交换机模板信息
*
* @param switchId 交换机模板ID
* @return 交换机模板信息
*/
@Override
public TmplSwitch selectTmplSwitchById(Integer switchId) {
return tmplSwitchMapper.selectTmplSwitchById(switchId);
}
/**
* 查询交换机模板列表
*
* @param tmplSwitch 交换机模板信息
* @return 交换机模板集合
*/
@Override
public List<TmplSwitch> selectTmplSwitchList(TmplSwitch tmplSwitch) {
return tmplSwitchMapper.selectTmplSwitchList(tmplSwitch);
}
/**
* 新增交换机模板
*
* @param tmplSwitch 交换机模板信息
* @return 结果
*/
@Override
public int insertTmplSwitch(TmplSwitch tmplSwitch) {
return saveOrUpdate(tmplSwitch);
}
private int saveOrUpdate(TmplSwitch tmplSwitch) {
JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo());
int affectRow = tmplSwitchMapper.selectTmplSwitchById(tmplSwitch.getSwitchId()) != null
? tmplSwitchMapper.updateTmplSwitch(tmplSwitch)
: tmplSwitchMapper.insertTmplSwitch(tmplSwitch);
if (affectRow > 0) {
List<TmplSwitchPort> list = new ArrayList<>();
jsonArray.forEach((i) -> {
JSONObject jsonObject = (JSONObject) i;
String valueStr = jsonObject.getString("value");
int num = 0;
if (StringUtils.isNotBlank(valueStr) && (num = Convert.toInt(valueStr)) > 0) {
SysDictData dictData = sysDictDataMapper
.selectDictDataById(Convert.toLong(jsonObject.getString("id")));
TmplSwitchPort tmplSwitchPort = new TmplSwitchPort();
tmplSwitchPort.setSwitchId(tmplSwitch.getSwitchId());
tmplSwitchPort.setSwitchPortType(Convert.toInt(dictData.getDictCode()));
tmplSwitchPort.setSwitchPortNum(num);
list.add(tmplSwitchPort);
}
});
int switchPorts = list.size() > 0 ? tmplSwitchPortMapper.batchTmplSwitchPort(list) : 0;
if (switchPorts == 0) {
throw new BusinessException("至少输入一个端口数量");
}
}
return affectRow;
}
/**
* 修改交换机模板
*
* @param tmplSwitch 交换机模板信息
* @return 更新后数据库中存在的值个数
*/
@Override
public int updateTmplSwitch(TmplSwitch tmplSwitch) {
//1.清空数据库中已存的值
tmplSwitchPortMapper.deleteTmplSwitchPortBySwitchId(tmplSwitch.getSwitchId());
//2.更新主表
return insertTmplSwitch(tmplSwitch);
}
/**
* 删除交换机模板对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteTmplSwitchByIds(String ids) {
return tmplSwitchMapper.deleteTmplSwitchByIds(Convert.toStrArray(ids));
}
}

View File

@ -1,77 +1,88 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper">
<resultMap type="TmplSwitchPort" id="TmplSwitchPortResult">
<result property="switchPortId" column="switch_port_id"/>
<result property="switchId" column="switch_id"/>
<result property="switchPortType" column="switch_port_type"/>
<result property="switchPortNum" column="switch_port_num"/>
</resultMap>
<sql id="selectTmplSwitchPortVo">
select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port
</sql>
<select id="selectTmplSwitchPortList" parameterType="TmplSwitchPort" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/>
<where>
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if>
<if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
<if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if>
</where>
</select>
<select id="selectTmplSwitchPortById" parameterType="Integer" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/>
where switch_port_id = #{switchPortId}
</select>
<insert id="insertTmplSwitchPort" parameterType="TmplSwitchPort">
insert into tmpl_switch_port
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="switchPortId != null ">switch_port_id,</if>
<if test="switchId != null ">switch_id,</if>
<if test="switchPortType != null ">switch_port_type,</if>
<if test="switchPortNum != null ">switch_port_num,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="switchPortId != null ">#{switchPortId},</if>
<if test="switchId != null ">#{switchId},</if>
<if test="switchPortType != null ">#{switchPortType},</if>
<if test="switchPortNum != null ">#{switchPortNum},</if>
</trim>
</insert>
<update id="updateTmplSwitchPort" parameterType="TmplSwitchPort">
update tmpl_switch_port
<trim prefix="SET" suffixOverrides=",">
<if test="switchId != null ">switch_id = #{switchId},</if>
<if test="switchPortType != null ">switch_port_type = #{switchPortType},</if>
<if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if>
</trim>
where switch_port_id = #{switchPortId}
</update>
<delete id="deleteTmplSwitchPortById" parameterType="Integer">
delete from tmpl_switch_port where switch_port_id = #{switchPortId}
</delete>
<delete id="deleteTmplSwitchPortByIds" parameterType="String">
delete from tmpl_switch_port where switch_port_id in
<foreach item="switchPortId" collection="array" open="(" separator="," close=")">
#{switchPortId}
</foreach>
</delete>
<insert id="batchTmplSwitchPort">
insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.switchId},#{item.switchPortType},#{item.switchPortNum})
</foreach>
</insert>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper">
<resultMap type="TmplSwitchPort" id="TmplSwitchPortResult">
<result property="switchPortId" column="switch_port_id"/>
<result property="switchId" column="switch_id"/>
<result property="switchPortType" column="switch_port_type"/>
<result property="switchPortNum" column="switch_port_num"/>
</resultMap>
<sql id="selectTmplSwitchPortVo">
select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port
</sql>
<select id="selectTmplSwitchPortList" parameterType="TmplSwitchPort" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/>
<where>
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if>
<if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
<if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if>
</where>
</select>
<select id="selectTmplSwitchPortById" parameterType="Integer" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/>
where switch_port_id = #{switchPortId}
</select>
<select id="selectBySwitchIdAndPortType" parameterType="Integer" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/>
where switch_id = #{switchPortId}
and switch_port_type = #{switchPortType}
</select>
<insert id="insertTmplSwitchPort" parameterType="TmplSwitchPort">
insert into tmpl_switch_port
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="switchPortId != null ">switch_port_id,</if>
<if test="switchId != null ">switch_id,</if>
<if test="switchPortType != null ">switch_port_type,</if>
<if test="switchPortNum != null ">switch_port_num,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="switchPortId != null ">#{switchPortId},</if>
<if test="switchId != null ">#{switchId},</if>
<if test="switchPortType != null ">#{switchPortType},</if>
<if test="switchPortNum != null ">#{switchPortNum},</if>
</trim>
</insert>
<insert id="batchTmplSwitchPort">
insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.switchId},#{item.switchPortType},#{item.switchPortNum})
</foreach>
</insert>
<update id="updateTmplSwitchPort" parameterType="TmplSwitchPort">
update tmpl_switch_port
<trim prefix="SET" suffixOverrides=",">
<if test="switchId != null ">switch_id = #{switchId},</if>
<if test="switchPortType != null ">switch_port_type = #{switchPortType},</if>
<if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if>
</trim>
where switch_port_id = #{switchPortId}
</update>
<delete id="deleteTmplSwitchPortById" parameterType="Integer">
delete from tmpl_switch_port where switch_port_id = #{switchPortId}
</delete>
<delete id="deleteTmplSwitchPortBySwitchId" parameterType="Integer">
delete from tmpl_switch_port where switch_id = #{switchId}
</delete>
<delete id="deleteTmplSwitchPortByIds" parameterType="String">
delete from tmpl_switch_port where switch_port_id in
<foreach item="switchPortId" collection="array" open="(" separator="," close=")">
#{switchPortId}
</foreach>
</delete>
</mapper>