mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
♻️ Refactoring code. 日程管理支持按周显示,抽取部分枚举值
This commit is contained in:
1 parent
673896ecf7
commit
2716461566
6 files changed
+230
-19
No files matched your search
+86
@@ -0,0 +1,86 @@
|
||||
package com.pig4cloud.pigx.admin.api.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysMenu;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class DataUtil {
|
||||
|
||||
/**
|
||||
* 根据当前部门id,向上查找所有的部门
|
||||
* @param deptId 当前部门id
|
||||
* @param allDeptList 所有部门列表
|
||||
* @return 返回包括自己部门在内的所有父级部门
|
||||
*/
|
||||
public List<SysDept> selectParentByDept(long deptId, List<SysDept> allDeptList) {
|
||||
List<SysDept> list = new ArrayList<>();
|
||||
Optional<SysDept> optionalDept = allDeptList.stream().filter(w -> w.getDeptId() == deptId).findFirst();
|
||||
|
||||
optionalDept.ifPresent(dept -> {
|
||||
if (dept.getParentId() != null) {
|
||||
Long parentId = dept.getParentId();
|
||||
List<SysDept> depts = selectParentByDept(parentId, allDeptList);
|
||||
list.add(dept);
|
||||
list.addAll(depts);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前部门id,向下查找所有的部门
|
||||
* @param deptId 当前部门id
|
||||
* @param allDeptList 所有部门列表
|
||||
* @return 返回包括自己部门在内的所有子级部门
|
||||
*/
|
||||
public List<SysDept> selectChildrenByDept(long deptId, List<SysDept> allDeptList) {
|
||||
List<SysDept> list = new ArrayList<>();
|
||||
Optional<SysDept> optionalDept = allDeptList.stream().filter(w -> w.getDeptId() == deptId).findFirst();
|
||||
|
||||
optionalDept.ifPresent(list::add);
|
||||
|
||||
List<SysDept> collect = allDeptList.stream()
|
||||
.filter(w -> w.getParentId() == deptId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isEmpty(collect)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
collect.forEach(dept -> {
|
||||
List<SysDept> depts = selectChildrenByDept(dept.getDeptId(), allDeptList);
|
||||
list.addAll(depts);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前菜单id,向下查找所有的菜单
|
||||
* @param menuId 当前菜单id
|
||||
* @param allMenuList 所有菜单列表
|
||||
* @return 返回包括自己在内的所有子级菜单
|
||||
*/
|
||||
public List<SysMenu> selectChildrenByMenu(long menuId, List<SysMenu> allMenuList) {
|
||||
List<SysMenu> list = new ArrayList<>();
|
||||
list.add(allMenuList.stream().filter(w -> w.getMenuId() == menuId).findFirst().get());
|
||||
|
||||
List<SysMenu> collect = allMenuList.stream()
|
||||
.filter(w -> w.getParentId() == menuId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(collect)) {
|
||||
return list;
|
||||
}
|
||||
collect.forEach(dept -> list.addAll(selectChildrenByMenu(dept.getMenuId(), allMenuList)));
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -33,6 +33,7 @@ import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -122,8 +123,9 @@ public class SysScheduleController {
|
||||
|
||||
@Operation(summary = "列表查询", description = "列表查询")
|
||||
@GetMapping("/list")
|
||||
public R list(String month) {
|
||||
List<SysScheduleEntity> list = sysScheduleService.selectListByScope(month);
|
||||
public R list(@RequestParam(required = false) LocalDate startDate,
|
||||
@RequestParam(required = false) LocalDate endDate) {
|
||||
List<SysScheduleEntity> list = sysScheduleService.selectListByScope(startDate, endDate);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysScheduleEntity;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -32,8 +33,18 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysScheduleService extends IService<SysScheduleEntity> {
|
||||
|
||||
/**
|
||||
* 根据分页信息和日程实体获取指定范围的日程列表
|
||||
* @param page 分页信息
|
||||
* @param sysSchedule 日程实体
|
||||
* @return 日程列表
|
||||
*/
|
||||
IPage<SysScheduleEntity> getScheduleByScope(Page page, SysScheduleEntity sysSchedule);
|
||||
|
||||
List<SysScheduleEntity> selectListByScope(String month);
|
||||
/**
|
||||
* 根据月份查询日程列表
|
||||
* @return 日程列表
|
||||
*/
|
||||
List<SysScheduleEntity> selectListByScope(LocalDate startDate, LocalDate endDate);
|
||||
|
||||
}
|
||||
+105
-8
@@ -20,21 +20,19 @@
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUserPost;
|
||||
import com.pig4cloud.pigx.admin.api.constant.OrgTypeEnum;
|
||||
import com.pig4cloud.pigx.admin.api.entity.*;
|
||||
import com.pig4cloud.pigx.admin.api.utils.DataUtil;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysDeptMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysPostMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysUserMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysUserPostMapper;
|
||||
import com.pig4cloud.pigx.admin.api.vo.OrgTreeVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.*;
|
||||
import com.pig4cloud.pigx.admin.service.SysDeptService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.datascope.DataScope;
|
||||
@@ -66,6 +64,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
|
||||
private final SysPostMapper postMapper;
|
||||
|
||||
private final SysRoleMapper roleMapper;
|
||||
|
||||
private final SysUserPostMapper userPostMapper;
|
||||
|
||||
/**
|
||||
@@ -243,6 +243,103 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门ID和类型获取组织树
|
||||
* @param parentDeptId 父部门ID
|
||||
* @param type 类型
|
||||
* @return 组织树信息
|
||||
*/
|
||||
public Map<String, Object> listOrgTree(Long parentDeptId, String type) {
|
||||
|
||||
List<OrgTreeVO> orgs = new LinkedList<>();
|
||||
|
||||
if (StrUtil.equals(type, OrgTypeEnum.ROLE.getType())) {
|
||||
// 角色
|
||||
List<SysRole> roleList = roleMapper.selectList(Wrappers.emptyWrapper());
|
||||
|
||||
roleList.forEach(role -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(role.getRoleId());
|
||||
orgTreeVo.setName(role.getRoleName());
|
||||
orgTreeVo.setType(OrgTypeEnum.ROLE.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgs.add(orgTreeVo);
|
||||
});
|
||||
|
||||
return Dict.create()
|
||||
.set("roleList", orgs)
|
||||
.set("childDepartments", orgs)
|
||||
.set("employees", new ArrayList<>());
|
||||
}
|
||||
|
||||
Dict dict = Dict.create()
|
||||
.set("titleDepartments", new ArrayList<>())
|
||||
.set("roleList", new ArrayList<>())
|
||||
.set("employees", new ArrayList<>());
|
||||
|
||||
List<SysDept> deptList = this.list(
|
||||
Wrappers.<SysDept>lambdaQuery().eq(Objects.nonNull(parentDeptId), SysDept::getParentId, parentDeptId));
|
||||
|
||||
// 查询所有部门及员工
|
||||
List<OrgTreeVO> deptVoList = new ArrayList<>();
|
||||
deptList.forEach(dept -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(dept.getDeptId());
|
||||
orgTreeVo.setName(dept.getName());
|
||||
orgTreeVo.setType(OrgTypeEnum.DEPT.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
deptVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("childDepartments", deptVoList);
|
||||
|
||||
if (!StrUtil.equals(type, OrgTypeEnum.DEPT.getType())) {
|
||||
|
||||
List<OrgTreeVO> userVoList = new ArrayList<>();
|
||||
|
||||
List<SysUser> userList = userMapper
|
||||
.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, CollUtil.toList(parentDeptId)));
|
||||
|
||||
userList.forEach(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
userVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("employees", userVoList);
|
||||
}
|
||||
|
||||
if (parentDeptId > 0) {
|
||||
List<SysDept> allDept = this.list();
|
||||
List<SysDept> depts = DataUtil.selectParentByDept(parentDeptId, allDept);
|
||||
dict.set("titleDepartments", CollUtil.reverse(depts));
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索用户
|
||||
* @param username 用户名/拼音/首字母
|
||||
* @return 匹配到的用户
|
||||
*/
|
||||
public List<OrgTreeVO> getOrgTreeUser(String username) {
|
||||
return userMapper.selectList(Wrappers.<SysUser>lambdaQuery().like(SysUser::getUsername, username))
|
||||
.stream()
|
||||
.map(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
return orgTreeVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询所有子节点。
|
||||
* @param allDeptList 所有部门列表
|
||||
|
||||
+21
-7
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.constant.ScheduleStateEnum;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysScheduleEntity;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysScheduleMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysScheduleService;
|
||||
@@ -30,8 +33,6 @@ import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -45,6 +46,12 @@ import java.util.Objects;
|
||||
public class SysScheduleServiceImpl extends ServiceImpl<SysScheduleMapper, SysScheduleEntity>
|
||||
implements SysScheduleService {
|
||||
|
||||
/**
|
||||
* 根据范围获取计划列表
|
||||
* @param page 分页对象
|
||||
* @param sysSchedule 计划实体对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@Override
|
||||
public IPage<SysScheduleEntity> getScheduleByScope(Page page, SysScheduleEntity sysSchedule) {
|
||||
LambdaQueryWrapper<SysScheduleEntity> wrapper = Wrappers.lambdaQuery();
|
||||
@@ -56,13 +63,20 @@ public class SysScheduleServiceImpl extends ServiceImpl<SysScheduleMapper, SysSc
|
||||
return baseMapper.selectPageByScope(page, wrapper, dataScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据月份查询日程列表
|
||||
* @param startDate 本周开始日期
|
||||
* @param endDate 本周结束日期
|
||||
* @return 日程列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysScheduleEntity> selectListByScope(String month) {
|
||||
LocalDate parse = LocalDate.parse(month, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
LocalDate firstDay = parse.with(TemporalAdjusters.firstDayOfMonth()); // 获取当前月的第一天
|
||||
LocalDate lastDay = parse.with(TemporalAdjusters.lastDayOfMonth());
|
||||
public List<SysScheduleEntity> selectListByScope(LocalDate startDate, LocalDate endDate) {
|
||||
DateTime beginOfWeek = DateUtil.beginOfWeek(DateUtil.date());
|
||||
DateTime endOfWeek = DateUtil.endOfWeek(DateUtil.date());
|
||||
LambdaQueryWrapper<SysScheduleEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.between(SysScheduleEntity::getDate, firstDay, lastDay);
|
||||
wrapper.between(SysScheduleEntity::getDate, Objects.isNull(startDate) ? beginOfWeek : startDate,
|
||||
Objects.isNull(endDate) ? endOfWeek : endDate);
|
||||
wrapper.ne(SysScheduleEntity::getState, ScheduleStateEnum.END.getCode());
|
||||
DataScope dataScope = new DataScope();
|
||||
dataScope.setUsername(SecurityUtils.getUser().getUsername());
|
||||
return baseMapper.selectListByScope(wrapper, dataScope);
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.constant.TenantStateEnum;
|
||||
import com.pig4cloud.pigx.admin.api.entity.*;
|
||||
import com.pig4cloud.pigx.admin.config.ClientDetailsInitRunner;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysRoleMenuMapper;
|
||||
@@ -90,7 +91,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
@Cacheable(value = CacheConstants.TENANT_DETAILS)
|
||||
public List<SysTenant> getNormalTenant() {
|
||||
return baseMapper
|
||||
.selectList(Wrappers.<SysTenant>lambdaQuery().eq(SysTenant::getStatus, CommonConstants.STATUS_NORMAL));
|
||||
.selectList(Wrappers.<SysTenant>lambdaQuery().eq(SysTenant::getStatus, TenantStateEnum.NORMAL.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user