| | |
| | | package com.kidgrow.usercenter.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.usercenter.mapper.SysOrganizationMapper; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | | import com.kidgrow.usercenter.vo.SysOrganizationVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.cglib.beans.BeanCopier; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | return baseMapper.findByObject(sysOrganization); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户 获取组织 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SysOrganization> findListByUserId(Long userId) { |
| | | return baseMapper.findListByUserId(userId); |
| | | } |
| | | |
| | | /** |
| | | * 根据map 查询, 将参数中的 access_token 去掉 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody getListByMap(Map<String, Object> params) { |
| | | //将access_token 参数去掉 |
| | | params.remove("access_token"); |
| | | List<SysOrganization> sysOrganizations = baseMapper.selectByMap(params); |
| | | return ResultBody.ok().data(sysOrganizations); |
| | | List<SysOrganizationVo> sysOrganizationVos=new ArrayList<>(); |
| | | sysOrganizations.forEach(e ->{ |
| | | if(e.getOrgParentId()!=null){ |
| | | SysOrganizationVo sysOrganizationVo=new SysOrganizationVo(); |
| | | BeanCopier beanCopier = BeanCopier.create(SysOrganization.class, SysOrganizationVo.class, false); |
| | | beanCopier.copy(e,sysOrganizationVo,null); |
| | | SysOrganization sysOrganization = baseMapper.selectById(e.getOrgParentId()); |
| | | if(sysOrganization!=null){ |
| | | sysOrganizationVo.setOrgParentName(sysOrganization.getOrgName()); |
| | | } |
| | | sysOrganizationVos.add(sysOrganizationVo); |
| | | } |
| | | }); |
| | | return ResultBody.ok().data(sysOrganizationVos); |
| | | } |
| | | |
| | | /** |
| | | * 更新状态 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody updateEnabled(Map<String, Object> params) { |
| | | Long id = MapUtils.getLong(params, "id"); |
| | | if(id==null){ |
| | | return ResultBody.failed("请选取一条数据"); |
| | | } |
| | | SysOrganization sysOrganization = baseMapper.selectById(id); |
| | | if (sysOrganization != null) { |
| | | sysOrganization.setEnabled(MapUtils.getBoolean(params,"enabled")); |
| | | int i = baseMapper.updateById(sysOrganization); |
| | | if(i>0){ |
| | | return ResultBody.ok(); |
| | | }else { |
| | | return ResultBody.failed("更新失败"); |
| | | } |
| | | }else { |
| | | return ResultBody.failed("更新失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取树状图 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody getTree(Map<String, Object> params) { |
| | | List<SysOrganization> sysOrganizations = baseMapper.selectByMap(params); |
| | | List<Map<String, Object>> treeData = getTreeData(Long.valueOf("-1"), sysOrganizations); |
| | | return ResultBody.ok().data(treeData); |
| | | } |
| | | |
| | | /** |
| | | * 将数据 封装成 tree (递归方式) |
| | | * @param MyId |
| | | * @param sysOrganizations |
| | | * @return |
| | | */ |
| | | public List<Map<String,Object>> getTreeData(Long MyId,List<SysOrganization> sysOrganizations){ |
| | | List<Map<String,Object>> listMap=new ArrayList<>(); |
| | | Map<Long, SysOrganization> collect = sysOrganizations.stream().collect(Collectors.toMap(SysOrganization::getId, SysOrganization -> SysOrganization)); |
| | | List<Long> idList = sysOrganizations.stream().filter(e -> e.getOrgParentId()==MyId).map(e -> e.getId()).collect(Collectors.toList()); |
| | | for (Long id:idList |
| | | ) { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("id",id); |
| | | map.put("name",collect.get(id).getOrgName()); |
| | | map.put("level",collect.get(id).getOrgLevel()); |
| | | List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList()); |
| | | if(childs.size()>0){ |
| | | List<Map<String, Object>> treeData = getTreeData(id, sysOrganizations); |
| | | map.put("children",treeData); |
| | | } |
| | | listMap.add(map); |
| | | } |
| | | return listMap; |
| | | } |
| | | } |