Browse Source

分离UserCache至blade-user-api

test
smallchill 6 years ago
parent
commit
2a6ed4b15e
  1. 9
      blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/FlowEntity.java
  2. 8
      blade-service-api/blade-user-api/pom.xml
  3. 62
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/cache/UserCache.java
  4. 5
      blade-service/blade-desk/pom.xml
  5. 3
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java
  6. 5
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java
  7. 28
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/utils/FlowCache.java

9
blade-service-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/FlowEntity.java

@ -17,7 +17,6 @@
package org.springblade.flowable.core.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
@ -31,8 +30,14 @@ import org.springblade.core.mp.base.BaseEntity;
@EqualsAndHashCode(callSuper = true)
public class FlowEntity extends BaseEntity {
@JsonIgnore
@TableField(exist = false)
private BladeFlow flow;
public BladeFlow getFlow() {
if (flow == null) {
flow = new BladeFlow();
}
return flow;
}
}

8
blade-service-api/blade-user-api/pom.xml

@ -14,4 +14,12 @@
<version>${bladex.project.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-cache</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
</dependencies>
</project>

62
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/cache/UserCache.java vendored

@ -0,0 +1,62 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.user.cache;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
/**
* 系统缓存
*
* @author Chill
*/
public class UserCache {
private static final String USER_CACHE = "blade:user";
private static final String USER_CACHE_ID_ = "user:id";
private static IUserClient userClient;
static {
userClient = SpringUtil.getBean(IUserClient.class);
}
/**
* 获取用户名
*
* @param userId 用户id
* @return
*/
public static User getUser(Integer userId) {
User user = CacheUtil.get(USER_CACHE, USER_CACHE_ID_ + userId, User.class);
if (Func.isEmpty(user)) {
R<User> result = userClient.userInfoById(userId);
if (result.isSuccess()) {
user = result.getData();
if (Func.isNotEmpty(user)) {
CacheUtil.put(USER_CACHE, USER_CACHE_ID_ + userId, user);
}
}
}
return user;
}
}

5
blade-service/blade-desk/pom.xml

@ -37,6 +37,11 @@
<artifactId>blade-dict-api</artifactId>
<version>${bladex.project.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-user-api</artifactId>
<version>${bladex.project.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-flow-api</artifactId>

3
blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java

@ -22,6 +22,7 @@ import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.desk.entity.ProcessLeave;
import org.springblade.desk.service.ILeaveService;
import org.springblade.system.user.cache.UserCache;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -46,6 +47,8 @@ public class LeaveController extends BladeController implements CacheNames {
@GetMapping("detail")
public R<ProcessLeave> detail(Integer businessId) {
ProcessLeave detail = leaveService.getById(businessId);
String name = UserCache.getUser(detail.getCreateUser()).getName();
detail.getFlow().setAssigneeName(name);
return R.data(detail);
}

5
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java

@ -51,6 +51,7 @@ import org.springblade.flowable.engine.entity.FlowProcess;
import org.springblade.flowable.engine.mapper.FlowMapper;
import org.springblade.flowable.engine.service.FlowService;
import org.springblade.flowable.engine.utils.FlowCache;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@ -138,7 +139,7 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
if (processInstanceList.size() > 0) {
if (StringUtil.isNotBlank(processInstanceList.get(0).getStartUserId())) {
String userId = processInstanceList.get(0).getStartUserId();
User user = FlowCache.getUser(Func.toInt(userId));
User user = UserCache.getUser(Func.toInt(userId));
if (user != null) {
flow.setAssignee(historicActivityInstance.getAssignee());
flow.setAssigneeName(user.getName());
@ -148,7 +149,7 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
}
// 获取任务执行人名称
if (StringUtil.isNotBlank(historicActivityInstance.getAssignee())) {
User user = FlowCache.getUser(Func.toInt(historicActivityInstance.getAssignee()));
User user = UserCache.getUser(Func.toInt(historicActivityInstance.getAssignee()));
if (user != null) {
flow.setAssignee(historicActivityInstance.getAssignee());
flow.setAssigneeName(user.getName());

28
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/utils/FlowCache.java

@ -19,12 +19,9 @@ package org.springblade.flowable.engine.utils;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.ProcessDefinition;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springblade.system.utils.DictUtil;
/**
@ -36,15 +33,10 @@ public class FlowCache {
private static final String FLOW_CACHE = "flow:process";
private static final String FLOW_CACHE_ID_ = "definition:id";
private static final String USER_CACHE = "blade:user";
private static final String USER_CACHE_ID_ = "user:id";
private static RepositoryService repositoryService;
private static IUserClient userClient;
static {
repositoryService = SpringUtil.getBean(RepositoryService.class);
userClient = SpringUtil.getBean(IUserClient.class);
}
/**
@ -77,24 +69,4 @@ public class FlowCache {
return DictUtil.getValue(category.split(StringPool.UNDERSCORE)[0], Func.toInt(category.split(StringPool.UNDERSCORE)[1]));
}
/**
* 获取用户名
*
* @param userId 用户id
* @return
*/
public static User getUser(Integer userId) {
User user = CacheUtil.get(USER_CACHE, USER_CACHE_ID_ + userId, User.class);
if (Func.isEmpty(user)) {
R<User> result = userClient.userInfoById(userId);
if (result.isSuccess()) {
user = result.getData();
if (Func.isNotEmpty(user)) {
CacheUtil.put(USER_CACHE, USER_CACHE_ID_ + userId, user);
}
}
}
return user;
}
}

Loading…
Cancel
Save