1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-07-20 04:23:01 +08:00

#523 fix delete organ bug

This commit is contained in:
Yu 2021-12-02 15:24:17 +08:00
parent 9b98efc63d
commit 84e025cbcc
2 changed files with 25 additions and 22 deletions

View File

@ -16,7 +16,6 @@
*/
package com.chatopera.cc.controller.admin;
import com.alibaba.fastjson.JSONArray;
import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.controller.Handler;
@ -111,11 +110,13 @@ public class OrganController extends Handler {
false));
// 处理附属组织
final Map<String, Organ> affiliates = organProxy.findAllOrganByParentAndOrgi(organData, super.getOrgi());
final Map<String, Organ> affiliates = organProxy.findAllOrganByParentAndOrgi(organData,
super.getOrgi());
List<User> affiliateUsers = new ArrayList<>();
for (final Map.Entry<String, Organ> o : affiliates.entrySet()) {
if (StringUtils.equals(o.getKey(), organData.getId())) continue;
if (StringUtils.equals(o.getKey(), organData.getId()))
continue;
List<User> ousers = userProxy.findByOrganAndOrgiAndDatastatus(
o.getKey(),
super.getOrgi(),
@ -163,7 +164,7 @@ public class OrganController extends Handler {
String msg = "admin_organ_new_success";
String firstId = null;
if (tempOrgan != null) {
msg = "admin_organ_update_name_not"; //分类名字重复
msg = "admin_organ_update_name_not"; // 分类名字重复
} else {
organ.setOrgi(super.getOrgi());
firstId = organ.getId();
@ -185,7 +186,8 @@ public class OrganController extends Handler {
@RequestMapping("/seluser")
@Menu(type = "admin", subtype = "seluser", admin = true)
public ModelAndView seluser(ModelMap map, HttpServletRequest request, @Valid String organ) {
Map<String, Organ> organs = organProxy.findAllOrganByParentAndOrgi(super.getOrgan(request), super.getOrgi(request));
Map<String, Organ> organs = organProxy.findAllOrganByParentAndOrgi(super.getOrgan(request),
super.getOrgi(request));
map.addAttribute("userList", userProxy.findUserInOrgans(organs.keySet()));
Organ organData = organRepository.findByIdAndOrgi(organ, super.getOrgi());
map.addAttribute("userOrganList", userProxy
@ -194,7 +196,6 @@ public class OrganController extends Handler {
return request(super.createView("/admin/organ/seluser"));
}
/**
* 执行添加用户到组织中
*
@ -208,8 +209,7 @@ public class OrganController extends Handler {
public ModelAndView saveuser(
HttpServletRequest request,
final @Valid String[] users,
final @Valid String organ
) {
final @Valid String organ) {
logger.info("[saveuser] save users {} into organ {}", StringUtils.join(users, ","), organ);
final User loginUser = super.getUser(request);
@ -271,15 +271,15 @@ public class OrganController extends Handler {
public ModelAndView userroledelete(
final HttpServletRequest request,
final @Valid String id,
final @Valid String organ
) {
final @Valid String organ) {
logger.info("[userroledelete] user id {}, organ {}", id, organ);
if (id != null) {
List<OrganUser> organUsers = organUserRes.findByUserid(id);
if (organUsers.size() > 1) {
organUserRes.deleteOrganUserByUseridAndOrgan(id, organ);
} else {
return request(super.createView("redirect:/admin/organ/index.html?organ=" + organ + "&msg=not_allow_remove_user"));
return request(super.createView(
"redirect:/admin/organ/index.html?organ=" + organ + "&msg=not_allow_remove_user"));
}
}
return request(super.createView("redirect:/admin/organ/index.html?organ=" + organ));
@ -320,7 +320,6 @@ public class OrganController extends Handler {
return request(super.createView("/admin/organ/area"));
}
@RequestMapping("/area/update")
@Menu(type = "admin", subtype = "organ")
public ModelAndView areaupdate(HttpServletRequest request, @Valid Organ organ) {
@ -347,11 +346,13 @@ public class OrganController extends Handler {
msg = "admin_oran_not_delete";
} else if (organ != null) {
List<OrganUser> organUsers = organUserRes.findByOrgan(organ.getId());
organUserRes.deleteInBatch(organUsers);
organRepository.delete(organ);
} else {
msg = "admin_organ_not_exist";
if (organUsers.size() > 0) {
msg = "admin_oran_not_empty";
} else {
organRepository.delete(organ);
}
}
return request(super.createView("redirect:/admin/organ/index.html?msg=" + msg));
}

View File

@ -165,17 +165,19 @@ block content
var layer = layui.layer;
var msg = '#{msg}';
if (msg == 'admin_organ_update_name_not') {
layer.msg('组织机构分类名已存在!', {icon: 2, time: 1500})
layer.msg('组织机构分类名已存在!', {icon: 2, time: 2000})
} else if (msg == 'admin_oran_not_delete') {
layer.msg('无法删除,因为存在子组织', {icon: 2, time: 1500})
layer.msg('无法删除,因为存在子组织', {icon: 2, time: 2000})
} else if (msg == 'admin_oran_not_empty') {
layer.msg('无法删除,因为组织下存在用户', {icon: 2, time: 2000})
} else if (msg == 'admin_organ_update_success') {
layer.msg('修改组织成功', {icon: 1, time: 1500})
layer.msg('修改组织成功', {icon: 1, time: 2000})
} else if (msg == 'admin_organ_new_success') {
layer.msg('新建组织成功', {icon: 1, time: 1500})
layer.msg('新建组织成功', {icon: 1, time: 2000})
} else if (msg == 'admin_organ_update_not_standard') {
layer.msg('修改无法完成,上级机构选择错误', {icon: 2, time: 1500})
layer.msg('修改无法完成,上级机构选择错误', {icon: 2, time: 2000})
} else if (msg == 'not_allow_remove_user') {
layer.msg('用户只有一个组织,不允许移除', {icon: 2, time: 1500})
layer.msg('用户只有一个组织,不允许移除', {icon: 2, time: 2000})
}
});