change - 监控单元信息添加导入功能

main
wenjy 3 years ago
parent a79762b3dc
commit fbb42c700d

@ -67,6 +67,15 @@
<artifactId>ruoyi-generator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -22,6 +23,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.web.multipart.MultipartFile;
/**
* Controller
@ -51,12 +53,45 @@ public class BaseMonitorunitInfoController extends BaseController
@RequiresPermissions("base:monitorUnitInfo:list")
@PostMapping("/list")
@ResponseBody
public List<BaseMonitorunitInfo> list(BaseMonitorunitInfo baseMonitorunitInfo)
public List<BaseMonitorunitInfoDto> list(BaseMonitorunitInfo baseMonitorunitInfo)
{
List<BaseMonitorunitInfo> list = baseMonitorunitInfoService.selectBaseMonitorunitInfoList(baseMonitorunitInfo);
List<BaseMonitorunitInfoDto> list = baseMonitorunitInfoService.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo);
return list;
}
/**
*
* @author WenJY
* @date 2022/2/7 9:57
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:monitorUnitInfo:importTemplate")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate() {
ExcelUtil<BaseMonitorunitInfo> util = new ExcelUtil<BaseMonitorunitInfo>(BaseMonitorunitInfo.class);
return util.importTemplateExcel("监控单元信息");
}
/**
*
* @author WenJY
* @date 2022/2/7 9:58
* @param file
* @param updateSupport
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:monitorUnitInfo:importData")
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<BaseMonitorunitInfo> util = new ExcelUtil<BaseMonitorunitInfo>(BaseMonitorunitInfo.class);
//读取file文件将文件内容转为list集合
List<BaseMonitorunitInfo> baseMonitorunitInfoList = util.importExcel(file.getInputStream());
String message = baseMonitorunitInfoService.importMould(baseMonitorunitInfoList,updateSupport);
return AjaxResult.success(message);
}
/**
*
*/

@ -1,10 +1,10 @@
<!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('监控单元信息列表')" />
<th:block th:include="include :: header('监控单元信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
@ -20,28 +20,35 @@
</li>
<li>
<label style="width: 95px">监控单元类型:</label>
<select name="monitorunitType" th:with="type=${@monitorunitTypeService.getMonitorunitType()}">
<select name="monitorunitType"
th:with="type=${@monitorunitTypeService.getMonitorunitType()}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.monitorunittypeName}" th:value="${dict.monitorunittypeId}"></option>
<option th:each="dict : ${type}" th:text="${dict.monitorunittypeName}"
th:value="${dict.monitorunittypeId}"></option>
</select>
</li>
<li>
<label style="width: 90px">所属变电站:</label>
<select name="substationId" th:with="substationInfo=${@substationInfoService.getSubstationInfo()}">
<select name="substationId"
th:with="substationInfo=${@substationInfoService.getSubstationInfo()}">
<option value="">所有</option>
<option th:each="substation : ${substationInfo}" th:text="${substation.substationName}" th:value="${substation.substationId}"></option>
<option th:each="substation : ${substationInfo}" th:text="${substation.substationName}"
th:value="${substation.substationId}"></option>
</select>
</li>
<li>
<label>是否启用:</label>
<select name="enableFlag" th:with="type=${@dict.getType('enable_flag')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
th:value="${dict.dictValue}"></option>
</select>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.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>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.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>
@ -55,6 +62,9 @@
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="base:monitorUnitInfo:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-info" onclick="$.table.importExcel() " shiro:hasPermission="base:monitorUnitInfo:import">
<i class="fa fa-upload"></i> 导入
</a>
<a class="btn btn-info" id="expandAllBtn">
<i class="fa fa-exchange"></i> 展开/折叠
</a>
@ -63,16 +73,16 @@
<table id="bootstrap-tree-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
var addFlag = [[${@permission.hasPermi('base:monitorUnitInfo:add')}]];
var editFlag = [[${@permission.hasPermi('base:monitorUnitInfo:edit')}]];
var removeFlag = [[${@permission.hasPermi('base:monitorUnitInfo:remove')}]];
var enableFlagDatas = [[${@dict.getType('enable_flag')}]];
var prefix = ctx + "base/monitorUnitInfo";
$(function() {
$(function () {
var options = {
code: "monitorunitId",
parentCode: "parentId",
@ -83,14 +93,17 @@
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
exportUrl: prefix + "/export",
importUrl: prefix + "/importData",
importTemplateUrl: prefix + "/importTemplate",
modalName: "监控单元信息",
columns: [{
field: 'selectItem',
radio: true
},
{
field:'objId',
title: '标识'
field: 'objId',
title: '标识',
visible: false
},
{
field: 'monitorunitId',
@ -103,17 +116,17 @@
align: 'left'
},
{
field: 'parentId',
field: 'parentName',
title: '父级监控单元',
align: 'left'
},
{
field: 'monitorunitType',
field: 'monitorunitTypeName',
title: '监控单元类型',
align: 'left'
},
{
field: 'substationId',
field: 'substationName',
title: '所属变电站',
align: 'left'
},
@ -121,7 +134,7 @@
field: 'enableFlag',
title: '是否启用',
align: 'left',
formatter: function(value, row, index) {
formatter: function (value, row, index) {
return $.table.selectDictLabel(enableFlagDatas, value);
}
},
@ -129,7 +142,7 @@
title: '操作',
align: 'center',
align: 'left',
formatter: function(value, row, index) {
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.objId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.objId + '\')"><i class="fa fa-plus"></i>新增</a> ');
@ -140,6 +153,22 @@
};
$.treeTable.init(options);
});
</script>
</script>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
<div class="col-xs-offset-1">
<input type="file" id="file" name="file"/>
<div class="mt10 pt5">
<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在,更新这条数据。"> 是否更新已经存在的用户数据
&nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
class="fa fa-file-excel-o"></i> 下载模板</a>
</div>
<font color="red" class="pull-left mt10">
提示仅允许导入“xls”或“xlsx”格式文件
</font>
</div>
</form>
</script>
</body>
</html>

@ -1,5 +1,7 @@
package com.ruoyi.common.core.domain;
import com.ruoyi.common.annotation.Excel;
/**
* Tree
*
@ -13,6 +15,7 @@ public class TreeEntity extends BaseEntity
private String parentName;
/** 父菜单ID */
@Excel(name = "父级编号")
private String parentId;
/** 显示顺序 */

@ -22,6 +22,10 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

@ -15,6 +15,13 @@ public class BaseMonitorunitInfo extends TreeEntity
{
private static final long serialVersionUID = 1L;
public BaseMonitorunitInfo() {
}
public BaseMonitorunitInfo(String monitorunitId) {
this.monitorunitId = monitorunitId;
}
/** 主键标识 */
private Long objId;

@ -0,0 +1,18 @@
package com.ruoyi.system.domain.dto;
import com.ruoyi.system.domain.BaseMonitorunitInfo;
import lombok.Data;
/**
* @author WenJY
* @date 20220207 10:12
*/
@Data
public class BaseMonitorunitInfoDto extends BaseMonitorunitInfo {
private String monitorunitTypeName;
private String substationName;
private String parentName;
}

@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.BaseMonitorunitInfo;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
/**
* Mapper
@ -27,6 +28,15 @@ public interface BaseMonitorunitInfoMapper
*/
public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(BaseMonitorunitInfo baseMonitorunitInfo);
/**
*
* @author WenJY
* @date 2022/2/7 10:23
* @param baseMonitorunitInfo
* @return java.util.List<com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto>
*/
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(BaseMonitorunitInfo baseMonitorunitInfo);
/**
*
*

@ -3,6 +3,7 @@ package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.BaseMonitorunitInfo;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
/**
* Service
@ -28,6 +29,24 @@ public interface IBaseMonitorunitInfoService
*/
public List<BaseMonitorunitInfo> selectBaseMonitorunitInfoList(BaseMonitorunitInfo baseMonitorunitInfo);
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(BaseMonitorunitInfo baseMonitorunitInfo);
/**
*
* @author WenJY
* @date 2022/2/7 9:53
* @param baseMonitorunitInfos
* @param updateSupport
* @return java.lang.String
*/
public String importMould(List<BaseMonitorunitInfo> baseMonitorunitInfos, boolean updateSupport);
/**
*
*

@ -1,9 +1,15 @@
package com.ruoyi.system.service.impl;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.BaseMonitorunitType;
import com.ruoyi.system.domain.dto.BaseMonitorunitInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BaseMonitorunitInfoMapper;
@ -47,6 +53,74 @@ public class BaseMonitorunitInfoServiceImpl implements IBaseMonitorunitInfoServi
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(baseMonitorunitInfo);
}
/**
*
*
* @param baseMonitorunitInfo
* @return
*/
@Override
public List<BaseMonitorunitInfoDto> selectBaseMonitorunitInfoDtoList(BaseMonitorunitInfo baseMonitorunitInfo)
{
return baseMonitorunitInfoMapper.selectBaseMonitorunitInfoDtoList(baseMonitorunitInfo);
}
/**
*
* @author WenJY
* @date 2022/2/7 9:53
* @param baseMonitorunitInfos
* @param updateSupport
* @return java.lang.String
*/
@Override
public String importMould(List<BaseMonitorunitInfo> baseMonitorunitInfos, boolean updateSupport) {
if (StringUtils.isNull(baseMonitorunitInfos) || baseMonitorunitInfos.size() == 0) {
throw new BusinessException("导入标准数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (BaseMonitorunitInfo baseMonitorunitInfo : baseMonitorunitInfos) {
try {
List<BaseMonitorunitInfo> baseMonitorunitInfoList =
baseMonitorunitInfoMapper.selectBaseMonitorunitInfoList(new BaseMonitorunitInfo(baseMonitorunitInfo.getMonitorunitId()));
if (baseMonitorunitInfoList.size() == 0) {
baseMonitorunitInfo.setCreateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setCreateTime(new Date());
baseMonitorunitInfoMapper.insertBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
successMsg.append("<br/>" + successNum + "、 " + baseMonitorunitInfo.getMonitorunitName() + " 导入成功");
} else if (updateSupport) {
for (BaseMonitorunitInfo unitInfo : baseMonitorunitInfoList) {
baseMonitorunitInfo.setObjId(unitInfo.getObjId());
baseMonitorunitInfo.setUpdateBy(ShiroUtils.getLoginName());
baseMonitorunitInfo.setUpdateTime(new Date());
baseMonitorunitInfoMapper.updateBaseMonitorunitInfo(baseMonitorunitInfo);
successNum++;
}
successMsg.append("<br/>" + successNum + "、" + baseMonitorunitInfo.getMonitorunitName() + " 更新成功");
} else {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、" + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 已存在");
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、标准: " + baseMonitorunitInfo.getMonitorunitId() + "、" + baseMonitorunitInfo.getMonitorunitName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
/**
*
*

@ -19,6 +19,23 @@
<result property="parentName" column="parent_name" />
</resultMap>
<resultMap type="BaseMonitorunitInfoDto" id="BaseMonitorunitInfoDtoResult">
<result property="objId" column="ObjId" />
<result property="monitorunitId" column="MonitorUnit_Id" />
<result property="monitorunitName" column="MonitorUnit_Name" />
<result property="parentId" column="Parent_Id" />
<result property="monitorunitType" column="MonitorUnit_Type" />
<result property="substationId" column="Substation_Id" />
<result property="enableFlag" column="Enable_Flag" />
<result property="createBy" column="Create_By" />
<result property="createTime" column="Create_Time" />
<result property="updateBy" column="Update_By" />
<result property="updateTime" column="Update_Time" />
<result property="parentName" column="parent_name" />
<result property="monitorunitTypeName" column="MonitorUnitType_Name" />
<result property="substationName" column="Substation_Name" />
</resultMap>
<sql id="selectBaseMonitorunitInfoVo">
select ObjId, MonitorUnit_Id, MonitorUnit_Name, Parent_Id, MonitorUnit_Type, Substation_Id, Enable_Flag, Create_By, Create_Time, Update_By, Update_Time from base_monitorunit_info
</sql>
@ -36,6 +53,24 @@
order by Parent_Id
</select>
<select id="selectBaseMonitorunitInfoDtoList" parameterType="BaseMonitorunitInfo" resultMap="BaseMonitorunitInfoDtoResult">
select t1.objid, t1.monitorunit_id, t1.monitorunit_name, t1.parent_id, t3.MonitorUnit_Name as parent_name,
t1.monitorunit_type,t2.MonitorUnitType_Name, t1.substation_id,t4.Substation_Name,
t1.enable_flag from base_monitorunit_info t1
left join base_monitorunit_type t2 on t1.MonitorUnit_Type = t2.MonitorUnitType_Id
left join base_monitorunit_info t3 on t1.Parent_Id = t3.MonitorUnit_Id
left join base_substation_info t4 on t1.Substation_Id = t4.Substation_Id
<where>
<if test="monitorunitId != null and monitorunitId != ''"> and t1.MonitorUnit_Id like concat('%', #{monitorunitId}, '%')</if>
<if test="monitorunitName != null and monitorunitName != ''"> and t1.MonitorUnit_Name like concat('%', #{monitorunitName}, '%')</if>
<if test="parentId != null and parentId != ''"> and t1.Parent_Id = #{parentId}</if>
<if test="monitorunitType != null "> and t1.MonitorUnit_Type = #{monitorunitType}</if>
<if test="substationId != null and substationId != ''"> and t1.Substation_Id = #{substationId}</if>
<if test="enableFlag != null "> and t1.Enable_Flag = #{enableFlag}</if>
</where>
order by t1.objId
</select>
<select id="selectBaseMonitorunitInfoByObjId" parameterType="Long" resultMap="BaseMonitorunitInfoResult">
select t.ObjId, t.MonitorUnit_Id, t.MonitorUnit_Name, t.Parent_Id, t.MonitorUnit_Type, t.Substation_Id, t.Enable_Flag, t.Create_By, t.Create_Time, t.Update_By, t.Update_Time, p.MonitorUnit_Name as parent_name
from base_monitorunit_info t

Loading…
Cancel
Save