部门管理支持批量保存排序

springboot2
RuoYi 4 weeks ago
parent c6d5f1cfe3
commit 569f0a57c0

@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
@ -186,4 +187,15 @@ public class SysDeptController extends BaseController
List<Ztree> ztrees = deptService.selectDeptTreeExcludeChild(dept); List<Ztree> ztrees = deptService.selectDeptTreeExcludeChild(dept);
return ztrees; return ztrees;
} }
/**
*
*/
@PostMapping("/updateSort")
@ResponseBody
public AjaxResult updateSort(@RequestParam String[] deptIds, @RequestParam String[] orderNums)
{
deptService.updateDeptSort(deptIds, orderNums);
return success();
}
} }

@ -1,112 +1,141 @@
<!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="dept-form"> <form id="dept-form">
<div class="select-list"> <div class="select-list">
<ul> <ul>
<li> <li>
部门名称:<input type="text" name="deptName"/> 部门名称:<input type="text" name="deptName"/>
</li> </li>
<li> <li>
部门状态:<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}"> 部门状态:<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
<option value="">所有</option> <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> </select>
</li> </li>
<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-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-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li> </li>
</ul> </ul>
</div> </div>
</form> </form>
</div> </div>
<div class="btn-group-sm" id="toolbar" role="group"> <div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:dept:add"> <a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:dept:add">
<i class="fa fa-plus"></i> 新增 <i class="fa fa-plus"></i> 新增
</a> </a>
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit"> <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit">
<i class="fa fa-edit"></i> 修改 <i class="fa fa-edit"></i> 修改
</a> </a>
<a class="btn btn-info" id="expandAllBtn"> <a class="btn btn-warning" onclick="saveSort()">
<i class="fa fa-exchange"></i> 展开/折叠 <i class="fa fa-sort-amount-asc"></i> 保存排序
</a> </a>
</div> <a class="btn btn-info" id="expandAllBtn">
<div class="col-sm-12 select-table table-striped"> <i class="fa fa-exchange"></i> 展开/折叠
<table id="bootstrap-tree-table"></table> </a>
</div> </div>
</div> <div class="col-sm-12 select-table table-striped">
</div> <table id="bootstrap-tree-table"></table>
<th:block th:include="include :: footer" /> </div>
<script th:inline="javascript"> </div>
var addFlag = [[${@permission.hasPermi('system:dept:add')}]]; </div>
var editFlag = [[${@permission.hasPermi('system:dept:edit')}]]; <th:block th:include="include :: footer" />
var removeFlag = [[${@permission.hasPermi('system:dept:remove')}]]; <script th:inline="javascript">
var datas = [[${@dict.getType('sys_normal_disable')}]]; var addFlag = [[${@permission.hasPermi('system:dept:add')}]];
var prefix = ctx + "system/dept" var editFlag = [[${@permission.hasPermi('system:dept:edit')}]];
var removeFlag = [[${@permission.hasPermi('system:dept:remove')}]];
$(function() { var datas = [[${@dict.getType('sys_normal_disable')}]];
var options = { var prefix = ctx + "system/dept"
code: "deptId", var originalOrders = {};
parentCode: "parentId",
uniqueId: "deptId", $(function() {
url: prefix + "/list", var options = {
createUrl: prefix + "/add/{id}", code: "deptId",
updateUrl: prefix + "/edit/{id}", parentCode: "parentId",
removeUrl: prefix + "/remove/{id}", uniqueId: "deptId",
modalName: "部门", url: prefix + "/list",
columns: [{ createUrl: prefix + "/add/{id}",
field: 'selectItem', updateUrl: prefix + "/edit/{id}",
radio: true removeUrl: prefix + "/remove/{id}",
}, modalName: "部门",
{ columns: [{
field: 'deptName', field: 'selectItem',
title: '部门名称', radio: true
align: "left" },
}, {
{ field: 'deptName',
field: 'orderNum', title: '部门名称',
title: '排序', align: "left"
align: "left" },
}, {
{ field: 'orderNum',
field: 'status', title: '排序',
title: '状态', align: "left",
align: "left", formatter: function(value, row, index) {
formatter: function(value, item, index) { var deptIdText = $.common.sprintf("<input type='hidden' name='deptIds' value='%s'>", row.deptId);
return $.table.selectDictLabel(datas, item.status); var orderNumText = $.common.sprintf("<input type='text' name='orderNums' value='%s' class='form-control' style='display:inline-block;width:60px;text-align:center;'>", row.orderNum);
} originalOrders[row.deptId] = row.orderNum;
}, return deptIdText + orderNumText;
{ }
field: 'createTime', },
title: '创建时间', {
align: "left" field: 'status',
}, title: '状态',
{ align: "left",
title: '操作', formatter: function(value, item, index) {
align: 'left', return $.table.selectDictLabel(datas, item.status);
formatter: function(value, row, index) { }
if (row.parentId != 0) { },
var actions = []; {
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>编辑</a> '); field: 'createTime',
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.deptId + '\')"><i class="fa fa-plus"></i>新增</a> '); title: '创建时间',
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')"><i class="fa fa-trash"></i>删除</a>'); align: "left"
return actions.join(''); },
} else { {
return ""; title: '操作',
} align: 'left',
} formatter: function(value, row, index) {
}] if (row.parentId != 0) {
}; var actions = [];
$.treeTable.init(options); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptId + '\')"><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.deptId + '\')"><i class="fa fa-plus"></i>新增</a> ');
</script> actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')"><i class="fa fa-trash"></i>删除</a>');
</body> return actions.join('');
} else {
return "";
}
}
}]
};
$.treeTable.init(options);
});
/* 保存排序-部门 */
function saveSort() {
var changedDeptIds = [];
var changedOrderNums = [];
$("input[name='deptIds']").each(function() {
var deptId = $(this).val();
var currentOrder = $(this).next("input[name='orderNums']").val();
if (String(originalOrders[deptId]) !== String(currentOrder)) {
changedDeptIds.push(deptId);
changedOrderNums.push(currentOrder);
}
});
if (changedDeptIds.length === 0) {
$.modal.alertWarning("未检测到排序修改");
return;
}
$.operate.post(prefix + "/updateSort", { "deptIds": changedDeptIds.join(","), "orderNums": changedOrderNums.join(",") });
}
</script>
</body>
</html> </html>

@ -114,4 +114,11 @@ public interface SysDeptMapper
* @return * @return
*/ */
public int selectNormalChildrenDeptById(Long deptId); public int selectNormalChildrenDeptById(Long deptId);
/**
*
*
* @param dept deptIdorderNum
*/
public void updateDeptSort(SysDept dept);
} }

@ -114,4 +114,12 @@ public interface ISysDeptService
* @param deptId id * @param deptId id
*/ */
public void checkDeptDataScope(Long deptId); public void checkDeptDataScope(Long deptId);
/**
*
*
* @param deptIds ID
* @param orderNums
*/
public void updateDeptSort(String[] deptIds, String[] orderNums);
} }

@ -324,4 +324,30 @@ public class SysDeptServiceImpl implements ISysDeptService
} }
} }
} }
/**
*
*
* @param deptIds ID
* @param orderNums
*/
@Override
@Transactional
public void updateDeptSort(String[] deptIds, String[] orderNums)
{
try
{
for (int i = 0; i < deptIds.length; i++)
{
SysDept dept = new SysDept();
dept.setDeptId(Convert.toLong(deptIds[i]));
dept.setOrderNum(Convert.toInt(orderNums[i]));
deptMapper.updateDeptSort(dept);
}
}
catch (Exception e)
{
throw new ServiceException("保存排序异常,请联系管理员");
}
}
} }

@ -155,4 +155,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</update> </update>
<update id="updateDeptSort" parameterType="SysDept">
update sys_dept set order_num = #{orderNum} where dept_id = #{deptId}
</update>
</mapper> </mapper>
Loading…
Cancel
Save