From ec978c44412537425017548c749c0ea02aa9c3e5 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 22 Jan 2022 18:27:07 +0800 Subject: [PATCH] =?UTF-8?q?bpm=20=E7=9A=84=20OA=20=E8=AF=B7=E5=81=87?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B=E5=90=8E=E7=AB=AF=E4=BC=98=E5=8C=96?= =?UTF-8?q?~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/oa/BpmOALeaveController.http | 12 ++ .../controller/oa/BpmOALeaveController.java | 69 +++++++ .../bpm/controller/oa/OALeaveController.java | 112 ------------ .../oa/vo/OALeaveApplyMembersVO.java | 25 --- .../controller/oa/vo/OALeaveCreateReqVO.java | 29 ++- .../bpm/controller/oa/vo/OALeaveExcelVO.java | 44 ----- .../controller/oa/vo/OALeaveExportReqVO.java | 54 ------ .../controller/oa/vo/OALeavePageReqVO.java | 36 +--- .../controller/oa/vo/OALeaveUpdateReqVO.java | 32 ---- .../bpm/convert/oa/OALeaveConvert.java | 13 +- .../bpm/dal/dataobject/leave/OALeaveDO.java | 44 +++-- .../bpm/dal/mysql/oa/BpmOALeaveMapper.java | 29 +++ .../bpm/dal/mysql/oa/OALeaveMapper.java | 47 ----- .../BpmProcessDefinitionService.java | 9 + .../impl/BpmProcessDefinitionServiceImpl.java | 12 +- .../bpm/service/oa/BpmOALeaveService.java | 53 ++++++ .../service/oa/LeaveApplyEndProcessor.java | 8 +- .../bpm/service/oa/OALeaveService.java | 80 -------- .../service/oa/impl/OALeaveServiceImpl.java | 172 ++++-------------- .../task/BpmProcessInstanceService.java | 12 +- .../dto/BpmProcessInstanceCreateReqDTO.java | 33 ++++ .../impl/BpmProcessInstanceServiceImpl.java | 23 ++- 更新日志.md | 1 + 23 files changed, 339 insertions(+), 610 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.http create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/OALeaveController.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveApplyMembersVO.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExcelVO.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExportReqVO.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveUpdateReqVO.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/BpmOALeaveMapper.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/OALeaveMapper.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/BpmOALeaveService.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/OALeaveService.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/dto/BpmProcessInstanceCreateReqDTO.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.http new file mode 100644 index 000000000..2b4b9b7a0 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.http @@ -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": "我要请假啦啦啦!" +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.java new file mode 100644 index 000000000..41c691a27 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/BpmOALeaveController.java @@ -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 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 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 getLeave(@RequestParam("id") Long id) { + OALeaveDO leave = leaveService.getLeave(id); + return success(OALeaveConvert.INSTANCE.convert(leave)); + } + + @GetMapping("/page") + @ApiOperation("获得请假申请分页") + public CommonResult> getLeavePage(@Valid OALeavePageReqVO pageVO) { + PageResult pageResult = leaveService.getLeavePage(getLoginUserId(), pageVO); + return success(OALeaveConvert.INSTANCE.convertPage(pageResult)); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/OALeaveController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/OALeaveController.java deleted file mode 100644 index 6a3ef12fa..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/OALeaveController.java +++ /dev/null @@ -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 createFormKeyLeave(@Valid @RequestBody OALeaveCreateReqVO createReqVO) { - // processKey 前台传入 - return success(leaveService.createLeave(createReqVO)); - } - - @GetMapping("/getLeaveApplyMembers") - @ApiOperation("获取本人请假申请流程中审批人员,可先检查这些人员是否存在") - public CommonResult getLeaveApplyMembers() { - return success(leaveService.getLeaveApplyMembers()); - } - - @PutMapping("/update") - @ApiOperation("更新请假申请") - @PreAuthorize("@ss.hasPermission('oa:leave:update')") - public CommonResult 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 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 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> getLeaveList(@RequestParam("ids") Collection ids) { - List list = leaveService.getLeaveList(ids); - return success(OALeaveConvert.INSTANCE.convertList(list)); - } - - @GetMapping("/page") - @ApiOperation("获得请假申请分页") - @PreAuthorize("@ss.hasPermission('oa:leave:query')") - public CommonResult> getLeavePage(@Valid OALeavePageReqVO pageVO) { - //值查询自己申请请假 - // TODO @芋艿:这里的传值,到底前端搞,还是后端搞。 - pageVO.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername()); - PageResult 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 list = leaveService.getLeaveList(exportReqVO); - // 导出 Excel - List datas = OALeaveConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "请假申请.xls", "数据", OALeaveExcelVO.class, datas); - } - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveApplyMembersVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveApplyMembersVO.java deleted file mode 100644 index 448f4f6fb..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveApplyMembersVO.java +++ /dev/null @@ -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; -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveCreateReqVO.java index 6cb5538f3..762e19862 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveCreateReqVO.java @@ -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 文件 的 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 taskVariables; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExcelVO.java deleted file mode 100644 index 9280529c8..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExcelVO.java +++ /dev/null @@ -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; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExportReqVO.java deleted file mode 100644 index e07d66f28..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveExportReqVO.java +++ /dev/null @@ -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; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeavePageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeavePageReqVO.java index ea7371523..7e83258e6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeavePageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeavePageReqVO.java @@ -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; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveUpdateReqVO.java deleted file mode 100644 index a9264c9ea..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/oa/vo/OALeaveUpdateReqVO.java +++ /dev/null @@ -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 @json:swagger 和 validator 的注解要加哈。 - - private String taskId; - - private String comment; - - private Map variables; - - // TODO @芋艿:variables 的作用是啥。 - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/oa/OALeaveConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/oa/OALeaveConvert.java index 4da3d56bf..3b49b10b0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/oa/OALeaveConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/oa/OALeaveConvert.java @@ -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 convertList(List list); PageResult convertPage(PageResult page); - List convertList02(List list); - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/leave/OALeaveDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/leave/OALeaveDO.java index b088b7b9c..e8b0e94d2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/leave/OALeaveDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/leave/OALeaveDO.java @@ -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; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/BpmOALeaveMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/BpmOALeaveMapper.java new file mode 100644 index 000000000..8248ea71e --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/BpmOALeaveMapper.java @@ -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 { + + default PageResult selectPage(Long userId, OALeavePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .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)); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/OALeaveMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/OALeaveMapper.java deleted file mode 100644 index 7da1e5479..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/oa/OALeaveMapper.java +++ /dev/null @@ -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 { - - default PageResult selectPage(OALeavePageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .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 selectList(OALeaveExportReqVO reqVO) { - return selectList(new QueryWrapperX() - .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") ); - } - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java index b7ebe80d6..b4a04a101 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java @@ -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 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java index 045fe2a71..289cd4d63 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java @@ -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 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/BpmOALeaveService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/BpmOALeaveService.java new file mode 100644 index 000000000..80d180c59 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/BpmOALeaveService.java @@ -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 getLeavePage(Long userId, OALeavePageReqVO pageReqVO); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java index 068dc4253..7744a8990 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java @@ -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); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/OALeaveService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/OALeaveService.java deleted file mode 100644 index e3590d43d..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/OALeaveService.java +++ /dev/null @@ -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 getLeaveList(Collection ids); - - /** - * 获得请假申请分页 - * - * @param pageReqVO 分页查询 - * @return 请假申请分页 - */ - PageResult getLeavePage(OALeavePageReqVO pageReqVO); - - /** - * 获得请假申请列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 请假申请列表 - */ - List getLeaveList(OALeaveExportReqVO exportReqVO); - - - - /** - * 获取本人请假申请流程中审批人员 - * @return 包括,本人部门的项目经理, 部门经理, HR - */ - OALeaveApplyMembersVO getLeaveApplyMembers(); -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java index a5a996d48..2278665e1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java @@ -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 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 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 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 getLeaveList(Collection ids) { - return leaveMapper.selectBatchIds(ids); - } - - @Override - public PageResult getLeavePage(OALeavePageReqVO pageReqVO) { - return leaveMapper.selectPage(pageReqVO); - } - - @Override - public List 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 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 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 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 getLeavePage(Long userId, OALeavePageReqVO pageReqVO) { + return leaveMapper.selectPage(userId, pageReqVO); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java index 55abbcadd..99e993447 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java @@ -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); + /** * 取消流程实例 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/dto/BpmProcessInstanceCreateReqDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/dto/BpmProcessInstanceCreateReqDTO.java new file mode 100644 index 000000000..972972107 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/dto/BpmProcessInstanceCreateReqDTO.java @@ -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 variables; + + /** + * 业务的唯一标识 + * + * 例如说,请假申请的编号。通过它,可以查询到对应的实例 + */ + @NotEmpty(message = "业务的唯一标识") + private String businessKey; +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java index 55b66bf85..c17c29e56 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java @@ -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 variables, String businessKey) { + // 校验流程定义 if (definition == null) { throw exception(PROCESS_DEFINITION_NOT_EXISTS); } @@ -91,14 +107,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService } // 创建流程实例 - Map 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(); diff --git a/更新日志.md b/更新日志.md index 8f298834d..1df8902de 100644 --- a/更新日志.md +++ b/更新日志.md @@ -42,6 +42,7 @@ * 【新增】已办任务的管理,支持详情的查看 * 【新增】任务分配规则,可指定角色、部门成员、部门负责人、用户、用户组、自定义脚本等维度,进行任务的审批 * 【新增】引入 bpmn-process-designer 0.0.1 版本,提供流程设计器的能力 +* 【优化】新增 LambdaQueryWrapperX 类,改成使用 Lambda 的方式选择字段,避免手写导致字段不正确 ### 🐞 Bug Fixes