diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http index f1a8c0e0c..95958cc8e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.http @@ -1,4 +1,4 @@ -### 请求 /login 接口 => 成功 +### 请求 /bpm/process-instance/create 接口 => 成功 POST {{baseUrl}}/bpm/process-instance/create Content-Type: application/json tenant-id: 1 @@ -11,3 +11,8 @@ Authorization: Bearer {{token}} "b": "2" } } + +### 请求 /bpm/process-instance/my-page 接口 => 成功 +GET {{baseUrl}}/bpm/process-instance/my-page +tenant-id: 1 +Authorization: Bearer {{token}} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java index c0430d28b..396d8f4e3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java @@ -1,15 +1,15 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.task; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; 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.ApiOperation; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; @@ -26,11 +26,19 @@ public class BpmProcessInstanceController { @Resource private BpmProcessInstanceService processInstanceService; + // TODO 芋艿:权限 + @PostMapping("/create") @ApiOperation("新建流程实例") public CommonResult createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) { return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO)); -// processInstanceService.getMyProcessInstancePage(getLoginUserId()); + } + + @GetMapping("/my-page") + @ApiOperation(value = "获得我的实例分页列表", notes = "在【我的流程】菜单中,进行调用") + public CommonResult> getMyProcessInstancePage( + @Valid BpmProcessInstanceMyPageReqVO pageReqVO) { + return success(processInstanceService.getMyProcessInstancePage(getLoginUserId(), pageReqVO)); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCreateReqVO.java index 29620d2e8..e4fbc95bb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceCreateReqVO.java @@ -9,8 +9,6 @@ import java.util.Map; @ApiModel("流程实例的创建 Request VO") @Data -//@EqualsAndHashCode(callSuper = true) -//@ToString(callSuper = true) public class BpmProcessInstanceCreateReqVO { @ApiModelProperty(value = "流程定义的编号", required = true, example = "1024") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceMyPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceMyPageReqVO.java index 01d16098f..fda34072f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceMyPageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstanceMyPageReqVO.java @@ -1,6 +1,41 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("流程实例的分页 Item Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class BpmProcessInstanceMyPageReqVO extends PageParam { + + @ApiModelProperty(value = "流程名称", example = "芋道") + private String name; + + @ApiModelProperty(value = "流程定义的编号", example = "2048") + private String processDefinitionId; + + @ApiModelProperty(value = "流程实例的状态", notes = "参见 bpm_process_instance_status", example = "1") + private Integer status; + + @ApiModelProperty(value = "流程实例的结果", notes = "参见 bpm_process_instance_result", example = "2") + private Integer result; + + @ApiModelProperty(value = "开始的创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginCreateTime; + + @ApiModelProperty(value = "结束的创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endCreateTime; + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstancePageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstancePageItemRespVO.java new file mode 100644 index 000000000..798517c4e --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/instance/BpmProcessInstancePageItemRespVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@ApiModel("流程实例的分页 Item Response VO") +@Data +public class BpmProcessInstancePageItemRespVO { + + @ApiModelProperty(value = "流程实例的编号", required = true, example = "1024") + private String id; + + @ApiModelProperty(value = "流程名称", required = true, example = "芋道") + private String name; + + @ApiModelProperty(value = "流程定义的编号", required = true, example = "2048") + private String processDefinitionId; + + @ApiModelProperty(value = "流程分类", required = true, notes = "参见 bpm_model_category 数据字典", example = "1") + private String category; + + @ApiModelProperty(value = "流程实例的状态", required = true, notes = "参见 bpm_process_instance_status", example = "1") + private Integer status; + + @ApiModelProperty(value = "流程实例的结果", required = true, notes = "参见 bpm_process_instance_result", example = "2") + private Integer result; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + + // TODO 芋艿:tasks + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java index 0d8f2fa4e..1b7a2e1a0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java @@ -1,12 +1,17 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.task; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.runtime.ProcessInstance; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.List; + /** * 流程实例 Convert * @@ -18,10 +23,20 @@ public interface BpmProcessInstanceConvert { BpmProcessInstanceConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceConvert.class); @Mappings({ - @Mapping(source = "startUserId", target = "userId"), - @Mapping(source = "id", target = "processInstanceId"), - @Mapping(source = "startTime", target = "createTime") + @Mapping(source = "instance.startUserId", target = "userId"), + @Mapping(source = "instance.id", target = "processInstanceId"), + @Mapping(source = "instance.startTime", target = "createTime"), + @Mapping(source = "definition.id", target = "processDefinitionId"), + @Mapping(source = "definition.name", target = "name"), + @Mapping(source = "definition.category", target = "category") }) - BpmProcessInstanceExtDO convert(ProcessInstance bean); + BpmProcessInstanceExtDO convert(ProcessInstance instance, ProcessDefinition definition); + + PageResult convertPage(PageResult page); + + List convertList(List list); + + @Mapping(source = "processInstanceId", target = "id") + BpmProcessInstancePageItemRespVO convert(BpmProcessInstanceExtDO bean); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java index d1c912172..72a025a34 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; import org.activiti.engine.history.HistoricProcessInstance; +import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.runtime.ProcessInstance; /** @@ -18,9 +19,9 @@ import org.activiti.engine.runtime.ProcessInstance; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor +//@Builder +//@NoArgsConstructor +//@AllArgsConstructor public class BpmProcessInstanceExtDO extends BaseDO { /** @@ -41,6 +42,19 @@ public class BpmProcessInstanceExtDO extends BaseDO { * 关联 {@link ProcessInstance#getId()} */ private String processInstanceId; + /** + * 流程定义的编号 + * + * 关联 {@link ProcessDefinition#getId()} + */ + private String processDefinitionId; + /** + * 流程分类 + * + * 冗余 {@link ProcessDefinition#getCategory()} + * 数据字典 bpm_model_category + */ + private String category; /** * 流程实例的状态 * @@ -48,7 +62,7 @@ public class BpmProcessInstanceExtDO extends BaseDO { */ private Integer status; /** - * 结果 + * 流程实例的结果 * * 枚举 {@link BpmProcessInstanceResultEnum} */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java index 602820d15..fa7a47ae5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java @@ -1,9 +1,24 @@ package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; +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.QueryWrapperX; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface BpmProcessInstanceExtMapper extends BaseMapper { +public interface BpmProcessInstanceExtMapper extends BaseMapperX { + + default PageResult selectPage(Long userId, BpmProcessInstanceMyPageReqVO reqVO) { + return selectPage(reqVO, new QueryWrapperX() + .eqIfPresent("user_id", userId) + .likeIfPresent("name", reqVO.getName()) + .eqIfPresent("process_definition_id", reqVO.getProcessDefinitionId()) + .eqIfPresent("status", reqVO.getStatus()) + .eqIfPresent("result", reqVO.getResult()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("id")); + } + } 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 d3587ecf4..58cb2aeb6 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 @@ -1,7 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; -import cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener.BpmProcessInstanceEventListener; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import javax.validation.Valid; @@ -21,6 +23,14 @@ public interface BpmProcessInstanceService { */ String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO); - void getMyProcessInstancePage(Long userId); + /** + * 获得流程实例的分页 + * + * @param userId 用户编号 + * @param pageReqVO 分页请求 + * @return 流程实例的分页 + */ + PageResult getMyProcessInstancePage(Long userId, + @Valid BpmProcessInstanceMyPageReqVO pageReqVO); } 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 32a6a2009..f06db74cf 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 @@ -1,7 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmProcessInstanceConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task.BpmProcessInstanceExtMapper; @@ -11,6 +14,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDef import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import lombok.extern.slf4j.Slf4j; import org.activiti.engine.HistoryService; import org.activiti.engine.RuntimeService; @@ -81,7 +85,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService // 设置流程名字 runtimeService.setProcessInstanceName(instance.getId(), definition.getName()); // 记录流程实例的拓展表 - createProcessInstanceExt(instance, definition.getName()); + createProcessInstanceExt(instance, definition); // 添加初始的评论 TODO 芋艿:在思考下 Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult(); @@ -101,22 +105,34 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService /** * 创建流程实例的拓展 * + * @param definition 流程定义 * @param instance 流程实例 - * @param name 实例名。此时,instance 的 name 为空,所以需要传递该参数 */ - private void createProcessInstanceExt(ProcessInstance instance, String name) { - BpmProcessInstanceExtDO instanceExt = BpmProcessInstanceConvert.INSTANCE.convert(instance); - instanceExt.setName(name); + private void createProcessInstanceExt(ProcessInstance instance, ProcessDefinition definition) { + BpmProcessInstanceExtDO instanceExt = BpmProcessInstanceConvert.INSTANCE.convert(instance, definition); instanceExt.setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus()); instanceExt.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); processInstanceExtMapper.insert(instanceExt); } + @Override + public PageResult getMyProcessInstancePage(Long userId, + BpmProcessInstanceMyPageReqVO pageReqVO) { + // 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页 + PageResult pageResult = processInstanceExtMapper.selectPage(userId, pageReqVO); + if (CollUtil.isEmpty(pageResult.getList())) { + return new PageResult<>(pageResult.getTotal()); + } + // TODO 芋艿:tasks + // 转换返回 + return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult); + } + public void getMyProcessInstancePage(Long userId) { // id title 所属流程 当前审批环节 状态 结果 创建时间 提交申请时间 【标题、状态】「ActBusiness」 // id title 流程类别 流程版本 提交时间 流程状态 耗时 当前节点 办理 【标题、提交时间】「HistoricProcessInstanceQuery」 - // id title 所属流程 流程类别 创建时间 状态 当前审批环节 【标题、状态】 + // id name 所属流程 流程类别 创建时间 状态 当前审批环节 【标题、流程、时间、状态、结果】 runtimeService.createProcessInstanceQuery().list(); HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery()