All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.mingsoft.organization.biz.impl.OrganizationBizImpl Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
/**
The MIT License (MIT) * Copyright (c) 2019 铭飞科技

 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package net.mingsoft.organization.biz.impl;

import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao;
import java.util.*;
import net.mingsoft.organization.entity.OrganizationEntity;
import net.mingsoft.organization.biz.IOrganizationBiz;
import net.mingsoft.organization.dao.IOrganizationDao;

/**
 * 组织机构管理持久化层
 * @author 铭飞开源团队
 * 创建日期:2020-1-6 14:53:26
* 历史修订:
*/ @Service("organizationorganizationBizImpl") public class OrganizationBizImpl extends BaseBizImpl implements IOrganizationBiz { @Autowired private IOrganizationDao organizationDao; @Override protected IBaseDao getDao() { // TODO Auto-generated method stub return organizationDao; } @Override public void saveEntity(OrganizationEntity entity) { setParentId(entity); super.saveEntity(entity); } @Override public void updateEntity(OrganizationEntity entity) { setParentId(entity); super.updateEntity(entity); setChildParentId(entity); } public List queryChildren(int id) { return organizationDao.queryChildren(id); } @Override public void delete(int[] ids) { List deleteIds=new ArrayList(); for (int id : ids) { OrganizationEntity entity = (OrganizationEntity) organizationDao.getEntity(id); //删除父类 if(entity != null){ entity.setOrganizationParentId(null); List childrenList = organizationDao.queryChildren(id); for(int i = 0; i < childrenList.size(); i++){ //删除子类 deleteIds.add(Integer.parseInt(childrenList.get(i).getId())); } } deleteIds.add(id); } organizationDao.delete(deleteIds.stream().mapToInt(Integer::valueOf).toArray()); } /** * 设置父级Id * @param organizationEntity */ private void setParentId(OrganizationEntity organizationEntity) { if(StringUtils.isNotEmpty(organizationEntity.getOrganizationId())&&Integer.parseInt(organizationEntity.getOrganizationId())>0) { OrganizationEntity entity = (OrganizationEntity)organizationDao.getEntity(Integer.parseInt(organizationEntity.getOrganizationId())); if(StringUtils.isEmpty(entity.getOrganizationParentId())) { organizationEntity.setOrganizationParentId(entity.getId()); } else { organizationEntity.setOrganizationParentId(entity.getOrganizationParentId()+","+entity.getId()); } }else { organizationEntity.setOrganizationParentId(null); } } /** * 给所有子集设置父级Id * @param organizationEntity */ private void setChildParentId(OrganizationEntity organizationEntity) { OrganizationEntity entity=new OrganizationEntity(); entity.setOrganizationId(organizationEntity.getId()); List list = organizationDao.query(entity); list.forEach(x->{ if(StringUtils.isEmpty(organizationEntity.getOrganizationParentId())) { x.setOrganizationParentId(organizationEntity.getId()); } else { x.setOrganizationParentId(organizationEntity.getOrganizationParentId()+","+organizationEntity.getId()); } super.updateEntity(x); setChildParentId(x); }); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy