2025-05-29 17:51:21 +08:00
|
|
|
|
package com.ruoyi.business.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
2025-06-06 14:56:15 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.AddTreeSelect;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.TreeSelect;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
2025-06-07 14:37:57 +08:00
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
2025-06-09 15:57:50 +08:00
|
|
|
|
import com.ruoyi.database.domain.ApprovalProcess;
|
|
|
|
|
import com.ruoyi.database.domain.BaseAddressInfo;
|
|
|
|
|
import com.ruoyi.database.domain.BusinessTripApproval;
|
2025-06-09 18:39:19 +08:00
|
|
|
|
import com.ruoyi.database.domain.dto.ApprovaltBusinessDto;
|
2025-06-09 15:57:50 +08:00
|
|
|
|
import com.ruoyi.database.domain.gwglLog;
|
2025-06-07 14:37:57 +08:00
|
|
|
|
import com.ruoyi.database.service.ApprovalProcessService;
|
2025-06-06 14:56:15 +08:00
|
|
|
|
import com.ruoyi.database.service.BaseAddressInfoService;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import com.ruoyi.database.service.BusinessTripApprovalService;
|
2025-06-07 16:43:52 +08:00
|
|
|
|
import com.ruoyi.database.service.gwglLogService;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
2025-06-06 16:13:23 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
2025-06-07 14:37:57 +08:00
|
|
|
|
import java.text.SimpleDateFormat;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import java.util.*;
|
2025-06-06 14:56:15 +08:00
|
|
|
|
import java.util.stream.Collectors;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description BusinessTripApprovalController
|
|
|
|
|
* @Author lijingtong
|
|
|
|
|
* @Date 2025-05-29
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/BusinessTripApproval")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Api(tags = "出差审批单")
|
|
|
|
|
public class BusinessTripApprovalController extends BaseController {
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
2025-05-29 17:51:21 +08:00
|
|
|
|
private final BusinessTripApprovalService businessTripApprovalService;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
private final ISysUserService sysUserService;
|
|
|
|
|
private final ISysDeptService sysDeptService;
|
2025-06-06 14:56:15 +08:00
|
|
|
|
private final BaseAddressInfoService baseAddressInfoService;
|
2025-06-07 14:37:57 +08:00
|
|
|
|
private final ApprovalProcessService approvalsProcessService;
|
2025-06-07 16:43:52 +08:00
|
|
|
|
private final gwglLogService gwglLogService;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
2025-06-06 15:35:31 +08:00
|
|
|
|
@PostMapping("/list")
|
2025-06-06 10:50:12 +08:00
|
|
|
|
@ApiOperation("查询出差申请")
|
2025-06-06 16:37:13 +08:00
|
|
|
|
public TableDataInfo list(BusinessTripApproval businessTripApproval) {
|
2025-05-29 17:51:21 +08:00
|
|
|
|
startPage();
|
2025-06-06 10:50:12 +08:00
|
|
|
|
QueryWrapper<BusinessTripApproval> queryWrapper = new QueryWrapper<>(businessTripApproval);
|
|
|
|
|
queryWrapper.orderByDesc("create_time");
|
|
|
|
|
List<BusinessTripApproval> list = businessTripApprovalService.list(queryWrapper);
|
|
|
|
|
long size = businessTripApprovalService.count(queryWrapper);
|
2025-06-06 14:56:15 +08:00
|
|
|
|
return getDataTableEnhance(list, size);
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
2025-06-06 15:35:31 +08:00
|
|
|
|
@PostMapping("/add")
|
2025-06-06 10:50:12 +08:00
|
|
|
|
@ApiOperation("新增出差申请")
|
2025-06-06 16:13:23 +08:00
|
|
|
|
public AjaxResult add(@RequestBody BusinessTripApproval dto) {
|
2025-05-29 17:51:21 +08:00
|
|
|
|
SysUser user = getLoginUser().getUser();
|
2025-06-09 16:46:59 +08:00
|
|
|
|
if (dto.getHasOffcialCar() == null) {
|
|
|
|
|
throw new RuntimeException("请选择是否自带公务车辆");
|
|
|
|
|
}
|
2025-06-06 14:56:15 +08:00
|
|
|
|
if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1) {
|
|
|
|
|
if (dto.getUseCarType() == null) {
|
2025-06-06 10:50:12 +08:00
|
|
|
|
throw new RuntimeException("请选择用车方式");
|
|
|
|
|
}
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-06 14:56:15 +08:00
|
|
|
|
if (dto.getStartDate() == null || dto.getEndDate() == null) {
|
2025-06-06 10:50:12 +08:00
|
|
|
|
throw new RuntimeException("请选择出差时间范围");
|
|
|
|
|
}
|
2025-06-06 14:56:15 +08:00
|
|
|
|
if (dto.getDestinationId() == null) {
|
2025-06-06 10:50:12 +08:00
|
|
|
|
throw new RuntimeException("请选择出差目的地");
|
|
|
|
|
}
|
|
|
|
|
dto.setUserName(user.getNickName());
|
|
|
|
|
dto.setUserId(user.getUserId());
|
|
|
|
|
dto.setDepartment(user.getDept().getDeptName());
|
|
|
|
|
List<Long> togUserIdList = dto.getTogUserIdList();
|
2025-06-09 16:46:59 +08:00
|
|
|
|
int isLeader = 0;
|
|
|
|
|
if (user.getIsLeader() != null) {
|
|
|
|
|
isLeader = 1;
|
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
StringBuilder ids = new StringBuilder();
|
2025-06-06 16:40:42 +08:00
|
|
|
|
if (togUserIdList != null && !togUserIdList.isEmpty()) {
|
|
|
|
|
for (Long aLong : togUserIdList) {
|
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
|
ids.append(",");
|
|
|
|
|
}
|
|
|
|
|
ids.append(aLong);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
SysUser user1 = sysUserService.selectUserById(aLong);
|
|
|
|
|
if (user1.getIsLeader() != null) {
|
|
|
|
|
isLeader = 1;
|
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
}
|
2025-06-06 16:40:42 +08:00
|
|
|
|
dto.setTogUserIds(ids.toString());
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-07 14:37:57 +08:00
|
|
|
|
|
|
|
|
|
String s = OrderNumberGenerator();
|
|
|
|
|
dto.setApplyNo(s);
|
2025-06-07 16:23:05 +08:00
|
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
|
String uuids = uuid.toString();
|
|
|
|
|
dto.setUuid(uuids);
|
2025-06-09 10:00:49 +08:00
|
|
|
|
BaseAddressInfo byId = baseAddressInfoService.getById(dto.getDestinationId());
|
2025-06-07 14:37:57 +08:00
|
|
|
|
ApprovalProcess approvalProcess = new ApprovalProcess();
|
|
|
|
|
approvalProcess.setApprovalNo(s);
|
2025-06-08 13:14:21 +08:00
|
|
|
|
approvalProcess.setProcessTitle("出差呈请");
|
2025-06-07 14:37:57 +08:00
|
|
|
|
approvalProcess.setSubmitterName(user.getNickName());
|
|
|
|
|
approvalProcess.setSubmitterId(user.getUserId());
|
|
|
|
|
approvalProcess.setSubmitTime(new Date().getTime());
|
2025-06-08 13:14:21 +08:00
|
|
|
|
approvalProcess.setMatterType(2);
|
2025-06-07 14:37:57 +08:00
|
|
|
|
approvalProcess.setReadStatus(0);
|
2025-06-09 10:00:49 +08:00
|
|
|
|
approvalProcess.setBusinessTripDestination(byId.getAddName());
|
|
|
|
|
approvalProcess.setStartTime(dto.getStartDate());
|
|
|
|
|
approvalProcess.setEndTime(dto.getEndDate());
|
2025-06-07 14:37:57 +08:00
|
|
|
|
approvalProcess.setCreateTime(new Date().getTime());
|
2025-06-07 16:23:05 +08:00
|
|
|
|
approvalProcess.setUuid(uuids);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
List<Long> longs = new ArrayList<>();
|
|
|
|
|
if (isLeader == 1) {
|
|
|
|
|
if (dto.getHasOffcialCar() == 1) {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(100);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
longs.add(2165L);
|
|
|
|
|
} else {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(400);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
longs.add(1660L);
|
|
|
|
|
longs.add(1661L);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(1);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
longs.add(user.getDept().getLeaderId());
|
|
|
|
|
}
|
2025-06-09 18:39:19 +08:00
|
|
|
|
addLog(approvalProcess, longs);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
return toAjax(businessTripApprovalService.save(dto)
|
|
|
|
|
&& approvalsProcessService.save(approvalProcess)
|
|
|
|
|
);
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-09 23:38:45 +08:00
|
|
|
|
/*@GetMapping("/userList")
|
2025-06-06 10:50:12 +08:00
|
|
|
|
@ApiOperation("查询用户人员列表")
|
|
|
|
|
public AjaxResult applyList() {
|
2025-06-09 23:38:45 +08:00
|
|
|
|
*//*List<SysUser> sysUsers = sysUserService.selectList();
|
2025-06-09 23:03:53 +08:00
|
|
|
|
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
|
|
|
|
sysDepts = sysDepts.stream()
|
|
|
|
|
.filter(dept -> dept.getDeptId() != 131000) // 过滤掉id为131000的部门
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<SysDept> depts = sysDeptService.buildDeptTree(sysDepts);
|
|
|
|
|
Map<Long, List<SysUser>> deptUsersMap = new HashMap<>();
|
|
|
|
|
for (SysUser user : sysUsers) {
|
|
|
|
|
deptUsersMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
|
|
|
|
}
|
2025-06-09 23:38:45 +08:00
|
|
|
|
return AjaxResult.success(buildTree(depts, deptUsersMap));*//*
|
2025-06-09 23:03:53 +08:00
|
|
|
|
|
|
|
|
|
// 获取当前用户ID
|
|
|
|
|
// 获取当前用户ID
|
|
|
|
|
Long userId = getLoginUser().getUser().getUserId();
|
|
|
|
|
// 查询用户和部门
|
2025-06-06 10:50:12 +08:00
|
|
|
|
List<SysUser> sysUsers = sysUserService.selectList();
|
|
|
|
|
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
2025-06-08 15:38:27 +08:00
|
|
|
|
sysDepts = sysDepts.stream()
|
|
|
|
|
.filter(dept -> dept.getDeptId() != 131000) // 过滤掉id为131000的部门
|
|
|
|
|
.collect(Collectors.toList());
|
2025-06-09 23:03:53 +08:00
|
|
|
|
|
|
|
|
|
// 构建部门树
|
2025-06-06 10:50:12 +08:00
|
|
|
|
List<SysDept> depts = sysDeptService.buildDeptTree(sysDepts);
|
2025-06-09 23:03:53 +08:00
|
|
|
|
|
|
|
|
|
// 查找当前用户所在部门
|
|
|
|
|
SysUser currentUser = sysUsers.stream()
|
|
|
|
|
.filter(user -> user.getUserId().equals(userId))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null);
|
|
|
|
|
|
|
|
|
|
Long currentDeptId = currentUser != null ? currentUser.getDeptId() : null;
|
|
|
|
|
|
|
|
|
|
// 构建用户映射
|
2025-06-06 10:50:12 +08:00
|
|
|
|
Map<Long, List<SysUser>> deptUsersMap = new HashMap<>();
|
|
|
|
|
for (SysUser user : sysUsers) {
|
|
|
|
|
deptUsersMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-09 23:03:53 +08:00
|
|
|
|
|
|
|
|
|
// 构建树结构
|
|
|
|
|
List<TreeSelect> treeList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 在最外层顶部添加当前部门资源(如果找到)
|
|
|
|
|
if (currentDeptId != null) {
|
|
|
|
|
SysDept currentDept = findDeptById(depts, currentDeptId);
|
|
|
|
|
if (currentDept != null) {
|
|
|
|
|
TreeSelect currentDeptNode = buildDeptNode(currentDept, deptUsersMap);
|
|
|
|
|
treeList.add(currentDeptNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保持原有部门树结构不变
|
|
|
|
|
treeList.addAll(buildTree(depts, deptUsersMap));
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(treeList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TreeSelect buildDeptNode(SysDept dept, Map<Long, List<SysUser>> deptUsersMap) {
|
|
|
|
|
TreeSelect treeSelect = new TreeSelect();
|
|
|
|
|
treeSelect.setId(dept.getDeptId());
|
|
|
|
|
treeSelect.setLabel(dept.getDeptName());
|
|
|
|
|
|
|
|
|
|
// 添加部门下的用户
|
|
|
|
|
List<TreeSelect> children = new ArrayList<>();
|
|
|
|
|
List<SysUser> users = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList());
|
|
|
|
|
for (SysUser user : users) {
|
|
|
|
|
TreeSelect userNode = new TreeSelect();
|
|
|
|
|
userNode.setLabel(user.getNickName());
|
|
|
|
|
userNode.setId(user.getUserId());
|
|
|
|
|
userNode.setDictId(dept.getDeptId());
|
|
|
|
|
userNode.setDictName(dept.getDeptName());
|
|
|
|
|
children.add(userNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 递归添加所有子部门
|
|
|
|
|
for (SysDept child : dept.getChildren()) {
|
|
|
|
|
children.add(buildDeptNode(child, deptUsersMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
|
treeSelect.setChildren(children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return treeSelect;
|
|
|
|
|
}
|
|
|
|
|
private SysDept findDeptById(List<SysDept> depts, Long deptId) {
|
|
|
|
|
for (SysDept dept : depts) {
|
|
|
|
|
SysDept found = findDeptInTree(dept, deptId);
|
|
|
|
|
if (found != null) {
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 辅助方法:在部门树中递归查找指定ID的部门
|
|
|
|
|
private SysDept findDeptInTree(SysDept dept, Long deptId) {
|
|
|
|
|
if (dept.getDeptId().equals(deptId)) {
|
|
|
|
|
return dept;
|
|
|
|
|
}
|
|
|
|
|
for (SysDept child : dept.getChildren()) {
|
|
|
|
|
SysDept found = findDeptInTree(child, deptId);
|
|
|
|
|
if (found != null) {
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2025-06-09 23:38:45 +08:00
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
@GetMapping("/userList")
|
|
|
|
|
@ApiOperation("查询用户人员列表")
|
|
|
|
|
public AjaxResult applyList() {
|
|
|
|
|
// Long currentUserId = getCurrentUserId();
|
|
|
|
|
Long currentUserId = getLoginUser().getUser().getUserId();
|
|
|
|
|
List<SysUser> sysUsers = sysUserService.selectList();
|
|
|
|
|
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
|
|
|
|
|
|
|
|
|
// 过滤无效部门并复制原始列表(避免修改原始数据)
|
|
|
|
|
List<SysDept> originalDepts = sysDepts.stream()
|
|
|
|
|
.filter(dept -> dept.getDeptId() != 131000)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 构建原始部门树
|
|
|
|
|
List<SysDept> deptTree = sysDeptService.buildDeptTree(originalDepts);
|
|
|
|
|
|
|
|
|
|
// 查找当前部门并从原始树中移除
|
|
|
|
|
SysDept currentDept = removeCurrentDeptFromTree(deptTree, currentUserId, sysUsers);
|
|
|
|
|
|
|
|
|
|
// 构建用户映射
|
|
|
|
|
Map<Long, List<SysUser>> deptUsersMap = sysUsers.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(SysUser::getDeptId));
|
|
|
|
|
|
|
|
|
|
// 构建结果:先添加当前部门(作为独立顶级节点),再添加原始树(已移除当前部门)
|
|
|
|
|
List<TreeSelect> treeList = new ArrayList<>();
|
|
|
|
|
if (currentDept != null) {
|
|
|
|
|
treeList.add(buildCurrentDeptNode(currentDept, deptUsersMap));
|
|
|
|
|
}
|
|
|
|
|
treeList.addAll(buildTree(deptTree, deptUsersMap)); // 原始树已不含当前部门
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(treeList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从部门树中查找并移除当前部门
|
|
|
|
|
private SysDept removeCurrentDeptFromTree(List<SysDept> deptTree, Long currentUserId, List<SysUser> sysUsers) {
|
|
|
|
|
SysUser currentUser = sysUsers.stream()
|
|
|
|
|
.filter(user -> user.getUserId().equals(currentUserId))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null);
|
|
|
|
|
if (currentUser == null) return null;
|
|
|
|
|
|
|
|
|
|
Long currentDeptId = currentUser.getDeptId();
|
|
|
|
|
SysDept currentDept = findDeptInTree(deptTree, currentDeptId);
|
|
|
|
|
|
|
|
|
|
// 递归从原始树中移除当前部门(避免重复显示)
|
|
|
|
|
if (currentDept != null) {
|
|
|
|
|
removeDeptFromParent(deptTree, currentDeptId);
|
|
|
|
|
}
|
|
|
|
|
return currentDept;
|
|
|
|
|
}
|
|
|
|
|
private TreeSelect buildDeptNode(SysDept dept, Map<Long, List<SysUser>> deptUsersMap) {
|
|
|
|
|
TreeSelect treeSelect = new TreeSelect();
|
|
|
|
|
treeSelect.setId(dept.getDeptId());
|
|
|
|
|
treeSelect.setLabel(dept.getDeptName());
|
|
|
|
|
|
|
|
|
|
// 添加部门下的用户
|
|
|
|
|
List<TreeSelect> children = new ArrayList<>();
|
|
|
|
|
List<SysUser> users = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList());
|
|
|
|
|
for (SysUser user : users) {
|
|
|
|
|
TreeSelect userNode = new TreeSelect();
|
|
|
|
|
userNode.setLabel(user.getNickName());
|
|
|
|
|
userNode.setId(user.getUserId());
|
|
|
|
|
userNode.setDictId(dept.getDeptId());
|
|
|
|
|
userNode.setDictName(dept.getDeptName());
|
|
|
|
|
children.add(userNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 递归添加所有子部门
|
|
|
|
|
for (SysDept child : dept.getChildren()) {
|
|
|
|
|
children.add(buildDeptNode(child, deptUsersMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
|
treeSelect.setChildren(children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return treeSelect;
|
|
|
|
|
}
|
|
|
|
|
// 递归查找部门节点
|
|
|
|
|
private SysDept findDeptInTree(List<SysDept> depts, Long deptId) {
|
|
|
|
|
for (SysDept dept : depts) {
|
|
|
|
|
if (dept.getDeptId().equals(deptId)) {
|
|
|
|
|
return dept;
|
|
|
|
|
}
|
|
|
|
|
SysDept found = findDeptInTree(dept.getChildren(), deptId);
|
|
|
|
|
if (found != null) {
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 23:38:45 +08:00
|
|
|
|
// 递归从父节点中移除指定部门
|
|
|
|
|
private void removeDeptFromParent(List<SysDept> depts, Long deptId) {
|
|
|
|
|
depts.removeIf(dept -> dept.getDeptId().equals(deptId)); // 移除顶级节点
|
|
|
|
|
depts.forEach(dept -> dept.getChildren().removeIf(child -> child.getDeptId().equals(deptId))); // 移除子节点
|
|
|
|
|
depts.forEach(dept -> removeDeptFromParent(dept.getChildren(), deptId)); // 深层递归
|
|
|
|
|
}
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
2025-06-09 23:38:45 +08:00
|
|
|
|
// 构建当前部门节点(仅显示一次在最外层)
|
|
|
|
|
private TreeSelect buildCurrentDeptNode(SysDept dept, Map<Long, List<SysUser>> deptUsersMap) {
|
|
|
|
|
TreeSelect node = new TreeSelect();
|
|
|
|
|
node.setId(dept.getDeptId());
|
|
|
|
|
node.setLabel(dept.getDeptName());
|
|
|
|
|
|
|
|
|
|
// 添加当前部门的用户和子部门(保持原有层级)
|
|
|
|
|
List<TreeSelect> children = new ArrayList<>();
|
|
|
|
|
deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList()).forEach(user -> {
|
|
|
|
|
TreeSelect userNode = new TreeSelect();
|
|
|
|
|
userNode.setLabel(user.getNickName());
|
|
|
|
|
userNode.setId(user.getUserId());
|
|
|
|
|
userNode.setDictId(dept.getDeptId());
|
|
|
|
|
userNode.setDictName(dept.getDeptName());
|
|
|
|
|
children.add(userNode);
|
|
|
|
|
});
|
|
|
|
|
dept.getChildren().forEach(child -> children.add(buildDeptNode(child, deptUsersMap))); // 递归子部门
|
|
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
|
node.setChildren(children);
|
|
|
|
|
}
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 原始buildTree方法(仅处理原始树,不含当前部门)
|
|
|
|
|
private List<TreeSelect> buildTree(List<SysDept> depts, Map<Long, List<SysUser>> deptUsersMap) {
|
|
|
|
|
return depts.stream().map(dept -> {
|
|
|
|
|
TreeSelect treeSelect = new TreeSelect();
|
|
|
|
|
treeSelect.setId(dept.getDeptId());
|
|
|
|
|
treeSelect.setLabel(dept.getDeptName());
|
|
|
|
|
|
|
|
|
|
// 处理当前部门以外的用户和子部门
|
|
|
|
|
List<TreeSelect> children = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList()).stream()
|
|
|
|
|
.map(user -> {
|
|
|
|
|
TreeSelect userNode = new TreeSelect();
|
|
|
|
|
userNode.setLabel(user.getNickName());
|
|
|
|
|
userNode.setId(user.getUserId());
|
|
|
|
|
userNode.setDictId(dept.getDeptId());
|
|
|
|
|
userNode.setDictName(dept.getDeptName());
|
|
|
|
|
return userNode;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
children.addAll(buildTree(dept.getChildren(), deptUsersMap)); // 递归原始树的子部门
|
|
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
|
treeSelect.setChildren(children);
|
|
|
|
|
}
|
|
|
|
|
return treeSelect;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前用户ID(保持不变)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*public List<TreeSelect> buildTree(List<SysDept> depts, Map<Long, List<SysUser>> deptUsersMap) {
|
2025-06-06 10:50:12 +08:00
|
|
|
|
List<TreeSelect> treeList = new ArrayList<>();
|
|
|
|
|
for (SysDept dept : depts) {
|
|
|
|
|
TreeSelect treeSelect = new TreeSelect();
|
|
|
|
|
treeSelect.setId(dept.getDeptId());
|
|
|
|
|
treeSelect.setLabel(dept.getDeptName());
|
|
|
|
|
// 分配用户到部门
|
|
|
|
|
List<SysUser> users = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList());
|
|
|
|
|
// 这里可以根据需要处理用户信息,比如只存储用户名或创建包含用户详细信息的子对象
|
|
|
|
|
// 这里简单示例,只存储用户名列表
|
|
|
|
|
List<TreeSelect> children = new ArrayList<>();
|
|
|
|
|
if (users != null) {
|
|
|
|
|
for (SysUser sysUser : users) {
|
|
|
|
|
TreeSelect treeSelect1 = new TreeSelect();
|
|
|
|
|
treeSelect1.setLabel(sysUser.getNickName());
|
|
|
|
|
treeSelect1.setId(sysUser.getUserId());
|
|
|
|
|
treeSelect1.setDictId(dept.getDeptId());
|
|
|
|
|
treeSelect1.setDictName(dept.getDeptName());
|
|
|
|
|
children.add(treeSelect1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 递归处理子部门
|
|
|
|
|
children.addAll(buildTree(dept.getChildren(), deptUsersMap));
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
|
treeSelect.setChildren(children); // 注意:这里我们重置了children,因为前面我们错误地将它设置为了用户名字符串列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treeList.add(treeSelect);
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
return treeList;
|
2025-06-09 23:38:45 +08:00
|
|
|
|
}*/
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
|
|
|
|
|
2025-06-06 14:56:15 +08:00
|
|
|
|
@GetMapping("/addressList")
|
|
|
|
|
@ApiOperation("查询地址信息列表")
|
|
|
|
|
public AjaxResult addressList() {
|
|
|
|
|
List<BaseAddressInfo> allAddresses = baseAddressInfoService.list();
|
|
|
|
|
Map<Long, List<BaseAddressInfo>> addressMap = allAddresses.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(BaseAddressInfo::getTopId));
|
|
|
|
|
List<AddTreeSelect> tree = buildTree(addressMap, 0L);
|
|
|
|
|
return AjaxResult.success(tree);
|
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
2025-06-06 14:56:15 +08:00
|
|
|
|
private List<AddTreeSelect> buildTree(
|
|
|
|
|
Map<Long, List<BaseAddressInfo>> addressMap,
|
|
|
|
|
Long parentId
|
|
|
|
|
) {
|
|
|
|
|
List<BaseAddressInfo> children = addressMap.get(parentId);
|
|
|
|
|
if (children == null) return Collections.emptyList();
|
|
|
|
|
|
|
|
|
|
return children.stream()
|
|
|
|
|
.map(info -> {
|
|
|
|
|
AddTreeSelect node = new AddTreeSelect();
|
|
|
|
|
node.setId(info.getId());
|
|
|
|
|
node.setLabel(info.getAddName());
|
|
|
|
|
node.setValue(info.getId().toString());
|
|
|
|
|
node.setChildren(buildTree(addressMap, info.getId()));
|
|
|
|
|
return node;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
2025-06-09 16:46:59 +08:00
|
|
|
|
|
2025-06-07 14:37:57 +08:00
|
|
|
|
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
private static final String DATA_KEY = "DDATAKEY:";
|
|
|
|
|
|
|
|
|
|
public static String OrderNumberGenerator() {
|
|
|
|
|
String format = sdf.format(new Date());
|
|
|
|
|
RedisCache bean = SpringUtils.getBean(RedisCache.class);
|
|
|
|
|
bean.setCacheObject(DATA_KEY + format, bean.getCacheObject(DATA_KEY + format) == null ? 1 : (Integer) (bean.getCacheObject(DATA_KEY + format)) + 1);
|
|
|
|
|
return format + String.format("%04d", (Integer) (bean.getCacheObject(DATA_KEY + format)));
|
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
2025-06-07 16:43:52 +08:00
|
|
|
|
|
|
|
|
|
@ApiOperation("审批出差申请")
|
|
|
|
|
@PostMapping("/approval")
|
2025-06-09 18:39:58 +08:00
|
|
|
|
public AjaxResult approval(@RequestBody ApprovaltBusinessDto dto) {
|
2025-06-07 16:43:52 +08:00
|
|
|
|
SysUser user = getLoginUser().getUser();
|
2025-06-09 18:39:19 +08:00
|
|
|
|
String uuid = dto.getUuid();
|
|
|
|
|
if (uuid == null) {
|
|
|
|
|
throw new RuntimeException("uuid不可为空");
|
|
|
|
|
}
|
|
|
|
|
if (dto.getState() == null) {
|
|
|
|
|
throw new RuntimeException("请选择通过或者驳回");
|
|
|
|
|
}
|
|
|
|
|
gwglLog one = gwglLogService.lambdaQuery()
|
|
|
|
|
.eq(gwglLog::getUuid, uuid)
|
|
|
|
|
.orderByDesc(gwglLog::getCreateTime)
|
|
|
|
|
.last("LIMIT 1")
|
|
|
|
|
.one();
|
|
|
|
|
Integer checkState = one.getCheckState();
|
|
|
|
|
if (checkState != 0) {
|
|
|
|
|
throw new RuntimeException("记录已被处理");
|
|
|
|
|
}
|
|
|
|
|
String checkUserId = one.getCheckUserId();
|
|
|
|
|
List<Long> longs = new ArrayList<>();
|
|
|
|
|
if (checkUserId != null) {
|
|
|
|
|
if (checkUserId.contains(",")) {
|
|
|
|
|
String[] split = checkUserId.split(",");
|
|
|
|
|
for (String s : split) {
|
|
|
|
|
longs.add(Long.parseLong(s));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
longs.add(Long.parseLong(checkUserId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (longs.isEmpty() || !longs.contains(user.getUserId())) {
|
|
|
|
|
throw new RuntimeException("当前用户无法操作");
|
|
|
|
|
}
|
|
|
|
|
ApprovalProcess approvalProcess = approvalsProcessService.lambdaQuery()
|
|
|
|
|
.eq(ApprovalProcess::getUuid, uuid)
|
|
|
|
|
.last("LIMIT 1")
|
|
|
|
|
.one();
|
|
|
|
|
BusinessTripApproval businessTripApproval = businessTripApprovalService.lambdaQuery()
|
|
|
|
|
.eq(BusinessTripApproval::getUuid,uuid)
|
|
|
|
|
.last("LIMIT 1")
|
|
|
|
|
.one();
|
2025-06-09 20:53:59 +08:00
|
|
|
|
Integer approvalStatus = approvalProcess.getApprovalStatusH();
|
2025-06-09 18:39:19 +08:00
|
|
|
|
|
|
|
|
|
if (dto.getState() == 1) {
|
|
|
|
|
if (approvalStatus == 1) {
|
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
if (businessTripApproval.getHasOffcialCar() == 1) {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(100);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
userIds.add(2165L);
|
|
|
|
|
} else {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(400);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
userIds.add(1660L);
|
|
|
|
|
userIds.add(1661L);
|
|
|
|
|
}
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}
|
|
|
|
|
if (approvalStatus == 100) {
|
|
|
|
|
if (dto.getDriverName() == null) {
|
|
|
|
|
throw new RuntimeException("驾驶员姓名不可为空");
|
|
|
|
|
}
|
|
|
|
|
if (dto.getPlateNo() == null) {
|
|
|
|
|
throw new RuntimeException("车牌号不可为空");
|
|
|
|
|
}
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(200);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
userIds.add(2157L);
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}
|
|
|
|
|
if (approvalStatus == 200) {
|
|
|
|
|
if (dto.getLeaderId() == null) {
|
|
|
|
|
throw new RuntimeException("请选择分管局领导");
|
|
|
|
|
}
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(300);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
userIds.add(dto.getLeaderId());
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}
|
|
|
|
|
if (approvalStatus == 300) {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(400);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
userIds.add(1660L);
|
|
|
|
|
userIds.add(1661L);
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}
|
|
|
|
|
if (approvalStatus == 400) {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(500);
|
2025-06-09 18:39:19 +08:00
|
|
|
|
}
|
|
|
|
|
one.setCheckState(dto.getState());
|
|
|
|
|
one.setCheckTime(System.currentTimeMillis() / 1000L);
|
|
|
|
|
one.setReason(dto.getReason());
|
|
|
|
|
boolean updateById = gwglLogService.updateById(one);
|
|
|
|
|
boolean updateById1 = approvalsProcessService.updateById(approvalProcess);
|
|
|
|
|
return toAjax(updateById1 && updateById);
|
|
|
|
|
} else if (dto.getState() == 2) {
|
|
|
|
|
if (dto.getReason() == null) {
|
|
|
|
|
throw new RuntimeException("驳回意见不可为空");
|
|
|
|
|
}
|
2025-06-09 19:15:39 +08:00
|
|
|
|
if (approvalStatus == 100 || approvalStatus == 200 || approvalStatus == 300) {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(400);
|
2025-06-09 19:15:39 +08:00
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
userIds.add(1660L);
|
|
|
|
|
userIds.add(1661L);
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}else {
|
2025-06-09 20:53:59 +08:00
|
|
|
|
approvalProcess.setApprovalStatusH(0);
|
2025-06-09 19:15:39 +08:00
|
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
|
|
userIds.add(approvalProcess.getSubmitterId());
|
|
|
|
|
addLog(approvalProcess, userIds);
|
|
|
|
|
}
|
2025-06-09 18:39:19 +08:00
|
|
|
|
one.setCheckState(dto.getState());
|
|
|
|
|
one.setCheckTime(System.currentTimeMillis() / 1000L);
|
|
|
|
|
one.setReason(dto.getReason());
|
|
|
|
|
boolean updateById = gwglLogService.updateById(one);
|
|
|
|
|
boolean updateById1 = approvalsProcessService.updateById(approvalProcess);
|
|
|
|
|
return toAjax(updateById1 && updateById);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("处理结果参数不正确");
|
2025-06-07 16:43:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 16:46:59 +08:00
|
|
|
|
|
|
|
|
|
public Boolean addLog(ApprovalProcess approvalProcess, List<Long> userIds) {
|
|
|
|
|
gwglLog gwglLog = new gwglLog();
|
|
|
|
|
gwglLog.setUserId(approvalProcess.getSubmitterId());
|
|
|
|
|
gwglLog.setUserName(approvalProcess.getSubmitterName());
|
|
|
|
|
gwglLog.setCheckState(0);
|
|
|
|
|
gwglLog.setUuid(approvalProcess.getUuid());
|
2025-06-09 20:53:59 +08:00
|
|
|
|
gwglLog.setApprovalStatusH(approvalProcess.getApprovalStatusH());
|
2025-06-09 18:39:19 +08:00
|
|
|
|
gwglLog.setCreateTime(System.currentTimeMillis() / 1000L);
|
2025-06-09 16:46:59 +08:00
|
|
|
|
SysUser user = new SysUser();
|
|
|
|
|
StringBuilder name = new StringBuilder();
|
2025-06-09 18:39:19 +08:00
|
|
|
|
StringBuilder ids = new StringBuilder();
|
2025-06-09 16:46:59 +08:00
|
|
|
|
for (Long userId : userIds) {
|
|
|
|
|
SysUser user1 = sysUserService.selectUserById(userId);
|
|
|
|
|
if (name.length() > 0) {
|
|
|
|
|
name.append(",");
|
|
|
|
|
}
|
|
|
|
|
name.append(user1.getNickName());
|
2025-06-09 18:39:19 +08:00
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
|
ids.append(",");
|
|
|
|
|
}
|
|
|
|
|
ids.append(user1.getUserId());
|
2025-06-09 16:46:59 +08:00
|
|
|
|
}
|
2025-06-09 18:39:19 +08:00
|
|
|
|
gwglLog.setCheckUserId(ids.toString());
|
2025-06-09 16:46:59 +08:00
|
|
|
|
gwglLog.setChecker(name.toString());
|
|
|
|
|
if (user.getDept() != null) {
|
|
|
|
|
gwglLog.setCheckDeptName(user.getDept().getDeptName());
|
|
|
|
|
}
|
|
|
|
|
gwglLog.setCheckDeptId(user.getDeptId());
|
|
|
|
|
return gwglLogService.save(gwglLog);
|
|
|
|
|
}
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|