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

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

View File

@ -1,62 +1,98 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > <html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head> <head>
<th:block th:include="include :: header('修改交换机模板')" /> <th:block th:include="include :: header('修改交换机模板')"/>
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-tmplSwitch-edit" th:object="${tmplSwitch}"> <form class="form-horizontal m" id="form-tmplSwitch-edit" th:object="${tmplSwitch}">
<input id="switchId" name="switchId" th:field="*{switchId}" type="hidden"> <input id="switchId" name="switchId" th:field="*{switchId}" type="hidden">
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">交换机品牌:</label> <label class="col-sm-3 control-label">交换机品牌:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="switchBrand" name="switchBrand" th:field="*{switchBrand}" class="form-control" type="text"> <input id="switchBrand" name="switchBrand" th:field="*{switchBrand}" class="form-control" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">交换机型号:</label> <label class="col-sm-3 control-label">交换机型号:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="switchType" name="switchType" th:field="*{switchType}" class="form-control" type="text"> <input id="switchType" name="switchType" th:field="*{switchType}" class="form-control" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">交换机电源数量:</label> <label class="col-sm-3 control-label">交换机电源数量:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="powerNum" name="powerNum" th:field="*{powerNum}" class="form-control" type="text"> <input id="powerNum" name="powerNum" th:field="*{powerNum}" class="form-control" type="text">
</div> </div>
</div> </div>
</form> <!--端口类型字典-->
</div> <div class="form-group" th:with="type=${@dict.getType('dict_port_type')}">
<div th:include="include::footer"></div> <div class="col-sm-6" th:each="dict : ${type}">
<script type="text/javascript"> <div class="col-md-12">
var prefix = ctx + "template/tmplSwitch"; <div class="form-group">
$("#form-tmplSwitch-edit").validate({ <label class="col-sm-6 control-label" th:text="${dict.dictLabel}"></label>
onkeyup: false, <div class="col-sm-5">
rules: { <input type="number" min="0" max="100" th:id="${dict.dictCode}"
switchBrand: { class="form-control switchPort"
required: true, placeholder="单位(个)">
minlength: 2, </div>
maxlength: 20 </div>
}, </div>
switchType: { </div>
required: true, </div>
minlength: 2,
maxlength: 20 </form>
}, </div>
powerNum: { <div th:include="include::footer"></div>
required: true, <script type="text/javascript" th:inline="javascript">
minlength: 1, var prefix = ctx + "template/tmplSwitch";
maxlength: 2 $("#form-tmplSwitch-edit").validate({
}, onkeyup: false,
}, rules: {
focusCleanup: true switchBrand: {
}); required: true,
minlength: 2,
function submitHandler() { maxlength: 20
if ($.validate.form()) { },
$.operate.save(prefix + "/edit", $('#form-tmplSwitch-edit').serialize()); switchType: {
} required: true,
} minlength: 2,
</script> maxlength: 20
</body> },
</html> 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> <!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head> <head>
<th:block th:include="include :: header('交换机模板列表')" /> <th:block th:include="include :: header('交换机模板列表')"/>
</head> </head>
<body class="gray-bg"> <body class="gray-bg">
<div class="container-div"> <div class="container-div">
<div class="row"> <div class="row">
<div class="col-sm-12 search-collapse"> <div class="col-sm-12 search-collapse">
<form id="formId"> <form id="formId">
<div class="select-list"> <div class="select-list">
<ul> <ul>
<li> <li>
交换机品牌:<input type="text" name="switchBrand"/> 交换机品牌:<input type="text" name="switchBrand"/>
</li> </li>
<li> <li>
交换机型号:<input type="text" name="switchType"/> 交换机型号:<input type="text" name="switchType"/>
</li> </li>
<li> <li>
交换机电源数量:<input type="text" name="powerNum"/> 交换机电源数量:<input type="text" name="powerNum"/>
</li> </li>
<li>
<li> <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a> 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> <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
</li> class="fa fa-refresh"></i>&nbsp;重置</a>
</ul> </li>
</div> </ul>
</form> </div>
</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"> <div class="btn-group-sm" id="toolbar" role="group">
<i class="fa fa-plus"></i> 添加 <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:tmplSwitch:add">
</a> <i class="fa fa-plus"></i> 添加
<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="template:tmplSwitch:edit"> </a>
<i class="fa fa-edit"></i> 修改 <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
</a> shiro:hasPermission="template:tmplSwitch:edit">
<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="template:tmplSwitch:remove"> <i class="fa fa-edit"></i> 修改
<i class="fa fa-remove"></i> 删除 </a>
</a> <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:tmplSwitch:export"> shiro:hasPermission="template:tmplSwitch:remove">
<i class="fa fa-download"></i> 导出 <i class="fa fa-remove"></i> 删除
</a> </a>
</div> <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:tmplSwitch:export">
<div class="col-sm-12 select-table table-striped"> <i class="fa fa-download"></i> 导出
<table id="bootstrap-table" data-mobile-responsive="true"></table> </a>
</div> </div>
</div> <div class="col-sm-12 select-table table-striped">
</div> <table id="bootstrap-table" data-mobile-responsive="true"></table>
<div th:include="include :: footer"></div> </div>
<script th:inline="javascript"> </div>
var editFlag = [[${@permission.hasPermi('template:tmplSwitch:edit')}]]; </div>
var removeFlag = [[${@permission.hasPermi('template:tmplSwitch:remove')}]]; <div th:include="include :: footer"></div>
var prefix = ctx + "template/tmplSwitch"; <script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('template:tmplSwitch:edit')}]];
$(function() { var removeFlag = [[${@permission.hasPermi('template:tmplSwitch:remove')}]];
var options = { var prefix = ctx + "template/tmplSwitch";
url: prefix + "/list",
createUrl: prefix + "/add", $(function () {
updateUrl: prefix + "/edit/{id}", var options = {
removeUrl: prefix + "/remove", url: prefix + "/list",
exportUrl: prefix + "/export", createUrl: prefix + "/add",
modalName: "交换机模板", updateUrl: prefix + "/edit/{id}",
showExport: true, removeUrl: prefix + "/remove",
columns: [{ exportUrl: prefix + "/export",
checkbox: true modalName: "交换机模板",
}, showExport: true,
{ columns: [{
field : 'switchId', checkbox: true
title : '交换机模板编号', },
visible: false {
}, field: 'switchId',
{ title: '交换机模板编号',
field : 'switchBrand', visible: false,
title : '交换机品牌', align: 'center'
sortable: true },
}, {
{ field: 'switchBrand',
field : 'switchType', title: '交换机品牌',
title : '交换机型号', sortable: true,
sortable: true align: 'center'
}, },
{ {
field : 'powerNum', field: 'switchType',
title : '交换机电源数量', title: '交换机型号',
sortable: true sortable: true,
}, align: 'center'
{ },
title: '操作', {
align: 'center', field: 'powerNum',
formatter: function(value, row, index) { title: '交换机电源数量',
var actions = []; sortable: true,
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> '); align: 'center'
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(''); ]
} };
}] $.each([[${@dict.getType('dict_port_type')}]], function (index, dict) {
}; options.columns.push({
$.table.init(options); field: dict.dictCode,
}); title: dict.dictLabel+"(个)",
</script> align: 'center',
</body> 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> </html>

View File

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

View File

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

View File

@ -1,71 +1,88 @@
package com.ruoyi.template.mapper; package com.ruoyi.template.mapper;
import com.ruoyi.template.domain.TmplSwitchPort; import com.ruoyi.template.domain.TmplSwitchPort;
import java.util.List; import java.util.List;
/** /**
* 交换机端口类型 数据层 * 交换机端口类型 数据层
* *
* @author TP * @author TP
* @date 2019-06-12 * @date 2019-06-12
*/ */
public interface TmplSwitchPortMapper public interface TmplSwitchPortMapper {
{ /**
/** * 查询交换机端口类型信息
* 查询交换机端口类型信息 *
* * @param switchPortId 交换机端口类型ID
* @param switchPortId 交换机端口类型ID * @return 交换机端口类型信息
* @return 交换机端口类型信息 */
*/ public TmplSwitchPort selectTmplSwitchPortById(Integer switchPortId);
public TmplSwitchPort selectTmplSwitchPortById(Integer switchPortId);
/**
/** * * 查询交换机端口类型信息
* 查询交换机端口类型列表 *
* * @param switchId 交换机ID
* @param tmplSwitchPort 交换机端口类型信息 * @param switchPortType 交换机端口类型
* @return 交换机端口类型集合 * @return 交换机端口类型信息
*/ */
public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort); public TmplSwitchPort selectBySwitchIdAndPortType(Integer switchId, Integer switchPortType);
/** /**
* 新增交换机端口类型 * 查询交换机端口类型列表
* *
* @param tmplSwitchPort 交换机端口类型信息 * @param tmplSwitchPort 交换机端口类型信息
* @return 结果 * @return 交换机端口类型集合
*/ */
public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort); public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort);
/** /**
* 修改交换机端口类型 * 新增交换机端口类型
* *
* @param tmplSwitchPort 交换机端口类型信息 * @param tmplSwitchPort 交换机端口类型信息
* @return 结果 * @return 结果
*/ */
public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort); public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/** /**
* 删除交换机端口类型 * 修改交换机端口类型
* *
* @param switchPortId 交换机端口类型ID * @param tmplSwitchPort 交换机端口类型信息
* @return 结果 * @return 结果
*/ */
public int deleteTmplSwitchPortById(Integer switchPortId); public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/** /**
* 批量删除交换机端口类型 * 删除交换机端口类型
* *
* @param switchPortIds 需要删除的数据ID * @param switchPortId 交换机端口类型ID
* @return 结果 * @return 结果
*/ */
public int deleteTmplSwitchPortByIds(String[] switchPortIds); public int deleteTmplSwitchPortById(Integer switchPortId);
/**
* 批量新增交换机端口信息 /**
* * 通过交换机ID批量删除交换机端口类型
* @param tmplSwitchPortList 交换机端口列表 *
* @return 结果 * @param switchId 交换机ID
*/ * @return 结果
public int batchTmplSwitchPort(List<TmplSwitchPort> tmplSwitchPortList); */
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; package com.ruoyi.template.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.template.domain.TmplSwitch; import com.ruoyi.template.domain.TmplSwitch;
import com.ruoyi.template.domain.TmplSwitchPort; import com.ruoyi.template.domain.TmplSwitchPort;
import com.ruoyi.template.mapper.TmplSwitchMapper; import com.ruoyi.template.mapper.TmplSwitchMapper;
import com.ruoyi.template.mapper.TmplSwitchPortMapper; import com.ruoyi.template.mapper.TmplSwitchPortMapper;
import com.ruoyi.template.service.ITmplSwitchService; import com.ruoyi.template.service.ITmplSwitchService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 交换机模板 服务层实现 * 交换机模板 服务层实现
* *
* @author TP * @author TP
* @date 2019-06-12 * @date 2019-06-12
*/ */
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class TmplSwitchServiceImpl implements ITmplSwitchService { public class TmplSwitchServiceImpl implements ITmplSwitchService {
@Autowired @Autowired
private TmplSwitchMapper tmplSwitchMapper; private TmplSwitchMapper tmplSwitchMapper;
@Autowired @Autowired
private TmplSwitchPortMapper tmplSwitchPortMapper; private TmplSwitchPortMapper tmplSwitchPortMapper;
@Autowired @Autowired
private SysDictDataMapper sysDictDataMapper; private SysDictDataMapper sysDictDataMapper;
/** /**
* 查询交换机模板信息 * 查询交换机模板信息
* *
* @param switchId 交换机模板ID * @param switchId 交换机模板ID
* @return 交换机模板信息 * @return 交换机模板信息
*/ */
@Override @Override
public TmplSwitch selectTmplSwitchById(Integer switchId) { public TmplSwitch selectTmplSwitchById(Integer switchId) {
return tmplSwitchMapper.selectTmplSwitchById(switchId); return tmplSwitchMapper.selectTmplSwitchById(switchId);
} }
/** /**
* 查询交换机模板列表 * 查询交换机模板列表
* *
* @param tmplSwitch 交换机模板信息 * @param tmplSwitch 交换机模板信息
* @return 交换机模板集合 * @return 交换机模板集合
*/ */
@Override @Override
public List<TmplSwitch> selectTmplSwitchList(TmplSwitch tmplSwitch) { public List<TmplSwitch> selectTmplSwitchList(TmplSwitch tmplSwitch) {
return tmplSwitchMapper.selectTmplSwitchList(tmplSwitch); return tmplSwitchMapper.selectTmplSwitchList(tmplSwitch);
} }
/** /**
* 新增交换机模板 * 新增交换机模板
* *
* @param tmplSwitch 交换机模板信息 * @param tmplSwitch 交换机模板信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertTmplSwitch(TmplSwitch tmplSwitch) { public int insertTmplSwitch(TmplSwitch tmplSwitch) {
JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo()); return saveOrUpdate(tmplSwitch);
int affectRow = tmplSwitchMapper.insertTmplSwitch(tmplSwitch); }
if (affectRow > 0) {
List<TmplSwitchPort> list = new ArrayList<>(); private int saveOrUpdate(TmplSwitch tmplSwitch) {
jsonArray.forEach((i) -> { JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo());
JSONObject jsonObject = (JSONObject) i; int affectRow = tmplSwitchMapper.selectTmplSwitchById(tmplSwitch.getSwitchId()) != null
String valueStr = jsonObject.getString("value"); ? tmplSwitchMapper.updateTmplSwitch(tmplSwitch)
int num = 0; : tmplSwitchMapper.insertTmplSwitch(tmplSwitch);
if (StringUtils.isNotBlank(valueStr) && (num = Convert.toInt(valueStr)) > 0) { if (affectRow > 0) {
SysDictData dictData = sysDictDataMapper List<TmplSwitchPort> list = new ArrayList<>();
.selectDictDataById(Convert.toLong(jsonObject.getString("id"))); jsonArray.forEach((i) -> {
TmplSwitchPort tmplSwitchPort = new TmplSwitchPort(); JSONObject jsonObject = (JSONObject) i;
tmplSwitchPort.setSwitchId(tmplSwitch.getSwitchId()); String valueStr = jsonObject.getString("value");
tmplSwitchPort.setSwitchPortType(Convert.toInt(dictData.getDictCode())); int num = 0;
tmplSwitchPort.setSwitchPortNum(num); if (StringUtils.isNotBlank(valueStr) && (num = Convert.toInt(valueStr)) > 0) {
list.add(tmplSwitchPort); SysDictData dictData = sysDictDataMapper
} .selectDictDataById(Convert.toLong(jsonObject.getString("id")));
}); TmplSwitchPort tmplSwitchPort = new TmplSwitchPort();
int switchPorts = list.size() > 0 ? tmplSwitchPortMapper.batchTmplSwitchPort(list) : 0; tmplSwitchPort.setSwitchId(tmplSwitch.getSwitchId());
if (switchPorts == 0) { tmplSwitchPort.setSwitchPortType(Convert.toInt(dictData.getDictCode()));
throw new BusinessException("至少输入一个端口数量"); tmplSwitchPort.setSwitchPortNum(num);
} list.add(tmplSwitchPort);
} }
return affectRow; });
} int switchPorts = list.size() > 0 ? tmplSwitchPortMapper.batchTmplSwitchPort(list) : 0;
if (switchPorts == 0) {
/** throw new BusinessException("至少输入一个端口数量");
* 修改交换机模板 }
* }
* @param tmplSwitch 交换机模板信息 return affectRow;
* @return 结果 }
*/
@Override /**
public int updateTmplSwitch(TmplSwitch tmplSwitch) { * 修改交换机模板
return tmplSwitchMapper.updateTmplSwitch(tmplSwitch); *
} * @param tmplSwitch 交换机模板信息
* @return 更新后数据库中存在的值个数
/** */
* 删除交换机模板对象 @Override
* public int updateTmplSwitch(TmplSwitch tmplSwitch) {
* @param ids 需要删除的数据ID //1.清空数据库中已存的值
* @return 结果 tmplSwitchPortMapper.deleteTmplSwitchPortBySwitchId(tmplSwitch.getSwitchId());
*/ //2.更新主表
@Override return insertTmplSwitch(tmplSwitch);
public int deleteTmplSwitchByIds(String ids) { }
return tmplSwitchMapper.deleteTmplSwitchByIds(Convert.toStrArray(ids));
} /**
* 删除交换机模板对象
} *
* @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" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper"> <mapper namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper">
<resultMap type="TmplSwitchPort" id="TmplSwitchPortResult"> <resultMap type="TmplSwitchPort" id="TmplSwitchPortResult">
<result property="switchPortId" column="switch_port_id"/> <result property="switchPortId" column="switch_port_id"/>
<result property="switchId" column="switch_id"/> <result property="switchId" column="switch_id"/>
<result property="switchPortType" column="switch_port_type"/> <result property="switchPortType" column="switch_port_type"/>
<result property="switchPortNum" column="switch_port_num"/> <result property="switchPortNum" column="switch_port_num"/>
</resultMap> </resultMap>
<sql id="selectTmplSwitchPortVo"> <sql id="selectTmplSwitchPortVo">
select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port
</sql> </sql>
<select id="selectTmplSwitchPortList" parameterType="TmplSwitchPort" resultMap="TmplSwitchPortResult"> <select id="selectTmplSwitchPortList" parameterType="TmplSwitchPort" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/> <include refid="selectTmplSwitchPortVo"/>
<where> <where>
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if> <if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if>
<if test="switchId != null ">and switch_id = #{switchId}</if> <if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if> <if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
<if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if> <if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if>
</where> </where>
</select> </select>
<select id="selectTmplSwitchPortById" parameterType="Integer" resultMap="TmplSwitchPortResult"> <select id="selectTmplSwitchPortById" parameterType="Integer" resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/> <include refid="selectTmplSwitchPortVo"/>
where switch_port_id = #{switchPortId} where switch_port_id = #{switchPortId}
</select> </select>
<insert id="insertTmplSwitchPort" parameterType="TmplSwitchPort"> <select id="selectBySwitchIdAndPortType" parameterType="Integer" resultMap="TmplSwitchPortResult">
insert into tmpl_switch_port <include refid="selectTmplSwitchPortVo"/>
<trim prefix="(" suffix=")" suffixOverrides=","> where switch_id = #{switchPortId}
<if test="switchPortId != null ">switch_port_id,</if> and switch_port_type = #{switchPortType}
<if test="switchId != null ">switch_id,</if> </select>
<if test="switchPortType != null ">switch_port_type,</if>
<if test="switchPortNum != null ">switch_port_num,</if>
</trim> <insert id="insertTmplSwitchPort" parameterType="TmplSwitchPort">
<trim prefix="values (" suffix=")" suffixOverrides=","> insert into tmpl_switch_port
<if test="switchPortId != null ">#{switchPortId},</if> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="switchId != null ">#{switchId},</if> <if test="switchPortId != null ">switch_port_id,</if>
<if test="switchPortType != null ">#{switchPortType},</if> <if test="switchId != null ">switch_id,</if>
<if test="switchPortNum != null ">#{switchPortNum},</if> <if test="switchPortType != null ">switch_port_type,</if>
</trim> <if test="switchPortNum != null ">switch_port_num,</if>
</insert> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<update id="updateTmplSwitchPort" parameterType="TmplSwitchPort"> <if test="switchPortId != null ">#{switchPortId},</if>
update tmpl_switch_port <if test="switchId != null ">#{switchId},</if>
<trim prefix="SET" suffixOverrides=","> <if test="switchPortType != null ">#{switchPortType},</if>
<if test="switchId != null ">switch_id = #{switchId},</if> <if test="switchPortNum != null ">#{switchPortNum},</if>
<if test="switchPortType != null ">switch_port_type = #{switchPortType},</if> </trim>
<if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if> </insert>
</trim>
where switch_port_id = #{switchPortId} <insert id="batchTmplSwitchPort">
</update> insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values
<foreach item="item" index="index" collection="list" separator=",">
<delete id="deleteTmplSwitchPortById" parameterType="Integer"> (#{item.switchId},#{item.switchPortType},#{item.switchPortNum})
delete from tmpl_switch_port where switch_port_id = #{switchPortId} </foreach>
</delete> </insert>
<delete id="deleteTmplSwitchPortByIds" parameterType="String"> <update id="updateTmplSwitchPort" parameterType="TmplSwitchPort">
delete from tmpl_switch_port where switch_port_id in update tmpl_switch_port
<foreach item="switchPortId" collection="array" open="(" separator="," close=")"> <trim prefix="SET" suffixOverrides=",">
#{switchPortId} <if test="switchId != null ">switch_id = #{switchId},</if>
</foreach> <if test="switchPortType != null ">switch_port_type = #{switchPortType},</if>
</delete> <if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if>
</trim>
<insert id="batchTmplSwitchPort"> where switch_port_id = #{switchPortId}
insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values </update>
<foreach item="item" index="index" collection="list" separator=",">
(#{item.switchId},#{item.switchPortType},#{item.switchPortNum}) <delete id="deleteTmplSwitchPortById" parameterType="Integer">
</foreach> delete from tmpl_switch_port where switch_port_id = #{switchPortId}
</insert> </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> </mapper>