| | |
| | | import com.moral.mapper.OrganizationMapper;
|
| | | import com.moral.mapper.OrganizationRelationMapper;
|
| | | import com.moral.service.OrganizationService;
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.springframework.data.annotation.Transient;
|
| | | import org.springframework.stereotype.Service;
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | | import tk.mybatis.mapper.entity.Example.Criteria;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import java.util.*;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import static com.moral.common.bean.Constants.IS_DELETE_FALSE;
|
| | |
|
| | |
| | | return organizations;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public PageBean queryByPageBean(PageBean pageBean){
|
| | | Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
|
| | | List<Example.Criteria> criteriaList = example.getOredCriteria();
|
| | |
| | | }else{
|
| | | organizationMapper.updateByPrimaryKey(organization);
|
| | | }
|
| | | //更新父组织关系
|
| | | addOrModifyOrgRelation(organization);
|
| | | }
|
| | | catch (Exception ex){
|
| | | throw ex;
|
| | | }
|
| | | }
|
| | |
|
| | | @Transient
|
| | | private void addOrModifyOrgRelation(Organization organization){
|
| | | OrganizationRelation relation = new OrganizationRelation();
|
| | | relation.setChildId(organization.getId());
|
| | | List<OrganizationRelation> relations = organizationRelationMapper.select(relation);
|
| | | if(CollectionUtils.isEmpty(relations)){
|
| | | relation.setParentId(organization.getParentId());
|
| | | organizationRelationMapper.insert(relation);
|
| | | }else{
|
| | | OrganizationRelation relationOfSelect = relations.get(0);
|
| | | //当关系发生修改时,更新关系
|
| | | if(organization.getParentId() !=null &&
|
| | | !organization.getParentId().equals(relationOfSelect.getParentId())
|
| | | ) {
|
| | | relationOfSelect.setParentId(organization.getParentId());
|
| | | organizationRelationMapper.updateByPrimaryKey(relationOfSelect);
|
| | | }else if(organization.getParentId() ==null){
|
| | | //ParentI为null,删除该条记录
|
| | | organizationRelationMapper.deleteByPrimaryKey(relationOfSelect.getId());
|
| | | }
|
| | | //删除多余关系
|
| | | if(relations.size()>1){
|
| | | relations.remove(0);
|
| | | List<Integer> relationIds = relations.stream().map(
|
| | | element->{
|
| | | return element.getId();
|
| | | }
|
| | | ).collect(Collectors.toList());
|
| | | Example example = new Example(OrganizationRelation.class);
|
| | | example.or().andIn("id",relationIds);
|
| | | organizationRelationMapper.deleteByExample(example);
|
| | | }
|
| | | }
|
| | | }
|
| | | @Override
|
| | | public void deleteByIds(Integer... ids) {
|
| | | Organization organization = new Organization();
|
| | |
| | | List<Organization> organizationList = organizationMapper.selectWithAreaNameByExample(example);
|
| | | return organizationList.size()>0?organizationList.get(0):null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Organization getFatherOrg(int childId) {
|
| | | OrganizationRelation relation = new OrganizationRelation();
|
| | | relation.setChildId(childId);
|
| | | List<OrganizationRelation> relations = organizationRelationMapper.select(relation);
|
| | | if (!CollectionUtils.isEmpty(relations)){
|
| | | OrganizationRelation relationOfSelect = relations.get(0);
|
| | | if(relationOfSelect.getParentId()!=null){
|
| | | return organizationMapper.selectByPrimaryKey(relationOfSelect.getParentId());
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | | }
|