出差申请

This commit is contained in:
hanrenchun 2025-06-06 10:50:12 +08:00
parent 16fd044098
commit 6a5f68accf
3 changed files with 182 additions and 102 deletions

View File

@ -3,18 +3,27 @@ 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;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.database.domain.BusinessTripApproval;
import com.ruoyi.database.domain.dto.ApprovaltDto;
import com.ruoyi.database.domain.PoliceLeaveApproval;
import com.ruoyi.database.service.BusinessTripApprovalService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
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;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.*;
/**
* @Description BusinessTripApprovalController
@ -27,81 +36,112 @@ import java.util.List;
@RequiredArgsConstructor
@Api(tags = "出差审批单")
public class BusinessTripApprovalController extends BaseController {
private final BusinessTripApprovalService businessTripApprovalService;
@GetMapping("/list")
@ApiOperation("查询出差审批单")
private final BusinessTripApprovalService businessTripApprovalService;
private final ISysUserService sysUserService;
private final ISysDeptService sysDeptService;
private final ISysDictDataService dictDataService;
@RequestMapping("/list")
@ApiOperation("查询出差申请")
public TableDataInfo list(BusinessTripApproval businessTripApproval) {
startPage();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
QueryWrapper<BusinessTripApproval> qw = new QueryWrapper<>(businessTripApproval);
qw.orderByDesc("create_time");
String fTime = businessTripApproval.getFTime();
String eTime = businessTripApproval.getETime();
// String 的字符串转成LoaclDateTime格式
List<BusinessTripApproval> list = businessTripApprovalService.list(qw);
long size = list.size();
QueryWrapper<BusinessTripApproval> queryWrapper = new QueryWrapper<>(businessTripApproval);
queryWrapper.orderByDesc("create_time");
List<BusinessTripApproval> list = businessTripApprovalService.list(queryWrapper);
long size = businessTripApprovalService.count(queryWrapper);
return getDataTableEnhance(list,size);
}
@ApiOperation("新增或修改出差审批单 传id为修改 不传id为新增")
@PostMapping("/add")
public AjaxResult add(@RequestBody BusinessTripApproval businessTripApproval) {
@PostMapping("add")
@ApiOperation("新增出差申请")
public AjaxResult add(BusinessTripApproval dto){
SysUser user = getLoginUser().getUser();
if (businessTripApproval.getId() == null) {
businessTripApproval.setCreateBy(user.getNickName());
businessTripApproval.setState(0);
boolean result = businessTripApprovalService.save(businessTripApproval);
if (!result) {
return AjaxResult.error("新增出差审批单失败");
if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1){
if (dto.getCarModel() == null){
throw new RuntimeException("请选择使用车型");
}
return AjaxResult.success(result);
}else {
businessTripApproval.setUpdateBy(user.getNickName());
boolean result = businessTripApprovalService.updateById(businessTripApproval);
if (!result) {
return AjaxResult.error("修改出差审批单失败");
if (dto.getUseCarType() == null){
throw new RuntimeException("请选择用车方式");
}
if (dto.getSeats() == null){
throw new RuntimeException("请输入座位数");
}
return AjaxResult.success(result);
}
}
@ApiOperation("删除出差审批单")
@DeleteMapping("/{id}")
public AjaxResult delete(@PathVariable Long id) {
boolean result = businessTripApprovalService.removeById(id);
if (!result) {
return AjaxResult.error("删除出差审批单失败");
if (dto.getStartDate() == null || dto.getEndDate() == null){
throw new RuntimeException("请选择出差时间范围");
}
return AjaxResult.success(result);
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);
}
dto.setTogUserIds(ids.toString());
return toAjax(businessTripApprovalService.save(dto));
}
@ApiOperation("查询审批流程")
@GetMapping("/state/{id}")
public AjaxResult state(@PathVariable Long id) {
BusinessTripApproval businessTripApproval = businessTripApprovalService.getById(id);
if (businessTripApproval == null) {
return AjaxResult.error("查询审批流程失败");
@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);
}
return AjaxResult.success(businessTripApproval.getState());
return AjaxResult.success(buildTree(depts, deptUsersMap));
}
@ApiOperation("审批")
@PostMapping("/approval")
public AjaxResult approval(@RequestBody ApprovaltDto dto) {
Long id = dto.getId();
Integer state = dto.getState();
BusinessTripApproval businessTripApproval = businessTripApprovalService.getById(id);
businessTripApproval.setState(state);
boolean result = businessTripApprovalService.updateById(businessTripApproval);
if (!result) {
return AjaxResult.error("审批出差失败");
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);
}
return AjaxResult.success("审批出差成功");
return treeList;
}
}

View File

@ -2,82 +2,76 @@ package com.ruoyi.database.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntityMini;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Data
@TableName("business_trip_approval")
@ApiModel("出差审批单")
public class BusinessTripApproval {
public class BusinessTripApproval extends BaseEntityMini {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty("主键ID")
private Long id;
@ApiModelProperty("出差人员姓名")
@TableField(condition = SqlCondition.LIKE)
private String name;
@ApiModelProperty("出差人id")
private Long userId;
@ApiModelProperty("部门")
@TableField(condition = SqlCondition.LIKE)
private String department;
@ApiModelProperty("出差事由")
@TableField(condition = SqlCondition.LIKE)
private String reason;
@ApiModelProperty("同行人员id")
private String togUserIds;
@ApiModelProperty("出差人姓名")
private String userName;
@ApiModelProperty("出差目的地")
@TableField(condition = SqlCondition.LIKE)
private String destination;
private Integer destinationId;
@TableField(exist = false)
private String destinationIdCn;
@ApiModelProperty("出差开始日期")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
private Long startDate;
@TableField(exist = false)
private String startDateCn;
@ApiModelProperty("出差结束日期")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
private Long endDate;
@TableField(exist = false)
private String endDateCn;
@ApiModelProperty("拟乘交通工具0-飞机/1-火车/2-汽车/3-轮船/4-其他)")
@TableField(condition = SqlCondition.EQUAL)
private String transport;
@ApiModelProperty("交通工具")
private Integer transportId;
@TableField(exist = false)
private String transportIdCn;
@ApiModelProperty("是否自带公务车辆0-否 1-是)")
private Integer hasOfficialCar;
@ApiModelProperty("是否自带公务车辆")
private Integer hasOffcialCar;
@ApiModelProperty("审批流程 0-未审批 1-部门审批通过 2-部门审批不通过 3-警务保障部门审批通过 4-警务保障部门审批不通过 5-局领导审批通过 6-局领导审批不通过")
@TableField(condition = SqlCondition.EQUAL)
private Integer state;
@ApiModelProperty("车型")
private Integer carModel;
@TableField(exist = false)
private String carModelCn;
@ApiModelProperty("单位负责人意见")
private String deptLeaderOpinion;
@ApiModelProperty("用车方式")
private Integer useCarType;
@TableField(exist = false)
private String useCarTypeCn;
@ApiModelProperty("局分管负责人意见")
private String LeaderOpinion;
@ApiModelProperty("座位数")
private Integer seats;
@ApiModelProperty("局主要领导意见")
private String mainLeaderOpinion;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
@ApiModelProperty("创建人")
private String createBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("修改时间")
private LocalDateTime updateTime;
@ApiModelProperty("修改人")
private String updateBy;
@TableField(exist = false)
private String fTime;
@TableField(exist = false)
private String eTime;
private List<Long> togUserIdList;
}

View File

@ -9,7 +9,7 @@ import com.ruoyi.common.core.domain.entity.SysMenu;
/**
* Treeselect树结构实体类
*
*
* @author ruoyi
*/
public class TreeSelect implements Serializable
@ -22,6 +22,20 @@ public class TreeSelect implements Serializable
/** 节点名称 */
private String label;
private String value;
private Long type;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long dictId;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String dictName;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children;
@ -74,4 +88,36 @@ public class TreeSelect implements Serializable
{
this.children = children;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Long getType() {
return type;
}
public void setType(Long type) {
this.type = type;
}
public Long getDictId() {
return dictId;
}
public void setDictId(Long dictId) {
this.dictId = dictId;
}
public String getDictName() {
return dictName;
}
public void setDictName(String dictName) {
this.dictName = dictName;
}
}