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

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

@ -35,6 +35,9 @@
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-warning" onclick="saveSort()">
<i class="fa fa-sort-amount-asc"></i> 保存排序
</a>
<a class="btn btn-info" id="expandAllBtn">
<i class="fa fa-exchange"></i> 展开/折叠
</a>
@ -51,6 +54,7 @@
var removeFlag = [[${@permission.hasPermi('system:dept:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "system/dept"
var originalOrders = {};
$(function() {
var options = {
@ -74,7 +78,13 @@
{
field: 'orderNum',
title: '排序',
align: "left"
align: "left",
formatter: function(value, row, index) {
var deptIdText = $.common.sprintf("<input type='hidden' name='deptIds' value='%s'>", row.deptId);
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: 'status',
@ -107,6 +117,25 @@
};
$.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>

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

@ -114,4 +114,12 @@ public interface ISysDeptService
* @param deptId id
*/
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>
</update>
<update id="updateDeptSort" parameterType="SysDept">
update sys_dept set order_num = #{orderNum} where dept_id = #{deptId}
</update>
</mapper>
Loading…
Cancel
Save