diff --git a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/add.html b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/add.html index c109f5ef8..3e41b003e 100644 --- a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/add.html +++ b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/add.html @@ -1,85 +1,87 @@ - - - - - - -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- -
-
-
-
- -
- -
-
-
-
-
-
-
-
- - - + + + + + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ + + diff --git a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/edit.html b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/edit.html index 44aca72ec..3c4a5d437 100644 --- a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/edit.html +++ b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/edit.html @@ -1,62 +1,98 @@ - - - - - - -
-
- -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
- - - + + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+ + + diff --git a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/tmplSwitch.html b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/tmplSwitch.html index d82eed277..4cb5ad403 100644 --- a/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/tmplSwitch.html +++ b/ruoyi-admin/src/main/resources/templates/template/tmplSwitch/tmplSwitch.html @@ -1,106 +1,129 @@ - - - - - - -
-
-
-
-
-
    -
  • - 交换机品牌: -
  • - -
  • - 交换机型号: -
  • - -
  • - 交换机电源数量: -
  • - -
  • -  搜索 -  重置 -
  • -
-
-
-
- - -
-
-
-
-
-
- - + + + + + + +
+
+
+
+
+
    +
  • + 交换机品牌: +
  • + +
  • + 交换机型号: +
  • + +
  • + 交换机电源数量: +
  • +
  • +  搜索 +  重置 +
  • +
+
+
+
+ + +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java index 243fd51d9..fbc9ce98d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java @@ -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基类 diff --git a/ruoyi-system/src/main/java/com/ruoyi/template/domain/TmplSwitch.java b/ruoyi-system/src/main/java/com/ruoyi/template/domain/TmplSwitch.java index 309e6e5ca..1ea73f097 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/template/domain/TmplSwitch.java +++ b/ruoyi-system/src/main/java/com/ruoyi/template/domain/TmplSwitch.java @@ -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 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 getSwitchPorts() { - return switchPorts; - } - - public void setSwitchPorts(List 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 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 getSwitchPorts() { + return switchPorts; + } + + public void setSwitchPorts(List 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(); + } +} + + diff --git a/ruoyi-system/src/main/java/com/ruoyi/template/mapper/TmplSwitchPortMapper.java b/ruoyi-system/src/main/java/com/ruoyi/template/mapper/TmplSwitchPortMapper.java index 8a3ed60ce..c7e2efbbb 100755 --- a/ruoyi-system/src/main/java/com/ruoyi/template/mapper/TmplSwitchPortMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/template/mapper/TmplSwitchPortMapper.java @@ -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 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 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 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 tmplSwitchPortList); + } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/template/service/impl/TmplSwitchServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/template/service/impl/TmplSwitchServiceImpl.java index b264c53da..640916809 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/template/service/impl/TmplSwitchServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/template/service/impl/TmplSwitchServiceImpl.java @@ -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 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 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 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 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)); + } + +} diff --git a/ruoyi-system/src/main/resources/mapper/template/TmplSwitchPortMapper.xml b/ruoyi-system/src/main/resources/mapper/template/TmplSwitchPortMapper.xml index 03c393824..5b716d701 100755 --- a/ruoyi-system/src/main/resources/mapper/template/TmplSwitchPortMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/template/TmplSwitchPortMapper.xml @@ -1,77 +1,88 @@ - - - - - - - - - - - - - select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port - - - - - - - - insert into tmpl_switch_port - - switch_port_id, - switch_id, - switch_port_type, - switch_port_num, - - - #{switchPortId}, - #{switchId}, - #{switchPortType}, - #{switchPortNum}, - - - - - update tmpl_switch_port - - switch_id = #{switchId}, - switch_port_type = #{switchPortType}, - switch_port_num = #{switchPortNum}, - - where switch_port_id = #{switchPortId} - - - - delete from tmpl_switch_port where switch_port_id = #{switchPortId} - - - - delete from tmpl_switch_port where switch_port_id in - - #{switchPortId} - - - - - insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values - - (#{item.switchId},#{item.switchPortType},#{item.switchPortNum}) - - - + + + + + + + + + + + + + select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port + + + + + + + + + + + insert into tmpl_switch_port + + switch_port_id, + switch_id, + switch_port_type, + switch_port_num, + + + #{switchPortId}, + #{switchId}, + #{switchPortType}, + #{switchPortNum}, + + + + + insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values + + (#{item.switchId},#{item.switchPortType},#{item.switchPortNum}) + + + + + update tmpl_switch_port + + switch_id = #{switchId}, + switch_port_type = #{switchPortType}, + switch_port_num = #{switchPortNum}, + + where switch_port_id = #{switchPortId} + + + + delete from tmpl_switch_port where switch_port_id = #{switchPortId} + + + + delete from tmpl_switch_port where switch_id = #{switchId} + + + + delete from tmpl_switch_port where switch_port_id in + + #{switchPortId} + + + \ No newline at end of file