提交 0247c298 编写于 作者: tangyaolong's avatar tangyaolong

我的分页待办开发提交

上级 e90bdcaa
...@@ -6,13 +6,16 @@ import cn.ibizlab.core.workflow.filter.WFTaskSearchContext; ...@@ -6,13 +6,16 @@ import cn.ibizlab.core.workflow.filter.WFTaskSearchContext;
import cn.ibizlab.core.workflow.mapper.WFCoreMapper; import cn.ibizlab.core.workflow.mapper.WFCoreMapper;
import cn.ibizlab.core.workflow.service.IWFGroupService; import cn.ibizlab.core.workflow.service.IWFGroupService;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService; import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import cn.ibizlab.core.workflow.service.IWFTaskService;
import cn.ibizlab.core.workflow.service.IWFUserService; import cn.ibizlab.core.workflow.service.IWFUserService;
import cn.ibizlab.util.client.IBZUAAFeignClient; import cn.ibizlab.util.client.IBZUAAFeignClient;
import cn.ibizlab.util.domain.MsgBody;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.RuleUtils; import cn.ibizlab.util.helper.RuleUtils;
import cn.ibizlab.util.security.AuthTokenUtil; import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationUser; import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.RemoteService; import cn.ibizlab.util.service.RemoteService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
...@@ -57,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -57,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
...@@ -72,6 +76,9 @@ import java.io.*; ...@@ -72,6 +76,9 @@ import java.io.*;
import java.security.Principal; import java.security.Principal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
@Service("wfCoreService") @Service("wfCoreService")
@Slf4j @Slf4j
...@@ -117,6 +124,9 @@ public class WFCoreService ...@@ -117,6 +124,9 @@ public class WFCoreService
@Autowired @Autowired
private IBZUAAFeignClient ibzuaaFeignClient; private IBZUAAFeignClient ibzuaaFeignClient;
private Map<String,List<Map<String,Object>>> taskMap = new ConcurrentHashMap<>();
private AuthenticationContext createAuthenticationContext() private AuthenticationContext createAuthenticationContext()
{ {
UserIdAuthenticationContext context=new UserIdAuthenticationContext(); UserIdAuthenticationContext context=new UserIdAuthenticationContext();
...@@ -229,6 +239,76 @@ public class WFCoreService ...@@ -229,6 +239,76 @@ public class WFCoreService
return new PageImpl<WFTask>(pages.getRecords(), context.getPageable(), pages.getTotal()); return new PageImpl<WFTask>(pages.getRecords(), context.getPageable(), pages.getTotal());
} }
/**
* 获取所有用户分页存储催办消息
* @return
*/
@Scheduled(fixedRate = 50000)
public synchronized void getBacklogPageContent() {
taskMap.clear();
List<Map> taskList = wfCoreMapper.searchMyTaskByPage();
for (Map map : taskList) {
//根据用户id分类
String templateCode = (String) map.get("UserId");
if (StringUtils.isEmpty(templateCode)){
continue;
}
if(!taskMap.containsKey(templateCode)){
List<Map<String,Object>> listMap = new ArrayList<>();
listMap.add(map);
taskMap.put(templateCode, listMap);
} else {
List<Map<String,Object>> listMap = taskMap.get(templateCode);
listMap.add(map);
taskMap.put(templateCode, listMap);
}
}
}
/**
* 缓存某个用户分页催办消息
* @return
*/
public Page<WFTask> getTaskByPage(WFTaskSearchContext context) {
if (ObjectUtils.isEmpty(context)) {
throw new BadRequestAlertException("无效消息上下文", "WFCoreService", "getBacklogByPage");
}
String toUserId = context.getSessioncontext().get("srfuserid") == null ? "" : context.getSessioncontext().get("srfuserid").toString();
if(StringUtils.isEmpty(toUserId)){
throw new BadRequestAlertException("无法获取当前用户", "WFCoreService", "getBacklogByPage");
}
if (!taskMap.containsKey(toUserId)) {
return Page.empty();
} else {
com.baomidou.mybatisplus.extension.plugins.pagination.Page<WFTask> pages = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>();
int current = context.getPages().getCurrent() < 0 ? 0 : (int) context.getPages().getCurrent();
int size = context.getPages().getCurrent() < 0 ? 0 : (int) context.getPages().getSize();
List<WFTask> pageList = new ArrayList<>();
// 用户ID传入,获取任务组
List<Map<String,Object>> msgBodyList = taskMap.get(toUserId);
List<WFTask> wfTaskList = new ArrayList<>();
for (Map<String,Object> map : msgBodyList) {
WFTask task = JSONObject.parseObject(JSONObject.toJSONString(map), WFTask.class);
wfTaskList.add(task);
}
//计算当前页第一条数据的下标
int currId = context.getPages().getCurrent() > 1 ? (current - 1) * size : 0;
for (int i = 0; i < size && i < msgBodyList.size() - currId; i++) {
pageList.add(wfTaskList.get(currId + i));
}
pages.setSize(size);
pages.setCurrent(current);
pages.setTotal(taskMap.get(toUserId).size());
pages.setRecords(pageList);
return new PageImpl<>(pages.getRecords(), context.getPageable(), pages.getTotal());
}
}
public List<WFTaskWay> getWFLinkByStep(String system,String appname, public List<WFTaskWay> getWFLinkByStep(String system,String appname,
String entity, String processDefinitionKey,String taskDefinitionKey) { String entity, String processDefinitionKey,String taskDefinitionKey) {
......
package cn.ibizlab.core.workflow.mapper; package cn.ibizlab.core.workflow.mapper;
import cn.ibizlab.core.workflow.domain.WFGroup;
import cn.ibizlab.core.workflow.domain.WFProcessNode; import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.domain.WFTask; import cn.ibizlab.core.workflow.domain.WFTask;
import cn.ibizlab.core.workflow.filter.WFTaskSearchContext; import cn.ibizlab.core.workflow.filter.WFTaskSearchContext;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;
import java.util.Map;
public interface WFCoreMapper { public interface WFCoreMapper {
Page<WFTask> searchMyTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ; Page<WFTask> searchMyTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ;
List<Map> searchMyTaskByPage() ;
List<WFProcessNode> searchMyTaskCnt(@Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ; List<WFProcessNode> searchMyTaskCnt(@Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ;
} }
...@@ -17,6 +17,20 @@ ...@@ -17,6 +17,20 @@
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if> <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select> </select>
<select id="searchMyTaskByPage" parameterType="cn.ibizlab.core.workflow.filter.WFTaskSearchContext" resultType="java.util.Map">
select distinct t1.TaskId as Id,USER_ID_ as UserId, t1.DefinitionId as ProcessDefinitionId, t1.DefinitionName as ProcessDefinitionName, t1.DefinitionKey as ProcessDefinitionKey, t1.InstanceId as
ProcessInstanceId,
t1.TaskName as Name, t1.TaskDefinitionKey, t1.BusinessKey as ProcessInstanceBusinessKey, t1.Description, t1.CreateTime from (
select res.ID_ as TaskId,link.USER_ID_,res.PROC_DEF_ID_ as DefinitionId,arp.NAME_ as DefinitionName,arp.KEY_ as DefinitionKey,
res.PROC_INST_ID_ as InstanceId,res.NAME_ as TaskName,res.TASK_DEF_KEY_ as TaskDefinitionKey,res.CATEGORY_ as BusinessKey,
res.DESCRIPTION_ as Description,res.CREATE_TIME_ as CreateTime
from ACT_RU_TASK RES inner join act_re_procdef arp on RES.PROC_DEF_ID_ = arp.ID_ left join ACT_RU_IDENTITYLINK link on res.ID_ = LINK.TASK_ID_
) t1
<where><if test="ew!=null and ew.sqlSegment!=null and !ew.emptyOfWhere">${ew.sqlSegment}</if></where>
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
<select id="searchMyTaskCnt" parameterType="cn.ibizlab.core.workflow.filter.WFTaskSearchContext" resultType="cn.ibizlab.core.workflow.domain.WFProcessNode"> <select id="searchMyTaskCnt" parameterType="cn.ibizlab.core.workflow.filter.WFTaskSearchContext" resultType="cn.ibizlab.core.workflow.domain.WFProcessNode">
select t.ProcessDefinitionKey,max(t.ProcessDefinitionName) as ProcessDefinitionName, select t.ProcessDefinitionKey,max(t.ProcessDefinitionName) as ProcessDefinitionName,
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.api.dto.WFTaskDTO; import cn.ibizlab.api.dto.WFTaskDTO;
import cn.ibizlab.api.mapping.WFGroupMapping;
import cn.ibizlab.api.mapping.WFTaskMapping;
import cn.ibizlab.core.workflow.domain.*; import cn.ibizlab.core.workflow.domain.*;
import cn.ibizlab.core.workflow.extensions.service.WFCoreService; import cn.ibizlab.core.workflow.extensions.service.WFCoreService;
import cn.ibizlab.core.workflow.filter.WFTaskSearchContext; import cn.ibizlab.core.workflow.filter.WFTaskSearchContext;
...@@ -10,7 +12,9 @@ import io.swagger.annotations.Api; ...@@ -10,7 +12,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -44,7 +48,8 @@ public class WFCoreResource ...@@ -44,7 +48,8 @@ public class WFCoreResource
private WFCoreService wfCoreService; private WFCoreService wfCoreService;
@Autowired @Autowired
private IWFTaskService taskService; @Lazy
public WFTaskMapping wfTaskMapping;
@ApiOperation(value = "getWFProcessDefinition", tags = {"WFProcessDefinition" }, notes = "根据系统实体查找当前适配的工作流模型") @ApiOperation(value = "getWFProcessDefinition", tags = {"WFProcessDefinition" }, notes = "根据系统实体查找当前适配的工作流模型")
@RequestMapping(method = RequestMethod.GET, value = "/{system}-app-{appname}/{entity}/process-definitions") @RequestMapping(method = RequestMethod.GET, value = "/{system}-app-{appname}/{entity}/process-definitions")
...@@ -191,6 +196,13 @@ public class WFCoreResource ...@@ -191,6 +196,13 @@ public class WFCoreResource
.body(domains.getContent()); .body(domains.getContent());
} }
@ApiOperation(value = "获取我的分页缓存待办", tags = {"工作流任务" } ,notes = "获取我的分页缓存待办")
@RequestMapping(method= RequestMethod.GET , value="/mypagetasks")
public ResponseEntity<Page<WFTask>> getTaskAll(WFTaskSearchContext context) {
Page page = wfCoreService.getTaskByPage(context);
return ResponseEntity.status(HttpStatus.OK).body(new PageImpl(wfTaskMapping.toDto(page.getContent()), page.getPageable(), page.getContent().size()));
}
@RequestMapping(value = "/mytasks/{processDefinitionKey}/{type}/{businessKey}/usertasks/{taskDefinitionKey}", method = RequestMethod.GET ) @RequestMapping(value = "/mytasks/{processDefinitionKey}/{type}/{businessKey}/usertasks/{taskDefinitionKey}", method = RequestMethod.GET )
public ResponseEntity openTask(@PathVariable("processDefinitionKey") final String processDefinitionKey,@PathVariable("type") final String type, public ResponseEntity openTask(@PathVariable("processDefinitionKey") final String processDefinitionKey,@PathVariable("type") final String type,
@PathVariable("businessKey") final String businessKey, @PathVariable("taskDefinitionKey") final String taskDefinitionKey, @PathVariable("businessKey") final String businessKey, @PathVariable("taskDefinitionKey") final String taskDefinitionKey,
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册