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;
|
|
|
|
|
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;
|
|
|
|
|
import com.ruoyi.database.domain.BusinessTripApproval;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import com.ruoyi.database.domain.PoliceLeaveApproval;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import com.ruoyi.database.service.BusinessTripApprovalService;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
|
import com.ruoyi.system.service.ISysDictDataService;
|
|
|
|
|
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 10:50:12 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import java.time.LocalDateTime;
|
2025-05-29 17:51:21 +08:00
|
|
|
|
import java.time.format.DateTimeFormatter;
|
2025-06-06 10:50:12 +08:00
|
|
|
|
import java.util.*;
|
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;
|
|
|
|
|
private final ISysDictDataService dictDataService;
|
|
|
|
|
|
2025-05-29 17:51:21 +08:00
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
@RequestMapping("/list")
|
|
|
|
|
@ApiOperation("查询出差申请")
|
2025-05-29 17:51:21 +08:00
|
|
|
|
public TableDataInfo list(BusinessTripApproval businessTripApproval) {
|
|
|
|
|
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-05-29 17:51:21 +08:00
|
|
|
|
return getDataTableEnhance(list,size);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
|
|
|
|
@PostMapping("add")
|
|
|
|
|
@ApiOperation("新增出差申请")
|
|
|
|
|
public AjaxResult add(BusinessTripApproval dto){
|
2025-05-29 17:51:21 +08:00
|
|
|
|
SysUser user = getLoginUser().getUser();
|
2025-06-06 10:50:12 +08:00
|
|
|
|
if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1){
|
|
|
|
|
if (dto.getCarModel() == null){
|
|
|
|
|
throw new RuntimeException("请选择使用车型");
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
if (dto.getUseCarType() == null){
|
|
|
|
|
throw new RuntimeException("请选择用车方式");
|
|
|
|
|
}
|
|
|
|
|
if (dto.getSeats() == null){
|
|
|
|
|
throw new RuntimeException("请输入座位数");
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
if (dto.getStartDate() == null || dto.getEndDate() == null){
|
|
|
|
|
throw new RuntimeException("请选择出差时间范围");
|
|
|
|
|
}
|
|
|
|
|
if (dto.getDestinationId() == null){
|
|
|
|
|
throw new RuntimeException("请选择出差目的地");
|
|
|
|
|
}
|
|
|
|
|
dto.setUserName(user.getNickName());
|
|
|
|
|
dto.setUserId(user.getUserId());
|
|
|
|
|
dto.setDepartment(user.getDept().getDeptName());
|
|
|
|
|
List<Long> togUserIdList = dto.getTogUserIdList();
|
|
|
|
|
StringBuilder ids = new StringBuilder();
|
|
|
|
|
for (Long aLong : togUserIdList) {
|
|
|
|
|
if (ids.length() > 0) {
|
|
|
|
|
ids.append(",");
|
|
|
|
|
}
|
|
|
|
|
ids.append(aLong);
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
dto.setTogUserIds(ids.toString());
|
|
|
|
|
return toAjax(businessTripApprovalService.save(dto));
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
@GetMapping("/userList")
|
|
|
|
|
@ApiOperation("查询用户人员列表")
|
|
|
|
|
public AjaxResult applyList() {
|
|
|
|
|
List<SysUser> sysUsers = sysUserService.selectList();
|
|
|
|
|
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
|
|
|
|
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-05-29 17:51:21 +08:00
|
|
|
|
}
|
2025-06-06 10:50:12 +08:00
|
|
|
|
return AjaxResult.success(buildTree(depts, deptUsersMap));
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
public List<TreeSelect> buildTree(List<SysDept> depts, Map<Long, List<SysUser>> deptUsersMap) {
|
|
|
|
|
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-05-29 17:51:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-06 10:50:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-29 17:51:21 +08:00
|
|
|
|
}
|