|
|
@@ -5,19 +5,31 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
+import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.utils.SpringUtils;
|
|
|
import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.common.redis.service.RedisService;
|
|
|
+import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.system.api.domain.SysDept;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.domain.vo.TreeSelect;
|
|
|
import com.xunmei.system.mapper.SysOrgMapper;
|
|
|
import com.xunmei.system.mapper.SysUserMapper;
|
|
|
import com.xunmei.system.service.ISysOrgService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 【请填写功能名称】Service业务层处理
|
|
|
@@ -32,6 +44,21 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
@Autowired
|
|
|
private SysUserMapper sysUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目启动时,缓存机构数据
|
|
|
+ */
|
|
|
+ @PostConstruct
|
|
|
+ public void init()
|
|
|
+ {
|
|
|
+ loadingOrgCache();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<SysOrg> selectPage(SysOrg org) {
|
|
|
//未删除
|
|
|
@@ -60,6 +87,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
query.like("name", org.getName());
|
|
|
org.setName(null);
|
|
|
}
|
|
|
+ query.lambda().orderByAsc(SysOrg::getPath);
|
|
|
//获取数据
|
|
|
page = baseMapper.selectPage(page, query);
|
|
|
//抓换为TableDataInfo适配前端
|
|
|
@@ -196,4 +224,79 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
public SysOrg getSysOrgByUserId(Long userId) {
|
|
|
return sysUserMapper.selectSysByUserId(userId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysOrg> selectDeptTreeList(SysOrg dept) {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ SysOrg sysOrg = baseMapper.selectSysOrgByUserId(userId);
|
|
|
+ if (ObjectUtil.isNull(sysOrg)) {
|
|
|
+ throw new ServiceException("当前用户没有部门信息");
|
|
|
+ }
|
|
|
+ final LambdaQueryWrapper<SysOrg> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysOrg::getDeleted, 0);
|
|
|
+ wrapper.isNotNull(SysOrg::getParentId);
|
|
|
+ Long parentId = Constants.TOP_ORG_PARENT_ID;
|
|
|
+ if (ObjectUtil.notEqual(Constants.TOP_ORG_PARENT_ID, sysOrg.getParentId())) {
|
|
|
+ parentId = sysOrg.getParentId();
|
|
|
+ wrapper.likeRight(SysOrg::getPath, sysOrg.getPath());
|
|
|
+ }
|
|
|
+ List<SysOrg> depts = baseMapper.selectList(wrapper);
|
|
|
+ final Map<Long, List<SysOrg>> collect = depts.stream().collect(Collectors.groupingBy(SysOrg::getParentId));
|
|
|
+ return handleTree(collect, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void loadingOrgCache() {
|
|
|
+ QueryWrapper<SysOrg> qw = new QueryWrapper<>();
|
|
|
+ qw.lambda().ge(SysOrg::getDeleted,0);
|
|
|
+ List<SysOrg> list = baseMapper.selectList(qw);
|
|
|
+ redisService.setCacheList(CacheConstants.ORG_CACHE_LIST_KEY, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clearOrgCache() {
|
|
|
+ redisService.deleteObject(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean saveOrUpdateOrg(SysOrg org) {
|
|
|
+
|
|
|
+ boolean isOk = false;
|
|
|
+ if(org.getId() != null){
|
|
|
+ isOk = this.updateById(org);
|
|
|
+ }else{
|
|
|
+ isOk = this.save(org);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 重置缓存
|
|
|
+ */
|
|
|
+ this.clearOrgCache();
|
|
|
+ this.loadingOrgCache();
|
|
|
+
|
|
|
+ return isOk;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean removeOrg(Long orgId) {
|
|
|
+ boolean rel = this.removeById(orgId);
|
|
|
+ /*
|
|
|
+ * 重置缓存
|
|
|
+ */
|
|
|
+ this.clearOrgCache();
|
|
|
+ this.loadingOrgCache();
|
|
|
+ return rel;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<SysOrg> handleTree(Map<Long, List<SysOrg>> map, Long parentId) {
|
|
|
+ List<SysOrg> orgList = map.get(parentId);
|
|
|
+ if (ObjectUtil.isNotEmpty(orgList)) {
|
|
|
+ orgList.forEach(org -> {
|
|
|
+ final List<SysOrg> tree = handleTree(map, org.getId());
|
|
|
+ org.setChildren(tree);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return orgList;
|
|
|
+ }
|
|
|
}
|