提交代码
parent
cf74666de8
commit
cbec808a2e
|
@ -38,8 +38,10 @@ server:
|
|||
wechat:
|
||||
mpAppId: wxe6fd9ad863ac09bf
|
||||
mpAppSecret: ed08e7f6f42a40fc9fa0ebbc1bc6a1db
|
||||
# 数据源配置
|
||||
wxAppId: wx9997d071b4996f23
|
||||
wxAppSecret: 5bcc9ca17b31133d93a025871fc5021d
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
|
|
|
@ -38,6 +38,8 @@ server:
|
|||
wechat:
|
||||
mpAppId: wx90a9158b6acc5584
|
||||
mpAppSecret: ec23a5d78f12afa569c64794570d753c
|
||||
wxAppId: wx9997d071b4996f23
|
||||
wxAppSecret: 5bcc9ca17b31133d93a025871fc5021d
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
|
@ -107,7 +109,7 @@ spring:
|
|||
# 端口,默认为6379
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
database: 1
|
||||
database: 0
|
||||
# 密码
|
||||
password: 123456
|
||||
# 连接超时时间
|
||||
|
|
|
@ -32,6 +32,16 @@ public class WechatAccountConfig {
|
|||
*/
|
||||
private static String myAccessToken;
|
||||
|
||||
/**
|
||||
* 微信小程序AppId
|
||||
*/
|
||||
private static String wxAppId;
|
||||
|
||||
/**
|
||||
* 微信小程序Secret
|
||||
*/
|
||||
private static String wxAppSecret;
|
||||
|
||||
public static String getMpAppId() {
|
||||
return mpAppId;
|
||||
}
|
||||
|
@ -63,4 +73,20 @@ public class WechatAccountConfig {
|
|||
public void setMyAccessToken(String myAccessToken) {
|
||||
WechatAccountConfig.myAccessToken = myAccessToken;
|
||||
}
|
||||
|
||||
public static String getWxAppId() {
|
||||
return wxAppId;
|
||||
}
|
||||
|
||||
public void setWxAppId(String wxAppId) {
|
||||
WechatAccountConfig.wxAppId = wxAppId;
|
||||
}
|
||||
|
||||
public static String getWxAppSecret() {
|
||||
return wxAppSecret;
|
||||
}
|
||||
|
||||
public void setWxAppSecret(String wxAppSecret) {
|
||||
WechatAccountConfig.wxAppSecret = wxAppSecret;
|
||||
}
|
||||
}
|
|
@ -14,6 +14,8 @@ public enum MessageTypeEnum {
|
|||
CLFYSP("50", "材料封样审批"),
|
||||
QYFSSP("60", "取样复试审批");
|
||||
|
||||
//工作流审批由ProcDefKey组成
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.ruoyi.flowable.config;
|
||||
|
||||
import com.ruoyi.flowable.listener.GlobalEventListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
|
||||
import org.flowable.spring.SpringProcessEngineConfiguration;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
/**
|
||||
* Flowable添加全局监听器
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class FlowableGlobalListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private final SpringProcessEngineConfiguration configuration;
|
||||
|
||||
private final GlobalEventListener globalEventListener;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
|
||||
/**
|
||||
* 任务创建全局监听-待办消息发送
|
||||
* PROCESS_CREATED 流程创建
|
||||
* TASK_CREATED 任务创建
|
||||
* TASK_COMPLETED 任务完成
|
||||
* PROCESS_COMPLETED 流程完成
|
||||
* 流程创建、任务创建、任务完成、流程完成
|
||||
*/
|
||||
dispatcher.addEventListener(globalEventListener,FlowableEngineEventType.TASK_CREATED);
|
||||
dispatcher.addEventListener(globalEventListener,FlowableEngineEventType.PROCESS_COMPLETED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,11 +22,7 @@ public class FlowTaskListener implements TaskListener{
|
|||
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
|
||||
log.info("任务监听器:{}", delegateTask);
|
||||
// TODO 获取事件类型 delegateTask.getEventName(),可以通过监听器给任务执行人发送相应的通知消息
|
||||
|
||||
|
||||
log.info("任务监听器:{}", delegateTask.getEventName(),delegateTask.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,276 @@
|
|||
package com.ruoyi.flowable.listener;
|
||||
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.enums.TemplateMessageEnum;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.flowable.flow.FindNextNodeUtil;
|
||||
import com.ruoyi.flowable.service.IFlowBusinessKeyService;
|
||||
import com.ruoyi.system.domain.SysUserOpenid;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserOpenidMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.identitylink.api.IdentityLink;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Flowable全局监听器
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class GlobalEventListener extends AbstractFlowableEngineEventListener {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private WxMpService wxMpService;
|
||||
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
@Autowired
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Autowired
|
||||
private SysUserOpenidMapper sysUserOpenidMapper;
|
||||
|
||||
@Autowired
|
||||
private IFlowBusinessKeyService flowBusinessKeyService;
|
||||
|
||||
@Override
|
||||
protected void processCompleted(FlowableEngineEntityEvent event) {
|
||||
log.info("任务流程审批完成...{}",event.getProcessInstanceId());
|
||||
super.processCompleted(event);
|
||||
List<WxMpTemplateMessage> list = new ArrayList<>();
|
||||
TaskEntity taskEntity = (TaskEntity)event.getEntity();
|
||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskEntity.getProcessInstanceId()).singleResult();
|
||||
String startUserId = processInstance.getStartUserId();
|
||||
SysUser sysUser = sysUserMapper.selectUserById(Convert.toLong(startUserId));
|
||||
//模板数据
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(this.getMsgId(sysUser.getPhonenumber()))
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId()).build();
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing14", this.getMsgProName(Convert.toLong(processInstance.getBusinessKey()))));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing1", processInstance.getProcessDefinitionName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing2", "申请审批通过"));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("time4", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,processInstance.getStartTime())));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing10", sysUser.getNickName()+"["+this.getMsgDepName(sysUser.getDeptId())+"]"));
|
||||
list.add(templateMessage);
|
||||
this.send(list,processInstance.getProcessDefinitionKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void taskCreated(FlowableEngineEntityEvent event) {
|
||||
log.info("创建任务节点...{}",event.getProcessInstanceId());
|
||||
super.taskCreated(event);
|
||||
List<WxMpTemplateMessage> list = new ArrayList<>();
|
||||
TaskEntity taskEntity = (TaskEntity)event.getEntity();
|
||||
List<IdentityLink> idList = taskService.getIdentityLinksForTask(taskEntity.getId());
|
||||
if (CollectionUtils.isNotEmpty(idList)) {
|
||||
List<String> candidateUsers = new ArrayList<>();
|
||||
List<String> candidateGroups = new ArrayList<>();
|
||||
idList.forEach(identityLink -> {
|
||||
if (StringUtils.isNotBlank(identityLink.getUserId())) {
|
||||
candidateUsers.add(identityLink.getUserId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(identityLink.getGroupId())) {
|
||||
candidateGroups.add(identityLink.getGroupId());
|
||||
}
|
||||
});
|
||||
log.info("查询任务节点...{}",String.join(",",candidateUsers),String.join(",",candidateGroups));
|
||||
if(StringUtils.isNotEmpty(candidateUsers) || StringUtils.isNotEmpty(candidateGroups)){
|
||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskEntity.getProcessInstanceId()).singleResult();
|
||||
List<SysUser> sysUserList = flowBusinessKeyService.findFlowTaskUsers(processInstance.getBusinessKey(),candidateUsers,candidateGroups);
|
||||
if(StringUtils.isNotEmpty(sysUserList)){
|
||||
String startUserId = processInstance.getStartUserId();
|
||||
SysUser sysUser = sysUserMapper.selectUserById(Convert.toLong(startUserId));
|
||||
for(SysUser taskUser:sysUserList){
|
||||
//模板数据
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(this.getMsgId(taskUser.getPhonenumber()))
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId()).build();
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing14", this.getMsgProName(Convert.toLong(processInstance.getBusinessKey()))));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing1", processInstance.getProcessDefinitionName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing2", Objects.equals(taskEntity.getName(),"提交申请")?"申请审批驳回":"待"+taskEntity.getName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("time4", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,processInstance.getStartTime())));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing10", sysUser.getNickName()+"["+this.getMsgDepName(sysUser.getDeptId())+"]"));
|
||||
list.add(templateMessage);
|
||||
}
|
||||
this.send(list,processInstance.getProcessDefinitionKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void taskCompleted(FlowableEngineEntityEvent event) {
|
||||
log.info("任务节点审批通过...{}",event.getProcessInstanceId());
|
||||
super.taskCompleted(event);
|
||||
List<WxMpTemplateMessage> list = new ArrayList<>();
|
||||
TaskEntity taskEntity = (TaskEntity)event.getEntity();
|
||||
Task task = taskService.createTaskQuery().taskId(taskEntity.getId()).singleResult();
|
||||
// 查询任务...
|
||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskEntity.getProcessInstanceId()).singleResult();
|
||||
String startUserId = processInstance.getStartUserId();
|
||||
SysUser sysUser = sysUserMapper.selectUserById(Convert.toLong(startUserId));
|
||||
if (Objects.nonNull(task)) {
|
||||
// Step 2. 获取当前流程所有流程变量(网关节点时需要校验表达式)
|
||||
Map<String, Object> variables = taskEntity.getVariables();
|
||||
UserTask nextUserTask = FindNextNodeUtil.getNextUserTasks(repositoryService, task, variables).get(0);
|
||||
List<SysUser> sysUserList = flowBusinessKeyService.findFlowTaskUsers(processInstance.getBusinessKey(),nextUserTask.getCandidateUsers(),nextUserTask.getCandidateGroups());
|
||||
if(StringUtils.isNotEmpty(sysUserList)){
|
||||
for(SysUser taskUser:sysUserList){
|
||||
//模板数据
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(this.getMsgId(taskUser.getPhonenumber()))
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId()).build();
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing14", this.getMsgProName(Convert.toLong(processInstance.getBusinessKey()))));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing1", processInstance.getProcessDefinitionName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing2", "待"+nextUserTask.getName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("time4", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,processInstance.getStartTime())));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing10", sysUser.getNickName()+"["+this.getMsgDepName(sysUser.getDeptId())+"]"));
|
||||
list.add(templateMessage);
|
||||
}
|
||||
this.send(list,processInstance.getProcessDefinitionKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单位名称
|
||||
* @param depId
|
||||
* @return
|
||||
*/
|
||||
private String getMsgDepName(Long depId){
|
||||
String name = Convert.toStr(redisCache.getCacheObject(CacheConstants.WX_MPMESSAGE_DNAME +depId));
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
return name;
|
||||
}else{
|
||||
SysDept sysDept = sysDeptMapper.selectDeptById(depId);
|
||||
//项目名称截取&&超过20字符微信限制并抛出异常
|
||||
String depName = sysDept.getDeptName();
|
||||
if(depName.length()>13){
|
||||
depName = sysDept.getDeptName().substring(0,13);
|
||||
}
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_DNAME +depId,depName,30, TimeUnit.MINUTES);
|
||||
return depName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目名称
|
||||
* @param proId
|
||||
* @return
|
||||
*/
|
||||
private String getMsgProName(Long proId){
|
||||
String name = Convert.toStr(redisCache.getCacheObject(CacheConstants.WX_MPMESSAGE_PNAME +proId));
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
return name;
|
||||
}else{
|
||||
Map<String, Object> proMap = flowBusinessKeyService.selectSurProjectById(proId);
|
||||
//项目名称截取&&超过20字符微信限制并抛出异常
|
||||
String proName = Convert.toStr(proMap.get("projectName"));
|
||||
if(proName.length()>20){
|
||||
proName = proName.substring(0,20);
|
||||
}
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_PNAME +proId,proName,30, TimeUnit.MINUTES);
|
||||
return proName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询微信用户列表
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
private String getMsgId(String userName){
|
||||
String openIds = Convert.toStr(redisCache.getCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName));
|
||||
if(StringUtils.isNotEmpty(openIds)){
|
||||
return openIds;
|
||||
}else{
|
||||
List<SysUserOpenid> list = sysUserOpenidMapper.findSysUserOpenidsByUser(userName);
|
||||
List<String> strs = list.stream().map(SysUserOpenid :: getMsgOpenId).collect(Collectors.toList());
|
||||
openIds = String.join(",",strs);
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName,openIds,30, TimeUnit.MINUTES);
|
||||
return openIds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板消息开关
|
||||
*/
|
||||
private boolean wxSwitch = true;
|
||||
|
||||
/**
|
||||
* 推送模板消息
|
||||
* @param lsit
|
||||
*/
|
||||
private void send(List<WxMpTemplateMessage> lsit, String messageType){
|
||||
try {
|
||||
if(wxSwitch && StringUtils.isNotEmpty(lsit)){
|
||||
for(WxMpTemplateMessage message:lsit){
|
||||
if(StringUtils.isNotEmpty(message.getToUser())){
|
||||
String[] toUsers = message.getToUser().split(",");
|
||||
for(String toUser:toUsers){
|
||||
//判断短时间内是否已发送相同类型的消息
|
||||
String key = CacheConstants.WX_MPMESSAGE_KEY +toUser+"-"+messageType;
|
||||
if(Convert.toBool(redisCache.getCacheObject(key),true)){
|
||||
//多个登录账号时批量发送
|
||||
message.setToUser(toUser);
|
||||
wxMpService.getTemplateMsgService().sendTemplateMsg(message);
|
||||
//5分钟内不推送相同类型的消息
|
||||
redisCache.setCacheObject(key,false,5, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.info("出错了...{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.flowable.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.system.domain.FlowTaskEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -12,12 +13,26 @@ import java.util.Map;
|
|||
public interface IFlowBusinessKeyService {
|
||||
|
||||
/**
|
||||
* 根据条件查询所有流任务
|
||||
* 根据条件查询所有流程任务
|
||||
* @param flowTaskEntity
|
||||
* @return
|
||||
*/
|
||||
public List<FlowTaskEntity> selectAllFlowTaskByParams(FlowTaskEntity flowTaskEntity);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程任务
|
||||
* @param procInsId
|
||||
* @return
|
||||
*/
|
||||
public FlowTaskEntity findFlowTaskByProcInsId(String procInsId);
|
||||
|
||||
/**
|
||||
* 查询项目信息
|
||||
* @param proId
|
||||
* @return
|
||||
*/
|
||||
public Map<String,Object> selectSurProjectById(Long proId);
|
||||
|
||||
/**
|
||||
* 根据条件统计所有流任务
|
||||
* @param flowTaskEntity
|
||||
|
@ -83,4 +98,13 @@ public interface IFlowBusinessKeyService {
|
|||
public List<FlowTaskEntity> findSafetyWorkList(FlowTaskEntity flowTaskEntity);
|
||||
|
||||
public List<FlowTaskEntity> listByCategory(FlowTaskEntity where);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskUsers(String businessKey, List<String> candidateUsers, List<String> candidateGroups);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.ruoyi.flowable.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.flowable.service.IFlowBusinessKeyService;
|
||||
import com.ruoyi.system.domain.FlowTaskEntity;
|
||||
import com.ruoyi.system.mapper.FlowBusinessKeyMapper;
|
||||
|
@ -8,10 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 业务工作流程自定义
|
||||
|
@ -35,6 +34,26 @@ public class FlowBusinessKeyServiceImpl implements IFlowBusinessKeyService {
|
|||
return flowBusinessKeyMapper.selectAllFlowTaskByParams(flowTaskEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件查询流程任务
|
||||
* @param procInsId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FlowTaskEntity findFlowTaskByProcInsId(String procInsId) {
|
||||
return flowBusinessKeyMapper.findFlowTaskByProcInsId(procInsId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目信息
|
||||
* @param proId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Object> selectSurProjectById(Long proId) {
|
||||
return flowBusinessKeyMapper.selectSurProjectById(proId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件统计所有流任务
|
||||
* @param flowTaskEntity
|
||||
|
@ -158,4 +177,21 @@ public class FlowBusinessKeyServiceImpl implements IFlowBusinessKeyService {
|
|||
public List<FlowTaskEntity> listByCategory(FlowTaskEntity where) {
|
||||
return flowBusinessKeyMapper.listByCategory(where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysUser> findFlowTaskUsers(String businessKey, List<String> candidateUsers, List<String> candidateGroups){
|
||||
if(StringUtils.isNotEmpty(candidateGroups) && candidateGroups.contains("47")){
|
||||
return flowBusinessKeyMapper.findFlowTaskDeptUsers(businessKey,candidateUsers,candidateGroups);
|
||||
}else{
|
||||
return flowBusinessKeyMapper.findFlowTaskUsers(businessKey,candidateUsers,candidateGroups);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -100,6 +100,19 @@ public class TokenService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户身份信息
|
||||
*/
|
||||
public void delLoginUser(HttpServletRequest request)
|
||||
{
|
||||
String token = this.getToken(request);
|
||||
if (StringUtils.isNotEmpty(token))
|
||||
{
|
||||
String userKey = getTokenKey(token);
|
||||
redisCache.deleteObject(userKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建令牌
|
||||
*
|
||||
|
@ -161,7 +174,7 @@ public class TokenService
|
|||
String userKey = getTokenKey(uuid);
|
||||
LoginUser user = redisCache.getCacheObject(userKey);
|
||||
user.setLoginTime(System.currentTimeMillis());
|
||||
int mobileExpireTime = 24;//expireTime * 3650 * 60 ;
|
||||
int mobileExpireTime = expireTime * 3650 * 60 ;
|
||||
user.setExpireTime(user.getLoginTime() + mobileExpireTime * MILLIS_MINUTE);
|
||||
// 根据uuid将loginUser缓存
|
||||
redisCache.setCacheObject(userKey, user, mobileExpireTime, TimeUnit.HOURS);
|
||||
|
|
|
@ -35,6 +35,11 @@
|
|||
<artifactId>ruoyi-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,54 @@
|
|||
package com.ruoyi.quartz.mapper;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 调度任务信息 数据层
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
public interface TaskMapper {
|
||||
|
||||
/**
|
||||
* 查询超时3天未办理的任务
|
||||
*/
|
||||
public List<Map<String, Object>> findDaysAwaitFlowTask();
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskUsers(@Param("businessKey") String businessKey, @Param("candidateUsers") List<String> candidateUsers, @Param("candidateGroups") List<String> candidateGroups);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskDeptUsers(@Param("businessKey") String businessKey, @Param("candidateUsers") List<String> candidateUsers, @Param("candidateGroups") List<String> candidateGroups);
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表
|
||||
*
|
||||
* @param userName 用户登录名
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findSysUserOpenidsByUser(String userName);
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表[项目甲代]
|
||||
*
|
||||
* @param proId 项目信息
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findMsgProMagUsers(Long proId);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.ruoyi.quartz.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 定时任务Service
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
public interface ITaskService {
|
||||
|
||||
/**
|
||||
* 查询超时3天未办理的任务
|
||||
*/
|
||||
public List<Map<String, Object>> findDaysAwaitFlowTask();
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskUsers(String businessKey, List<String> candidateUsers, List<String> candidateGroups);
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表
|
||||
*
|
||||
* @param userName 用户登录名
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findSysUserOpenidsByUser(String userName);
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表[项目甲代]
|
||||
*
|
||||
* @param proId 项目信息
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findMsgProMagUsers(Long proId);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.ruoyi.quartz.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.quartz.mapper.TaskMapper;
|
||||
import com.ruoyi.quartz.service.ITaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 定时任务ServiceImpl
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
@Service
|
||||
public class ITaskServiceImpl implements ITaskService {
|
||||
|
||||
@Autowired
|
||||
private TaskMapper taskMapper;
|
||||
|
||||
/**
|
||||
* 查询超时3天未办理的任务
|
||||
*/
|
||||
public List<Map<String, Object>> findDaysAwaitFlowTask(){
|
||||
return taskMapper.findDaysAwaitFlowTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysUser> findFlowTaskUsers(String businessKey, List<String> candidateUsers, List<String> candidateGroups){
|
||||
if(StringUtils.isNotEmpty(candidateGroups) && candidateGroups.contains("47")){
|
||||
return taskMapper.findFlowTaskDeptUsers(businessKey,candidateUsers,candidateGroups);
|
||||
}else{
|
||||
return taskMapper.findFlowTaskUsers(businessKey,candidateUsers,candidateGroups);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表
|
||||
*
|
||||
* @param userName 用户登录名
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findSysUserOpenidsByUser(String userName) {
|
||||
return taskMapper.findSysUserOpenidsByUser(userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户绑定小程序openId列表[项目甲代]
|
||||
*
|
||||
* @param proId 项目信息
|
||||
* @return 用户绑定小程序openId集合
|
||||
*/
|
||||
public List<Map<String, Object>> findMsgProMagUsers(Long proId) {
|
||||
return taskMapper.findMsgProMagUsers(proId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package com.ruoyi.quartz.task;
|
||||
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.enums.TemplateMessageEnum;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.quartz.service.ITaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 工作流任务超时提醒定时任务
|
||||
*
|
||||
* @author JiangYuQi
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("flowTaskExpiredTask")
|
||||
public class FlowTaskExpiredTask {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private WxMpService wxMpService;
|
||||
|
||||
@Autowired
|
||||
private ITaskService taskService;
|
||||
|
||||
/**
|
||||
* 从Flowable中查询超时数据进行消息提醒
|
||||
* 分布式锁::quartz.task.flowTaskExpiredTask.notifyExpiredData
|
||||
* 由程序定时调用 JiangYuQi
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public void notifyApplyExpiredData() {
|
||||
/**String key = "quartz.task.flowTaskExpiredTask.notifyExpiredData";
|
||||
boolean lock = redisLock.tryLock(key, Constants.REDIS_LOCK, TimeUnit.SECONDS);
|
||||
if (lock) {*/
|
||||
try {
|
||||
log.info("劫持锁...{}...开始执行::工程审批超时提醒定时任务...{}");
|
||||
List<Map<String, Object>> list = taskService.findDaysAwaitFlowTask();
|
||||
for(Map<String, Object> dataMap:list){
|
||||
List<String> candidateUsers = new ArrayList<>();
|
||||
List<String> candidateGroups = new ArrayList<>();
|
||||
if(StringUtils.isNotNull(dataMap.get("ASSIGNEE_"))){
|
||||
candidateUsers.add(Convert.toStr(dataMap.get("ASSIGNEE_")));
|
||||
}
|
||||
if(StringUtils.isNotNull(dataMap.get("USER_ID_"))){
|
||||
candidateUsers.add(Convert.toStr(dataMap.get("USER_ID_")));
|
||||
}
|
||||
if(StringUtils.isNotNull(dataMap.get("GROUP_ID_"))){
|
||||
candidateGroups.add(Convert.toStr(dataMap.get("GROUP_ID_")));
|
||||
}
|
||||
String businessKey = Convert.toStr(dataMap.get("businessKey"));
|
||||
String businessKeyName = Convert.toStr(dataMap.get("businessKeyName"));
|
||||
List<SysUser> sysUserList = taskService.findFlowTaskUsers(businessKey,candidateUsers,candidateGroups);
|
||||
if(StringUtils.isNotEmpty(sysUserList)){
|
||||
for(SysUser taskUser:sysUserList){
|
||||
//模板数据
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(this.getMsgId(taskUser.getPhonenumber()))
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId()).build();
|
||||
// templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing14", businessKeyName));
|
||||
// templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing1", processInstance.getProcessDefinitionName()));
|
||||
// templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing2", Objects.equals(taskEntity.getName(),"提交申请")?"申请审批驳回":"待"+taskEntity.getName()));
|
||||
// templateMessage.addWxMpTemplateData(new WxMpTemplateData("time4", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,processInstance.getStartTime())));
|
||||
// templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing10", sysUser.getNickName()+"["+this.getMsgDepName(sysUser.getDeptId())+"]"));
|
||||
// list.add(templateMessage);
|
||||
}
|
||||
//this.send(list,processInstance.getProcessDefinitionKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("任务执行异常...{}...::::结束执行...{}", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
/**finally {
|
||||
log.info("释放锁...{}", key);
|
||||
redisLock.unlock(key);
|
||||
}
|
||||
}else{
|
||||
log.info("尝试劫持锁失败...{}", key);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询微信用户列表
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
private String getMsgId(String userName){
|
||||
String openIds = Convert.toStr(redisCache.getCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName));
|
||||
if(StringUtils.isNotEmpty(openIds)){
|
||||
return openIds;
|
||||
}else{
|
||||
List<Map<String, Object>> list = taskService.findSysUserOpenidsByUser(userName);
|
||||
List<String> strs = list.stream().map(Map -> Map.get("msgOpenId").toString()).collect(Collectors.toList());
|
||||
openIds = String.join(",",strs);
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName,openIds,30, TimeUnit.MINUTES);
|
||||
return openIds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板消息开关
|
||||
*/
|
||||
private boolean wxSwitch = true;
|
||||
|
||||
/**
|
||||
* 推送模板消息
|
||||
* @param lsit
|
||||
*/
|
||||
private void send(List<WxMpTemplateMessage> lsit, String messageType){
|
||||
try {
|
||||
if(wxSwitch && StringUtils.isNotEmpty(lsit)){
|
||||
for(WxMpTemplateMessage message:lsit){
|
||||
if(StringUtils.isNotEmpty(message.getToUser())){
|
||||
String[] toUsers = message.getToUser().split(",");
|
||||
for(String toUser:toUsers){
|
||||
//判断短时间内是否已发送相同类型的消息
|
||||
String key = CacheConstants.WX_MPMESSAGE_KEY +toUser+"-"+messageType;
|
||||
if(Convert.toBool(redisCache.getCacheObject(key),true)){
|
||||
//多个登录账号时批量发送
|
||||
message.setToUser(toUser);
|
||||
wxMpService.getTemplateMsgService().sendTemplateMsg(message);
|
||||
//5分钟内不推送相同类型的消息
|
||||
redisCache.setCacheObject(key,false,5, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.info("出错了...{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?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.ruoyi.quartz.mapper.TaskMapper">
|
||||
|
||||
<!--查询超时的代办任务-->
|
||||
<select id="findDaysAwaitFlowTask" resultType="Map">
|
||||
select fa.businessKey,fa.businessKeyName,fa.ASSIGNEE_,fa.USER_ID_,fa.GROUP_ID_,count(1) as total from vw_flow_await fa where fa.taskName !='提交申请' and fa.duration > 4320 GROUP BY fa.businessKey,fa.businessKeyName,fa.ASSIGNEE_,fa.USER_ID_,fa.GROUP_ID_
|
||||
</select>
|
||||
|
||||
<select id="findFlowTaskUsers" resultType="com.ruoyi.common.core.domain.entity.SysUser">
|
||||
select su.* from sys_user su
|
||||
left join sur_project_userinfo spu on spu.user_id = su.user_id
|
||||
left join sys_user_role sur on sur.user_id = su.user_id
|
||||
where spu.project_id = #{businessKey}
|
||||
<if test="candidateUsers !=null and candidateUsers.size()>0">
|
||||
and su.user_id in
|
||||
<foreach collection="candidateUsers" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="candidateGroups !=null and candidateGroups.size()>0">
|
||||
and sur.role_id in
|
||||
<foreach collection="candidateGroups" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="findFlowTaskDeptUsers" resultType="com.ruoyi.common.core.domain.entity.SysUser">
|
||||
select su.* from sys_user su
|
||||
left join sys_dept sd on sd.dept_id = su.dept_id
|
||||
left join sys_user_role sur on sur.user_id = su.user_id
|
||||
where 1=1
|
||||
<if test="candidateUsers !=null and candidateUsers.size()>0">
|
||||
and su.user_id in
|
||||
<foreach collection="candidateUsers" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="candidateGroups !=null and candidateGroups.size()>0">
|
||||
and sur.role_id in
|
||||
<foreach collection="candidateGroups" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
and EXISTS
|
||||
(SELECT 1 FROM sur_project sp WHERE sp.id=#{businessKey} and (FIND_IN_SET(sp.deptId,sd.ancestors) or sp.deptId=sd.dept_id));
|
||||
</select>
|
||||
|
||||
<select id="findSysUserOpenidsByUser" parameterType="String" resultType="Map">
|
||||
select id, openId, msgOpenId, userId, loginName, nickname, isDel, creatTime, unionid from sys_user_openid where loginName = #{loginName} and isDel = 0
|
||||
</select>
|
||||
|
||||
<!--查询项目甲方代表-->
|
||||
<select id="findMsgProMagUsers" parameterType="Long" resultType="Map">
|
||||
select suo.id, suo.openId, suo.msgOpenId, suo.userId, suo.loginName, suo.nickname, suo.isDel, suo.creatTime, suo.unionid
|
||||
from sys_user_openid suo
|
||||
left join sys_user su on su.phonenumber = suo.loginName
|
||||
left join sur_project_userinfo spu on spu.user_id = su.user_id
|
||||
where spu.project_id = #{proId} and spu.job_type=21 and spu.is_del = 0 and su.del_flag = '0' and suo.isDel=0
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -1,6 +1,8 @@
|
|||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.system.domain.FlowTaskEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -17,6 +19,20 @@ public interface FlowBusinessKeyMapper {
|
|||
*/
|
||||
public List<FlowTaskEntity> selectAllFlowTaskByParams(FlowTaskEntity flowTaskEntity);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程任务
|
||||
* @param procInsId
|
||||
* @return
|
||||
*/
|
||||
public FlowTaskEntity findFlowTaskByProcInsId(String procInsId);
|
||||
|
||||
/**
|
||||
* 查询项目信息
|
||||
* @param proId
|
||||
* @return
|
||||
*/
|
||||
public Map<String,Object> selectSurProjectById(Long proId);
|
||||
|
||||
/**
|
||||
* 根据流程Id查询操作日志
|
||||
* @param procInsId
|
||||
|
@ -74,4 +90,22 @@ public interface FlowBusinessKeyMapper {
|
|||
public List<FlowTaskEntity> findSafetyWorkList(FlowTaskEntity flowTaskEntity);
|
||||
|
||||
public List<FlowTaskEntity> listByCategory(FlowTaskEntity where);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskUsers(@Param("businessKey") String businessKey, @Param("candidateUsers") List<String> candidateUsers, @Param("candidateGroups") List<String> candidateGroups);
|
||||
|
||||
/**
|
||||
* 根据条件查询流程用户
|
||||
* @param businessKey 流程归属表单
|
||||
* @param candidateUsers 办理用户列表
|
||||
* @param candidateGroups 办理角色列表
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> findFlowTaskDeptUsers(@Param("businessKey") String businessKey, @Param("candidateUsers") List<String> candidateUsers, @Param("candidateGroups") List<String> candidateGroups);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<!-- fa.assigneeId,-->
|
||||
<!-- fa.assigneeName,-->
|
||||
<!-- fa.assigneeDeptName-->
|
||||
<select id="selectAllFlowTaskByParams" parameterType="com.ruoyi.system.domain.FlowTaskEntity" resultType="com.ruoyi.system.domain.FlowTaskEntity">
|
||||
<select id="selectAllFlowTaskByParams" parameterType="com.ruoyi.system.domain.FlowTaskEntity" resultType="com.ruoyi.system.domain.FlowTaskEntity">
|
||||
SELECT * FROM
|
||||
vw_flow_all fa
|
||||
<where>
|
||||
|
@ -50,6 +50,12 @@
|
|||
order by fa.createTime desc
|
||||
</select>
|
||||
|
||||
<!--查询工作流任务-->
|
||||
<select id="findFlowTaskByProcInsId" parameterType="string" resultType="com.ruoyi.system.domain.FlowTaskEntity">
|
||||
select vf.* as startUserPhone from vw_flow_all vf
|
||||
where vf.procInsId = #{procInsId}
|
||||
</select>
|
||||
|
||||
<!--查询工作流操作日志-->
|
||||
<select id="selectCommentByProcInsId" parameterType="string" resultType="map">
|
||||
select * from vw_flow_comment where procInstId = #{procInstId} order by startTime DESC
|
||||
|
@ -387,7 +393,6 @@
|
|||
<if test="deptId !=null and deptId>0">and businessDeptId=#{deptId}</if>
|
||||
GROUP BY businessKey ) a,sur_project b WHERE a.businessKey=b.id
|
||||
ORDER BY a.cnt DESC
|
||||
|
||||
</select>
|
||||
|
||||
<select id="findSafetyWorkList" parameterType="com.ruoyi.system.domain.FlowTaskEntity" resultType="com.ruoyi.system.domain.FlowTaskEntity">
|
||||
|
@ -422,4 +427,49 @@
|
|||
</where>
|
||||
order by fa.createTime desc
|
||||
</select>
|
||||
|
||||
<select id="selectSurProjectById" parameterType="Long" resultType="Map">
|
||||
select * from sur_project where id = #{proId}
|
||||
</select>
|
||||
|
||||
<select id="findFlowTaskUsers" resultType="com.ruoyi.common.core.domain.entity.SysUser">
|
||||
select su.* from sys_user su
|
||||
left join sur_project_userinfo spu on spu.user_id = su.user_id
|
||||
left join sys_user_role sur on sur.user_id = su.user_id
|
||||
where spu.project_id = #{businessKey}
|
||||
<if test="candidateUsers !=null and candidateUsers.size()>0">
|
||||
and su.user_id in
|
||||
<foreach collection="candidateUsers" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="candidateGroups !=null and candidateGroups.size()>0">
|
||||
and sur.role_id in
|
||||
<foreach collection="candidateGroups" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="findFlowTaskDeptUsers" resultType="com.ruoyi.common.core.domain.entity.SysUser">
|
||||
select su.* from sys_user su
|
||||
left join sys_dept sd on sd.dept_id = su.dept_id
|
||||
left join sys_user_role sur on sur.user_id = su.user_id
|
||||
where 1=1
|
||||
<if test="candidateUsers !=null and candidateUsers.size()>0">
|
||||
and su.user_id in
|
||||
<foreach collection="candidateUsers" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="candidateGroups !=null and candidateGroups.size()>0">
|
||||
and sur.role_id in
|
||||
<foreach collection="candidateGroups" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
and EXISTS
|
||||
(SELECT 1 FROM sur_project sp WHERE sp.id=#{businessKey} and (FIND_IN_SET(sp.deptId,sd.ancestors) or sp.deptId=sd.dept_id));
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -32,39 +32,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and rd.category_ = #{category}
|
||||
</if>
|
||||
</where>
|
||||
<!-- GROUP BY rp.key_-->
|
||||
<!-- GROUP BY rp.key_ -->
|
||||
group by rp.deployment_id_
|
||||
order by rpr.SORT_
|
||||
</select>
|
||||
|
||||
<select id="selectMyDeployList" resultType="com.ruoyi.system.domain.FlowProcDefDto">
|
||||
SELECT
|
||||
DISTINCT rp.id_ as id,
|
||||
rp.deployment_id_ as deploymentId,
|
||||
rd.name_ as name,
|
||||
rd.category_ as category,
|
||||
sdd.dict_label as categoryName,
|
||||
rp.key_ as flowKey,
|
||||
rp.version_ as version,
|
||||
rp.suspension_state_ as suspensionState,
|
||||
rd.deploy_time_ as deploymentTime
|
||||
FROM
|
||||
act_re_procdef rp
|
||||
LEFT JOIN act_re_deployment rd ON rp.deployment_id_ = rd.id_
|
||||
left join sys_dict_data sdd on sdd.dict_type='sys_process_category' and sdd.dict_value = rd.category_
|
||||
left join act_re_procdef_role rpr on rp.key_ = rpr.PROCDEF_KEY_
|
||||
left join sys_user_role sur on sur.role_id = rpr.ROLE_ID_
|
||||
left join sys_user su on su.user_id = sur.user_id
|
||||
<where>
|
||||
su.user_name = #{username}
|
||||
<if test="name != null and name != ''">
|
||||
and rd.name_ like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="category != null and category != ''">
|
||||
and rd.category_ = #{category}
|
||||
</if>
|
||||
</where>
|
||||
order by rd.deploy_time_ desc
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
rp.id_ as id,
|
||||
rp.deployment_id_ as deploymentId,
|
||||
rd.name_ as name,
|
||||
rd.category_ as category,
|
||||
sdd.dict_label as categoryName,
|
||||
rp.key_ as flowKey,
|
||||
rp.version_ as version,
|
||||
rp.suspension_state_ as suspensionState,
|
||||
rd.deploy_time_ as deploymentTime,
|
||||
ROW_NUMBER () OVER (
|
||||
PARTITION BY rp.key_
|
||||
ORDER BY
|
||||
rp.version_ DESC
|
||||
) AS rn
|
||||
FROM
|
||||
act_re_procdef rp
|
||||
LEFT JOIN act_re_deployment rd ON rp.deployment_id_ = rd.id_
|
||||
left join sys_dict_data sdd on sdd.dict_type='sys_process_category' and sdd.dict_value = rd.category_
|
||||
left join act_re_procdef_role rpr on rp.key_ = rpr.PROCDEF_KEY_
|
||||
left join sys_user_role sur on sur.role_id = rpr.ROLE_ID_
|
||||
left join sys_user su on su.user_id = sur.user_id
|
||||
<where>
|
||||
su.user_name = #{username}
|
||||
<if test="name != null and name != ''">
|
||||
and rd.name_ like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="category != null and category != ''">
|
||||
and rd.category_ = #{category}
|
||||
</if>
|
||||
</where>
|
||||
order by rd.deploy_time_ desc
|
||||
) v WHERE v.rn = 1
|
||||
</select>
|
||||
|
||||
<delete id="deleteDeployByRoleId" parameterType="string">
|
||||
|
|
|
@ -8,10 +8,10 @@ import com.ruoyi.common.core.redis.RedisCache;
|
|||
import com.ruoyi.framework.web.service.SysLoginService;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.web.userLogin.service.IWechatUserLoginService;
|
||||
import com.yanzhu.jh.trouble.domain.SmzSspProblemmodify;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -55,11 +55,11 @@ public class WechatUserLoginController extends BaseController {
|
|||
ajax.put(Constants.TOKEN, token);
|
||||
// 移动端这里刷新token有效期为长期
|
||||
tokenService.refreshMobileToken(token);
|
||||
// 查询当前用户的微信公众号msgOpenId
|
||||
ajax.put("data",wechatUserLoginService.findUserInfo(loginBody.getUsername(),loginBody.getOpenId()));
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
|
@ -109,7 +109,15 @@ public class WechatUserLoginController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/selectRoleMenuList")
|
||||
public AjaxResult selectRoleMenuList(@RequestParam Map<String,Object> map){
|
||||
return success(wechatUserLoginService.selectRoleMenuList(map));
|
||||
//设置缓存
|
||||
String key="wechat_selectRoleMenuList-"+map.get("username")+map.get("type");
|
||||
Object obj=redisCache.getCacheObject(key);
|
||||
if(obj!=null){
|
||||
return success(obj);
|
||||
}
|
||||
List<Map<String,Object>> list = wechatUserLoginService.selectRoleMenuList(map);
|
||||
redisCache.setCacheObject(key, list, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,4 +152,19 @@ public class WechatUserLoginController extends BaseController {
|
|||
return wechatUserLoginService.updataUser(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loginOut")
|
||||
public AjaxResult loginOut(HttpServletRequest request){
|
||||
try {
|
||||
tokenService.delLoginUser(request);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public interface WechatUserLoginMapper {
|
|||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
int checkBindByOpenId(String openId);
|
||||
List<Map<String,Object>> checkBindByOpenId(String openId);
|
||||
|
||||
/**
|
||||
* 根据用户openid查询用户信息
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.text.Convert;
|
|||
import com.ruoyi.common.enums.DeptTypeEnum;
|
||||
import com.ruoyi.common.enums.SysRoleEnum;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
|
@ -123,21 +124,22 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
|
|||
projectInfo.put("logCompanyName",userData.get("dept_name"));
|
||||
data.put("projectInfo",projectInfo);
|
||||
}
|
||||
data.put("userinfo",userInfo);
|
||||
//存储用户openid
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("loginName",loginName);
|
||||
map.put("userId", Convert.toStr(userData.get("user_id")));
|
||||
map.put("nickname",userData.get("nick_name"));
|
||||
map.put("openId",openId);
|
||||
map.put("unionid",redisCache.getCacheObject("openid-unionid"+openId));
|
||||
//验证手机号码是否绑定
|
||||
int count = wechatUserLoginMapper.checkBindByOpenId(openId);
|
||||
if(count > 0){
|
||||
List<Map<String,Object>> checkList = wechatUserLoginMapper.checkBindByOpenId(openId);
|
||||
if(StringUtils.isNotNull(checkList)){
|
||||
//将公众号openid传入到个人信息中...
|
||||
userInfo.put("msgOpenId",checkList.get(0).get("msgOpenId"));
|
||||
wechatUserLoginMapper.updateUserOpenId(map);
|
||||
}else {
|
||||
wechatUserLoginMapper.addUserOpenId(map);
|
||||
}
|
||||
data.put("userinfo",userInfo);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -182,10 +184,7 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
|
|||
String resultStr = HttpUtil.get(url);
|
||||
JSONObject json = JSONObject.parseObject(resultStr);
|
||||
//删除参数session_key,否则小程序检测关键参数暴露,提示整改
|
||||
String key = "openid-unionid"+json.get("openid");
|
||||
redisCache.setCacheObject(key,json.get("unionid"),24, TimeUnit.HOURS);
|
||||
json.remove("session_key");
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,13 @@ server:
|
|||
# Tomcat启动初始化的线程数,默认值10
|
||||
min-spare: 100
|
||||
|
||||
#微信公众号配置
|
||||
wechat:
|
||||
mpAppId: wxe6fd9ad863ac09bf
|
||||
mpAppSecret: ed08e7f6f42a40fc9fa0ebbc1bc6a1db
|
||||
wxAppId: wx9997d071b4996f23
|
||||
wxAppSecret: 5bcc9ca17b31133d93a025871fc5021d
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
|
|
|
@ -34,6 +34,13 @@ server:
|
|||
# Tomcat启动初始化的线程数,默认值10
|
||||
min-spare: 100
|
||||
|
||||
#微信公众号配置
|
||||
wechat:
|
||||
mpAppId: wxe6fd9ad863ac09bf
|
||||
mpAppSecret: ed08e7f6f42a40fc9fa0ebbc1bc6a1db
|
||||
wxAppId: wx9997d071b4996f23
|
||||
wxAppSecret: 5bcc9ca17b31133d93a025871fc5021d
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
|
|
|
@ -92,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
SELECT
|
||||
id,
|
||||
openId,
|
||||
msgOpenId,
|
||||
userId,
|
||||
loginName,
|
||||
nickname
|
||||
|
@ -108,8 +109,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<!--验证当前openId是否已绑定-->
|
||||
<select id="checkBindByOpenId" parameterType="String" resultType="int">
|
||||
select count(1) from sys_user_openid where openId=#{openId} and isDel=0
|
||||
<select id="checkBindByOpenId" parameterType="String" resultType="Map">
|
||||
select id,openId,msgOpenId,userId,loginName,nickname from sys_user_openid where openId=#{openId} and isDel=0
|
||||
</select>
|
||||
|
||||
<!--查询角色相关菜单-->
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.yanzhu.jh.wxsetting.service.impl;
|
||||
|
||||
import com.ruoyi.common.config.WechatAccountConfig;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
|
@ -150,7 +151,9 @@ public class WxMessageImpl{
|
|||
//模板数据
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(supMsgId)
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId()).build();
|
||||
.templateId(TemplateMessageEnum.APPLY_DEFAULT.getId())
|
||||
.miniProgram(new WxMpTemplateMessage.MiniProgram(WechatAccountConfig.getWxAppId(), "/pageage/project_checking/list/index?barProId="+surProjectChecking.getProjectId()))
|
||||
.build();
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing14", this.getMsgProName(surProjectChecking.getProjectId())));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing1", MessageTypeEnum.JPYSSP.getName()));
|
||||
templateMessage.addWxMpTemplateData(new WxMpTemplateData("thing2", "待"+surProjectChecking.getSuperviseUserName()+"审批"));
|
||||
|
@ -503,7 +506,7 @@ public class WxMessageImpl{
|
|||
list = sysUserOpenidMapper.findMsgProSupUsers(proId);
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_P_SUP +proId,list,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_P_SUP +proId,list,30, TimeUnit.MINUTES);
|
||||
List<String> strs = list.stream().map(SysUserOpenid :: getMsgOpenId).collect(Collectors.toList());
|
||||
return String.join(",",strs);
|
||||
}else{
|
||||
|
@ -526,7 +529,7 @@ public class WxMessageImpl{
|
|||
list = sysUserOpenidMapper.findMsgProMagUsers(proId);
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_P_MAG +proId,list,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_P_MAG +proId,list,30, TimeUnit.MINUTES);
|
||||
List<String> strs = list.stream().map(SysUserOpenid :: getMsgOpenId).collect(Collectors.toList());
|
||||
return String.join(",",strs);
|
||||
}else{
|
||||
|
@ -552,7 +555,7 @@ public class WxMessageImpl{
|
|||
depName = sysDept.getDeptName().substring(0,13);
|
||||
}
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_DNAME +depId,depName,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_DNAME +depId,depName,30, TimeUnit.MINUTES);
|
||||
return depName;
|
||||
}
|
||||
}
|
||||
|
@ -574,7 +577,7 @@ public class WxMessageImpl{
|
|||
proName = surProject.getProjectName().substring(0,20);
|
||||
}
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_PNAME +proId,proName,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_PNAME +proId,proName,30, TimeUnit.MINUTES);
|
||||
return proName;
|
||||
}
|
||||
}
|
||||
|
@ -592,7 +595,7 @@ public class WxMessageImpl{
|
|||
SysUser sysUser = sysUserMapper.selectUserByUserName(userName);
|
||||
name = sysUser!=null?sysUser.getNickName():"";
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_UNAME +userName,name,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_UNAME +userName,name,30, TimeUnit.MINUTES);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -611,7 +614,7 @@ public class WxMessageImpl{
|
|||
List<String> strs = list.stream().map(SysUserOpenid :: getMsgOpenId).collect(Collectors.toList());
|
||||
openIds = String.join(",",strs);
|
||||
//设置30分钟有效期
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName,openIds,1, TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(CacheConstants.WX_MPMESSAGE_OPENID +userName,openIds,30, TimeUnit.MINUTES);
|
||||
return openIds;
|
||||
}
|
||||
}
|
||||
|
@ -619,7 +622,7 @@ public class WxMessageImpl{
|
|||
/**
|
||||
* 模板消息开关
|
||||
*/
|
||||
private boolean wxSwitch=false;
|
||||
private boolean wxSwitch=true;
|
||||
|
||||
/**
|
||||
* 推送模板消息
|
||||
|
@ -639,7 +642,7 @@ public class WxMessageImpl{
|
|||
message.setToUser(toUser);
|
||||
wxMpService.getTemplateMsgService().sendTemplateMsg(message);
|
||||
//5分钟内不推送相同类型的消息
|
||||
redisCache.setCacheObject(key,false,30, TimeUnit.SECONDS);
|
||||
redisCache.setCacheObject(key,false,1, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue