Merge remote-tracking branch 'origin/master'

This commit is contained in:
李京通 2025-06-06 11:06:16 +08:00
commit 8210cee797
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; 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.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.database.domain.BusinessTripApproval; 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.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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; 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.time.format.DateTimeFormatter;
import java.util.List; import java.util.*;
/** /**
* @Description BusinessTripApprovalController * @Description BusinessTripApprovalController
@ -27,81 +36,112 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
@Api(tags = "出差审批单") @Api(tags = "出差审批单")
public class BusinessTripApprovalController extends BaseController { public class BusinessTripApprovalController extends BaseController {
private final BusinessTripApprovalService businessTripApprovalService;
@GetMapping("/list") private final BusinessTripApprovalService businessTripApprovalService;
@ApiOperation("查询出差审批单") private final ISysUserService sysUserService;
private final ISysDeptService sysDeptService;
private final ISysDictDataService dictDataService;
@RequestMapping("/list")
@ApiOperation("查询出差申请")
public TableDataInfo list(BusinessTripApproval businessTripApproval) { public TableDataInfo list(BusinessTripApproval businessTripApproval) {
startPage(); startPage();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); QueryWrapper<BusinessTripApproval> queryWrapper = new QueryWrapper<>(businessTripApproval);
QueryWrapper<BusinessTripApproval> qw = new QueryWrapper<>(businessTripApproval); queryWrapper.orderByDesc("create_time");
qw.orderByDesc("create_time"); List<BusinessTripApproval> list = businessTripApprovalService.list(queryWrapper);
String fTime = businessTripApproval.getFTime(); long size = businessTripApprovalService.count(queryWrapper);
String eTime = businessTripApproval.getETime();
// String 的字符串转成LoaclDateTime格式
List<BusinessTripApproval> list = businessTripApprovalService.list(qw);
long size = list.size();
return getDataTableEnhance(list,size); return getDataTableEnhance(list,size);
} }
@ApiOperation("新增或修改出差审批单 传id为修改 不传id为新增")
@PostMapping("/add") @PostMapping("add")
public AjaxResult add(@RequestBody BusinessTripApproval businessTripApproval) { @ApiOperation("新增出差申请")
public AjaxResult add(BusinessTripApproval dto){
SysUser user = getLoginUser().getUser(); SysUser user = getLoginUser().getUser();
if (businessTripApproval.getId() == null) { if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1){
businessTripApproval.setCreateBy(user.getNickName()); if (dto.getCarModel() == null){
businessTripApproval.setState(0); throw new RuntimeException("请选择使用车型");
boolean result = businessTripApprovalService.save(businessTripApproval);
if (!result) {
return AjaxResult.error("新增出差审批单失败");
} }
return AjaxResult.success(result); if (dto.getUseCarType() == null){
}else { throw new RuntimeException("请选择用车方式");
businessTripApproval.setUpdateBy(user.getNickName());
boolean result = businessTripApprovalService.updateById(businessTripApproval);
if (!result) {
return AjaxResult.error("修改出差审批单失败");
} }
return AjaxResult.success(result); if (dto.getSeats() == null){
throw new RuntimeException("请输入座位数");
} }
} }
if (dto.getStartDate() == null || dto.getEndDate() == null){
@ApiOperation("删除出差审批单") throw new RuntimeException("请选择出差时间范围");
@DeleteMapping("/{id}")
public AjaxResult delete(@PathVariable Long id) {
boolean result = businessTripApprovalService.removeById(id);
if (!result) {
return AjaxResult.error("删除出差审批单失败");
} }
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("/userList")
@GetMapping("/state/{id}") @ApiOperation("查询用户人员列表")
public AjaxResult state(@PathVariable Long id) { public AjaxResult applyList() {
BusinessTripApproval businessTripApproval = businessTripApprovalService.getById(id); List<SysUser> sysUsers = sysUserService.selectList();
if (businessTripApproval == null) { List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
return AjaxResult.error("查询审批流程失败"); 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("审批") public List<TreeSelect> buildTree(List<SysDept> depts, Map<Long, List<SysUser>> deptUsersMap) {
@PostMapping("/approval") List<TreeSelect> treeList = new ArrayList<>();
public AjaxResult approval(@RequestBody ApprovaltDto dto) { for (SysDept dept : depts) {
Long id = dto.getId(); TreeSelect treeSelect = new TreeSelect();
Integer state = dto.getState(); treeSelect.setId(dept.getDeptId());
BusinessTripApproval businessTripApproval = businessTripApprovalService.getById(id); treeSelect.setLabel(dept.getDeptName());
businessTripApproval.setState(state); // 分配用户到部门
boolean result = businessTripApprovalService.updateById(businessTripApproval); List<SysUser> users = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList());
if (!result) { // 这里可以根据需要处理用户信息比如只存储用户名或创建包含用户详细信息的子对象
return AjaxResult.error("审批出差失败"); // 这里简单示例只存储用户名列表
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);
} }
return AjaxResult.success("审批出差成功"); }
// 递归处理子部门
children.addAll(buildTree(dept.getChildren(), deptUsersMap));
if (!children.isEmpty()) {
treeSelect.setChildren(children); // 注意这里我们重置了children因为前面我们错误地将它设置为了用户名字符串列表
}
treeList.add(treeSelect);
}
return treeList;
} }
} }

View File

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

View File

@ -22,6 +22,20 @@ public class TreeSelect implements Serializable
/** 节点名称 */ /** 节点名称 */
private String label; 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) @JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children; private List<TreeSelect> children;
@ -74,4 +88,36 @@ public class TreeSelect implements Serializable
{ {
this.children = children; 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;
}
} }