|
@@ -1,254 +0,0 @@
|
|
|
-package com.bosshand.virgo.service;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.bosshand.virgo.core.dao.*;
|
|
|
-import com.bosshand.virgo.core.model.*;
|
|
|
-import com.bosshand.virgo.util.StringUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class DepartmentService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MgrDepartmentDao mgrDepartmentDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MgrOrganizationTypeDao mgrOrganizationTypeDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MgrOrganizationDao mgrOrganizationDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MgrUserRoleDao mgrUserRoleDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MgrUserDao mgrUserDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AttendanceDao attendanceDao;
|
|
|
-
|
|
|
- public void saveDepartment(MgrDepartment department) {
|
|
|
- mgrDepartmentDao.insert(department);
|
|
|
- }
|
|
|
-
|
|
|
- public void deleteDepartment(int id) {
|
|
|
- mgrDepartmentDao.delete(id);
|
|
|
- }
|
|
|
-
|
|
|
- public void updateDepartment(MgrDepartment department) {
|
|
|
- mgrDepartmentDao.update(department);
|
|
|
- }
|
|
|
-
|
|
|
- public List<MgrOrganization> getListByProjectId(long projectId) {
|
|
|
- List<MgrDepartment> list = mgrDepartmentDao.getProjectId(projectId);
|
|
|
- if (list.size() > 0) {
|
|
|
- Set<Long> set = new HashSet<>();
|
|
|
- list.forEach(ls -> set.add(ls.getOrganizationId()));
|
|
|
-
|
|
|
- MgrDepartment department = new MgrDepartment();
|
|
|
- department.setProjectId(projectId);
|
|
|
-
|
|
|
- List<MgrOrganization> organizationList = mgrOrganizationDao.organizationByIds(new ArrayList<Long>(set));
|
|
|
- for (MgrOrganization organization : organizationList) {
|
|
|
- department.setOrganizationId(organization.getId());
|
|
|
- organization.setDepartmentList(getList(department));
|
|
|
- }
|
|
|
- return organizationList;
|
|
|
- }
|
|
|
- return new ArrayList<MgrOrganization>();
|
|
|
- }
|
|
|
-
|
|
|
- // get hierarchy
|
|
|
- public List<MgrDepartment> getList(MgrDepartment department) {
|
|
|
- List<MgrUserRole> mList = mgrUserRoleDao.getOrganizationId(department.getOrganizationId());
|
|
|
- List<MgrDepartment> list = mgrDepartmentDao.getList(department);
|
|
|
- list.forEach(ls -> ls.setUsers(getUserListByDepartment(mList, ls.getId())));
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- list.forEach(ls -> {
|
|
|
- if (ls.getParentId() == -1) {
|
|
|
- ids.add(ls.getId());
|
|
|
- }
|
|
|
- });
|
|
|
- List<MgrDepartment> hierarchy = new ArrayList<>();
|
|
|
- if (ids.size() > 0) {
|
|
|
- ids.forEach(ll -> hierarchy.add(getNodeTreeById(ll, list)));
|
|
|
- }
|
|
|
- return hierarchy;
|
|
|
- }
|
|
|
-
|
|
|
- private MgrDepartment getNodeTreeById(int id, List<MgrDepartment> list) {
|
|
|
- MgrDepartment node = null;
|
|
|
- List<MgrDepartment> departmentList = list;
|
|
|
- for (MgrDepartment data : departmentList) {
|
|
|
- if (data.getId() == id) {
|
|
|
- node = data;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (node != null) {
|
|
|
- node.setChildren(getChildNode(node.getId(), departmentList));
|
|
|
- }
|
|
|
- return node;
|
|
|
- }
|
|
|
-
|
|
|
- private List<MgrDepartment> getChildNode(int parentId, List<MgrDepartment> list) {
|
|
|
- List<MgrDepartment> nodeList = new ArrayList<MgrDepartment>();
|
|
|
- nodeList.clear();
|
|
|
- for (MgrDepartment data : list) {
|
|
|
- if (data.getParentId() == parentId) {
|
|
|
- nodeList.add(data);
|
|
|
- }
|
|
|
- }
|
|
|
- if (nodeList.size() > 0) {
|
|
|
- for (MgrDepartment data : nodeList) {
|
|
|
- List<MgrDepartment> childList = getChildNode(data.getId(), list);
|
|
|
- data.setChildren(childList);
|
|
|
- }
|
|
|
- }
|
|
|
- return nodeList;
|
|
|
- }
|
|
|
-
|
|
|
- private List<MgrUser> getUserListByDepartment(List<MgrUserRole> list, int departmentId) {
|
|
|
-
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
-
|
|
|
- List<MgrUserRole> mlist = new ArrayList<>();
|
|
|
-
|
|
|
- list.forEach(ls -> {
|
|
|
- String departments = ls.getDepartments();
|
|
|
- if (StringUtil.notBlank(departments)) {
|
|
|
- String[] split = departments.split(",");
|
|
|
- for (int i = 0; i < split.length; i++) {
|
|
|
- if(StringUtil.notBlank(split[i])) {
|
|
|
- if (Integer.parseInt(split[i]) == departmentId) {
|
|
|
- userIds.add(ls.getUserId());
|
|
|
- mlist.add(ls);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (userIds.size() == 0) {
|
|
|
- return new ArrayList<MgrUser>();
|
|
|
- }
|
|
|
-
|
|
|
- List<MgrUser> userList = mgrUserDao.getIds(userIds);
|
|
|
- for (MgrUser user : userList) {
|
|
|
- for (MgrUserRole ur : mlist) {
|
|
|
- if (user.getId() == ur.getUserId()) {
|
|
|
- user.setMenus(ur.getMenus());
|
|
|
- user.setResources(ur.getResources());
|
|
|
- user.setRoles(ur.getRoles());
|
|
|
- user.setOrganizationTypeRoles(ur.getOrganizationTypeRoles());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return userList;
|
|
|
- }
|
|
|
-
|
|
|
- // generation hierarchy
|
|
|
- public void saveDepartmentHierarchy(long organizationTypeId, long organizationId, long projectId) {
|
|
|
- MgrOrganizationType organizationType = mgrOrganizationTypeDao.get(organizationTypeId);
|
|
|
- String hierarchy = organizationType.getHierarchy();
|
|
|
- recursion(organizationId, projectId, hierarchy, -1);
|
|
|
- }
|
|
|
-
|
|
|
- private void recursion(long organizationId, long projectId, String st, int parentId) {
|
|
|
- JSONArray list = JSON.parseArray(st);
|
|
|
- if (list.size() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- MgrDepartment d = new MgrDepartment();
|
|
|
- d.setOrganizationId(organizationId);
|
|
|
- d.setProjectId(projectId);
|
|
|
- d.setParentId(parentId);
|
|
|
- d.setTemplateId(Long.parseLong(list.getJSONObject(i).get("id").toString()));
|
|
|
- d.setName((String) list.getJSONObject(i).get("name"));
|
|
|
- mgrDepartmentDao.insert(d);
|
|
|
- recursion(organizationId, projectId, JSON.toJSONString(list.getJSONObject(i).get("children")), d.getId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> statisticalListByProjectId(long projectId, String startDate, String endDate) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- List<MgrDepartment> list = mgrDepartmentDao.getProjectId(projectId);
|
|
|
- if (list.size() > 0) {
|
|
|
- Set<Long> set = new HashSet<>();
|
|
|
- list.forEach(ls -> set.add(ls.getOrganizationId()));
|
|
|
- MgrDepartment department = new MgrDepartment();
|
|
|
- department.setProjectId(projectId);
|
|
|
- List<MgrOrganization> organizationList = mgrOrganizationDao.organizationByIds(new ArrayList<Long>(set));
|
|
|
- int con = 0;
|
|
|
- int si = 0;
|
|
|
- Attendance attendance = new Attendance();
|
|
|
- attendance.setStartDate(startDate + " 00:00:00");
|
|
|
- attendance.setEndDate(endDate + " 23:59:59");
|
|
|
- for (MgrOrganization organization : organizationList) {
|
|
|
- department.setOrganizationId(organization.getId());
|
|
|
- List<MgrUserRole> mList = mgrUserRoleDao.getOrganizationId(department.getOrganizationId());
|
|
|
- List<MgrDepartment> alist = mgrDepartmentDao.getList(department);
|
|
|
- int cont = 0;
|
|
|
- for (MgrDepartment mgrDepartment : alist) {
|
|
|
- int size = getUserListByDepartment(mList, mgrDepartment.getId()).size();
|
|
|
- cont += size;
|
|
|
- }
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("all", cont);
|
|
|
- attendance.setProjectId(projectId);
|
|
|
- attendance.setOrganizationId(organization.getId());
|
|
|
- List<Attendance> users = attendanceDao.getByUser(attendance);
|
|
|
- json.put("sign", users.size());
|
|
|
- map.put(organization.getName(), json);
|
|
|
- con += cont;
|
|
|
- si += users.size();
|
|
|
- }
|
|
|
- map.put("项目总人数", con);
|
|
|
- map.put("allSign", si);
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public String personByProjectId(long projectId) {
|
|
|
- List<MgrDepartment> list = mgrDepartmentDao.getProjectId(projectId);
|
|
|
- JSONArray ja = new JSONArray();
|
|
|
- if (list.size() > 0) {
|
|
|
- Set<Long> set = new HashSet<>();
|
|
|
- list.forEach(ls -> set.add(ls.getOrganizationId()));
|
|
|
- MgrDepartment department = new MgrDepartment();
|
|
|
- department.setProjectId(projectId);
|
|
|
- List<MgrOrganization> organizationList = mgrOrganizationDao.organizationByIds(new ArrayList<Long>(set));
|
|
|
- for (MgrOrganization organization : organizationList) {
|
|
|
- JSONObject js = new JSONObject();
|
|
|
- department.setOrganizationId(organization.getId());
|
|
|
- List<MgrUserRole> mList = mgrUserRoleDao.getOrganizationId(department.getOrganizationId());
|
|
|
- List<MgrDepartment> alist = mgrDepartmentDao.getList(department);
|
|
|
- Set<MgrUser> set1 = new HashSet<>();
|
|
|
- for (MgrDepartment mgrDepartment : alist) {
|
|
|
- List<MgrUser> userListByDepartment = getUserListByDepartment(mList, mgrDepartment.getId());
|
|
|
- userListByDepartment.forEach(ls -> set1.add(ls));
|
|
|
- }
|
|
|
- js.put("organizationName", organization.getName());
|
|
|
- js.put("organizationId", organization.getId());
|
|
|
- JSONArray jaa = new JSONArray();
|
|
|
- for (MgrUser u : set1) {
|
|
|
- JSONObject jss = new JSONObject();
|
|
|
- jss.put("userId", u.getId());
|
|
|
- jss.put("userName", u.getName());
|
|
|
- jaa.add(jss);
|
|
|
- }
|
|
|
- js.put("userIds", jaa);
|
|
|
- ja.add(js);
|
|
|
- }
|
|
|
- }
|
|
|
- return JSONObject.toJSONString(ja);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|