Commit a01aae81 by shiwenbo

处理部门人员管理与权限管理功能中的部门和人员可选范围

parent 1ad2bf1e
...@@ -71,6 +71,7 @@ public final class AuthMgrConstants { ...@@ -71,6 +71,7 @@ public final class AuthMgrConstants {
String PARAMETER_SEARCH = " staff.name like :staffName "; String PARAMETER_SEARCH = " staff.name like :staffName ";
String PARAMETER_user_enabled =" staff.user.enabled=:enabled "; String PARAMETER_user_enabled =" staff.user.enabled=:enabled ";
String PARAMETER_user_locked =" staff.user.locked=:locked "; String PARAMETER_user_locked =" staff.user.locked=:locked ";
String PARAMETER_relation_department = " staff.department.paths like :relationDepartmentId ";
} }
} }
...@@ -9,11 +9,11 @@ public interface AuthManagerDao { ...@@ -9,11 +9,11 @@ public interface AuthManagerDao {
List<StaffInfo> getEnabledStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked); List<StaffInfo> getEnabledStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked);
List<StaffInfo> getStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked, Boolean enabled); List<StaffInfo> getStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked, Boolean enabled, UUID relationDepartmentId);
Integer getEnabledStaffCount(UUID roleId, UUID deptId, String searchStr); Integer getEnabledStaffCount(UUID roleId, UUID deptId, String searchStr);
Integer getStaffCount(UUID roleId, UUID deptId, String searchStr, Boolean enabled); Integer getStaffCount(UUID roleId, UUID deptId, String searchStr, Boolean enabled, UUID relationDepartmentId);
} }
...@@ -22,11 +22,11 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -22,11 +22,11 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
@Override @Override
public List<StaffInfo> getEnabledStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked) { public List<StaffInfo> getEnabledStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked) {
return this.getStaffInfo(roleId, deptId, searchStr, pageNo, pageSize, locked, null); return this.getStaffInfo(roleId, deptId, searchStr, pageNo, pageSize, locked, null, null);
} }
@Override @Override
public List<StaffInfo> getStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked,Boolean enabled) { public List<StaffInfo> getStaffInfo(UUID roleId, UUID deptId, String searchStr, Integer pageNo, Integer pageSize,Integer locked,Boolean enabled,UUID relationDepartmentId) {
return template.execute(new HibernateCallback<List<StaffInfo>>(){ return template.execute(new HibernateCallback<List<StaffInfo>>(){
@Override @Override
public List<StaffInfo> doInHibernate(Session session) throws HibernateException { public List<StaffInfo> doInHibernate(Session session) throws HibernateException {
...@@ -43,6 +43,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -43,6 +43,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
if(locked!=null){ if(locked!=null){
hql+=AuthMgrConstants.HQL.PARAMETER_user_locked+" and "; hql+=AuthMgrConstants.HQL.PARAMETER_user_locked+" and ";
} }
if(relationDepartmentId!=null) {
hql+=AuthMgrConstants.HQL.PARAMETER_relation_department+ " and ";
}
hql+=AuthMgrConstants.HQL.PARAMETER_user_enabled; hql+=AuthMgrConstants.HQL.PARAMETER_user_enabled;
// hql +=" 1=1 "; // hql +=" 1=1 ";
Query<StaffInfo> query = session.createQuery(hql, StaffInfo.class); Query<StaffInfo> query = session.createQuery(hql, StaffInfo.class);
...@@ -63,6 +66,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -63,6 +66,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
if(locked!=null){ if(locked!=null){
query.setParameter("locked", locked==1?false:true); query.setParameter("locked", locked==1?false:true);
} }
if(relationDepartmentId != null) {
query.setParameter("relationDepartmentId", "%" + relationDepartmentId + "%");
}
query.setFirstResult((pageNo -1)*pageSize); query.setFirstResult((pageNo -1)*pageSize);
query.setMaxResults(pageSize); query.setMaxResults(pageSize);
return query.getResultList(); return query.getResultList();
...@@ -73,11 +79,11 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -73,11 +79,11 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
@Override @Override
public Integer getEnabledStaffCount(UUID roleId, UUID deptId, String searchStr) { public Integer getEnabledStaffCount(UUID roleId, UUID deptId, String searchStr) {
return this.getStaffCount(roleId, deptId, searchStr, null); return this.getStaffCount(roleId, deptId, searchStr, null, null);
} }
@Override @Override
public Integer getStaffCount(UUID roleId, UUID deptId, String searchStr, Boolean enabled) { public Integer getStaffCount(UUID roleId, UUID deptId, String searchStr, Boolean enabled, UUID relationDepartmentId) {
return template.execute(new HibernateCallback<Integer>(){ return template.execute(new HibernateCallback<Integer>(){
@Override @Override
...@@ -95,6 +101,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -95,6 +101,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
if(enabled!=null) { if(enabled!=null) {
hql+=AuthMgrConstants.HQL.PARAMETER_user_enabled + " and "; hql+=AuthMgrConstants.HQL.PARAMETER_user_enabled + " and ";
} }
if(relationDepartmentId!=null) {
hql+=AuthMgrConstants.HQL.PARAMETER_relation_department + " and ";
}
hql +=" 1=1 "; hql +=" 1=1 ";
Query<Long> query = session.createQuery(hql, Long.class); Query<Long> query = session.createQuery(hql, Long.class);
...@@ -110,6 +119,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao { ...@@ -110,6 +119,9 @@ public class AuthManagerDaoImpl implements AuthManagerDao {
if(enabled!=null) { if(enabled!=null) {
query.setParameter("enabled", enabled); query.setParameter("enabled", enabled);
} }
if(relationDepartmentId != null) {
query.setParameter("relationDepartmentId", "%" + relationDepartmentId + "%");
}
return query.getSingleResult().intValue(); return query.getSingleResult().intValue();
}}); }});
} }
......
...@@ -5,12 +5,14 @@ import java.util.ArrayList; ...@@ -5,12 +5,14 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
...@@ -19,6 +21,7 @@ import org.springframework.util.Assert; ...@@ -19,6 +21,7 @@ import org.springframework.util.Assert;
import com.beecode.amino.core.Amino; import com.beecode.amino.core.Amino;
import com.beecode.bap.log.LogConstants; import com.beecode.bap.log.LogConstants;
import com.beecode.bap.log.service.LogService; import com.beecode.bap.log.service.LogService;
import com.beecode.bap.staff.BapContext;
import com.beecode.bap.staff.Staff; import com.beecode.bap.staff.Staff;
import com.beecode.bap.staff.service.StaffService; import com.beecode.bap.staff.service.StaffService;
import com.beecode.bap2.common.license.LicenseProperty; import com.beecode.bap2.common.license.LicenseProperty;
...@@ -36,6 +39,8 @@ import com.beecode.bcp.authz.service.RoleService; ...@@ -36,6 +39,8 @@ import com.beecode.bcp.authz.service.RoleService;
import com.beecode.bcp.group.service.GroupService; import com.beecode.bcp.group.service.GroupService;
import com.beecode.bcp.type.KClass; import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.bcp.type.support.NullObject;
import com.beecode.inz.authmgr.common.AuthMgrConstants.RoleRootGroup; import com.beecode.inz.authmgr.common.AuthMgrConstants.RoleRootGroup;
import com.beecode.inz.authmgr.dao.AuthManagerDao; import com.beecode.inz.authmgr.dao.AuthManagerDao;
import com.beecode.inz.authmgr.domain.Page; import com.beecode.inz.authmgr.domain.Page;
...@@ -48,6 +53,9 @@ import com.jiuqi.np.tenant.Tenant; ...@@ -48,6 +53,9 @@ import com.jiuqi.np.tenant.Tenant;
import com.jiuqi.np.tenant.spring.TenantRuntime; import com.jiuqi.np.tenant.spring.TenantRuntime;
public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEventPublisherAware { public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEventPublisherAware {
@Autowired
private BapContext bapContext;
@Autowired @Autowired
private StaffService staffService; private StaffService staffService;
...@@ -219,10 +227,16 @@ public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEve ...@@ -219,10 +227,16 @@ public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEve
if (pageSize == null) { if (pageSize == null) {
pageSize = Integer.MAX_VALUE; pageSize = Integer.MAX_VALUE;
} }
UUID relationDepartmentId = this.getCurrentLoginRegionalCompanyRelationDepartmentId();
Page<StaffInfo> page = new Page<>(); Page<StaffInfo> page = new Page<>();
List<StaffInfo> staffInfos = authManagerDao.getStaffInfo(roleId, deptId, searchStr, pageNo, pageSize,locked , enabled); if(relationDepartmentId == null) {
page.setItemCount(0);
page.setDatas(null);
return page;
}
List<StaffInfo> staffInfos = authManagerDao.getStaffInfo(roleId, deptId, searchStr, pageNo, pageSize,locked , enabled, relationDepartmentId);
page.setItemCount(authManagerDao.getStaffCount(roleId, deptId, searchStr, enabled)); page.setItemCount(authManagerDao.getStaffCount(roleId, deptId, searchStr, enabled, relationDepartmentId));
page.setPageNo(pageNo); page.setPageNo(pageNo);
page.setPageSize(pageSize); page.setPageSize(pageSize);
staffInfos.forEach(staff -> staff.setRoles(getRoleByUser(staff.getUserId()))); staffInfos.forEach(staff -> staff.setRoles(getRoleByUser(staff.getUserId())));
...@@ -230,6 +244,20 @@ public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEve ...@@ -230,6 +244,20 @@ public class AuthManagerServiceImpl implements AuthManagerService,ApplicationEve
return page; return page;
} }
/**
* 获取当前登录的区域公司
* @return
*/
public UUID getCurrentLoginRegionalCompanyRelationDepartmentId() {
Map<String, String> map = bapContext.getCurrentUserDatas();
String currentRegionalCompany = map.get("currentRegionalCompany");
JSONObject param = new JSONObject(currentRegionalCompany);
if(param.isNull("departmentId")) {
return null;
}
String departmentId = param.getString("departmentId");
return UUID.fromString(departmentId);
}
private List<Role> getRoleByUser(UUID userId) { private List<Role> getRoleByUser(UUID userId) {
return roleService.getByUser(userId).stream() return roleService.getByUser(userId).stream()
......
...@@ -2,7 +2,9 @@ package com.xyst.dinas.biz.web; ...@@ -2,7 +2,9 @@ package com.xyst.dinas.biz.web;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -17,6 +19,9 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -17,6 +19,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.beecode.bap.department.service.DepartmentService; import com.beecode.bap.department.service.DepartmentService;
import com.beecode.bap.staff.Staff;
import com.beecode.bap.staff.service.StaffService;
import com.beecode.bap.staff.util.StaffUtil;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj; import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.biz.enumeration.PlanningCycleEnum; import com.xyst.dinas.biz.enumeration.PlanningCycleEnum;
...@@ -29,6 +34,9 @@ public class DinasCommonController { ...@@ -29,6 +34,9 @@ public class DinasCommonController {
public DepartmentService departmentService; public DepartmentService departmentService;
@Autowired @Autowired
public StaffService staffService;
@Autowired
public PlanningCycleService planningCycleService; public PlanningCycleService planningCycleService;
/** /**
...@@ -58,6 +66,60 @@ public class DinasCommonController { ...@@ -58,6 +66,60 @@ public class DinasCommonController {
return list; return list;
} }
/**
* @Description: 根据部门id查询该部门及其子部门的职员列表(包括该部门自身)
* @param id
* @return return_type
* @throws
*/
@ResponseBody
@RequestMapping(value = "/dinasBiz/staff/queryStaffByDepartmentId", method = RequestMethod.POST)
public List<Map<String, Object>> queryStaffByDepartmentId(@RequestBody String body) {
JSONObject param = new JSONObject(body);
List<Map<String, Object>> temp = new ArrayList<Map<String, Object>>();
if(param.isNull("id")) {
return null;
}
String departmentId = param.getString("id");
Boolean enable = param.getBoolean("enable");
List<KObject> list = staffService.getAllByDept(UUID.fromString(departmentId));
for(int i = 0; i < list.size(); i++) {
if(list.get(i).get("user").getBoolean("enabled") != enable) {
list.remove(i);
}
}
for (KObject item : list) {
temp.add(toMap(item));
}
return temp;
}
private Map<String, Object> toMap(KObject staff) {
Map<String, Object> map = new HashMap<>();
KObject user = staff.get(Staff.USER);
KObject dept = staff.get(Staff.DEPARTMENT);
map.put(Staff.ID, staff.getUuid(Staff.ID));
map.put(Staff.CODE, staff.getString(Staff.CODE));
map.put(Staff.NAME, staff.getString(Staff.NAME));
map.put(Staff.SHORTNAME, staff.getString(Staff.SHORTNAME));
map.put(Staff.SEX, staff.getInt(Staff.SEX));
map.put(Staff.ENTRYTIME, StaffUtil.instantToLong(staff.getInstant(Staff.ENTRYTIME)));
map.put(Staff.TELEPHONE, staff.getString(Staff.TELEPHONE));
map.put(Staff.DUTY, staff.getString(Staff.DUTY));
map.put(Staff.EMAIL, staff.getString(Staff.EMAIL));
map.put(Staff.BIRTHDAY, StaffUtil.instantToLong(staff.getInstant(Staff.BIRTHDAY)));
map.put(Staff.QQ, staff.getString(Staff.QQ));
map.put(Staff.WECHAT, staff.getString(Staff.WECHAT));
map.put(Staff.PORTRAIT, staff.getString(Staff.PORTRAIT));
map.put(Staff.DEPARTMENTID, dept.getString(Staff.ID));
map.put(Staff.DEPARTMENT, dept.getString(Staff.NAME));
map.put(Staff.USERNAME, user.getString(Staff.USERNAME));
map.put(Staff.CREATETIME, StaffUtil.instantToLong(staff.getInstant(Staff.ENTRYTIME)));
map.put(Staff.LOCKED, user.getBoolean(Staff.LOCKED));
map.put(Staff.ENABLED, user.getBoolean(Staff.ENABLED));
return map;
}
@RequestMapping("/planningCycle/init") @RequestMapping("/planningCycle/init")
public ResponseObj initPlanningCycleData() { public ResponseObj initPlanningCycleData() {
planningCycleService.initData(); planningCycleService.initData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment