zoukankan      html  css  js  c++  java
  • bladex中服务远程调用

    //api中接口

     //实现类

     

     //需要调用的远程服务的接口

     

     //需要远程调用服务的实现类

     

    package org.springblade.flow.business.service.impl;
    
    import lombok.AllArgsConstructor;
    import org.flowable.task.api.Task;
    import org.springblade.core.secure.utils.AuthUtil;
    import org.springblade.core.tool.utils.Func;
    import org.springblade.flow.business.service.ISendWeChatMsg;
    import org.springblade.resource.entity.WeChatSendMsgTextParam;
    import org.springblade.resource.feign.IWeChatClient;
    import org.springblade.system.user.cache.UserCache;
    import org.springblade.system.user.entity.User;
    import org.springframework.stereotype.Service;
    
    import java.text.MessageFormat;
    import java.util.List;
    import java.util.Map;
    
    import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
    
    @Service
    @AllArgsConstructor
    public class SendWeChatMsg implements ISendWeChatMsg {
    
    	private IWeChatClient weChatClient;
    
    	@Override
    	//发送消息
    	public void sendWeChatMsg(List<Task> curTasks,List<Task> nextTasks,String msgType){
    		if(Func.isEmpty(nextTasks)||Func.isNull(nextTasks)){
    			return ;
    		}
    		Map<String, Object> map = nextTasks.get(0).getProcessVariables();
    		String subject = "";
    		String orderCode = "";
    		String formName ="";
    		if(Func.isNotEmpty(map)) {
    			if (map.containsKey("subject")) {
    				subject = map.get("subject").toString();
    			}
    			if (map.containsKey("orderCode")) {
    				orderCode = map.get("orderCode").toString();
    			}
    			if (map.containsKey("formName")) {
    				formName = map.get("formName").toString();
    			}
    		}
    		String userId ="";
    		String userName = "";
    		if(Func.isNotEmpty(curTasks)) {
    			Task task = curTasks.get(0);
    			String assignee = task.getAssignee();
    			if(Func.isNotEmpty(assignee)){
    				if(assignee.contains(TASK_USR_PREFIX)){
    					User fromUser = UserCache.getUserByTaskUser(assignee);
    					if(Func.isNotEmpty(fromUser)) {
    						userId = String.valueOf(fromUser.getId());
    						userName = fromUser.getName();
    					}
    				}
    				else if(Func.isNumeric(assignee)){
    					userId = assignee;
    					User user = UserCache.getUser(Long.valueOf(assignee));
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    				else {
    					userId = String.valueOf(AuthUtil.getUserId());
    					User user = UserCache.getUser(AuthUtil.getUserId());
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    			}
    			else {
    				userId = String.valueOf(AuthUtil.getUserId());
    				User user = UserCache.getUser(AuthUtil.getUserId());
    				if(Func.isNotEmpty(user)){
    					userName = user.getName();
    				}
    			}
    		}
    
    		String weChatId ="";
    		if(Func.isNotEmpty(nextTasks)) {
    			for(Task task : nextTasks) {
    				String assignee = task.getAssignee();
    				if(Func.isNotEmpty(assignee)){
    					if(assignee.contains(TASK_USR_PREFIX)){
    						User toUser = UserCache.getUserByTaskUser(assignee);
    						if(Func.isNotEmpty(toUser)) {
    							if(Func.isNotEmpty(weChatId)){
    								weChatId = weChatId+","+toUser.getWeChatId();
    							}
    							else{
    								weChatId = toUser.getWeChatId();
    							}
    						}
    					}
    					else if(Func.isNumeric(assignee)){
    						User toUser = UserCache.getUser(Long.valueOf(assignee));
    						if(Func.isNotEmpty(toUser)){
    							if(Func.isNotEmpty(weChatId)){
    								weChatId = weChatId+","+toUser.getWeChatId();
    							}
    							else{
    								weChatId = toUser.getWeChatId();
    							}
    						}
    					}
    				}
    			}
    		}
    
    		if(Func.isNotEmpty(weChatId)){
    			if("textCard".equals(msgType)){
    
    			}
    			else if("news".equals(msgType)){
    
    			}
    			else{
    				//默认text
    				WeChatSendMsgTextParam text = new WeChatSendMsgTextParam();
    				String subjectFormat = "您有新接收的{0}代办事务,请处理: 主题 - {1} 单号 - {2} ";
    				String content = MessageFormat.format(subjectFormat,formName,subject,orderCode);
    				text.setTouser(weChatId);
    				text.setContent(content);
    				weChatClient.sendTextMsgFlow(userId,userName,subject,text);
    			}
    		}
    
    	}
    
    	@Override
    	//发送消息
    	public void sendWeChatMsg(String taskUser,List<Task> nextTasks,String msgType){
    		if(Func.isEmpty(nextTasks)||Func.isNull(nextTasks)){
    			return ;
    		}
    		Map<String, Object> map = nextTasks.get(0).getProcessVariables();
    		String subject = "";
    		String orderCode = "";
    		String formName ="";
    		if(Func.isNotEmpty(map)) {
    			if (map.containsKey("subject")) {
    				subject = map.get("subject").toString();
    			}
    			if (map.containsKey("orderCode")) {
    				orderCode = map.get("orderCode").toString();
    			}
    			if (map.containsKey("formName")) {
    				formName = map.get("formName").toString();
    			}
    		}
    		String userId ="";
    		String userName = "";
    		if(Func.isNotEmpty(taskUser)) {
    			String assignee = taskUser;
    			if(Func.isNotEmpty(assignee)){
    				if(assignee.contains(TASK_USR_PREFIX)){
    					User fromUser = UserCache.getUserByTaskUser(assignee);
    					if(Func.isNotEmpty(fromUser)) {
    						userId = String.valueOf(fromUser.getId());
    						userName = fromUser.getName();
    					}
    				}
    				else if(Func.isNumeric(assignee)){
    					userId = assignee;
    					User user = UserCache.getUser(Long.valueOf(assignee));
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    				else {
    					userId = String.valueOf(AuthUtil.getUserId());
    					User user = UserCache.getUser(AuthUtil.getUserId());
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    			}
    			else {
    				userId = String.valueOf(AuthUtil.getUserId());
    				User user = UserCache.getUser(AuthUtil.getUserId());
    				if(Func.isNotEmpty(user)){
    					userName = user.getName();
    				}
    			}
    		}
    
    		String weChatId ="";
    		if(Func.isNotEmpty(nextTasks)) {
    			for(Task task : nextTasks) {
    				String assignee = task.getAssignee();
    				if(Func.isNotEmpty(assignee)){
    					if(assignee.contains(TASK_USR_PREFIX)){
    						User toUser = UserCache.getUserByTaskUser(assignee);
    						if(Func.isNotEmpty(toUser)) {
    							if(Func.isNotEmpty(weChatId)){
    								weChatId = weChatId+","+toUser.getWeChatId();
    							}
    							else{
    								weChatId = toUser.getWeChatId();
    							}
    						}
    					}
    					else if(Func.isNumeric(assignee)){
    						User toUser = UserCache.getUser(Long.valueOf(assignee));
    						if(Func.isNotEmpty(toUser)){
    							if(Func.isNotEmpty(weChatId)){
    								weChatId = weChatId+","+toUser.getWeChatId();
    							}
    							else{
    								weChatId = toUser.getWeChatId();
    							}
    						}
    					}
    				}
    			}
    		}
    
    		if(Func.isNotEmpty(weChatId)){
    			if("textCard".equals(msgType)){
    
    			}
    			else if("news".equals(msgType)){
    
    			}
    			else{
    				//默认text
    				WeChatSendMsgTextParam text = new WeChatSendMsgTextParam();
    				String subjectFormat = "您有新接收的{0}代办事务,请处理: 主题 - {1} 单号 - {2} ";
    				String content = MessageFormat.format(subjectFormat,formName,subject,orderCode);
    				text.setTouser(weChatId);
    				text.setContent(content);
    				weChatClient.sendTextMsgFlow(userId,userName,subject,text);
    			}
    		}
    
    	}
    
    	@Override
    	public void sendEndWeChatMsg(List<Task> curTasks, List<Task> nextTasks, String msgType) {
    		if(Func.isEmpty(nextTasks)||Func.isNull(nextTasks)){
    			return ;
    		}
    		Map<String, Object> map = nextTasks.get(0).getProcessVariables();
    		String subject = "";
    		String orderCode = "";
    		String formName ="";
    		String ccUser ="";
    		if(Func.isNotEmpty(map)) {
    			if (map.containsKey("subject")) {
    				subject = map.get("subject").toString();
    			}
    			if (map.containsKey("orderCode")) {
    				orderCode = map.get("orderCode").toString();
    			}
    			if (map.containsKey("formName")) {
    				formName = map.get("formName").toString();
    			}
    			if (map.containsKey("ccUser")) {
    				ccUser = map.get("ccUser").toString();
    			}
    		}
    		String userId ="";
    		String userName = "";
    		if(Func.isNotEmpty(curTasks)) {
    			String assignee = curTasks.get(0).getAssignee();
    			if(Func.isNotEmpty(assignee)){
    				if(assignee.contains(TASK_USR_PREFIX)){
    					User fromUser = UserCache.getUserByTaskUser(assignee);
    					if(Func.isNotEmpty(fromUser)) {
    						userId = String.valueOf(fromUser.getId());
    						userName = fromUser.getName();
    					}
    				}
    				else if(Func.isNumeric(assignee)){
    					userId = assignee;
    					User user = UserCache.getUser(Long.valueOf(assignee));
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    				else {
    					userId = String.valueOf(AuthUtil.getUserId());
    					User user = UserCache.getUser(AuthUtil.getUserId());
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    			}
    			else {
    				userId = String.valueOf(AuthUtil.getUserId());
    				User user = UserCache.getUser(AuthUtil.getUserId());
    				if(Func.isNotEmpty(user)){
    					userName = user.getName();
    				}
    			}
    		}
    
    		String weChatId ="";
    		if(Func.isNotEmpty(ccUser)){
    			String[] toTaskUserArray = Func.toStrArray(ccUser);
    			for(int index = 0 ; index< toTaskUserArray.length;index++){
    				String toTaskUser = toTaskUserArray[index];
    				User toUser = null;
    				if(toTaskUser.contains(TASK_USR_PREFIX)){
    					toUser = UserCache.getUserByTaskUser(toTaskUser);
    				}
    				else if(Func.isNumeric(toTaskUser)) {
    					toUser = UserCache.getUser(Long.valueOf(toTaskUser));
    				}
    				if(Func.isNotEmpty(toUser)&&Func.isNotEmpty(toUser.getWeChatId())) {
    					if(Func.isNotEmpty(weChatId)){
    						weChatId = weChatId+","+toUser.getWeChatId();
    					}
    					else{
    						weChatId = toUser.getWeChatId();
    					}
    				}
    			}
    		}
    
    		if(Func.isNotEmpty(weChatId)){
    			if("textCard".equals(msgType)){
    
    			}
    			else if("news".equals(msgType)){
    
    			}
    			else{
    				//默认text
    				WeChatSendMsgTextParam text = new WeChatSendMsgTextParam();
    				String subjectFormat = "您有新接收的{0}抄送事务,请处理: 主题 - {1} 单号 - {2} ";
    				String content = MessageFormat.format(subjectFormat,formName,subject,orderCode);
    				text.setTouser(weChatId);
    				text.setContent(content);
    				weChatClient.sendTextMsgFlow(userId,userName,subject,text);
    			}
    		}
    	}
    
    	@Override
    	public void sendEndWeChatMsg(String taskUser, Map<String,Object> map, String msgType) {
    		if(Func.isEmpty(map)||Func.isNull(map)){
    			return ;
    		}
    		String subject = "";
    		String orderCode = "";
    		String formName ="";
    		String ccUser ="";
    		if(Func.isNotEmpty(map)) {
    			if (map.containsKey("subject")) {
    				subject = map.get("subject").toString();
    			}
    			if (map.containsKey("orderCode")) {
    				orderCode = map.get("orderCode").toString();
    			}
    			if (map.containsKey("formName")) {
    				formName = map.get("formName").toString();
    			}
    			if (map.containsKey("ccUser")) {
    				ccUser = map.get("ccUser").toString();
    			}
    		}
    		String userId ="";
    		String userName = "";
    		if(Func.isNotEmpty(taskUser)) {
    			String assignee = taskUser;
    			if(Func.isNotEmpty(assignee)){
    				if(assignee.contains(TASK_USR_PREFIX)){
    					User fromUser = UserCache.getUserByTaskUser(assignee);
    					if(Func.isNotEmpty(fromUser)) {
    						userId = String.valueOf(fromUser.getId());
    						userName = fromUser.getName();
    					}
    				}
    				else if(Func.isNumeric(assignee)){
    					userId = assignee;
    					User user = UserCache.getUser(Long.valueOf(assignee));
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    				else {
    					userId = String.valueOf(AuthUtil.getUserId());
    					User user = UserCache.getUser(AuthUtil.getUserId());
    					if(Func.isNotEmpty(user)){
    						userName = user.getName();
    					}
    				}
    			}
    			else {
    				userId = String.valueOf(AuthUtil.getUserId());
    				User user = UserCache.getUser(AuthUtil.getUserId());
    				if(Func.isNotEmpty(user)){
    					userName = user.getName();
    				}
    			}
    		}
    
    		String weChatId ="";
    		if(Func.isNotEmpty(ccUser)){
    			String[] toTaskUserArray = Func.toStrArray(ccUser);
    			for(int index = 0 ; index< toTaskUserArray.length;index++){
    				String toTaskUser = toTaskUserArray[index];
    				User toUser = null;
    				if(toTaskUser.contains(TASK_USR_PREFIX)){
    					toUser = UserCache.getUserByTaskUser(toTaskUser);
    				}
    				else if(Func.isNumeric(toTaskUser)) {
    					toUser = UserCache.getUser(Long.valueOf(toTaskUser));
    				}
    				if(Func.isNotEmpty(toUser)&&Func.isNotEmpty(toUser.getWeChatId())) {
    					if(Func.isNotEmpty(weChatId)){
    						weChatId = weChatId+","+toUser.getWeChatId();
    					}
    					else{
    						weChatId = toUser.getWeChatId();
    					}
    				}
    			}
    		}
    
    		if(Func.isNotEmpty(weChatId)){
    			if("textCard".equals(msgType)){
    
    			}
    			else if("news".equals(msgType)){
    
    			}
    			else{
    				//默认text
    				WeChatSendMsgTextParam text = new WeChatSendMsgTextParam();
    				String subjectFormat = "您有新接收的{0}抄送事务,请处理: 主题 - {1} 单号 - {2} ";
    				String content = MessageFormat.format(subjectFormat,formName,subject,orderCode);
    				text.setTouser(weChatId);
    				text.setContent(content);
    				weChatClient.sendTextMsgFlow(userId,userName,subject,text);
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    cookie的设置、获取和删除封装
    原生javascript封装ajax和jsonp
    javascript模块化应用
    图解javascript this指向什么?
    学习bootstrap心得
    javascript使用两个逻辑非运算符(!!)的原因
    dubbo小教程
    JSTL与EL表达式(为空判断)
    自己整理的常用SQL Server 2005 语句、
    python基础:迭代器、生成器(yield)详细解读
  • 原文地址:https://www.cnblogs.com/xianz666/p/14510175.html
Copyright © 2011-2022 走看看