Flowable之传阅功能实现

1.定义传阅表

CREATE TABLE `wf_copy` (
  `copy_id` varchar(32) NOT NULL COMMENT '抄送主键',
  `title` varchar(255) DEFAULT '' COMMENT '抄送标题',
  `process_id` varchar(64) DEFAULT '' COMMENT '流程主键',
  `process_name` varchar(255) DEFAULT '' COMMENT '流程名称',
  `category_id` varchar(255) DEFAULT '' COMMENT '流程分类主键',
  `deployment_id` varchar(64) DEFAULT '' COMMENT '部署主键',
  `instance_id` varchar(64) DEFAULT '' COMMENT '流程实例主键',
  `task_id` varchar(64) DEFAULT '' COMMENT '任务主键',
  `business_key` varchar(64)DEFAULT '' COMMENT '公文id',
  `user_id` varchar(32) DEFAULT NULL COMMENT '接收用户id',
  `read_flag` int DEFAULT '0' COMMENT '状态(0未读, 1已读)',
  `create_by` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 1代表删除)',
  PRIMARY KEY (`copy_id`) USING BTREE
) COMMENT='传阅表';

2.添加 Controller 

@Slf4j
@Api(tags = "传阅")
@RequiredArgsConstructor
@RestController
@RequestMapping("/workflow/copy")
public class WfCopyController extends RequestInterceptor {
    private final IWfCopyService copyService;

    /**
     * /workflow/copy/pageBySender?pageNum=1&pageSize=10&draftedDate=2024-01-01,2024-07-01
     * @param pageQuery
     * @param query
     * @return
     */
    @ApiOperation(value = "分页查询:我传阅的")
    @GetMapping(value = "/pageBySender")
    public TableDataInfo<WfCopyRow> pageBySender(PageQuery pageQuery, TaskCopyQuery query) {
        query.setCreateBy(sessionService.getUserId());
        TableDataInfo<WfCopyRow> dataInfo = copyService.queryPageList(query, pageQuery);
        return dataInfo;
    }

    @ApiOperation(value = "分页查询:我的待阅/已阅")
    @GetMapping(value = "/pageByReceiver")
    public TableDataInfo<WfCopyRow> pageByReceiver(PageQuery pageQuery, TaskCopyQuery query) {
        query.setUserId(sessionService.getUserId());
        TableDataInfo<WfCopyRow> dataInfo = copyService.queryPageList(query, pageQuery);
        return dataInfo;
    }

    /**
     * 传阅任务
     * @param copyTask {"procInstId":"", "taskId":"非必填", "copyDeptIds":[], "copyUserIds":[], "copyRoleKeys":["bgs_leader"]}
     * @return
     */
    @ApiOperation(value = "添加传阅")
    @PostMapping(value = "")
    public Result addCopyTask(@Valid @RequestBody WfCopyUser copyTask) {
        if (!copyService.makeCopy(copyTask)) {
            throw new RuntimeException("传阅失败");
        }
        return Result.ok();
    }

    @ApiOperation(value = "撤回传阅(支持多个)")
    @DeleteMapping(value = "/{ids}")
    public Result revokeCopyTask(@PathVariable String[] ids) {
        if (!copyService.removeBatchByIds(Arrays.asList(ids))) {
            throw new RuntimeException("撤回传阅失败");
        }
        return Result.ok();
    }

    @ApiOperation(value = "更新状态")
    @PutMapping
    public Result<Integer> edit(@Valid @RequestBody WfCopyRead bo) {
        return Result.ok(copyService.updateCopyRead(bo));
    }

    @ApiOperation(value = "详情")
    @GetMapping("/{copyId}")
    public Result<WfCopy> detail(@PathVariable String copyId) {
        return Result.ok(copyService.getById(copyId));
    }
}

3.定义 IService

public interface IWfCopyService extends IService<WfCopy> {

    /**
     * 查询传阅列表
     *
     * @param wfCopy 传阅
     * @return 传阅集合
     */
    TableDataInfo<WfCopyRow> queryPageList(TaskCopyQuery wfCopy, PageQuery pageQuery);

    /**
     * 传阅
     * @param copyVO
     * @return
     */
    Boolean makeCopy(WfCopyUser copyVO);

    /**
     * 根据状态
     * @param bo
     * @return
     */
    Integer updateCopyRead(WfCopyRead bo);
}

4.添加 ServiceImpl


@RequiredArgsConstructor
@Service
public class WfCopyServiceImpl extends ServiceImpl<WfCopyMapper, WfCopy> implements IWfCopyService {

    private final WfCopyMapper baseMapper;
    private final HistoryService historyService;
    private final SysRoleMapper roleMapper;
    private final SysUserRoleMapper userRoleMapper;

    /**
     * 查询传阅列表
     *
     * @param bo 传阅
     * @return 传阅
     */
    @Override
    public TableDataInfo<WfCopyRow> queryPageList(TaskCopyQuery bo, PageQuery pageQuery) {
        QueryWrapper<WfCopy> wrapper = QueryWrapperUtil.build(bo);
        wrapper.orderByDesc("c.create_time");
        Page<WfCopyRow> result = baseMapper.selectPageWfCopyRow(pageQuery.build(), wrapper);
        return TableDataInfo.build(result);
    }

    @Override
    public Boolean makeCopy(WfCopyUser copyVO) {
        HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
            .processInstanceId(copyVO.getProcInstId()).singleResult();
        List<String> copyUserIdList = new ArrayList();
        String[] userIds = copyVO.getCopyUserIds();
        if(userIds!=null && userIds.length>0){
            copyUserIdList.addAll(Arrays.asList(userIds));
        }
        //查询部门关联的userIds
        String[] deptIds = copyVO.getCopyDeptIds();
        if(deptIds!=null && deptIds.length>0){
            SysRole sysRole = roleMapper.selectByRoleKey(Cons.ROLE_JSY);
            //查询部门下的接收员
            for(String deptId : deptIds){
                List<String> deptUserIds = userRoleMapper.selectUserIds(sysRole.getRoleId(), deptId);
                copyUserIdList.addAll(deptUserIds);
            }
        }
        List<WfCopy> copyList = new ArrayList<>();
        String taskId = copyVO.getTaskId();
        String title = instance.getProcessDefinitionName();
        if(StrUtil.isNotBlank(taskId)){
            HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
            //Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
            title = instance.getProcessDefinitionName() + "-" + taskInstance.getName();
        }
        //查询角色关联的userIds
        String[] copyRoleKeys = copyVO.getCopyRoleKeys();
        if(copyRoleKeys!=null && copyRoleKeys.length>0){
            for(String roleKey : copyRoleKeys){
                List<String> roleUserIds = userRoleMapper.selectUserIdsByRoleKey(roleKey);
                copyUserIdList.addAll(roleUserIds);
            }
        }
        for (String userId : copyUserIdList) {
            WfCopy copy = new WfCopy();
            copy.setTitle(title);
            copy.setProcessId(instance.getProcessDefinitionId());
            copy.setProcessName(instance.getProcessDefinitionName());
            copy.setDeploymentId(instance.getDeploymentId());
            copy.setInstanceId(copyVO.getProcInstId());
            copy.setTaskId(taskId);
            copy.setBusinessKey(instance.getBusinessKey());
            copy.setUserId(userId);
            copyList.add(copy);
        }
        return this.saveBatch(copyList);
    }

    @Override
    public Integer updateCopyRead(WfCopyRead bo) {
        return baseMapper.updateCopyRead(bo);
    }
}

5.添加 Mapper


@CacheNamespace(implementation= MybatisTimedCache.class, eviction= MybatisTimedCache.class)
@Mapper
public interface WfCopyMapper extends BaseMapper<WfCopy> {

    @Update("update wf_copy set read_flag=#{readFlag} where copy_id=#{copyId}")
    Integer updateCopyRead(WfCopyRead bo);

    Page<WfCopyRow> selectPageWfCopyRow(Page page, @Param("ew") QueryWrapper<WfCopy> wrapper);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.geline.cloud.workflow.mapper.WfCopyMapper">
    <!--<sql id="Base_Column_List">
        copy_id, title, process_id, process_name, category_id, deployment_id, instance_id,
    task_id, business_key, user_id, read_flag, create_by, create_time, update_by, update_time,
    del_flag
    </sql>-->

    <select id="selectPageWfCopyRow" resultType="com.geline.cloud.workflow.domain.WfCopyRow">
        select c.copy_id, c.title, c.process_id, c.instance_id, c.task_id, c.user_id,
               u.nick_name, c.create_time, c.business_key, c.read_flag, c.del_flag
        from wf_copy c
        left join t_gongwe gw on gw.id=c.business_key
        left join sys_user_info u on u.user_id=c.user_id
        left join sys_dept d on d.dept_id=gw.handle_dept_id
        ${ew.customSqlSegment}
    </select>
</mapper>

6.添加 WfCopyUser 


@ApiModel("添加传阅VO")
@Getter
@Setter
public class WfCopyUser {

    @NotBlank(message = "procInstId can not be blank !")
    @ApiModelProperty("流程实例Id")
    private String procInstId;

    @ApiModelProperty("任务Id(非必填)")
    private String taskId;

    @ApiModelProperty("传阅部门ids(非必填)(主办会办接收员时有用)")
    private String[] copyDeptIds;

    @ApiModelProperty("传阅用户ids(非必填)")
    private String[] copyUserIds;

    @ApiModelProperty("传阅角色key(非必填)")
    private String[] copyRoleKeys;

}

7.添加 TaskCopyQuery 


@ApiModel("传阅查询参数")
@Getter
@Setter
public class TaskCopyQuery {

    @ApiModelProperty(value = "接收人id", hidden = true)
    @TableField(value = "c.user_id")
    private String userId;

    @ApiModelProperty(value = "发送人id", hidden = true)
    @TableField(value = "c.create_by")
    private String createBy;

    @ApiModelProperty(value = "公文标题")
    @TableField(value = "c.title", condition = SqlConditions.LIKE)
    private String title;

    @ApiModelProperty(value = "流水号")
    @TableField(value = "gw.serial_number", condition = SqlConditions.LIKE)
    private String serialNumber;

    @ApiModelProperty(value = "公文编号")
    @TableField(value = "gw.gw_code", condition = SqlConditions.LIKE)
    private String gwCode;

    @ApiModelProperty(value = "主办单位")
    @TableField(value = "d.dept_name", condition = SqlConditions.LIKE)
    private String handleDeptName;

    @ApiModelProperty(value = "公文类型")
    @TableField(value = "gw.gw_kind")
    private String gwKind;

    @ApiModelProperty(value = "拟搞人")
    @TableField(value = "gw.drafted_user", condition = SqlConditions.LIKE)
    private String draftedUser;

    @ApiModelProperty(value = "拟搞日期(格式:draftedDate[0]=2020-01-01&draftedDate[1]=2020-02-01)")
    @TableField(value = "gw.drafted_date", condition = SqlConditions.BETWEEN_AND)
    private String[] draftedDate;

    @ApiModelProperty(value = "紧急程度")
    @TableField(value = "gw.grade")
    private String grade;

    @ApiModelProperty(value = "发文单位")
    @TableField(value = "gw.from_dept_name", condition = SqlConditions.LIKE)
    private String fromDeptName;

    @ApiModelProperty(value = "状态(0未读, 1已读)")
    @TableField(value = "c.read_flag")
    private Integer readFlag;

    @ApiModelProperty(value = "删除标志(0正常, 1撤回)")
    @TableField(value = "c.del_flag")
    private String delFlag = "0";
}

8.添加 WfCopyRow 


@ApiModel("传阅返回对象")
@Getter
@Setter
public class WfCopyRow {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("传阅主键")
    private String copyId;

    @ApiModelProperty("传阅标题")
    private String title;

    @ApiModelProperty(value = "业务ID")
    private String businessKey;

    @ApiModelProperty("流程主键")
    private String processId;

    @ApiModelProperty("流程名称")
    private String processName;

    @ApiModelProperty("流程分类主键")
    private String categoryId;

    @ApiModelProperty("部署主键")
    private String deploymentId;

    @ApiModelProperty("流程实例主键")
    private String instanceId;

    @ApiModelProperty("任务主键")
    private String taskId;

    @ApiModelProperty("接收人id")
    private String userId;

    @ApiModelProperty("接收人")
    private String nickName;

    @ApiModelProperty(value = "状态(0未读, 1已读)")
    private Integer readFlag;

    @ApiModelProperty(value = "状态")
    private String readFlagDesc;

    @ApiModelProperty(value = "撤回标志(0正常, 1撤回)")
    private String delFlag;

    @ApiModelProperty("传阅时间")
    private Date createTime;

    @ApiModelProperty(value = "公文信息")
    @TransSQL(value = "select * from t_gongwe where id=#{businessKey}")
    private GwSendRow gongwe;

    public String getReadFlagDesc() {
        return readFlag!=null && readFlag==1 ? "已读" : "未读";
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星梦天河

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值