464 lines
13 KiB
Java
464 lines
13 KiB
Java
package com.zcloud.service.system.impl;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
import com.zcloud.entity.system.Menu;
|
||
import com.zcloud.mapper.datasource.system.SupervisionDepartmentMapper;
|
||
import com.zcloud.mapper.dsno2.system.Department2Mapper;
|
||
import com.zcloud.util.DateUtil;
|
||
import com.zcloud.util.Jurisdiction;
|
||
import com.zcloud.util.UuidUtil;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import com.zcloud.entity.Page;
|
||
import com.zcloud.entity.PageData;
|
||
import com.zcloud.entity.system.Department;
|
||
import com.zcloud.mapper.datasource.system.DepartmentMapper;
|
||
import com.zcloud.service.system.DepartmentService;
|
||
import com.zcloud.util.Tools;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
/**
|
||
* 说明: 组织机构
|
||
* 创建人:FH Q313596790
|
||
* 官网:
|
||
*/
|
||
@Service(value="departmentService")
|
||
@Transactional //开启事物
|
||
public class DepartmentServiceImpl implements DepartmentService{
|
||
|
||
@Resource
|
||
private DepartmentMapper departmentMapper;
|
||
|
||
@Resource
|
||
private Department2Mapper department2Mapper;
|
||
/**新增
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public void save(PageData pd)throws Exception{
|
||
departmentMapper.save(pd);
|
||
}
|
||
|
||
/**删除
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public void delete(PageData pd)throws Exception{
|
||
departmentMapper.delete(pd);
|
||
}
|
||
|
||
public List<PageData> listTreeManageAndCorp2(PageData pd) throws Exception {
|
||
return departmentMapper.listTreeManageAndCorp2(pd);
|
||
}
|
||
/**修改
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public void edit(PageData pd)throws Exception{
|
||
departmentMapper.edit(pd);
|
||
}
|
||
|
||
/**列表
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
public List<PageData> list(Page page)throws Exception{
|
||
return (List<PageData>)departmentMapper.datalistPage(page);
|
||
}
|
||
|
||
/**通过id获取数据
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public PageData findById(PageData pd)throws Exception{
|
||
return (PageData)departmentMapper.findById(pd);
|
||
}
|
||
/**通过名称获取数据
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public PageData findByName(PageData pd)throws Exception{
|
||
List<PageData> dept = departmentMapper.findByName(pd);
|
||
if(dept != null && dept.size() > 0) {
|
||
return dept.get(0);
|
||
} else {
|
||
return null;
|
||
}
|
||
|
||
}
|
||
|
||
/**通过编码获取数据
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public PageData findByBianma(PageData pd)throws Exception{
|
||
return (PageData)departmentMapper.findByBianma(pd);
|
||
}
|
||
|
||
/**
|
||
* 通过ID获取其子级列表
|
||
* @param parentId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<Department> listSubDepartmentByParentId(String parentId) throws Exception {
|
||
return (List<Department>)departmentMapper.listSubDepartmentByParentId(parentId);
|
||
}
|
||
|
||
/**
|
||
* 获取所有数据并填充每条数据的子级列表(递归处理)
|
||
* @param MENU_ID
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<Department> listAllDepartment(String parentId) throws Exception {
|
||
List<Department> departmentList = this.listSubDepartmentByParentId(parentId);
|
||
for(Department depar : departmentList){
|
||
depar.setTreeurl("department_list.html?DEPARTMENT_ID="+depar.getDEPARTMENT_ID());
|
||
depar.setSubDepartment(this.listAllDepartment(depar.getDEPARTMENT_ID()));
|
||
depar.setTarget("treeFrame");
|
||
depar.setIcon("../../../assets/images/user.gif");
|
||
}
|
||
return departmentList;
|
||
}
|
||
|
||
/**
|
||
* 获取所有数据并填充每条数据的子级列表(递归处理)
|
||
* @param MENU_ID
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<Department> listAllDepartment(String parentId,String url) throws Exception {
|
||
List<Department> departmentList = this.listSubDepartmentByParentId(parentId);
|
||
for(Department depar : departmentList){
|
||
depar.setTreeurl(url+depar.getDEPARTMENT_ID());
|
||
depar.setSubDepartment(this.listAllDepartment(depar.getDEPARTMENT_ID(),url));
|
||
depar.setTarget("treeFrame");
|
||
depar.setIcon("../../../assets/images/user.gif");
|
||
}
|
||
return departmentList;
|
||
}
|
||
|
||
/**
|
||
* 获取所有数据并填充每条数据的子级列表(递归处理)下拉ztree用
|
||
* @param MENU_ID
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<PageData> listAllDepartmentToSelect(String parentId,List<PageData> zdepartmentPdList) throws Exception {
|
||
List<PageData>[] arrayDep = this.listAllbyPd(parentId,zdepartmentPdList);
|
||
List<PageData> departmentPdList = arrayDep[1];
|
||
for(PageData pd : departmentPdList){
|
||
this.listAllDepartmentToSelect(pd.getString("id"),arrayDep[0]);
|
||
}
|
||
return arrayDep[0];
|
||
}
|
||
|
||
/**下拉ztree用
|
||
* @param parentId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public List<PageData>[] listAllbyPd(String parentId,List<PageData> zdepartmentPdList) throws Exception {
|
||
List<Department> departmentList = this.listSubDepartmentByParentId(parentId);
|
||
List<PageData> departmentPdList = new ArrayList<PageData>();
|
||
for(Department depar : departmentList){
|
||
PageData pd = new PageData();
|
||
pd.put("id", depar.getDEPARTMENT_ID());
|
||
pd.put("parentId", depar.getPARENT_ID());
|
||
pd.put("name", depar.getNAME());
|
||
pd.put("icon", "../../../assets/images/user.gif");
|
||
departmentPdList.add(pd);
|
||
zdepartmentPdList.add(pd);
|
||
}
|
||
List<PageData>[] arrayDep = new List[2];
|
||
arrayDep[0] = zdepartmentPdList;
|
||
arrayDep[1] = departmentPdList;
|
||
return arrayDep;
|
||
}
|
||
|
||
/**获取某个部门所有下级部门ID(返回拼接字符串 in的形式, ('a','b','c'))
|
||
* @param DEPARTMENT_ID
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public String getDEPARTMENT_IDS(String DEPARTMENT_ID) throws Exception {
|
||
DEPARTMENT_ID = Tools.notEmpty(DEPARTMENT_ID)?DEPARTMENT_ID:"0";
|
||
List<PageData> zdepartmentPdList = new ArrayList<PageData>();
|
||
zdepartmentPdList = this.listAllDepartmentToSelect(DEPARTMENT_ID,zdepartmentPdList);
|
||
StringBuffer sb = new StringBuffer();
|
||
sb.append("");
|
||
for(PageData dpd : zdepartmentPdList){
|
||
sb.append(dpd.getString("id"));
|
||
sb.append(",");
|
||
}
|
||
sb.append("'fh'");
|
||
return sb.toString();
|
||
}
|
||
|
||
/**通过条件获取全部
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public List<PageData> listAll(PageData pd)throws Exception{
|
||
return (List<PageData>)departmentMapper.listAll(pd);
|
||
}
|
||
|
||
/**通过部门名称、分公司ID查数据
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public List<PageData> isrepeat(PageData pd)throws Exception{
|
||
return (List<PageData>)departmentMapper.isrepeat(pd);
|
||
}
|
||
|
||
/**通过企业主部门
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public PageData findByCorpId(PageData pd)throws Exception{
|
||
return departmentMapper.findByCorpId(pd);
|
||
}
|
||
/**列表 关联 部门级别名称
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
@Override
|
||
public List<PageData> listForLevelName(Page page) throws Exception {
|
||
// TODO Auto-generated method stub
|
||
return departmentMapper.forLevelNamedatalistPage(page);
|
||
}
|
||
|
||
/**
|
||
* 查询公司部门总数
|
||
* @param pd
|
||
* @return
|
||
*/
|
||
public int getDepCount(PageData pd)throws Exception{
|
||
return departmentMapper.getDepCount(pd);
|
||
}
|
||
|
||
/**
|
||
* 查询公司检查过清单的部门总数
|
||
* @param pd
|
||
* @return
|
||
*/
|
||
public int getWorkedDepCount(PageData pd)throws Exception{
|
||
return departmentMapper.getWorkedDepCount(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> statisticsByCorp(PageData pd) throws Exception {
|
||
return departmentMapper.statisticsByCorp(pd);
|
||
}
|
||
|
||
/**
|
||
* 查询分公司的安全管理部门
|
||
* @param pd
|
||
* @return
|
||
*/
|
||
@Override
|
||
public List<PageData> saftmanagelist(PageData pd) throws Exception {
|
||
return departmentMapper.saftmanagelist(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listTreeCorpDept(PageData pd) throws Exception {
|
||
return departmentMapper.listTreeCorpDept(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listDept(PageData pd) throws Exception {
|
||
return departmentMapper.listDept(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listDept(Page page) throws Exception {
|
||
return departmentMapper.Dept(page);
|
||
}
|
||
|
||
/**修改 部门的主管领导或者 主要负责人
|
||
* @param pd
|
||
* @throws Exception
|
||
*/
|
||
public void editByLeaderOrCharge(PageData pd)throws Exception{
|
||
departmentMapper.editByLeaderOrCharge(pd);
|
||
}
|
||
@Override
|
||
public List<PageData> saftpersonlist(PageData pd) throws Exception {
|
||
return departmentMapper.saftpersonlist(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listForDoor(PageData pd) throws Exception {
|
||
return departmentMapper.listForDoor(pd);
|
||
}
|
||
|
||
public List<PageData> getGenealogy(PageData pd) throws Exception{
|
||
PageData information = departmentMapper.findById(pd);
|
||
if (information == null || information.size() < 0){
|
||
return null;
|
||
}
|
||
information.put("level",0);
|
||
List<PageData> result = new ArrayList<>();
|
||
if (information.getString("PARENT_ID").equals("0")){
|
||
result.add(information);
|
||
return result;
|
||
}
|
||
|
||
if (information.getString("PARENT_ID").equals(information.getString("CORPINFO_ID"))){
|
||
result.add(information);
|
||
return result;
|
||
}
|
||
|
||
result.add(information);
|
||
getGenealogyUtil(information.getString("PARENT_ID"),result,1);
|
||
|
||
result = result.stream().sorted((o1,o2) -> new BigDecimal(o2.get("level").toString()).compareTo(new BigDecimal(o1.get("level").toString()))).collect(Collectors.toList());
|
||
|
||
return result;
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listTreeManageAndCorpNum(PageData pd) {
|
||
return departmentMapper.listTreeManageAndCorpNum(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> islistAll(PageData pd) {
|
||
return departmentMapper.islistAll(pd);
|
||
}
|
||
|
||
private List<PageData> getGenealogyUtil(String id,List<PageData> list,int level) throws Exception{
|
||
PageData condition = new PageData();
|
||
condition.put("DEPARTMENT_ID",id);
|
||
PageData parent = departmentMapper.findById(condition);
|
||
parent.put("level",level);
|
||
list.add(parent);
|
||
if (parent.getString("PARENT_ID").equals(parent.getString("CORPINFO_ID"))){
|
||
return list;
|
||
}
|
||
return getGenealogyUtil(parent.getString("PARENT_ID"),list,++level);
|
||
}
|
||
/**
|
||
* 获取所有数据并填充每条数据的子级列表(递归处理)
|
||
* @param MENU_ID
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<Department> listAllDepartmentV2(String parentId,String url) throws Exception {
|
||
String CORPINFO_ID = Jurisdiction.getCORPINFO_ID();
|
||
List<Department> listAll = departmentMapper.listDepartAllByCorpinfoId(CORPINFO_ID);
|
||
Map<String,List<Department>> listAllMap = new HashMap<>();
|
||
for (Department itemList: listAll){
|
||
String parentID = itemList.getPARENT_ID();
|
||
List<Department> item = new ArrayList<>();
|
||
if(listAllMap.containsKey(parentID)){
|
||
item = listAllMap.get(parentID);
|
||
}
|
||
item.add(itemList);
|
||
listAllMap.put(parentID,item);
|
||
}
|
||
List<Department> departmentList = this.listAllDigui("0",listAllMap,url); //获取所有菜单
|
||
return departmentList;
|
||
}
|
||
|
||
public List<Department> listAllDigui(String parentId, Map<String,List<Department>> allList,String url) throws Exception {
|
||
List<Department> itemList = this.listSubMenuByParentId(parentId,allList); //更具pid 获取数据
|
||
for(Department depar : itemList){
|
||
depar.setTreeurl(url+depar.getDEPARTMENT_ID());
|
||
depar.setSubDepartment(this.listAllDigui(depar.getDEPARTMENT_ID(),allList,url));
|
||
depar.setTarget("treeFrame");
|
||
depar.setIcon("../../../assets/images/user.gif");
|
||
}
|
||
return itemList;
|
||
}
|
||
public List<Department> listSubMenuByParentId (String parentId,Map<String,List<Department>> allList){ //更具pid 获取数据
|
||
List<Department> menuList = new ArrayList<>();
|
||
if(allList.containsKey(parentId)){
|
||
menuList = allList.get(parentId);
|
||
}
|
||
return menuList;
|
||
}
|
||
public List<PageData> getSonIdsByParid(PageData pd) throws Exception {
|
||
return departmentMapper.getSonIdsByParid(pd);
|
||
}
|
||
|
||
public Map<String,String> getDepartMapFroExcel (PageData pd) throws Exception{
|
||
Map<String,String> reMap = new HashMap<>();
|
||
List<PageData> departAllList = departmentMapper.listAll(pd);
|
||
for (PageData data :departAllList){
|
||
if (reMap.containsKey(data.getString("NAME"))) {
|
||
reMap.put(data.getString("NAME"),"-1");
|
||
}else {
|
||
reMap.put(data.getString("NAME"),data.getString("DEPARTMENT_ID"));
|
||
}
|
||
}
|
||
return reMap;
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listTreeManageAndCorp1(PageData pd) throws Exception {
|
||
return departmentMapper.listTreeManageAndCorp1(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listTreeManageAndCorpForPcPunishThePerson(PageData pd) throws Exception {
|
||
return departmentMapper.listTreeManageAndCorpForPcPunishThePerson(pd);
|
||
}
|
||
|
||
@Override
|
||
public PageData getDepartmentInfo(PageData pd) throws Exception {
|
||
return departmentMapper.getInfo(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> listTreeManageAndCorpHasOrder(PageData pd) {
|
||
return departmentMapper.listTreeManageAndCorpHasOrder(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<Department> listAllCorpDepartment(String parentId) throws Exception{
|
||
List<Department> departmentList = this.listSubCorpDepartmentByParentId(parentId);
|
||
for(Department depar : departmentList){
|
||
depar.setTreeurl("department_list.html?DEPARTMENT_ID="+depar.getDEPARTMENT_ID());
|
||
depar.setSubDepartment(this.listAllCorpDepartment(depar.getDEPARTMENT_ID()));
|
||
depar.setTarget("treeFrame");
|
||
depar.setIcon("../../../assets/images/user.gif");
|
||
}
|
||
return departmentList;
|
||
}
|
||
|
||
@Override
|
||
public PageData getCorpDepartment(PageData condition) throws Exception {
|
||
return departmentMapper.findByCorpDepartmentId(condition);
|
||
}
|
||
|
||
@Override
|
||
public int getDepartmentCount(PageData pageData) {
|
||
return departmentMapper.getDepartmentCount(pageData);
|
||
}
|
||
|
||
/**
|
||
* 通过ID获取其子级列表
|
||
* @param parentId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public List<Department> listSubCorpDepartmentByParentId(String parentId) throws Exception {
|
||
return departmentMapper.listSubCorpDepartmentByParentId(parentId);
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|