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

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

@ -25,13 +25,15 @@
</div> </div>
</div> </div>
<!--端口类型字典-->
<div class="form-group" th:with="type=${@dict.getType('dict_port_type')}"> <div class="form-group" th:with="type=${@dict.getType('dict_port_type')}">
<div class="col-sm-6" th:each="dict : ${type}"> <div class="col-sm-6" th:each="dict : ${type}">
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" th:text="${dict.dictLabel}"></label> <label class="col-sm-6 control-label" th:text="${dict.dictLabel}"></label>
<div class="col-sm-9"> <div class="col-sm-5">
<input type="number" value="" th:name="${dict.dictCode}" class="form-control switchPort" <input type="number" min="0" max="100" th:id="${dict.dictCode}"
class="form-control switchPort"
placeholder="单位(个)"> placeholder="单位(个)">
</div> </div>
</div> </div>
@ -70,7 +72,7 @@
var data = $('#form-tmplSwitch-add').serializeArray(); var data = $('#form-tmplSwitch-add').serializeArray();
var params = []; var params = [];
$(".switchPort").each(function () { $(".switchPort").each(function () {
params.push({"id": $(this).attr("name"), "value": $(this).val()}); params.push({"id": $(this).attr("id"), "value": $(this).val()});
}); });
var obj = { var obj = {
"name": "foreignKeyInfo", "name": "foreignKeyInfo",

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
},
powerNum: {
required: true,
minlength: 1,
maxlength: 2
},
},
focusCleanup: true
});
function submitHandler() { </form>
if ($.validate.form()) { </div>
$.operate.save(prefix + "/edit", $('#form-tmplSwitch-edit').serialize()); <div th:include="include::footer"></div>
} <script type="text/javascript" th:inline="javascript">
} var prefix = ctx + "template/tmplSwitch";
</script> $("#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> </body>
</html> </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>
<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>
<li> <div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a> <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:tmplSwitch:add">
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a> <i class="fa fa-plus"></i> 添加
</li> </a>
</ul> <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
</div> shiro:hasPermission="template:tmplSwitch:edit">
</form> <i class="fa fa-edit"></i> 修改
</div> </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";
<div class="btn-group-sm" id="toolbar" role="group"> $(function () {
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="template:tmplSwitch:add"> var options = {
<i class="fa fa-plus"></i> 添加 url: prefix + "/list",
</a> createUrl: prefix + "/add",
<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="template:tmplSwitch:edit"> updateUrl: prefix + "/edit/{id}",
<i class="fa fa-edit"></i> 修改 removeUrl: prefix + "/remove",
</a> exportUrl: prefix + "/export",
<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="template:tmplSwitch:remove"> modalName: "交换机模板",
<i class="fa fa-remove"></i> 删除 showExport: true,
</a> columns: [{
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="template:tmplSwitch:export"> checkbox: true
<i class="fa fa-download"></i> 导出 },
</a> {
</div> field: 'switchId',
<div class="col-sm-12 select-table table-striped"> title: '交换机模板编号',
<table id="bootstrap-table" data-mobile-responsive="true"></table> visible: false,
</div> align: 'center'
</div> },
</div> {
<div th:include="include :: footer"></div> field: 'switchBrand',
<script th:inline="javascript"> title: '交换机品牌',
var editFlag = [[${@permission.hasPermi('template:tmplSwitch:edit')}]]; sortable: true,
var removeFlag = [[${@permission.hasPermi('template:tmplSwitch:remove')}]]; align: 'center'
var prefix = ctx + "template/tmplSwitch"; },
{
$(function() { field: 'switchType',
var options = { title: '交换机型号',
url: prefix + "/list", sortable: true,
createUrl: prefix + "/add", align: 'center'
updateUrl: prefix + "/edit/{id}", },
removeUrl: prefix + "/remove", {
exportUrl: prefix + "/export", field: 'powerNum',
modalName: "交换机模板", title: '交换机电源数量',
showExport: true, sortable: true,
columns: [{ align: 'center'
checkbox: true }
}, ]
{ };
field : 'switchId', $.each([[${@dict.getType('dict_port_type')}]], function (index, dict) {
title : '交换机模板编号', options.columns.push({
visible: false field: dict.dictCode,
}, title: dict.dictLabel+"(个)",
{ align: 'center',
field : 'switchBrand', formatter: function (value, row, index) {
title : '交换机品牌', $.each(row.switchPorts, function (index, switchPort) {
sortable: true if (switchPort.switchPortType == dict.dictCode) {
}, value = switchPort.switchPortNum;
{ }
field : 'switchType', });
title : '交换机型号', return value;
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> 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> </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

@ -36,38 +36,38 @@ public class TmplSwitch extends BaseEntity {
*/ */
private List<TmplSwitchPort> switchPorts; private List<TmplSwitchPort> switchPorts;
public void setSwitchId(Integer switchId) {
this.switchId = switchId;
}
public Integer getSwitchId() { public Integer getSwitchId() {
return switchId; return switchId;
} }
public void setSwitchBrand(String switchBrand) { public void setSwitchId(Integer switchId) {
this.switchBrand = switchBrand; this.switchId = switchId;
} }
public String getSwitchBrand() { public String getSwitchBrand() {
return switchBrand; return switchBrand;
} }
public void setSwitchType(String switchType) { public void setSwitchBrand(String switchBrand) {
this.switchType = switchType; this.switchBrand = switchBrand;
} }
public String getSwitchType() { public String getSwitchType() {
return switchType; return switchType;
} }
public void setPowerNum(Integer powerNum) { public void setSwitchType(String switchType) {
this.powerNum = powerNum; this.switchType = switchType;
} }
public Integer getPowerNum() { public Integer getPowerNum() {
return powerNum; return powerNum;
} }
public void setPowerNum(Integer powerNum) {
this.powerNum = powerNum;
}
public List<TmplSwitchPort> getSwitchPorts() { public List<TmplSwitchPort> getSwitchPorts() {
return switchPorts; return switchPorts;
} }
@ -87,3 +87,5 @@ public class TmplSwitch extends BaseEntity {
.toString(); .toString();
} }
} }

View File

@ -10,62 +10,79 @@ 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 switchPortType 交换机端口类型
* @return 交换机端口类型信息
*/
public TmplSwitchPort selectBySwitchIdAndPortType(Integer switchId, Integer switchPortType);
/**
* 查询交换机端口类型列表 * 查询交换机端口类型列表
* *
* @param tmplSwitchPort 交换机端口类型信息 * @param tmplSwitchPort 交换机端口类型信息
* @return 交换机端口类型集合 * @return 交换机端口类型集合
*/ */
public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort); public List<TmplSwitchPort> selectTmplSwitchPortList(TmplSwitchPort tmplSwitchPort);
/** /**
* 新增交换机端口类型 * 新增交换机端口类型
* *
* @param tmplSwitchPort 交换机端口类型信息 * @param tmplSwitchPort 交换机端口类型信息
* @return 结果 * @return 结果
*/ */
public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort); public int insertTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/** /**
* 修改交换机端口类型 * 修改交换机端口类型
* *
* @param tmplSwitchPort 交换机端口类型信息 * @param tmplSwitchPort 交换机端口类型信息
* @return 结果 * @return 结果
*/ */
public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort); public int updateTmplSwitchPort(TmplSwitchPort tmplSwitchPort);
/** /**
* 删除交换机端口类型 * 删除交换机端口类型
* *
* @param switchPortId 交换机端口类型ID * @param switchPortId 交换机端口类型ID
* @return 结果 * @return 结果
*/ */
public int deleteTmplSwitchPortById(Integer switchPortId); public int deleteTmplSwitchPortById(Integer switchPortId);
/**
/**
* 通过交换机ID批量删除交换机端口类型
*
* @param switchId 交换机ID
* @return 结果
*/
public int deleteTmplSwitchPortBySwitchId(Integer switchId);
/**
* 批量删除交换机端口类型 * 批量删除交换机端口类型
* *
* @param switchPortIds 需要删除的数据ID * @param switchPortIds 需要删除的数据ID
* @return 结果 * @return 结果
*/ */
public int deleteTmplSwitchPortByIds(String[] switchPortIds); public int deleteTmplSwitchPortByIds(String[] switchPortIds);
/** /**
* 批量新增交换机端口信息 * 批量新增交换机端口信息
* *
* @param tmplSwitchPortList 交换机端口列表 * @param tmplSwitchPortList 交换机端口列表
* @return 结果 * @return 结果
*/ */
public int batchTmplSwitchPort(List<TmplSwitchPort> tmplSwitchPortList); public int batchTmplSwitchPort(List<TmplSwitchPort> tmplSwitchPortList);
} }

View File

@ -65,8 +65,14 @@ public class TmplSwitchServiceImpl implements ITmplSwitchService {
*/ */
@Override @Override
public int insertTmplSwitch(TmplSwitch tmplSwitch) { public int insertTmplSwitch(TmplSwitch tmplSwitch) {
return saveOrUpdate(tmplSwitch);
}
private int saveOrUpdate(TmplSwitch tmplSwitch) {
JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo()); JSONArray jsonArray = JSONArray.parseArray(tmplSwitch.getForeignKeyInfo());
int affectRow = tmplSwitchMapper.insertTmplSwitch(tmplSwitch); int affectRow = tmplSwitchMapper.selectTmplSwitchById(tmplSwitch.getSwitchId()) != null
? tmplSwitchMapper.updateTmplSwitch(tmplSwitch)
: tmplSwitchMapper.insertTmplSwitch(tmplSwitch);
if (affectRow > 0) { if (affectRow > 0) {
List<TmplSwitchPort> list = new ArrayList<>(); List<TmplSwitchPort> list = new ArrayList<>();
jsonArray.forEach((i) -> { jsonArray.forEach((i) -> {
@ -95,11 +101,14 @@ public class TmplSwitchServiceImpl implements ITmplSwitchService {
* 修改交换机模板 * 修改交换机模板
* *
* @param tmplSwitch 交换机模板信息 * @param tmplSwitch 交换机模板信息
* @return 结果 * @return 更新后数据库中存在的值个数
*/ */
@Override @Override
public int updateTmplSwitch(TmplSwitch tmplSwitch) { public int updateTmplSwitch(TmplSwitch tmplSwitch) {
return tmplSwitchMapper.updateTmplSwitch(tmplSwitch); //1.清空数据库中已存的值
tmplSwitchPortMapper.deleteTmplSwitchPortBySwitchId(tmplSwitch.getSwitchId());
//2.更新主表
return insertTmplSwitch(tmplSwitch);
} }
/** /**

View File

@ -30,6 +30,13 @@
where switch_port_id = #{switchPortId} where switch_port_id = #{switchPortId}
</select> </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 id="insertTmplSwitchPort" parameterType="TmplSwitchPort">
insert into tmpl_switch_port insert into tmpl_switch_port
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -46,6 +53,13 @@
</trim> </trim>
</insert> </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 id="updateTmplSwitchPort" parameterType="TmplSwitchPort">
update tmpl_switch_port update tmpl_switch_port
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
@ -60,6 +74,10 @@
delete from tmpl_switch_port where switch_port_id = #{switchPortId} delete from tmpl_switch_port where switch_port_id = #{switchPortId}
</delete> </delete>
<delete id="deleteTmplSwitchPortBySwitchId" parameterType="Integer">
delete from tmpl_switch_port where switch_id = #{switchId}
</delete>
<delete id="deleteTmplSwitchPortByIds" parameterType="String"> <delete id="deleteTmplSwitchPortByIds" parameterType="String">
delete from tmpl_switch_port where switch_port_id in delete from tmpl_switch_port where switch_port_id in
<foreach item="switchPortId" collection="array" open="(" separator="," close=")"> <foreach item="switchPortId" collection="array" open="(" separator="," close=")">
@ -67,11 +85,4 @@
</foreach> </foreach>
</delete> </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>
</mapper> </mapper>