bpm 的 OA 请假的示例后端优化~

pull/2/head
YunaiV 2022-01-22 18:27:07 +08:00
parent 531629634b
commit ec978c4441
23 changed files with 339 additions and 610 deletions

View File

@ -0,0 +1,12 @@
### 请求 /bpm/oa/leave/create 接口 => 成功
POST {{baseUrl}}/bpm/oa/leave/create
Content-Type: application/json
tenant-id: 1
Authorization: Bearer {{token}}
{
"startTime": "2022-03-01",
"endTime": "2022-03-03",
"type": 1,
"reason": "我要请假啦啦啦!"
}

View File

@ -0,0 +1,69 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.oa.OALeaveConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.oa.BpmOALeaveService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/**
* OA Controller
*
* @author jason
* @author
*/
@Api(tags = "OA 请假申请")
@RestController
@RequestMapping("/bpm/oa/leave")
@Validated
public class BpmOALeaveController {
@Resource
private BpmOALeaveService leaveService;
// TODO @芋艿:权限
@PostMapping("/create")
@ApiOperation("创建请求申请")
public CommonResult<Long> createLeave(@Valid @RequestBody OALeaveCreateReqVO createReqVO) {
return success(leaveService.createLeave(getLoginUserId(), createReqVO));
}
@DeleteMapping("/cancel")
@ApiOperation("取消请假申请")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
public CommonResult<Boolean> cancelLeave(@RequestParam("id") Long id) {
leaveService.cancelLeave(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得请假申请")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
public CommonResult<OALeaveRespVO> getLeave(@RequestParam("id") Long id) {
OALeaveDO leave = leaveService.getLeave(id);
return success(OALeaveConvert.INSTANCE.convert(leave));
}
@GetMapping("/page")
@ApiOperation("获得请假申请分页")
public CommonResult<PageResult<OALeaveRespVO>> getLeavePage(@Valid OALeavePageReqVO pageVO) {
PageResult<OALeaveDO> pageResult = leaveService.getLeavePage(getLoginUserId(), pageVO);
return success(OALeaveConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -1,112 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.oa.OALeaveConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.oa.OALeaveService;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Api(tags = "请假申请")
@RestController
@RequestMapping("/oa/leave")
@Validated
public class OALeaveController {
@Resource
private OALeaveService leaveService;
@PostMapping("/form-key/create")
@ApiOperation("创建外置请假申请")
public CommonResult<Long> createFormKeyLeave(@Valid @RequestBody OALeaveCreateReqVO createReqVO) {
// processKey 前台传入
return success(leaveService.createLeave(createReqVO));
}
@GetMapping("/getLeaveApplyMembers")
@ApiOperation("获取本人请假申请流程中审批人员,可先检查这些人员是否存在")
public CommonResult<OALeaveApplyMembersVO> getLeaveApplyMembers() {
return success(leaveService.getLeaveApplyMembers());
}
@PutMapping("/update")
@ApiOperation("更新请假申请")
@PreAuthorize("@ss.hasPermission('oa:leave:update')")
public CommonResult<Boolean> updateLeave(@Valid @RequestBody OALeaveUpdateReqVO updateReqVO) {
leaveService.updateLeave(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除请假申请")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('oa:leave:delete')")
public CommonResult<Boolean> deleteLeave(@RequestParam("id") Long id) {
leaveService.deleteLeave(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得请假申请")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<OALeaveRespVO> getLeave(@RequestParam("id") Long id) {
OALeaveDO leave = leaveService.getLeave(id);
return success(OALeaveConvert.INSTANCE.convert(leave));
}
@GetMapping("/list")
@ApiOperation("获得请假申请列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<List<OALeaveRespVO>> getLeaveList(@RequestParam("ids") Collection<Long> ids) {
List<OALeaveDO> list = leaveService.getLeaveList(ids);
return success(OALeaveConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得请假申请分页")
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<PageResult<OALeaveRespVO>> getLeavePage(@Valid OALeavePageReqVO pageVO) {
//值查询自己申请请假
// TODO @芋艿:这里的传值,到底前端搞,还是后端搞。
pageVO.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername());
PageResult<OALeaveDO> pageResult = leaveService.getLeavePage(pageVO);
return success(OALeaveConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@ApiOperation("导出请假申请 Excel")
@PreAuthorize("@ss.hasPermission('oa:leave:export')")
@OperateLog(type = EXPORT)
public void exportLeaveExcel(@Valid OALeaveExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<OALeaveDO> list = leaveService.getLeaveList(exportReqVO);
// 导出 Excel
List<OALeaveExcelVO> datas = OALeaveConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "请假申请.xls", "数据", OALeaveExcelVO.class, datas);
}
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ApiModel("请假申请审批人员 Response VO")
@Data
@Builder
@EqualsAndHashCode
@ToString
public class OALeaveApplyMembersVO {
@ApiModelProperty(value = "部门的hr")
private String hr;
@ApiModelProperty(value = "部门的项目经理")
private String pm;
@ApiModelProperty(value = "部门的部门经理")
private String bm;
}

View File

@ -2,22 +2,31 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo;
import lombok.*;
import io.swagger.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("请假申请创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OALeaveCreateReqVO extends OALeaveBaseVO {
public class OALeaveCreateReqVO {
/**
* bpmn <process> id
*/
@ApiModelProperty(value = "流程key")
private String processKey;
@ApiModelProperty(value = "请假的开始时间", required = true)
@NotNull(message = "开始时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date startTime;
@ApiModelProperty(value = "请假的结束时间", required = true)
@NotNull(message = "结束时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date endTime;
@ApiModelProperty(value = "请假类型", required = true, example = "1", notes = "参见 bpm_oa_type")
private Integer type;
@ApiModelProperty(value = "原因", required = true, example = "阅读芋道源码")
private String reason;
@ApiModelProperty(value = "流程用户任务的变量")
private Map<String,Object> taskVariables;
}

View File

@ -1,44 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import com.alibaba.excel.annotation.ExcelProperty;
/**
* Excel VO
*
* @author
*/
@Data
public class OALeaveExcelVO {
@ExcelProperty("请假表单主键")
private Long id;
@ExcelProperty("流程id")
private String processInstanceId;
@ExcelProperty("状态")
private Integer status;
@ExcelProperty("申请人id")
private String userId;
@ExcelProperty("开始时间")
private Date startTime;
@ExcelProperty("结束时间")
private Date endTime;
@ExcelProperty("请假类型")
private String leaveType;
@ExcelProperty("原因")
private String reason;
@ExcelProperty("申请时间")
private Date applyTime;
}

View File

@ -1,54 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel(value = "请假申请 Excel 导出 Request VO", description = "参数和 OaLeavePageReqVO 是一致的")
@Data
public class OALeaveExportReqVO {
@ApiModelProperty(value = "流程id")
private String processInstanceId;
@ApiModelProperty(value = "状态")
private Integer status;
@ApiModelProperty(value = "申请人id")
private String userId;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始开始时间")
private Date beginStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束开始时间")
private Date endStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始结束时间")
private Date beginEndTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束结束时间")
private Date endEndTime;
@ApiModelProperty(value = "请假类型")
private String leaveType;
@ApiModelProperty(value = "原因")
private String reason;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始申请时间")
private Date beginApplyTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束申请时间")
private Date endApplyTime;
}

View File

@ -14,43 +14,21 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class OALeavePageReqVO extends PageParam {
@ApiModelProperty(value = "流程id")
private String processInstanceId;
@ApiModelProperty(value = "状态", example = "1", notes = "参见 bpm_process_instance_result 枚举")
private Integer result;
@ApiModelProperty(value = "状态")
private Integer status;
@ApiModelProperty(value = "请假类型", example = "1", notes = "参见 bpm_oa_type")
private Integer type;
@ApiModelProperty(value = "申请人id")
private String userId;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始开始时间")
private Date beginStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束开始时间")
private Date endStartTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始结束时间")
private Date beginEndTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束结束时间")
private Date endEndTime;
@ApiModelProperty(value = "请假类型")
private String leaveType;
@ApiModelProperty(value = "原因")
@ApiModelProperty(value = "原因", example = "阅读芋道源码", notes = "模糊匹配")
private String reason;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始申请时间")
private Date beginApplyTime;
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束申请时间")
private Date endApplyTime;
private Date endCreateTime;
}

View File

@ -1,32 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.Map;
@ApiModel("请假申请更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OALeaveUpdateReqVO extends OALeaveBaseVO {
@ApiModelProperty(value = "请假表单主键", required = true)
@NotNull(message = "请假表单主键不能为空")
private Long id;
// TODO @jsonswagger 和 validator 的注解要加哈。
private String taskId;
private String comment;
private Map<String,Object> variables;
// TODO @芋艿variables 的作用是啥。
}

View File

@ -1,17 +1,14 @@
package cn.iocoder.yudao.adminserver.modules.bpm.convert.oa;
import java.util.*;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveExcelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Convert
*
@ -24,14 +21,10 @@ public interface OALeaveConvert {
OALeaveDO convert(OALeaveCreateReqVO bean);
OALeaveDO convert(OALeaveUpdateReqVO bean);
OALeaveRespVO convert(OALeaveDO bean);
List<OALeaveRespVO> convertList(List<OALeaveDO> list);
PageResult<OALeaveRespVO> convertPage(PageResult<OALeaveDO> page);
List<OALeaveExcelVO> convertList02(List<OALeaveDO> list);
}

View File

@ -1,16 +1,21 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import lombok.*;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import org.activiti.engine.runtime.ProcessInstance;
/**
* DO
* OA DO
*
* @author
* {@link #day} 1 0.5
*
* @author jason
* @author
*/
@TableName("oa_leave")
@TableName("bpm_oa_leave")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ -25,17 +30,20 @@ public class OALeaveDO extends BaseDO {
@TableId
private Long id;
/**
* id
*
*
* {@link SysUserDO#getId()}
*/
private String processInstanceId;
private Long userId;
/**
*
*
*/
private Integer status;
@TableField("`type`")
private String type;
/**
* id
*
*/
private String userId;
private String reason;
/**
*
*/
@ -45,16 +53,22 @@ public class OALeaveDO extends BaseDO {
*/
private Date endTime;
/**
*
*
*/
private String leaveType;
private Long day;
/**
*
*
*
* {@link cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum}
* BpmProcessInstanceResultEnum
*/
private String reason;
private Integer result;
/**
*
*
*
* {@link ProcessInstance#getId()}
*/
private Date applyTime;
private String processInstanceId;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author jason
* @author
*/
@Mapper
public interface BpmOALeaveMapper extends BaseMapperX<OALeaveDO> {
default PageResult<OALeaveDO> selectPage(Long userId, OALeavePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<OALeaveDO>()
.eqIfPresent(OALeaveDO::getId, userId)
.eqIfPresent(OALeaveDO::getResult, reqVO.getResult())
.eqIfPresent(OALeaveDO::getType, reqVO.getType())
.likeIfPresent(OALeaveDO::getReason, reqVO.getReason())
.betweenIfPresent(OALeaveDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(OALeaveDO::getId));
}
}

View File

@ -1,47 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa;
import java.util.*;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeaveExportReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.OALeavePageReqVO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author
*/
@Mapper
public interface OALeaveMapper extends BaseMapperX<OALeaveDO> {
default PageResult<OALeaveDO> selectPage(OALeavePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<OALeaveDO>()
.eqIfPresent("process_instance_id", reqVO.getProcessInstanceId())
.eqIfPresent("status", reqVO.getStatus())
.eqIfPresent("user_id", reqVO.getUserId())
.betweenIfPresent("start_time", reqVO.getBeginStartTime(), reqVO.getEndStartTime())
.betweenIfPresent("end_time", reqVO.getBeginEndTime(), reqVO.getEndEndTime())
.eqIfPresent("leave_type", reqVO.getLeaveType())
.eqIfPresent("reason", reqVO.getReason())
.betweenIfPresent("apply_time", reqVO.getBeginApplyTime(), reqVO.getEndApplyTime())
.orderByDesc("id") );
}
default List<OALeaveDO> selectList(OALeaveExportReqVO reqVO) {
return selectList(new QueryWrapperX<OALeaveDO>()
.eqIfPresent("process_instance_id", reqVO.getProcessInstanceId())
.eqIfPresent("status", reqVO.getStatus())
.eqIfPresent("user_id", reqVO.getUserId())
.betweenIfPresent("start_time", reqVO.getBeginStartTime(), reqVO.getEndStartTime())
.betweenIfPresent("end_time", reqVO.getBeginEndTime(), reqVO.getEndEndTime())
.eqIfPresent("leave_type", reqVO.getLeaveType())
.eqIfPresent("reason", reqVO.getReason())
.betweenIfPresent("apply_time", reqVO.getBeginApplyTime(), reqVO.getEndApplyTime())
.orderByDesc("id") );
}
}

View File

@ -22,6 +22,7 @@ import java.util.Set;
*
* @author yunlong.li
* @author ZJQ
* @author
*/
public interface BpmProcessDefinitionService {
@ -75,6 +76,14 @@ public interface BpmProcessDefinitionService {
*/
ProcessDefinition getProcessDefinition2(String id);
/**
*
*
* @param key
* @return
*/
ProcessDefinition getActiveProcessDefinition(String key);
/**
* BpmProcessDefinitionExtDO
*

View File

@ -42,6 +42,7 @@ import static java.util.Collections.emptyList;
*
* @author yunlongn
* @author ZJQ
* @author
*/
@Service
@Validated
@ -137,14 +138,9 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
return repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
}
/**
*
*
* @param processDefinitionKey
* @return
*/
private ProcessDefinition getActiveProcessDefinition(String processDefinitionKey) {
return repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey).active().singleResult();
@Override
public ProcessDefinition getActiveProcessDefinition(String key) {
return repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).active().singleResult();
}
@Override

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
*
* @author jason
* @author
*/
public interface BpmOALeaveService {
/**
*
*
* @param userId
* @param createReqVO
* @return
*/
Long createLeave(Long userId, @Valid OALeaveCreateReqVO createReqVO);
/**
*
*
* @param id
*/
void cancelLeave(Long id);
/**
*
*
* @param id
* @return
*/
OALeaveDO getLeave(Long id);
/**
*
*
* @param userId
* @param pageReqVO
* @return
*/
PageResult<OALeaveDO> getLeavePage(Long userId, OALeavePageReqVO pageReqVO);
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.OALeaveMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.BpmOALeaveMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
@ -19,7 +19,7 @@ import java.util.Objects;
public class LeaveApplyEndProcessor implements ExecutionListener {
@Resource
private OALeaveMapper leaveMapper;
private BpmOALeaveMapper leaveMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@ -29,9 +29,9 @@ public class LeaveApplyEndProcessor implements ExecutionListener {
OALeaveDO updateDo = new OALeaveDO();
updateDo.setId(Long.valueOf(businessKey));
if (Objects.equals(approved, true)) {
updateDo.setStatus(BpmProcessInstanceResultEnum.APPROVE.getResult());
updateDo.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult());
} else {
updateDo.setStatus(BpmProcessInstanceResultEnum.REJECT.getResult());
updateDo.setResult(BpmProcessInstanceResultEnum.REJECT.getResult());
}
leaveMapper.updateById(updateDo);

View File

@ -1,80 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.oa;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
*
* @author
*/
public interface OALeaveService {
/**
*
*
* @param createReqVO
* @return
*/
Long createLeave(@Valid OALeaveCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateLeave(@Valid OALeaveUpdateReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteLeave(Long id);
/**
*
*
* @param id
* @return
*/
OALeaveDO getLeave(Long id);
/**
*
*
* @param ids
* @return
*/
List<OALeaveDO> getLeaveList(Collection<Long> ids);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<OALeaveDO> getLeavePage(OALeavePageReqVO pageReqVO);
/**
* , Excel
*
* @param exportReqVO
* @return
*/
List<OALeaveDO> getLeaveList(OALeaveExportReqVO exportReqVO);
/**
*
* @return HR
*/
OALeaveApplyMembersVO getLeaveApplyMembers();
}

View File

@ -1,25 +1,16 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.oa.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.oa.OALeaveConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.OALeaveMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.BpmOALeaveMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.oa.OALeaveService;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO;
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dept.SysPostMapper;
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.oa.BpmOALeaveService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.builders.TaskPayloadBuilder;
import org.activiti.api.task.runtime.TaskRuntime;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -31,91 +22,56 @@ import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstan
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* Service
* OA Service
*
* @author
* @author jason
* @author
*/
@Service
@Validated
public class OALeaveServiceImpl implements OALeaveService {
public class OALeaveServiceImpl implements BpmOALeaveService {
/**
* OA KEY
*/
private static final String PROCESS_KEY = "oa_leave";
@Resource
private OALeaveMapper leaveMapper;
private BpmOALeaveMapper leaveMapper;
@Resource
private RuntimeService runtimeService;
@Resource
private org.activiti.engine.TaskService activitiTaskService;
@Resource
private TaskRuntime taskRuntime;
@Resource
private SysPostMapper sysPostMapper;
@Resource
private SysUserMapper sysUserMapper;
private BpmProcessInstanceService processInstanceService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createLeave(OALeaveCreateReqVO createReqVO) {
// 插入 OA 请假单
OALeaveDO leave = OALeaveConvert.INSTANCE.convert(createReqVO);
leave.setStatus(BpmProcessInstanceResultEnum.PROCESS.getResult());
// TODO @jason应该是存储 userId
leave.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername());
leaveMapper.insert(leave);
Date startTime = createReqVO.getStartTime();
Date endTime = createReqVO.getEndTime();
long day = DateUtil.betweenDay(startTime, endTime, false);
public Long createLeave(Long userId, OALeaveCreateReqVO createReqVO) {
// TODO 芋道源码
// 校验是否超过请假天数的上限;
long day = DateUtil.betweenDay(createReqVO.getStartTime(), createReqVO.getEndTime(), false);
if (day <= 0) {
throw ServiceExceptionUtil.exception(OA_DAY_LEAVE_ERROR);
}
Map<String, Object> taskVariables = createReqVO.getTaskVariables();
taskVariables.put("day", day);
// 创建工作流
Long id = leave.getId();
String businessKey = String.valueOf(id);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(createReqVO.getProcessKey(), businessKey, taskVariables);
String processInstanceId = processInstance.getProcessInstanceId();
// 插入 OA 请假单
OALeaveDO leave = OALeaveConvert.INSTANCE.convert(createReqVO).setUserId(userId).setDay(day)
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
leaveMapper.insert(leave);
// 发起 BPM 流程
Map<String, Object> processInstanceVariables = new HashMap<>();
processInstanceVariables.put("day", day);
String processInstanceId = processInstanceService.createProcessInstance(userId,
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(leave.getId())));
// 将工作流的编号,更新到 OA 请假单中
OALeaveDO updateDo = new OALeaveDO();
updateDo.setProcessInstanceId(processInstanceId);
updateDo.setId(id);
leaveMapper.updateById(updateDo);
return id;
leaveMapper.updateById(new OALeaveDO().setId(leave.getId()).setProcessInstanceId(processInstanceId));
return leave.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateLeave(OALeaveUpdateReqVO updateReqVO) {
// 校验存在
this.validateLeaveExists(updateReqVO.getId());
final Task task = taskRuntime.task(updateReqVO.getTaskId());
activitiTaskService.addComment(task.getId(), task.getProcessInstanceId(), updateReqVO.getComment());
Map<String, Object> variables = updateReqVO.getVariables();
//如何得到部门领导人, 暂时写死
variables.put("deptLeader", "admin");
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId())
.withVariables(variables)
.build());
// TOTO @芋道源码 貌似 IDEA 会自动加上final不需要加 final 哈。虽然是不变,但是代码比较少这么去写)
Object reApply = variables.get("reApply");
if(Objects.equals(reApply, true)){
// 更新 表单
OALeaveDO updateObj = OALeaveConvert.INSTANCE.convert(updateReqVO);
leaveMapper.updateById(updateObj);
}
}
// TODO @jason要不请假不支持删除只支持取消
@Override
public void deleteLeave(Long id) {
public void cancelLeave(Long id) {
// TODO 需要重新实现
// 校验存在
this.validateLeaveExists(id);
// 删除
@ -134,62 +90,8 @@ public class OALeaveServiceImpl implements OALeaveService {
}
@Override
public List<OALeaveDO> getLeaveList(Collection<Long> ids) {
return leaveMapper.selectBatchIds(ids);
}
@Override
public PageResult<OALeaveDO> getLeavePage(OALeavePageReqVO pageReqVO) {
return leaveMapper.selectPage(pageReqVO);
}
@Override
public List<OALeaveDO> getLeaveList(OALeaveExportReqVO exportReqVO) {
return leaveMapper.selectList(exportReqVO);
}
/**
*
* @return hr
*/
@Override
public OALeaveApplyMembersVO getLeaveApplyMembers() {
final Long id = SecurityFrameworkUtils.getLoginUser().getId();
//项目经理
//TODO jason 定义enum
SysPostDO pmPostDO = sysPostMapper.selectByCode("pm");
if (Objects.isNull(pmPostDO)) {
throw ServiceExceptionUtil.exception(OA_PM_POST_NOT_EXISTS);
}
SysUserDO userDO = sysUserMapper.selectById(id);
final List<SysUserDO> pmUsers = sysUserMapper.selectListByDepartIdAndPostId(userDO.getDeptId(), pmPostDO.getId());
if (CollUtil.isEmpty(pmUsers)) {
throw ServiceExceptionUtil.exception(OA_DEPART_PM_POST_NOT_EXISTS);
}
//部门经理
SysPostDO bmPostDO = sysPostMapper.selectByCode("bm");
if (Objects.isNull(bmPostDO)) {
throw ServiceExceptionUtil.exception(OA_BM_POST_NOT_EXISTS);
}
final List<SysUserDO> bmUsers = sysUserMapper.selectListByDepartIdAndPostId(userDO.getDeptId(), bmPostDO.getId());
if (CollUtil.isEmpty(bmUsers)) {
throw ServiceExceptionUtil.exception(OA_DEPART_BM_POST_NOT_EXISTS);
}
//人事
SysPostDO hrPostDO = sysPostMapper.selectByCode("hr");
if (Objects.isNull(hrPostDO)) {
throw ServiceExceptionUtil.exception(OA_HR_POST_NOT_EXISTS);
}
final List<SysUserDO> hrUsers = sysUserMapper.selectListByDepartIdAndPostId(userDO.getDeptId(), hrPostDO.getId());
if (CollUtil.isEmpty(hrUsers)) {
throw ServiceExceptionUtil.exception(OA_DEPART_BM_POST_NOT_EXISTS);
}
return OALeaveApplyMembersVO.builder().pm(pmUsers.get(0).getUsername())
.bm(bmUsers.get(0).getUsername())
.hr(hrUsers.get(0).getUsername()).build();
public PageResult<OALeaveDO> getLeavePage(Long userId, OALeavePageReqVO pageReqVO) {
return leaveMapper.selectPage(userId, pageReqVO);
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.*;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import org.activiti.engine.history.HistoricProcessInstance;
@ -21,7 +22,7 @@ import java.util.Set;
public interface BpmProcessInstanceService {
/**
*
*
*
* @param userId
* @param createReqVO
@ -29,6 +30,15 @@ public interface BpmProcessInstanceService {
*/
String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO);
/**
*
*
* @param userId
* @param createReqDTO
* @return
*/
String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO);
/**
*
*

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.dto;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.Map;
/**
* Request DTO
*
* @author
*/
@Data
public class BpmProcessInstanceCreateReqDTO {
/**
*
*/
@NotEmpty(message = "流程定义的标识不能为空")
private String processDefinitionKey;
/**
*
*/
private Map<String, Object> variables;
/**
*
*
*
*/
@NotEmpty(message = "业务的唯一标识")
private String businessKey;
}

View File

@ -16,6 +16,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDef
import cn.iocoder.yudao.adminserver.modules.bpm.service.message.BpmMessageService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO;
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService;
@ -81,8 +82,23 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Override
@Transactional(rollbackFor = Exception.class)
public String createProcessInstance(Long userId, BpmProcessInstanceCreateReqVO createReqVO) {
// 校验流程定义
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId());
// 发起流程
return createProcessInstance0(userId, definition, createReqVO.getVariables(), null);
}
@Override
public String createProcessInstance(Long userId, BpmProcessInstanceCreateReqDTO createReqDTO) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
// 发起流程
return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey());
}
private String createProcessInstance0(Long userId, ProcessDefinition definition,
Map<String, Object> variables, String businessKey) {
// 校验流程定义
if (definition == null) {
throw exception(PROCESS_DEFINITION_NOT_EXISTS);
}
@ -91,14 +107,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
// 创建流程实例
Map<String, Object> variables = createReqVO.getVariables();
ProcessInstance instance = runtimeService.startProcessInstanceById(createReqVO.getProcessDefinitionId(), variables);
ProcessInstance instance = runtimeService.startProcessInstanceById(definition.getId(), businessKey, variables);
// 设置流程名字
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
// 补全流程实例的拓展表
processInstanceExtMapper.updateByProcessInstanceId(new BpmProcessInstanceExtDO().setProcessInstanceId(instance.getId())
.setFormVariables(createReqVO.getVariables()));
.setFormVariables(variables));
// 添加初始的评论 TODO 芋艿:在思考下
// Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();

View File

@ -42,6 +42,7 @@
* 【新增】已办任务的管理,支持详情的查看
* 【新增】任务分配规则,可指定角色、部门成员、部门负责人、用户、用户组、自定义脚本等维度,进行任务的审批
* 【新增】引入 bpmn-process-designer 0.0.1 版本,提供流程设计器的能力
* 【优化】新增 LambdaQueryWrapperX 类,改成使用 Lambda 的方式选择字段,避免手写导致字段不正确
### 🐞 Bug Fixes