package com.ruoyi.system.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.common.basic.PageInfo;
|
import com.ruoyi.system.mapper.TDeptMapper;
|
import com.ruoyi.system.mapper.TLeaveMapper;
|
import com.ruoyi.system.mapper.TProjectDeptMapper;
|
import com.ruoyi.system.model.TDept;
|
import com.ruoyi.system.model.TLeave;
|
import com.ruoyi.system.model.TProjectDept;
|
import com.ruoyi.system.query.LeaveListQuery;
|
import com.ruoyi.system.service.TLeaveService;
|
import com.ruoyi.system.vo.system.DeptListVO;
|
import com.ruoyi.system.vo.system.LeaveListVO;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
|
import java.time.format.DateTimeFormatter;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 请假记录 服务实现类
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2025-05-28
|
*/
|
@Service
|
public class TLeaveServiceImpl extends ServiceImpl<TLeaveMapper, TLeave> implements TLeaveService {
|
|
@Autowired
|
private TProjectDeptMapper projectDeptMapper;
|
@Autowired
|
private TDeptMapper deptMapper;
|
@Override
|
public PageInfo<LeaveListVO> pageList(LeaveListQuery query) {
|
if (StringUtils.hasLength(query.getDeptName())){
|
List<String> collect = projectDeptMapper.selectList(new LambdaQueryWrapper<TProjectDept>().like(TProjectDept::getProjectName, query.getDeptName()))
|
.stream().map(TProjectDept::getId).collect(Collectors.toList());
|
List<String> collect1 = deptMapper.selectList(new LambdaQueryWrapper<TDept>().like(TDept::getDeptName, query.getDeptName()))
|
.stream().map(TDept::getId).collect(Collectors.toList());
|
collect.addAll(collect1);
|
if (collect.isEmpty()){
|
collect.add("0");
|
}
|
query.setDeptIds(collect);
|
}
|
|
PageInfo<LeaveListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
|
List<LeaveListVO> list = this.baseMapper.pageList(query,pageInfo);
|
for (LeaveListVO leaveListVO : list) {
|
String start = leaveListVO.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
String end = leaveListVO.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
leaveListVO.setLeaveTime(start+"至"+end);
|
if (leaveListVO.getDeptType() == 1){
|
TProjectDept tProjectDept = projectDeptMapper.selectById(leaveListVO.getDeptId());
|
if (!tProjectDept.getParentId().equals("0")){
|
TProjectDept tProjectDept1 = projectDeptMapper.selectById(tProjectDept.getParentId());
|
leaveListVO.setDeptName(tProjectDept1.getProjectName()+">"+tProjectDept.getProjectName());
|
}else{
|
leaveListVO.setDeptName(tProjectDept.getProjectName());
|
}
|
}else{
|
TDept tDept = deptMapper.selectById(leaveListVO.getDeptId());
|
leaveListVO.setDeptName(tDept.getDeptName());
|
}
|
}
|
pageInfo.setRecords(list);
|
return pageInfo;
|
}
|
}
|